Example #1
0
        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;
            }
        }
Example #2
0
        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");
        }