public void StartImport() { TabelList tabelList = TabelList.GetInstance(); string[] files = Directory.GetFiles(FilePath, "*.txt"); foreach (var file in files) { string date = file.Split('_')[2].Split('.')[0]; int month = Convert.ToInt32(string.Concat(date[0], date[1])); int year = Convert.ToInt32(string.Concat("20", date[2], date[3])); string[] lines = File.ReadAllLines(file); for (int i = 1; i < lines.Count(); i++) { string[] fields = lines[i].Split(';'); for (int j = 2; j < fields.Count(); j++) { if ((fields[j] == "Я") || (fields[j] == "Я/Н")) { Tabel tabel = new Tabel(fields[0], new DateTime(year, month, j - 1)); tabel.Save(); } } } File.Move(file, FilePath + @"\processed\" + DateTime.Today.ToShortDateString() + " " + Path.GetFileName(file)); } }
private Dictionary <int, Driver> GetDriversDictionary() { DriverCarList driverCarList = DriverCarList.getInstance(); //TODO: EF?? TabelList tabelList = TabelList.GetInstance(); Dictionary <int, Driver> drivers = new Dictionary <int, Driver>(); for (int day = 1; day <= _date.AddMonths(1).AddDays(-1).Day; day++) { DateTime curDate = new DateTime(_date.Year, _date.Month, day); Driver driver = driverCarList.GetDriver(_car, curDate); List <int> days = tabelList.GetDays(driver, curDate); if (days.Count == 0) { break; } //throw new NullReferenceException("Нет табельных листов на выбранный месяц для водителя " + driver.GetName(NameType.Short)); if (!days.Exists(item => item == day)) { continue; } drivers.Add(day, driver); } return(drivers); }
private void KomandByColor() { /* Отметить дни командировки - цветом */ tabelList = TabelList.GetInstance(); List <Tabel> tL = tabelList.getItemWithoutDay("businessTrip", driverCurrent, dtpDate.Value); if (tL.Count != 0) { int i = 0; foreach (DataGridViewRow row in dgv.Rows) { DateTime date = Convert.ToDateTime(row.Cells[0].Value); if (tabelList.getItem("businessTrip", driverCurrent, date) != null) { row.DefaultCellStyle.BackColor = Color.FromArgb(115, 214, 186); tL = tL.Where(t => t.Date.Year == date.Year && t.Date.Month == date.Month && t.Date.Day != date.Day) .ToList(); } } if (tL.Count != 0) { foreach (Tabel tab in tL) { while (dgv.Rows[i].DefaultCellStyle.BackColor == Color.FromArgb(115, 214, 186)) { i++; } if (dgv.Rows[i].DefaultCellStyle.BackColor != Color.FromArgb(115, 214, 186)) { dgv.Rows[i].Cells[0].Value = tab.Date; dgv.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(115, 214, 186); } i++; } } } }