Esempio n. 1
0
        private void SendReportButton_Click(object sender, EventArgs e)
        {
            if (OrdersManager.MainOrdersBindingSource.Count == 0)
            {
                return;
            }

            DetailsReport.Save = false;
            DetailsReport.Send = false;

            PhantomForm PhantomForm = new Infinium.PhantomForm();

            PhantomForm.Show();

            ClientReportMenu = new ClientReportMenu(this);
            TopForm          = ClientReportMenu;

            ClientReportMenu.ShowDialog();

            PhantomForm.Close();
            DetailsReport.Save = ClientReportMenu.Save;
            DetailsReport.Send = ClientReportMenu.Send;

            PhantomForm.Dispose();
            ClientReportMenu.Dispose();
            TopForm = null;

            if (!DetailsReport.Save && !DetailsReport.Send)
            {
                return;
            }

            int[] SelectedMegaOrders = OrdersManager.GetSelectedMegaOrders();

            if (!OrdersManager.AreSelectedMegaOrdersOneClient)
            {
                Infinium.LightMessageBox.Show(ref TopForm, false,
                                              "Выбраны заказы разных клиентов",
                                              "Создание отчета");
                return;
            }

            if (!OrdersManager.AreSelectedMegaOrdersAgree(SelectedMegaOrders))
            {
                Infinium.LightMessageBox.Show(ref TopForm, false,
                                              "Выбранные заказы несогласованы",
                                              "Создание отчета");
                return;
            }

            int[] MainOrders = OrdersManager.GetMainOrders(SelectedMegaOrders);

            decimal ComplaintProfilCost = 0;
            decimal ComplaintTPSCost    = 0;
            decimal TransportCost       = 0;
            decimal AdditionalCost      = 0;
            int     CurrencyTypeID      = Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["CurrencyTypeID"]);
            decimal Rate        = Convert.ToDecimal(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["PaymentRate"]);
            int     OrderNumber = Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["OrderNumber"]);
            int     ClientID    = Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["ClientID"]);

            for (int i = 0; i < MegaOrdersDataGrid.SelectedRows.Count; i++)
            {
                ComplaintProfilCost += Convert.ToDecimal(MegaOrdersDataGrid.SelectedRows[i].Cells["ComplaintProfilCost"].Value);
                ComplaintTPSCost    += Convert.ToDecimal(MegaOrdersDataGrid.SelectedRows[i].Cells["ComplaintTPSCost"].Value);
                TransportCost       += Convert.ToDecimal(MegaOrdersDataGrid.SelectedRows[i].Cells["TransportCost"].Value);
                AdditionalCost      += Convert.ToDecimal(MegaOrdersDataGrid.SelectedRows[i].Cells["AdditionalCost"].Value);
            }

            //CheckMainOrdersForm = new CheckMainOrdersForm(this, MainOrders, ref DecorCatalogOrder);

            //TopForm = CheckMainOrdersForm;
            //CheckMainOrdersForm.ShowDialog();

            //int[] CheckedMainOrders = CheckMainOrdersForm.CheckedMainOrders;
            //int[] CheckedOrderNumbers = CheckMainOrdersForm.CheckedOrderNumbers;

            //PhantomForm.Close();

            //PhantomForm.Dispose();
            //CheckMainOrdersForm.Dispose();
            //TopForm = null;

            //if (!CheckMainOrdersForm.IsChecked)
            //    return;

            //REPORT

            string ClientName = OrdersManager.GetClientName(ClientID);

            Thread T = new Thread(delegate() { SplashWindow.CreateSmallSplash(ref TopForm, "Загрузка данных с сервера.\r\nПодождите..."); });

            T.Start();

            while (!SplashWindow.bSmallCreated)
            {
                ;
            }

            int[]  SelectedOrderNumbers = OrdersManager.GetSelectedOrderNumbers();
            string FileName             = DetailsReport.Report(SelectedMegaOrders, SelectedOrderNumbers, MainOrders, ClientID, ClientName,
                                                               ComplaintProfilCost, ComplaintTPSCost, TransportCost, AdditionalCost,
                                                               OrdersManager.GetMainOrdersCost(MainOrders), CurrencyTypeID);

            while (SplashWindow.bSmallCreated)
            {
                SmallWaitForm.CloseS = true;
            }
            NeedSplash = true;

            if (!DetailsReport.Send)
            {
                return;
            }

            //SEND

            T = new Thread(delegate() { SplashWindow.CreateSmallSplash(ref TopForm, "Отправка письма.\r\nПодождите..."); });
            T.Start();
            while (!SplashWindow.bSmallCreated)
            {
                ;
            }

            SendEmail.Send(ClientID, string.Join(",", SelectedOrderNumbers), DetailsReport.Save, FileName);

            while (SplashWindow.bSmallCreated)
            {
                SmallWaitForm.CloseS = true;
            }
            NeedSplash = true;

            if (SendEmail.Success == false)
            {
                //MessageBox.Show(ExcMessage);
                Infinium.LightMessageBox.Show(ref TopForm, false,
                                              "Отправка отчета невозможна: отсутствует подключение к интернету либо адрес электронной почты указан неверно",
                                              "Отправка письма");
            }

            if (!DetailsReport.Save)
            {
                SendEmail.DeleteFile(FileName);
            }
        }