/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.meal_good model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update td_meal_good set "); strSql.Append(" meal_id = @meal_id , "); strSql.Append(" group_id = @group_id , "); strSql.Append(" good_id = @good_id , "); strSql.Append(" standard_price_id = @standard_price_id , "); strSql.Append(" unit_id = @unit_id , "); strSql.Append(" sell_price = @sell_price , "); strSql.Append(" standard_price = @standard_price , "); strSql.Append(" standard_group_price = @standard_group_price , "); strSql.Append(" add_time = @add_time, "); strSql.Append(" action_price=@action_price, "); strSql.Append(" quantity=@quantity "); strSql.Append(" where meal_id=@meal_id and group_id=@group_id and good_id=@good_id and standard_price_id=@standard_price_id and unit_id=@unit_id "); SqlParameter[] parameters = { new SqlParameter("@meal_id", SqlDbType.Int, 4), new SqlParameter("@group_id", SqlDbType.Int, 4), new SqlParameter("@good_id", SqlDbType.Int, 4), new SqlParameter("@standard_price_id", SqlDbType.Decimal, 9), new SqlParameter("@unit_id", SqlDbType.Int, 4), new SqlParameter("@sell_price", SqlDbType.Decimal, 9), new SqlParameter("@standard_price", SqlDbType.Decimal, 9), new SqlParameter("@standard_group_price", SqlDbType.Decimal, 9), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@action_price", SqlDbType.Decimal, 9), new SqlParameter("@quantity", SqlDbType.Int, 4) }; parameters[0].Value = model.meal_id; parameters[1].Value = model.group_id; parameters[2].Value = model.good_id; parameters[3].Value = model.standard_price_id; parameters[4].Value = model.unit_id; parameters[5].Value = model.sell_price; parameters[6].Value = model.standard_price; parameters[7].Value = model.standard_group_price; parameters[8].Value = model.add_time; parameters[9].Value = model.action_price; parameters[10].Value = model.quantity; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public void Add(Model.meal_good model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into td_meal_good("); strSql.Append("meal_id,group_id,good_id,standard_price_id,unit_id,sell_price,standard_price,standard_group_price,add_time,action_price,quantity"); strSql.Append(") values ("); strSql.Append("@meal_id,@group_id,@good_id,@standard_price_id,@unit_id,@sell_price,@standard_price,@standard_group_price,@add_time,@action_price,@quantity"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@meal_id", SqlDbType.Int, 4), new SqlParameter("@group_id", SqlDbType.Int, 4), new SqlParameter("@good_id", SqlDbType.Int, 4), new SqlParameter("@standard_price_id", SqlDbType.Decimal, 9), new SqlParameter("@unit_id", SqlDbType.Int, 4), new SqlParameter("@sell_price", SqlDbType.Decimal, 9), new SqlParameter("@standard_price", SqlDbType.Decimal, 9), new SqlParameter("@standard_group_price", SqlDbType.Decimal, 9), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@action_price", SqlDbType.Decimal, 9), new SqlParameter("@quantity", SqlDbType.Int, 4) }; parameters[0].Value = model.meal_id; parameters[1].Value = model.group_id; parameters[2].Value = model.good_id; parameters[3].Value = model.standard_price_id; parameters[4].Value = model.unit_id; parameters[5].Value = model.sell_price; parameters[6].Value = model.standard_price; parameters[7].Value = model.standard_group_price; parameters[8].Value = model.add_time; parameters[9].Value = model.action_price; parameters[10].Value = model.quantity; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.meal_good GetModel(int meal_id, int group_id, int good_id, decimal standard_price_id, int unit_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select meal_id, group_id, good_id, standard_price_id, unit_id, sell_price, standard_price, standard_group_price, add_time ,action_price,quantity "); strSql.Append(" from td_meal_good "); strSql.Append(" where meal_id=@meal_id and group_id=@group_id and good_id=@good_id and standard_price_id=@standard_price_id and unit_id=@unit_id"); SqlParameter[] parameters = { new SqlParameter("@meal_id", SqlDbType.Int, 4), new SqlParameter("@group_id", SqlDbType.Int, 4), new SqlParameter("@good_id", SqlDbType.Int, 4), new SqlParameter("@standard_price_id", SqlDbType.Decimal, 9), new SqlParameter("@unit_id", SqlDbType.Int, 4) }; parameters[0].Value = meal_id; parameters[1].Value = group_id; parameters[2].Value = good_id; parameters[3].Value = standard_price_id; parameters[4].Value = unit_id; Model.meal_good model = new Model.meal_good(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["meal_id"].ToString() != "") { model.meal_id = int.Parse(ds.Tables[0].Rows[0]["meal_id"].ToString()); } if (ds.Tables[0].Rows[0]["group_id"].ToString() != "") { model.group_id = int.Parse(ds.Tables[0].Rows[0]["group_id"].ToString()); } if (ds.Tables[0].Rows[0]["good_id"].ToString() != "") { model.good_id = int.Parse(ds.Tables[0].Rows[0]["good_id"].ToString()); } if (ds.Tables[0].Rows[0]["standard_price_id"].ToString() != "") { model.standard_price_id = decimal.Parse(ds.Tables[0].Rows[0]["standard_price_id"].ToString()); } if (ds.Tables[0].Rows[0]["unit_id"].ToString() != "") { model.unit_id = int.Parse(ds.Tables[0].Rows[0]["unit_id"].ToString()); } if (ds.Tables[0].Rows[0]["sell_price"].ToString() != "") { model.sell_price = decimal.Parse(ds.Tables[0].Rows[0]["sell_price"].ToString()); } if (ds.Tables[0].Rows[0]["standard_price"].ToString() != "") { model.standard_price = decimal.Parse(ds.Tables[0].Rows[0]["standard_price"].ToString()); } if (ds.Tables[0].Rows[0]["standard_group_price"].ToString() != "") { model.standard_group_price = decimal.Parse(ds.Tables[0].Rows[0]["standard_group_price"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } if (ds.Tables[0].Rows[0]["action_price"].ToString() != "") { model.action_price = decimal.Parse(ds.Tables[0].Rows[0]["action_price"].ToString()); } if (ds.Tables[0].Rows[0]["quantity"].ToString() != "") { model.quantity = int.Parse(ds.Tables[0].Rows[0]["quantity"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.meal_good GetModel(int meal_id, int group_id, int good_id, decimal standard_price_id, int unit_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select meal_id, group_id, good_id, standard_price_id, unit_id, sell_price, standard_price, standard_group_price, add_time ,action_price,quantity "); strSql.Append(" from td_meal_good "); strSql.Append(" where meal_id=@meal_id and group_id=@group_id and good_id=@good_id and standard_price_id=@standard_price_id and unit_id=@unit_id"); SqlParameter[] parameters = { new SqlParameter("@meal_id", SqlDbType.Int,4), new SqlParameter("@group_id", SqlDbType.Int,4), new SqlParameter("@good_id", SqlDbType.Int,4), new SqlParameter("@standard_price_id", SqlDbType.Decimal,9), new SqlParameter("@unit_id", SqlDbType.Int,4) }; parameters[0].Value = meal_id; parameters[1].Value = group_id; parameters[2].Value = good_id; parameters[3].Value = standard_price_id; parameters[4].Value = unit_id; Model.meal_good model = new Model.meal_good(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["meal_id"].ToString() != "") { model.meal_id = int.Parse(ds.Tables[0].Rows[0]["meal_id"].ToString()); } if (ds.Tables[0].Rows[0]["group_id"].ToString() != "") { model.group_id = int.Parse(ds.Tables[0].Rows[0]["group_id"].ToString()); } if (ds.Tables[0].Rows[0]["good_id"].ToString() != "") { model.good_id = int.Parse(ds.Tables[0].Rows[0]["good_id"].ToString()); } if (ds.Tables[0].Rows[0]["standard_price_id"].ToString() != "") { model.standard_price_id = decimal.Parse(ds.Tables[0].Rows[0]["standard_price_id"].ToString()); } if (ds.Tables[0].Rows[0]["unit_id"].ToString() != "") { model.unit_id = int.Parse(ds.Tables[0].Rows[0]["unit_id"].ToString()); } if (ds.Tables[0].Rows[0]["sell_price"].ToString() != "") { model.sell_price = decimal.Parse(ds.Tables[0].Rows[0]["sell_price"].ToString()); } if (ds.Tables[0].Rows[0]["standard_price"].ToString() != "") { model.standard_price = decimal.Parse(ds.Tables[0].Rows[0]["standard_price"].ToString()); } if (ds.Tables[0].Rows[0]["standard_group_price"].ToString() != "") { model.standard_group_price = decimal.Parse(ds.Tables[0].Rows[0]["standard_group_price"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } if (ds.Tables[0].Rows[0]["action_price"].ToString() != "") { model.action_price = decimal.Parse(ds.Tables[0].Rows[0]["action_price"].ToString()); } if (ds.Tables[0].Rows[0]["quantity"].ToString() != "") { model.quantity = int.Parse(ds.Tables[0].Rows[0]["quantity"].ToString()); } return model; } else { return null; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.meal_good model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public void Add(Model.meal_good model) { dal.Add(model); }
private bool DoAdd() { bool result = false; string check_good = DTRequest.GetFormString("ck_good"); if (string.IsNullOrEmpty(check_good)) { JscriptMsg("请选择商品!", "", "Error"); return false; } BLL.meal bll = new BLL.meal(); Model.meal model = new Model.meal(); model.title = txt_title.Text.Trim(); model.category_id = Convert.ToInt32(ddlCategoryId.SelectedValue); model.img_url = txtImgUrl.Text.Trim(); model.add_time = DateTime.Now; model.index_url = txtIndexUrl.Text.Trim(); model.sort_id = int.Parse(txtSortId.Text.ToString()); BLL.standard_price bll_standard_price = new BLL.standard_price(); int _meal_id = bll.Add(model); if (_meal_id > 0) { BLL.meal_good bll_meal_good = new BLL.meal_good(); string[] arr_str = check_good.Split(','); BLL.standard_group_price bll_standard_group_price = new BLL.standard_group_price(); for (int i = 0; i < arr_str.Length; i++) { Model.article model_good = new Model.article(); model_good = new BLL.article().GetModel(Convert.ToInt32(arr_str[i].Split('_')[0])); if (model_good != null) { if (!string.IsNullOrEmpty(arr_str[i])) { DataTable dt_standard_group_price = bll_standard_group_price.GetList("good_id=" + arr_str[i].Split('_')[0] + " and standard_price_id=" + arr_str[i].Split('_')[1]).Tables[0]; if (dt_standard_group_price != null && dt_standard_group_price.Rows.Count > 0) { //有会员规格价格 商品ID_规格价格ID_单位ID_数量 默认sell_price 规格价格standard_price(有规格未登入) 组别价格standard_group_price(不管有没有规格已登入) foreach (DataRow dr_group_price in dt_standard_group_price.Rows) { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = Convert.ToInt32(dr_group_price["group_id"]); model_meal_good.meal_id = _meal_id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(dr_group_price["group_price"]); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } else { if (model_good.group_price.Count > 0) { foreach (Model.user_group_price model_user_group in model_good.group_price) { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = model_user_group.group_id; model_meal_good.meal_id = _meal_id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(model_user_group.price); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } else { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = 0; model_meal_good.meal_id = _meal_id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } } } } //AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加用户:" + model.user_name); //记录日志 result = true; } return result; }
private bool DoEdit(int _id) { string check_good = DTRequest.GetFormString("ck_good"); if (string.IsNullOrEmpty(check_good)) { JscriptMsg("请选择商品!", "", "Error"); return(false); } bool result = false; BLL.meal bll = new BLL.meal(); Model.meal model = bll.GetModel(_id); model.title = txt_title.Text.Trim(); model.img_url = txtImgUrl.Text.Trim(); model.category_id = Convert.ToInt32(ddlCategoryId.SelectedValue); model.index_url = txtIndexUrl.Text.Trim(); model.sort_id = int.Parse(txtSortId.Text.ToString()); if (bll.Update(model)) { BLL.standard_price bll_standard_price = new BLL.standard_price(); BLL.meal_good bll_meal_good = new BLL.meal_good(); bll_meal_good.Delete(_id); string[] arr_str = check_good.Split(','); BLL.standard_group_price bll_standard_group_price = new BLL.standard_group_price(); for (int i = 0; i < arr_str.Length; i++) { Model.article model_good = new Model.article(); model_good = new BLL.article().GetModel(Convert.ToInt32(arr_str[i].Split('_')[0])); if (model_good != null) { if (!string.IsNullOrEmpty(arr_str[i])) { DataTable dt_standard_group_price = bll_standard_group_price.GetList("good_id=" + arr_str[i].Split('_')[0] + " and standard_price_id=" + arr_str[i].Split('_')[1]).Tables[0]; if (dt_standard_group_price != null && dt_standard_group_price.Rows.Count > 0) { //有会员规格价格 foreach (DataRow dr_group_price in dt_standard_group_price.Rows) { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = Convert.ToInt32(dr_group_price["group_id"]); model_meal_good.meal_id = _id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(dr_group_price["group_price"]); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } else { if (model_good.group_price.Count > 0) { foreach (Model.user_group_price model_user_group in model_good.group_price) { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = model_user_group.group_id; model_meal_good.meal_id = _id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(model_user_group.price); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } else { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = 0; model_meal_good.meal_id = _id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } } } } //AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改用户信息:" + model.user_name); //记录日志 result = true; } return(result); }