public void UpdateData() { Logging.ToLog("DataProvider - Обновление данных"); DataTable dataTable = firebirdClient.GetDataTable(configuration.DataBaseQuery, new Dictionary <string, object>() { { "@chairList", configuration.GetChairsIdForSystem(Environment.MachineName) } }); ChairsDict.Clear(); Logging.ToLog("DataProvider - Получено строк - " + dataTable.Rows.Count); if (dataTable.Rows.Count != 0) { IsUpdateSuccessfull = true; foreach (DataRow dataRow in dataTable.Rows) { try { ItemChair itemChair = ParseItemChair(dataRow); if (!ChairsDict.ContainsKey(itemChair.ChID)) { ChairsDict.Add(itemChair.ChID, itemChair); } else { Logging.ToLog("!!! DataProvider - элемент с ключом уже добавлен: " + itemChair.ChID); } } catch (Exception e) { IsUpdateSuccessfull = false; Logging.ToLog(e.Message + Environment.NewLine + e.StackTrace); } } } else { Logging.ToLog("DataProvider - Результат запроса - 0 строк"); IsUpdateSuccessfull = false; } OnUpdateCompleted(null, EventArgs.Empty); if (previousDay == DateTime.Now.Day) { return; } Logging.ToLog("DataProvider - ----- Автоматическое завершение работы"); Application.Current.Shutdown(); }
private ItemChair ParseItemChair(DataRow dataRow) { string chid = dataRow["CHID"].ToString(); string rnum = dataRow["RNUM"].ToString(); string status = dataRow["STATUS"].ToString(); string acfullname = dataRow["ACFULLNAME"].ToString(); string timeleft = dataRow["TIMELEFT"].ToString(); string dsinfo = dataRow["DSINFO"].ToString(); Logging.ToLog("DataProvider - Кресло: " + chid + "|" + rnum); ItemChair itemChair = new ItemChair(chid, rnum); ItemChair.StatusInfo currentState = new ItemChair.StatusInfo() { PatientToInviteName = acfullname, ReceptionTimeLeft = timeleft }; switch (status) { case "10": currentState.Status = ItemChair.Status.Delayed; break; case "20": case "21": currentState.Status = ItemChair.Status.Underway; break; case "30": case "31": currentState.Status = ItemChair.Status.Invitation; break; case "40": currentState.Status = ItemChair.Status.Free; break; case "50": default: currentState.Status = ItemChair.Status.NotConducted; break; } itemChair.CurrentState = currentState; if (string.IsNullOrEmpty(dsinfo)) { return(itemChair); } if (!dsinfo.Contains("|")) { Logging.ToLog("DataProvider - Строка не содержит разделитель |, пропуск обработки"); return(itemChair); } string[] docInfo = dsinfo.Split('|'); if (docInfo.Length != 4) { Logging.ToLog("DataProvider - Количество элементов в строке не соответствует 4, пропуск обработки"); return(itemChair); } string[] docNames = docInfo[0].Split('@'); //new string[] { "Иванов Иван Иванович", "Сидоров Роман Андреевич" }; // string[] docPositions = docInfo[1].Split('@'); //new string[] { "Терапевт", "Хирург" }; // string[] docDepartments = docInfo[2].Split('@'); //new string[] { "Терапия", "Хирургия" }; // string workTime = docInfo[3]; for (int i = 0; i < docNames.Length; i++) { Logging.ToLog("DataProvider - Сотрудник: " + docNames[i] + "|" + docPositions[i] + "|" + docDepartments[i] + "|" + workTime); Logging.ToLog("DataProvider - Статус: " + currentState.Status); string docName = ClearDoctorName(docNames[i]); string docPosition = docPositions[i]; if (docName.TrimEnd(' ').EndsWith("ич") && docPosition.ToLower().Contains("медицинская сестра")) { docPosition = "Медицинский брат"; } ItemChair.Employee employee = new ItemChair.Employee() { Name = docName, Position = docPosition, Department = docDepartments[i], WorkingTime = workTime }; //doctors list is using for photo search if (!doctors.Contains(employee.Name)) { doctors.Add(employee.Name); } if (currentState.employees.Where(x => x.Name.Equals(employee.Name)).Count() == 0) { currentState.employees.Add(employee); } else { for (int x = 0; x < currentState.employees.Count; x++) { if (currentState.employees[x].Name.Equals(employee.Name)) { if (!currentState.employees[x].Department.Contains(employee.Department)) { currentState.employees[x].Department += ", " + employee.Department; } if (!currentState.employees[x].Position.Contains(employee.Position)) { currentState.employees[x].Position += ", " + employee.Position; } break; } } } } itemChair.CurrentState = currentState; return(itemChair); }