private CustomerCache() { lock (dummy) { if (Customers == null) { Customers = new List <Customer>(); } Customers?.Clear(); Customer customer; DBFunctions.GetInstance().OpenConnection(); using (SQLiteDataReader reader = DBFunctions.GetInstance().GetReader("Select Id, Name, FullAddress, Location, ContactPerson, Phone, ManagerId from Customers")) { while (reader.Read()) { customer = new Customer(); customer.Id = (Int64)reader[0]; customer.Name = reader[1].ToString(); customer.FullAddress = reader[2].ToString(); customer.Location = reader[3].ToString(); customer.ContactPerson = reader[4].ToString(); customer.Phone = reader[5].ToString(); customer.AccountManager = new Employee { Id = (Int64)reader[6] }; Customers.Add(customer); } reader.Close(); } foreach (var c in Customers) { c.AccountManager = EmployeeCache.GetInstance().GetById(c.AccountManager.Id); } } }
private Customer GetFromDbByName(string name) { var cust = new Customer(); cust.Name = name; SQLiteCommand command = DBFunctions.GetInstance().GetCommand("Select ID,Name,FullAddress,Location,ContactPerson,Phone,ManagerId From Customers Where (Name) = (?)"); command.Parameters.AddWithValue("Name", cust.Name); using (SQLiteDataReader reader = DBFunctions.GetInstance().GetReader(command)) { if (reader.Read()) { cust.Id = (Int64)reader[0]; cust.Name = reader[1].ToString(); cust.FullAddress = reader[2].ToString(); cust.Location = reader[3].ToString(); cust.ContactPerson = reader[4].ToString(); cust.Phone = reader[5].ToString(); cust.AccountManager = EmployeeCache.GetInstance().GetById((Int64)reader[6]); } else { cust = null; } reader.Close(); } return(cust); }
private ProcessCache() { lock (dummy) { if (Processes == null) { Processes = new List <Process>(); } Processes?.Clear(); Process process; DBFunctions.GetInstance().OpenConnection(); using (SQLiteDataReader reader = DBFunctions.GetInstance().GetReader("Select Id, Name, Description, ResourceId, EmployeeId, Rate, StartDate, EndDate, DurationHours, Status, ProjectId, Type from Processes"))//, QNumber from Processes")) { while (reader.Read()) { process = new Process(); process.Id = (Int64)reader[0]; process.Name = reader[1].ToString(); process.Description = reader[2].ToString(); process.ExecutingResource = new Resource { Id = (Int64)reader[3] }; process.ExecutingEmployee = new Employee { Id = (Int64)reader[4] }; process.Rate = reader[5].ToString(); var startDate = reader[6].ToString(); if (string.IsNullOrEmpty(startDate)) { process.StartDate = null; } else { process.StartDate = DateTimeOffset.Parse(startDate); } var endDate = reader[7].ToString(); if (string.IsNullOrEmpty(endDate)) { process.EndDate = null; } else { process.EndDate = DateTimeOffset.Parse(endDate); } process.DurationHours = reader[8].ToString(); process.Status = Enum.Parse <Process.ProcessStatus>(reader[9].ToString()); process.ProjectId = (Int64)reader[10]; process.Type = Enum.Parse <Process.ProcessType>(reader[11].ToString()); //process.QNumber = int.Parse(reader[12].ToString()); Processes.Add(process); } reader.Close(); } foreach (var p in Processes) { p.ExecutingResource = ResourceCache.GetInstance().GetById(p.ExecutingResource.Id); p.ExecutingEmployee = EmployeeCache.GetInstance().GetById(p.ExecutingEmployee.Id); } } }