/// <summary> /// 增加一个分组 /// </summary> /// <param name="model">分组实体类</param> /// <returns></returns> public bool CreateGroup(Entity.BASE_GROUP model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Base_Group("); strSql.Append("GroupName,GroupOrder,GroupDescription,GroupType)"); strSql.Append(" values ("); strSql.Append("@GroupName,@GroupOrder,@GroupDescription,@GroupType)"); SqlParameter[] parameters = { new SqlParameter("@GroupName", SqlDbType.NVarChar, 30), new SqlParameter("@GroupOrder", SqlDbType.Int, 4), new SqlParameter("@GroupDescription", SqlDbType.NVarChar), new SqlParameter("@GroupType", SqlDbType.Int, 4) }; parameters[0].Value = model.GroupName; parameters[1].Value = model.GroupOrder; parameters[2].Value = model.GroupDescription; parameters[3].Value = model.GroupType; if (SqlServerHelper.ExecuteSql(strSql.ToString(), parameters) >= 1) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">分组实体类</param> /// <returns></returns> public bool UpdateGroup(Entity.BASE_GROUP model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Base_Group set "); strSql.Append("GroupName=@GroupName,"); strSql.Append("GroupOrder=@GroupOrder,"); strSql.Append("GroupDescription=@GroupDescription"); strSql.Append(" where GroupID=@GroupID "); SqlParameter[] parameters = { new SqlParameter("@GroupID", SqlDbType.Int, 4), new SqlParameter("@GroupName", SqlDbType.NVarChar, 30), new SqlParameter("@GroupOrder", SqlDbType.Int, 4), new SqlParameter("@GroupDescription", SqlDbType.NVarChar) }; parameters[0].Value = model.GroupID; parameters[1].Value = model.GroupName; parameters[2].Value = model.GroupOrder; parameters[3].Value = model.GroupDescription; if (SqlServerHelper.ExecuteSql(strSql.ToString(), parameters) >= 1) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Entity.BASE_GROUP entity) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Base_Group("); strSql.Append("GroupName,GroupOrder,GroupDescription,GroupType"); strSql.Append(") values ("); strSql.Append("@GroupName,@GroupOrder,@GroupDescription,@GroupType"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@GroupName", SqlDbType.NVarChar, 30), new SqlParameter("@GroupOrder", SqlDbType.Int, 4), new SqlParameter("@GroupDescription", SqlDbType.NVarChar, 50), new SqlParameter("@GroupType", SqlDbType.Int, 4) }; parameters[0].Value = entity.GroupName; parameters[1].Value = entity.GroupOrder; parameters[2].Value = entity.GroupDescription; parameters[3].Value = entity.GroupType; object obj = SqlServerHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新数据 /// </summary> protected void GroupsLists_RowUpdating(object sender, GridViewUpdateEventArgs e) { Entity.BASE_GROUP model = new Entity.BASE_GROUP(); model.GroupID = int.Parse(GroupsLists.DataKeys[e.RowIndex].Values[0].ToString()); model.GroupName = ((TextBox)GroupsLists.Rows[e.RowIndex].FindControl("txt_name")).Text.Trim(); model.GroupDescription = ((TextBox)GroupsLists.Rows[e.RowIndex].FindControl("txt_Description")).Text.Trim(); model.GroupOrder = int.Parse(((TextBox)GroupsLists.Rows[e.RowIndex].FindControl("txt_order")).Text); if (!bll.UpdateGroup(model)) { strinfo.InnerHtml = Smart.Utility.JScript.errinfo("记录更新失败!"); strinfo.Visible = true; } //返回浏览狀態 GroupsLists.EditIndex = -1; BindOrder(); }
/// <summary> /// 得到一个对象实体 /// </summary> public Entity.BASE_GROUP GetEntity(int GroupID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select GroupID, GroupName, GroupOrder, GroupDescription, GroupType "); strSql.Append(" from Base_Group "); strSql.Append(" where GroupID=@GroupID"); SqlParameter[] parameters = { new SqlParameter("@GroupID", SqlDbType.Int, 4) }; parameters[0].Value = GroupID; Entity.BASE_GROUP entity = new Entity.BASE_GROUP(); DataSet ds = SqlServerHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["GroupID"].ToString() != "") { entity.GroupID = int.Parse(ds.Tables[0].Rows[0]["GroupID"].ToString()); } entity.GroupName = ds.Tables[0].Rows[0]["GroupName"].ToString(); if (ds.Tables[0].Rows[0]["GroupOrder"].ToString() != "") { entity.GroupOrder = int.Parse(ds.Tables[0].Rows[0]["GroupOrder"].ToString()); } entity.GroupDescription = ds.Tables[0].Rows[0]["GroupDescription"].ToString(); if (ds.Tables[0].Rows[0]["GroupType"].ToString() != "") { entity.GroupType = int.Parse(ds.Tables[0].Rows[0]["GroupType"].ToString()); } return(entity); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Entity.BASE_GROUP entity) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Base_Group set "); strSql.Append(" GroupName = @GroupName , "); strSql.Append(" GroupOrder = @GroupOrder , "); strSql.Append(" GroupDescription = @GroupDescription , "); strSql.Append(" GroupType = @GroupType "); strSql.Append(" where GroupID=@GroupID "); SqlParameter[] parameters = { new SqlParameter("@GroupID", SqlDbType.Int, 4), new SqlParameter("@GroupName", SqlDbType.NVarChar, 30), new SqlParameter("@GroupOrder", SqlDbType.Int, 4), new SqlParameter("@GroupDescription", SqlDbType.NVarChar, 50), new SqlParameter("@GroupType", SqlDbType.Int, 4) }; parameters[4].Value = entity.GroupID; parameters[5].Value = entity.GroupName; parameters[6].Value = entity.GroupOrder; parameters[7].Value = entity.GroupDescription; parameters[8].Value = entity.GroupType; int rows = SqlServerHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 添加数据 /// </summary> protected void btn_add_Click(object sender, EventArgs e) { if (txt_Name.Text.Trim() != "" || txt_order.Text.Trim() != "" || Smart.Utility.TypeParse.IsUnsign(txt_order.Text.Trim())) { Entity.BASE_GROUP model = new Entity.BASE_GROUP(); model.GroupName = txt_Name.Text.Trim(); model.GroupDescription = txt_Description.Text.Trim(); model.GroupOrder = int.Parse(txt_order.Text.Trim()); model.GroupType = int.Parse(gtList.SelectedValue); if (!bll.Exists(txt_Name.Text.Trim(), int.Parse(gtList.SelectedValue))) { if (bll.CreateGroup(model)) { //strinfo.InnerHtml = Smart.Utility.JScript.errinfo("新增成功!"); //strinfo.Visible = true; BindOrder(); } else { strinfo.InnerHtml = Smart.Utility.JScript.errinfo("新增操作失败!"); strinfo.Visible = true; } txt_Name.Text = ""; txt_Description.Text = ""; txt_order.Text = ""; BindOrder(); } else { strinfo.InnerHtml = Smart.Utility.JScript.errinfo("分组已经存在,请更换后重试!"); strinfo.Visible = true; } } }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">分组实体类</param> /// <returns></returns> public bool UpdateGroup(Entity.BASE_GROUP model) { return(dal.UpdateGroup(model)); }
/// <summary> /// 增加一个分组 /// </summary> /// <param name="model">分组实体类</param> /// <returns></returns> public bool CreateGroup(Entity.BASE_GROUP model) { return(dal.CreateGroup(model)); }