private SysRoleEntity GetSysRoleFromIDataReader(DbDataReader dr) { SysRoleEntity dt = new SysRoleEntity(); if (dr.FieldCount > 0) { if (dr["RoleID"].ToString() != "" || dr["RoleID"] != null) dt.RoleID = Int32.Parse(dr["RoleID"].ToString()); dt.RoleName = dr["RoleName"].ToString(); dt.RoleDesc = dr["RoleDesc"].ToString(); if (dr["DisplayOrder"].ToString() != "" || dr["DisplayOrder"] != null) dt.DisplayOrder = Int32.Parse(dr["DisplayOrder"].ToString()); dt.UseFlag = dr["UseFlag"].ToString(); dt.CreateUser = dr["CreateUser"].ToString(); dt.CreateDate = Convert.ToDateTime(dr["CreateDate"]); dt.LastModifier = dr["LastModifier"].ToString(); dt.LastModifyDate = Convert.ToDateTime(dr["LastModifyDate"]); dr.Close(); return dt; } dr.Close(); return null; }
/// <summary> /// 新增信息 /// </summary> /// <param name="_SysRoleEntity"></param> /// <returns>返回string "-1"表示该已经存在,否则成功 </returns> public string AddSysRole(SysRoleEntity _SysRoleEntity) { //判断该记录是否已经存在 DbParameter[] prams = { MakeInParam("@RoleName",(DbType)SqlDbType.VarChar,50,_SysRoleEntity.RoleName), }; string sql = "select * from [dbo].[SysRole] where RoleName=@RoleName "; if (ExecuteDataset(CommandType.Text, sql, prams).Tables[0].Rows.Count > 0) { return "-1";//该记录已经存在 } else { DbParameter[] pramsInsert = { MakeInParam("@RoleName",(DbType)SqlDbType.VarChar,50,_SysRoleEntity.RoleName ), MakeInParam("@RoleDesc",(DbType)SqlDbType.VarChar,2000,_SysRoleEntity.RoleDesc ), MakeInParam("@DisplayOrder",(DbType)SqlDbType.Int,4,_SysRoleEntity.DisplayOrder ), MakeInParam("@UseFlag",(DbType)SqlDbType.VarChar,1,_SysRoleEntity.UseFlag ), MakeInParam("@CreateUser",(DbType)SqlDbType.VarChar,50,_SysRoleEntity.CreateUser ), MakeInParam("@CreateDate",(DbType)SqlDbType.DateTime,23,_SysRoleEntity.CreateDate ), MakeInParam("@LastModifier",(DbType)SqlDbType.VarChar,50,_SysRoleEntity.LastModifier ), MakeInParam("@LastModifyDate",(DbType)SqlDbType.DateTime,23,_SysRoleEntity.LastModifyDate ), }; StringBuilder sb = new StringBuilder(); sb.Append("INSERT INTO [dbo].[SysRole]"); sb.Append("("); sb.Append(" [RoleName]"); sb.Append(",[RoleDesc]"); sb.Append(",[DisplayOrder]"); sb.Append(",[UseFlag]"); sb.Append(",[CreateUser]"); sb.Append(",[CreateDate]"); sb.Append(",[LastModifier]"); sb.Append(",[LastModifyDate]"); sb.Append(") "); sb.Append(" VALUES ("); sb.Append("@RoleName,"); sb.Append("@RoleDesc,"); sb.Append("@DisplayOrder,"); sb.Append("@UseFlag,"); sb.Append("@CreateUser,"); sb.Append("@CreateDate,"); sb.Append("@LastModifier,"); sb.Append("@LastModifyDate )"); sb.Append("select @@identity;"); string RoleID = ExecuteScalar(CommandType.Text, sb.ToString(), pramsInsert).ToString(); UpdateSysRoleUser(RoleID, _SysRoleEntity.dtUserList); return "0"; } }
/// <summary> /// 修改信息 /// </summary> /// <param name="_SysRoleEntity"></param> /// <returns>返回string "-1"表示该已经存在,否则成功 </returns> public string UpdateSysRole(SysRoleEntity _SysRoleEntity) { DbParameter[] pramsUpdate = { MakeInParam("@RoleID",(DbType)SqlDbType.Int,4,_SysRoleEntity.RoleID ), MakeInParam("@RoleName",(DbType)SqlDbType.VarChar,50,_SysRoleEntity.RoleName ), MakeInParam("@RoleDesc",(DbType)SqlDbType.VarChar,2000,_SysRoleEntity.RoleDesc ), MakeInParam("@DisplayOrder",(DbType)SqlDbType.Int,4,_SysRoleEntity.DisplayOrder ), MakeInParam("@UseFlag",(DbType)SqlDbType.VarChar,1,_SysRoleEntity.UseFlag ), MakeInParam("@CreateUser",(DbType)SqlDbType.VarChar,50,_SysRoleEntity.CreateUser ), MakeInParam("@CreateDate",(DbType)SqlDbType.DateTime,23,_SysRoleEntity.CreateDate ), MakeInParam("@LastModifier",(DbType)SqlDbType.VarChar,50,_SysRoleEntity.LastModifier ), MakeInParam("@LastModifyDate",(DbType)SqlDbType.DateTime,23,_SysRoleEntity.LastModifyDate ), }; StringBuilder sb = new StringBuilder(); sb.Append("Update [dbo].[SysRole]"); sb.Append(" set "); sb.Append(" [RoleName]=@RoleName,"); sb.Append(" [RoleDesc]=@RoleDesc,"); sb.Append(" [DisplayOrder]=@DisplayOrder,"); sb.Append(" [UseFlag]=@UseFlag,"); sb.Append(" [CreateUser]=@CreateUser,"); sb.Append(" [CreateDate]=@CreateDate,"); sb.Append(" [LastModifier]=@LastModifier,"); sb.Append(" [LastModifyDate]=@LastModifyDate "); sb.Append(" where [RoleID]=@RoleID "); ExecuteScalar(CommandType.Text, sb.ToString(), pramsUpdate); UpdateSysRoleUser(_SysRoleEntity.RoleID.ToString(), _SysRoleEntity.dtUserList); return "0"; }
private string SaveData() { SysRoleEntity _SysRoleEntity = new SysRoleEntity(); _SysRoleEntity.RoleID = Convert.ToInt32(txtRoleID.Value != string.Empty ? txtRoleID.Value : "0"); _SysRoleEntity.RoleName = txtRoleName.Text; _SysRoleEntity.RoleDesc = txtRoleDesc.Text; _SysRoleEntity.DisplayOrder = Convert.ToInt32(txtDisplayOrder.Text != string.Empty ? txtDisplayOrder.Text : "99990"); _SysRoleEntity.UseFlag = chkUseFlag.Checked ? "1" : "0"; _SysRoleEntity.CreateUser = userEntity.UserID; _SysRoleEntity.CreateDate = DateTime.Now; _SysRoleEntity.LastModifier = userEntity.UserID; _SysRoleEntity.LastModifyDate = DateTime.Now; _SysRoleEntity.dtUserList = (DataTable)ViewState["dtUserList"]; string sResult = "-1"; if (strOperationState == "Add") sResult = DbHelper.GetInstance().AddSysRole(_SysRoleEntity); else if (strOperationState == "Update") sResult = DbHelper.GetInstance().UpdateSysRole(_SysRoleEntity); ArrayList arl = new ArrayList(); arl.Add("SysRole"); arl.Add(""); arl.Add(""); sResult = DbHelper.GetInstance().sp_ReDisplayOrder(arl); return sResult; }