public void AddUploadDumpList(UploadDump uploadDump) { uploadDumpList.Add(uploadDump); }
public UploadDump GetUploadDump01_USR(UploadDump uploadDump, string path) { Excel.Application ObjWorkExcel = new Excel.Application(); Excel.Workbook ObjWorkBook = ObjWorkExcel.Workbooks.Open(path, 0, true, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); Excel.Worksheet ObjWorkSheet = (Excel.Worksheet)ObjWorkBook.Sheets[GetNumListExcel(ObjWorkBook)]; //получить 1 лист int column = dateUploadData.Day + 3; int row = 13; if (uploadDump.devision == "ЭМУ") { row = 22; } if (uploadDump.devision == "УСР") { row = 12; } string textData = ""; string textCorrectData = ""; //Get WorkData & Set worker do { try { textCorrectData = ObjWorkSheet.Cells[row, 2].Text.ToString(); } catch { textCorrectData = ""; } try { textData = ObjWorkSheet.Cells[row, column].Text.ToString(); } catch { textData = ""; } if (textData == "Б" || textData == "б") { uploadDump.bol += 1; uploadDump.worker += 1; } if (textData == "П" || textData == "п") { uploadDump.prostoy += 1; uploadDump.worker += 1; } if (textData == "О" || textData == "о" || textData == "o" || textData == "O") { uploadDump.po += 1; uploadDump.worker += 1; } if (textData == "C" || textData == "c" || textData == "С" || textData == "с" || textData == "В" || textData == "в") { uploadDump.so += 1; uploadDump.worker += 1; } try { if (textData.Substring(0, 1) == "K" || textData.Substring(0, 1) == "k" || textData.Substring(0, 1) == "К" || textData.Substring(0, 1) == "к") { uploadDump.kom += 1; uploadDump.worker += 1; } } catch { } if (textData == "У" || textData == "у") { uploadDump.uvo += 1; uploadDump.worker += 1; } try { if (Convert.ToInt32(textData) <= 8 & Convert.ToInt32(textData) > 0 & Convert.ToInt32(textCorrectData) > 0) { uploadDump.work8 += 1; uploadDump.worker += 1; } if (Convert.ToInt32(textData) > 8) { uploadDump.work10 += 1; uploadDump.worker += 1; } } catch { } if (textData.ToUpper() == "УСР") { uploadDump.setUSR += 1; } if (textData.ToUpper() == "УСМК") { uploadDump.setUSMK += 1; } if (textData.ToUpper() == "УСШ") { uploadDump.setUSS += 1; } if (textData.ToUpper() == "УИШ") { uploadDump.setUIS += 1; } if (textData.ToUpper() == "ЭМУ") { uploadDump.setEMU += 1; } row++; } while (textCorrectData != "Итого по бригадам"); //Get Start position Get worker do { textCorrectData = ObjWorkSheet.Cells[row, 2].Text.ToString(); textData = ObjWorkSheet.Cells[row, column].Text.ToString(); row++; } while (textCorrectData != "Перемещения"); row += 3; //getUSR do { textCorrectData = ObjWorkSheet.Cells[row, 2].Text.ToString(); textData = ObjWorkSheet.Cells[row, column].Text.ToString(); try { if (Convert.ToInt32(textData) > 0) { uploadDump.getUSR += 1; } } catch { } row++; } while (textCorrectData != "УСМК"); //getUSMK do { textCorrectData = ObjWorkSheet.Cells[row, 2].Text.ToString(); textData = ObjWorkSheet.Cells[row, column].Text.ToString(); try { if (Convert.ToInt32(textData) > 0) { uploadDump.getUSMK += 1; } } catch { } row++; } while (textCorrectData != "УСШ"); //getUSS do { textCorrectData = ObjWorkSheet.Cells[row, 2].Text.ToString(); textData = ObjWorkSheet.Cells[row, column].Text.ToString(); try { if (Convert.ToInt32(textData) > 0) { uploadDump.getUSS += 1; } } catch { } row++; } while (textCorrectData != "УИШ"); //getUIS do { textCorrectData = ObjWorkSheet.Cells[row, 2].Text.ToString(); textData = ObjWorkSheet.Cells[row, column].Text.ToString(); try { if (Convert.ToInt32(textData) > 0) { uploadDump.getUIS += 1; } } catch { } row++; } while (textCorrectData != "ЭМУ"); //getEMU do { textCorrectData = ObjWorkSheet.Cells[row, 2].Text.ToString(); textData = ObjWorkSheet.Cells[row, column].Text.ToString(); try { if (Convert.ToInt32(textData) > 0) { uploadDump.getEMU += 1; } } catch { } row++; } while (row < 300); ObjWorkBook.Close(false, Type.Missing, Type.Missing); //закрыть не сохраняя ObjWorkExcel.Quit(); // выйти из экселя GC.Collect(); // убрать за собой return(uploadDump); }
static void Main(string[] args) { string tabel_01USR = "******"; string tabel_02USMK = "M:\\Производственный отдел\\Отчеты мастеров\\!Новая структура\\02_Участок сборки модулей\\Табель_УСМК.xlsx"; string tabel_04UIS = "M:\\Производственный отдел\\Отчеты мастеров\\!Новая структура\\04_Шинный участок\\Табель_УИШ.xlsm"; string tabel_03USS = "M:\\Производственный отдел\\Отчеты мастеров\\!Новая структура\\03_Участок сборки шкафов\\Табель_УСШ.xlsm"; string tabel_05EMU = "M:\\Производственный отдел\\Отчеты мастеров\\!Новая структура\\05_Электромонтажный участок (2)\\табель_ЭМУ.xlsm"; Logger logger = LogManager.GetCurrentClassLogger(); Excel.Application ObjWorkExcel = new Excel.Application(); DateTime dateTime = DateTime.Now.AddDays(-7); string textConsole = ""; for (int i = 0; i < 15; i++) { DateTime date = dateTime.AddDays(i); ReadExcel readExcel = new ReadExcel(date); textConsole = DateTime.Now.ToString() + " | " + "Зафиксирована дата загрузки данных: " + readExcel.DateUploadData.ToString().Substring(0, 10) + Environment.NewLine; Console.WriteLine(textConsole); //01_УСР UploadDump uploadDump = new UploadDump(date, "УСР"); uploadDump = readExcel.GetUploadDump01_USR(uploadDump, tabel_01USR); readExcel.AddUploadDumpList(uploadDump); textConsole = DateTime.Now.ToString() + " | " + "Успешно считаны данные по 01_УСР: " + Environment.NewLine; Console.WriteLine(textConsole); //02_УСМК UploadDump uploadDump1 = new UploadDump(date, "УСМК"); uploadDump = readExcel.GetUploadDump01_USR(uploadDump1, tabel_02USMK); readExcel.AddUploadDumpList(uploadDump1); textConsole = DateTime.Now.ToString() + " | " + "Успешно считаны данные по 02_УСМК: " + Environment.NewLine; Console.WriteLine(textConsole); //03_УСШ UploadDump uploadDump2 = new UploadDump(date, "УСШ"); uploadDump = readExcel.GetUploadDump01_USR(uploadDump2, tabel_03USS); readExcel.AddUploadDumpList(uploadDump2); textConsole = DateTime.Now.ToString() + " | " + "Успешно считаны данные по 03_УСШ: " + Environment.NewLine; Console.WriteLine(textConsole); //04_УИШ UploadDump uploadDump3 = new UploadDump(date, "УИШ"); uploadDump = readExcel.GetUploadDump01_USR(uploadDump3, tabel_04UIS); readExcel.AddUploadDumpList(uploadDump3); textConsole = DateTime.Now.ToString() + " | " + "Успешно считаны данные по 04_УИШ: " + Environment.NewLine; Console.WriteLine(textConsole); //05_ЭМУ UploadDump uploadDump4 = new UploadDump(date, "ЭМУ"); uploadDump = readExcel.GetUploadDump01_USR(uploadDump4, tabel_05EMU); readExcel.AddUploadDumpList(uploadDump4); textConsole = DateTime.Now.ToString() + " | " + "Успешно считаны данные по 05_ЭМУ: " + Environment.NewLine; Console.WriteLine(textConsole); readExcel.WriteUploadDataInReport(); textConsole = DateTime.Now.ToString() + " | Данные записаны в отчет успешно! " + Environment.NewLine; Console.WriteLine(textConsole); logger.Debug(" class Form1 : Form - buttonStart_Click "); } }