public List <SYS_RightOfUser> SelectAllSYS_RightOfUser() { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); List <SYS_RightOfUser> sys_rightofuser = new List <SYS_RightOfUser>(); DbDataReader reader = null; try { reader = _DbHelper.ExecuteReader(conn, Common.DatabaseSchema + "[SYS_RightOfUser_SelectAll]", (DbParameter[])null); if (reader.HasRows) { SYS_RightOfUserDataAccess.SetListSYS_RightOfUserInfo(ref reader, ref sys_rightofuser); } return(sys_rightofuser); } catch (Exception ex) { throw new Exception(String.Format(" SYS_RightOfUserDataAccess.SelectAll: {0}", ex.Message)); } finally { if (reader != null) { reader.Close(); } conn.Close(); } }
public SYS_RightOfUser SelectSYS_RightOfUser(int ID) { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); SYS_RightOfUser sys_rightofuser = new SYS_RightOfUser(); DbDataReader reader = null; try { List <DbParameter> para = new List <DbParameter>(); para.Add(_DbHelper.CreateParameter(FIELD_ID, ID, false)); reader = _DbHelper.ExecuteReader(conn, Common.DatabaseSchema + "[SYS_RightOfUser_SelectById]", para.ToArray()); if (reader.HasRows && reader.Read()) { SYS_RightOfUserDataAccess.SetSYS_RightOfUserInfo(reader, ref sys_rightofuser); } return(sys_rightofuser); } catch (Exception ex) { throw new Exception(String.Format("SYS_RightOfUserDataAccess.SelectById: {0}", ex.Message)); } finally { if (reader != null) { reader.Close(); } conn.Close(); } }
private static void SetListSYS_RightOfUserInfo(ref DbDataReader reader, ref List <SYS_RightOfUser> sys_rightofusers) { SYS_RightOfUser sys_rightofuser = null; while (reader.Read()) { sys_rightofuser = new SYS_RightOfUser(); SYS_RightOfUserDataAccess.SetSYS_RightOfUserInfo(reader, ref sys_rightofuser); sys_rightofusers.Add(sys_rightofuser); } }
public int InsertSYS_UserAll(DM_USER dm_user) { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); SYS_RoleOfUserDataAccess sysRoleOfUserDataAccess = new SYS_RoleOfUserDataAccess(); SYS_RightOfUserDataAccess sysRightOfUserDataAccess = new SYS_RightOfUserDataAccess(); try { List <DbParameter> para = new List <DbParameter>(); DbParameter ouput = _DbHelper.CreateParameter(FIELD_IDUSER, DbType.Int32, true); para.Add(_DbHelper.CreateParameter(FIELD_IDMA_DVIQLY, dm_user.IDMA_DVIQLY, false)); para.Add(_DbHelper.CreateParameter(FIELD_XACNHAN, dm_user.XACNHAN, false)); para.Add(_DbHelper.CreateParameter(FIELD_USERNAME, dm_user.USERNAME, false)); para.Add(_DbHelper.CreateParameter(FIELD_PASSWORD, dm_user.PASSWORD, false)); para.Add(_DbHelper.CreateParameter(FIELD_HOTEN, dm_user.HOTEN, false)); para.Add(_DbHelper.CreateParameter(FIELD_DIACHI, dm_user.DIACHI, false)); para.Add(_DbHelper.CreateParameter(FIELD_SODT, dm_user.SODT, false)); para.Add(_DbHelper.CreateParameter(FIELD_EMAIL, dm_user.EMAIL, false)); para.Add(_DbHelper.CreateParameter(FIELD_NGAYSINH, dm_user.NGAYSINH, false)); para.Add(_DbHelper.CreateParameter(FIELD_NGAYTAO, dm_user.NGAYTAO, false)); para.Add(_DbHelper.CreateParameter(FIELD_IS_ADMIN, dm_user.IS_ADMIN, false)); para.Add(_DbHelper.CreateParameter(FIELD_CHUCDANH, dm_user.CHUCDANH, false)); para.Add(ouput); _DbHelper.ExecuteNonQuery(conn, Common.DatabaseSchema + "[DM_USER_Insert]", para.ToArray()); dm_user.IDUSER = (int)ouput.Value; SYS_RoleOfUser sysRoleOfUser = new SYS_RoleOfUser(); sysRoleOfUser.RoleId = dm_user.Roles.ID; //sysRoleOfUser.RoleId = sys_user.IDOrganization; sysRoleOfUser.UserId = dm_user.IDUSER; if (dm_user.Roles.ID != 0) { sysRoleOfUserDataAccess.InsertSYS_RoleOfUser(sysRoleOfUser); } } catch (Exception ex) { throw new Exception(String.Format("SYS_UserDataAccess.Insert: {0}", ex.Message)); } finally { conn.Close(); } return(dm_user.IDUSER); }
public int InsertSYS_UserAll(SYS_User sys_user) { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); SYS_RoleOfUserDataAccess sysRoleOfUserDataAccess = new SYS_RoleOfUserDataAccess(); SYS_RightOfUserDataAccess sysRightOfUserDataAccess = new SYS_RightOfUserDataAccess(); try { List <DbParameter> para = new List <DbParameter>(); DbParameter ouput = _DbHelper.CreateParameter(FIELD_ID, DbType.Int32, true); para.Add(_DbHelper.CreateParameter(FIELD_USERNAME, sys_user.UserName, false)); para.Add(_DbHelper.CreateParameter(FIELD_PASSWORD, sys_user.Password, false)); para.Add(_DbHelper.CreateParameter(FIELD_FIRSTNAME, sys_user.FirstName, false)); para.Add(_DbHelper.CreateParameter(FIELD_MIDNAME, sys_user.MidName, false)); para.Add(_DbHelper.CreateParameter(FIELD_LASTNAME, sys_user.LastName, false)); para.Add(_DbHelper.CreateParameter(FIELD_EMAIL, sys_user.Email, false)); para.Add(_DbHelper.CreateParameter(FIELD_ISACTIVE, sys_user.IsActive, false)); para.Add(_DbHelper.CreateParameter(FIELD_NUMBERPHONE, sys_user.NumberPhone, false)); para.Add(_DbHelper.CreateParameter(FIELD_IDORGANIZATION, sys_user.IDOrganization, false)); para.Add(ouput); _DbHelper.ExecuteReader(conn, Common.DatabaseSchema + "[SYS_User_Insert]", para.ToArray()); sys_user.ID = (int)ouput.Value; SYS_RoleOfUser sysRoleOfUser = new SYS_RoleOfUser(); sysRoleOfUser.RoleId = sys_user.Roles.ID; //sysRoleOfUser.RoleId = sys_user.IDOrganization; sysRoleOfUser.UserId = sys_user.ID; if (sys_user.Roles.ID != 0) { sysRoleOfUserDataAccess.InsertSYS_RoleOfUser(sysRoleOfUser); } } catch (Exception ex) { throw new Exception(String.Format("SYS_UserDataAccess.Insert: {0}", ex.Message)); } finally { conn.Close(); } return(sys_user.ID); }