| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.ComponentModel;
|
|---|
| 4 | using System.Data;
|
|---|
| 5 | using System.Data.SqlClient;
|
|---|
| 6 | using System.Drawing;
|
|---|
| 7 | using System.Text;
|
|---|
| 8 | using System.Windows.Forms;
|
|---|
| 9 | using BazaZamowien.Classes;
|
|---|
| 10 |
|
|---|
| 11 | namespace BazaZamowien
|
|---|
| 12 | {
|
|---|
| 13 | public partial class premieForm : Form
|
|---|
| 14 | {
|
|---|
| 15 | private bool queryExist;
|
|---|
| 16 | private SqlCommand refreshCommand = new SqlCommand();
|
|---|
| 17 |
|
|---|
| 18 | private static premieForm premieFormInstace;
|
|---|
| 19 |
|
|---|
| 20 | SqlCommand command = new SqlCommand();
|
|---|
| 21 |
|
|---|
| 22 | public static premieForm getPremieForm(MDImainForm parent)
|
|---|
| 23 | {
|
|---|
| 24 | if (premieFormInstace == null)
|
|---|
| 25 | {
|
|---|
| 26 | premieFormInstace = new premieForm(parent);
|
|---|
| 27 | }
|
|---|
| 28 | return premieFormInstace;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | private premieForm(MDImainForm parent)
|
|---|
| 32 | {
|
|---|
| 33 | InitializeComponent();
|
|---|
| 34 |
|
|---|
| 35 | this.MdiParent = parent;
|
|---|
| 36 |
|
|---|
| 37 | this.pREMIE2TableAdapter.Connection.ConnectionString = ConnString.getConnString().PremieConnStr;
|
|---|
| 38 |
|
|---|
| 39 | PremieDBBindings.bindujDzialy((ComboBox)dzialyToolStripComboBox.Control, User.getUser().PremieGrupa);
|
|---|
| 40 | PremieDBBindings.bindujPracownikow((ComboBox)pracownikToolStripComboBox.Control, User.getUser().PremieGrupa);
|
|---|
| 41 |
|
|---|
| 42 | adminToolStripButton.Visible = toolStripSeparator2.Visible = User.getUser().PremieGrupa == 22;
|
|---|
| 43 | wspolczynnikiToolStripButton.Visible = toolStripSeparator1.Visible = (User.getUser().PremieGrupa == 22 || User.getUser().PremieGrupa == 1);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | private void premieForm_Load(object sender, EventArgs e)
|
|---|
| 47 | {
|
|---|
| 48 | danePoczatkowe();
|
|---|
| 49 |
|
|---|
| 50 | uprawnienia();
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | private void dodajToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 54 | {
|
|---|
| 55 | premiaForm pf = new premiaForm(0);
|
|---|
| 56 | if (pf.ShowDialog() == DialogResult.OK)
|
|---|
| 57 | {
|
|---|
| 58 | danePoczatkowe();
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | private void edytujToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 63 | {
|
|---|
| 64 | if (pREMIE2BindingSource.Current != null)
|
|---|
| 65 | {
|
|---|
| 66 | DataRowView row = (DataRowView)pREMIE2BindingSource.Current;
|
|---|
| 67 | int ID = Convert.ToInt32(row["ID"]);
|
|---|
| 68 |
|
|---|
| 69 | premiaForm pf = new premiaForm(ID);
|
|---|
| 70 | if (pf.ShowDialog() == DialogResult.OK)
|
|---|
| 71 | {
|
|---|
| 72 | odswiez();
|
|---|
| 73 | }
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | private void usunToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 79 | {
|
|---|
| 80 | if (pREMIE2BindingSource.Current != null)
|
|---|
| 81 | {
|
|---|
| 82 | DataRowView row = (DataRowView)pREMIE2BindingSource.Current;
|
|---|
| 83 | int ID = Convert.ToInt32(row["ID"]);
|
|---|
| 84 |
|
|---|
| 85 | if (MessageBox.Show("Czy na pewno chcesz usun¹æ rekord?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|---|
| 86 | {
|
|---|
| 87 | pREMIE2TableAdapter.Delete(ID);
|
|---|
| 88 | odswiez();
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | private void uprawnienia()
|
|---|
| 95 | {
|
|---|
| 96 | usunToolStripButton.Visible = User.getUser().St_kierownik;
|
|---|
| 97 | dzialyToolStripComboBox.Enabled = !(User.getUser().IDEDzialuCT == 8);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | private void szukajToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 101 | {
|
|---|
| 102 | this.Cursor = Cursors.WaitCursor;
|
|---|
| 103 |
|
|---|
| 104 | command.Connection = new SqlConnection(ConnString.getConnString().PremieConnStr);
|
|---|
| 105 | command.CommandText = "select * from premie2 where 1=1 ";
|
|---|
| 106 | command.Parameters.Clear();
|
|---|
| 107 |
|
|---|
| 108 | if (rokToolStripTextBox.Text != "")
|
|---|
| 109 | {
|
|---|
| 110 | int i;
|
|---|
| 111 | if (!Int32.TryParse(rokToolStripTextBox.Text, out i))
|
|---|
| 112 | {
|
|---|
| 113 | MessageBox.Show("Podaj poprawny rok.");
|
|---|
| 114 | return;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | command.CommandText += " and (Rok=@rok) ";
|
|---|
| 118 | command.Parameters.AddWithValue("@rok", i);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | if (msToolStripTextBox.Text != "")
|
|---|
| 122 | {
|
|---|
| 123 | int i;
|
|---|
| 124 | if (!Int32.TryParse(msToolStripTextBox.Text, out i))
|
|---|
| 125 | {
|
|---|
| 126 | MessageBox.Show("Podaj poprawny rok.");
|
|---|
| 127 | return;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | command.CommandText += " and (miesiac=@ms) ";
|
|---|
| 131 | command.Parameters.AddWithValue("@ms", i);
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | //reklama ma jeszcze filt po oddzialach, reszta nie musi
|
|---|
| 135 | if (User.getUser().IDEDzialuCT == 8)
|
|---|
| 136 | {
|
|---|
| 137 | if (pracownikToolStripComboBox.SelectedItem != null)
|
|---|
| 138 | {
|
|---|
| 139 | command.CommandText += " and IDEPracownika=@ide ";
|
|---|
| 140 | command.Parameters.AddWithValue("@ide", ((BoundItem)pracownikToolStripComboBox.SelectedItem).IDEvalue1);
|
|---|
| 141 | }
|
|---|
| 142 | else
|
|---|
| 143 | {
|
|---|
| 144 | command.CommandText += " and IDEPracownika in (select IDePracownik from dbo.PODWLADNOSC where ideKierownik =@kier) ";
|
|---|
| 145 | command.Parameters.AddWithValue("@kier", User.getUser().IDE_CT);
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 | else
|
|---|
| 149 | {
|
|---|
| 150 | if (dzialyToolStripComboBox.SelectedItem != null)
|
|---|
| 151 | {
|
|---|
| 152 | command.CommandText += " and Dzial=@dzial ";
|
|---|
| 153 | command.Parameters.AddWithValue("@dzial", dzialyToolStripComboBox.SelectedItem.ToString());
|
|---|
| 154 | }
|
|---|
| 155 | else
|
|---|
| 156 | {
|
|---|
| 157 | command.CommandText += " and Dzial in (select dzial from dbo.GrupaDzial left join dbo.Dzialy on" +
|
|---|
| 158 | " dzialy.IDE = grupaDzial.IDEdzial where dbo.GrupaDzial.IDEGrupy = @grupa)";
|
|---|
| 159 | command.Parameters.AddWithValue("@grupa", User.getUser().PremieGrupa);
|
|---|
| 160 |
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | if (pracownikToolStripComboBox.SelectedItem != null)
|
|---|
| 164 | {
|
|---|
| 165 | command.CommandText += " and IDEPracownika=@ide ";
|
|---|
| 166 | command.Parameters.AddWithValue("@ide", ((BoundItem)pracownikToolStripComboBox.SelectedItem).IDEvalue1);
|
|---|
| 167 | }
|
|---|
| 168 | else
|
|---|
| 169 | {
|
|---|
| 170 | command.CommandText += " and IDEPracownika in (select distinct IdePracownik from dbo.PODWLADNOSC " +
|
|---|
| 171 | " where ideDzial in (select IDEDzial from dbo.GrupaDzial where IDEGrupy = @grupa2))";
|
|---|
| 172 | command.Parameters.AddWithValue("@grupa2", User.getUser().PremieGrupa);
|
|---|
| 173 | }
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | pREMIEDataSet.PREMIE2.Clear();
|
|---|
| 177 |
|
|---|
| 178 | SqlDataAdapter adapter = new SqlDataAdapter(command);
|
|---|
| 179 | adapter.Fill(pREMIEDataSet.PREMIE2);
|
|---|
| 180 |
|
|---|
| 181 | this.refreshCommand = command;
|
|---|
| 182 | this.queryExist = true;
|
|---|
| 183 |
|
|---|
| 184 | this.Cursor = Cursors.Default;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | private void filtrToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 188 | {
|
|---|
| 189 | rokToolStripTextBox.Text = "";
|
|---|
| 190 |
|
|---|
| 191 | msToolStripTextBox.Text = "";
|
|---|
| 192 |
|
|---|
| 193 | dzialyToolStripComboBox.SelectedIndex = -1;
|
|---|
| 194 |
|
|---|
| 195 | pracownikToolStripComboBox.SelectedIndex = -1;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | /// <summary>
|
|---|
| 199 | /// ostatnio dodane
|
|---|
| 200 | /// </summary>
|
|---|
| 201 | private void danePoczatkowe()
|
|---|
| 202 | {
|
|---|
| 203 |
|
|---|
| 204 | string query = "select top 20 * from premie2";
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 | if (User.getUser().IDEDzialuCT == 8)
|
|---|
| 208 | {
|
|---|
| 209 | query += " where idePracownika in (select IDePracownik from dbo.PODWLADNOSC where ideKierownik =" + User.getUser().IDE_CT + ")";
|
|---|
| 210 | }
|
|---|
| 211 | else
|
|---|
| 212 | {
|
|---|
| 213 | query += " where Dzial in (select dzial from dbo.GrupaDzial left join dbo.Dzialy on";
|
|---|
| 214 | query += " dzialy.IDE = grupaDzial.IDEdzial where dbo.GrupaDzial.IDEGrupy = @grupa) ";
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | query += " and rok >= year(getdate()) - 1 ";
|
|---|
| 218 | query += " ORDER BY ID desc";
|
|---|
| 219 |
|
|---|
| 220 | SqlCommand command = new SqlCommand();
|
|---|
| 221 | command.CommandText = query;
|
|---|
| 222 | command.Connection = new SqlConnection(ConnString.getConnString().PremieConnStr);
|
|---|
| 223 | command.Parameters.AddWithValue("@grupa", User.getUser().PremieGrupa);
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 | SqlDataAdapter adapter = new SqlDataAdapter();
|
|---|
| 227 | adapter.SelectCommand = command;
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 | this.pREMIEDataSet.PREMIE2.Clear();
|
|---|
| 231 |
|
|---|
| 232 | adapter.Fill(this.pREMIEDataSet.PREMIE2);
|
|---|
| 233 |
|
|---|
| 234 | this.refreshCommand = command;
|
|---|
| 235 | this.queryExist = true;
|
|---|
| 236 |
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | private void odswiez()
|
|---|
| 240 | {
|
|---|
| 241 | if (queryExist)
|
|---|
| 242 | {
|
|---|
| 243 | SqlDataAdapter adapter = new SqlDataAdapter();
|
|---|
| 244 | adapter.SelectCommand = this.refreshCommand;
|
|---|
| 245 |
|
|---|
| 246 | this.pREMIEDataSet.PREMIE2.Clear();
|
|---|
| 247 |
|
|---|
| 248 | adapter.Fill(this.pREMIEDataSet.PREMIE2);
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | private void wspolczynnikiToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 253 | {
|
|---|
| 254 | PremieWspolczynniki premieWspolczynniki = new PremieWspolczynniki();
|
|---|
| 255 | premieWspolczynniki.ShowDialog();
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | private void adminToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 259 | {
|
|---|
| 260 | AdminFormPremie adminPremieForm = new AdminFormPremie();
|
|---|
| 261 | adminPremieForm.ShowDialog();
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | private void emailToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 265 | {
|
|---|
| 266 | if (pREMIE2BindingSource.Current != null)
|
|---|
| 267 | {
|
|---|
| 268 | DataRowView row = (DataRowView) pREMIE2BindingSource.Current;
|
|---|
| 269 | int IDEpremia = Convert.ToInt32(row["ID"]);
|
|---|
| 270 |
|
|---|
| 271 | MailForm mailForm = new MailForm();
|
|---|
| 272 | PremieMail.initMailForm(mailForm,IDEpremia);
|
|---|
| 273 | mailForm.ShowDialog();
|
|---|
| 274 | }
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | private void exportToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 278 | {
|
|---|
| 279 | this.Cursor = Cursors.WaitCursor;
|
|---|
| 280 |
|
|---|
| 281 | ExcelHandler ex = new ExcelHandler();
|
|---|
| 282 | ex.exportToExcel(pREMIE2DataGridView);
|
|---|
| 283 |
|
|---|
| 284 | this.Cursor = Cursors.Default;
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | private void drukujToolStripButton_Click(object sender, EventArgs e)
|
|---|
| 288 | {
|
|---|
| 289 | PrintDGV.Print_DataGridView(pREMIE2DataGridView,100);
|
|---|
| 290 | }
|
|---|
| 291 | }
|
|---|
| 292 | } |
|---|