private void executeCreateCustomerCommand() { if (VisibilityCivilCustomerCreate == true) { CivilCustomer civilCustomer = new CivilCustomer(); if (!IsDefaultCivil()) { civilCustomer = new CivilCustomer() { ID = ID, FirstName = FirstName, LastName = LastName, Address = Address, IDnumber = IDnumber, Type = "FIZICKO LICE" } } ; Broker.Instance.InsertCustomerIntoBase(civilCustomer, null, _user); ResetToDefaultCivil(); AllCustomers = Broker.Instance.LoadAllCustomers("Civil"); } else if (VisibilityPublicCustomerCreate == true) { PublicCustomer publicCustomer = new PublicCustomer(); if (!IsDefaultPublic()) { publicCustomer = new PublicCustomer() { ID = ID, CompanyName = CompanyName, CompanyAddress = CompanyAddress, PIB = PIB, CompanyIDnumber = CompanyIDnumber, Type = "PRAVNO LICE" } } ; Broker.Instance.InsertCustomerIntoBase(null, publicCustomer, _user); ResetToDefaultPublic(); AllCustomers = Broker.Instance.LoadAllCustomers("Public"); } }
//private void ResetToDefault() //{ // SelectedElement = null; // Discount = 0; // PaymentTime = 0; // OfferValidity = 0; // DeliveryTime = 0; // Number = 0; //} public void Start(User user, CivilCustomer civilCustomer, PublicCustomer publicCustomer) { Accepted = false; IsChecked = true; _user = user; _civilCustomer = civilCustomer; _publicCustomer = publicCustomer; if (_civilCustomer != null) { _customerInfo = $"ID:\t{_civilCustomer.ID}\nIme:\t{_civilCustomer.FirstName} {_civilCustomer.LastName}\nAdresa:\t{_civilCustomer.Address}\nJMBG:\t{_civilCustomer.IDnumber}"; } else if (_publicCustomer != null) { _customerInfo = $"ID:\t\t{_publicCustomer.ID}\nNaziv firme:\t{_publicCustomer.CompanyName}\nAdresa:\t\t{_publicCustomer.CompanyAddress}\nPIB:\t\t{_publicCustomer.PIB}\nMaticni broj:\t{_publicCustomer.CompanyIDnumber}"; } IsSelected = true; FinishedAdding = false; AllElements = Broker.Instance.LoadAllElements(); OfferNumber = Broker.Instance.GetMaxOfferID(); Started?.Invoke(this, new EventArgs()); }
public void InsertCustomerIntoBase(CivilCustomer civilCustomer, PublicCustomer publicCustomer, User user) { try { _conn.Open(); long customerID = 0; if (civilCustomer != null) { SqlCommand cmdCustomer = new SqlCommand($"insert into kupac (tip,prodavacid) values ('{civilCustomer.Type}','{user.ID}');select cast (scope_identity() as bigint)", _conn); customerID = (long)cmdCustomer.ExecuteScalar(); SqlCommand cmdCivilCustomer = new SqlCommand($"insert into fizickolice (kupacid, ime, prezime, adresa, maticnibroj) values ({customerID}, '{civilCustomer.FirstName}'," + $"'{civilCustomer.LastName}', '{civilCustomer.Address}', '{civilCustomer.IDnumber}')", _conn); cmdCivilCustomer.ExecuteScalar(); } else if (publicCustomer != null) { SqlCommand cmdCustomer = new SqlCommand($"insert into kupac (tip) values ('{publicCustomer.Type}');select cast (scope_identity() as bigint)", _conn); customerID = (long)cmdCustomer.ExecuteScalar(); SqlCommand cmcPublicCustomer = new SqlCommand($"insert into pravnolice (kupacid, firma, adresa, pib, maticnibroj) values ({customerID},'{publicCustomer.CompanyName}', '{publicCustomer.CompanyAddress}', '{publicCustomer.PIB}', '{publicCustomer.CompanyIDnumber}')", _conn); cmcPublicCustomer.ExecuteScalar(); } } catch (Exception e) { MessageBox.Show($"Greska\n{e.Message}"); } finally { if (_conn.State == System.Data.ConnectionState.Open) { _conn.Close(); } } }
public ObservableCollection <CustomerClass> LoadAllCustomers(string type) { ObservableCollection <CustomerClass> _allCustomers = new ObservableCollection <CustomerClass>(); SqlCommand cmd; if (type == "Civil") { cmd = new SqlCommand("select kupacid, ime, prezime, adresa, maticnibroj from fizickolice", _conn); } else if (type == "Public") { cmd = new SqlCommand("select kupacid, firma, adresa, pib, maticnibroj from pravnolice", _conn); } else { return(null); } try { _conn.Open(); var reader = cmd.ExecuteReader(); CivilCustomer civilustomer = new CivilCustomer(); PublicCustomer publicCustomer = new PublicCustomer(); while (reader.Read()) { if (type == "Civil") { civilustomer = new CivilCustomer() { ID = reader.GetInt64(0), FirstName = reader.GetString(1), LastName = reader.GetString(2), Address = reader.GetString(3), IDnumber = reader.GetString(4) }; _allCustomers.Add(civilustomer); } else if (type == "Public") { publicCustomer = new PublicCustomer() { ID = reader.GetInt64(0), CompanyName = reader.GetString(1), CompanyAddress = reader.GetString(2), PIB = reader.GetString(3), CompanyIDnumber = reader.GetString(4) }; _allCustomers.Add(publicCustomer); } } return(_allCustomers); } finally { if (_conn.State == System.Data.ConnectionState.Open) { _conn.Close(); } } }
private static PdfPTable Header(PdfPCell cell, long brojPonude, float width, bool lockedWidth, CivilCustomer civilCustomer, PublicCustomer publicCustomer) { string url = @"D:\slika.JPG"; PdfPTable headerTable = new PdfPTable(1); PdfPTable table = new PdfPTable(3); table.TotalWidth = width; table.LockedWidth = lockedWidth; headerTable.TotalWidth = width; headerTable.LockedWidth = lockedWidth; float[] widths = new float[] { 1f, 2f, 2f }; table.SetWidths(widths); Font font = new Font(); font.SetFamily("Times New Roman"); font.Size = 9f; //ovde Image imm = Image.GetInstance(new Uri(url)); imm.ScaleToFit(100f, 50f); cell = new PdfPCell(imm); cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.HorizontalAlignment = 1; cell.VerticalAlignment = Rectangle.ALIGN_MIDDLE; cell.Border = 0; table.AddCell(cell); cell = new PdfPCell(new Paragraph("Kompanija KTITOR doo\nDobanovacki put 58\n11080 Zemun\nTel: 011 30 70 700\nFax: 011 30 70 777\n" + "PIB: 1000019999", font)); cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.HorizontalAlignment = 0; cell.Border = 0; table.AddCell(cell); if (civilCustomer != null) { cell = new PdfPCell(new Paragraph($"Kupac:\n{civilCustomer.FirstName} {civilCustomer.LastName}\n{civilCustomer.Address}\n{civilCustomer.IDnumber}", font)); cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.HorizontalAlignment = 2; cell.Border = 0; table.AddCell(cell); } else if (publicCustomer != null) { cell = new PdfPCell(new Paragraph($"Kupac:\n{publicCustomer.CompanyName}\n{publicCustomer.CompanyAddress}\n{publicCustomer.CompanyIDnumber}\n{publicCustomer.PIB}", font)); cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.HorizontalAlignment = 2; cell.Border = 0; table.AddCell(cell); } cell = new PdfPCell(table); cell.BackgroundColor = BaseColor.LIGHT_GRAY; headerTable.AddCell(cell); return(headerTable); }