static public void Save(DealerMailingList objDealerMailingList, Database db, DbTransaction trans, bool CommitTrans) { try { if (objDealerMailingList.IsModified == true) { if (objDealerMailingList.ID == 0) { Insert(objDealerMailingList, db, trans); } else { Update(objDealerMailingList, db, trans); } } if (CommitTrans == true) { trans.Commit(); } } catch (Exception e) { if (CommitTrans == true) { //we were hoping to commit the transaction which means we're at the end so //Roll back the transaction. Otherwise just rethrow the error and let the next //higher level catch it and rollback trans.Rollback(); } //and then rethrow the error throw (e); } }
static public void Delete(DealerMailingList objDealerMailingList) { Database db = DatabaseFactory.CreateDatabase("BKLeadsOnline"); System.Data.Common.DbCommand dbCommand = db.GetStoredProcCommand("p_DealerMailingListDelete"); db.AddInParameter(dbCommand, "ID", DbType.Int32, objDealerMailingList.ID); db.ExecuteNonQuery(dbCommand); }
static private void Insert(DealerMailingList objDealerMailingList) { Database db = DatabaseFactory.CreateDatabase("BKLeadsOnline"); System.Data.Common.DbCommand dbCommand = db.GetStoredProcCommand("p_DealerMailingListInsert"); db.AddOutParameter(dbCommand, "ID", DbType.Int32, 4); if (objDealerMailingList.DealerID > 0) { db.AddInParameter(dbCommand, "DealerID", DbType.Int32, objDealerMailingList.DealerID); } else { db.AddInParameter(dbCommand, "DealerID", DbType.Int32, Convert.DBNull); } if (objDealerMailingList.CreationDate > DateTime.MinValue) { db.AddInParameter(dbCommand, "CreationDate", DbType.DateTime, objDealerMailingList.CreationDate); } else { db.AddInParameter(dbCommand, "CreationDate", DbType.DateTime, Convert.DBNull); } if (objDealerMailingList.StartFilterDate > DateTime.MinValue) { db.AddInParameter(dbCommand, "StartFilterDate", DbType.DateTime, objDealerMailingList.StartFilterDate); } else { db.AddInParameter(dbCommand, "StartFilterDate", DbType.DateTime, Convert.DBNull); } if (objDealerMailingList.EndFilterDate > DateTime.MinValue) { db.AddInParameter(dbCommand, "EndFilterDate", DbType.DateTime, objDealerMailingList.EndFilterDate); } else { db.AddInParameter(dbCommand, "EndFilterDate", DbType.DateTime, Convert.DBNull); } db.AddInParameter(dbCommand, "NumberCases", DbType.Int32, objDealerMailingList.NumberCases); db.AddInParameter(dbCommand, "Printed", DbType.Boolean, objDealerMailingList.Printed); if (objDealerMailingList.DocTemplateID > 0) { db.AddInParameter(dbCommand, "DocTemplateID", DbType.Int32, objDealerMailingList.DocTemplateID); } else { db.AddInParameter(dbCommand, "DocTemplateID", DbType.Int32, Convert.DBNull); } db.ExecuteNonQuery(dbCommand); objDealerMailingList.ID = Int32.Parse(db.GetParameterValue(dbCommand, "ID").ToString()); }
static public void Save(DealerMailingList objDealerMailingList) { if (objDealerMailingList.IsModified == true) { if (objDealerMailingList.ID == 0) { Insert(objDealerMailingList); } else { Update(objDealerMailingList); } } }
public DealerMailingList Copy() { DealerMailingList _dealerMailingList = new DealerMailingList(); _dealerMailingList.ID = _iD; _dealerMailingList.DealerID = _dealerID; _dealerMailingList.CreationDate = _creationDate; _dealerMailingList.StartFilterDate = _startFilterDate; _dealerMailingList.EndFilterDate = _endFilterDate; _dealerMailingList.NumberCases = _numberCases; _dealerMailingList.Printed = _printed; _dealerMailingList.DocTemplateID = _docTemplateID; _dealerMailingList.DealerName = _dealerName; _dealerMailingList.DocTemplateDisplayName = _docTemplateDisplayName; return(_dealerMailingList); }
static private void LoadDealerMailingList(DealerMailingList objDealerMailingList, IDataReader _reader) { if (_reader.IsDBNull(0) != true) { objDealerMailingList.ID = _reader.GetInt32(0); } if (_reader.IsDBNull(1) != true) { objDealerMailingList.DealerID = _reader.GetInt32(1); } if (_reader.IsDBNull(2) != true) { objDealerMailingList.CreationDate = _reader.GetDateTime(2); } if (_reader.IsDBNull(3) != true) { objDealerMailingList.StartFilterDate = _reader.GetDateTime(3); } if (_reader.IsDBNull(4) != true) { objDealerMailingList.EndFilterDate = _reader.GetDateTime(4); } if (_reader.IsDBNull(5) != true) { objDealerMailingList.NumberCases = _reader.GetInt32(5); } if (_reader.IsDBNull(6) != true) { objDealerMailingList.Printed = _reader.GetBoolean(6); } if (_reader.IsDBNull(7) != true) { objDealerMailingList.DocTemplateID = _reader.GetInt32(7); } if (_reader.IsDBNull(8) != true) { objDealerMailingList.DealerName = _reader.GetString(8); } if (_reader.IsDBNull(9) != true) { objDealerMailingList.DocTemplateDisplayName = _reader.GetString(9); } }
//get the existing mailing lists static public List <DealerMailingList> GetForDealer(int DealerID) { List <DealerMailingList> objDealerMailingLists = new List <DealerMailingList>(); Database db = DatabaseFactory.CreateDatabase("BKLeadsOnline"); using (IDataReader reader = db.ExecuteReader(CommandType.Text, _selectViewSQL + " Where DealerID = " + DealerID + " Order by EndFilterDate desc ")) { while (reader.Read()) { DealerMailingList objDealerMailingList = new DealerMailingList(); LoadDealerMailingList(objDealerMailingList, reader); objDealerMailingList.IsModified = false; objDealerMailingLists.Add(objDealerMailingList); } // always call Close when done reading. reader.Close(); return(objDealerMailingLists); } }
static public DealerMailingList GetByID(int ID) { DealerMailingList objDealerMailingList = new DealerMailingList(); string query = _selectViewSQL + " where ID = " + ID; Database db = DatabaseFactory.CreateDatabase("BKLeadsOnline"); using (IDataReader reader = db.ExecuteReader(CommandType.Text, query)) { if (reader.Read()) { LoadDealerMailingList(objDealerMailingList, reader); // always call Close when done reading. reader.Close(); objDealerMailingList.IsModified = false; return(objDealerMailingList); } else { return(null); } } }
/// <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); } }