Example #1
0
        private void btnProcessStatements_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (ProcessStatementsDialogue dlg = new ProcessStatementsDialogue())
            {
                LayoutControlGrid.Validate();


                using (var uow = new DevExpress.Xpo.Session())
                {
                    XDB.ORG_Company company = null;
                    foreach (XDB.GLX_Account account in this.XPCollection)
                    {
                        switch (IsCustomer)
                        {
                        case true: company = uow.Query <XDB.ORG_Company>().SingleOrDefault(n => n.TypeId.Id == (byte)BL.ORG.ORG_Type.Customer && n.EntityId.EntityId.CodeSub == account.EntityId.CodeSub);
                            break;

                        case false: company = uow.Query <XDB.ORG_Company>().SingleOrDefault(n => n.TypeId.Id == (byte)BL.ORG.ORG_Type.Supplier && n.EntityId.EntityId.CodeSub == account.EntityId.CodeSub);
                            break;
                        }

                        if (account.PrintStatement || account.EmailStatement)
                        {
                            dlg.Statements.Add(new CDS.Client.DataAccessLayer.Types.Statement()
                            {
                                EntityId    = account.EntityId.Id,
                                Code        = account.EntityId.CodeSub,
                                Name        = account.EntityId.Name,
                                Contact     = company.AccountsContactName,
                                Email       = company.AccountsContactEmail,
                                ShouldPrint = account.PrintStatement,
                                ShouldEmail = account.EmailStatement
                            });
                        }
                    }
                }
                dlg.ShowDialog();
            }

            if (StatementTask != null && StatementTask.Status != System.Threading.Tasks.TaskStatus.RanToCompletion)
            {
                Essential.BaseAlert.ShowAlert("Processing statements", "Statements will now be processed in the background.\nClick on \"View Active Processing\" to check progress.", Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Information);
                btnViewActiveProcessing.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
                btnProcessStatements.Visibility    = DevExpress.XtraBars.BarItemVisibility.Never;
                UpdateTimer.Start();
            }
        }
Example #2
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);
        }
Example #3
0
        private void GridView_MouseDown(object sender, MouseEventArgs e)
        {
            GridView    view = sender as GridView;
            Point       p    = view.GridControl.PointToClient(MousePosition);
            GridHitInfo info = view.CalcHitInfo(p);

            if (info.HitTest == GridHitTest.Column)
            {
                LayoutControlGrid.Validate();
                var statements = this.XPCollection.Cast <CDS.Client.DataAccessLayer.XDB.GLX_Account>();

                bool clearEmail = false, clearPrint = false;
                if (info.Column == colEmailStatement && statements.Count(n => n.EmailStatement) > 0)
                {
                    clearEmail = true;
                }
                else
                if (info.Column == colPrintStatement && statements.Count(n => n.PrintStatement) > 0)
                {
                    clearPrint = true;
                }

                using (var uow = new DevExpress.Xpo.Session())
                {
                    XDB.ORG_Company company = null;

                    foreach (CDS.Client.DataAccessLayer.XDB.GLX_Account account in XPCollection)
                    {
                        if (account.EntityId.AccountBalance == 0.00M)
                        {
                            continue;
                        }

                        switch (IsCustomer)
                        {
                        case true: company = uow.Query <XDB.ORG_Company>().SingleOrDefault(n => n.TypeId.Id == (byte)BL.ORG.ORG_Type.Customer && n.EntityId.EntityId.CodeSub == account.EntityId.CodeSub);
                            break;

                        case false: company = uow.Query <XDB.ORG_Company>().SingleOrDefault(n => n.TypeId.Id == (byte)BL.ORG.ORG_Type.Supplier && n.EntityId.EntityId.CodeSub == account.EntityId.CodeSub);
                            break;
                        }

                        if (clearEmail)
                        {
                            account.EmailStatement = false;
                        }
                        else if (info.Column == colEmailStatement)
                        {
                            if (company.StatementPreference == "Email" || (company.StatementPreference == "Email, Print" || company.StatementPreference == "Print, Email"))
                            {
                                account.EmailStatement = true;
                            }

                            if (account.EntityId.AccountBalance != 0)
                            {
                                account.EmailStatement = true;
                            }
                        }

                        if (clearPrint)
                        {
                            account.PrintStatement = false;
                        }
                        else if (info.Column == colPrintStatement)
                        {
                            if (company.StatementPreference == "Print" || (company.StatementPreference == "Email, Print" || company.StatementPreference == "Print, Email"))
                            {
                                account.PrintStatement = true;
                            }

                            if (account.EntityId.AccountBalance != 0)
                            {
                                account.PrintStatement = true;
                            }
                        }
                    }
                }

                clearEmail = false;
                clearPrint = false;

                if (statements.Count(n => n.EmailStatement) > 0 || statements.Count(n => n.PrintStatement) > 0)
                {
                    btnProcessStatements.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
                }
                else
                {
                    btnProcessStatements.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
                }

                GridView.RefreshData();
            }
        }