示例#1
0
        public ActionResult EmailReport()
        {
            DevExpress.XtraReports.UI.XtraReport currentReport = (DevExpress.XtraReports.UI.XtraReport)Session["currentReport"];

            IIrmaServiceDataModel emailDataModel = IrmaServiceSystem.GetServiceModel(IrmaConstants.IrmaPobModels.Emails);
            PobEmailModel         emailModel     = emailDataModel.GetItem(string.Format("Name=\"PobSummaryReport\""), "Name");

            char[]            sep          = { ';' };
            string[]          recipients   = (emailModel != null && emailModel.Recipients != null) ? emailModel.Recipients.Split(sep) : null;
            IServiceDataModel pobDataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.User);

            try
            {
                using (SmtpClient client = new SmtpClient("smtp.ensco.ws"))
                {
                    MemoryStream memStream = new MemoryStream();
                    currentReport.ExportToPdf(memStream);

                    memStream.Seek(0, System.IO.SeekOrigin.Begin);
                    Attachment att = new Attachment(memStream, "PobSummayReport.pdf", "application/pdf");

                    MailMessage message = new MailMessage();
                    message.Attachments.Add(att);
                    message.From    = new MailAddress("*****@*****.**");
                    message.Subject = emailModel.Subject;

                    // Get recepients
                    foreach (string id in recipients)
                    {
                        UserModel user = pobDataModel.GetItem(string.Format("Id={0}", id), "Id");
                        if (user != null && user.Email != null)
                        {
                            message.To.Add(new MailAddress(user.Email));
                        }
                    }

                    // This line can be used to embed HTML into the email itself
                    // MailMessage message = currentReport.ExportToMail("*****@*****.**", emailModel.Recipients, emailModel.Subject);

                    // Get correct credentials for irma profile
                    client.Credentials = new System.Net.NetworkCredential("Ensco\\023627", "");
                    client.Send(message);

                    memStream.Close();
                    memStream.Flush();
                }
            }
            catch (Exception ex)
            {
            }

            return(View("ShowReportPartial", currentReport));
        }
