/// <summary> /// As administrators user, they can assign a module that has expired to a staff /// </summary> /// <param name="exception"></param> /// <returns></returns> public bool AssignModuleToAccount(ExceptionAccess exception) { ConnectDB db = new ConnectDB(); SqlCommand cmd; //add a new record data in Account_Module table cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "INSERT INTO Exception(accountId,moduleId,reason,creationDate,expiryDate)VALUES(@accountId, @moduleId, @reason, @creationDate, expiryDate);"; cmd.Parameters.AddWithValue("@accountId", exception.AccountId); cmd.Parameters.AddWithValue("@moduleId", exception.ModuleId); cmd.Parameters.AddWithValue("@reason", exception.Reason); cmd.Parameters.AddWithValue("@creationDate", exception.CreationDate); cmd.Parameters.AddWithValue("@expiryDate", exception.ExpiryDate); db.changeData(cmd); db.Close(); return(true); }
/// <summary> /// Query Exception table to see if the module is assigned to employees /// </summary> /// <param name="moduleId"></param> /// <returns></returns> public ExceptionAccess GetExceptionData(int moduleId) { ExceptionAccess exceptionModule = new ExceptionAccess(); ConnectDB db = new ConnectDB(); SqlCommand cmd; SqlDataReader dr; cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; if (moduleId == 0) { return(exceptionModule); } else { cmd.CommandText = "SELECT * FROM Exception WHERE moduleId = @moduleId;"; cmd.Parameters.Add("@moduleId", SqlDbType.Int).Value = moduleId; } dr = db.searchData(cmd); if (dr.HasRows) { while (dr.Read()) { if (System.DBNull.Value.Equals(dr[0])) { exceptionModule.ExceptionId = 0; } else { exceptionModule.ExceptionId = Convert.ToInt32(dr[0]); } if (System.DBNull.Value.Equals(dr[1])) { exceptionModule.AccountId = 0; } else { exceptionModule.AccountId = Convert.ToInt32(dr[1]); } if (System.DBNull.Value.Equals(dr[2])) { exceptionModule.ModuleId = 0; } else { exceptionModule.ModuleId = Convert.ToInt32(dr[2]); } if (System.DBNull.Value.Equals(dr[3])) { exceptionModule.Reason = null; } else { exceptionModule.Reason = Convert.ToString(dr[3]); } if (System.DBNull.Value.Equals(dr[4])) { exceptionModule.CreationDate = default(DateTime); } else { exceptionModule.CreationDate = Convert.ToDateTime(dr[4]); } if (System.DBNull.Value.Equals(dr[5])) { exceptionModule.ExpiryDate = default(DateTime); } else { exceptionModule.ExpiryDate = Convert.ToDateTime(dr[5]); } } } if ((dr != null) && (!dr.IsClosed)) { dr.Close(); } db.Close(); return(exceptionModule); }