private void btnAddProductTypes_Click(object sender, EventArgs e) { if (validateInput()) { //Create the sale object using the Sale Class constructor var productType = new _ProductType(); using (var conn = ConnectionManager.DatabaseConnection()) using (var cmd = new SqlCommand("sp_ProductTypes_CreateProductType", conn)) { cmd.CommandType = CommandType.StoredProcedure; SqlParameter nptid = cmd.Parameters.Add("NewProductTypeID", SqlDbType.Int); nptid.Direction = ParameterDirection.Output; cmd.Parameters.AddWithValue("ProductType", txtProductType.Text); cmd.Transaction = conn.BeginTransaction(); cmd.ExecuteNonQuery(); cmd.Transaction.Commit(); } if (MessageBox.Show("Would you like to add another Product Type into the database", "Add another?", MessageBoxButtons.YesNo) == DialogResult.Yes) { txtProductType.Clear(); txtProductTypeID.Clear(); } else { this.Close(); } } }
private void DisplayProductTypes() { string selectQuery; selectQuery = "SELECT * FROM ProductTypes"; List <_ProductType> ptList = new List <_ProductType>(); try { // Automatically open and close the connection using (var conn = ConnectionManager.DatabaseConnection()) using (var cmd = new SqlCommand(selectQuery, conn)) using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { //Define the list items var productType = new _ProductType( int.Parse(rdr["ProductTypeID"].ToString()), rdr["ProductType"].ToString()); ptList.Add(productType); } dgvProductType.DataSource = ptList; } } catch (Exception ex) { MessageBox.Show("Unsuccessful" + ex); } }
private void btnUpdateProductTypes_Click(object sender, EventArgs e) { if (validateInput()) { //Create an object of the ProductType class. var updateExistingProductType = new _ProductType(int.Parse(txtProductTypeID.Text), txtProductType.Text); using (var conn = ConnectionManager.DatabaseConnection()) { //Specify the Stored Procedure using (var cmd = new SqlCommand("sp_ProductTypes_UpdateProductType", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("ProductTypeID", updateExistingProductType.ProductTypeID); cmd.Parameters.AddWithValue("ProductType", updateExistingProductType.ProductType); cmd.Transaction = conn.BeginTransaction(); cmd.ExecuteNonQuery(); cmd.Transaction.Commit(); } } this.Close(); } }
public frmUpdateProductTypes(_ProductType productType) { InitializeComponent(); //Fill in the form txtProductTypeID.Text = productType.ProductTypeID.ToString(); txtProductType.Text = productType.ProductType; }
private void frmUpdateProduct_Load(object sender, EventArgs e) { //Populate the combobox with the values from the ProductTypes table string populateProductType = "SELECT * FROM ProductTypes"; List <_ProductType> proTypeList = new List <_ProductType>(); try { // Automatically open and close the connection using (var conn = ConnectionManager.DatabaseConnection()) using (var cmd = new SqlCommand(populateProductType, conn)) using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { //Define the list items var productType = new _ProductType( int.Parse(rdr["ProductTypeID"].ToString()), rdr["ProductType"].ToString()); proTypeList.Add(productType); } } cbProductType.DataSource = proTypeList; cbProductType.DisplayMember = "ProductType"; cbProductType.ValueMember = "ProductTypeID"; } catch (Exception ex) { MessageBox.Show("Unsuccessful" + ex); } cbProductType.SelectedValue = updateProduct.ProductTypeID; }
private void btnSearchProductType_Click(object sender, EventArgs e) { List <_ProductType> ptList = new List <_ProductType>(); try { // Automatically open and close the connection using (var conn = ConnectionManager.DatabaseConnection()) { using (var cmd = conn.CreateCommand()) { if (rbShowAll.Checked) { cmd.CommandText = "SELECT * FROM ProductTypes"; } if (rbSearchProductTypeID.Checked) { cmd.CommandText = "SELECT * FROM ProductTypes WHERE ProductTypeID = @producttypeid"; } if (rbSearchProductType.Checked) { cmd.CommandText = "SELECT * FROM ProductTypes WHERE ProductType = @producttype"; } cmd.Parameters.AddWithValue("producttypeid", txtSearchProductTypeID.Text); cmd.Parameters.AddWithValue("producttype", txtSearchProductType.Text); cmd.Transaction = conn.BeginTransaction(); cmd.ExecuteNonQuery(); cmd.Transaction.Commit(); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { //Define the list items var producttype = new _ProductType( int.Parse(rdr["ProductTypeID"].ToString()), rdr["ProductType"].ToString()); ptList.Add(producttype); } dgvProductType.DataSource = ptList; } } } } catch (Exception ex) { MessageBox.Show("Unsuccessful" + ex); } }