示例#2
0
        private string Kyso(DataRow dr, string Cert)
        {
            try
            {
                XmlDataDocument document = new XmlDataDocument();
                document.Load(DuongDanInvoice + "\\Hoadon.xml");
                string  fileName = Config.GetValue("MaSoThue").ToString() + "_" + dr["Soseri"].ToString().Replace("/", "") + "_" + dr["SoHoaDon"].ToString();
                XmlNode MT32     = document.ChildNodes[1].ChildNodes[0];
                MT32.Attributes["MT32ID"].Value   = dr["MT32ID"].ToString();
                MT32.Attributes["SoHoaDon"].Value = dr["SoHoaDon"].ToString();
                MT32.Attributes["Soseri"].Value   = dr["Soseri"].ToString();
                MT32.Attributes["MaKH"].Value     = dr["MaKH"].ToString();
                MT32.Attributes["TenKH"].Value    = dr["TenKH"].ToString();
                MT32.Attributes["NguoiMua"].Value = dr["OngBa"].ToString();
                MT32.Attributes["MST"].Value      = dr["MST"].ToString();
                MT32.Attributes["DiaChi"].Value   = dr["DiaChi"].ToString();
                MT32.Attributes["Email"].Value    = dr["Email"].ToString();
                MT32.Attributes["Diengiai"].Value = dr["Diengiai"].ToString();
                MT32.Attributes["TTienH"].Value   = dr["TTienH"].ToString();
                MT32.Attributes["TThue"].Value    = dr["TThue"].ToString();
                MT32.Attributes["TTien"].Value    = dr["TTien"].ToString();
                DataRow[] ldrDt = Data.Tables[1].Select("MT32ID='" + dr["MT32ID"].ToString() + "'");
                XmlNode   OldDT = MT32.ChildNodes[0];
                MT32.RemoveChild(OldDT);
                DataTable tb = Data.Tables[1].Clone();

                foreach (DataRow drdt in ldrDt)
                {
                    XmlNode Dt32 = OldDT.Clone();
                    Dt32.Attributes["MT32ID"].Value   = drdt["MT32ID"].ToString();
                    Dt32.Attributes["DT32ID"].Value   = drdt["DT32ID"].ToString();
                    Dt32.Attributes["MaVT"].Value     = drdt["MaVT"].ToString();
                    Dt32.Attributes["TenVT"].Value    = drdt["TenVT"].ToString();
                    Dt32.Attributes["TenDVT"].Value   = drdt["TenDVT"].ToString();
                    Dt32.Attributes["Soluong"].Value  = drdt["Soluong"].ToString();
                    Dt32.Attributes["Gia"].Value      = drdt["Gia"].ToString();
                    Dt32.Attributes["PS"].Value       = drdt["PS"].ToString();
                    Dt32.Attributes["Thuesuat"].Value = drdt["Thuesuat"].ToString();
                    Dt32.Attributes["Thue"].Value     = drdt["Thue"].ToString();
                    MT32.AppendChild(Dt32);
                    //Tạo table gán cho report
                    DataRow drdt1 = tb.NewRow();
                    drdt1.ItemArray = drdt.ItemArray;
                    tb.Rows.Add(drdt1);
                }

                XmlNode Signature = document.ChildNodes[1].ChildNodes[1];
                Signature.InnerText = Cert;
                document.Save(DuongDanInvoice + "\\" + fileName + ".xml");
                //Kết xuất file Mẫu hóa đơn


                string reportFile, title;
                if (int.Parse(drMauHD["SoDong"].ToString()) > 0)
                {
                    for (int i = tb.Rows.Count; i < int.Parse(drMauHD["SoDong"].ToString()); i++)
                    {
                        DataRow drdt1 = tb.NewRow();
                        tb.Rows.Add(drdt1);
                    }
                }
                reportFile = DuongDanInvoice + "\\HoaDonMau.repx";
                title      = "HÓA ĐƠN GIÁ TRỊ GIA TĂNG";
                DateTime t  = DateTime.Now;
                Stream   rF = File.OpenRead(reportFile);
                TimeSpan ts = DateTime.Now - t;

                if (System.IO.File.Exists(reportFile))
                {
                    t                = DateTime.Now;
                    rptTmp           = DevExpress.XtraReports.UI.XtraReport.FromFile(reportFile, true);
                    rptTmp.Landscape = bool.Parse(drMauHD["Landcap"].ToString());
                    if (drMauHD["KieuGiay"].ToString() == "A4")
                    {
                        rptTmp.PaperKind = PaperKind.A4;
                    }
                    else if (drMauHD["KieuGiay"].ToString() == "A5")
                    {
                        rptTmp.PaperKind = PaperKind.A5;
                    }
                    //rptTmp = DevExpress.XtraReports.UI.XtraReport.FromStream(rF, true);
                    TimeSpan ts1 = DateTime.Now - t;
                    rptTmp.DataSource = tb;
                    XRControl xrcTitle = rptTmp.FindControl("title", true);
                    if (xrcTitle != null)
                    {
                        xrcTitle.Text = title;
                    }

                    SetVariables(dr, rptTmp, Cert);
                    rptTmp.ScriptReferences = new string[] { Application.StartupPath + "\\CDTLib.dll" };
                    //MessageBox.Show(IntPtr.Size.ToString());
                    if (IntPtr.Size == 8)
                    {
                        rptTmp.PrintingSystem.StartPrint += new PrintDocumentEventHandler(PrintingSystem_StartPrint);
                    }
                    string path = DuongDanInvoice + "\\" + fileName + ".pdf";
                    rptTmp.ExportToPdf(path);
                    //rptTmp.ShowPreview();
                    //rptTmp.PrintingSystem.PreviewFormEx.KeyUp += new KeyEventHandler(PreviewFormEx_KeyUp);
                    //rptTmp.ShowPreviewDialog();
                    //Gưi mail cho khach hàng

                    return(SendMail(path, dr));
                }
                else
                {
                    return("Không tìm thấy file mẫu báo cáo");
                }
                //return string.Empty;
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }