private void RemoveButton_Click(object sender, EventArgs e) { int ID; if (int.TryParse(ProductID.Text, out ID)) { if (_PHPRepo.VerifyProductID(ID)) { _PHPRepo.GetProductbyId(ID); Product _Product = _PHPRepo.GetProductbyId(ID); _PHPRepo.deleteProduct(_Product); MessageBox.Show("Product has been deleted ", "Sucessful", MessageBoxButtons.OK, MessageBoxIcon.None); StockList.Items.Clear(); List <Product> _NewList = _PHPRepo.GetProducts(); foreach (Product p in _NewList) { string[] row = { p.ProductId.ToString(), p.Product_Name.ToString(), p.Price.ToString(), p.Stock_Level.ToString() }; var listViewItem = new ListViewItem(row); StockList.Items.Add(listViewItem); } ; ProductID.Clear(); } else { MessageBox.Show("Could not find item: " + ID); } } else { MessageBox.Show("Please enter a valid ID"); } }
private void Deletebtn_Click(object sender, EventArgs e) { try { Connect connectObj = new Connect(); con = connectObj.connect(); SqlCommand cmd = new SqlCommand("DELETE FROM PRODUCT WHERE PID = @pid", con); cmd.Parameters.AddWithValue("@pid", ProductID.Text); int i = cmd.ExecuteNonQuery(); con.Close(); //If count is equal to 1, than show frmMain form if (i != 0) { MessageBox.Show("Product Deletion Successful!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Product Deletion Failed", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } ProductName.Clear(); ProductID.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); //MessageBox.Show("Product Not found", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (con != null) { con.Close(); } } }
private void Clear_Click(object sender, EventArgs e) { ProductName.Clear(); VendorID.Clear(); Amount.Clear(); ProductID.Clear(); }
private void Submit_Click(object sender, EventArgs e) { if (ProductName.Text == "" || VendorID.Text == "" || Amount.Text == "" || ProductID.Text == "") { MessageBox.Show("Please provide all the details", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { Connect connectObj = new Connect(); con = connectObj.connect(); SqlCommand cmd = new SqlCommand("Insert into PRODUCT (PID,PNAME,AMOUNT,VID) values(@pid,@pname,@amount,@vid);", con); cmd.Parameters.AddWithValue("@pid", ProductID.Text); cmd.Parameters.AddWithValue("@pname", ProductName.Text); cmd.Parameters.AddWithValue("@vid", VendorID.Text); cmd.Parameters.AddWithValue("@amount", Amount.Text); int i = cmd.ExecuteNonQuery(); //If count is equal to 1, than show frmMain form if (i != 0) { MessageBox.Show("Product Insertion Successful!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Product Insertion Failed", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Information); } con.Close(); ProductName.Clear(); VendorID.Clear(); Amount.Clear(); ProductID.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (con != null) { con.Close(); } } }
private void Add_Click(object sender, EventArgs e) { if (ProductID.Text == "" || Quantity.Text == "" || ProductName.Text == "") { MessageBox.Show("Please provide all the details", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { Connect connectObj = new Connect(); con = connectObj.connect(); SqlCommand cmd = new SqlCommand("Insert into STOCK (PID,QUANTITY) values(@pID,@quantity);", con); cmd.Parameters.AddWithValue("@pid", ProductID.Text); cmd.Parameters.AddWithValue("@quantity", Quantity.Text); int i = cmd.ExecuteNonQuery(); //If count is equal to 1, than show frmMain form if (i != 0) { MessageBox.Show("Stock Insertion Successful!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Stock Insertion Failed", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } con.Close(); //Clear all the fields ProductID.Clear(); Quantity.Clear(); ProductName.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (con != null) { con.Close(); } } }
private void clear_Click(object sender, EventArgs e) { Cust_search.Clear(); CustName.Clear(); PhoneNumber.Clear(); Cust_address.Clear(); custEmail.Clear(); Product_search.Clear(); Product_Name.Clear(); ProductID.Clear(); Total_Amt.Text = "0"; SubTotal.Clear(); Discount.Text = "0"; GST.Clear(); PaidAmount.Clear(); ReturnAmount.Clear(); Quantity.Text = "0"; Amount.Text = "0"; AddedProducts.DataSource = null; }
private void Save_Click(object sender, EventArgs e) { //Create the orders try { Connect connectObj = new Connect(); con = connectObj.connect(); SqlCommand cmd = new SqlCommand("Insert into MYORDER (ORD_ID,CID,DATE,AMOUNT) values(@oid,@cid,@date,@amount);", con); cmd.Parameters.AddWithValue("@oid", OrderID.Text); //cmd.Parameters.AddWithValue("@pid", textBox8.Text); cmd.Parameters.AddWithValue("@cid", cid); cmd.Parameters.AddWithValue("@date", date.Text); cmd.Parameters.AddWithValue("@amount", Total_Amt.Text); int i = cmd.ExecuteNonQuery(); //If count is equal to 1, than show frmMain form if (i != 0) { MessageBox.Show("Order Insertion Successful!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Order Insertion Failed", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (con != null) { con.Close(); } } //Insert into orderDetails try { int j; Connect connectObj = new Connect(); con = connectObj.connect(); for (int i = 0; i < transactionDT.Rows.Count; i++) { SqlCommand cmd = new SqlCommand("Insert into ORDER_DETAILS (ord_id,pid,quantity) values(@oid,@pid,@quantity);", con); cmd.Parameters.AddWithValue("@oid", OrderID.Text); cmd.Parameters.AddWithValue("@pid", transactionDT.Rows[i]["Product ID"].ToString()); cmd.Parameters.AddWithValue("@quantity", transactionDT.Rows[i]["Quantity"].ToString()); j = cmd.ExecuteNonQuery(); } con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (con != null) { con.Close(); } } //Update stock table after creating order try { int j; Connect connectObj = new Connect(); con = connectObj.connect(); for (int i = 0; i < transactionDT.Rows.Count; i++) { SqlCommand cmd = new SqlCommand("UPDATE STOCK SET QUANTITY = QUANTITY - @quantity WHERE PID = @pid", con); cmd.Parameters.AddWithValue("@pid", transactionDT.Rows[i]["Product ID"].ToString()); cmd.Parameters.AddWithValue("@quantity", transactionDT.Rows[i]["Quantity"].ToString()); j = cmd.ExecuteNonQuery(); } con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (con != null) { con.Close(); } } //Clear all the fields. Cust_search.Clear(); CustName.Clear(); PhoneNumber.Clear(); Cust_address.Clear(); custEmail.Clear(); Product_search.Clear(); Product_Name.Clear(); ProductID.Clear(); Total_Amt.Text = "0"; SubTotal.Clear(); Discount.Text = "0"; GST.Clear(); PaidAmount.Clear(); ReturnAmount.Clear(); Quantity.Text = "0"; Amount.Text = "0"; AddedProducts.DataSource = null; }
private void Add_Click(object sender, EventArgs e) { String PNAME = Product_Name.Text; String PID = ProductID.Text; if (Quantity.Text == "" || Product_Name.Text == "" || ProductID.Text == "") { MessageBox.Show("Enter the Quantity!!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { Connect connectObj = new Connect(); con = connectObj.connect(); SqlCommand cmd = new SqlCommand("Select * from STOCK where PID =@pid and QUANTITY >= @quantity", con); cmd.Parameters.AddWithValue("@pid", ProductID.Text); cmd.Parameters.AddWithValue("@quantity", Quantity.Text); SqlDataAdapter adapt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapt.Fill(ds); con.Close(); int count = ds.Tables[0].Rows.Count; //If count is equal to 1, than show frmMain form if (count != 1) { MessageBox.Show("Check stock!!!!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (con != null) { con.Close(); } } decimal quantity = decimal.Parse(Quantity.Text); decimal amount = decimal.Parse(Amount.Text); decimal total = amount * quantity; decimal subtotal = decimal.Parse(SubTotal.Text); subtotal += total; if (PNAME == "") { MessageBox.Show("select a product and try again", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { transactionDT.Rows.Add(PNAME, PID, quantity, amount, total); AddedProducts.DataSource = transactionDT; SubTotal.Text = subtotal.ToString(); if (ProductID.Text == "" || OrderID.Text == "") { MessageBox.Show("Please provide all the details", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Product_Name.Clear(); ProductID.Clear(); Quantity.Text = "0"; Amount.Text = "0"; } }
private void clear_Click(object sender, EventArgs e) { ProductID.Clear(); Productname.Clear(); Quantity.Clear(); }