public static bool AddCustomer(Customer customerToAdd) { bool result = true; if (_allCustomers.Where(customer => customer.Name == customerToAdd.Name).Count() != 0) { result = false; } else { _allCustomers.Add(customerToAdd); SaveCustomers(); } return result; }
private void BtAddCompanyClick(object sender, EventArgs e) { Customer customer; bool nameIsOk = false; errorProvider.Clear(); if (btAddCompany.Text == "Add") { customer = new Customer(); nameIsOk = true; } else { customer = ((Customer) cbCompanies.SelectedItem); if (customer.Name == tbCompanyName.Text || Controller.AllCustomers().Where(customername => customername.Name == tbCompanyName.Text).Count() == 0) { nameIsOk = true; Controller.RemoveCustomer(customer); } if (!string.IsNullOrEmpty(customer.Logo) && customer.Name != tbCompanyName.Text && nameIsOk) { SetLogo(customer); } } if (!nameIsOk) { errorProvider.SetError(tbCompanyName, "Name already exists"); } else { customer.Name = tbCompanyName.Text; customer.VatNumber = tbVatNr.Text; customer.WebPage = tbWebPage.Text; customer.Email = tbEmail.Text; customer.Telephone = tbTelephone.Text; customer.VisitAdress.Country = tbVisitCountry.Text; customer.VisitAdress.PostNumber = tbVisitPostNumber.Text; customer.VisitAdress.Street = tbVisitStreet.Text; customer.VisitAdress.City = tbVisitCity.Text; customer.PostalAdress.City = tbPostalCity.Text; customer.PostalAdress.Country = tbPostalCountry.Text; customer.PostalAdress.PostNumber = tbPostalPostNumber.Text; customer.PostalAdress.Street = tbPostalStreet.Text; if (cbCustomerType.SelectedItem != null) customer.TypeOfCustomer = (Customer.CustomerType) Enum.Parse( typeof (Customer.CustomerType), cbCustomerType.SelectedItem.ToString()); //if (Controller.AddCustomer(customer)) //{ cbCompanies.UpdateInfo(); cbCompanies.SelectedItem = (Controller.AllCustomers()).Where(name => name.Name == customer.Name).First(); //} //else //{ // errorProvider.SetError(tbCompanyName, "Name already exists"); //} } }
private void SetLogo(Customer customer) { customer.Logo = Controller.ChangeLogoName(customer.Logo, tbCompanyName.Text); var ms = new MemoryStream(File.ReadAllBytes(customer.Logo)); pbxCompanyLogo.Image = Image.FromStream(ms); pbxCompanyLogo.Show(); }
internal static void RemoveCustomer(Customer customer) { _allCustomers.Remove(customer); SaveCustomers(); }
internal static void ChangeLogo(Customer customerToAddLogoTo) { var openFileDialog1 = new OpenFileDialog { InitialDirectory = "c:\\", Filter = AvalibleImageFormats(), FilterIndex = 2, RestoreDirectory = true }; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { File.Delete(customerToAddLogoTo.Logo); var extension = Path.GetExtension(openFileDialog1.FileName); var savePath = ImageDir("logo") + customerToAddLogoTo.Name + extension; File.Copy(openFileDialog1.FileName, savePath); } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } }