private void add_btn_Click(object sender, EventArgs e) { if (username.Text.Trim() == "") { MessageBox.Show("USERNAME IS REQUIRED !!", "ERROR"); username.Focus(); return; } if (password.Text.Trim() == "") { MessageBox.Show("PASSWORD IS REQUIRED !!", "ERROR"); password.Focus(); return; } if (password2.Text.Trim() == "") { MessageBox.Show("PASSWORD VERIFICATION IS REQUIRED !!", "ERROR"); password.Focus(); return; } if (password.Text.Trim() != password2.Text.Trim()) { MessageBox.Show("PASSWORD AND PASSWORD VERIFICATION ARE MISMATCHED !!", "ERROR"); password.Focus(); return; } if (emp_id.Text == "") { MessageBox.Show("YOU DID NOT CHOOSE EMPLOYEE !!", "ERROR"); emp_id.Focus(); return; } String QueryString = "SELECT * FROM USERS WHERE USERNAME = '******'"; Dictionary <string, string> Params = new Dictionary <string, string>(); //Params.Add("@username", username.Text); using (DataTable DT = DB.getS(QueryString, Params, "CHECK IF USERNAME EXISTED", false)) { if (DT.Rows.Count > 0) { MessageBox.Show("THIS USERNAME IS ALREADY EXISTED IN DATABASE !!", "ERROR"); return; } } DataTable myDT; String unique_key = ""; do { unique_key = new Random().Next(1000000).ToString(); QueryString = "SELECT COUNT(*) ROW_COUNT FROM USERS WHERE UNIQUE_KEY = '" + unique_key + "'"; myDT = DB.getS(QueryString, null, "CHECK IF THE UNIQUE KEY IS USED.", false); } while (Convert.ToInt32(myDT.Rows[0]["ROW_COUNT"].ToString()) > 0); myDT.Dispose(); QueryString = @" INSERT INTO USERS ( username, password, emp_id, created_date, created_by, unique_key) VALUES ( '" + username.Text.Trim().Replace("'", "''") + @"', '" + GF.SHA256_encode(password.Text.Trim()) + @"', "; if (emp_id.currentID == -1) { QueryString += "NULL"; } else { QueryString += emp_id.currentID.ToString(); } QueryString += @", CONVERT(DATETIME, '" + GF.NOW() + "', 103), "; QueryString += GF.user_id.ToString() + ", '" + unique_key + "')"; GF.showLoading(this); DB.beginTrans(); if (DB.set(QueryString, "CREATE NEW USER")) { DB.close(); GF.closeLoading(); ((btn_dgv)this.Owner.Controls["btn_dgv"]).refresh_btn.PerformClick(); this.Close(); } else { MessageBox.Show("ERROR INSERT INTO DATABASE !!", "ERROR"); GF.closeLoading(); return; } }
private void manage_btn_Click(object sender, EventArgs e) { GF.showLoading(this); if (currentItemID == -1) { MessageBox.Show("PLEASE ENTER ITEM CODE !!", "ERROR"); item_code.Focus(); GF.closeLoading(); return; } if (price.Text.Trim() == "") { MessageBox.Show("PLEASE ENTER THE PRICE !!", "ERROR"); price.Focus(); GF.closeLoading(); return; } int tmp; if (!Int32.TryParse(price.Text.Trim(), out tmp)) { MessageBox.Show("PRICE MUST BE IN DIGIT !!", "ERROR"); price.Select(); GF.closeLoading(); return; } string queryString = "SELECT * FROM SPA_ITEM WHERE ITEM_ID = " + currentItemID.ToString(); if (manage_btn.Text == "UPDATE") { queryString += " AND SPA_ITEM_ID != " + GF.selected_id.ToString(); } using (DataTable myDT = DB.getS(queryString, null, "CHECK IF SPA_ITEM EXIST", false)) { if (myDT.Rows.Count > 0) { MessageBox.Show("THIS SPA_ITEM IS ALREADY EXISTED !!", "ERROR"); GF.closeLoading(); DB.rollbackTrans(); item_code.Select(); return; } } DB.beginTrans(); if (manage_btn.Text == "ADD") { queryString = "INSERT INTO SPA_ITEM (ITEM_ID, PRICE, LAST_CHANGE) VALUES ("; queryString += currentItemID.ToString() + ", "; queryString += price.Text.Trim() + ", "; queryString += GF.modDate(GF.NOW()) + ")"; if (!DB.set(queryString, "INSERT SPA_ITEM[" + currentItemID.ToString() + "]")) { MessageBox.Show("ERROR INSERT INTO SPA_ITEM[" + currentItemID.ToString() + "] !!", "ERROR"); GF.closeLoading(); DB.rollbackTrans(); return; } else { GF.closeLoading(); DB.close(); ((btn_dgv)this.Owner.Controls["btn_dgv"]).refresh_btn.PerformClick(); this.Close(); } } if (manage_btn.Text == "UPDATE") { queryString = "UPDATE SPA_ITEM SET "; queryString += "PRICE = " + price.Text.Trim() + ", "; queryString += "LAST_CHANGE = " + GF.modDate(GF.NOW()) + " "; queryString += "WHERE ITEM_ID = " + currentItemID.ToString(); if (!DB.set(queryString, "UPDATE SPA_ITEM[" + currentItemID.ToString() + "]")) { MessageBox.Show("ERROR UPDATE SPA_ITEM[" + currentItemID.ToString() + "] !!", "ERROR"); GF.closeLoading(); DB.rollbackTrans(); return; } else { GF.closeLoading(); DB.close(); ((btn_dgv)this.Owner.Controls["btn_dgv"]).refresh_btn.PerformClick(); this.Close(); } } }
private void manage_btn_Click(object sender, EventArgs e) { GF.showLoading(this); if (currentItemID == -1) { MessageBox.Show("PLEASE ENTER ITEM CODE !!", "ERROR"); item_code.Focus(); GF.closeLoading(); return; } if (price.Text.Trim() == "") { MessageBox.Show("PLEASE ENTER THE PRICE !!", "ERROR"); price.Focus(); GF.closeLoading(); return; } int tmp; if (!Int32.TryParse(price.Text.Trim(), out tmp)) { MessageBox.Show("PRICE MUST BE IN DIGIT !!", "ERROR"); price.Select(); GF.closeLoading(); return; } DB.beginTrans(); string queryString = "SELECT * FROM ITEM_PRICE WHERE ITEM_ID = " + currentItemID.ToString(); if (manage_btn.Text == "UPDATE") { queryString += " AND ITEM_PRICE_ID != " + GF.selected_id.ToString(); } using (DataTable myDT = DB.getS(queryString, null, "CHECK IF ITEM PRICE EXIST", false)) { if (myDT.Rows.Count > 0) { if (myDT.Rows[0]["IS_USE"].ToString() == "0") { queryString = "UPDATE ITEM_PRICE SET IS_USE = 1, PRICE=" + price.Text.Trim() + ", APPLY_DISCOUNT=" + (apply_discount.Checked ? "1" : "0") + " WHERE ITEM_ID = " + currentItemID.ToString(); if (!DB.set(queryString, "RE-ENABLE ITEM_ID[" + currentItemID.ToString() + "]")) { MessageBox.Show("ERROR RE-ENABLE ITEM_PRICE[" + currentItemID.ToString() + "] !!", "ERROR"); GF.closeLoading(); DB.rollbackTrans(); return; } else { GF.closeLoading(); DB.close(); ((btn_dgv)this.Owner.Controls["btn_dgv"]).refresh_btn.PerformClick(); this.Close(); } } else { MessageBox.Show("THIS ITEM IS ALREADY EXISTED !!", "ERROR"); GF.closeLoading(); DB.rollbackTrans(); item_code.Select(); return; } } } if (manage_btn.Text == "ADD") { queryString = "INSERT INTO ITEM_PRICE (ITEM_ID, PRICE, LAST_CHANGE, APPLY_DISCOUNT) VALUES ("; queryString += currentItemID.ToString() + ", "; queryString += price.Text.Trim() + ", "; queryString += GF.modDate(GF.NOW()) + ", "; queryString += (apply_discount.Checked ? "1" : "0") + ")"; if (!DB.set(queryString, "INSERT ITEM_PRICE[" + currentItemID.ToString() + "]")) { MessageBox.Show("ERROR INSERT INTO ITEM_PRICE[" + currentItemID.ToString() + "] !!", "ERROR"); GF.closeLoading(); DB.rollbackTrans(); return; } else { GF.closeLoading(); DB.close(); ((btn_dgv)this.Owner.Controls["btn_dgv"]).refresh_btn.PerformClick(); this.Close(); } } if (manage_btn.Text == "UPDATE") { queryString = "UPDATE ITEM_PRICE SET "; queryString += "PRICE = " + price.Text.Trim() + ", "; queryString += "LAST_CHANGE = " + GF.modDate(GF.NOW()) + ", "; queryString += "APPLY_DISCOUNT = " + (apply_discount.Checked ? "1" : "0") + " "; queryString += "WHERE ITEM_ID = " + currentItemID.ToString(); if (!DB.set(queryString, "UPDATE ITEM_PRICE[" + currentItemID.ToString() + "]")) { MessageBox.Show("ERROR UPDATE ITEM_PRICE[" + currentItemID.ToString() + "] !!", "ERROR"); GF.closeLoading(); DB.rollbackTrans(); return; } else { GF.closeLoading(); DB.close(); ((btn_dgv)this.Owner.Controls["btn_dgv"]).refresh_btn.PerformClick(); this.Close(); } } }