示例#1
0
        private void btnRemittance_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (StatementDialogue dlg = new StatementDialogue())
            {
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    DevExpress.XtraReports.Parameters.ParameterCollection parameters = new DevExpress.XtraReports.Parameters.ParameterCollection();
                    parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()
                    {
                        Name = "Period", Value = dlg.Period
                    });
                    parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()
                    {
                        Name = "Account", Value = BL.SYS.SYS_Entity.LoadCompanyDebtorEntity(CompanyCode, DataContext).Id
                    });
                    parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()
                    {
                        Name = "Site_", Value = BL.ApplicationDataContext.Instance.LoggedInUser.DefaultSite.EntityId
                    });

                    Int64 reportId = DataContext.ReadonlyContext.VW_Report.FirstOrDefault(n => n.Name == "Account Statement").Id;

                    ShowReport(reportId, parameters);
                }
            }
        }
示例#2
0
        private void btnSecondCount_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var parameters = new DevExpress.XtraReports.Parameters.ParameterCollection();

            parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()
            {
                Name = "StockTakeId", Value = itmStockTake.Id
            });

            ShowReport("Stock Take Second Count", parameters);
        }
示例#3
0
        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DB.RPT_Report rptReport = BL.RPT.RPT_Report.Load(1, DataContext);
            //this.Text = rptReport.Name;
            System.IO.Stream xmlstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(rptReport.Data));

            //XtraReport report = new XtraReport();
            DevExpress.XtraReports.UI.XtraReport report = new DevExpress.XtraReports.UI.XtraReport();
            report.LoadLayoutFromXml(xmlstream);
            //report.CurrentPrintControl = PrintControl;
            //SqlDataAdapter adp = (SqlDataAdapter)report.DataAdapter;

            if (report.DataSource is DevExpress.DataAccess.Sql.SqlDataSource)
            {
                ((DevExpress.DataAccess.Sql.SqlDataSource)(report.DataSource)).Connection.ConnectionString = BL.ApplicationDataContext.Instance.SqlConnectionString.ConnectionString;
            }
            else if (report.DataSource is DevExpress.DataAccess.EntityFramework.EFDataSource)
            {
                ((DevExpress.DataAccess.EntityFramework.EFDataSource)(report.DataSource)).Connection.ConnectionString = BL.ApplicationDataContext.Instance.EntityViewConnectionString.ConnectionString;
            }
            else
            {
                throw new Exception("Data Source type not implemented in reports");
            }

            //adp.SelectCommand.Connection.ConnectionString = BL.ApplicationDataContext.Instance.SqlConnectionString.ConnectionString;
            DevExpress.XtraReports.Parameters.ParameterCollection Parameters = new DevExpress.XtraReports.Parameters.ParameterCollection();
            Parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()
            {
                Name = "Code_Main_starts_with", Value = "00100"
            });
            if (Parameters.Count != 0)
            {
                foreach (var extparam in Parameters)
                {
                    foreach (var param in report.Parameters)
                    {
                        if (extparam.Name == param.Name)
                        {
                            param.Value = extparam.Value;
                            break;
                        }
                    }
                }
            }
            report.ExportToPdf(@"C:\accounts_report.pdf");
        }
