| 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 | if (User.getUser().IdAgencji == 6)
|
|---|
| 267 | {
|
|---|
| 268 | FactureViewer fv = new FactureViewer(idFaktury);
|
|---|
| 269 | fv.ShowDialog();
|
|---|
| 270 | }
|
|---|
| 271 | else
|
|---|
| 272 | {
|
|---|
| 273 | FactureViewer fv = new FactureViewer(idFaktury, true);
|
|---|
| 274 | fv.ShowDialog();
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | this.Cursor = Cursors.Default;
|
|---|
| 278 |
|
|---|
| 279 | wystawFaktureButton.Enabled = false;
|
|---|
| 280 | wystawProformeButton.Enabled = false;
|
|---|
| 281 | this.DialogResult = DialogResult.OK;
|
|---|
| 282 | this.Close();
|
|---|
| 283 | }
|
|---|
| 284 | else
|
|---|
| 285 | {
|
|---|
| 286 | this.Cursor = Cursors.Default;
|
|---|
| 287 | }
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 | /// <summary>
|
|---|
| 292 | /// Wystawienie proformy polega na wystawieniu faktury i poniejszym usuniêciu jej z bazy...
|
|---|
| 293 | /// </summary>
|
|---|
| 294 | private void wystawProformeButton_Click(object sender, EventArgs e)
|
|---|
| 295 | {
|
|---|
| 296 | bool ok = false;
|
|---|
| 297 |
|
|---|
| 298 | if (iD_KONTAComboBox.SelectedValue == null)
|
|---|
| 299 | {
|
|---|
| 300 | MessageBox.Show("Wybierz konto");
|
|---|
| 301 | return;
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | SqlConnection conn = new SqlConnection(
|
|---|
| 305 | ConnString.getConnString().Value);
|
|---|
| 306 |
|
|---|
| 307 | SqlTransaction transaction;
|
|---|
| 308 |
|
|---|
| 309 | SqlCommand command = new SqlCommand("Proc_Make_Faktura_Waluty", conn);
|
|---|
| 310 | command.CommandType = CommandType.StoredProcedure;
|
|---|
| 311 |
|
|---|
| 312 | command.Parameters.AddWithValue("@ReklamaID", this.reklamaId);
|
|---|
| 313 | command.Parameters.AddWithValue("@FakturaNumer", nUMERTextBox.Text);
|
|---|
| 314 | command.Parameters.AddWithValue("@NumerRoz", nUMER_ROZTextBox.Text);
|
|---|
| 315 |
|
|---|
| 316 | switch (sPOSOB_ZAPLATYListBox.SelectedIndex)
|
|---|
| 317 | {
|
|---|
| 318 | case 1:
|
|---|
| 319 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Przelew");
|
|---|
| 320 | break;
|
|---|
| 321 | case 2:
|
|---|
| 322 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Gotówka");
|
|---|
| 323 | break;
|
|---|
| 324 | case 3:
|
|---|
| 325 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Barter");
|
|---|
| 326 | break;
|
|---|
| 327 | default:
|
|---|
| 328 | command.Parameters.AddWithValue("@FakturaSposobZaplaty", "Karta kredytowa");
|
|---|
| 329 | break;
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | DataRowView r = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 333 |
|
|---|
| 334 | command.Parameters.AddWithValue("@Zaplacono", zAPLACONOCheckBox.Checked);
|
|---|
| 335 | command.Parameters.AddWithValue("@FakturaDataWyst", dATA_WYSTAWIENIADateTimePicker.Value);
|
|---|
| 336 | command.Parameters.AddWithValue("@FakturaDataSprzed", dATA_SPRZEDAZYDateTimePicker.Value);
|
|---|
| 337 | command.Parameters.AddWithValue("@FakturaTerminZaplaty", tERMIN_ZAPLATYDateTimePicker.Value);
|
|---|
| 338 | command.Parameters.AddWithValue("@Konto", iD_KONTAComboBox.SelectedValue);
|
|---|
| 339 | command.Parameters.AddWithValue("@StawkaVat", r["VAT"]);
|
|---|
| 340 |
|
|---|
| 341 | if (zaliczka_BruttoTextBox.Text != "")
|
|---|
| 342 | {
|
|---|
| 343 | command.Parameters.AddWithValue("@Zaliczka_Brutto", r["Zaliczka_Brutto"]);
|
|---|
| 344 | command.Parameters.AddWithValue("@Zaliczka_Data", zaliczka_DataDateTimePicker.Value);
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | command.Parameters.AddWithValue("@wyroznienie", r["wyroznienie"]);
|
|---|
| 348 |
|
|---|
| 349 | SqlCommand command2 = new SqlCommand();
|
|---|
| 350 | command2.Connection = conn;
|
|---|
| 351 | command2.CommandType = CommandType.Text;
|
|---|
| 352 | command2.CommandText = "select Brutto_Euro, Brutto_Euro_Miano, waluta_kurs, waluta_przelicznik,waluta_kurs_z_dnia,waluta_tabela_nr from "
|
|---|
| 353 | + "reklama where reklamaId= " + this.reklamaId;
|
|---|
| 354 |
|
|---|
| 355 | conn.Open();
|
|---|
| 356 |
|
|---|
| 357 | SqlDataReader reader = command2.ExecuteReader();
|
|---|
| 358 | while (reader.Read())
|
|---|
| 359 | {
|
|---|
| 360 | command.Parameters.AddWithValue("@waluta_brutto", reader.GetValue(0));
|
|---|
| 361 | command.Parameters.AddWithValue("@waluta_miano", reader.GetValue(1));
|
|---|
| 362 | command.Parameters.AddWithValue("@waluta_kurs", reader.GetValue(2));
|
|---|
| 363 | command.Parameters.AddWithValue("@waluta_przelicznik", reader.GetValue(3));
|
|---|
| 364 | command.Parameters.AddWithValue("@waluta_kurs_z_dnia", reader.GetValue(4));
|
|---|
| 365 | command.Parameters.AddWithValue("@waluta_tabela_nr", reader.GetValue(5));
|
|---|
| 366 | }
|
|---|
| 367 |
|
|---|
| 368 | conn.Close();
|
|---|
| 369 |
|
|---|
| 370 | conn.Open();
|
|---|
| 371 |
|
|---|
| 372 | transaction = conn.BeginTransaction();
|
|---|
| 373 |
|
|---|
| 374 | command.Transaction = transaction;
|
|---|
| 375 |
|
|---|
| 376 | try
|
|---|
| 377 | {
|
|---|
| 378 | command.ExecuteNonQuery();
|
|---|
| 379 | transaction.Commit();
|
|---|
| 380 | ok = true;
|
|---|
| 381 | }
|
|---|
| 382 | catch (Exception ex)
|
|---|
| 383 | {
|
|---|
| 384 | MessageBox.Show(ex.GetType() + ex.Message);
|
|---|
| 385 |
|
|---|
| 386 | try
|
|---|
| 387 | {
|
|---|
| 388 | transaction.Rollback();
|
|---|
| 389 | }
|
|---|
| 390 | catch (Exception ex2)
|
|---|
| 391 | {
|
|---|
| 392 | MessageBox.Show("ROLLBACK:" + ex2.GetType() + ex2.Message);
|
|---|
| 393 | }
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 | conn.Close();
|
|---|
| 397 |
|
|---|
| 398 | //odswiezanie
|
|---|
| 399 |
|
|---|
| 400 | if (ok)
|
|---|
| 401 | {
|
|---|
| 402 | rEKLAMADataSet.REKLAMA.Clear();
|
|---|
| 403 | rEKLAMATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, this.reklamaId);
|
|---|
| 404 | DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 405 |
|
|---|
| 406 | int idFaktury = Convert.ToInt32(row["id_faktury"]);
|
|---|
| 407 | this.fAKTURYTableAdapter.FillByIdFaktury(this.rEKLAMADataSet.FAKTURY, idFaktury);
|
|---|
| 408 |
|
|---|
| 409 | FactureViewer fv = new FactureViewer(idFaktury, false);
|
|---|
| 410 | fv.ShowDialog();
|
|---|
| 411 |
|
|---|
| 412 | this.usunFakture(idFaktury);
|
|---|
| 413 |
|
|---|
| 414 | //odswiezenie reklam
|
|---|
| 415 | rEKLAMADataSet.REKLAMA.Clear();
|
|---|
| 416 | rEKLAMATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, this.reklamaId);
|
|---|
| 417 | row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 418 |
|
|---|
| 419 | //ustawienie pól formularza na dodanie nowej faktury
|
|---|
| 420 |
|
|---|
| 421 | nUMER_ROZTextBox.Text = Utils.tagAgenta(row["SYMBOL AKWIZYTORA"].ToString());
|
|---|
| 422 | nUMERTextBox.Text = Utils.numerNowejFaktury(nUMER_ROZTextBox.Text, DateTime.Today.Year).ToString();
|
|---|
| 423 |
|
|---|
| 424 | if (row["FAKTURA DATA SPRZEDA¯Y"] == DBNull.Value)
|
|---|
| 425 | {
|
|---|
| 426 | dATA_SPRZEDAZYDateTimePicker.Value = DateTime.Today;
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 | if (row["FAKTURA DATA WYSTAWIENIA"] == DBNull.Value)
|
|---|
| 430 | {
|
|---|
| 431 | dATA_WYSTAWIENIADateTimePicker.Value = DateTime.Today;
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | if (row["Zaliczka_Data"] == DBNull.Value)
|
|---|
| 435 | {
|
|---|
| 436 | zaliczka_DataDateTimePicker.Value = DateTime.Today;
|
|---|
| 437 | }
|
|---|
| 438 |
|
|---|
| 439 | if (row["FAKTURA TERMIN ZAP£ATY"] == DBNull.Value)
|
|---|
| 440 | {
|
|---|
| 441 | tERMIN_ZAPLATYDateTimePicker.Value = DateTime.Today.AddDays(7);
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | //iD_KONTAComboBox.SelectedIndex = 0;
|
|---|
| 445 |
|
|---|
| 446 | sPOSOB_ZAPLATYListBox.SelectedIndex = 1;
|
|---|
| 447 |
|
|---|
| 448 | rEKLAMABindingSource.EndEdit();
|
|---|
| 449 |
|
|---|
| 450 | wystawFaktureButton.Enabled = true;
|
|---|
| 451 | wystawProformeButton.Enabled = true;
|
|---|
| 452 | }
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | /// <summary>
|
|---|
| 456 | /// Zmiana faktury dla Poznania.
|
|---|
| 457 | /// </summary>
|
|---|
| 458 | private void fakturaPoznan(int idFaktury)
|
|---|
| 459 | {
|
|---|
| 460 |
|
|---|
| 461 | int idSprzedawcy = 6;
|
|---|
| 462 | int idNabywcy = 18845;
|
|---|
| 463 | int idKonta = 43;
|
|---|
| 464 |
|
|---|
| 465 | SqlCommand command = new SqlCommand();
|
|---|
| 466 | command.Connection = new SqlConnection(ConnString.getConnString().Value);
|
|---|
| 467 | command.CommandText = "select Adres_Fkatura from Klienci where CustomerId=18845";
|
|---|
| 468 |
|
|---|
| 469 | command.Connection.Open();
|
|---|
| 470 |
|
|---|
| 471 | string nabywcaAdres = Convert.ToString(command.ExecuteScalar());
|
|---|
| 472 |
|
|---|
| 473 | command.CommandText = "select Nip from KLIENCI where CustomerId=18845";
|
|---|
| 474 |
|
|---|
| 475 | string nabywcaNIP = Convert.ToString(command.ExecuteScalar());
|
|---|
| 476 |
|
|---|
| 477 | command.CommandText = "select Adres_Fk from AGENCJE where Id_agencji = 2";
|
|---|
| 478 |
|
|---|
| 479 | string sprzedawcaAdres = Convert.ToString(command.ExecuteScalar());
|
|---|
| 480 |
|
|---|
| 481 | command.CommandText = "select NIP from AGENCJE where Id_agencji = 2";
|
|---|
| 482 |
|
|---|
| 483 | string sprzedawcaNIP = Convert.ToString(command.ExecuteScalar());
|
|---|
| 484 |
|
|---|
| 485 | command.Connection.Close();
|
|---|
| 486 |
|
|---|
| 487 | command.CommandText = "update faktury set ID_SPRZEDAWCY=@idSprzedawcy, ID_NABYWCY=@idNabywcy," +
|
|---|
| 488 | "NABYWCA_ADRES=@nadres,SPRZEDAWCA_ADRES=@sadres,NABYWCA_NIP=@nnip,SPRZEDAWCA_NIP=@snip," +
|
|---|
| 489 | "ID_KONTA=@idKonta where ID_FAKTURY=@idFaktury";
|
|---|
| 490 |
|
|---|
| 491 | command.Parameters.AddWithValue("@idSprzedawcy", idSprzedawcy);
|
|---|
| 492 | command.Parameters.AddWithValue("@idNabywcy", idNabywcy);
|
|---|
| 493 | command.Parameters.AddWithValue("@nadres", nabywcaAdres);
|
|---|
| 494 | command.Parameters.AddWithValue("@sadres", sprzedawcaAdres);
|
|---|
| 495 | command.Parameters.AddWithValue("@nnip", nabywcaNIP);
|
|---|
| 496 | command.Parameters.AddWithValue("@snip", sprzedawcaNIP);
|
|---|
| 497 | command.Parameters.AddWithValue("@idKonta", idKonta);
|
|---|
| 498 | command.Parameters.AddWithValue("@idFaktury", idFaktury);
|
|---|
| 499 |
|
|---|
| 500 | try
|
|---|
| 501 | {
|
|---|
| 502 | command.Connection.Open();
|
|---|
| 503 | command.ExecuteNonQuery();
|
|---|
| 504 | command.Connection.Close();
|
|---|
| 505 | }
|
|---|
| 506 | catch (Exception e1)
|
|---|
| 507 | {
|
|---|
| 508 | MessageBox.Show(e1.Message);
|
|---|
| 509 | }
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | /// <summary>
|
|---|
| 513 | /// Zmiana faktury dla Katowic.
|
|---|
| 514 | /// </summary>
|
|---|
| 515 | private void fakturaKatowice(int idFaktury)
|
|---|
| 516 | {
|
|---|
| 517 | int idSprzedawcy = 4;
|
|---|
| 518 | int idNabywcy = 678;
|
|---|
| 519 | int idKonta = 43;
|
|---|
| 520 |
|
|---|
| 521 | SqlCommand command = new SqlCommand();
|
|---|
| 522 | command.Connection = new SqlConnection(ConnString.getConnString().Value);
|
|---|
| 523 | command.CommandText = "select Adres_Fkatura from Klienci where CustomerId=678";
|
|---|
| 524 |
|
|---|
| 525 | command.Connection.Open();
|
|---|
| 526 |
|
|---|
| 527 | string nabywcaAdres = Convert.ToString(command.ExecuteScalar());
|
|---|
| 528 |
|
|---|
| 529 | command.CommandText = "select Nip from KLIENCI where CustomerId=678";
|
|---|
| 530 |
|
|---|
| 531 | string nabywcaNIP = Convert.ToString(command.ExecuteScalar());
|
|---|
| 532 |
|
|---|
| 533 | command.CommandText = "select Adres_Fk from AGENCJE where Id_agencji = 2";
|
|---|
| 534 |
|
|---|
| 535 | string sprzedawcaAdres = Convert.ToString(command.ExecuteScalar());
|
|---|
| 536 |
|
|---|
| 537 | command.CommandText = "select NIP from AGENCJE where Id_agencji = 2";
|
|---|
| 538 |
|
|---|
| 539 | string sprzedawcaNIP = Convert.ToString(command.ExecuteScalar());
|
|---|
| 540 |
|
|---|
| 541 | command.Connection.Close();
|
|---|
| 542 |
|
|---|
| 543 | command.CommandText = "update faktury set ID_SPRZEDAWCY=@idSprzedawcy, ID_NABYWCY=@idNabywcy," +
|
|---|
| 544 | "NABYWCA_ADRES=@nadres,SPRZEDAWCA_ADRES=@sadres,NABYWCA_NIP=@nnip,SPRZEDAWCA_NIP=@snip," +
|
|---|
| 545 | "ID_KONTA=@idKonta where ID_FAKTURY=@idFaktury";
|
|---|
| 546 |
|
|---|
| 547 | command.Parameters.AddWithValue("@idSprzedawcy", idSprzedawcy);
|
|---|
| 548 | command.Parameters.AddWithValue("@idNabywcy", idNabywcy);
|
|---|
| 549 | command.Parameters.AddWithValue("@nadres", nabywcaAdres);
|
|---|
| 550 | command.Parameters.AddWithValue("@sadres", sprzedawcaAdres);
|
|---|
| 551 | command.Parameters.AddWithValue("@nnip", nabywcaNIP);
|
|---|
| 552 | command.Parameters.AddWithValue("@snip", sprzedawcaNIP);
|
|---|
| 553 | command.Parameters.AddWithValue("@idKonta", idKonta);
|
|---|
| 554 | command.Parameters.AddWithValue("@idFaktury", idFaktury);
|
|---|
| 555 |
|
|---|
| 556 | try
|
|---|
| 557 | {
|
|---|
| 558 | command.Connection.Open();
|
|---|
| 559 | command.ExecuteNonQuery();
|
|---|
| 560 | command.Connection.Close();
|
|---|
| 561 | }
|
|---|
| 562 | catch (Exception e1)
|
|---|
| 563 | {
|
|---|
| 564 | MessageBox.Show(e1.Message);
|
|---|
| 565 | }
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 | }
|
|---|
| 569 |
|
|---|
| 570 | private void zamknijButton_Click(object sender, EventArgs e)
|
|---|
| 571 | {
|
|---|
| 572 | fAKTURYBindingSource.CancelEdit();
|
|---|
| 573 | this.DialogResult = DialogResult.Cancel;
|
|---|
| 574 | this.Close();
|
|---|
| 575 | }
|
|---|
| 576 |
|
|---|
| 577 | private void usunButton_Click(object sender, EventArgs e)
|
|---|
| 578 | {
|
|---|
| 579 | if (rEKLAMABindingSource.Current != null)
|
|---|
| 580 | {
|
|---|
| 581 | bool ok = MessageBox.Show("Czyna pewno chcesz usun¹æ fakturê?", "", MessageBoxButtons.YesNo) == DialogResult.Yes ? true : false;
|
|---|
| 582 |
|
|---|
| 583 | if (ok)
|
|---|
| 584 | {
|
|---|
| 585 | DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 586 | int idFaktury = Convert.ToInt32(row["id_faktury"]);
|
|---|
| 587 |
|
|---|
| 588 | this.usunFakture(idFaktury);
|
|---|
| 589 |
|
|---|
| 590 | this.rEKLAMADataSet.REKLAMA.Clear();
|
|---|
| 591 | this.rEKLAMATableAdapter.FillByReklamaId(this.rEKLAMADataSet.REKLAMA, reklamaId);
|
|---|
| 592 | wystawFaktureButton.Enabled = true;
|
|---|
| 593 | wystawProformeButton.Enabled = true;
|
|---|
| 594 | usunButton.Enabled = false;
|
|---|
| 595 | }
|
|---|
| 596 | }
|
|---|
| 597 | }
|
|---|
| 598 |
|
|---|
| 599 | /// <summary>
|
|---|
| 600 | /// Usuwa fakture z tabel: FAKTURA, FAKTURA_DETAILS, REKLAMA (czêsciowo)
|
|---|
| 601 | /// </summary>
|
|---|
| 602 | /// <param name="idFaktury"></param>
|
|---|
| 603 | private void usunFakture(int idFaktury) {
|
|---|
| 604 |
|
|---|
| 605 | SqlConnection conn = new SqlConnection(
|
|---|
| 606 | ConnString.getConnString().Value);
|
|---|
| 607 |
|
|---|
| 608 | //usuwanie faktury
|
|---|
| 609 | SqlCommand command3 = new SqlCommand();
|
|---|
| 610 | command3.CommandText = "delete from faktury where id_faktury = @param ";
|
|---|
| 611 | command3.CommandType = CommandType.Text;
|
|---|
| 612 | command3.Parameters.AddWithValue("@param", idFaktury);
|
|---|
| 613 |
|
|---|
| 614 | command3.Connection = conn;
|
|---|
| 615 |
|
|---|
| 616 | conn.Open();
|
|---|
| 617 |
|
|---|
| 618 | command3.ExecuteNonQuery();
|
|---|
| 619 |
|
|---|
| 620 | conn.Close();
|
|---|
| 621 |
|
|---|
| 622 | //usuwanie pozycji faktury
|
|---|
| 623 | command3 = new SqlCommand();
|
|---|
| 624 | command3.CommandText = "delete from faktura_details where id_faktury = @param ";
|
|---|
| 625 | command3.CommandType = CommandType.Text;
|
|---|
| 626 | command3.Parameters.AddWithValue("@param", idFaktury);
|
|---|
| 627 |
|
|---|
| 628 | command3.Connection = conn;
|
|---|
| 629 |
|
|---|
| 630 | conn.Open();
|
|---|
| 631 |
|
|---|
| 632 | command3.ExecuteNonQuery();
|
|---|
| 633 |
|
|---|
| 634 | conn.Close();
|
|---|
| 635 |
|
|---|
| 636 | //usuniecie informacji o fakturze z tabeli REKLAMA
|
|---|
| 637 | command3.CommandText = "update REKLAMA set ID_FAKTURY = null where ID_FAKTURY = @param ";
|
|---|
| 638 |
|
|---|
| 639 | conn.Open();
|
|---|
| 640 |
|
|---|
| 641 | command3.ExecuteNonQuery();
|
|---|
| 642 |
|
|---|
| 643 | conn.Close();
|
|---|
| 644 | }
|
|---|
| 645 |
|
|---|
| 646 | private void poznanKatowiceButton_Click(object sender, EventArgs e)
|
|---|
| 647 | {
|
|---|
| 648 | DataRowView row = (DataRowView)rEKLAMABindingSource.Current;
|
|---|
| 649 |
|
|---|
| 650 | // zmiana faktury dla Poznania i Katowic
|
|---|
| 651 | if (row["customerId_Sub"] != DBNull.Value)
|
|---|
| 652 | {
|
|---|
| 653 | if (row["id_faktury"] == DBNull.Value)
|
|---|
| 654 | {
|
|---|
| 655 | MessageBox.Show("Faktura nie zosta³a wystawiona");
|
|---|
| 656 | return;
|
|---|
| 657 | }
|
|---|
| 658 |
|
|---|
| 659 | int idFaktury = Convert.ToInt32(row["id_faktury"]);
|
|---|
| 660 |
|
|---|
| 661 | switch (Convert.ToInt32(row["customerId_Sub"]))
|
|---|
| 662 | {
|
|---|
| 663 | case 678:
|
|---|
| 664 | fakturaKatowice(idFaktury);
|
|---|
| 665 | MessageBox.Show("Faktura zosta³a zmieniona");
|
|---|
| 666 | break;
|
|---|
| 667 | case 18845:
|
|---|
| 668 | fakturaPoznan(idFaktury);
|
|---|
| 669 | MessageBox.Show("Faktura zosta³a zmieniona");
|
|---|
| 670 | break;
|
|---|
| 671 | }
|
|---|
| 672 | }
|
|---|
| 673 | }
|
|---|
| 674 |
|
|---|
| 675 | private void Facturer_Shown(object sender, EventArgs e)
|
|---|
| 676 | {
|
|---|
| 677 |
|
|---|
| 678 | if (!User.getUser().St_kierownik)
|
|---|
| 679 | {
|
|---|
| 680 | foreach (Control c in this.Controls)
|
|---|
| 681 | {
|
|---|
| 682 | c.Enabled = false;
|
|---|
| 683 | }
|
|---|
| 684 | }
|
|---|
| 685 | }
|
|---|
| 686 | }
|
|---|
| 687 | } |
|---|