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"); }
public void SendEmail() { Supplier s = db.Suppliers.Where(x => x.Supplier_ID == supplierID).FirstOrDefault(); Supplier_Contact_Details sc = db.Supplier_Contact_Details.Where(x => x.Supplier_Contact_ID == s.Supplier_ID).FirstOrDefault(); Stock_Item st = db.Stock_Item.Where(x => x.Stock_ID == stockID).FirstOrDefault(); Stock_Order_Line so = db.Stock_Order_Line.Where(x => x.Stock_Order_Line_ID == stockID).FirstOrDefault(); try { SmtpClient client = new SmtpClient("smtp.gmail.com", 587); MailMessage message = new MailMessage(); string myEmail = "*****@*****.**"; string pswd = "@mulaudzi"; message.From = new MailAddress(myEmail); message.Subject = "Placing an order"; foreach (var order in Globals.StockOrders) { message.Body = "Dear " + s.Supplier_Name + "\nWe are very interested in making an order for the following item:\n\n" + order.StockItemName + " Quantity: " + order.sOrderQuantity + "\n\nWe look forward to your reply \n\nKind Regards Mr Mafokwane (Manager)"; } //message.Body = "Dear \n"+s.Supplier_Name+"\nWe are very interested in making an order for the following item: \n"+ // st.Stock_Item_Name +" Quantity"+ so.Stock_Order_Quantity + // "\n\nWe look forward to your reply \n\nKind Regards Mr Mafokwane (Manager)"; //message.To.Add(sc.Supplier_Email_Adress); message.To.Add(sc.Supplier_Email_Adress); client.UseDefaultCredentials = false; client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential(myEmail, pswd); client.Send(message); message = null; } catch (Exception ex) { MessageBox.Show("Error " + ex); } }