示例#4
0
        private bool ProcessStatementEmail(long statementId)
        {
            bool HasMailed;

            using (var uow = new DevExpress.Xpo.UnitOfWork())
            {
                XDB.GLX_Statement statement = uow.Query <XDB.GLX_Statement>().SingleOrDefault(n => n.Id == statementId);

                var             account = uow.Query <XDB.GLX_Account>().SingleOrDefault(n => n.EntityId.Id == statement.EntityId.Id);
                XDB.ORG_Company company = null;

                if (account.EntityId.CodeMain == BL.ApplicationDataContext.Instance.SiteAccounts.DebtorsEntity.CodeMain)
                {
                    company = uow.Query <XDB.ORG_Company>().SingleOrDefault(n => n.TypeId.Id == (byte)BL.ORG.ORG_Type.Customer && n.EntityId.EntityId.CodeSub == account.EntityId.CodeSub);
                }
                else
                if (account.EntityId.CodeMain == BL.ApplicationDataContext.Instance.SiteAccounts.CreditorsEntity.CodeMain)
                {
                    company = uow.Query <XDB.ORG_Company>().SingleOrDefault(n => n.TypeId.Id == (byte)BL.ORG.ORG_Type.Supplier && n.EntityId.EntityId.CodeSub == account.EntityId.CodeSub);
                }

                if (!System.Text.RegularExpressions.Regex.IsMatch(company.AccountsContactEmail,
                                                                  @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                                                                  @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
                                                                  System.Text.RegularExpressions.RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)))
                {
                    return(false);
                }



                try
                {
                    DB.RPT_Report rptReport = BL.RPT.RPT_Report.LoadByName("Account Statement", DataContext);

                    System.IO.Stream xmlstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(rptReport.Data));

                    DevExpress.XtraReports.UI.XtraReport report = new DevExpress.XtraReports.UI.XtraReport();
                    report.LoadLayoutFromXml(xmlstream);

                    if (report.DataSource is DevExpress.DataAccess.Sql.SqlDataSource)
                    {
                        ((DevExpress.DataAccess.Sql.SqlDataSource)(report.DataSource)).Connection.ConnectionString = BL.ApplicationDataContext.Instance.SqlConnectionString.ConnectionString;
                    }
                    else
                    {
                        throw new Exception("Data Source type not implemented in reports");
                    }

                    DevExpress.XtraReports.Parameters.ParameterCollection Parameters = new DevExpress.XtraReports.Parameters.ParameterCollection();
                    Parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()
                    {
                        Name = "Account", Value = statement.EntityId.Id
                    });
                    Parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()
                    {
                        Name = "Period", Value = statement.PeriodId.Id
                    });

                    if (Parameters.Count != 0)
                    {
                        foreach (var extparam in Parameters)
                        {
                            foreach (var param in report.Parameters)
                            {
                                if (extparam.Name == param.Name)
                                {
                                    param.Value = extparam.Value;
                                    break;
                                }
                            }
                        }
                    }



                    // Create a new memory stream and export the report into it as PDF.
                    System.IO.MemoryStream mem = new System.IO.MemoryStream();
                    report.ExportToPdf(mem);

                    // Create a new attachment and put the PDF report into it.
                    mem.Seek(0, System.IO.SeekOrigin.Begin);
                    System.Net.Mail.Attachment att = new System.Net.Mail.Attachment(mem, account.EntityId.CodeMain + ".pdf", "application/pdf");

                    // Create a new message and attach the PDF report to it.
                    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                    mail.Attachments.Add(att);

                    report.ExportOptions.Email.RecipientAddress = company.AccountsContactEmail;
                    report.ExportOptions.Email.RecipientName    = company.AccountsContactName;
                    report.ExportOptions.Email.Subject          = "Statement of Account for ACC# " + account.EntityId.CodeSub;
                    report.ExportOptions.Email.Body             = string.Format("Please see attached Statement of Account for ACC# {0} ({1:N2})", account.EntityId.CodeSub, account.EntityId.AccountBalance);

                    // Specify sender and recipient options for the e-mail message.
                    mail.From = new System.Net.Mail.MailAddress(BL.ApplicationDataContext.Instance.CompanySite.AccountEmailAddress, BL.ApplicationDataContext.Instance.LoggedInUser.DisplayName);
                    mail.To.Add(new System.Net.Mail.MailAddress(report.ExportOptions.Email.RecipientAddress,
                                                                report.ExportOptions.Email.RecipientName));

                    // Specify other e-mail options.
                    mail.Subject = report.ExportOptions.Email.Subject;
                    mail.Body    = report.ExportOptions.Email.Body;

                    // Send the e-mail message via the specified SMTP server.
                    System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(BL.ApplicationDataContext.Instance.CompanySite.SMTPServerLocation, 587);
                    if (BL.ApplicationDataContext.Instance.CompanySite.AccountEmailPassword != null && BL.ApplicationDataContext.Instance.CompanySite.AccountEmailPassword != string.Empty)
                    {
                        System.Net.NetworkCredential credential =
                            new System.Net.NetworkCredential(BL.ApplicationDataContext.Instance.CompanySite.AccountEmailUsername, BL.ApplicationDataContext.Instance.CompanySite.AccountEmailPassword);

                        if (BL.ApplicationDataContext.Instance.CompanySite.AccountEmailDomain != string.Empty)
                        {
                            credential.Domain = BL.ApplicationDataContext.Instance.CompanySite.AccountEmailDomain;
                        }

                        smtpClient.UseDefaultCredentials = false;
                        smtpClient.Credentials           = credential;
                        smtpClient.EnableSsl             = true;
                    }
                    smtpClient.Send(mail);

                    // Close the memory stream.
                    mem.Close();
                    mem.Flush();
                    statement.HasMailed = HasMailed = true;
                }
                catch (Exception ex)
                {
                    statement.HasMailed = HasMailed = false;
                }

                uow.CommitChanges();
            }
            return(HasMailed);
        }
