| 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 |
|
|---|
| 10 | namespace Baza_Reklam
|
|---|
| 11 | {
|
|---|
| 12 | public partial class Facturer : Form
|
|---|
| 13 | {
|
|---|
| 14 | private int reklamaId;
|
|---|
| 15 | private int customerId;
|
|---|
| 16 |
|
|---|
| 17 | public Facturer(int rekId)
|
|---|
| 18 | {
|
|---|
| 19 | InitializeComponent();
|
|---|
| 20 | this.reklamaId = rekId;
|
|---|
| 21 |
|
|---|
| 22 | kLIENCITableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 23 | kONTATableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 24 | fAKTURYTableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 25 | rEKLAMATableAdapter.Connection.ConnectionString = ConnString.getConnString().Value;
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | /// <summary>
|
|---|
| 29 | /// £aduje informacje z reklamy o fakturze - je¿eli by³a wczeniej wystawiona proforma
|
|---|
| 30 | /// lub inna faktura, to w tabeli REKLAMA sa zapamietane min. daty. Je¿eli faktura jest wystawiana
|
|---|
| 31 | /// po raz pierwszy to wpisuje daty systemowe.
|
|---|
| 32 | /// </summary>
|
|---|
| 33 | private void Facturer_Load(object sender, EventArgs e)
|
|---|
| 34 | {
|
|---|
| 35 | this.rEKLAMATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, reklamaId);
|
|---|
| 36 |
|
|---|
| 37 | if (rEKLAMABindingSource.Current != null)
|
|---|
| 38 | {
|
|---|
| 39 | DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 40 |
|
|---|
| 41 | int idAgencji = Utils.idAgencji(row["SYMBOL AKWIZYTORA"].ToString());
|
|---|
| 42 |
|
|---|
| 43 | this.kONTATableAdapter.FillByIdAgencji(this.sLOWNIKDataSet.KONTA, idAgencji);
|
|---|
| 44 |
|
|---|
| 45 | rEKLAMABindingSource.ResetBindings(false);
|
|---|
| 46 |
|
|---|
| 47 | customerId = Convert.ToInt32(row["customerId"]);
|
|---|
| 48 |
|
|---|
| 49 | kLIENCITableAdapter.FillByCustomerId(this.rEKLAMADataSet.KLIENCI, customerId);
|
|---|
| 50 |
|
|---|
| 51 | if (row["id_faktury"] != DBNull.Value)
|
|---|
| 52 | {
|
|---|
| 53 | wystawFaktureButton.Enabled = false;
|
|---|
| 54 | wystawProformeButton.Enabled = false;
|
|---|
| 55 | usunButton.Enabled = true & User.getUser().St_kierownik;
|
|---|
| 56 |
|
|---|
| 57 | nUMER_ROZTextBox.Text = Utils.tagAgenta(row["SYMBOL AKWIZYTORA"].ToString());
|
|---|
| 58 |
|
|---|
| 59 | string numer_fakt = Convert.ToString(row["FAKTURA NUMER"]);
|
|---|
| 60 | string[] read = new string[3];
|
|---|
| 61 | read = numer_fakt.Split("/".ToCharArray(), 3);
|
|---|
| 62 | nUMERTextBox.Text = read[0];
|
|---|
| 63 | }
|
|---|
| 64 | else
|
|---|
| 65 | {
|
|---|
| 66 | nUMER_ROZTextBox.Text = Utils.tagAgenta(row["SYMBOL AKWIZYTORA"].ToString());
|
|---|
| 67 | nUMERTextBox.Text = Utils.numerNowejFaktury(nUMER_ROZTextBox.Text, DateTime.Today.Year).ToString();
|
|---|
| 68 |
|
|---|
| 69 | if (row["FAKTURA DATA SPRZEDA¯Y"] == DBNull.Value)
|
|---|
| 70 | {
|
|---|
| 71 | dATA_SPRZEDAZYDateTimePicker.Value = DateTime.Today;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | if (row["FAKTURA DATA WYSTAWIENIA"] == DBNull.Value)
|
|---|
| 75 | {
|
|---|
| 76 | dATA_WYSTAWIENIADateTimePicker.Value = DateTime.Today;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | if (row["Zaliczka_Data"] == DBNull.Value)
|
|---|
| 80 | {
|
|---|
| 81 | zaliczka_DataDateTimePicker.Value = DateTime.Today;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | if (row["FAKTURA TERMIN ZAP£ATY"] == DBNull.Value)
|
|---|
| 85 | {
|
|---|
| 86 | tERMIN_ZAPLATYDateTimePicker.Value = DateTime.Today.AddDays(7);
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | sPOSOB_ZAPLATYListBox.SelectedIndex = 1;
|
|---|
| 90 |
|
|---|
| 91 | rEKLAMABindingSource.EndEdit();
|
|---|
| 92 |
|
|---|
| 93 | wystawFaktureButton.Enabled = true;
|
|---|
| 94 | wystawProformeButton.Enabled = true;
|
|---|
| 95 | usunButton.Enabled = false;
|
|---|
| 96 |
|
|---|
| 97 | // iD_KONTAComboBox.SelectedIndex = 0;
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | /// <summary>
|
|---|
| 103 | /// Wywietla szczegó³y konta
|
|---|
| 104 | /// </summary>
|
|---|
| 105 | private void button1_Click(object sender, EventArgs e)
|
|---|
| 106 | {
|
|---|
| 107 | if (kONTABindingSource.Current != null)
|
|---|
| 108 | {
|
|---|
| 109 | DataRowView row = (DataRowView)kONTABindingSource.Current;
|
|---|
| 110 | MessageBox.Show(row["konto"].ToString());
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | private void wystawFaktureButton_Click(object sender, EventArgs e)
|
|---|
| 115 | {
|
|---|
| 116 | this.Cursor = Cursors.WaitCursor;
|
|---|
| 117 |
|
|---|
| 118 | bool ok = false;
|
|---|
| 119 |
|
|---|
| 120 | // if (tYPLabel1.Text == "BEZP£ATNA"
|
|---|
| 121 |
|
|---|
| 122 | if (zATWIERDZONO_DO_DRUKUCheckBox.CheckState != CheckState.Checked)
|
|---|
| 123 | {
|
|---|
| 124 | MessageBox.Show("Zamówienie nie jest zatwierdzone do druku.");
|
|---|
| 125 | this.Cursor = Cursors.Default;
|
|---|
| 126 | return;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | if (Utils.istniejeFaktura(Convert.ToInt32(nUMERTextBox.Text),
|
|---|
| 130 | nUMER_ROZTextBox.Text, dATA_WYSTAWIENIADateTimePicker.Value.Year))
|
|---|
| 131 | {
|
|---|
| 132 | MessageBox.Show("Istnieje ju¿ faktura o numerze " + nUMERTextBox.Text + "/" + nUMER_ROZTextBox.Text + "/" + dATA_WYSTAWIENIADateTimePicker.Value.Year.ToString());
|
|---|
| 133 | this.Cursor = Cursors.Default;
|
|---|
| 134 | return;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | if (iD_KONTAComboBox.SelectedValue == null)
|
|---|
| 138 | {
|
|---|
| 139 | MessageBox.Show("Wybierz konto");
|
|---|
| 140 | this.Cursor = Cursors.Default;
|
|---|
| 141 | return;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 | if ((nipKrajTextBox.Text.Length == 0) && ((int)iD_KONTAComboBox.SelectedValue != 1))
|
|---|
| 146 | {
|
|---|
| 147 | if (MessageBox.Show("Brak kodu kraju w EU. Czy na pewno chcesz wystawiæ fakturê?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
|
|---|
| 148 | == DialogResult.No)
|
|---|
| 149 | {
|
|---|
| 150 | this.Cursor = Cursors.Default;
|
|---|
| 151 | return;
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | SqlConnection conn = new SqlConnection(ConnString.getConnString().Value);
|
|---|
| 156 |
|
|---|
| 157 | SqlTransaction transaction;
|
|---|
| 158 |
|
|---|
| 159 | SqlCommand command = new SqlCommand("Proc_Make_Faktura_Waluty", conn);
|
|---|
| 160 | command.CommandType = CommandType.StoredProcedure;
|
|---|
| 161 |
|
|---|
| 162 | //dodawanie parametrow
|
|---|
| 163 | command.Parameters.AddWithValue("@ReklamaID", this.reklamaId);
|
|---|
| 164 | command.Parameters.AddWithValue("@FakturaNumer", nUMERTextBox.Text);
|
|---|
| 165 | command.Parameters.AddWithValue("@NumerRoz", nUMER_ROZTextBox.Text);
|
|---|
| 166 |
|
|---|
| 167 | switch (sPOSOB_ZAPLATYListBox.SelectedIndex)
|
|---|
| 168 | {
|
|---|
| 169 | case 1:
|
|---|
| 170 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Przelew");
|
|---|
| 171 | break;
|
|---|
| 172 | case 2:
|
|---|
| 173 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Gotówka");
|
|---|
| 174 | break;
|
|---|
| 175 | case 3:
|
|---|
| 176 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Barter");
|
|---|
| 177 | break;
|
|---|
| 178 | default:
|
|---|
| 179 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Karta kredytowa");
|
|---|
| 180 | break;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 184 |
|
|---|
| 185 | command.Parameters.AddWithValue("@Zaplacono", zAPLACONOCheckBox.Checked);
|
|---|
| 186 | command.Parameters.AddWithValue("@FakturaDataWyst", dATA_WYSTAWIENIADateTimePicker.Value);
|
|---|
| 187 | command.Parameters.AddWithValue("@FakturaDataSprzed", dATA_SPRZEDAZYDateTimePicker.Value);
|
|---|
| 188 | command.Parameters.AddWithValue("@FakturaTerminZaplaty", tERMIN_ZAPLATYDateTimePicker.Value);
|
|---|
| 189 | command.Parameters.AddWithValue("@Konto", iD_KONTAComboBox.SelectedValue);
|
|---|
| 190 | command.Parameters.AddWithValue("@StawkaVat", row["VAT"]);
|
|---|
| 191 |
|
|---|
| 192 | if (zaliczka_BruttoTextBox.Text != "")
|
|---|
| 193 | {
|
|---|
| 194 | command.Parameters.AddWithValue("@Zaliczka_Brutto", row["Zaliczka_Brutto"]);
|
|---|
| 195 | command.Parameters.AddWithValue("@Zaliczka_Data", zaliczka_DataDateTimePicker.Value);
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | command.Parameters.AddWithValue("@wyroznienie", row["wyroznienie"]);
|
|---|
| 199 |
|
|---|
| 200 | //dodawanie parametrow do faktury w walucie
|
|---|
| 201 | SqlCommand command2 = new SqlCommand();
|
|---|
| 202 | command2.Connection = conn;
|
|---|
| 203 | command2.CommandType = CommandType.Text;
|
|---|
| 204 | command2.CommandText = "select Brutto_Euro, Brutto_Euro_Miano, waluta_kurs, waluta_przelicznik,waluta_kurs_z_dnia,waluta_tabela_nr from "
|
|---|
| 205 | + "reklama where reklamaId= " + this.reklamaId;
|
|---|
| 206 |
|
|---|
| 207 | conn.Open();
|
|---|
| 208 |
|
|---|
| 209 | SqlDataReader reader = command2.ExecuteReader();
|
|---|
| 210 | while (reader.Read())
|
|---|
| 211 | {
|
|---|
| 212 | command.Parameters.AddWithValue("@waluta_brutto", reader.GetValue(0));
|
|---|
| 213 | command.Parameters.AddWithValue("@waluta_miano", reader.GetValue(1));
|
|---|
| 214 | command.Parameters.AddWithValue("@waluta_kurs", reader.GetValue(2));
|
|---|
| 215 | command.Parameters.AddWithValue("@waluta_przelicznik", reader.GetValue(3));
|
|---|
| 216 | command.Parameters.AddWithValue("@waluta_kurs_z_dnia", reader.GetValue(4));
|
|---|
| 217 | command.Parameters.AddWithValue("@waluta_tabela_nr", reader.GetValue(5));
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | conn.Close();
|
|---|
| 221 |
|
|---|
| 222 | conn.Open();
|
|---|
| 223 |
|
|---|
| 224 | //wystawanie faktury
|
|---|
| 225 | transaction = conn.BeginTransaction();
|
|---|
| 226 |
|
|---|
| 227 | command.Transaction = transaction;
|
|---|
| 228 |
|
|---|
| 229 | try
|
|---|
| 230 | {
|
|---|
| 231 | command.ExecuteNonQuery();
|
|---|
| 232 | transaction.Commit();
|
|---|
| 233 | ok = true;
|
|---|
| 234 | MessageBox.Show("Fakture dodano!");
|
|---|
| 235 | }
|
|---|
| 236 | catch (Exception ex)
|
|---|
| 237 | {
|
|---|
| 238 | MessageBox.Show(ex.GetType() + ex.Message);
|
|---|
| 239 |
|
|---|
| 240 | try
|
|---|
| 241 | {
|
|---|
| 242 | transaction.Rollback();
|
|---|
| 243 | }
|
|---|
| 244 | catch (Exception ex2)
|
|---|
| 245 | {
|
|---|
| 246 | MessageBox.Show("ROLLBACK:" + ex2.GetType() + ex2.Message);
|
|---|
| 247 | }
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | conn.Close();
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 | //odswiezanie - musi byæ bo faktura jest dodawana przez procedure
|
|---|
| 254 |
|
|---|
| 255 | if (ok)
|
|---|
| 256 | {
|
|---|
| 257 | rEKLAMADataSet.REKLAMA.Clear();
|
|---|
| 258 | rEKLAMATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, this.reklamaId);
|
|---|
| 259 | row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 260 |
|
|---|
| 261 | this.rEKLAMADataSet.FAKTURY.Clear();
|
|---|
| 262 | int idFaktury = Convert.ToInt32(row["id_faktury"]);
|
|---|
| 263 | this.fAKTURYTableAdapter.FillByIdFaktury(this.rEKLAMADataSet.FAKTURY, idFaktury);
|
|---|
| 264 |
|
|---|
| 265 | //wydruk faktury
|
|---|
| 266 | FactureViewer fv = new FactureViewer(idFaktury, true);
|
|---|
| 267 | fv.ShowDialog();
|
|---|
| 268 |
|
|---|
| 269 | this.Cursor = Cursors.Default;
|
|---|
| 270 |
|
|---|
| 271 | wystawFaktureButton.Enabled = false;
|
|---|
| 272 | wystawProformeButton.Enabled = false;
|
|---|
| 273 | this.DialogResult = DialogResult.OK;
|
|---|
| 274 | this.Close();
|
|---|
| 275 | }
|
|---|
| 276 | else
|
|---|
| 277 | {
|
|---|
| 278 | this.Cursor = Cursors.Default;
|
|---|
| 279 | }
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 | /// <summary>
|
|---|
| 284 | /// Wystawienie proformy polega na wystawieniu faktury i poniejszym usuniêciu jej z bazy...
|
|---|
| 285 | /// </summary>
|
|---|
| 286 | private void wystawProformeButton_Click(object sender, EventArgs e)
|
|---|
| 287 | {
|
|---|
| 288 | bool ok = false;
|
|---|
| 289 |
|
|---|
| 290 | if (iD_KONTAComboBox.SelectedValue == null)
|
|---|
| 291 | {
|
|---|
| 292 | MessageBox.Show("Wybierz konto");
|
|---|
| 293 | return;
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | SqlConnection conn = new SqlConnection(
|
|---|
| 297 | ConnString.getConnString().Value);
|
|---|
| 298 |
|
|---|
| 299 | SqlTransaction transaction;
|
|---|
| 300 |
|
|---|
| 301 | SqlCommand command = new SqlCommand("Proc_Make_Faktura_Waluty", conn);
|
|---|
| 302 | command.CommandType = CommandType.StoredProcedure;
|
|---|
| 303 |
|
|---|
| 304 | command.Parameters.AddWithValue("@ReklamaID", this.reklamaId);
|
|---|
| 305 | command.Parameters.AddWithValue("@FakturaNumer", nUMERTextBox.Text);
|
|---|
| 306 | command.Parameters.AddWithValue("@NumerRoz", nUMER_ROZTextBox.Text);
|
|---|
| 307 |
|
|---|
| 308 | switch (sPOSOB_ZAPLATYListBox.SelectedIndex)
|
|---|
| 309 | {
|
|---|
| 310 | case 1:
|
|---|
| 311 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Przelew");
|
|---|
| 312 | break;
|
|---|
| 313 | case 2:
|
|---|
| 314 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Gotówka");
|
|---|
| 315 | break;
|
|---|
| 316 | case 3:
|
|---|
| 317 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Barter");
|
|---|
| 318 | break;
|
|---|
| 319 | default:
|
|---|
| 320 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Karta kredytowa");
|
|---|
| 321 | break;
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | DataRowView r = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 325 |
|
|---|
| 326 | command.Parameters.AddWithValue("@Zaplacono", zAPLACONOCheckBox.Checked);
|
|---|
| 327 | command.Parameters.AddWithValue("@FakturaDataWyst", dATA_WYSTAWIENIADateTimePicker.Value);
|
|---|
| 328 | command.Parameters.AddWithValue("@FakturaDataSprzed", dATA_SPRZEDAZYDateTimePicker.Value);
|
|---|
| 329 | command.Parameters.AddWithValue("@FakturaTerminZaplaty", tERMIN_ZAPLATYDateTimePicker.Value);
|
|---|
| 330 | command.Parameters.AddWithValue("@Konto", iD_KONTAComboBox.SelectedValue);
|
|---|
| 331 | command.Parameters.AddWithValue("@StawkaVat", r["VAT"]);
|
|---|
| 332 |
|
|---|
| 333 | if (zaliczka_BruttoTextBox.Text != "")
|
|---|
| 334 | {
|
|---|
| 335 | command.Parameters.AddWithValue("@Zaliczka_Brutto", r["Zaliczka_Brutto"]);
|
|---|
| 336 | command.Parameters.AddWithValue("@Zaliczka_Data", zaliczka_DataDateTimePicker.Value);
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 | command.Parameters.AddWithValue("@wyroznienie", r["wyroznienie"]);
|
|---|
| 340 |
|
|---|
| 341 | SqlCommand command2 = new SqlCommand();
|
|---|
| 342 | command2.Connection = conn;
|
|---|
| 343 | command2.CommandType = CommandType.Text;
|
|---|
| 344 | command2.CommandText = "select Brutto_Euro, Brutto_Euro_Miano, waluta_kurs, waluta_przelicznik,waluta_kurs_z_dnia,waluta_tabela_nr from "
|
|---|
| 345 | + "reklama where reklamaId= " + this.reklamaId;
|
|---|
| 346 |
|
|---|
| 347 | conn.Open();
|
|---|
| 348 |
|
|---|
| 349 | SqlDataReader reader = command2.ExecuteReader();
|
|---|
| 350 | while (reader.Read())
|
|---|
| 351 | {
|
|---|
| 352 | command.Parameters.AddWithValue("@waluta_brutto", reader.GetValue(0));
|
|---|
| 353 | command.Parameters.AddWithValue("@waluta_miano", reader.GetValue(1));
|
|---|
| 354 | command.Parameters.AddWithValue("@waluta_kurs", reader.GetValue(2));
|
|---|
| 355 | command.Parameters.AddWithValue("@waluta_przelicznik", reader.GetValue(3));
|
|---|
| 356 | command.Parameters.AddWithValue("@waluta_kurs_z_dnia", reader.GetValue(4));
|
|---|
| 357 | command.Parameters.AddWithValue("@waluta_tabela_nr", reader.GetValue(5));
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | conn.Close();
|
|---|
| 361 |
|
|---|
| 362 | conn.Open();
|
|---|
| 363 |
|
|---|
| 364 | transaction = conn.BeginTransaction();
|
|---|
| 365 |
|
|---|
| 366 | command.Transaction = transaction;
|
|---|
| 367 |
|
|---|
| 368 | try
|
|---|
| 369 | {
|
|---|
| 370 | command.ExecuteNonQuery();
|
|---|
| 371 | transaction.Commit();
|
|---|
| 372 | ok = true;
|
|---|
| 373 | }
|
|---|
| 374 | catch (Exception ex)
|
|---|
| 375 | {
|
|---|
| 376 | MessageBox.Show(ex.GetType() + ex.Message);
|
|---|
| 377 |
|
|---|
| 378 | try
|
|---|
| 379 | {
|
|---|
| 380 | transaction.Rollback();
|
|---|
| 381 | }
|
|---|
| 382 | catch (Exception ex2)
|
|---|
| 383 | {
|
|---|
| 384 | MessageBox.Show("ROLLBACK:" + ex2.GetType() + ex2.Message);
|
|---|
| 385 | }
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | conn.Close();
|
|---|
| 389 |
|
|---|
| 390 | //odswiezanie
|
|---|
| 391 |
|
|---|
| 392 | if (ok)
|
|---|
| 393 | {
|
|---|
| 394 | rEKLAMADataSet.REKLAMA.Clear();
|
|---|
| 395 | rEKLAMATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, this.reklamaId);
|
|---|
| 396 | DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 397 |
|
|---|
| 398 | int idFaktury = Convert.ToInt32(row["id_faktury"]);
|
|---|
| 399 | this.fAKTURYTableAdapter.FillByIdFaktury(this.rEKLAMADataSet.FAKTURY, idFaktury);
|
|---|
| 400 |
|
|---|
| 401 | FactureViewer fv = new FactureViewer(idFaktury, false);
|
|---|
| 402 | fv.ShowDialog();
|
|---|
| 403 |
|
|---|
| 404 | this.usunFakture(idFaktury);
|
|---|
| 405 |
|
|---|
| 406 | //odswiezenie reklam
|
|---|
| 407 | rEKLAMADataSet.REKLAMA.Clear();
|
|---|
| 408 | rEKLAMATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, this.reklamaId);
|
|---|
| 409 | row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 410 |
|
|---|
| 411 | //ustawienie pól formularza na dodanie nowej faktury
|
|---|
| 412 |
|
|---|
| 413 | nUMER_ROZTextBox.Text = Utils.tagAgenta(row["SYMBOL AKWIZYTORA"].ToString());
|
|---|
| 414 | nUMERTextBox.Text = Utils.numerNowejFaktury(nUMER_ROZTextBox.Text, DateTime.Today.Year).ToString();
|
|---|
| 415 |
|
|---|
| 416 | if (row["FAKTURA DATA SPRZEDA¯Y"] == DBNull.Value)
|
|---|
| 417 | {
|
|---|
| 418 | dATA_SPRZEDAZYDateTimePicker.Value = DateTime.Today;
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | if (row["FAKTURA DATA WYSTAWIENIA"] == DBNull.Value)
|
|---|
| 422 | {
|
|---|
| 423 | dATA_WYSTAWIENIADateTimePicker.Value = DateTime.Today;
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | if (row["Zaliczka_Data"] == DBNull.Value)
|
|---|
| 427 | {
|
|---|
| 428 | zaliczka_DataDateTimePicker.Value = DateTime.Today;
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | if (row["FAKTURA TERMIN ZAP£ATY"] == DBNull.Value)
|
|---|
| 432 | {
|
|---|
| 433 | tERMIN_ZAPLATYDateTimePicker.Value = DateTime.Today.AddDays(7);
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | //iD_KONTAComboBox.SelectedIndex = 0;
|
|---|
| 437 |
|
|---|
| 438 | sPOSOB_ZAPLATYListBox.SelectedIndex = 1;
|
|---|
| 439 |
|
|---|
| 440 | rEKLAMABindingSource.EndEdit();
|
|---|
| 441 |
|
|---|
| 442 | wystawFaktureButton.Enabled = true;
|
|---|
| 443 | wystawProformeButton.Enabled = true;
|
|---|
| 444 | }
|
|---|
| 445 | }
|
|---|
| 446 |
|
|---|
| 447 | /// <summary>
|
|---|
| 448 | /// Zmiana faktury dla Poznania.
|
|---|
| 449 | /// </summary>
|
|---|
| 450 | private void fakturaPoznan(int idFaktury)
|
|---|
| 451 | {
|
|---|
| 452 |
|
|---|
| 453 | int idSprzedawcy = 6;
|
|---|
| 454 | int idNabywcy = 18845;
|
|---|
| 455 | int idKonta = 43;
|
|---|
| 456 |
|
|---|
| 457 | SqlCommand command = new SqlCommand();
|
|---|
| 458 | command.Connection = new SqlConnection(ConnString.getConnString().Value);
|
|---|
| 459 | command.CommandText = "select Adres_Fkatura from Klienci where CustomerId=18845";
|
|---|
| 460 |
|
|---|
| 461 | command.Connection.Open();
|
|---|
| 462 |
|
|---|
| 463 | string nabywcaAdres = Convert.ToString(command.ExecuteScalar());
|
|---|
| 464 |
|
|---|
| 465 | command.CommandText = "select Nip from KLIENCI where CustomerId=18845";
|
|---|
| 466 |
|
|---|
| 467 | string nabywcaNIP = Convert.ToString(command.ExecuteScalar());
|
|---|
| 468 |
|
|---|
| 469 | command.CommandText = "select Adres_Fk from AGENCJE where Id_agencji = 2";
|
|---|
| 470 |
|
|---|
| 471 | string sprzedawcaAdres = Convert.ToString(command.ExecuteScalar());
|
|---|
| 472 |
|
|---|
| 473 | command.CommandText = "select NIP from AGENCJE where Id_agencji = 2";
|
|---|
| 474 |
|
|---|
| 475 | string sprzedawcaNIP = Convert.ToString(command.ExecuteScalar());
|
|---|
| 476 |
|
|---|
| 477 | command.Connection.Close();
|
|---|
| 478 |
|
|---|
| 479 | command.CommandText = "update faktury set ID_SPRZEDAWCY=@idSprzedawcy, ID_NABYWCY=@idNabywcy," +
|
|---|
| 480 | "NABYWCA_ADRES=@nadres,SPRZEDAWCA_ADRES=@sadres,NABYWCA_NIP=@nnip,SPRZEDAWCA_NIP=@snip," +
|
|---|
| 481 | "ID_KONTA=@idKonta where ID_FAKTURY=@idFaktury";
|
|---|
| 482 |
|
|---|
| 483 | command.Parameters.AddWithValue("@idSprzedawcy", idSprzedawcy);
|
|---|
| 484 | command.Parameters.AddWithValue("@idNabywcy", idNabywcy);
|
|---|
| 485 | command.Parameters.AddWithValue("@nadres", nabywcaAdres);
|
|---|
| 486 | command.Parameters.AddWithValue("@sadres", sprzedawcaAdres);
|
|---|
| 487 | command.Parameters.AddWithValue("@nnip", nabywcaNIP);
|
|---|
| 488 | command.Parameters.AddWithValue("@snip", sprzedawcaNIP);
|
|---|
| 489 | command.Parameters.AddWithValue("@idKonta", idKonta);
|
|---|
| 490 | command.Parameters.AddWithValue("@idFaktury", idFaktury);
|
|---|
| 491 |
|
|---|
| 492 | try
|
|---|
| 493 | {
|
|---|
| 494 | command.Connection.Open();
|
|---|
| 495 | command.ExecuteNonQuery();
|
|---|
| 496 | command.Connection.Close();
|
|---|
| 497 | }
|
|---|
| 498 | catch (Exception e1)
|
|---|
| 499 | {
|
|---|
| 500 | MessageBox.Show(e1.Message);
|
|---|
| 501 | }
|
|---|
| 502 | }
|
|---|
| 503 |
|
|---|
| 504 | /// <summary>
|
|---|
| 505 | /// Zmiana faktury dla Katowic.
|
|---|
| 506 | /// </summary>
|
|---|
| 507 | private void fakturaKatowice(int idFaktury)
|
|---|
| 508 | {
|
|---|
| 509 | int idSprzedawcy = 4;
|
|---|
| 510 | int idNabywcy = 678;
|
|---|
| 511 | int idKonta = 43;
|
|---|
| 512 |
|
|---|
| 513 | SqlCommand command = new SqlCommand();
|
|---|
| 514 | command.Connection = new SqlConnection(ConnString.getConnString().Value);
|
|---|
| 515 | command.CommandText = "select Adres_Fkatura from Klienci where CustomerId=678";
|
|---|
| 516 |
|
|---|
| 517 | command.Connection.Open();
|
|---|
| 518 |
|
|---|
| 519 | string nabywcaAdres = Convert.ToString(command.ExecuteScalar());
|
|---|
| 520 |
|
|---|
| 521 | command.CommandText = "select Nip from KLIENCI where CustomerId=678";
|
|---|
| 522 |
|
|---|
| 523 | string nabywcaNIP = Convert.ToString(command.ExecuteScalar());
|
|---|
| 524 |
|
|---|
| 525 | command.CommandText = "select Adres_Fk from AGENCJE where Id_agencji = 2";
|
|---|
| 526 |
|
|---|
| 527 | string sprzedawcaAdres = Convert.ToString(command.ExecuteScalar());
|
|---|
| 528 |
|
|---|
| 529 | command.CommandText = "select NIP from AGENCJE where Id_agencji = 2";
|
|---|
| 530 |
|
|---|
| 531 | string sprzedawcaNIP = Convert.ToString(command.ExecuteScalar());
|
|---|
| 532 |
|
|---|
| 533 | command.Connection.Close();
|
|---|
| 534 |
|
|---|
| 535 | command.CommandText = "update faktury set ID_SPRZEDAWCY=@idSprzedawcy, ID_NABYWCY=@idNabywcy," +
|
|---|
| 536 | "NABYWCA_ADRES=@nadres,SPRZEDAWCA_ADRES=@sadres,NABYWCA_NIP=@nnip,SPRZEDAWCA_NIP=@snip," +
|
|---|
| 537 | "ID_KONTA=@idKonta where ID_FAKTURY=@idFaktury";
|
|---|
| 538 |
|
|---|
| 539 | command.Parameters.AddWithValue("@idSprzedawcy", idSprzedawcy);
|
|---|
| 540 | command.Parameters.AddWithValue("@idNabywcy", idNabywcy);
|
|---|
| 541 | command.Parameters.AddWithValue("@nadres", nabywcaAdres);
|
|---|
| 542 | command.Parameters.AddWithValue("@sadres", sprzedawcaAdres);
|
|---|
| 543 | command.Parameters.AddWithValue("@nnip", nabywcaNIP);
|
|---|
| 544 | command.Parameters.AddWithValue("@snip", sprzedawcaNIP);
|
|---|
| 545 | command.Parameters.AddWithValue("@idKonta", idKonta);
|
|---|
| 546 | command.Parameters.AddWithValue("@idFaktury", idFaktury);
|
|---|
| 547 |
|
|---|
| 548 | try
|
|---|
| 549 | {
|
|---|
| 550 | command.Connection.Open();
|
|---|
| 551 | command.ExecuteNonQuery();
|
|---|
| 552 | command.Connection.Close();
|
|---|
| 553 | }
|
|---|
| 554 | catch (Exception e1)
|
|---|
| 555 | {
|
|---|
| 556 | MessageBox.Show(e1.Message);
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | private void zamknijButton_Click(object sender, EventArgs e)
|
|---|
| 563 | {
|
|---|
| 564 | fAKTURYBindingSource.CancelEdit();
|
|---|
| 565 | this.DialogResult = DialogResult.Cancel;
|
|---|
| 566 | this.Close();
|
|---|
| 567 | }
|
|---|
| 568 |
|
|---|
| 569 | private void usunButton_Click(object sender, EventArgs e)
|
|---|
| 570 | {
|
|---|
| 571 | if (rEKLAMABindingSource.Current != null)
|
|---|
| 572 | {
|
|---|
| 573 | bool ok = MessageBox.Show("Czyna pewno chcesz usun¹æ fakturê?", "", MessageBoxButtons.YesNo) == DialogResult.Yes ? true : false;
|
|---|
| 574 |
|
|---|
| 575 | if (ok)
|
|---|
| 576 | {
|
|---|
| 577 | DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 578 | int idFaktury = Convert.ToInt32(row["id_faktury"]);
|
|---|
| 579 |
|
|---|
| 580 | this.usunFakture(idFaktury);
|
|---|
| 581 |
|
|---|
| 582 | this.rEKLAMADataSet.REKLAMA.Clear();
|
|---|
| 583 | this.rEKLAMATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, reklamaId);
|
|---|
| 584 | wystawFaktureButton.Enabled = true;
|
|---|
| 585 | wystawProformeButton.Enabled = true;
|
|---|
| 586 | usunButton.Enabled = false;
|
|---|
| 587 | }
|
|---|
| 588 | }
|
|---|
| 589 | }
|
|---|
| 590 |
|
|---|
| 591 | /// <summary>
|
|---|
| 592 | /// Usuwa fakture z tabel: FAKTURA, FAKTURA_DETAILS, REKLAMA (czêsciowo)
|
|---|
| 593 | /// </summary>
|
|---|
| 594 | /// <param name="idFaktury"></param>
|
|---|
| 595 | private void usunFakture(int idFaktury) {
|
|---|
| 596 |
|
|---|
| 597 | SqlConnection conn = new SqlConnection(
|
|---|
| 598 | ConnString.getConnString().Value);
|
|---|
| 599 |
|
|---|
| 600 | //usuwanie faktury
|
|---|
| 601 | SqlCommand command3 = new SqlCommand();
|
|---|
| 602 | command3.CommandText = "delete from faktury where id_faktury = @param ";
|
|---|
| 603 | command3.CommandType = CommandType.Text;
|
|---|
| 604 | command3.Parameters.AddWithValue("@param", idFaktury);
|
|---|
| 605 |
|
|---|
| 606 | command3.Connection = conn;
|
|---|
| 607 |
|
|---|
| 608 | conn.Open();
|
|---|
| 609 |
|
|---|
| 610 | command3.ExecuteNonQuery();
|
|---|
| 611 |
|
|---|
| 612 | conn.Close();
|
|---|
| 613 |
|
|---|
| 614 | //usuwanie pozycji faktury
|
|---|
| 615 | command3 = new SqlCommand();
|
|---|
| 616 | command3.CommandText = "delete from faktura_details where id_faktury = @param ";
|
|---|
| 617 | command3.CommandType = CommandType.Text;
|
|---|
| 618 | command3.Parameters.AddWithValue("@param", idFaktury);
|
|---|
| 619 |
|
|---|
| 620 | command3.Connection = conn;
|
|---|
| 621 |
|
|---|
| 622 | conn.Open();
|
|---|
| 623 |
|
|---|
| 624 | command3.ExecuteNonQuery();
|
|---|
| 625 |
|
|---|
| 626 | conn.Close();
|
|---|
| 627 |
|
|---|
| 628 | //usuniecie informacji o fakturze z tabeli REKLAMA
|
|---|
| 629 | command3.CommandText = "update REKLAMA set ID_FAKTURY = null where ID_FAKTURY = @param ";
|
|---|
| 630 |
|
|---|
| 631 | conn.Open();
|
|---|
| 632 |
|
|---|
| 633 | command3.ExecuteNonQuery();
|
|---|
| 634 |
|
|---|
| 635 | conn.Close();
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 | private void poznanKatowiceButton_Click(object sender, EventArgs e)
|
|---|
| 639 | {
|
|---|
| 640 | DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 641 |
|
|---|
| 642 | // zmiana faktury dla Poznania i Katowic
|
|---|
| 643 | if (row["customerId_Sub"] != DBNull.Value)
|
|---|
| 644 | {
|
|---|
| 645 | if (row["id_faktury"] == DBNull.Value)
|
|---|
| 646 | {
|
|---|
| 647 | MessageBox.Show("Faktura nie zosta³a wystawiona");
|
|---|
| 648 | return;
|
|---|
| 649 | }
|
|---|
| 650 |
|
|---|
| 651 | int idFaktury = Convert.ToInt32(row["id_faktury"]);
|
|---|
| 652 |
|
|---|
| 653 | switch (Convert.ToInt32(row["customerId_Sub"]))
|
|---|
| 654 | {
|
|---|
| 655 | case 678:
|
|---|
| 656 | fakturaKatowice(idFaktury);
|
|---|
| 657 | MessageBox.Show("Faktura zosta³a zmieniona");
|
|---|
| 658 | break;
|
|---|
| 659 | case 18845:
|
|---|
| 660 | fakturaPoznan(idFaktury);
|
|---|
| 661 | MessageBox.Show("Faktura zosta³a zmieniona");
|
|---|
| 662 | break;
|
|---|
| 663 | }
|
|---|
| 664 | }
|
|---|
| 665 | }
|
|---|
| 666 |
|
|---|
| 667 | private void Facturer_Shown(object sender, EventArgs e)
|
|---|
| 668 | {
|
|---|
| 669 |
|
|---|
| 670 | if (!User.getUser().St_kierownik)
|
|---|
| 671 | {
|
|---|
| 672 | foreach (Control c in this.Controls)
|
|---|
| 673 | {
|
|---|
| 674 | c.Enabled = false;
|
|---|
| 675 | }
|
|---|
| 676 | }
|
|---|
| 677 | }
|
|---|
| 678 | }
|
|---|
| 679 | } |
|---|