/// <summary> /// 重写虚方法,此方法将在Init事件前执行 /// </summary> protected override void ShowPage() { id = DTRequest.GetQueryInt("id"); page = DTRequest.GetQueryString("page"); BLL.meal_good bll = new BLL.meal_good(); if (id > 0) //如果ID获取到,将使用ID { if (bll.GetList("meal_id='" + id + "'").Tables[0].Rows.Count <= 0) { HttpContext.Current.Response.Redirect(linkurl("error", "?msg=" + Utils.UrlEncode("出错啦,您要浏览的页面不存在或已删除啦!"))); return; } // model = bll.GetModel(id); model_meal = new BLL.meal().GetModel(id); if (model_meal == null) { HttpContext.Current.Response.Redirect(linkurl("error", "?msg=" + Utils.UrlEncode("出错啦,您要浏览的页面不存在或已删除啦!"))); return; } dt = bll.GetList("meal_id='"+id+"'").Tables[0]; } //跳转URL if (model.link_url != null) model.link_url = model.link_url.Trim(); if (!string.IsNullOrEmpty(model.link_url)) { HttpContext.Current.Response.Redirect(model.link_url); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.meal GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, title, category_id, img_url, add_time ,index_url ,sort_id"); strSql.Append(" from td_meal "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.meal model = new Model.meal(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.title = ds.Tables[0].Rows[0]["title"].ToString(); if (ds.Tables[0].Rows[0]["category_id"].ToString() != "") { model.category_id = int.Parse(ds.Tables[0].Rows[0]["category_id"].ToString()); } model.img_url = ds.Tables[0].Rows[0]["img_url"].ToString(); if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } model.index_url = ds.Tables[0].Rows[0]["index_url"].ToString(); if (ds.Tables[0].Rows[0]["sort_id"].ToString() != "") { model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.meal model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update td_meal set "); strSql.Append(" title = @title , "); strSql.Append(" category_id = @category_id , "); strSql.Append(" img_url = @img_url , "); strSql.Append(" add_time = @add_time, "); strSql.Append(" index_url=@index_url, "); strSql.Append(" sort_id=@sort_id "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 50), new SqlParameter("@category_id", SqlDbType.Int, 4), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@index_url", SqlDbType.NVarChar, 255), new SqlParameter("@sort_id", SqlDbType.Int, 4) }; parameters[0].Value = model.id; parameters[1].Value = model.title; parameters[2].Value = model.category_id; parameters[3].Value = model.img_url; parameters[4].Value = model.add_time; parameters[5].Value = model.index_url; parameters[6].Value = model.sort_id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.meal model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into td_meal("); strSql.Append("title,category_id,img_url,add_time,index_url,sort_id"); strSql.Append(") values ("); strSql.Append("@title,@category_id,@img_url,@add_time,@index_url,@sort_id"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.NVarChar, 50), new SqlParameter("@category_id", SqlDbType.Int, 4), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@index_url", SqlDbType.NVarChar, 255), new SqlParameter("@sort_id", SqlDbType.Int, 4) }; parameters[0].Value = model.title; parameters[1].Value = model.category_id; parameters[2].Value = model.img_url; parameters[3].Value = model.add_time; parameters[4].Value = model.index_url; parameters[5].Value = model.sort_id; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 重写虚方法,此方法将在Init事件前执行 /// </summary> protected override void ShowPage() { id = DTRequest.GetQueryInt("id"); page = DTRequest.GetQueryString("page"); BLL.meal_good bll = new BLL.meal_good(); if (id > 0) //如果ID获取到,将使用ID { if (bll.GetList("meal_id='" + id + "'").Tables[0].Rows.Count <= 0) { HttpContext.Current.Response.Redirect(linkurl("error", "?msg=" + Utils.UrlEncode("出错啦,您要浏览的页面不存在或已删除啦!"))); return; } // model = bll.GetModel(id); model_meal = new BLL.meal().GetModel(id); if (model_meal == null) { HttpContext.Current.Response.Redirect(linkurl("error", "?msg=" + Utils.UrlEncode("出错啦,您要浏览的页面不存在或已删除啦!"))); return; } dt = bll.GetList("meal_id='" + id + "'").Tables[0]; } //跳转URL if (model.link_url != null) { model.link_url = model.link_url.Trim(); } if (!string.IsNullOrEmpty(model.link_url)) { HttpContext.Current.Response.Redirect(model.link_url); } }
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; }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.meal GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, title, category_id, img_url, add_time ,index_url ,sort_id"); strSql.Append(" from td_meal "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Model.meal model = new Model.meal(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.title = ds.Tables[0].Rows[0]["title"].ToString(); if (ds.Tables[0].Rows[0]["category_id"].ToString() != "") { model.category_id = int.Parse(ds.Tables[0].Rows[0]["category_id"].ToString()); } model.img_url = ds.Tables[0].Rows[0]["img_url"].ToString(); if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } model.index_url = ds.Tables[0].Rows[0]["index_url"].ToString(); if (ds.Tables[0].Rows[0]["sort_id"].ToString() != "") { model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString()); } return model; } else { return null; } }
private void ShowInfo(int _id) { BLL.meal bll = new BLL.meal(); Model.meal model = bll.GetModel(_id); ddlCategoryId.SelectedValue = model.category_id.ToString(); txt_title.Text = model.title; txtImgUrl.Text = model.img_url; txtIndexUrl.Text = model.index_url; txtSortId.Text = model.sort_id.ToString(); BLL.meal_good bll_meal_good = new BLL.meal_good(); DataTable dt_meal_good = bll_meal_good.GetList("meal_id=" + _id).Tables[0]; string str_ck = ""; string str_standard_good_price_ids = ","; foreach (DataRow dr in dt_meal_good.Rows) { if (str_standard_good_price_ids.IndexOf("," + (Convert.ToInt32(dr["meal_id"]) + "-" + Convert.ToInt32(dr["good_id"]) + "-" + Convert.ToDecimal(dr["standard_price_id"]) + "-" + Convert.ToDecimal(dr["unit_id"])) + ",") > -1) { continue; } str_standard_good_price_ids += Convert.ToInt32(dr["meal_id"]) + "-" + Convert.ToInt32(dr["good_id"]) + "-" + Convert.ToDecimal(dr["standard_price_id"]) + "-" + Convert.ToDecimal(dr["unit_id"]) + ","; Model.article model_good = new BLL.article().GetModel(Convert.ToInt32(dr["good_id"])); if (model_good != null) { //单位 string unit = ""; string str_quantity = ",数量:" + Convert.ToInt32(dr["quantity"]); Model.unit model_unit = new BLL.unit().GetModel(Convert.ToInt32(dr["unit_id"])); if (model_unit != null) { unit = ",单位:" + model_unit.title; if (!string.IsNullOrEmpty(model_unit.content)) { unit += "(" + model_unit.content + ")"; } } //规格 string standard = ""; BLL.standard_price bll_standard_price = new BLL.standard_price(); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(dr["standard_price_id"])); if (model_standard_price != null) { if (!string.IsNullOrEmpty(model_standard_price.standards)) { string[] arr_standard = model_standard_price.standards.Split(','); string[] arr_standard_value = model_standard_price.standard_values.Split(','); for (int i = 0; i < arr_standard.Length; i++) { standard += arr_standard[i] + ":"; if (i < arr_standard_value.Length) { standard += arr_standard_value[i]; } standard += ","; } } } if (!string.IsNullOrEmpty(standard)) { standard = standard.Substring(0, standard.Length - 1); } str_ck += "<span onclick='ck_goods(this)'>" + model_good.title + str_quantity + unit + " " + standard + "<input type='checkbox' name='ck_good' style='display:none;' value='" + model_good.id + "_" + Convert.ToDecimal(dr["standard_price_id"]) + "_" + Convert.ToInt32(dr["unit_id"]) + "_" + Convert.ToInt32(dr["quantity"]) + "' checked='checked'/></span><br />"; } goods.InnerHtml = str_ck; } }
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); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.meal model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.meal model) { return(dal.Add(model)); }