/// <summary> /// List employees /// </summary> /// <param name="clientID"></param> public static List <ClientWorkHoursAllocation> List(int clientID) { var workAllocationList = new List <ClientWorkHoursAllocation>(); using (var connection = new MySqlConnection(ConnString.ConnectionString)) { var commandString = string.Format( " SELECT " + ListOfFields(",", "") + " FROM " + tableName + " WHERE FKCompanyUID = {0}", clientID); using (var command = new MySqlCommand( commandString, connection)) { connection.Open(); using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { ClientWorkHoursAllocation clientWork = new ClientWorkHoursAllocation(); LoadObject(reader, clientWork); workAllocationList.Add(clientWork); } } } } return(workAllocationList); }
/// <summary> /// This method loads the information from the sqlreader into the Employee object /// </summary> /// <param name="reader"></param> /// <param name="employee"></param> private static void LoadObject(MySqlDataReader reader, ClientWorkHoursAllocation clientWorkAllocation) { clientWorkAllocation.UID = Convert.ToInt32(reader[FieldName.UID.ToString()]); clientWorkAllocation.Date = Convert.ToDateTime(reader[FieldName.Date.ToString()]); clientWorkAllocation.FKClientWorkIsFor = Convert.ToInt32(reader[FieldName.FKClientWorkIsFor.ToString()]); clientWorkAllocation.FKCompanyUID = Convert.ToInt32(reader[FieldName.FKCompanyUID.ToString()]); clientWorkAllocation.FKEmployeeUID = Convert.ToInt32(reader[FieldName.FKEmployeeUID.ToString()]); clientWorkAllocation.FKInvoiceItemID = Convert.ToInt32(reader[FieldName.FKInvoiceItemID.ToString()]); clientWorkAllocation.FKInvoiceUID = Convert.ToInt32(reader[FieldName.FKInvoiceUID.ToString()]); clientWorkAllocation.FKTaskUID = Convert.ToInt32(reader[FieldName.FKTaskUID.ToString()]); clientWorkAllocation.Hours = Convert.ToInt32(reader[FieldName.Hours.ToString()]); }