コード例 #1
0
ファイル: MainForm.cs プロジェクト: alx-fad3/AgreementOpener
        // Отчет по халве
        private void ReportButtonClick(object sender, EventArgs e)
        {
            var data = _web.GetRelatedProducts(dateTimePicker1.Value, dateTimePicker2.Value);

            var save = new SaveFileDialog
            {
                DefaultExt       = "xlsx",
                InitialDirectory = @"C:\",
                FileName         = $"Халва {DateTime.Now:yyyy-MM-dd}"
            };

            save.ShowDialog();

            var excelFormer = new ExcelFormer(data, save.FileName);

            try
            {
                excelFormer.ToExcel();
                MessageBox.Show("Excel file saved!");
                if (checkBox1.Checked)
                {
                    var mailer = new Mailer(
                        ConfigurationManager.AppSettings.Get("smtpServer"),
                        ConfigurationManager.AppSettings.Get("sender"),
                        ConfigurationManager.AppSettings.Get("senderPass"),
                        mailCombo.Text,
                        save.FileName,
                        $"Отчет по Халве {DateTime.Now:yyyy-MM-dd}",
                        $"{DateTime.Now:D}");

                    mailer.SendMail();
                    MessageBox.Show($"Отправлено на {mailCombo.Text}");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: alx-fad3/WebAdmin
        public async Task <ActionResult> Reports(string npf, string date1, string date2)
        {
            try
            {
                DateTime d1;
                DateTime.TryParse(date1, out d1);
                DateTime d2;
                DateTime.TryParse(date2, out d2);

                if (string.IsNullOrEmpty(npf))
                {
                    throw new Exception("Не указан фонд");
                }
                else if (npf == "halva")
                {
                    var relatedProductsList = await commander.GetRelatedProductsAsync(d1, d2);

                    string reportPath = $@"C:\inetpub\Download_Reports\halva_{DateTime.Now.ToString("yyyy-MM-dd")}.xlsx";
                    ViewBag.reportPath = ExcelFormer.RelatedProductListToExcel(relatedProductsList, reportPath);
                }
                else
                {
                    var agreementsList = await commander.GetAgreementsAsync(npf, d1, d2);

                    string reportPath = $@"C:\inetpub\Download_Reports\{npf}_{DateTime.Now.ToString("yyyy-MM-dd")}.xlsx";
                    ViewBag.reportPath = ExcelFormer.RelatedProductListToExcel(agreementsList, reportPath);
                }

                return(Download(ViewBag.reportPath));
            }
            catch (Exception ex)
            {
                ViewBag.error = ex.Message;
                return(View("Error"));
            }
        }