private void SendMail_Click(object sender, EventArgs e)
        {
            MailSender  mailSender  = new MailSender();
            SystemOwner systemOwner = new OwnerMapper().Get();
            string      subject     = "";

            try
            {
                if (card != null)
                {
                    subject    = $"Информация по ремонту №{card.IdRepair}";
                    mailSender = new MailSender(card.Car.Owner, systemOwner,
                                                subject, card.ToString());
                }
                else if (wayBill != null)
                {
                    subject    = $"Информация по грузоперевозке №{wayBill.IdWayBill}";
                    mailSender = new MailSender(wayBill.Client, systemOwner,
                                                subject, wayBill.ToString());
                }
                mailSender.SendMessage();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Сообщение не отправлено ошибка:\n {ex.Message}");
            }
        }
Exemple #2
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)
         {
         }
     }
 }
Exemple #4
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)
         {
         }
     }
 }
 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)
         {
         }
     }
 }
 public OwnerRepository()
 {
     Mapper = new OwnerMapper();
 }