/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(Base_ModuleData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into Base_Module("); strSql.Append(@"ParentId,Code,FullName,CategoryId,NavigateUrl,ImageIndex,SelectedImageIndex,Target,SortCode,Enabled, DeletionStateCode,IsPublic,IsMenu,Expand,AllowEdit,AllowDelete,Description,CreateOn,CreateUserId,CreateBy, ModifiedOn,ModifiedUserId,ModifiedBy)"); strSql.Append(" values ("); strSql.Append(@"@ParentId,@Code,@FullName,@CategoryId,@NavigateUrl,@ImageIndex,@SelectedImageIndex,@Target,@SortCode,@Enabled, @DeletionStateCode,@IsPublic,@IsMenu,@Expand,@AllowEdit,@AllowDelete,@Description,@CreateOn,@CreateUserId,@CreateBy, @ModifiedOn,@ModifiedUserId,@ModifiedBy)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@ParentId", SqlDbType.Int), new SqlParameter("@Code", SqlDbType.NVarChar,100), new SqlParameter("@FullName", SqlDbType.NVarChar,100), new SqlParameter("@CategoryId", SqlDbType.NVarChar,50), new SqlParameter("@NavigateUrl", SqlDbType.NVarChar,200), new SqlParameter("@ImageIndex", SqlDbType.NVarChar,50), new SqlParameter("@SelectedImageIndex", SqlDbType.NVarChar,50), new SqlParameter("@Target", SqlDbType.NVarChar,100), new SqlParameter("@SortCode", SqlDbType.Int), new SqlParameter("@Enabled", SqlDbType.Int), new SqlParameter("@DeletionStateCode", SqlDbType.Int), new SqlParameter("@IsPublic", SqlDbType.Int), new SqlParameter("@IsMenu", SqlDbType.Int), new SqlParameter("@Expand", SqlDbType.Int), new SqlParameter("@AllowEdit", SqlDbType.Int), new SqlParameter("@AllowDelete", SqlDbType.Int), new SqlParameter("@Description", SqlDbType.NVarChar,200), new SqlParameter("@CreateOn", SqlDbType.SmallDateTime), new SqlParameter("@CreateUserId", SqlDbType.NVarChar,50), new SqlParameter("@CreateBy", SqlDbType.NVarChar,50), new SqlParameter("@ModifiedOn", SqlDbType.SmallDateTime), new SqlParameter("@ModifiedUserId", SqlDbType.NVarChar,50), new SqlParameter("@ModifiedBy", SqlDbType.NVarChar,50) }; parameters[0].Value = model.ParentId; parameters[1].Value = model.Code; parameters[2].Value = model.FullName; parameters[3].Value = model.CategoryId; parameters[4].Value = model.NavigateUrl; parameters[5].Value = model.ImageIndex; parameters[6].Value = model.SelectedImageIndex; parameters[7].Value = model.Target; parameters[8].Value = model.SortCode; parameters[9].Value = model.Enabled; parameters[10].Value = model.DeletionStateCode; parameters[11].Value = model.IsPublic; parameters[12].Value = model.IsMenu; parameters[13].Value = model.Expand; parameters[14].Value = model.AllowEdit; parameters[15].Value = model.AllowDelete; parameters[16].Value = model.Description; parameters[17].Value = model.CreateOn == string.Empty ? null : model.CreateOn; parameters[18].Value = model.CreateUserId; parameters[19].Value = model.CreateBy; parameters[20].Value = model.ModifiedOn == string.Empty ? null : model.ModifiedOn; parameters[21].Value = model.ModifiedUserId; parameters[22].Value = model.ModifiedBy; int id = 0; try { object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ret != null && ret != DBNull.Value) { id = Convert.ToInt32(ret); } } catch (Exception ex) { throw ex; } return id; }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(Base_ModuleData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update Base_Module set "); strSql.Append("ParentId=@ParentId,"); strSql.Append("Code=@Code,"); strSql.Append("FullName=@FullName,"); strSql.Append("CategoryId=@CategoryId,"); strSql.Append("NavigateUrl=@NavigateUrl,"); strSql.Append("ImageIndex=@ImageIndex,"); strSql.Append("SelectedImageIndex=@SelectedImageIndex,"); strSql.Append("Target=@Target,"); strSql.Append("SortCode=@SortCode,"); strSql.Append("Enabled=@Enabled,"); strSql.Append("DeletionStateCode=@DeletionStateCode,"); strSql.Append("IsPublic=@IsPublic,"); strSql.Append("IsMenu=@IsMenu,"); strSql.Append("Expand=@Expand,"); strSql.Append("AllowEdit=@AllowEdit,"); strSql.Append("AllowDelete=@AllowDelete,"); strSql.Append("Description=@Description,"); strSql.Append("CreateOn=@CreateOn,"); strSql.Append("CreateUserId=@CreateUserId,"); strSql.Append("CreateBy=@CreateBy,"); strSql.Append("ModifiedOn=@ModifiedOn,"); strSql.Append("ModifiedUserId=@ModifiedUserId,"); strSql.Append("ModifiedBy=@ModifiedBy"); strSql.Append(" where Id = @Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int), new SqlParameter("@ParentId", SqlDbType.Int), new SqlParameter("@Code", SqlDbType.NVarChar,100), new SqlParameter("@FullName", SqlDbType.NVarChar,100), new SqlParameter("@CategoryId", SqlDbType.NVarChar,50), new SqlParameter("@NavigateUrl", SqlDbType.NVarChar,200), new SqlParameter("@ImageIndex", SqlDbType.NVarChar,50), new SqlParameter("@SelectedImageIndex", SqlDbType.NVarChar,50), new SqlParameter("@Target", SqlDbType.NVarChar,100), new SqlParameter("@SortCode", SqlDbType.Int), new SqlParameter("@Enabled", SqlDbType.Int), new SqlParameter("@DeletionStateCode", SqlDbType.Int), new SqlParameter("@IsPublic", SqlDbType.Int), new SqlParameter("@IsMenu", SqlDbType.Int), new SqlParameter("@Expand", SqlDbType.Int), new SqlParameter("@AllowEdit", SqlDbType.Int), new SqlParameter("@AllowDelete", SqlDbType.Int), new SqlParameter("@Description", SqlDbType.NVarChar,200), new SqlParameter("@CreateOn", SqlDbType.SmallDateTime), new SqlParameter("@CreateUserId", SqlDbType.NVarChar,50), new SqlParameter("@CreateBy", SqlDbType.NVarChar,50), new SqlParameter("@ModifiedOn", SqlDbType.SmallDateTime), new SqlParameter("@ModifiedUserId", SqlDbType.NVarChar,50), new SqlParameter("@ModifiedBy", SqlDbType.NVarChar,50) }; parameters[0].Value = model.Id; parameters[1].Value = model.ParentId; parameters[2].Value = model.Code; parameters[3].Value = model.FullName; parameters[4].Value = model.CategoryId; parameters[5].Value = model.NavigateUrl; parameters[6].Value = model.ImageIndex; parameters[7].Value = model.SelectedImageIndex; parameters[8].Value = model.Target; parameters[9].Value = model.SortCode; parameters[10].Value = model.Enabled; parameters[11].Value = model.DeletionStateCode; parameters[12].Value = model.IsPublic; parameters[13].Value = model.IsMenu; parameters[14].Value = model.Expand; parameters[15].Value = model.AllowEdit; parameters[16].Value = model.AllowDelete; parameters[17].Value = model.Description; parameters[18].Value = model.CreateOn == string.Empty ? null : model.CreateOn; parameters[19].Value = model.CreateUserId; parameters[20].Value = model.CreateBy; parameters[21].Value = model.ModifiedOn == string.Empty ? null : model.ModifiedOn; parameters[22].Value = model.ModifiedUserId; parameters[23].Value = model.ModifiedBy; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(Base_ModuleData model) { return this.ase_ModuleDB.ModifyRecord(model); }
/// <summary> /// 得到一个model /// </summary> /// <param name="Id">主键值</param> /// <returns>model</returns> public Base_ModuleData GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select Id,ParentId,Code,FullName,CategoryId,NavigateUrl,ImageIndex,SelectedImageIndex,Target,SortCode,Enabled, DeletionStateCode,IsPublic,IsMenu,Expand,AllowEdit,AllowDelete,Description,CreateOn,CreateUserId,CreateBy, ModifiedOn,ModifiedUserId,ModifiedBy from Base_Module"); strSql.Append(" where Id = @Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int) }; parameters[0].Value = Id; Base_ModuleData model = new Base_ModuleData(); DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row["Id"] != DBNull.Value) { model.Id = Convert.ToInt32(row["Id"]); } if (row["ParentId"] != DBNull.Value) { model.ParentId = Convert.ToInt32(row["ParentId"]); } if (row["Code"] != DBNull.Value) { model.Code = Convert.ToString(row["Code"]); } if (row["FullName"] != DBNull.Value) { model.FullName = Convert.ToString(row["FullName"]); } if (row["CategoryId"] != DBNull.Value) { model.CategoryId = Convert.ToString(row["CategoryId"]); } if (row["NavigateUrl"] != DBNull.Value) { model.NavigateUrl = Convert.ToString(row["NavigateUrl"]); } if (row["ImageIndex"] != DBNull.Value) { model.ImageIndex = Convert.ToString(row["ImageIndex"]); } if (row["SelectedImageIndex"] != DBNull.Value) { model.SelectedImageIndex = Convert.ToString(row["SelectedImageIndex"]); } if (row["Target"] != DBNull.Value) { model.Target = Convert.ToString(row["Target"]); } if (row["SortCode"] != DBNull.Value) { model.SortCode = Convert.ToInt32(row["SortCode"]); } if (row["Enabled"] != DBNull.Value) { model.Enabled = Convert.ToInt32(row["Enabled"]); } if (row["DeletionStateCode"] != DBNull.Value) { model.DeletionStateCode = Convert.ToInt32(row["DeletionStateCode"]); } if (row["IsPublic"] != DBNull.Value) { model.IsPublic = Convert.ToInt32(row["IsPublic"]); } if (row["IsMenu"] != DBNull.Value) { model.IsMenu = Convert.ToInt32(row["IsMenu"]); } if (row["Expand"] != DBNull.Value) { model.Expand = Convert.ToInt32(row["Expand"]); } if (row["AllowEdit"] != DBNull.Value) { model.AllowEdit = Convert.ToInt32(row["AllowEdit"]); } if (row["AllowDelete"] != DBNull.Value) { model.AllowDelete = Convert.ToInt32(row["AllowDelete"]); } if (row["Description"] != DBNull.Value) { model.Description = Convert.ToString(row["Description"]); } if (row["CreateOn"] != DBNull.Value) { model.CreateOn = Convert.ToString(row["CreateOn"]); } if (row["CreateUserId"] != DBNull.Value) { model.CreateUserId = Convert.ToString(row["CreateUserId"]); } if (row["CreateBy"] != DBNull.Value) { model.CreateBy = Convert.ToString(row["CreateBy"]); } if (row["ModifiedOn"] != DBNull.Value) { model.ModifiedOn = Convert.ToString(row["ModifiedOn"]); } if (row["ModifiedUserId"] != DBNull.Value) { model.ModifiedUserId = Convert.ToString(row["ModifiedUserId"]); } if (row["ModifiedBy"] != DBNull.Value) { model.ModifiedBy = Convert.ToString(row["ModifiedBy"]); } return model; } else { return null; } }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(Base_ModuleData model) { return this.ase_ModuleDB.AddRecord(model); }