| 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 premiaForm : Form
|
|---|
| 14 | {
|
|---|
| 15 | bool nowa =false;
|
|---|
| 16 | Premia premia;
|
|---|
| 17 |
|
|---|
| 18 | public premiaForm(int id)
|
|---|
| 19 | {
|
|---|
| 20 | InitializeComponent();
|
|---|
| 21 |
|
|---|
| 22 | this.pREMIE2TableAdapter.Connection.ConnectionString = ConnString.getConnString().PremieConnStr;
|
|---|
| 23 |
|
|---|
| 24 | PremieDBBindings.bindujDzialy(dZIALComboBox,User.getUser().PremieGrupa);
|
|---|
| 25 | PremieDBBindings.bindujPracownikow(nAMEComboBox, User.getUser().PremieGrupa);
|
|---|
| 26 |
|
|---|
| 27 | int rok = 1997;
|
|---|
| 28 | while (rok != DateTime.Today.Year +1)
|
|---|
| 29 | {
|
|---|
| 30 | rOKComboBox.Items.Add(rok);
|
|---|
| 31 | rok++;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | if (id == 0)
|
|---|
| 35 | {
|
|---|
| 36 | nowa = true;
|
|---|
| 37 |
|
|---|
| 38 | DataView table = (DataView)pREMIE2BindingSource.List;
|
|---|
| 39 | DataRowView row = table.AddNew();
|
|---|
| 40 |
|
|---|
| 41 | row["ROK"] = DateTime.Today.Year;
|
|---|
| 42 | row["MIESIAC"] = DateTime.Today.Month;
|
|---|
| 43 | row["data_wprowadzenia"] = DateTime.Now;
|
|---|
| 44 | row["wprowadzil"] = User.getUser().Symbol.ToLower();
|
|---|
| 45 |
|
|---|
| 46 | pREMIE2BindingSource.EndEdit();
|
|---|
| 47 | }
|
|---|
| 48 | else
|
|---|
| 49 | {
|
|---|
| 50 | this.pREMIE2TableAdapter.FillByID(this.pREMIEDataSet.PREMIE2, id);
|
|---|
| 51 | dodajButton.Text = "Zapisz";
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 | premia = new Premia();
|
|---|
| 56 |
|
|---|
| 57 | this.nAMEComboBox.SelectedIndexChanged += new System.EventHandler(this.nAMEComboBox_SelectedIndexChanged);
|
|---|
| 58 |
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | private void anulujButton_Click(object sender, EventArgs e)
|
|---|
| 62 | {
|
|---|
| 63 | this.Close();
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | private void dodajButton_Click(object sender, EventArgs e)
|
|---|
| 67 | {
|
|---|
| 68 | pREMIE2BindingSource.EndEdit();
|
|---|
| 69 |
|
|---|
| 70 | DataRowView row = (DataRowView)pREMIE2BindingSource.Current;
|
|---|
| 71 |
|
|---|
| 72 | if (nowa)
|
|---|
| 73 | {
|
|---|
| 74 | if (nAMEComboBox.SelectedItem == null)
|
|---|
| 75 | {
|
|---|
| 76 | MessageBox.Show("Wybierz pracownika.");
|
|---|
| 77 | return;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | if (dZIALComboBox.SelectedItem == null)
|
|---|
| 81 | {
|
|---|
| 82 | MessageBox.Show("Wybierz dzia³.");
|
|---|
| 83 | return;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | if (rOKComboBox.SelectedItem == null)
|
|---|
| 87 | {
|
|---|
| 88 | MessageBox.Show("Wybierz rok.");
|
|---|
| 89 | return;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | if (mIESIACComboBox.SelectedItem == null)
|
|---|
| 93 | {
|
|---|
| 94 | MessageBox.Show("Wybierz miesi¹c.");
|
|---|
| 95 | return;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | row["name"] = nAMEComboBox.Text;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | DataTable changes = pREMIEDataSet.PREMIE2.GetChanges();
|
|---|
| 102 |
|
|---|
| 103 | if (changes != null)
|
|---|
| 104 | {
|
|---|
| 105 | row["data_modyfikacji"] = nowa ? row["data_wprowadzenia"] : DateTime.Now;
|
|---|
| 106 | row["zmodyfikowal"] = User.getUser().Symbol.ToLower();
|
|---|
| 107 | pREMIE2BindingSource.EndEdit();
|
|---|
| 108 | pREMIE2TableAdapter.Update(this.pREMIEDataSet);
|
|---|
| 109 | MessageBox.Show("Zmiany zosta³y zapisane.");
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | this.DialogResult = DialogResult.OK;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | private void bRUTTOTextBox_Leave(object sender, EventArgs e)
|
|---|
| 116 | {
|
|---|
| 117 | pREMIE2BindingSource.EndEdit();
|
|---|
| 118 | DataRowView row = (DataRowView)pREMIE2BindingSource.Current;
|
|---|
| 119 |
|
|---|
| 120 | decimal result;
|
|---|
| 121 | if (Decimal.TryParse(row["brutto"].ToString(), out result))
|
|---|
| 122 | {
|
|---|
| 123 | row["netto"] = premia.BruttoToNetto(result);
|
|---|
| 124 | pREMIE2BindingSource.EndEdit();
|
|---|
| 125 | }
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | private void nETTOTextBox_Leave(object sender, EventArgs e)
|
|---|
| 129 | {
|
|---|
| 130 | pREMIE2BindingSource.EndEdit();
|
|---|
| 131 | DataRowView row = (DataRowView)pREMIE2BindingSource.Current;
|
|---|
| 132 |
|
|---|
| 133 | decimal result;
|
|---|
| 134 | if (Decimal.TryParse(row["netto"].ToString(), out result))
|
|---|
| 135 | {
|
|---|
| 136 | row["brutto"] = premia.NettoToBrutto(result);
|
|---|
| 137 | pREMIE2BindingSource.EndEdit();
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | private void IloscLubWycena_Leave(object sender, EventArgs e)
|
|---|
| 142 | {
|
|---|
| 143 | pREMIE2BindingSource.EndEdit();
|
|---|
| 144 | DataRowView row = (DataRowView)pREMIE2BindingSource.Current;
|
|---|
| 145 |
|
|---|
| 146 | decimal result1;
|
|---|
| 147 | int result2;
|
|---|
| 148 |
|
|---|
| 149 | if (Decimal.TryParse(row["wycena"].ToString(), out result1) && (Int32.TryParse(row["il"].ToString(),out result2)))
|
|---|
| 150 | {
|
|---|
| 151 | decimal netto = (Math.Round(result1, 2) * result2);
|
|---|
| 152 | row["netto"] = netto.ToString();
|
|---|
| 153 | row["brutto"] = premia.NettoToBrutto(netto).ToString();
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | private void nAMEComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|---|
| 158 | {
|
|---|
| 159 | DataRowView row = (DataRowView)pREMIE2BindingSource.Current;
|
|---|
| 160 | row["IDEPracownika"] = ((BoundItem)nAMEComboBox.SelectedItem).IDEvalue1;
|
|---|
| 161 | pREMIE2BindingSource.EndEdit();
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 | }
|
|---|
| 166 | } |
|---|