/// <summary> /// 增加一条数据 /// </summary> public int Add(Leadin.Model.ArticleType model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_ArticleType("); strSql.Append("Title,ParentId,StateInfo,SortNum,Remark)"); strSql.Append(" values ("); strSql.Append("@Title,@ParentId,@StateInfo,@SortNum,@Remark)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@ParentId", SqlDbType.Int, 4), new SqlParameter("@StateInfo", SqlDbType.Int, 4), new SqlParameter("@SortNum", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.NText) }; parameters[0].Value = model.Title; parameters[1].Value = model.ParentId; parameters[2].Value = model.StateInfo; parameters[3].Value = model.SortNum; parameters[4].Value = model.Remark; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Leadin.Model.ArticleType DataRowToModel(DataRow row) { Leadin.Model.ArticleType model = new Leadin.Model.ArticleType(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["Title"] != null) { model.Title = row["Title"].ToString(); } if (row["ParentId"] != null && row["ParentId"].ToString() != "") { model.ParentId = int.Parse(row["ParentId"].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["Remark"] != null) { model.Remark = row["Remark"].ToString(); } } return(model); }
/// <summary> /// 绑定会员类别详细信息 /// </summary> /// <param name="id"></param> void BindDetail(int id) { Leadin.Model.ArticleType model = blltype.GetModel(typeid); txtRemark.Text = model.Remark; txtSortNum.Text = model.SortNum.ToString(); txtTypeName.Text = model.Title; ckState.Checked = model.StateInfo == 1 ? true : false; }
/// <summary> /// 提交 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnOk_Click(object sender, EventArgs e) { Leadin.Model.ArticleType model = new Leadin.Model.ArticleType(); bool IsEdit = string.IsNullOrEmpty(Request.Params["id"]); if (!IsEdit) { model = blltype.GetModel(int.Parse(Request.Params["id"])); } model.ParentId = 0; model.Remark = txtRemark.Text; model.SortNum = int.Parse(txtSortNum.Text); model.StateInfo = ckState.Checked ? 1 : 0; model.Title = txtTypeName.Text; if (IsEdit) { if (blltype.Add(model) > 0) { JsMessage("success", "资讯类别添加成功!", 1000, "List.aspx"); } else { JsMessage("error", "资讯类别添加失败,请检查您的输入!", 1000, "back"); } } else { if (blltype.Update(model)) { JsMessage("success", "资讯类别编辑成功!", 1000, "List.aspx?page=" + Request.Params["page"]); } else { JsMessage("error", "资讯类别编辑失败,请检查您的输入!", 1000, "back"); } } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Leadin.Model.ArticleType model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_ArticleType set "); strSql.Append("Title=@Title,"); strSql.Append("ParentId=@ParentId,"); strSql.Append("StateInfo=@StateInfo,"); strSql.Append("SortNum=@SortNum,"); strSql.Append("Remark=@Remark"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@ParentId", SqlDbType.Int, 4), new SqlParameter("@StateInfo", SqlDbType.Int, 4), new SqlParameter("@SortNum", SqlDbType.Int, 4), new SqlParameter("@Remark", SqlDbType.NText), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.Title; parameters[1].Value = model.ParentId; parameters[2].Value = model.StateInfo; parameters[3].Value = model.SortNum; parameters[4].Value = model.Remark; parameters[5].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") { Label lbid = e.Item.FindControl("lbid") as Label; Leadin.Model.ArticleType model = bll.GetModel(int.Parse(lbid.Text)); if (model.StateInfo == 1) { model.StateInfo = 0; } else { model.StateInfo = 1; } bll.Update(model); } BindRepList(); }
/// <summary> /// 得到一个对象实体 /// </summary> public Leadin.Model.ArticleType GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Title,ParentId,StateInfo,SortNum,Remark from tb_ArticleType "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Leadin.Model.ArticleType model = new Leadin.Model.ArticleType(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }