public List <SYS_RoleOfUser> SelectSYS_RoleOfUserByRoleID(int RoleID) { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); List <SYS_RoleOfUser> sys_roleofuser = new List <SYS_RoleOfUser>(); DbDataReader reader = null; try { List <DbParameter> para = new List <DbParameter>(); para.Add(_DbHelper.CreateParameter(FIELD_USERID, RoleID, false)); reader = _DbHelper.ExecuteReader(conn, Common.DatabaseSchema + "[SYS_RoleOfUser_SelectByIDRole]", para.ToArray()); SYS_RoleOfUserDataAccess.SetListSYS_RoleOfUserInfo(ref reader, ref sys_roleofuser); return(sys_roleofuser); } catch (Exception ex) { throw new Exception(String.Format("SYS_RoleOfUserDataAccess.SelectById: {0}", ex.Message)); } finally { if (reader != null) { reader.Close(); } conn.Close(); } }
public void DeleteSYS_User(SYS_User sys_user) { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); try { SYS_RoleOfUserDataAccess sysRoleOfUserDA = new SYS_RoleOfUserDataAccess(); SYS_RoleOfUser sysRoleOfUser = new SYS_RoleOfUser(); sysRoleOfUser.UserId = sys_user.ID; sysRoleOfUserDA.DeleteSYS_RoleOfUserByIDUser(sysRoleOfUser); List <DbParameter> para = new List <DbParameter>(); para.Add(_DbHelper.CreateParameter(FIELD_ID, sys_user.ID, false)); _DbHelper.ExecuteReader(conn, Common.DatabaseSchema + "[SYS_User_Delete]", para.ToArray()); } catch (Exception) { throw; } finally { conn.Close(); } }
public List <SYS_RoleOfUser> SelectAllSYS_RoleOfUser() { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); List <SYS_RoleOfUser> sys_roleofuser = new List <SYS_RoleOfUser>(); DbDataReader reader = null; try { reader = _DbHelper.ExecuteReader(conn, Common.DatabaseSchema + "[SYS_RoleOfUser_SelectAll]", (DbParameter[])null); if (reader.HasRows) { SYS_RoleOfUserDataAccess.SetListSYS_RoleOfUserInfo(ref reader, ref sys_roleofuser); } return(sys_roleofuser); } catch (Exception ex) { throw new Exception(String.Format(" SYS_RoleOfUserDataAccess.SelectAll: {0}", ex.Message)); } finally { if (reader != null) { reader.Close(); } conn.Close(); } }
private static void SetListSYS_RoleOfUserInfo(ref DbDataReader reader, ref List <SYS_RoleOfUser> sys_roleofusers) { SYS_RoleOfUser sys_roleofuser = null; while (reader.Read()) { sys_roleofuser = new SYS_RoleOfUser(); SYS_RoleOfUserDataAccess.SetSYS_RoleOfUserInfo(reader, ref sys_roleofuser); sys_roleofusers.Add(sys_roleofuser); } }
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); }
public void UpdateSYS_UserAll(SYS_User sys_user) { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); try { List <DbParameter> para = new List <DbParameter>(); para.Add(_DbHelper.CreateParameter(FIELD_ID, sys_user.ID, false)); 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)); _DbHelper.ExecuteReader(conn, Common.DatabaseSchema + "[SYS_User_Update]", para.ToArray()); SYS_RoleOfUserDataAccess sysRoleOfUserDataAccess = new SYS_RoleOfUserDataAccess(); SYS_RoleOfUser sysRoleOfUser = new SYS_RoleOfUser(); //SYS_RightOfUserDataAccess sysRightOfUserDataAccess = new SYS_RightOfUserDataAccess(); SYS_RightOfUser sysRightOfUserID = new SYS_RightOfUser(); sysRightOfUserID.UserId = sys_user.ID; sysRoleOfUser.UserId = sys_user.ID; //sysRightOfUserDataAccess.DeleteSYS_RightOfUser; Xóa toàn bộ quyền của User đó //sysRightOfUserDataAccess.DeleteSYS_RightOfUserByIDUser(sysRightOfUserID); sysRoleOfUserDataAccess.DeleteSYS_RoleOfUserByIDUser(sysRoleOfUser); sysRoleOfUser.RoleId = sys_user.Roles.ID; sysRoleOfUserDataAccess.InsertSYS_RoleOfUser(sysRoleOfUser); } catch (Exception ex) { throw new Exception(String.Format("SYS_UserDataAccess.UpdateAll: {0}", ex.Message)); } finally { conn.Close(); } }
public void UpdateSYS_UserAll(DM_USER dm_user) { DbConnection conn = _DbHelper.CreateConnection(Common.ConnectionString); conn.Open(); try { List <DbParameter> para = new List <DbParameter>(); para.Add(_DbHelper.CreateParameter(FIELD_IDUSER, dm_user.IDUSER, false)); 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_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_IS_ADMIN, dm_user.IS_ADMIN, false)); para.Add(_DbHelper.CreateParameter(FIELD_CHUCDANH, dm_user.CHUCDANH, false)); _DbHelper.ExecuteNonQuery(conn, Common.DatabaseSchema + "[DM_USER_Update]", para.ToArray()); SYS_RoleOfUserDataAccess sysRoleOfUserDataAccess = new SYS_RoleOfUserDataAccess(); SYS_RoleOfUser sysRoleOfUser = new SYS_RoleOfUser(); SYS_RightOfUser sysRightOfUserID = new SYS_RightOfUser(); sysRightOfUserID.UserId = dm_user.IDUSER; sysRoleOfUser.UserId = dm_user.IDUSER; sysRoleOfUserDataAccess.DeleteSYS_RoleOfUserByIDUser(sysRoleOfUser); sysRoleOfUser.RoleId = dm_user.Roles.ID; sysRoleOfUserDataAccess.InsertSYS_RoleOfUser(sysRoleOfUser); } catch (Exception ex) { throw new Exception(String.Format("dm_user_Update.UpdateAll: {0}", ex.Message)); } finally { conn.Close(); } }