示例#5
0
        public static void EmailtoPDF(Essential.BaseForm.ReportTemplateType reportTemplate, long id, string filename, BL.DataContext dataContext)
        {
            string reportName = null;

            //rptReport = BL.RPT.RPT_Report.LoadByName("Sales Document Template", DataContext);
            //
            //rptReport = BL.RPT.RPT_Report.LoadByName("Picking Slip Document Template", DataContext);
            //
            //rptReport = BL.RPT.RPT_Report.LoadByName("Purchase Document Template", DataContext);
            //
            //rptReport = BL.RPT.RPT_Report.LoadByName("Transfer Document Template", DataContext);
            //
            //rptReport = BL.RPT.RPT_Report.LoadByName("Stock Document Template", DataContext);
            //
            //rptReport = BL.RPT.RPT_Report.LoadByName("Work Document Template", DataContext);
            //
            //rptReport = BL.RPT.RPT_Report.LoadByName("Work Document Template", DataContext);

            switch (reportTemplate)
            {
            case Essential.BaseForm.ReportTemplateType.None:
                reportName = "";
                break;

            case Essential.BaseForm.ReportTemplateType.SalesDocument:
                reportName = "Sales Document Template";
                break;

            case Essential.BaseForm.ReportTemplateType.PurchaseDocument:
                reportName = "Purchase Document Template";
                break;

            case Essential.BaseForm.ReportTemplateType.PickerDocument:
                reportName = "Picking Slip Document Template";
                break;

            case Essential.BaseForm.ReportTemplateType.StockDocument:
                reportName = "Stock Document Template";
                break;

            case Essential.BaseForm.ReportTemplateType.WorkDocument:
                reportName = "Work Document Template";
                break;

            case Essential.BaseForm.ReportTemplateType.TransferDocument:
                reportName = "Transfer Document Template";
                break;
            }

            DB.RPT_Report rptReport = BL.RPT.RPT_Report.LoadByName(reportName, dataContext);

            if (rptReport == null)
            {
                return;
            }

            System.IO.Stream xmlstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(rptReport.Data));

            DevExpress.XtraReports.UI.XtraReport report = new DevExpress.XtraReports.UI.XtraReport();
            report.LoadLayoutFromXml(xmlstream);

            if (report.DataSource is DevExpress.DataAccess.Sql.SqlDataSource)
            {
                ((DevExpress.DataAccess.Sql.SqlDataSource)(report.DataSource)).Connection.ConnectionString = BL.ApplicationDataContext.Instance.SqlConnectionString.ConnectionString;
            }
            else if (report.DataSource is DevExpress.DataAccess.EntityFramework.EFDataSource)
            {
                ((DevExpress.DataAccess.EntityFramework.EFDataSource)(report.DataSource)).Connection.ConnectionString = BL.ApplicationDataContext.Instance.EntityViewConnectionString.ConnectionString;
            }
            else
            {
                throw new Exception("Data Source type not implemented in reports");
            }

            //adp.SelectCommand.Connection.ConnectionString = BL.ApplicationDataContext.Instance.SqlConnectionString.ConnectionString;
            DevExpress.XtraReports.Parameters.ParameterCollection Parameters = new DevExpress.XtraReports.Parameters.ParameterCollection();
            Parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()
            {
                Name = "DocumentId", Value = id
            });
            if (Parameters.Count != 0)
            {
                foreach (var extparam in Parameters)
                {
                    foreach (var param in report.Parameters)
                    {
                        if (extparam.Name == param.Name)
                        {
                            param.Value = extparam.Value;
                            break;
                        }
                    }
                }
            }

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            report.ExportToPdf(ms);
            CDS.Client.Desktop.Essential.UTL.SendMailForm mail = new CDS.Client.Desktop.Essential.UTL.SendMailForm();
            mail.AttachFile(ms, filename);
            mail.ShowDialog();
        }
示例#6
0
        public static System.IO.MemoryStream DocumentPreview(string connectionString, Int64 documentId, Int64 reportId)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            using (UnitOfWork uow = new UnitOfWork())
            {
                uow.ConnectionString = connectionString;
                uow.Connect();

                DAL.Datamodel.RPT_Report rptReport = uow.Query <DAL.Datamodel.RPT_Report>().Where(r => r.Id == reportId).FirstOrDefault();

                System.IO.Stream xmlstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(rptReport.Data));

                DevExpress.XtraReports.UI.XtraReport report = new DevExpress.XtraReports.UI.XtraReport();
                report.LoadLayoutFromXml(xmlstream);

                foreach (object oObject in report.ObjectStorage)
                {
                    if (oObject is DevExpress.XtraReports.Parameters.LookUpSettings)
                    {
                        object dataSource = (oObject as DevExpress.XtraReports.Parameters.LookUpSettings).DataSource;

                        if (dataSource is DevExpress.DataAccess.Sql.SqlDataSource)
                        {
                            ((DevExpress.DataAccess.Sql.SqlDataSource)(dataSource)).Connection.ConnectionString = connectionString;
                        }
                        else
                        {
                            throw new Exception("Data Source type not implemented in reports");
                        }
                    }
                }

                foreach (object oObject in report.ComponentStorage)
                {
                    if (oObject is DevExpress.DataAccess.Sql.SqlDataSource)
                    {
                        ((DevExpress.DataAccess.Sql.SqlDataSource)(oObject)).Connection.ConnectionString = connectionString;
                    }
                }

                DevExpress.XtraReports.Parameters.ParameterCollection Parameters = new DevExpress.XtraReports.Parameters.ParameterCollection();

                Parameters.Add(new DevExpress.XtraReports.Parameters.Parameter()
                {
                    Name = "DocumentId", Value = documentId.ToString()
                });
                if (Parameters.Count != 0)
                {
                    foreach (var extparam in Parameters)
                    {
                        foreach (var param in report.Parameters)
                        {
                            if (extparam.Name == param.Name)
                            {
                                param.Value = extparam.Value;
                                break;
                            }
                        }
                    }
                }

                report.ExportToPdf(ms);
            }

            return(ms);
        }