/// <summary> /// Constructor /// </summary> WorkerManager() { this._Workers = null; this._WorkerCtrls = new List <WorkerCtrl>(); this._isRefreshingControls = false; this._WorkerListFilter = null; this.InactiveWorkersLoaded = false; this._selectedWorkers = null; this.IgnoreControlRefresh = false; }
/// <summary> /// Constructor /// </summary> public Call() { this.required_workers = 1; this.traveltime_mins = 0; this._workers = null; this.flag = FlagCode.None; this._markedForDeletion = false; this._MarkForSave = true; this.Old = new Dictionary <string, object>(); this.OldWorkers = new List <Worker>(); this.SaveMarkerChanged += Call_SaveMarkerChanged; this.SaveMarkerChanging += Call_SaveMarkerChanging; }
/// <summary> /// load all the workers /// </summary> /// <param name="ignoreDeleted"></param> public void LoadWorkers(LoadOptions options = LoadOptions.All | LoadOptions.IgnoreDeleted) //bool ignoreDeleted = true, bool ignoreInactive = true) { if (isLoading) { return; } isLoading = true; //load here if (_Workers == null) { _Workers = new WorkerCollection(); } else if ((options & LoadOptions.OnlyInactive) != LoadOptions.OnlyInactive) { _Workers.Clear(); } InactiveWorkersLoaded = true; try { string query = "SELECT id, Firstname, Surname, idStatus, contactno_primary, contactno_secondary, postcode, notes, isDriver, location_longitude, location_latitude, ENumber, add1, add2 FROM tbl_Worker"; string whereclause = ""; if ((options & LoadOptions.OnlyInactive) == LoadOptions.OnlyInactive) { //only load inactive workers whereclause += " idStatus == " + ((int)Worker.Status.Inactive).ToString(); } else { if ((options & LoadOptions.IgnoreDeleted) == LoadOptions.IgnoreDeleted) { if (whereclause.Length > 0) { whereclause += " and "; } whereclause += " idStatus <> " + ((int)Worker.Status.Deleted).ToString(); } if ((options & LoadOptions.IgnoreInactive) == LoadOptions.IgnoreInactive) { if (whereclause.Length > 0) { whereclause += " and "; } whereclause += " idStatus <> " + ((int)Worker.Status.Inactive).ToString(); InactiveWorkersLoaded = false; } } query += " WHERE " + whereclause; DataTable dt = Common.Database.ExecuteDatabaseQuery(query); foreach (DataRow row in dt.Rows) { Worker w = new Worker() { id = Convert.ToInt32(row[0]), firstname = row[1].ToString(), surname = row[2].ToString(), idStatus = (Worker.Status)Convert.ToInt16(row[3]), contactno_primary = row[4].ToString(), contactno_secondary = row[5].ToString(), postcode = row[6].ToString(), notes = row[7].ToString(), isDriver = Convert.ToBoolean(row[8]), MarkForSave = false, LongLatCoords = new LongLat((row[9] == DBNull.Value ? null : row[9].ToString()), (row[10] == DBNull.Value ? null : row[10].ToString()), (row[6] == DBNull.Value ? null : row[6].ToString())), ENumber = row[11].ToString(), add1 = row[12].ToString(), add2 = row[13].ToString() }; //now load the holidays query = "SELECT dateHoliday, duration_mins FROM tbl_Worker_Holidays WHERE idWorker = " + w.id.ToString(); DataTable dt_hols = Common.Database.ExecuteDatabaseQuery(query); foreach (DataRow holiday_row in dt_hols.Rows) { w.Holidays.Add(new Absence() { DateStart = (DateTime)holiday_row[0], Duration = Convert.ToInt32(holiday_row[1]), Reason = Absence.AbsenceReason.Holiday }); } //now load the sickdays query = "SELECT dateSick, duration_mins FROM tbl_Worker_Sickness WHERE idWorker = " + w.id.ToString(); DataTable dt_sick = Common.Database.ExecuteDatabaseQuery(query); foreach (DataRow sickness_row in dt_sick.Rows) { w.SickDays.Add(new Absence() { DateStart = (DateTime)sickness_row[0], Duration = Convert.ToInt32(sickness_row[1]), Reason = Absence.AbsenceReason.Sickness }); } //now load the training query = "SELECT dateTraining, duration_mins FROM tbl_Worker_Training WHERE idWorker = " + w.id.ToString(); DataTable dt_training = Common.Database.ExecuteDatabaseQuery(query); foreach (DataRow training_row in dt_training.Rows) { w.Training.Add(new Absence() { DateStart = (DateTime)training_row[0], Duration = Convert.ToInt32(training_row[1]), Reason = Absence.AbsenceReason.Training }); } w.ConstructOld(); _Workers.Add(w); } } catch (Exception ex) { throw new Exception("Unable to load all workers", ex); } isLoading = false; }