コード例 #1
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)
         {
         }
     }
 }
コード例 #2
0
        private void btnCreateWayBill_Click(object sender, EventArgs e)
        {
            if (textBoxClient.Text == "" || textBoxTrip.Text == "" ||
                comboBoxCar.Text == "" || comboBoxDriver.Text == "" ||
                !pickerStart.Checked)
            {
                MessageBox.Show("Вы ввели не все данные!");
                return;
            }
            if (pickerEnd.Checked && pickerEnd.Value < pickerStart.Value)
            {
                MessageBox.Show("Дата выгрузки не может быть меньше даты закрузки!");
            }
            WayBillMapper wm = new WayBillMapper();

            if (wayBill == null)
            {
                insWayBill.Car      = new CarMapper().Get(comboBoxCar.SelectedValue.ToString());
                insWayBill.Driver   = new EmployeeMapper().Get(comboBoxDriver.SelectedValue.ToString());
                insWayBill.LoadDate = pickerStart.Value;
                if (!pickerEnd.Checked)
                {
                    insWayBill.UnloadDate = null;
                }
                else
                {
                    insWayBill.UnloadDate = pickerEnd.Value;
                }
                insWayBill.BaseDocument = textBoxBaseDoc.Text;

                insWayBill.Kilometers = (textBoxKm.Text == "") ? default : int.Parse(textBoxKm.Text);

                                        insWayBill.Cost = (txtBoxCost.Text == "") ? default : double.Parse(txtBoxCost.Text);

                                                          insWayBill.Fuel = (textBoxFuel.Text == "") ? default : float.Parse(textBoxFuel.Text);
                                                                            insWayBill.Notes = textBoxNotes.Text;
                                                                            try
                                                                            {
                                                                                wm.Insert(insWayBill);
                                                                            }
                                                                            catch (Exception ex)
                                                                            {
                                                                                MessageBox.Show(ex.Message);
                                                                                return;
                                                                            }
            }
            else
            {
                wayBill.Car      = new CarMapper().Get(comboBoxCar.SelectedValue.ToString());
                wayBill.Driver   = new EmployeeMapper().Get(comboBoxDriver.SelectedValue.ToString());
                wayBill.LoadDate = pickerStart.Value;
                if (!pickerEnd.Checked)
                {
                    wayBill.UnloadDate = null;
                }
                else
                {
                    wayBill.UnloadDate = pickerEnd.Value;
                }
                wayBill.BaseDocument = textBoxBaseDoc.Text;
                wayBill.Kilometers   = int.Parse(textBoxKm.Text);
                wayBill.Cost         = double.Parse(txtBoxCost.Text);
                wayBill.Fuel         = float.Parse(textBoxFuel.Text);
                wayBill.Notes        = textBoxNotes.Text;
                try
                {
                    wm.Update(wayBill);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
            Form1.WindowIndex = WindowsStruct.ActiveWayBills;
            DataSets.CreateDSForDataGrid(Form1.WindowIndex, mainForm.dataGridView);
            this.Close();
        }