private void SupplierForm_Load(object sender, EventArgs e) { SupplierType sp = new SupplierType(); //// int index = supplierCity.City_ID; foreach (var item in db.Supplier_Type.Where(a => a.Supplier_Type_Description != null).ToList()) { //cbxSupplierType.Items.Add(item.Supplier_Type_Description); } //if(cbxSupplierType.SelectedText =="Ingredient Supplier") //{ // cbxSupplierType.SelectedIndex = 1; //} //else //{ // cbxSupplierType.SelectedIndex = 2; //} if (index != -1) { btnUpdateSupplier.Visible = true; Supplier newSupplier = new Supplier(); Supplier_Contact_Details supplierContact = new Supplier_Contact_Details(); Address supplierAddress = new Address(); // City supplierCity = new City(); Suburb supplierSuburb = new Suburb(); Banking_Details bank = new Banking_Details(); Adress_Type addressType = new Adress_Type(); newSupplier = db.Suppliers.Single(x => x.Supplier_ID == index); supplierContact = db.Supplier_Contact_Details.Single(x => x.Supplier_ID == index); supplierAddress = db.Addresses.Single(x => x.Supplier_ID == index); bank = db.Banking_Details.Single(x => x.Supplier_ID == index); //supplierCity = db.Cities.FirstOrDefault(x => x.City_ID == index); // supplierAddress = db.Addresses.Single(x=>x.Suburb_ID==index); supplierSuburb = db.Suburbs.Single(x => x.Suburb_ID == supplierAddress.Suburb_ID); txtSupplierName.Text = newSupplier.Supplier_Name; txtSupplierEmail.Text = supplierContact.Supplier_Email_Adress; txtSupplierPhone.Text = supplierContact.Supplier_Contact_Number.ToString(); txtSupplierContactP.Text = supplierContact.Supplier_Contact_Name; txtStreetName.Text = supplierAddress.Street_Name; txtProvince.Text = supplierAddress.Province; txtCity.Text = supplierAddress.City_Name;//supplierCity.City_Name; txtSuburb.Text = supplierSuburb.Suburb_Name; txtCode.Text = supplierSuburb.Zip_Code; txtBankName.Text = bank.Bank_Name; txtAccNumber.Text = bank.Bank_Acc_No.ToString(); txtBranchCode.Text = bank.Branch_Code.ToString(); supplierAddress.Supplier_ID = newSupplier.Supplier_ID; supplierContact.Supplier_ID = newSupplier.Supplier_ID; supplierAddress.Suburb_ID = supplierSuburb.Suburb_ID; //supplierSuburb.City_ID = supplierCity.City_ID; } }
private void btnUpdateSupplier_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { try { Supplier newSupplier = new Supplier(); Supplier_Contact_Details supplierContact = new Supplier_Contact_Details(); Address supplierAddress = new Address(); City supplierCity = new City(); Suburb supplierSuburb = new Suburb(); Banking_Details bank = new Banking_Details(); Adress_Type addressType = new Adress_Type(); newSupplier.Supplier_Name = txtSupplierName.Text; supplierContact.Supplier_Email_Adress = txtSupplierEmail.Text; supplierContact.Supplier_Contact_Number = Convert.ToInt32(txtSupplierPhone.Text); supplierContact.Supplier_Contact_Name = txtSupplierContactName.Text; supplierAddress.Street_Name = txtStreetName.Text; supplierAddress.Province = txtProvince.Text; // //supplierCity.City_Name = txtCity.Text; supplierSuburb.Suburb_Name = txtSuburb.Text; supplierSuburb.Zip_Code = txtCode.Text; bank.Bank_Name = txtBankName.Text; bank.Bank_Acc_No = Convert.ToInt32(txtAccNumber.Text); bank.Branch_Code = Convert.ToInt32(txtBranchCode.Text); supplierAddress.Supplier_ID = newSupplier.Supplier_ID; supplierContact.Supplier_ID = newSupplier.Supplier_ID; supplierAddress.Suburb_ID = supplierSuburb.Suburb_ID; //supplierSuburb.City_ID = supplierCity.City_ID; bank.Supplier_ID = newSupplier.Supplier_ID; //newSupplier.Supplier_Type_ID = sp // db.Cities.Add(supplierCity); db.Suburbs.Add(supplierSuburb); db.Suppliers.Add(newSupplier); db.Addresses.Add(supplierAddress); db.Supplier_Contact_Details.Add(supplierContact); db.Banking_Details.Add(bank); db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } this.Close(); f.loadSuppliers(); MessageBox.Show("Supplier details successfully updated"); }
private void button7_Click_1(object sender, EventArgs e) { Customer cust = new Customer(); if (ValidateChildren(ValidationConstraints.Enabled)) { try { //City city = db.Cities.FirstOrDefault(c => c.City_Name == txtCity.Text); Suburb suburb = db.Suburbs.FirstOrDefault(c => c.Suburb_Name == txtSurburb.Text); cust.Customer_Name = txtCustomerNames.Text; cust.Customer_Surname = txtCustomerSurname.Text; if ((suburb != null)) { // cust.City_ID = city.City_ID; cust.Suburb_ID = suburb.Suburb_ID; } else { MessageBox.Show("Error:City or Suburb not found"); return; } cust.Customer_Address = txtProvimce.Text + " " + "\n " + suburb.Suburb_Name + " " + txtStreeName.Text; cust.Customer_Contact_Number = Convert.ToInt32(txtContactNo.Text); db.Customers.Add(cust); db.SaveChanges(); Globals.addCustomer = true; Globals.custId = cust.Customer_ID; Globals.refresher = true; MessageBox.Show("New customer added successfully"); } catch (Exception i) { MessageBox.Show(Convert.ToString(i)); } } }