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)); } }
/* Excel не загружает, если из планировщика */ //public void StartImportExcel() //{ // try // { // using (ExcelDoc excel = new ExcelDoc(FilePath)) // { // int i = 2; // string curCell = "C" + i; // while (excel.getValue(curCell) != null) // { // curCell = "A" + i; // if ((excel.getValue(curCell) == null) || // ((excel.getValue(curCell).ToString().ToUpper() != "AM") && (excel.getValue(curCell).ToString().ToUpper() != "АМ"))) // { // curCell = "C" + i; // i++; // continue; // } // curCell = "C" + i; // string number = excel.getValue(curCell).ToString(); // curCell = "D" + i; // DateTime dateBegin; // DateTime.TryParse(excel.getValue1(curCell).ToString(), out dateBegin); // curCell = "E" + i; // DateTime dateEnd; // DateTime.TryParse(excel.getValue1(curCell).ToString(), out dateEnd); // for (DateTime date = dateBegin; date <= dateEnd; date = date.AddDays(1)) // { // Tabel tabel = new Tabel(number, date) { Comment = "businessTrip" }; // tabel.Save(); // } // curCell = "C" + i; // i++; // } // } // } // catch (NullReferenceException ex) // { // LogManager.Logger.Error(ex, "Error in file {file}", FilePath); // } // catch (COMException ex) // { // LogManager.Logger.Error(ex, "Error in file {file}", FilePath); // } //} /* txt формат предыдущего файла */ public void StartImport() { try { string[] files = Directory.GetFiles(FilePath, "VygruzkaAvto_Braun_КК1.txt"); string[] lines = File.ReadAllLines(files[0]); for (int i = 1; i < lines.Count(); i++) { string[] fields = lines[i].Split(';'); if (fields[0] != "АМ") { continue; } string number = fields[2]; //табельный номер DateTime dateBegin; DateTime.TryParse(fields[3], out dateBegin); DateTime dateEnd; DateTime.TryParse(fields[4], out dateEnd); for (DateTime date = dateBegin; date <= dateEnd; date = date.AddDays(1)) { Tabel tabel = new Tabel(number, date) { Comment = "businessTrip" }; tabel.Save(); } } File.Move(files[0], FilePath + @"\processed\" + DateTime.Today.ToShortDateString() + " " + Path.GetFileName(files[0])); } catch { } }