Exemplo n.º 1
0
        public Document Execute()
        {
            //Open the template document
            Document doc = new Document(System.IO.Path.Combine(mDocPath, _tempplateName));

            //get the dealerlogo
            DealerService.GetLogo(_dealer);

            // Set up the event handler for image fields.
            //doc.MailMerge.FieldMergingCallback = new HandleMergeImageFieldFromBlob(_dealer);

            //Example of a very simple mail merge to populate fields only once from an array of values.
            //doc.MailMerge.Execute(
            //    new string[] { "MyName", "MyTitle", "MyAddress1", "MyAddress2" },
            //    new object[] { "James Bond", "Secret Agent", "MI5 Headquarters", "Milbank, London" });

            //Mail merge BankruptcyCase details from DataTable to the document.
            //Whole document content will be repeated for each record.
            List <BankruptcyCase>             _leads  = BankruptcyCaseService.GetTop1000Rows();
            BankruptcyCaseMailMergeDataSource _source = new BankruptcyCaseMailMergeDataSource(_leads);

            doc.MailMerge.Execute(_source);

            return(doc);
        }
Exemplo n.º 2
0
        static public List <ZipGeoCode> GetInsideRadius(int DealerID)
        {
            List <ZipGeoCode> objZipGeoCodes = new List <ZipGeoCode>();
            Dealer            dealer         = DealerService.GetByID(DealerID);
            Database          db             = DatabaseFactory.CreateDatabase("BKLeadsOnline");

            System.Data.Common.DbCommand dbCommand = db.GetStoredProcCommand("p_ZipGeoCodesInRadiusLoad");
            db.AddInParameter(dbCommand, "Latitude", DbType.Double, dealer.Latitude);
            db.AddInParameter(dbCommand, "Longitude", DbType.Double, dealer.Longitude);
            db.AddInParameter(dbCommand, "MaxDistance", DbType.Double, dealer.MaxDistance);

            using (IDataReader reader = db.ExecuteReader(dbCommand))
            {
                while (reader.Read())
                {
                    ZipGeoCode objZipGeoCode = new ZipGeoCode();
                    LoadZipGeoCodeWithDistanceAndNumLeads(objZipGeoCode, reader);
                    objZipGeoCode.IsModified = false;
                    objZipGeoCodes.Add(objZipGeoCode);
                }
                // always call Close when done reading.
                reader.Close();
                return(objZipGeoCodes);
            }
        }
Exemplo n.º 3
0
        public DealerSalesReport(int dealerID, DateTime startDate, DateTime endDate)
        {
            DealerID  = dealerID;
            StartDate = startDate;
            EndDate   = EndDate;

            //
            // Required for telerik Reporting designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            this.DataSource = DealerMailingListCaseService.GetByDealerSalesReport(dealerID, startDate, endDate);

            txtStartDate.Value = startDate.ToShortDateString();
            txtEndDate.Value   = endDate.ToShortDateString();

            Dealer _dealer = DealerService.GetByID(DealerID);

            txtDealerName.Value = _dealer.DealerName;
        }
