//update Category public int UpdateCategory(EC_tb_Category ec_tb_cat, bool database_type) { if (!database_type) { return(ConnectionDB.ExecuteNonQuery("update tb_Category set [CategoryName]='" + ec_tb_cat.CategoryName + "' where CategoryID=" + ec_tb_cat.CategoryID + "")); } else { return(ConnectionDB.ExecuteNonQuery("update tb_Category set [CategoryName]=N'" + ec_tb_cat.CategoryName + "' where CategoryID=" + ec_tb_cat.CategoryID + "")); } }
//insert Category precede public int InsertCategory(EC_tb_Category ec_tb_cat, bool database_type) { if (!database_type) { return(ConnectionDB.ExecuteNonQuery("INSERT INTO tb_Category([CategoryName]) VALUES('" + ec_tb_cat.CategoryName + "')")); } else { return(ConnectionDB.ExecuteNonQuery("INSERT INTO tb_Category([CategoryName]) VALUES(N'" + ec_tb_cat.CategoryName + "')")); } }
//txbCategoryName_KeyDown private void txbCategoryName_KeyDown(object sender, KeyEventArgs e) { if (e.Key.ToString() == "Return") { if (txbCategoryName.Text == "") { tblNotification.Text = FindResource("have_not_enter_category_name").ToString(); txbCategoryName.Focus(); return; } if (bus_tb_category.GetCatagorySetting("where Upper(CategoryName)='" + txbCategoryName.Text.ToString().ToUpper() + "'").Rows.Count > 0) { tblNotification.Text = FindResource("category_name_already").ToString(); txbCategoryName.Focus(); return; } else { try { EC_tb_Category ec_tb_category = new EC_tb_Category(); //ec_tb_category.CategoryID = bus_tb_category.GetMaxCategoryID("") + 1; ec_tb_category.CategoryName = txbCategoryName.Text; if (bus_tb_category.InsertCategory(ec_tb_category, StaticClass.GeneralClass.flag_database_type_general) == 1) { if (addcategory_delegate != null) { StaticClass.GeneralClass.flag_add_edit_delete_category_general = true; addcategory_delegate(); } this.Close(); } } catch (Exception ex) { tblNotification.Text = ex.Message; } } } }
//InSertAllCategory private int InSertAllCategory(DataTable dt_category) { int result = 0; foreach (DataRow datarow in dt_category.Rows) { if (datarow[0].ToString() != "") { EC_tb_Category ec_tb_category = new EC_tb_Category(); ec_tb_category.CategoryID = Convert.ToInt32(datarow[0].ToString()); ec_tb_category.CategoryName = StaticClass.GeneralClass.HandlingSpecialCharacter(datarow[1].ToString()); if (bus_tb_category.InsertCategory(ec_tb_category, StaticClass.GeneralClass.flag_database_type_general) == 1) { result++; } } } return(result); }
//AcceptAdd private void AcceptEdit() { try { EC_tb_Category ec_tb_category = new EC_tb_Category(); if (txbCategoryName.Text == "") { tblNotification.Text = FindResource("category_name_empty").ToString(); txbCategoryName.Focus(); return; } if (bus_tb_category.GetCatagorySetting("where Upper(CategoryName)='" + txbCategoryName.Text.ToString().ToUpper() + "'").Rows.Count > 0) { tblNotification.Text = FindResource("category_name_already").ToString(); txbCategoryName.Focus(); return; } else { ec_tb_category.CategoryName = StaticClass.GeneralClass.HandlingSpecialCharacter(txbCategoryName.Text.Trim()); ec_tb_category.CategoryID = StaticClass.GeneralClass.categoryid_general; if (bus_tb_category.UpdateCategory(ec_tb_category, StaticClass.GeneralClass.flag_database_type_general) == 1) { if (lbcategory_edit_delegate != null) { StaticClass.GeneralClass.flag_add_edit_delete_category_general = true; lbcategory_edit_delegate(true); } this.Close(); } } } catch (Exception ex) { tblNotification.Text = ex.Message; } }
//muiBtnOK_Click private void muiBtnOK_Click(object sender, RoutedEventArgs e) { try { if (bus_tb_orderdetail.CheckExist(" Where CategoryID = " + StaticClass.GeneralClass.categoryid_general) != "") { tblNotification.Text = FindResource("category_uses_existing").ToString(); return; } else { EC_tb_Category ec_tb_category = new EC_tb_Category(); ec_tb_category.CategoryID = StaticClass.GeneralClass.categoryid_general; if (bus_tb_category.DeleteCategory(ec_tb_category) == 1) { CashierRegisterEntity.EC_tb_Product ec_tb_product = new CashierRegisterEntity.EC_tb_Product(); ec_tb_product.CategoryID = StaticClass.GeneralClass.categoryid_general; if (bus_tb_product.DeleteProductFromCategoryID(ec_tb_product) >= 0) { if (lbcategory_delete_delegate != null) { StaticClass.GeneralClass.flag_add_edit_delete_category_general = true; lbcategory_delete_delegate(false); } this.Close(); } } } } catch (Exception ex) { tblNotification.Text = ex.Message; } }
private long getCatIdFromCatName(string _catName) //if not exists then insert and return CatgoryID { int _rs = 0; if (!string.IsNullOrEmpty(_catName)) { int _tmp = Model.Setting.TableModel.getCatIdByName(_catName); if (_tmp <= 0) { EC_tb_Category ec_tb_category = new EC_tb_Category(); ec_tb_category.CategoryName = _catName; if (bus_tb_category.InsertCategory(ec_tb_category, StaticClass.GeneralClass.flag_database_type_general) == 1) { _rs = Model.Setting.TableModel.getCatIdByName(_catName); } } else { _rs = _tmp; } } return(_rs); }
//delete Category public int DeleteCategory(EC_tb_Category ec_tb_cat) { return(sql_tb_cat.DeleteCategory(ec_tb_cat)); }
//update Category public int UpdateCategory(EC_tb_Category ec_tb_cat, bool database_type) { return(sql_tb_cat.UpdateCategory(ec_tb_cat, database_type)); }
//insert Category public int InsertCategory(EC_tb_Category ec_tb_cat, bool database_type) { return(sql_tb_cat.InsertCategory(ec_tb_cat, database_type)); }
//delete Category public int DeleteCategory(EC_tb_Category ec_tb_cat) { return(ConnectionDB.ExecuteNonQuery("delete from tb_Category where [CategoryID]=" + ec_tb_cat.CategoryID)); }