Exemple #1
0
        public FileResult GetXLSReport(string month)
        {
            try
            {
                string[] val = month.Split('-');

                DateTime start = new DateTime(Convert.ToInt32(val[1]), Convert.ToInt32(val[0]), 1);
                DateTime end   = start.AddMonths(1).AddDays(-1);
                List <TaskReportRecordModel> data     = this.LoadMonthlyData(start, end);
                List <TaskReportRecordModel> dataPrev = this.LoadTillThisTimeData(start);
                TaskMonthlyReport            rp       = new TaskMonthlyReport(start);
                rp.prepareReport();
                string outputfile = rp.loadReportFile(data, dataPrev);
                if (outputfile.Length > 0)
                {
                    string filename = Path.GetFileName(outputfile);
                    return(File(outputfile, System.Net.Mime.MediaTypeNames.Application.Octet, filename));
                }
            }
            catch
            {
            }

            MemoryStream mStreamMain = new MemoryStream();

            return(File(mStreamMain.ToArray(), System.Net.Mime.MediaTypeNames.Application.Octet, "EmptyReport.xlsx"));
        }
Exemple #2
0
        public JsonResult SendMonthlyReport(string month)
        {
            try
            {
                if (null == month || month.Trim().Length == 0)
                {
                    DateTime m = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, 1);
                    month = m.ToString("MM-yyyy");
                }
                string[] val = month.Split('-');

                DateTime start = new DateTime(Convert.ToInt32(val[1]), Convert.ToInt32(val[0]), 1);
                DateTime end   = start.AddMonths(1).AddDays(-1);
                List <TaskReportRecordModel> data     = this.LoadMonthlyData(start, end);
                List <TaskReportRecordModel> dataPrev = this.LoadTillThisTimeData(start);
                TaskMonthlyReport            rp       = new TaskMonthlyReport(start);
                rp.prepareReport();
                string outputfile = rp.loadReportFile(data, dataPrev);
                if (outputfile.Length > 0)
                {
                    string filename = Path.GetFileName(outputfile);

                    MailMessage mail       = new MailMessage();
                    SmtpClient  smtpClient = new SmtpClient(WebConfigurationManager.AppSettings["EmailReportServer"]);
                    mail.From    = new MailAddress(WebConfigurationManager.AppSettings["EmailReportFrom"], "No Reply");
                    mail         = this.addUserEmails(mail);
                    mail.Subject = Path.GetFileNameWithoutExtension(outputfile);
                    mail.Body    = Path.GetFileNameWithoutExtension(outputfile);

                    System.Net.Mail.Attachment attachment;
                    attachment = new System.Net.Mail.Attachment(outputfile);
                    mail.Attachments.Add(attachment);

                    smtpClient.Port        = Convert.ToInt32(WebConfigurationManager.AppSettings["EmailReportPort"]);
                    smtpClient.Credentials = new System.Net.NetworkCredential(WebConfigurationManager.AppSettings["EmailReportFrom"], WebConfigurationManager.AppSettings["EmailReportPass"]);
                    smtpClient.EnableSsl   = Convert.ToBoolean(WebConfigurationManager.AppSettings["EmailReportSSL"]);

                    smtpClient.Send(mail);
                    smtpClient.Dispose();
                }
            }
            catch
            {
            }
            return(Json(new { message = "Đã tạo xong báo cáo tháng" }, JsonRequestBehavior.AllowGet));
        }