Exemplo n.º 4
0
        public byte[] CreateMailingList(int MailingListID, bool UseWord)
        {
            DealerMailingList _originalMailingList;
            Dealer            _mergeDealer;

            _originalMailingList = DealerMailingListService.GetByID(MailingListID);
            _mergeDealer         = DealerService.GetByID(_originalMailingList.DealerID);

            if (WordDoc == null || WordFileSize == 0)
            {
                return(null);
            }
            else //if (_wordDoc != null && _wordFileSize > 0 )
            {
                //use ASPOSE to create PDF doc from Word byte array with no merging
                //do an on the fly conversion to PDF
                MemoryStream inStream = new MemoryStream(_wordDoc);

                //we also need a bankruptcy case or actully a list of cases with one item
                List <BankruptcyCase> _cases = BankruptcyCaseService.getMailingList(_originalMailingList.ID, _mergeDealer.ID, false);
                //_cases.Add(new BankruptcyCase() { FirstName = "Jane", LastName = "Doe", AddrLine1 = "1 Main St.", City = "Anytown", StateCode = "KS", ZipCodeString = "1001" });

                // Load the stream into a new document object.
                Aspose.Words.Document _asposeDoc = new Document(inStream);

                //Set up the event handler for image fields.
                _asposeDoc.MailMerge.FieldMergingCallback = new HandleMergeImageFieldFromBlob(_mergeDealer);

                //Example of a very simple mail merge to populate fields only once from an array of values.
                //does the dealer have a legal disclaimer?

                string _legalDisclaimer;
                if (_mergeDealer.LegalDisclaimer.Length > 0)
                {
                    _legalDisclaimer = _mergeDealer.LegalDisclaimer;
                }
                else
                {
                    _legalDisclaimer = _mergeDealer.DealerName + ConfigurationManager.AppSettings["LegalDisclaimer"];
                }

                _asposeDoc.MailMerge.Execute(
                    new string[] { "DealerName", "DealerFullAddress", "DealerPhoneNumber", "DealerPrimaryContactName", "DealerURL", "LegalDisclaimer", "DealerAddress", "DealerCity", "DealerState", "DealerZipCode", "MailingDate" },
                    new object[] { _mergeDealer.DealerName, _mergeDealer.DealerFullAddress, _mergeDealer.Phone, _mergeDealer.DealerPrimaryContactName, _mergeDealer.DealerURL, _legalDisclaimer, _mergeDealer.AddressLine1, _mergeDealer.City, _mergeDealer.State, _mergeDealer.Zip, DateTime.Now.ToShortDateString() });

                //det the dealer logo if the dealer is form the DB
                if (_mergeDealer.ID > 0)
                {
                    DealerService.GetLogo(_mergeDealer);
                }

                BankruptcyCaseMailMergeDataSource _source = new BankruptcyCaseMailMergeDataSource(_cases);
                _asposeDoc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedFields;

                //execute the mail merge
                _asposeDoc.MailMerge.Execute(_source);

                //send back a converted PDF
                MemoryStream outStream = new MemoryStream();
                //_asposeDoc.Save(outStream, Aspose.Words.SaveFormat.Doc);
                if (UseWord)
                {
                    _asposeDoc.Save(outStream, Aspose.Words.SaveFormat.Doc);
                }
                else
                {
                    _asposeDoc.Save(outStream, Aspose.Words.SaveFormat.Pdf);
                }

                _mailngListDoc = outStream.ToArray();
                return(_mailngListDoc);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// If no paramters are passed other than the dealer then we get the new leads since last login.
        /// If this is the first login or default we get the most recent default number of mailings
        /// </summary>
        /// <param name="_dealer"></param>
        /// <param name="StartDate"></param>
        /// <param name="EndDate"></param>
        /// <param name="NumberOfMailings"></param>
        /// <returns></returns>

        public byte[] CreateMailingList(Dealer _dealer, DateTime StartDate, DateTime EndDate, int NumberOfMailings, bool UseWord)
        {
            DateTime _startDate = DateTime.MinValue;
            DateTime _endDate   = DateTime.MinValue;
            int      _numberOfMailings;

            _mergeDealer = _dealer;

            if (WordDoc == null || WordFileSize == 0)
            {
                return(null);
            }
            //the options are
            else //1.  Start and End Date are null requested NumberOfMailings = 0   - get most recent
            {
                if ((StartDate == null || StartDate == DateTime.MinValue) && NumberOfMailings == 0)
                {
                    //get all data since the last mailinglist
                    List <DealerMailingList> _lists = DealerMailingListService.GetForDealer(_dealer.ID);
                    if (_lists.Count > 0)
                    {
                        //_startDate = DateTime.Parse(_lists[0].EndFilterDate.ToString("MM/dd/yyyy")).AddDays(1);
                        _startDate = DealerMailingListService.GetMaxDischargedDateForDealerMailingList(_dealer.ID);
                    }
                    else
                    {
                        _startDate = DateTime.Parse(DateTime.Now.ToString("MM/dd/yyyy")).AddYears(-2);
                    }
                }
                else if (StartDate > DateTime.MinValue)
                {
                    _startDate = DateTime.Parse(StartDate.ToString("MM/dd/yyyy"));
                }
                else
                {
                    _startDate = DateTime.Parse(DateTime.Now.ToString("MM/dd/yyyy")).AddYears(-2);
                }

                if (EndDate == null || EndDate == DateTime.MinValue)
                {
                    _endDate = DateTime.Parse(DateTime.Now.ToString("MM/dd/yyyy"));
                }
                else
                {
                    _endDate = DateTime.Parse(EndDate.ToString("MM/dd/yyyy"));
                }

                if (NumberOfMailings == 0)
                {
                    //use the default number from the dealer
                    _numberOfMailings = _dealer.NumberOfMailers;
                }
                else
                {
                    _numberOfMailings = NumberOfMailings;
                }

                //use ASPOSE to create PDF doc from Word byte array with no merging
                //do an on the fly conversion to PDF
                MemoryStream inStream = new MemoryStream(_wordDoc);

                //we also need a bankruptcy case or actully a list of cases with one item
                List <BankruptcyCase> _cases = BankruptcyCaseService.getMailingList(_startDate, _endDate, _mergeDealer.ID, _numberOfMailings);

                if (_cases.Count == 0)
                {
                    return(null);
                }

                //_cases.Add(new BankruptcyCase() { FirstName = "Jane", LastName = "Doe", AddrLine1 = "1 Main St.", City = "Anytown", StateCode = "KS", ZipCodeString = "1001" });

                // Load the stream into a new document object.
                Aspose.Words.Document _asposeDoc = new Document(inStream);

                //Set up the event handler for image fields.
                _asposeDoc.MailMerge.FieldMergingCallback = new HandleMergeImageFieldFromBlob(_mergeDealer);

                //Example of a very simple mail merge to populate fields only once from an array of values.
                //does the dealer have a legal disclaimer?

                string _legalDisclaimer;
                if (_mergeDealer.LegalDisclaimer.Length > 0)
                {
                    _legalDisclaimer = _mergeDealer.LegalDisclaimer;
                }
                else
                {
                    _legalDisclaimer = _mergeDealer.DealerName + ConfigurationManager.AppSettings["LegalDisclaimer"];
                }

                _asposeDoc.MailMerge.Execute(
                    new string[] { "DealerName", "DealerFullAddress", "DealerPhoneNumber", "DealerPrimaryContactName", "DealerURL", "LegalDisclaimer", "DealerAddress", "DealerCity", "DealerState", "DealerZipCode", "MailingDate" },
                    new object[] { _mergeDealer.DealerName, _mergeDealer.DealerFullAddress, _mergeDealer.Phone, _mergeDealer.DealerPrimaryContactName, _mergeDealer.DealerURL, _legalDisclaimer, _mergeDealer.AddressLine1, _mergeDealer.City, _mergeDealer.State, _mergeDealer.Zip, DateTime.Now.ToShortDateString() });

                //det the dealer logo if the dealer is form the DB
                if (_mergeDealer.ID > 0)
                {
                    DealerService.GetLogo(_mergeDealer);
                }

                BankruptcyCaseMailMergeDataSource _source = new BankruptcyCaseMailMergeDataSource(_cases);
                _asposeDoc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedFields;

                //execute the mail merge
                _asposeDoc.MailMerge.Execute(_source);

                //send back a converted PDF
                MemoryStream outStream = new MemoryStream();
                if (UseWord)
                {
                    _asposeDoc.Save(outStream, Aspose.Words.SaveFormat.Doc);
                }
                else
                {
                    _asposeDoc.Save(outStream, Aspose.Words.SaveFormat.Pdf);
                }
                _mailngListDoc = outStream.ToArray();

                //save the dealer mailinglist in the database
                DealerMailingList _list = new DealerMailingList()
                {
                    CreationDate = DateTime.Now, DealerID = _mergeDealer.ID, DocTemplateID = this.ID, StartFilterDate = _startDate, EndFilterDate = _endDate, NumberCases = _cases.Count
                };
                DealerMailingListService.Save(_list);
                foreach (BankruptcyCase _case in _cases)
                {
                    DealerMailingListCaseService.Insert(new DealerMailingListCase()
                    {
                        BankruptcyCaseID = _case.ID, DealerID = _mergeDealer.ID, DealerMailingListID = _list.ID
                    });
                }

                return(_mailngListDoc);
            }
        }