public Window_Add_Client(kontrahent k) { InitializeComponent(); _type = "Modyfication"; _k = k; Button_Add_New_Client.Text = "Zmień"; Add_Client_Information(); }
private void Add_New_Client() { var Adress = new adres(); var kontrahent = new kontrahent(); Boolean flag = false; using (zlecenieEntities db = new zlecenieEntities()) { try { kontrahent.Imie = textBox_Name.Text.ToString(); kontrahent.Nazwisko = textBox_Lastname.Text.ToString(); if (textBox_PESEL.Text == "") { kontrahent.Pesel = null; } else { kontrahent.Pesel = System.Convert.ToInt64(textBox_PESEL.Text); } if (textBox_NIP.Text == "") { kontrahent.NIP = null; } else { kontrahent.NIP = System.Convert.ToInt64(textBox_NIP.Text); } kontrahent.Nazwa_Firmy = textBox_Company_Name.Text.ToString(); Adress.Miasto = textBox_Adress_Town_Name.Text; Adress.Nazwa_ulicy = textBox_Street_Name.Text; Adress.Kod_pocztowy = textBox_Code_1.Text + textBox_Code_2.Text; Adress.Numer_budynku = textBox_Building_Number.Text; Adress.Numer_mieszkania = textBox_Home_Number.Text; Adress.Państwo = comboBox_Country_ID.Text; db.adres.AddOrUpdate(Adress); db.SaveChanges(); kontrahent.E_mail = textBox_Email_Adress.Text.ToString(); kontrahent.Telefon_1 = textBox_Phone_Number_1.Text.ToString(); kontrahent.Telefon_2 = textBox_Phone_Number_2.Text.ToString(); kontrahent.Adres = Adress.ID; flag = true; } catch (Exception) { MessageBox.Show("Podano nieprawidłowy numer NIP lub PESEL", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); flag = false; } if (flag == true) { db.kontrahent.Add(kontrahent); db.SaveChanges(); MessageBox.Show("Kontrahent dodany", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void button_Add_New_Address_Click(object sender, EventArgs e) { var Adress = new adres(); var kontrahent = new kontrahent(); Boolean flag = false; using (zlecenieEntities db = new zlecenieEntities()) { try { kontrahent.Imie = textBox_imie.Text.ToString(); kontrahent.Nazwisko = textBox_nazwisko.Text.ToString(); if (textBox_pesel.Text == "") { kontrahent.Pesel = null; } else { kontrahent.Pesel = System.Convert.ToInt64(textBox_pesel.Text); } if (textBox_nip.Text == "") { kontrahent.NIP = null; } else { kontrahent.NIP = System.Convert.ToInt64(textBox_nip.Text); } kontrahent.Nazwa_Firmy = textBox_firma.Text.ToString(); Adress.Miasto = textBox_town.Text; Adress.Nazwa_ulicy = textBox_street.Text; Adress.Kod_pocztowy = textBox_kod_1.Text + textBox_kod_2.Text; Adress.Numer_budynku = textBox_building.Text; Adress.Numer_mieszkania = textBox_home.Text; Adress.Państwo = comboBox1.Text; db.adres.Add(Adress); db.SaveChanges(); kontrahent.E_mail = textBox_email.Text.ToString(); kontrahent.Telefon_1 = textBox_tel.Text.ToString(); kontrahent.Telefon_2 = textBox_tel2.Text.ToString(); kontrahent.Adres = Adress.ID; flag = true; } catch (Exception) { MessageBox.Show("Podano nieprawidłowy numer NIP lub PESEL", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); flag = false; } if (flag == true) { db.kontrahent.Add(kontrahent); db.SaveChanges(); MessageBox.Show("Kontrahent dodany", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
} // Modify Offer information private void Button_Modify_Client_Click(object sender, EventArgs e) { using (zlecenieEntities db = new zlecenieEntities()) { try { int ID = cW.getSelectedClient(); if (ID != 0) { kontrahent mc = db.kontrahent.Find(ID); OpenChildForm(new Window_Add_Client(mc)); } } catch { } } } // Modify Client information
} // Update dataGrid net and gross price value after enter new quantity value private void Button_chose_Client_Click(object sender, EventArgs e) { try { using (zlecenieEntities db = new zlecenieEntities()) { kontrahent k = new kontrahent(); Window_Choice_Client_For_Offer window_Choice_Client = new Window_Choice_Client_For_Offer(k); window_Choice_Client.ShowDialog(); client_id = k.ID; k = db.kontrahent.Find(k.ID); adres a = new adres(); a = db.adres.Find(k.Adres); textBox_Offer_Name.Text = k.Imie.ToString(); textBox_Offer_LastName.Text = k.Nazwisko.ToString(); textBox_Offer_CompanyName.Text = k.Nazwa_Firmy.ToString(); } } catch { } } // Add information about Client to Offer Form
} // Update dataGrid net and gross price value after enter new quantity value private void Button_chose_Client_Click(object sender, EventArgs e) { using (zlecenieEntities db = new zlecenieEntities()) { kontrahent k = new kontrahent(); Window_Choice_Client_For_Offer window_Choice_Client = new Window_Choice_Client_For_Offer(k); window_Choice_Client.ShowDialog(); client_id = k.ID; k = db.kontrahent.Find(k.ID); adres a = new adres(); a = db.adres.Find(k.Adres); textBox_Offer_Name.Text = k.Imie.ToString(); textBox_Offer_LastName.Text = k.Nazwisko.ToString(); textBox_Offer_CompanyName.Text = k.Nazwa_Firmy.ToString(); textBox_Town_Name.Text = a.Miasto.ToString(); textBox_Post_Code_1.Text = a.Kod_pocztowy.ToString().Remove(2, 3); textBox_Post_Code_2.Text = a.Kod_pocztowy.ToString().Remove(0, 2); textBox_Street_Name.Text = a.Nazwa_ulicy.ToString(); textBox_Building_Number.Text = a.Numer_budynku.ToString(); textBox_Home_Number.Text = a.Numer_mieszkania.ToString(); textBox_Country_ID.Text = a.Państwo.ToString(); } } // Add information about Client to Offer Form
public Window_Choice_Client_For_Offer(kontrahent k) { InitializeComponent(); Client_List_Update(); _k = k; }