//On click of modify button, opens a new form and grabs the information from the selected value in the datagrid view ~ TS
        private void btnModifySuppliers_Click(object sender, EventArgs e)
        {
            frmSuppliersAddModify secondSupplierForm = new frmSuppliersAddModify();
            int      rowNum = supplierDataGridView.CurrentCell.RowIndex;
            int      suppId = Convert.ToInt32(supplierDataGridView["dataGridViewTextBoxColumn1", rowNum].Value);
            Supplier currentSupplier;

            //Grabs the supplier based on the selected supplierID ~ TS
            using (SuppliersDataContext dbContext = new SuppliersDataContext())
            {
                currentSupplier = (from s in dbContext.Suppliers
                                   where s.SupplierId == suppId
                                   select s).Single();
            }
            secondSupplierForm.isModify        = true;
            secondSupplierForm.currentSupplier = currentSupplier;
            DialogResult result = secondSupplierForm.ShowDialog();

            if (result == DialogResult.OK || result == DialogResult.Retry)
            {
                db = new SuppliersDataContext();
                supplierDataGridView.DataSource = db.Suppliers;
                supplierDataGridView.Sort(dataGridViewTextBoxColumn1, 0);
            }
        }
示例#2
0
 //On click of save button it creates a new supplier based on the input provided ~ TS
 private void btnSaveSuppliers_Click(object sender, EventArgs e)
 {
     if (!isModify)                                       // If add supplier ~ TS
     {
         if (Validator.IsPresent(supNameTextBox) == true) //If the supplier name is not empty ~ TS
         {
             Supplier newSupp = new Supplier
             {
                 SupName = supNameTextBox.Text
             };
             using (SuppliersDataContext dbContext = new SuppliersDataContext())
             {
                 supplierForm.db.Suppliers.InsertOnSubmit(newSupp);
                 supplierForm.db.SubmitChanges();
             }
             DialogResult = DialogResult.OK;
         }
     }
     else // Is modify ~ TS
     {
         using (SuppliersDataContext dbContext = new SuppliersDataContext())
         {
             Supplier supp = dbContext.Suppliers.Single(p => p.SupplierId == Convert.ToInt32(supplierIdTextBox.Text));
             if (supp != null)
             {
                 supp.SupName = supNameTextBox.Text;
                 dbContext.SubmitChanges();
                 DialogResult = DialogResult.OK;
             }
         }
     }
 }
        //On click of add button, opens new form and connects back to the database ~ TS
        private void btnAddSuppliers_Click(object sender, EventArgs e)
        {
            frmSuppliersAddModify secondSupplierForm = new frmSuppliersAddModify();

            secondSupplierForm.supplierForm = this;
            DialogResult result = secondSupplierForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                db = new SuppliersDataContext();
                supplierDataGridView.DataSource = db.Suppliers;
                supplierDataGridView.Sort(dataGridViewTextBoxColumn1, 0);
            }
        }