private void btnModify_Click(object sender, EventArgs e) { frmAddModifySupplierContact frm = new frmAddModifySupplierContact(); frm.isAddSupplierContact = false; int index = lstSupplier.SelectedIndex; supplier = suppliers[index]; frm.supplierContact = contact; frm.Show(); }
private void button1_Click(object sender, EventArgs e) { frmAddModifySupplierContact frm = new frmAddModifySupplierContact(); frm.isAddSupplierContact = true; int index = lstSupplier.SelectedIndex; supplier = suppliers[index]; frm.supplierId = supplier.SupplierId; frm.Show(); }
private void lstSupplier_SelectedIndexChanged(object sender, EventArgs e) { int index = lstSupplier.SelectedIndex; lstSupplierContacts.Items.Clear(); supplier = suppliers[index]; MessageBox.Show(supplier.SupplierId.ToString()); contacts = SupplierContactsDB.GetSupplierContactsList(supplier.SupplierId); foreach (SupplierContacts cont in contacts) { if (cont.SupConFirstName != null && cont.SupConFirstName != "") { lstSupplierContacts.Items.Add(cont.SupplierContactId + ": " + cont.SupConFirstName + " " + cont.SupConLastName); } } }
public static List<Supplier> GetSupplier() { // create a list object of all the suppliers List<Supplier> supplier = new List<Supplier>(); // set the connection to database SqlConnection connection = TravelExpertsDB.GetConnection(); // select query string selectStatement = "Select SupplierId, SupName " + "From Suppliers " + "Order by SupName"; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); try { // open connection connection.Open(); // read the query command SqlDataReader supplierReader = selectCommand.ExecuteReader(); while (supplierReader.Read()) { // create a new object class s Supplier s = new Supplier(); // read values from columns in database s.SupplierId = (int) supplierReader["SupplierId"]; s.SupName = supplierReader["SupName"].ToString(); supplier.Add(s); } // ends read supplierReader.Close(); } catch (SqlException ex) { throw ex; } finally { // close database connection connection.Close(); } return supplier; }
private void btnModify_Click(object sender, EventArgs e) { frmAddModifySupplierContact frm = new frmAddModifySupplierContact(); frm.isAddSupplierContact = false; int index = lstSupplier.SelectedIndex; supplier = suppliers[index]; frm.supplierContact = contact; //frm.Show(); DialogResult rslt = frm.ShowDialog(); if (rslt == DialogResult.OK) { setSupplierContacts(); clearSupplierContact(); } else if (rslt == DialogResult.Retry) { if (contact != null) setSupplierContacts(); else clearSupplierContact(); } }
//Event handler for add button click //opens modify/add form and passes relevent data private void btnAdd_Click(object sender, EventArgs e) { frmAddModifySupplierContact frm = new frmAddModifySupplierContact();//create form instance frm.isAddSupplierContact = true; //true value tells form to add int index = lstSupplier.SelectedIndex; //get selected supplier supplier = suppliers[index]; //set supplier holder to supplier in list frm.supplierId = supplier.SupplierId; //pass supplier object to add contact into //frm.Show(); //show form DialogResult rslt = frm.ShowDialog(); //if modify ok if (rslt == DialogResult.OK) { setSupplierContacts(); //reset supplier contacts clearSupplierContact(); //clear display form } //if modify failed and retries else if (rslt == DialogResult.Retry) { if (contact != null) setSupplierContacts(); else clearSupplierContact(); } }
public static List<Supplier> GetSupplier() { List<Supplier> supplier = new List<Supplier>(); SqlConnection connection = TravelExpertsDB.GetConnection(); string selectStatement = "Select SupplierId, SupName " + "From Suppliers " + "Order by SupplierId"; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); //selectCommand.Parameters.AddWithValue("@SupplierId", SupplierID); try { connection.Open(); SqlDataReader supplierReader = selectCommand.ExecuteReader(); while (supplierReader.Read()) { Supplier s = new Supplier(); s.SupplierId = (int)supplierReader["SupplierId"]; s.SupName = supplierReader["SupName"].ToString(); supplier.Add(s); } supplierReader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return supplier; }
private void setSupplierContacts() { int index = lstSupplier.SelectedIndex; lstSupplierContacts.Items.Clear(); supplier = suppliers[index]; contacts = SupplierContactsDB.GetSupplierContactsList(supplier.SupplierId); foreach (SupplierContacts cont in contacts) { lstSupplierContacts.Items.Add(cont.SupplierContactId + ": " + cont.SupConFirstName + " " + cont.SupConLastName); } }
//sets supplier contacts in contact supplier list box //calls SupplierContactDb to get supplier contacts private void setSupplierContacts() { int index = lstSupplier.SelectedIndex; //get selected supplier lstSupplierContacts.Items.Clear(); supplier = suppliers[index]; //get supplier selected in supplier list box, store in supplier object //collects List of supplier contacts by calling GetSupplierContactsList, passes it supplier id contacts = SupplierContactsDB.GetSupplierContactsList(supplier.SupplierId); //Loop through contacts List and add to list box foreach (SupplierContacts cont in contacts) { lstSupplierContacts.Items.Add(cont.SupplierContactId + ": " + cont.SupConFirstName + " " + cont.SupConLastName); } }