/// <summary> /// 增加一条数据 /// </summary> public int Add(Leadin.Model.Store model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_Store("); strSql.Append("Num,Title,AddressInfo,BusinessTime,PayType,ImgUrl,Scope,City,StoreType,StateInfo,SortNum,IsHot,IsRec,IsIndex,Remark,AddTime)"); strSql.Append(" values ("); strSql.Append("@Num,@Title,@AddressInfo,@BusinessTime,@PayType,@ImgUrl,@Scope,@City,@StoreType,@StateInfo,@SortNum,@IsHot,@IsRec,@IsIndex,@Remark,@AddTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Num", SqlDbType.NVarChar, 100), new SqlParameter("@Title", SqlDbType.NVarChar, 200), new SqlParameter("@AddressInfo", SqlDbType.NVarChar, 200), new SqlParameter("@BusinessTime", SqlDbType.NVarChar, 200), new SqlParameter("@PayType", SqlDbType.NVarChar, 200), new SqlParameter("@ImgUrl", SqlDbType.NVarChar, 200), new SqlParameter("@Scope", SqlDbType.NVarChar, 200), new SqlParameter("@City", SqlDbType.Int, 4), new SqlParameter("@StoreType", SqlDbType.Int, 4), new SqlParameter("@StateInfo", SqlDbType.Int, 4), new SqlParameter("@SortNum", SqlDbType.Int, 4), new SqlParameter("@IsHot", SqlDbType.Int, 4), new SqlParameter("@IsRec", SqlDbType.Int, 4), new SqlParameter("@IsIndex", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.NText), new SqlParameter("@AddTime", SqlDbType.DateTime) }; parameters[0].Value = model.Num; parameters[1].Value = model.Title; parameters[2].Value = model.AddressInfo; parameters[3].Value = model.BusinessTime; parameters[4].Value = model.PayType; parameters[5].Value = model.ImgUrl; parameters[6].Value = model.Scope; parameters[7].Value = model.City; parameters[8].Value = model.StoreType; parameters[9].Value = model.StateInfo; parameters[10].Value = model.SortNum; parameters[11].Value = model.IsHot; parameters[12].Value = model.IsRec; parameters[13].Value = model.IsIndex; parameters[14].Value = model.Remark; parameters[15].Value = model.AddTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 提交 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnOk_Click(object sender, EventArgs e) { Leadin.Model.Store model = new Leadin.Model.Store(); bool IsEdit = string.IsNullOrEmpty(Request.Params["id"]); if (!IsEdit) { model = bll.GetModel(int.Parse(Request.Params["id"])); } model.AddressInfo = txtAddress.Text; model.BusinessTime = txtBeginTime.Text; model.City = int.Parse(Request.Form[ddlSubCity.UniqueID]); model.ImgUrl = txtfileico1.Text; model.IsHot = ckHot.Checked ? 1 : 0; model.IsIndex = ckIndex.Checked ? 1 : 0; model.IsRec = ckRec.Checked ? 1 : 0; model.PayType = txtPayType.Text; model.Remark = txtContent.Text; model.Scope = txtScope.Text; model.SortNum = int.Parse(txtSortNum.Text); model.StateInfo = ckState.Checked ? 1 : 0; model.StoreType = int.Parse(ddlType.SelectedValue); model.Title = txtName.Text; if (IsEdit) { model.Num = SetNumId("SID"); model.AddTime = DateTime.Now; if (bll.Add(model) > 0) { JsMessage("success", "门店添加成功", 1000, "List.aspx"); } else { JsMessage("error", "门店添加失败,请检查您的输入", 1000, "back"); } } else { if (bll.Update(model)) { JsMessage("success", "门店信息编辑成功", 1000, "List.aspx"); } else { JsMessage("error", "门店信息编辑失败,请检查您的输入", 1000, "back"); } } }
/// <summary> /// 绑定门店详细信息 /// </summary> /// <param name="id"></param> void BindDetail(int id) { Leadin.Model.Store model = bll.GetModel(id); txtAddress.Text = model.AddressInfo; txtBeginTime.Text = model.BusinessTime; txtContent.Text = model.Remark; txtfileico1.Text = model.ImgUrl; txtName.Text = model.Title; txtPayType.Text = model.PayType; txtScope.Text = model.Scope; txtSortNum.Text = model.SortNum.ToString(); ckHot.Checked = model.IsHot == 1 ? true : false; ckIndex.Checked = model.IsIndex == 1 ? true : false; ckRec.Checked = model.IsRec == 1 ? true : false; ckState.Checked = model.StateInfo == 1 ? true : false; ddlType.SelectedValue = model.StoreType.ToString(); int parentId = bllcity.GetModel(model.City).ParentId; DataSet ds = bllcity.GetList(0, "ParentId=0 and StateInfo=1", "SortNum desc,Id desc"); foreach (DataRow item in ds.Tables[0].Rows) { ddlCity.Items.Add(new ListItem(item["Title"].ToString(), item["Id"].ToString())); } DataSet dssub = bllcity.GetList("StateInfo=1 and ParentId=" + parentId); ddlSubCity.Items.Clear(); foreach (DataRow item in dssub.Tables[0].Rows) { ddlSubCity.Items.Add(new ListItem(item["Title"].ToString(), item["Id"].ToString())); } ddlSubCity.SelectedValue = model.City.ToString(); ddlCity.SelectedValue = parentId.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public Leadin.Model.Store GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Num,Title,AddressInfo,BusinessTime,PayType,ImgUrl,Scope,City,StoreType,StateInfo,SortNum,IsHot,IsRec,IsIndex,Remark,AddTime from tb_Store "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Leadin.Model.Store model = new Leadin.Model.Store(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Leadin.Model.Store DataRowToModel(DataRow row) { Leadin.Model.Store model = new Leadin.Model.Store(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["Num"] != null) { model.Num = row["Num"].ToString(); } if (row["Title"] != null) { model.Title = row["Title"].ToString(); } if (row["AddressInfo"] != null) { model.AddressInfo = row["AddressInfo"].ToString(); } if (row["BusinessTime"] != null) { model.BusinessTime = row["BusinessTime"].ToString(); } if (row["PayType"] != null) { model.PayType = row["PayType"].ToString(); } if (row["ImgUrl"] != null) { model.ImgUrl = row["ImgUrl"].ToString(); } if (row["Scope"] != null) { model.Scope = row["Scope"].ToString(); } if (row["City"] != null && row["City"].ToString() != "") { model.City = int.Parse(row["City"].ToString()); } if (row["StoreType"] != null && row["StoreType"].ToString() != "") { model.StoreType = int.Parse(row["StoreType"].ToString()); } if (row["StateInfo"] != null && row["StateInfo"].ToString() != "") { model.StateInfo = int.Parse(row["StateInfo"].ToString()); } if (row["SortNum"] != null && row["SortNum"].ToString() != "") { model.SortNum = int.Parse(row["SortNum"].ToString()); } if (row["IsHot"] != null && row["IsHot"].ToString() != "") { model.IsHot = int.Parse(row["IsHot"].ToString()); } if (row["IsRec"] != null && row["IsRec"].ToString() != "") { model.IsRec = int.Parse(row["IsRec"].ToString()); } if (row["IsIndex"] != null && row["IsIndex"].ToString() != "") { model.IsIndex = int.Parse(row["IsIndex"].ToString()); } if (row["Remark"] != null) { model.Remark = row["Remark"].ToString(); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(row["AddTime"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Leadin.Model.Store model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_Store set "); strSql.Append("Num=@Num,"); strSql.Append("Title=@Title,"); strSql.Append("AddressInfo=@AddressInfo,"); strSql.Append("BusinessTime=@BusinessTime,"); strSql.Append("PayType=@PayType,"); strSql.Append("ImgUrl=@ImgUrl,"); strSql.Append("Scope=@Scope,"); strSql.Append("City=@City,"); strSql.Append("StoreType=@StoreType,"); strSql.Append("StateInfo=@StateInfo,"); strSql.Append("SortNum=@SortNum,"); strSql.Append("IsHot=@IsHot,"); strSql.Append("IsRec=@IsRec,"); strSql.Append("IsIndex=@IsIndex,"); strSql.Append("Remark=@Remark,"); strSql.Append("AddTime=@AddTime"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Num", SqlDbType.NVarChar, 100), new SqlParameter("@Title", SqlDbType.NVarChar, 200), new SqlParameter("@AddressInfo", SqlDbType.NVarChar, 200), new SqlParameter("@BusinessTime", SqlDbType.NVarChar, 200), new SqlParameter("@PayType", SqlDbType.NVarChar, 200), new SqlParameter("@ImgUrl", SqlDbType.NVarChar, 200), new SqlParameter("@Scope", SqlDbType.NVarChar, 200), new SqlParameter("@City", SqlDbType.Int, 4), new SqlParameter("@StoreType", SqlDbType.Int, 4), new SqlParameter("@StateInfo", SqlDbType.Int, 4), new SqlParameter("@SortNum", SqlDbType.Int, 4), new SqlParameter("@IsHot", SqlDbType.Int, 4), new SqlParameter("@IsRec", SqlDbType.Int, 4), new SqlParameter("@IsIndex", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.NText), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.Num; parameters[1].Value = model.Title; parameters[2].Value = model.AddressInfo; parameters[3].Value = model.BusinessTime; parameters[4].Value = model.PayType; parameters[5].Value = model.ImgUrl; parameters[6].Value = model.Scope; parameters[7].Value = model.City; parameters[8].Value = model.StoreType; parameters[9].Value = model.StateInfo; parameters[10].Value = model.SortNum; parameters[11].Value = model.IsHot; parameters[12].Value = model.IsRec; parameters[13].Value = model.IsIndex; parameters[14].Value = model.Remark; parameters[15].Value = model.AddTime; parameters[16].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 属性改变 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void repList_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "lbtnState")//修改状态 { HiddenField hidid = e.Item.FindControl("hidid") as HiddenField; Leadin.Model.Store model = bll.GetModel(int.Parse(hidid.Value)); if (model.StateInfo == 1) { model.StateInfo = 0; } else { model.StateInfo = 1; } bll.Update(model); } if (e.CommandName == "lbtnIndex")//修改是否首页显示 { HiddenField hidid = e.Item.FindControl("hidid") as HiddenField; Leadin.Model.Store model = bll.GetModel(int.Parse(hidid.Value)); if (model.IsIndex == 1) { model.IsIndex = 0; } else { model.IsIndex = 1; } bll.Update(model); } if (e.CommandName == "lbtnhot")//修改是否热门显示 { HiddenField hidid = e.Item.FindControl("hidid") as HiddenField; Leadin.Model.Store model = bll.GetModel(int.Parse(hidid.Value)); if (model.IsHot == 1) { model.IsHot = 0; } else { model.IsHot = 1; } bll.Update(model); } if (e.CommandName == "lbtnRec")//修改是否推荐显示 { HiddenField hidid = e.Item.FindControl("hidid") as HiddenField; Leadin.Model.Store model = bll.GetModel(int.Parse(hidid.Value)); if (model.IsRec == 1) { model.IsRec = 0; } else { model.IsRec = 1; } bll.Update(model); } BindList(); }