public static SysRole GetSysRole(short roleid) { SysRole item = new SysRole(); try { ArrayList paras = new ArrayList(); paras.Add(DBUtils.MakeInParam("@Role_ID", SqlDbType.SmallInt, roleid)); paras.Add(DBUtils.MakeInParam("@Get_Action", SqlDbType.NVarChar, 10, DataGetAction.Row.ToString().ToLower())); SqlDataReader reader = DBUtils.ExecuteReader(CommandType.StoredProcedure, PublicConsts.DatabaseOwner + ".P_Get_SysRole", paras); if (reader.Read()) { item = PopulateSysRole(reader); } reader.Close(); } catch { throw; } return(item); }
public static void SaveSysRole(SysRole item, DataTable menus, DataTable navs, DataProviderAction action) { if (item == null) { return; } SqlConnection conn = DBUtils.GetConnection(); SqlCommand cmd = DBUtils.GetCommand(); try { cmd.Transaction = conn.BeginTransaction(); ArrayList paras = new ArrayList(); if (action == DataProviderAction.Create) { paras.Add(DBUtils.MakeOutParam("@Role_ID", SqlDbType.SmallInt)); } else { paras.Add(DBUtils.MakeInParam("@Role_ID", SqlDbType.SmallInt, item.RoleID)); } paras.Add(DBUtils.MakeInParam("@Role_Name", SqlDbType.NVarChar, 16, item.RoleName)); paras.Add(DBUtils.MakeInParam("@Role_Desc", SqlDbType.NVarChar, 60, item.RoleDesc)); paras.Add(DBUtils.MakeInParam("@Crt_Date", SqlDbType.DateTime, item.CrtDate)); paras.Add(DBUtils.MakeInParam("@Role_Man", SqlDbType.NVarChar, 6, item.RoleMan)); paras.Add(DBUtils.MakeInParam("@Auth_Bound", SqlDbType.SmallInt, item.AuthBound)); paras.Add(DBUtils.MakeInParam("@Action", SqlDbType.Int, action)); DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, PublicConsts.DatabaseOwner + ".P_Save_SysRole", paras); if (action == DataProviderAction.Create) { item.RoleID = ((((SqlParameter)paras[0]).Value != null) ? (Convert.ToInt16(((SqlParameter)paras[0]).Value)) : (short)0); } paras.Clear(); paras.Add(DBUtils.MakeInParam("@Role_ID", SqlDbType.SmallInt, item.RoleID)); DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, PublicConsts.DatabaseOwner + ".P_Delete_RoleMenuAndNav", paras); foreach (DataRow menu in menus.Rows) { if (Convert.ToBoolean(menu["Is_Select"])) { paras.Clear(); paras.Add(DBUtils.MakeInParam("@Role_ID", SqlDbType.SmallInt, item.RoleID)); paras.Add(DBUtils.MakeInParam("@M_ID", SqlDbType.SmallInt, Convert.ToInt16(menu["M_ID"]))); paras.Add(DBUtils.MakeInParam("@M_Auth", SqlDbType.Int, Convert.ToInt32(menu["Role_Auth"]))); DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, PublicConsts.DatabaseOwner + ".P_Insert_RoleMenu", paras); } } foreach (DataRow nav in navs.Rows) { if (Convert.ToBoolean(nav["Is_Select"])) { paras.Clear(); paras.Add(DBUtils.MakeInParam("@Role_ID", SqlDbType.SmallInt, item.RoleID)); paras.Add(DBUtils.MakeInParam("@Rib_Btn", SqlDbType.SmallInt, Convert.ToInt16(nav["Rib_Btn"]))); DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, PublicConsts.DatabaseOwner + ".P_Insert_RoleNav", paras); } } cmd.Transaction.Commit(); } catch { cmd.Transaction.Rollback(); throw; } finally { DBUtils.SetDispose(conn, cmd); } }