예제 #1
0
 static public void MakeActOfWorkInExcel(string idRepair, string unloadPath)
 {
     rowStartForDelete = 0;
     try
     {
         xlApp      = new Excel.Application();
         xlWorkBook = xlApp.Workbooks.Open(ConfigurationManager.AppSettings.Get("PathForOpenAct"));
         xlSheet    = xlWorkBook.Sheets[1];
         SystemOwner  systemOwner  = new OwnerMapper().Get();
         CardOfRepair card         = new CardMapper().Get(idRepair.ToString());
         FileOperator fileOperator = new FileOperator();
         xlSheet.Cells[1, "A"]  = systemOwner.ToString();
         xlSheet.Cells[59, "F"] = systemOwner.Director.GetShortName();
         xlSheet.Cells[3, "G"]  = card.IdRepair;
         xlSheet.Cells[3, "J"]  = ((DateTime)card.TimeOfFinish).ToString("dd/MM/yyyy");
         if (card.Car.Owner != null)
         {
             xlSheet.Cells[4, "D"] = $"{card.Car.Owner.Name}, ИНН {card.Car.Owner.INN}";
         }
         xlSheet.Cells[5, "E"] = $"{card.Car.Mark} {card.Car.Number}";
         List <Malfunctions> MalfList  = card.ListOfMalf.Select(n => n).Where(n => n.MalfOrSpare == 0).ToList <Malfunctions>();
         List <Malfunctions> SpareList = card.ListOfMalf.Select(n => n).Where(n => n.MalfOrSpare == 1).ToList <Malfunctions>();
         FillRowsWithMalf(xlSheet, rowStartAct1, rowFinishAct1, MalfList);
         FillRowsWithSpares(xlSheet, rowStartAct2, rowFinishAct2, SpareList);
         xlSheet.Cells[34, "Q"] = Malfunctions.GetTotalPriceFromList(MalfList);
         xlSheet.Cells[54, "Q"] = Malfunctions.GetTotalPriceFromList(SpareList);
         xlSheet.Cells[55, "Q"] = card.TotalPrice;
         xlWorkBook.SaveAs(fileOperator.MakeActPath(card, mainPath));
         xlWorkBook.Close();
         xlApp.Quit();
         while (System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) > 0)
         {
         }
         //MessageBox.Show($"Акт № {idRepair} выгружен в формате Excel!");
     }
     catch (Exception ex)
     {
         MessageBox.Show($"Не удалось сделать акт выполненных работ № {idRepair}\n" +
                         $"{ex.Message}");
         xlWorkBook.Close(false);
         xlApp.Quit();
         while (System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) > 0)
         {
         }
     }
 }
예제 #2
0
 static public void MakeOrderInExcel(string idRepair, string unloadPath)
 {
     rowStartForDelete = 0;
     try
     {
         xlApp      = new Excel.Application();
         xlWorkBook = xlApp.Workbooks.Open(ConfigurationManager.AppSettings.Get("PathForOpenOrder"));
         xlSheet    = xlWorkBook.Sheets[1];
         CardOfRepair card         = new CardMapper().Get(idRepair.ToString());
         SystemOwner  systemOwner  = new OwnerMapper().Get();
         FileOperator fileOperator = new FileOperator();
         xlSheet.Cells[3, "G"]  = card.IdRepair;
         xlSheet.Cells[5, "O"]  = card.TimeOfStart.ToString("dd/MM/yyyy");
         xlSheet.Cells[7, "O"]  = ((DateTime)card.TimeOfFinish).ToString("dd/MM/yyyy");
         xlSheet.Cells[9, "A"]  = $"Заказчик: {card.Car.Owner.Name}";
         xlSheet.Cells[1, "J"]  = $"Исполнитель: {systemOwner.Name} {systemOwner.Address} {systemOwner.PhoneNumber}";
         xlSheet.Cells[64, "I"] = systemOwner.Director.GetShortName();
         xlSheet.Cells[10, "D"] = card.Car.Mark;
         xlSheet.Cells[11, "G"] = card.Car.Number;
         List <Malfunctions> MalfList  = card.ListOfMalf.Select(n => n).Where(n => n.MalfOrSpare == 0).ToList <Malfunctions>();
         List <Malfunctions> SpareList = card.ListOfMalf.Select(n => n).Where(n => n.MalfOrSpare == 1).ToList <Malfunctions>();
         FillRowsWithMalf(xlSheet, rowStartOrder1, rowFinishOrder1, MalfList);
         FillRowsWithSpares(xlSheet, rowStartOrder2, rowFinishOrder2, SpareList);
         xlSheet.Cells[41, "Q"] = Malfunctions.GetTotalPriceFromList(MalfList);
         xlSheet.Cells[61, "Q"] = Malfunctions.GetTotalPriceFromList(SpareList);
         xlSheet.Cells[62, "Q"] = card.TotalPrice;
         xlWorkBook.SaveAs(fileOperator.MakeOrderPath(card, mainPath));
         xlWorkBook.Close();
         xlApp.Quit();
         while (System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) > 0)
         {
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show($"Не удалось сделать акт выполненных работ № {idRepair}\n" +
                         $"{ex.Message}");
         xlWorkBook.Close(false);
         xlApp.Quit();
         while (System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) > 0)
         {
         }
     }
 }