private void button1_Click(object sender, EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; using (zlecenieEntities db = new zlecenieEntities()) { string login = textBox1.Text.ToLower(); string password = textBox2.Text; Dane_Logowania dane_Logowania = new Dane_Logowania(); dane_Logowania = db.Dane_Logowania.Find(login.ToLower()); if (login == "" && password == "") { MessageBox.Show("Wypełnij pola Hasło i Login", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (login == "") { MessageBox.Show("Wypełnij pole Login", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (password == "") { MessageBox.Show("Wypełnij pole Hasło", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { if (dane_Logowania.Login.ToLower() == login && dane_Logowania.Hasło == password) { Close(); } else { MessageBox.Show("Błędne dane", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Błędne dane", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } Cursor.Current = Cursors.Default; } catch { MessageBox.Show("Brak połączenia z serwerem", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void Modify() { produkt produkt = new produkt(); Boolean flag = false; try { produkt.ID = _p.ID; produkt.Nazwa = textBox_Product_Name.Text.ToString(); produkt.Producent = textBox_Manufacturer.Text.ToString(); produkt.Numer_katalogowy = textBox_Catalog.Text.ToString(); produkt.Vat = System.Convert.ToDouble(ComboBox_Taxes.Text); produkt.Cena_brutto = System.Convert.ToDecimal(textBox_Price_Gross.Text); produkt.Kategoria = (int)comboBox_Product_Category.SelectedValue; produkt.Status = (int)comboBox_Product_Status.SelectedValue; try { produkt.Ilość = System.Convert.ToDouble(textBox_Quantity.Text); produkt.Jm = comboBox_Unit.Text.ToString(); try { produkt.Cena_netto = System.Convert.ToDecimal(textBox_Price_Net.Text); flag = true; } catch { MessageBox.Show("Cena musi być liczbą", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch { MessageBox.Show("Ilość musi być liczbą", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception) { MessageBox.Show("Wypełnij wszystkie dane", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); flag = false; } if (flag == true) { using (zlecenieEntities db = new zlecenieEntities()) { db.produkt.AddOrUpdate(produkt); db.SaveChanges(); MessageBox.Show("Produkt zmodyfikowany", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void Client_List_Update() { Cursor.Current = Cursors.WaitCursor; using (zlecenieEntities db = new zlecenieEntities()) { try { Client_list.Items.Clear(); List <kontrahent> list = db.kontrahent.ToList(); foreach (kontrahent C in list.Where(lvi => lvi.Nazwa_Firmy.ToLower().Contains(textBox4.Text.ToLower()) && lvi.Nazwisko.ToLower().Contains(textBox5.Text.ToLower()) && lvi.ID.ToString().ToLower().Contains(textBox6.Text.ToLower()))) { ListViewItem item = new ListViewItem(C.ID.ToString()); item.SubItems.Add(C.Imie); item.SubItems.Add(C.Nazwisko); item.SubItems.Add(C.Pesel.ToString()); item.SubItems.Add(C.NIP.ToString()); item.SubItems.Add(C.Nazwa_Firmy); if (C.Adres != 0) { adres Client_Adress = new adres(); Client_Adress = db.adres.Find(C.Adres); if (Client_Adress.Numer_mieszkania == null) { item.SubItems.Add(Client_Adress.Miasto.ToString() + " " + Client_Adress.Kod_pocztowy.ToString().Remove(2, 3) + "-" + Client_Adress.Kod_pocztowy.ToString().Remove(0, 2) + ", " + Client_Adress.Nazwa_ulicy.ToString() + " " + Client_Adress.Numer_budynku.ToString() + " " + Client_Adress.Państwo.ToString()); } else { item.SubItems.Add(Client_Adress.Miasto.ToString() + " " + Client_Adress.Kod_pocztowy.ToString().Remove(2, 3) + "-" + Client_Adress.Kod_pocztowy.ToString().Remove(0, 2) + ", " + Client_Adress.Nazwa_ulicy.ToString() + " " + Client_Adress.Numer_budynku.ToString() + "/" + Client_Adress.Numer_mieszkania.ToString() + " " + Client_Adress.Państwo.ToString()); } } item.SubItems.Add(C.E_mail); item.SubItems.Add(C.Telefon_1.ToString()); item.SubItems.Add(C.Telefon_2.ToString()); item.Font = new Font(item.Font, FontStyle.Regular); Client_list.Items.Add(item); } } catch (Exception e) { MessageBox.Show(e.Message); } } Cursor.Current = Cursors.Default; } // Add Clients information from DB to listView
} // Add Clients information from DB to listView private void textBox_client_company_search_TextChanged(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; using (zlecenieEntities db = new zlecenieEntities()) { try { Client_list.Items.Clear(); List <kontrahent> list = db.kontrahent.ToList(); foreach (kontrahent C in list.Where(lvi => lvi.Nazwa_Firmy.ToLower().Contains(textBox_client_company_search.Text.ToLower()) && lvi.Nazwisko.ToLower().Contains(textBox_client_name_search.Text.ToLower()) && lvi.ID.ToString().ToLower().Contains(textBox_client_id_search.Text.ToLower()))) { ListViewItem item = new ListViewItem(C.ID.ToString()); item.SubItems.Add(C.Imie); item.SubItems.Add(C.Nazwisko); item.SubItems.Add(C.Pesel.ToString()); item.SubItems.Add(C.NIP.ToString()); item.SubItems.Add(C.Nazwa_Firmy); if (C.Adres != 0) { adres Client_Adress = new adres(); Client_Adress = db.adres.Find(C.Adres); if (Client_Adress.Numer_mieszkania == null) { item.SubItems.Add(Client_Adress.Miasto.ToString() + " " + Client_Adress.Kod_pocztowy.ToString().Remove(2, 3) + "-" + Client_Adress.Kod_pocztowy.ToString().Remove(0, 2) + ", " + Client_Adress.Nazwa_ulicy.ToString() + " " + Client_Adress.Numer_budynku.ToString() + " " + Client_Adress.Państwo.ToString()); } else { item.SubItems.Add(Client_Adress.Miasto.ToString() + " " + Client_Adress.Kod_pocztowy.ToString().Remove(2, 3) + "-" + Client_Adress.Kod_pocztowy.ToString().Remove(0, 2) + ", " + Client_Adress.Nazwa_ulicy.ToString() + " " + Client_Adress.Numer_budynku.ToString() + "/" + Client_Adress.Numer_mieszkania.ToString() + " " + Client_Adress.Państwo.ToString()); } } item.SubItems.Add(C.E_mail); item.SubItems.Add(C.Telefon_1.ToString()); item.SubItems.Add(C.Telefon_2.ToString()); item.Font = new Font(item.Font, FontStyle.Regular); Client_list.Items.Add(item); } } catch (Exception) { } } Cursor.Current = Cursors.Default; } // Search and fill list by input
} // 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
} // Modify Product information private void button_Modify_Offer_Click(object sender, EventArgs e) { using (zlecenieEntities db = new zlecenieEntities()) { try { int ID = ofW.getSelectedOffer(); if (ID != 0) { oferta mof = db.oferta.Find(ID); OpenChildForm(new Window_Add_Offer(mof)); } } catch { } } } // Modify Offer information
} // Open New Client Window #endregion #region buttons_modify private void button_Modify_Product_Click(object sender, EventArgs e) { using (zlecenieEntities db = new zlecenieEntities()) { try { int ID = pW.getSelectedProduct(); if (ID != 0) { produkt pm = db.produkt.Find(ID); OpenChildForm(new Window_Add_Product(pm)); } } catch { } } } // Modify Product information
} // Modify Client information private void button_Modify_Order_Info_Click(object sender, EventArgs e) { using (zlecenieEntities db = new zlecenieEntities()) { try { int ID = oW.getSelectedProduct(); if (ID != 0) { zlecenie mo = db.zlecenie.Find(ID); OpenChildForm(new Window_Add_Order(mo)); } } catch (Exception f) { } } } // Modify Order information
private void Modify_Client_Info() { kontrahent kontrahent = new kontrahent(); adres Adress = new adres(); Boolean flag = true; using (zlecenieEntities db = new zlecenieEntities()) { try { kontrahent.ID = _k.ID; kontrahent.Imie = textBox_Name.Text; kontrahent.Nazwisko = textBox_Lastname.Text; kontrahent.NIP = System.Convert.ToInt64(textBox_NIP.Text); kontrahent.Pesel = System.Convert.ToInt64(textBox_PESEL.Text); kontrahent.Nazwa_Firmy = textBox_Company_Name.Text; 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; kontrahent.Telefon_1 = textBox_Phone_Number_1.Text; kontrahent.Telefon_2 = textBox_Phone_Number_2.Text; 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.AddOrUpdate(kontrahent); db.SaveChanges(); MessageBox.Show("Dane kontrahenta zmienione", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
} // Delete product from Datagrid void Save_Order() { using (zlecenieEntities db = new zlecenieEntities()) { Cursor.Current = Cursors.WaitCursor; zlecenie new_order = new zlecenie(); try { new_order.Nazwa = textBox_O_Name.Text; new_order.Kontrahent = client_id; new_order.Data_od = dateTimePicker1.Value; new_order.Data_do = dateTimePicker2.Value; new_order.Adres_zlecenia = db.adres.Find(a.ID).ID; new_order.Opis = Order_Information_Box.Text; new_order.Status_zlecenia = 1; db.zlecenie.Add(new_order); db.SaveChanges(); /*foreach (DataGridViewRow row in dataGridView1.Rows) * { * produkty_w_wycenie produkty_W_Wycenie = new produkty_w_wycenie(); * produkty_W_Wycenie.ID_zlecenie = new_order.ID; * produkty_W_Wycenie.ID_produktu = System.Convert.ToInt32(row.Cells[0].Value); * produkty_W_Wycenie.ilość = System.Convert.ToDecimal(row.Cells[4].Value); * produkty_W_Wycenie.Marża = System.Convert.ToInt32(row.Cells[5].Value); * produkty_W_Wycenie.Zysk_netto = System.Convert.ToDecimal(row.Cells[11].Value); * decimal actual_price = Convert.ToDecimal(row.Cells[6].Value.ToString().Trim(' ', 'z', 'ł')); * produkty_W_Wycenie.Aktualna_cena_netto = actual_price; * db.produkty_w_wycenie.Add(produkty_W_Wycenie); * db.SaveChanges(); * }*/ Cursor.Current = Cursors.Default; MessageBox.Show("Zlecenie utworzone", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception f) { MessageBox.Show(f.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); //MessageBox.Show("Błąd zapisu", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } // Save new offer
private void button_PStatus_withdrawn_Click(object sender, EventArgs e) { using (zlecenieEntities db = new zlecenieEntities()) { try { int ID = pW.getSelectedProduct(); if (ID != 0) { produkt pm = db.produkt.Find(ID); pm.Status = 2; db.SaveChanges(); pW = new Product_Window(); OpenChildForm(pW); } } catch { } } }
private void button_Ostatus_Refused_Click(object sender, EventArgs e) { using (zlecenieEntities db = new zlecenieEntities()) { try { int ID = ofW.getSelectedOffer(); if (ID != 0) { oferta of = db.oferta.Find(ID); of.Status = 4; db.SaveChanges(); ofW = new Offer_Window(); OpenChildForm(ofW); } } catch { } } }
private void Add_Offer_Information() { using (zlecenieEntities db = new zlecenieEntities()) { textBox_O_Name.Text = _o.Nazwa; textBox_Offer_Name.Text = db.kontrahent.Find(_o.Id_zleceniodawca).Imie; textBox_Offer_LastName.Text = db.kontrahent.Find(_o.Id_zleceniodawca).Nazwisko; textBox_Offer_CompanyName.Text = db.kontrahent.Find(_o.Id_zleceniodawca).Nazwa_Firmy; textBox_Town_Name.Text = db.adres.Find(db.kontrahent.Find(_o.Id_zleceniodawca).Adres).Miasto; textBox_Post_Code_1.Text = (db.adres.Find(db.kontrahent.Find(_o.Id_zleceniodawca).Adres).Kod_pocztowy).Remove(2, 3); textBox_Post_Code_2.Text = (db.adres.Find(db.kontrahent.Find(_o.Id_zleceniodawca).Adres).Kod_pocztowy).Remove(0, 2); textBox_Street_Name.Text = db.adres.Find(db.kontrahent.Find(_o.Id_zleceniodawca).Adres).Nazwa_ulicy; textBox_Building_Number.Text = db.adres.Find(db.kontrahent.Find(_o.Id_zleceniodawca).Adres).Numer_budynku; textBox_Home_Number.Text = db.adres.Find(db.kontrahent.Find(_o.Id_zleceniodawca).Adres).Numer_mieszkania; textBox_Country_ID.Text = db.adres.Find(db.kontrahent.Find(_o.Id_zleceniodawca).Adres).Państwo; Offer_Information_Box.Text = _o.Opis; dateTimePicker1.Value = _o.Data_Od.Date; dateTimePicker2.Value = _o.Data_Do.Date; List <produkty_w_wycenie> list = db.produkty_w_wycenie.ToList(); foreach (produkty_w_wycenie produkty_W_Wycenie in list.Where(id => id.ID_zlecenie == _o.ID)) { DataGridViewRow item_grid = new DataGridViewRow(); item_grid.CreateCells(dataGridView1); item_grid.Cells[0].Value = db.produkt.Find(produkty_W_Wycenie.ID_produktu).ID; item_grid.Cells[1].Value = db.produkt.Find(produkty_W_Wycenie.ID_produktu).Nazwa; item_grid.Cells[2].Value = db.produkt.Find(produkty_W_Wycenie.ID_produktu).Producent; item_grid.Cells[3].Value = db.produkt.Find(produkty_W_Wycenie.ID_produktu).Jm; item_grid.Cells[4].Value = produkty_W_Wycenie.ilość; item_grid.Cells[5].Value = produkty_W_Wycenie.Marża; item_grid.Cells[6].Value = produkty_W_Wycenie.Aktualna_cena_netto; item_grid.Cells[7].Value = produkty_W_Wycenie.Aktualna_cena_netto; item_grid.Cells[8].Value = db.produkt.Find(produkty_W_Wycenie.ID_produktu).Vat + " %"; item_grid.Cells[9].Value = Math.Round(db.produkt.Find(produkty_W_Wycenie.ID_produktu).Cena_brutto, 2); item_grid.Cells[10].Value = db.kategoria_produktu.Find(db.produkt.Find(produkty_W_Wycenie.ID_produktu).Kategoria).Nazwa_kategorii; item_grid.Cells[11].Value = produkty_W_Wycenie.Zysk_netto; dataGridView1.Rows.Add(item_grid); } } } // Fill offer window with information about actual offer
} // Delete product from Datagrid void Save_Offer() { using (zlecenieEntities db = new zlecenieEntities()) { Cursor.Current = Cursors.WaitCursor; oferta new_offer = new oferta(); try { new_offer.Nazwa = textBox_O_Name.Text; new_offer.Id_zleceniodawca = client_id; new_offer.Data_Od = dateTimePicker1.Value; new_offer.Data_Do = dateTimePicker2.Value; new_offer.Opis = Offer_Information_Box.Text; new_offer.Status = 1; db.oferta.AddOrUpdate(new_offer); db.SaveChanges(); foreach (DataGridViewRow row in dataGridView1.Rows) { produkty_w_wycenie produkty_W_Wycenie = new produkty_w_wycenie(); produkty_W_Wycenie.ID_zlecenie = new_offer.ID; produkty_W_Wycenie.ID_produktu = System.Convert.ToInt32(row.Cells[0].Value); produkty_W_Wycenie.ilość = System.Convert.ToDecimal(row.Cells[4].Value); produkty_W_Wycenie.Marża = System.Convert.ToInt32(row.Cells[5].Value); produkty_W_Wycenie.Zysk_netto = System.Convert.ToDecimal(row.Cells[11].Value); decimal actual_price = Convert.ToDecimal(row.Cells[6].Value.ToString().Trim(' ', 'z', 'ł')); produkty_W_Wycenie.Aktualna_cena_netto = actual_price; db.produkty_w_wycenie.Add(produkty_W_Wycenie); db.SaveChanges(); } Cursor.Current = Cursors.Default; MessageBox.Show("Oferta utworzona", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception f) { MessageBox.Show(f.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); //MessageBox.Show("Błąd zapisu", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } // Save new offer
} // Search and fill list by input private void Offer_list_SelectedIndexChanged_1(object sender, EventArgs e) { using (zlecenieEntities db = new zlecenieEntities()) { try { Position_In_Offer_ListView.Items.Clear(); string id_offer = Offer_list.SelectedItems[0].Text; List <produkty_w_wycenie> list = db.produkty_w_wycenie.ToList(); foreach (produkty_w_wycenie p in list.Where(id => id.ID_zlecenie.ToString() == id_offer)) { ListViewItem item = new ListViewItem(p.ID_produktu.ToString()); item.SubItems.Add(db.produkt.Find(p.ID_produktu).Nazwa); item.SubItems.Add(db.produkt.Find(p.ID_produktu).Producent); item.SubItems.Add(db.produkt.Find(p.ID_produktu).Numer_katalogowy); item.SubItems.Add(db.produkt.Find(p.ID_produktu).Jm); decimal ilość = p.ilość; item.SubItems.Add(ilość.ToString()); decimal margin = p.Marża; decimal netto = p.Aktualna_cena_netto; decimal price_w_margin = Math.Round((netto * ilość) + (netto * ilość * margin / 100), 2); item.SubItems.Add(price_w_margin.ToString() + " zł"); decimal vat = System.Convert.ToDecimal(db.produkt.Find(p.ID_produktu).Vat); item.SubItems.Add(vat.ToString() + "%"); decimal brutto = Math.Round(price_w_margin + (price_w_margin * (vat / 100)), 2); item.SubItems.Add(brutto.ToString() + " zł"); item.SubItems.Add(db.kategoria_produktu.Find(db.produkt.Find(p.ID_produktu).Kategoria).Nazwa_kategorii); item.SubItems.Add(Math.Round(ilość * price_w_margin, 2).ToString() + " zł"); item.SubItems.Add(Math.Round(ilość * brutto, 2).ToString() + " zł"); item.Font = new Font(item.Font, FontStyle.Regular); Position_In_Offer_ListView.Items.Add(item); } Calculate_tax_price(); } catch (Exception) { } } } // Fill actual Offer products list
} // 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
private void button_Add_New_Address_Click(object sender, EventArgs e) { var Address = new adres(); Boolean flag = false; using (zlecenieEntities db = new zlecenieEntities()) { try { Address.Miasto = textBox_town.Text; Address.Nazwa_ulicy = textBox_street.Text; if (textBox_kod_1.TextLength == 2 && textBox_kod_2.TextLength == 3) { Address.Kod_pocztowy = textBox_kod_1.Text + textBox_kod_2.Text; Address.Numer_budynku = textBox_building.Text; Address.Numer_mieszkania = textBox_home.Text; Address.Państwo = comboBox1.Text; flag = true; } else { MessageBox.Show("Błąd dla kodu pocztowego", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { MessageBox.Show("Wypełnij wszystkie dane", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); flag = false; } if (flag == true) { db.adres.Add(Address); db.SaveChanges(); MessageBox.Show("Adres dodany", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); Address_List_Update(); } } }
} // 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
void Add_Client_Information() { using (zlecenieEntities db = new zlecenieEntities()) { adres adres = new adres(); textBox_Name.Text = _k.Imie.ToString(); textBox_Lastname.Text = _k.Nazwisko.ToString(); textBox_PESEL.Text = _k.Pesel.ToString(); textBox_NIP.Text = _k.NIP.ToString(); adres = db.adres.Find(_k.Adres); textBox_Adress_Town_Name.Text = adres.Miasto.ToString(); textBox_Street_Name.Text = adres.Nazwa_ulicy.ToString(); textBox_Code_1.Text = adres.Kod_pocztowy.ToString().Remove(2, 3); textBox_Code_2.Text = adres.Kod_pocztowy.ToString().Remove(0, 2); textBox_Building_Number.Text = adres.Numer_budynku.ToString(); textBox_Home_Number.Text = adres.Numer_mieszkania.ToString(); comboBox_Country_ID.Text = adres.Państwo.ToString(); textBox_Company_Name.Text = _k.Nazwa_Firmy.ToString(); textBox_Email_Adress.Text = _k.E_mail.ToString(); textBox_Phone_Number_1.Text = _k.Telefon_1.ToString(); textBox_Phone_Number_2.Text = _k.Telefon_2.ToString(); } }
void list_search(Boolean active_products) { if (active_products == true) { Cursor.Current = Cursors.WaitCursor; using (zlecenieEntities db = new zlecenieEntities()) { Products_list.Items.Clear(); List <produkt> list = db.produkt.ToList(); foreach (produkt p in list.Where(lvi => lvi.Nazwa.ToLower().Contains(textBox_product_name_search.Text.ToLower()) && lvi.Producent.ToLower().Contains(textBox_product_producent_search.Text.ToLower()) && lvi.Numer_katalogowy.ToLower().Contains(textBox_product_symbol_search.Text.ToLower()))) { decimal value = Math.Round(p.Cena_netto * System.Convert.ToDecimal(p.Ilość), 2); ListViewItem item = new ListViewItem(p.ID.ToString()); item.SubItems.Add(p.Nazwa); item.SubItems.Add(p.Producent); item.SubItems.Add(p.Numer_katalogowy); item.SubItems.Add(p.Jm); item.SubItems.Add(p.Ilość.ToString()); item.SubItems.Add(p.Cena_netto.ToString() + " zł"); item.SubItems.Add(p.Vat.ToString() + " %"); item.SubItems.Add(p.Cena_brutto.ToString() + " zł"); if (p.Kategoria != 0) { kategoria_produktu product_cat = new kategoria_produktu(); product_cat = db.kategoria_produktu.Find(p.Kategoria); item.SubItems.Add(product_cat.Nazwa_kategorii.ToString()); } item.SubItems.Add(value.ToString() + " zł"); item.SubItems.Add(db.statusy_produktów.Find(p.Status).Status.ToString()); item.Font = new Font(item.Font, FontStyle.Regular); Products_list.Items.Add(item); } } Cursor.Current = Cursors.Default; } if (active_products == false) { Cursor.Current = Cursors.WaitCursor; using (zlecenieEntities db = new zlecenieEntities()) { Products_list.Items.Clear(); List <produkt> list = db.produkt.ToList(); foreach (produkt p in list.Where(lvi => lvi.Nazwa.ToLower().Contains(textBox_product_name_search.Text.ToLower()) && lvi.Producent.ToLower().Contains(textBox_product_producent_search.Text.ToLower()) && lvi.Numer_katalogowy.ToLower().Contains(textBox_product_symbol_search.Text.ToLower()) && lvi.Status.ToString().Contains("1"))) { decimal value = Math.Round(p.Cena_netto * System.Convert.ToDecimal(p.Ilość), 2); ListViewItem item = new ListViewItem(p.ID.ToString()); item.SubItems.Add(p.Nazwa); item.SubItems.Add(p.Producent); item.SubItems.Add(p.Numer_katalogowy); item.SubItems.Add(p.Jm); item.SubItems.Add(p.Ilość.ToString()); item.SubItems.Add(p.Cena_netto.ToString() + " zł"); item.SubItems.Add(p.Vat.ToString() + " %"); item.SubItems.Add(p.Cena_brutto.ToString() + " zł"); if (p.Kategoria != 0) { kategoria_produktu product_cat = new kategoria_produktu(); product_cat = db.kategoria_produktu.Find(p.Kategoria); item.SubItems.Add(product_cat.Nazwa_kategorii.ToString()); } item.SubItems.Add(value.ToString() + " zł"); item.SubItems.Add(db.statusy_produktów.Find(p.Status).Status.ToString()); item.Font = new Font(item.Font, FontStyle.Regular); Products_list.Items.Add(item); } } Cursor.Current = Cursors.Default; } }
} // Add information about Client to Offer Form private void button2_Click(object sender, EventArgs e) { PdfPCell getCell(String text, int alignment) { string ss = @"C:\Windows\Fonts\micross.ttf"; BaseFont aa = BaseFont.CreateFont(ss, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); iTextSharp.text.Font bb = new iTextSharp.text.Font(aa, 8, iTextSharp.text.Font.NORMAL); PdfPCell cell = new PdfPCell(new Phrase(text, bb)); cell.Padding = (0); cell.HorizontalAlignment = alignment; cell.Border = PdfPCell.NO_BORDER; return(cell); } string My_Info = ""; string Client_info = ""; using (zlecenieEntities db = new zlecenieEntities()) { int My_ID = 20; int Client_ID = _o.ID; if (_o != null) { Client_ID = _o.Id_zleceniodawca; } else { Client_ID = client_id; } My_Info = db.kontrahent.Find(My_ID).Imie + " " + db.kontrahent.Find(My_ID).Nazwisko + "\n" + db.kontrahent.Find(My_ID).Nazwa_Firmy + "\nul. " + db.adres.Find(db.kontrahent.Find(My_ID).Adres).Nazwa_ulicy + " " + db.adres.Find(db.kontrahent.Find(My_ID).Adres).Numer_budynku + "/" + db.adres.Find(db.kontrahent.Find(My_ID).Adres).Numer_mieszkania + "\n" + db.adres.Find(db.kontrahent.Find(My_ID).Adres).Kod_pocztowy.Remove(2, 3) + "-" + db.adres.Find(db.kontrahent.Find(My_ID).Adres).Kod_pocztowy.Remove(0, 2) + " " + db.adres.Find(db.kontrahent.Find(My_ID).Adres).Miasto + "\nNIP: " + db.kontrahent.Find(My_ID).NIP + "\nPESEL: " + db.kontrahent.Find(My_ID).Pesel + "\nEmail: " + db.kontrahent.Find(My_ID).E_mail + "\nTel: " + db.kontrahent.Find(My_ID).Telefon_1 + "\nTel: " + db.kontrahent.Find(My_ID).Telefon_2 + "\nPaństwo: " + db.adres.Find(db.kontrahent.Find(My_ID).Adres).Państwo; Client_info = db.kontrahent.Find(Client_ID).Imie + " " + db.kontrahent.Find(Client_ID).Nazwisko + "\n" + db.kontrahent.Find(Client_ID).Nazwa_Firmy + "\nul. " + db.adres.Find(db.kontrahent.Find(Client_ID).Adres).Nazwa_ulicy + " " + db.adres.Find(db.kontrahent.Find(Client_ID).Adres).Numer_budynku + "/" + db.adres.Find(db.kontrahent.Find(Client_ID).Adres).Numer_mieszkania + "\n" + db.adres.Find(db.kontrahent.Find(Client_ID).Adres).Kod_pocztowy.Remove(2, 3) + "-" + db.adres.Find(db.kontrahent.Find(Client_ID).Adres).Kod_pocztowy.Remove(0, 2) + " " + db.adres.Find(db.kontrahent.Find(Client_ID).Adres).Miasto + "\nNIP: " + db.kontrahent.Find(Client_ID).NIP + "\nPESEL: " + db.kontrahent.Find(Client_ID).Pesel + "\nEmail: " + db.kontrahent.Find(Client_ID).E_mail + "\nTel: " + db.kontrahent.Find(Client_ID).Telefon_1 + "\nTel: " + db.kontrahent.Find(Client_ID).Telefon_2 + "\nPaństwo: " + db.adres.Find(db.kontrahent.Find(Client_ID).Adres).Państwo; } Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(@"E:\E-elektryk oferty\" + _o.ID + "_" + DateTime.Now.Month + "_" + DateTime.Now.Year + ".pdf", FileMode.Create)); document.Open(); #region font string myFont = @"C:\Windows\Fonts\micross.ttf"; BaseFont bf = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); iTextSharp.text.Font Font_Table_Headers = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.BOLD); iTextSharp.text.Font Font_Table_Cells = new iTextSharp.text.Font(bf, 6, iTextSharp.text.Font.NORMAL); iTextSharp.text.Font Title_Font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD); #endregion #region Client_info PdfPTable headers = new PdfPTable(2); headers.HorizontalAlignment = Element.ALIGN_LEFT; headers.AddCell(getCell(My_Info, Element.ALIGN_LEFT)); headers.AddCell(getCell(Client_info, Element.ALIGN_RIGHT)); document.Add(headers); #endregion #region Title Paragraph title = new Paragraph(); Chunk c1 = new Chunk("Oferta nr: " + _o.ID + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year, Title_Font); title.Add(c1); title.Alignment = Element.ALIGN_CENTER; document.Add(title); Paragraph pause = new Paragraph(); Chunk c2 = new Chunk(" ", Title_Font); pause.Add(c2); pause.Alignment = Element.ALIGN_CENTER; document.Add(pause); #endregion #region date Paragraph date = new Paragraph(); Chunk c3 = new Chunk("Oferta ważna od: " + dateTimePicker1.Value.ToString().Remove(10, 9) + "\r", Font_Table_Cells); Chunk c4 = new Chunk("Oferta ważna do: " + dateTimePicker2.Value.ToString().Remove(10, 9), Font_Table_Cells); date.Add(c3); date.Add(c4); date.Alignment = Element.ALIGN_LEFT; document.Add(date); document.Add(pause); #endregion #region tabela int columns = dataGridView1.Columns.Count; PdfPTable table = new PdfPTable(columns); float[] widths = new float[] { 10, 45, 25, 10, 15, 15, 15, 10, 15, 30 }; table.SetWidths(widths); table.AddCell(new PdfPCell(new Phrase("ID", Font_Table_Headers))); table.AddCell(new PdfPCell(new Phrase("Nazwa", Font_Table_Headers))); table.AddCell(new PdfPCell(new Phrase("Producent", Font_Table_Headers))); table.AddCell(new PdfPCell(new Phrase("JM", Font_Table_Headers))); table.AddCell(new PdfPCell(new Phrase("Ilość", Font_Table_Headers))); table.AddCell(new PdfPCell(new Phrase("C.j", Font_Table_Headers))); table.AddCell(new PdfPCell(new Phrase("Netto", Font_Table_Headers))); table.AddCell(new PdfPCell(new Phrase("Vat", Font_Table_Headers))); table.AddCell(new PdfPCell(new Phrase("Brutto", Font_Table_Headers))); table.AddCell(new PdfPCell(new Phrase("Kategoria", Font_Table_Headers))); for (int j = 0; j < dataGridView1.Rows.Count; j++) { for (int i = 0; i < dataGridView1.Columns.Count; i++) { table.AddCell(new PdfPCell(new Phrase(dataGridView1.Rows[j].Cells[i].Value.ToString(), Font_Table_Cells))); } } document.Add(table); #endregion document.Close(); MessageBox.Show("Utworzono ofertę " + _o.ID + "." + DateTime.Now.Month + "." + DateTime.Now.Year + ".pdf"); Process myProcess = new Process(); myProcess.StartInfo.FileName = "acroRd32.exe"; //not the full application path myProcess.StartInfo.Arguments = "\"" + @"E:\E-elektryk oferty\" + _o.ID + "_" + DateTime.Now.Month + "_" + DateTime.Now.Year + ".pdf" + "\""; myProcess.Start(); } // Generate offer pdf using itextsharp
void Choice_Address_For_Client(int button_number) { TextBox[] textBox = { textBox_Town, textBox_Kod_1, textBox_Kod_2, textBox_Street, textBox_Building_Number, textBox_Home_Number, textBox_Country }; switch (button_number) { case 1: { try { using (zlecenieEntities db = new zlecenieEntities()) { textBox_Town.Text = db.adres.Find(db.kontrahent.Find(client_id).Adres).Miasto; textBox_Kod_1.Text = (db.adres.Find(db.kontrahent.Find(client_id).Adres).Kod_pocztowy).Remove(2, 3); textBox_Kod_2.Text = (db.adres.Find(db.kontrahent.Find(client_id).Adres).Kod_pocztowy).Remove(0, 2); textBox_Street.Text = db.adres.Find(db.kontrahent.Find(client_id).Adres).Nazwa_ulicy; textBox_Building_Number.Text = db.adres.Find(db.kontrahent.Find(client_id).Adres).Numer_budynku; textBox_Home_Number.Text = db.adres.Find(db.kontrahent.Find(client_id).Adres).Numer_mieszkania; textBox_Country.Text = db.adres.Find(db.kontrahent.Find(client_id).Adres).Państwo; for (int i = 0; i < textBox.Length; i++) { textBox[i].Enabled = false; } } } catch { MessageBox.Show("Wybierz Kontrahenta", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; } case 2: { try { using (zlecenieEntities db = new zlecenieEntities()) { a = new adres(); Window_Choice_Adres_For_Order window_Choice_Adres = new Window_Choice_Adres_For_Order(a); window_Choice_Adres.ShowDialog(); a = db.adres.Find(a.ID); textBox_Town.Text = a.Miasto; textBox_Kod_1.Text = a.Kod_pocztowy.Remove(2, 3); textBox_Kod_2.Text = a.Kod_pocztowy.Remove(0, 2); textBox_Street.Text = a.Nazwa_ulicy; textBox_Building_Number.Text = a.Numer_budynku; textBox_Home_Number.Text = a.Numer_mieszkania; textBox_Country.Text = a.Państwo; for (int i = 0; i < textBox.Length; i++) { textBox[i].Enabled = false; } } } catch { } break; } } }
} // Save or update information about Offer private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.Checked) { using (zlecenieEntities db = new zlecenieEntities()) { List <produkt> list = db.produkt.ToList(); listView1.Items.Clear(); foreach (produkt p in list.Where(lvi => lvi.Nazwa.ToLower().Contains(textBox_name_search.Text.ToLower().Trim()) && lvi.Producent.ToLower().Contains(textBox_Producent_search.Text.ToLower().Trim()))) { ListViewItem item = new ListViewItem(p.ID.ToString()); item.SubItems.Add(p.Nazwa.ToLower()); item.SubItems.Add(p.Producent.ToString()); item.SubItems.Add(p.Jm.ToString()); item.SubItems.Add(p.Ilość.ToString()); item.SubItems.Add(p.Cena_netto.ToString() + " zł"); item.SubItems.Add(p.Vat.ToString() + " %"); item.SubItems.Add(p.Cena_brutto.ToString() + " zł"); if (p.Kategoria != 0) { kategoria_produktu product_cat = new kategoria_produktu(); product_cat = db.kategoria_produktu.Find(p.Kategoria); item.SubItems.Add(product_cat.Nazwa_kategorii.ToString()); } item.SubItems.Add(db.statusy_produktów.Find(p.Status).Status); item.Font = new System.Drawing.Font(item.Font, FontStyle.Regular); listView1.Items.Add(item); } } calculate(); } else { using (zlecenieEntities db = new zlecenieEntities()) { List <produkt> list = db.produkt.ToList(); listView1.Items.Clear(); foreach (produkt p in list.Where(lvi => lvi.Nazwa.ToLower().Contains(textBox_name_search.Text.ToLower().Trim()) && lvi.Producent.ToLower().Contains(textBox_Producent_search.Text.ToLower().Trim()) && lvi.Status.ToString().Contains("1"))) { ListViewItem item = new ListViewItem(p.ID.ToString()); item.SubItems.Add(p.Nazwa.ToLower()); item.SubItems.Add(p.Producent.ToString()); item.SubItems.Add(p.Jm.ToString()); item.SubItems.Add(p.Ilość.ToString()); item.SubItems.Add(p.Cena_netto.ToString() + " zł"); item.SubItems.Add(p.Vat.ToString() + " %"); item.SubItems.Add(p.Cena_brutto.ToString() + " zł"); if (p.Kategoria != 0) { kategoria_produktu product_cat = new kategoria_produktu(); product_cat = db.kategoria_produktu.Find(p.Kategoria); item.SubItems.Add(product_cat.Nazwa_kategorii.ToString()); } item.SubItems.Add(db.statusy_produktów.Find(p.Status).Status); item.Font = new System.Drawing.Font(item.Font, FontStyle.Regular); listView1.Items.Add(item); } } calculate(); } }