/// <summary> /// 获得Model /// </summary> /// <param name="Top">大于0取前几行数据,否则取全部</param> /// <param name="whereStr">where条件</param> /// <param name="filedOrder">排序字段Order By + filedOrder (不可为空)</param> /// <returns></returns> public Model.goods_spec_type GetModel(int Top, string whereStr, string filedOrder) { DataTable dt = dal.GetList(Top, whereStr, filedOrder).Tables[0]; Model.goods_spec_type model = dt.Rows.Count > 0 ? DataRowToModel(dt.Rows[0]) : null; return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.goods_spec_type DataRowToModel(DataRow row) { Model.goods_spec_type model = new Model.goods_spec_type(); if (row != null) { if (row["id"] != null) //&& row["id"].ToString() != "" { model.id = Convert.ToInt32(row["id"]); } if (row["goods_id"] != null) //&& row["goods_id"].ToString() != "" { model.goods_id = Convert.ToInt32(row["goods_id"]); } if (row["spec"] != null) //&& row["spec"].ToString() != "" { model.spec = Convert.ToInt32(row["spec"]); } if (row["stock"] != null) //&& row["stock"].ToString() != "" { model.stock = Convert.ToInt32(row["stock"]); } if (row["price"] != null) //&& row["price"].ToString() != "" { model.price = Convert.ToDecimal(row["price"]); } return(model); } else { return(null); } }
/// <summary> /// 获得Model /// </summary> /// <param name="whereStr"></param> /// <returns></returns> public Model.goods_spec_type GetModel(string whereStr) { DataTable dt = dal.GetList(whereStr).Tables[0]; Model.goods_spec_type model = dt.Rows.Count > 0 ? DataRowToModel(dt.Rows[0]) : null; return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.goods_spec_type model) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"UPDATE ybd_goods_spec_type SET goods_id = @goods_id ,spec = @spec ,stock = @stock ,price = @price WHERE id = @id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) , new SqlParameter("@goods_id", SqlDbType.Int, 4) , new SqlParameter("@spec", SqlDbType.Int, 4) , new SqlParameter("@stock", SqlDbType.Int, 4) , new SqlParameter("@price", SqlDbType.Decimal, 9) }; parameters[0].Value = model.id; parameters[1].Value = model.goods_id; parameters[2].Value = model.spec; parameters[3].Value = model.stock; parameters[4].Value = model.price; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void BindInfo() { BLL.goods_spec_type bll = new BLL.goods_spec_type(); Model.goods_spec_type model = bll.GetModel(this.id); if (model == null) { JscriptMsg("信息不存在或已被删除!", "back"); return; } txtgoods_id.Text = model.goods_id + ""; txtspec.Text = model.spec + ""; txtstock.Text = model.stock + ""; txtprice.Text = model.price + ""; }
//保存 protected void btnSubmit_Click(object sender, EventArgs e) { ChkAdminLevel("_ybd_goods_spec_type", EnumCollection.ActionEnum.Add.ToString()); //检查权限 #region string strError = string.Empty; if (txtgoods_id.Text.Trim() == "" || txtgoods_id.Text.Trim().Length > 4) { strError += "商品id为空或超出长度![br]"; } if (txtspec.Text.Trim() == "" || txtspec.Text.Trim().Length > 4) { strError += "规格为空或超出长度![br]"; } if (txtstock.Text.Trim() == "" || txtstock.Text.Trim().Length > 4) { strError += "库存为空或超出长度![br]"; } if (txtprice.Text.Trim() == "" || txtprice.Text.Trim().Length > 9) { strError += "价格为空或超出长度![br]"; } if (strError != string.Empty) { JscriptMsg(strError, "", "Error"); return; } #endregion Model.goods_spec_type model = new Model.goods_spec_type(); BLL.goods_spec_type bll = new BLL.goods_spec_type(); model.goods_id = Convert.ToInt32(txtgoods_id.Text); model.spec = Convert.ToInt32(txtspec.Text); model.stock = Convert.ToInt32(txtstock.Text); model.price = Convert.ToDecimal(txtprice.Text); int id = bll.Add(model); if (id > 0) { AddAdminLog(EnumCollection.ActionEnum.Add.ToString(), "添加商品规格种类信息,主键:" + id); //记录日志 JscriptMsg("添加商品规格种类信息成功!", "Manage.aspx", ""); } else { JscriptMsg("保存过程中发生错误!", ""); } }
private bool DoAdd() { Model.goods_spec_item model = new Model.goods_spec_item(); BLL.goods_spec_item bll = new BLL.goods_spec_item(); model.goods_id = this.goods_id; model.name = txtTitle.Text.Trim(); model.sort = Utils.StrToInt(txtSort.Text.Trim(), 0); model.parent_id = 0; if (this.id > 0) { Model.goods_spec_item main_mdoel = new BLL.goods_spec_item().GetModel(this.id); model.goods_id = main_mdoel.goods_id; model.parent_id = this.id; this.goods_id = model.goods_id; } int addId = bll.Add(model); if (addId > 0) { Model.goods_spec_type spec_type = new Model.goods_spec_type(); Model.goods_goods goods = new BLL.goods_goods().GetModel(this.goods_id); if (goods != null) { spec_type.goods_id = this.goods_id; spec_type.price = goods.price; spec_type.spec = addId; spec_type.stock = 100; } else { spec_type.goods_id = this.goods_id; spec_type.price = 0; spec_type.spec = addId; spec_type.stock = 100; } new BLL.goods_spec_type().Add(spec_type); return(true); } return(false); }
//保存 protected void btnSubmit_Click(object sender, EventArgs e) { ChkAdminLevel("_ybd_goods_spec_type", EnumCollection.ActionEnum.Modify.ToString()); //检查权限 BLL.goods_spec_type bll = new BLL.goods_spec_type(); Model.goods_spec_type model = bll.GetModel(this.id); model.goods_id = Convert.ToInt32(txtgoods_id.Text); model.spec = Convert.ToInt32(txtspec.Text); model.stock = Convert.ToInt32(txtstock.Text); model.price = Convert.ToDecimal(txtprice.Text); if (bll.Update(model)) { AddAdminLog(EnumCollection.ActionEnum.Modify.ToString(), "修改商品规格种类信息,主键:" + id); //记录日志 JscriptMsg("修改商品规格种类信息成功!", "Manage.aspx"); } else { JscriptMsg("保存过程中发生错误!", ""); } }
//删除规格 protected void btnDelete_Click(object sender, EventArgs e) { ChkAdminLevel("_goods_list", EnumCollection.ActionEnum.Delete.ToString()); //检查权限 BLL.goods_spec_item bll = new BLL.goods_spec_item(); for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { DataTable old_dt = new BLL.goods_spec_item().GetList("goods_id=" + goods_id + " and parent_id !=0 "); int old_sum = old_dt.AsEnumerable().GroupBy(a => a.Field <int>("parent_id")).Count(); if (bll.DeleteNew(id)) { //更新规格信息 DataTable spec_dt = new BLL.goods_spec_item().GetList("goods_id=" + goods_id + " and parent_id !=0 "); if (spec_dt.AsEnumerable().GroupBy(a => a.Field <int>("parent_id")).Count() == 1 && old_sum > 1) { for (int j = 0; j < spec_dt.Rows.Count; j++) { Model.goods_goods goods_model = new BLL.goods_goods().GetModel(Utils.StrToInt(spec_dt.Rows[j]["goods_id"].ToString(), 0)); if (goods_model != null) { Model.goods_spec_type type_model = new Model.goods_spec_type(); type_model.goods_id = goods_model.id; type_model.spec = Utils.StrToInt(spec_dt.Rows[j]["id"].ToString(), 0); type_model.price = goods_model.price; type_model.stock = 100; new BLL.goods_spec_type().Add(type_model); } } } } } } AddAdminLog(EnumCollection.ActionEnum.Delete.ToString(), "删除规格"); //记录日志 JscriptMsg("删除数据成功!", "goods_spec.aspx?page=" + this.page + "&goods_id=" + this.goods_id); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.goods_spec_type model) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"Insert Into ybd_goods_spec_type( goods_id ,spec ,stock ,price ) Values ( @goods_id ,@spec ,@stock ,@price ); SELECT @@IDENTITY;"); SqlParameter[] parameters = { new SqlParameter("@goods_id", SqlDbType.Int, 4) , new SqlParameter("@spec", SqlDbType.Int, 4) , new SqlParameter("@stock", SqlDbType.Int, 4) , new SqlParameter("@price", SqlDbType.Decimal, 9) }; parameters[0].Value = model.goods_id; parameters[1].Value = model.spec; parameters[2].Value = model.stock; parameters[3].Value = model.price; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private bool DoAdd() { BLL.goods_goods bll = new BLL.goods_goods(); Model.goods_goods model = new Model.goods_goods(); model.ct_id = 0; model.group_id = Convert.ToInt32(rbtnGroup.SelectedValue); model.category_id = Convert.ToInt32(ddlCategory.SelectedValue); model.title = Convert.ToString(txttitle.Text); model.subtitle = Convert.ToString(txtsubtitle.Text); model.img_src = Convert.ToString(txtimg_src.Text); model.oprice = Convert.ToDecimal(txtoprice.Text); model.price = Convert.ToDecimal(txtprice.Text); model.parameters = Convert.ToString(txtparameters.Text); model.details = Convert.ToString(txtdetails.Text); model.sales_num = Convert.ToInt32(txtsales_num.Text); model.status = Convert.ToInt32(rbtnStatus.SelectedValue); model.sj_time = System.DateTime.Now; model.xj_time = System.DateTime.Now; model.add_time = System.DateTime.Now; int row = bll.Add(model); if (row > 0) { #region 添加轮播图 string[] albumArr = Request.Form.GetValues("hid_photo_name"); if (albumArr != null && albumArr.Length > 0) { for (int i = 0; i < albumArr.Length; i++) { string[] imgArr = albumArr[i].Split('|'); if (imgArr.Length == 3) { Model.common_albums pic_model = new Model.common_albums(); pic_model = new Model.common_albums() { group_id = (int)EnumCollection.img_group.商品轮播图, rc_data_id = row, rc_type = 0, original_path = imgArr[1], thumb_path = imgArr[2], remark = "", add_time = DateTime.Now }; new BLL.common_albums().Add(pic_model); } } } #endregion #region 添加默认规格 BLL.goods_spec_item specBll = new BLL.goods_spec_item(); Model.goods_spec_item item = new Model.goods_spec_item(); item.name = "规格"; item.parent_id = 0; item.goods_id = row; item.sort = 1; int spec = specBll.Add(item); if (spec > 0) { item = new Model.goods_spec_item(); item.name = "平装"; item.parent_id = spec; item.goods_id = row; item.sort = 1; int subspec = specBll.Add(item); if (subspec > 0) { Model.goods_spec_type type = new Model.goods_spec_type(); type.goods_id = row; type.price = model.price; type.stock = 100; type.spec = subspec; if (new BLL.goods_spec_type().Add(type) <= 0) { specBll.DeleteList(spec + "," + subspec); } } else { specBll.Delete(spec); } } #endregion AddAdminLog(EnumCollection.ActionEnum.Modify.ToString(), "添加商品信息,主键:" + row); //记录日志 return(true); } return(false); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.goods_spec_type model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.goods_spec_type model) { return(dal.Add(model)); }