예제 #1
0
 //deletes selected supplier in DB, updates dgv
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         Supplier selectedSupplier = null;
         foreach (DataGridViewRow row in dgvSuppliers.SelectedRows)
         {
             selectedSupplier = new Supplier(Convert.ToInt32(row.Cells[0].Value.ToString()),
                                             row.Cells[1].Value.ToString());
             string message = "Are you sure you want to delete " +
                              selectedSupplier.SupName +
                              " ?";
             DialogResult button = MessageBox.Show(message, "Confirm Delete",
                                                   MessageBoxButtons.YesNo);
             if (button == DialogResult.Yes)
             {
                 SupplierDB.DeleteSupplier(selectedSupplier);
                 suppliers = SupplierDB.GetAllSuppliers();
                 UpdateBinding();
                 txtSuppName.Clear();
             }
         }
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.Message, ex.GetType().ToString());
         MessageBox.Show("Deleting this supplier will cause you to lose a record in your booking history. \nThe delete action has been suspended. \nPlease contact DBA.");
     }
 }
예제 #2
0
        //opens AddSupplier form, receives newly added suppliers, inserts to DB and updates dgv, scrolls down to latest new supplier added
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddSuppliers newForm      = new frmAddSuppliers();
            List <Supplier> newSuppliers = newForm.GetNewSuppliers();

            try
            {
                if (newSuppliers != null)
                {
                    foreach (Supplier ns in newSuppliers)
                    {
                        SupplierDB.InsertSupplier(ns);
                    }
                }
                suppliers = SupplierDB.GetAllSuppliers();
                UpdateBinding();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }

            txtSuppName.Clear();
            //select on the last row of the list
            dgvSuppliers.ClearSelection();
            int rowIndex = dgvSuppliers.Rows.Count - 1;

            dgvSuppliers.Rows[rowIndex].Selected = true;
            //scroll down as well
            dgvSuppliers.FirstDisplayedScrollingRowIndex = rowIndex;
        }
        private void btnClear_Click(object sender, EventArgs e)
        {
            try
            {
                suppliers = SupplierDB.GetAllSuppliers();//call function to get all suppliers
                UpdateBinding();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());//show exception if there any
            }

            txtSName.Clear();//for clear textBox
            txtSName.Select();
        }
예제 #4
0
        //resets everything to default
        private void btnClear_Click(object sender, EventArgs e)
        {
            try
            {
                suppliers = SupplierDB.GetAllSuppliers();
                UpdateBinding();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }

            txtSuppName.Clear();
            txtSuppName.Select();
        }
예제 #5
0
        //opens EditSupplier form, receives edited supplier, updates DB, selects edited supplier in dgv
        private void btnEdit_Click(object sender, EventArgs e)
        {
            Supplier editedSupplier = null;
            Supplier newSupplier    = null;

            foreach (DataGridViewRow row in dgvSuppliers.SelectedRows)
            {
                editedSupplier = new Supplier(Convert.ToInt32(row.Cells[0].Value.ToString()),
                                              row.Cells[1].Value.ToString());
            }

            frmEditSupplier newForm = new frmEditSupplier();

            //this.Hide();

            newSupplier = newForm.GetEditSupplier(editedSupplier);

            //this.Show();

            try
            {
                SupplierDB.UpdateSupplier(editedSupplier, newSupplier);
                suppliers = SupplierDB.GetAllSuppliers();
                UpdateBinding();
                txtSuppName.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }

            //set the modified row to be selected
            dgvSuppliers.ClearSelection();
            int rowIndex = -1;

            foreach (DataGridViewRow row in dgvSuppliers.Rows)
            {
                if (row.Cells[0].Value.ToString().Equals(editedSupplier.SupplierId.ToString()))
                {
                    rowIndex = row.Index;
                    break;
                }
            }
            dgvSuppliers.Rows[rowIndex].Selected         = true;
            dgvSuppliers.FirstDisplayedScrollingRowIndex = rowIndex;
        }
 private void txtSName_TextChanged(object sender, EventArgs e)
 {
     try
     {
         if (txtSName.Text != "")                                      //check if text s name empty
         {
             suppliers = SupplierDB.GetSuppliersByName(txtSName.Text); //function call to GetSupplierByName
             UpdateBinding();
         }
         else
         {
             suppliers = SupplierDB.GetAllSuppliers();//function calls to GetAllSuppliers
             UpdateBinding();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString());//show exception if there any
     }
 }
예제 #7
0
        private void SupplierForm_Load(object sender, EventArgs e)
        {
            this.ControlBox  = false;
            this.MaximizeBox = false;
            this.MinimizeBox = false;

            try
            {
                // load the products table data
                suppliers = SupplierDB.GetAllSuppliers();
                UpdateBinding();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }

            SuppliersListFormat(dgvSuppliers);
            frmProduct.ProductListFormat(dgvProducts);

            txtSuppName.Select();
        }