Exemple #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)
         {
         }
     }
 }
 public void MakeWayBillInExcel(string idWaybill)
 {
     try
     {
         xlApp      = new Excel.Application();
         xlWorkBook = xlApp.Workbooks.Open(ConfigurationManager.AppSettings.Get("PathForOpenBill"));
         xlSheet    = xlWorkBook.Sheets[1];
         SystemOwner  systemOwner  = new OwnerMapper().Get();
         WayBill      wayBill      = new WayBillMapper().Get(idWaybill);
         FileOperator fileOperator = new FileOperator();
         xlSheet.Cells[22, "Y"] = "рейс";
         xlSheet.Cells[5, "B"]  = systemOwner.Bank.Name;
         xlSheet.Cells[5, "X"]  = systemOwner.Bank.BIK;
         xlSheet.Cells[6, "X"]  = systemOwner.Bank.KorBill;
         xlSheet.Cells[9, "B"]  = systemOwner.Name;
         xlSheet.Cells[8, "D"]  = systemOwner.INN;
         xlSheet.Cells[8, "X"]  = systemOwner.Bill;
         xlSheet.Cells[17, "F"] = systemOwner.ToString();
         xlSheet.Cells[30, "H"] = systemOwner.Director.GetFullName();
         xlSheet.Cells[13, "K"] = wayBill.IdWayBill;
         xlSheet.Cells[13, "Q"] = ((DateTime)wayBill.UnloadDate).ToString("dd/MM/yyyy");
         xlSheet.Cells[19, "F"] = $"{wayBill.Client.Name}, ИНН {wayBill.Client.INN}, {wayBill.Client.Address}";
         xlSheet.Cells[22, "D"] = $"Транспортные услуги по маршруту: {wayBill.Trip.Name} " +
                                  $" Водитель: {wayBill.Driver.GetShortName()} Машина: {wayBill.Car.ToString()} По договор-заявке {wayBill.BaseDocument}";
         xlSheet.Cells[22, "AB"] = wayBill.Cost;
         xlSheet.Cells[28, "B"]  = RuDateAndMoneyConverter.CurrencyToTxt(wayBill.Cost, true);
         xlWorkBook.SaveAs(fileOperator.MakeBillPath(wayBill, mainPath));
         xlWorkBook.Close();
         xlApp.Quit();
         while (System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) > 0)
         {
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show($"Не удалось сделать счет на оплату № {idWaybill}\n" +
                         $"{ex.Message}");
         xlWorkBook.Close(false);
         xlApp.Quit();
         while (System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) > 0)
         {
         }
     }
 }
 public void MakeBillInExcel(string idRepair)
 {
     try
     {
         xlApp      = new Excel.Application();
         xlWorkBook = xlApp.Workbooks.Open(ConfigurationManager.AppSettings.Get("PathForOpenBill"));
         xlSheet    = xlWorkBook.Sheets[1];
         SystemOwner  systemOwner  = new OwnerMapper().Get();
         CardOfRepair card         = new CardMapper().Get(idRepair.ToString());
         FileOperator fileOperator = new FileOperator();
         xlSheet.Cells[5, "B"]  = systemOwner.Bank.Name;
         xlSheet.Cells[5, "X"]  = systemOwner.Bank.BIK;
         xlSheet.Cells[6, "X"]  = systemOwner.Bank.KorBill;
         xlSheet.Cells[9, "B"]  = systemOwner.Name;
         xlSheet.Cells[8, "D"]  = systemOwner.INN;
         xlSheet.Cells[8, "X"]  = systemOwner.Bill;
         xlSheet.Cells[17, "F"] = systemOwner.ToString();
         xlSheet.Cells[30, "H"] = systemOwner.Director.GetFullName();
         xlSheet.Cells[13, "K"] = card.IdRepair;
         xlSheet.Cells[13, "Q"] = ((DateTime)card.TimeOfFinish).ToString("dd/MM/yyyy");
         xlSheet.Cells[19, "F"] = $"{card.Car.Owner.Name}, ИНН {card.Car.Owner.INN}, {card.Car.Owner.Address}";
         xlSheet.Cells[22, "D"] = $"Ремонт автомобиля: {card.Car.ToString()} по заявке № {idRepair}" +
                                  $" от {((DateTime)card.TimeOfFinish).ToString("dd/MM/yyyy")}";
         xlSheet.Cells[22, "AB"] = card.TotalPrice;
         xlSheet.Cells[28, "B"]  = RuDateAndMoneyConverter.CurrencyToTxt(card.TotalPrice, true);
         xlWorkBook.SaveAs(fileOperator.MakeBillPath(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)
         {
         }
     }
 }