private void confirm_button_Click(object sender, EventArgs e) { Connect.exec("UPDATE Product SET Product_Name='" + product_NameTextBox.Text + "' ,Discounts= '" + discountsTextBox.Text + "',Product_Price= '" + product_PriceTextBox.Text + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); Connect.exec("UPDATE Stock SET Quantity='" + quantity_textbox.Text + "',Reordering_level= '" + reordering_levelTextBox.Text + "',Shelf_location = '" + shelf_locationTextBox.Text + "',Description= '" + descriptionRichTextBox.Text + "',Dimension= '" + dimensionTextBox.Text + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); MessageBox.Show("Update Success!"); }
private void LoginBtn_Click(object sender, EventArgs e) { string sqlStr = ""; Login = false; if (txtUsername.Text.Length == 0 || txtPassword.Text.Length == 0) { MessageBox.Show("Missing username or password. " + "Please try again."); txtUsername.Clear(); txtPassword.Clear(); } else { try { DataTable dt = Connect.query("Select * from Staff WHERE Staff_ID = '" + txtUsername.Text + "' AND Password = '******'"); if (dt.Rows.Count > 0) { if (dt.Rows[0]["Staff"].ToString().Equals("True")) { Staff = true; Login = true; getVar.name = "Login As:" + dt.Rows[0]["LastName"].ToString() + " " + dt.Rows[0]["FirstName"].ToString(); getVar.storeID = dt.Rows[0]["Store_ID"].ToString(); } else { Staff = false; Login = true; getVar.name = "Login As:" + dt.Rows[0]["FirstName"].ToString(); getVar.storeID = dt.Rows[0]["Store_ID"].ToString(); } } else { MessageBox.Show("Incorrect user name or password. " + "Please try again."); txtUsername.Clear(); txtPassword.Clear(); } if (Login) { if (Staff) { Menu staffmenu = new Menu(this); staffmenu.Show(); this.Hide(); txtUsername.Clear(); txtPassword.Clear(); } else if (!Staff) { SearchItem nonstaffmenu = new SearchItem(this); nonstaffmenu.Show(); this.Hide(); txtUsername.Clear(); txtPassword.Clear(); } } } catch (Exception ex) { MessageBox.Show(ex.Message + "\nSQL: " + sqlStr); } } }
private void button3_Click(object sender, EventArgs e) { if (orderqty_textbox.Text != "" && quantity_textbox.Text != "" && (Int32.Parse(quantity_textbox.Text) >= Int32.Parse(orderqty_textbox.Text))) { Table_Temp = Connect.query("SELECT max(Invoice_No) FROM Invoice WHERE (Pay_Status=False AND Using_Status=True);"); getVar.invoice_no = Table_Temp.Rows[0][0].ToString(); Table_Temp = Connect.query("SELECT max(Invoice_No)+1 FROM Invoice WHERE (Pay_Status=True AND Using_Status=True);"); string old_invoice_no = Table_Temp.Rows[0][0].ToString(); if (getVar.invoice_no == "" && old_invoice_no == "") { getVar.invoice_no = "1"; quantity_textbox.Text = (Int32.Parse(quantity_textbox.Text) - Int32.Parse(orderqty_textbox.Text)).ToString(); Connect.exec("INSERT INTO Invoice(Invoice_No,Store_ID,Using_Status) VALUES ('" + getVar.invoice_no.ToString() + "','" + getVar.storeID.ToString() + "',True)"); Connect.exec("INSERT INTO Product_Invoice( Invoice_No,Product_ID,Quantity,Deposit ) VALUES ('" + getVar.invoice_no.ToString() + "','" + product_IDTextBox.Text + "','" + orderqty_textbox.Text + "','" + product_PriceTextBox.Text + "')"); Connect.exec("UPDATE Stock SET Quantity='" + quantity_textbox.Text + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); MessageBox.Show("Add order complete!"); } else if ((old_invoice_no.ToString() == "") && (getVar.invoice_no == "1")) { quantity_textbox.Text = (Int32.Parse(quantity_textbox.Text) - Int32.Parse(orderqty_textbox.Text)).ToString(); Table_Temp = Connect.query("SELECT Quantity FROM Product_Invoice WHERE (Invoice_No = " + getVar.invoice_no.ToString() + " AND Product_ID= " + product_IDTextBox.Text + ");"); if (!(Table_Temp.Rows.Count == 0)) { int temp = Int32.Parse(Table_Temp.Rows[0][0].ToString()) + Int32.Parse(orderqty_textbox.Value.ToString()); Connect.exec("UPDATE Product_invoice SET Quantity='" + temp + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); Connect.exec("UPDATE Stock SET Quantity='" + quantity_textbox.Text + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); MessageBox.Show("Add order complete!"); } else { //duplocate Connect.exec("INSERT INTO Product_invoice(Quantity,Product_ID,Invoice_No,Deposit) VALUES('" + orderqty_textbox.Value.ToString() + "','" + product_IDTextBox.Text + "','" + getVar.invoice_no.ToString() + "','" + product_PriceTextBox.Text + "')"); Connect.exec("UPDATE Stock SET Quantity='" + quantity_textbox.Text + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); MessageBox.Show("Add order complete!"); } } else if ((getVar.invoice_no != "") && (old_invoice_no.ToString() != "")) { Table_Temp = Connect.query("SELECT Quantity FROM Product_Invoice WHERE (Invoice_No = " + getVar.invoice_no.ToString() + " AND Product_ID= " + product_IDTextBox.Text + ");"); if (!(Table_Temp.Rows.Count == 0)) { int temp = Int32.Parse(Table_Temp.Rows[0][0].ToString()) + Int32.Parse(orderqty_textbox.Value.ToString()); Connect.exec("UPDATE Product_invoice SET Quantity='" + temp + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); Connect.exec("UPDATE Stock SET Quantity='" + quantity_textbox.Text + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); MessageBox.Show("Add order complete!"); } else { Connect.exec("INSERT INTO Product_invoice(Quantity,Product_ID,Invoice_No,Deposit) VALUES('" + orderqty_textbox.Value.ToString() + "','" + product_IDTextBox.Text + "','" + old_invoice_no.ToString() + "','" + product_PriceTextBox.Text + "')"); Connect.exec("UPDATE Stock SET Quantity='" + quantity_textbox.Text + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); MessageBox.Show("Add order complete!"); } } else { Connect.exec("INSERT INTO Invoice(Invoice_No,Store_ID,Using_Status) VALUES ('" + old_invoice_no + "','" + getVar.storeID.ToString() + "',True)"); Connect.exec("INSERT INTO Product_Invoice( Product_ID,Quantity,Deposit,Invoice_No ) VALUES ('" + product_IDTextBox.Text + "','" + orderqty_textbox.Text + "','" + product_PriceTextBox.Text + "','" + old_invoice_no.ToString() + "')"); Connect.exec("UPDATE Stock SET Quantity='" + quantity_textbox.Text + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); Table_Temp = Connect.query("SELECT Quantity FROM Product_Invoice WHERE (Invoice_No = " + old_invoice_no.ToString() + " AND Product_ID= " + product_IDTextBox.Text + ");"); int temp = Int32.Parse(Table_Temp.Rows[0][0].ToString()) + Int32.Parse(orderqty_textbox.Value.ToString()); Connect.exec("UPDATE Product_invoice SET Quantity='" + temp + "' WHERE Product_ID = " + product_IDTextBox.Text + ";"); MessageBox.Show("Add order complete!"); } } else if ((Int32.Parse(orderqty_textbox.Text) < 0)) { MessageBox.Show("Please input postive number!"); } else if (quantity_textbox.Text.ToString() == "") { MessageBox.Show("Please select item"); } else if ((Int32.Parse(quantity_textbox.Text) < Int32.Parse(orderqty_textbox.Text))) { MessageBox.Show("Not enough stock!"); } Table = Connect.query("SELECT Product.Product_ID AS [Product ID], Product.Product_Name AS [Product Name], Product.Product_Price AS [Price], Product.Discounts AS [Discount], Stock.Category_ID AS [Category], Stock.Quantity AS [Quantity], Stock.Reordering_level AS [Reordering level], Stock.Shelf_location AS [Shelf Location], Stock.Description, Stock.Dimension from Product left join Stock on Product.Product_ID = Stock.Product_ID WHERE Deleted = False;"); dataGridView1.DataSource = Table; }