public bool updateSegmentDetails() { bool status = true; try { AdvanceListMasterPrimaryKey pk = new AdvanceListMasterPrimaryKey(Convert.ToInt64(hdfListId.Value));//hiddenEditID.Value)); AdvanceListMaster listMasterNew = AdvanceListMaster.SelectOne(pk, ConnectionString); listMaster.ListMasterID = Convert.ToInt64(hdfListId.Value); listMaster.ListName = txtSegmentName.Text; listMaster.ListDesc = txtDescription.Text; listMaster.ModifiedDate = System.DateTime.Now; listMaster.CreatedDate = listMasterNew.CreatedDate; listMaster.IsSegment = true; listMaster.Update(); segmentInfo = (DataTable)ViewState["SegementDetails"]; segmentMaster.ListMasterID = Convert.ToInt64(hdfListId.Value); segmentMaster.SegmentName = txtSegmentName.Text; segmentMaster.SelectCondition = segmentInfo.Rows[0]["SelectCondition"].ToString(); segmentMaster.SegmentFilter = segmentInfo.Rows[0]["SegmentFilter"].ToString(); segmentMaster.Type = segmentInfo.Rows[0]["Type"].ToString(); segmentMaster.Update(); Response.Redirect("~/pages/Segments.aspx?name=" + txtSegmentName.Text + "&mode=update"); return status; } catch (Exception) { return false; } }
/// <summary> /// This method will get row(s) from the database using the value of the field specified /// along with the details of the child table. /// </summary> /// /// <param name="pk" type="AdvanceListMasterPrimaryKey">Primary Key information based on which data is to be fetched.</param> /// /// <returns>object of class AdvanceListContactMasters</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 7/28/2012 02:17:32 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// public static AdvanceListContactMasters SelectAllByForeignKeyFromAdvanceListMaster(AdvanceListMasterPrimaryKey pk, string ConnectionString) { DatabaseHelper oDatabaseHelper = new DatabaseHelper(ConnectionString); bool ExecutionState = false; AdvanceListContactMasters obj = null; // Pass the values of all key parameters to the stored procedure. System.Collections.Specialized.NameValueCollection nvc = pk.GetKeysAndValues(); foreach (string key in nvc.Keys) { oDatabaseHelper.AddParameter("@" + key,nvc[key] ); } // The parameter '@ErrorCode' will contain the status after execution of the stored procedure. oDatabaseHelper.AddParameter("@ErrorCode", -1, System.Data.ParameterDirection.Output); IDataReader dr=oDatabaseHelper.ExecuteReader("sp_AdvanceListContactMaster_SelectAllByForeignKeyAdvanceListMaster", ref ExecutionState); obj = new AdvanceListContactMasters(); obj = AdvanceListContactMaster.PopulateObjectsFromReaderWithCheckingReader(dr, oDatabaseHelper, ConnectionString); dr.Close(); oDatabaseHelper.Dispose(); return obj; }
public void ProcessSingleAdvancedImportRecipients(DataRow dr) { bool isFirstRowHeader = false; bool isSendNotificationEmail = false; char[] delimiterChar = null; DataTable dtFileData = null; string[] strFileData = null; StreamReader sr = null; int JobID = 0; try { Logger.logdata(logforimportrecipients, "************** in ProcessSingleAdvancedImportRecipients(..) method **************"); Logger.logdata(logforimportrecipients, string.Format("ProcessSingleAdvancedImportRecipients(..) has been started at {0}", DateTime.Now.ToString())); Logger.logdata(logforimportrecipients, string.Format("Import process satarted for job with ID: {0} at {1}", dr["ID"].ToString(), DateTime.Now.ToString())); //Get the filename of imported file. string filename = dr["GuidFilename"].ToString(); ImportJobID = dr["ID"].ToString(); DateTime importStartTime = DateTime.Now; if (File.Exists(Path.Combine(importFilePath, filename))) { //update import job status AdvancedImportJobPrimaryKey objAdvancedImportJobPrimaryKey = new AdvancedImportJobPrimaryKey(Convert.ToInt64(ImportJobID)); AdvancedImportJob objAdvancedImportJob = AdvancedImportJob.SelectOne(objAdvancedImportJobPrimaryKey, connectionString); objAdvancedImportJob.Status = Common.ImportStatus.InProcess.ToString(); //AdvancedImportJob obj = new AdvancedImportJob(connectionString); //obj.Update(); objAdvancedImportJob.Update(); //Insert Import History ReplyPositiveBL.AdvancedImportHistory objImportHistory = new ReplyPositiveBL.AdvancedImportHistory(connectionString); objImportHistory.ImportJobID = Convert.ToInt64(ImportJobID); objImportHistory.Staus = "Processing"; objImportHistory.StatusMessage = "File import is in processing."; //objImportHistory.UpdatedCount = updatedCount; //objImportHistory.InsertedCount = insertedCount; objImportHistory.StartTime = importStartTime; //objImportHistory.EndTime = DateTime.Now; objImportHistory.InsertandReturnID(ref JobID); isSendNotificationEmail = Convert.ToBoolean(dr["Notification"].ToString()); isFirstRowHeader = Convert.ToBoolean(dr["IsFileHasHeader"].ToString()); delimiterChar = getSeparatorChar(dr["FileType"].ToString()); Logger.logdata(logforimportrecipients, string.Format("import filepath: {0}", Path.Combine(importFilePath, filename))); //Read the import file content. FileStream Stream = new FileStream(Path.Combine(importFilePath, filename), FileMode.Open, FileAccess.Read); Logger.logdata(logforimportrecipients, string.Format("stream length: {0}", Stream.Length)); //convert file stream to datatable. if (dr["FileType"].ToString().Equals("Excel(.xls, .xlsx)")) { //Commented By swaroop June7-12 dtFileData = getDataTableOfExcel(Stream, filename, false); //dtFileData = getDataTableOfExcel(Stream, filename, isFirstRowHeader); } else { sr = new StreamReader(Stream); strFileData = sr.ReadToEnd().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); dtFileData = convertFileToDatatable(strFileData, isFirstRowHeader, delimiterChar); } //remove header from datatable if first row is header. if (isFirstRowHeader) { dtFileData.Rows.RemoveAt(0); } //get fieldmap sqlQry = "select * from AdvancedFieldMap where ImportJobID =" + ImportJobID; ds = getDataset(sqlQry); DataTable dtFieldMap = ds.Tables[0]; //The following code is for removing Unmapped columns while importing a file to List if (dtFileData.Columns.Count != dtFieldMap.Rows.Count) { string[] ActualColumns = (from dc in dtFileData.Columns.Cast<DataColumn>() select dc.ColumnName).ToArray(); string[] MappedColumns = dtFieldMap.AsEnumerable().Select(row => row.Field<string>("SourceField")).ToArray(); string[] UnMappedColumns = ActualColumns.Except(MappedColumns).ToArray(); foreach (string clm in UnMappedColumns) { if (dtFileData.Columns.Contains(clm)) dtFileData.Columns.Remove(clm); } } // process file data if (dtFileData.Rows.Count > 0) { Logger.logdata(logforimportrecipients, string.Format("total number of records found in imported file: {0}", dtFileData.Rows.Count)); string emailAddressColumn = dtFieldMap.Select("DestinationField='EmailAddress'")[0]["SourceField"].ToString(); string purlColumn =dtFieldMap.Select("DestinationField='Purl'")[0]["SourceField"].ToString(); dtFileData = RemoveDuplicateRows(dtFileData,purlColumn, dtFieldMap); Logger.logdata(logforimportrecipients, string.Format("valid recipients count in selected file: {0}", dtFileData.Rows.Count)); int totalRecipientsFound = dtFileData.Rows.Count; int validRecipientsFound = dtFileData.Rows.Count; int inValidRecipientsFound = totalRecipientsFound - validRecipientsFound; int insertedCount = 0; int updatedCount = 0; if (dtFileData.Rows.Count == 0) { //throw new Exception("Please select proper file to import."); } //upsert into RecipientMaster and listcontactmaster based on importlimit. var AllRecords = from item in dtFileData.AsEnumerable() select item; Logger.logdata(logforimportrecipients, string.Format("all records count in selected file: {0}", AllRecords.Count())); int nextRecords = 0; int importLimit = Convert.ToInt32(ConfigurationManager.AppSettings["ImportRecipientsLimit"].ToString()); Logger.logdata(logforimportrecipients, string.Format("Import limit: {0}", importLimit)); while (true) { Logger.logdata(logforimportrecipients, string.Format("looping records: {0}", nextRecords)); var top1000 = AllRecords.Skip(nextRecords).Take(importLimit); if (top1000.Count() == 0) { break; } else { DataTable dtContacts = dtFileData.Clone(); top1000.CopyToDataTable(dtContacts, LoadOption.PreserveChanges); DataTable dtListContactMasterResult = ImportRecordsToRecipientMaster(dtContacts, dtFieldMap, dr); insertedCount += Convert.ToInt32(dtListContactMasterResult.Compute("Count(Status)", "Status='Inserted' and ListMasterID=" + Convert.ToInt64(dr["ListID"].ToString()))); updatedCount += Convert.ToInt32(dtListContactMasterResult.Compute("Count(Status)", "Status='Updated' and ListMasterID=" + Convert.ToInt64(dr["ListID"].ToString()))); nextRecords = nextRecords + importLimit; } } Logger.logdata(logforimportrecipients, string.Format("total number of records inserted: {0}", insertedCount)); Logger.logdata(logforimportrecipients, string.Format("total number of records found updated: {0}", updatedCount)); //build html string to send notification email. //get listname of listid`````````````` AdvanceListMasterPrimaryKey objListMasterPrimaryKey = new AdvanceListMasterPrimaryKey(Convert.ToInt64(dr["ListID"])); AdvanceListMaster objListmaster = AdvanceListMaster.SelectOne(objListMasterPrimaryKey, connectionString); StringBuilder objStringBuilder = new StringBuilder(); objStringBuilder.Append("<table width=100%>"); objStringBuilder.Append("<tr><td>" + string.Format("Imported file: <b>{0}</b>.", dr["Filename"].ToString()) + "</td></tr>"); objStringBuilder.Append("<tr><td>" + string.Format("Total number of recipients found: <b>{0}</b>.", totalRecipientsFound) + "</td></tr>"); objStringBuilder.Append("<tr><td>" + string.Format("Number of valid recipients found: <b>{0}</b>.", validRecipientsFound) + "</td></tr>"); objStringBuilder.Append("<tr><td>" + string.Format("Number of InValid recipients found: <b>{0}</b>.", inValidRecipientsFound) + "</td></tr>"); objStringBuilder.Append("<br>"); objStringBuilder.Append("<br>"); objStringBuilder.Append("<tr><td><b>ListName</b></td><td><b>Inserted</b></td><td><b>Updated</b></td>"); objStringBuilder.Append("<tr><td colspan=3><hr></td></tr>"); objStringBuilder.Append("<tr><td>" + objListmaster.ListName + "</td><td>" + insertedCount + "</td><td>" + updatedCount + "</td></tr>"); //update import job status //ImportJobPrimaryKey objAdvancedImportJobPrimaryKey = new AdvancedImportJobPrimaryKey(Convert.ToInt64(ImportJobID)); //ImportJob objAdvancedImportJob = AdvancedImportJob.SelectOne(objAdvancedImportJobPrimaryKey, connectionString); objAdvancedImportJob.Status = Common.ImportStatus.Success.ToString(); objAdvancedImportJob.Update(); //Insert Import History //ReplyPositiveBL.ImportHistory objImportHistory = new ReplyPositiveBL.AdvancedImportHistory(connectionString); objImportHistory.ImportJobID = Convert.ToInt64(ImportJobID); objImportHistory.Staus = "SUCCESS"; objImportHistory.StatusMessage = "File import process completed successfully."; objImportHistory.UpdatedCount = updatedCount; objImportHistory.InsertedCount = insertedCount; objImportHistory.InvalidCount = inValidRecipientsFound; objImportHistory.StartTime = importStartTime; objImportHistory.ID = JobID; objImportHistory.EndTime = DateTime.Now; objImportHistory.Update(); //send notification email. if (isSendNotificationEmail) sendNotificationMail(objStringBuilder.ToString(), dr["NotificationEmailIDs"].ToString(), filename); } } Logger.logdata(logforimportrecipients, string.Format("Import process ended for job with ID: {0} at {1}", dr["ID"].ToString(), DateTime.Now.ToString())); Logger.logdata(logforimportrecipients, string.Format("ProcessSingleAdvancedImportRecipients(..) method has been ended at {0}", DateTime.Now.ToString())); Logger.logdata(logforimportrecipients, "************** Exit ProcessSingleImportRecipients(..) method **************"); } catch (Exception ex) { //update import job status ImportJobPrimaryKey objImportJobPrimaryKey = new ImportJobPrimaryKey(Convert.ToInt64(ImportJobID)); ImportJob objImportJob = ImportJob.SelectOne(objImportJobPrimaryKey, connectionString); objImportJob.Status = Common.ImportStatus.Error.ToString(); objImportJob.Update(); throw ex; } }
/// <summary> /// This method will get row(s) from the database using the value of the field specified /// along with the details of the child table. /// </summary> /// /// <param name="pk" type="AdvanceListMasterPrimaryKey">Primary Key information based on which data is to be fetched.</param> /// /// <returns>object of class AdvanceListMaster</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 7/28/2012 02:16:48 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// public static AdvanceListMaster SelectOneWithAdvanceListMasterUsingListMasterID(AdvanceListMasterPrimaryKey pk,string ConnectionString) { DatabaseHelper oDatabaseHelper = new DatabaseHelper(ConnectionString); bool ExecutionState = false; AdvanceListMaster obj=null; // Pass the values of all key parameters to the stored procedure. System.Collections.Specialized.NameValueCollection nvc = pk.GetKeysAndValues(); foreach (string key in nvc.Keys) { oDatabaseHelper.AddParameter("@" + key,nvc[key] ); } // The parameter '@ErrorCode' will contain the status after execution of the stored procedure. oDatabaseHelper.AddParameter("@ErrorCode", -1, System.Data.ParameterDirection.Output); IDataReader dr=oDatabaseHelper.ExecuteReader("sp_AdvanceListMaster_SelectOneWithAdvanceListMasterUsingListMasterID", ref ExecutionState); if (dr.Read()) { obj = new AdvanceListMaster(ConnectionString); PopulateObjectFromReader(obj,dr); dr.NextResult(); //Get the child records. obj.AdvanceListMasters=AdvanceListMaster.PopulateObjectsFromReader(dr,ConnectionString); } dr.Close(); oDatabaseHelper.Dispose(); return obj; }
/// <summary> /// This method will Delete one row from the database using the primary key information /// </summary> /// /// <param name="pk" type="AdvanceListMasterPrimaryKey">Primary Key information based on which data is to be fetched.</param> /// /// <returns>True if succeeded</returns> /// /// <remarks> /// /// <RevisionHistory> /// Author Date Description /// DLGenerator 7/28/2012 02:16:48 PM Created function /// /// </RevisionHistory> /// /// </remarks> /// public static bool Delete(AdvanceListMasterPrimaryKey pk) { DatabaseHelper oDatabaseHelper = new DatabaseHelper(); bool ExecutionState = false; // Pass the values of all key parameters to the stored procedure. System.Collections.Specialized.NameValueCollection nvc = pk.GetKeysAndValues(); foreach (string key in nvc.Keys) { oDatabaseHelper.AddParameter("@" + key,nvc[key] ); } // The parameter '@ErrorCode' will contain the status after execution of the stored procedure. oDatabaseHelper.AddParameter("@ErrorCode", -1, System.Data.ParameterDirection.Output); oDatabaseHelper.ExecuteScalar("sp_AdvanceListMaster_Delete", ref ExecutionState); oDatabaseHelper.Dispose(); return ExecutionState; }
private void createSegemnt(string SegmentType) { try { lblMainMsg.Text = string.Empty; AdvanceListMasterBase listMaster = new AdvanceListMasterBase(ConnectionString); AdvanceSegmentMasterBase segmentMaster = new AdvanceSegmentMasterBase(ConnectionString); AdvanceListContactMaster objListContactMaster = new AdvanceListContactMaster(ConnectionString); DataTable dtListContactMaster = new DataTable(); dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string))); dtListContactMaster.Columns.Add(new DataColumn("IsSegment", typeof(bool))); dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool))); List<string> contactids = new List<string>(); contactids = (List<string>)Session["ContactId"]; if (hdfListId.Value != "") { bool isDeleted = objListContactMaster.DeleteAllContactsFromList(Convert.ToInt64(hdfListId.Value)); if (isDeleted) { foreach (string contactID in contactids) { DataRow rowListContactMaster = dtListContactMaster.NewRow(); rowListContactMaster["ListMasterID"] = hdfListId.Value; rowListContactMaster["ContactId"] = contactID; //rowListContactMaster["CreatedDate"] = DateTime.Now.ToString(); rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString(); rowListContactMaster["IsActive"] = true; dtListContactMaster.Rows.Add(rowListContactMaster); } string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" }; string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" }; AdvanceListContactMaster.BulkCopy(dtListContactMaster, "AdvanceListContactMaster", SourceColumn, DestinationColumn, ConnectionString); AdvanceListMasterPrimaryKey pk = new AdvanceListMasterPrimaryKey(Convert.ToInt64(hdfListId.Value));//hiddenEditID.Value)); AdvanceListMaster listMasterNew = AdvanceListMaster.SelectOne(pk, ConnectionString); listMaster.ListMasterID = Convert.ToInt64(hdfListId.Value); listMaster.ListName = txtSegmentName.Text; listMaster.ListDesc = txtDescription.Text; listMaster.CreatedDate = listMasterNew.CreatedDate; listMaster.ModifiedDate = System.DateTime.Now; listMaster.IsSegment = true; listMaster.Update(); segmentMaster.ListMasterID = Convert.ToInt64(hdfListId.Value); segmentMaster.SegmentName = txtSegmentName.Text; segmentMaster.SelectCondition = SelectedIds.Value.Substring(0, SelectedIds.Value.Length); if (rbSegCamRecOnly.Checked) HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='QueryBuild(this);'"); else HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='ListQueryBuild(this);'"); HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorName\"", "\"ddlOperator\" onChange='getSearchKeys(this);'"); HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorDefault\"", "\"ddlOperatorCommon\" onChange='displayDefaultValues(this);'"); segmentMaster.SegmentFilter = HtmlContent.Value; segmentMaster.Type = SegmentType; segmentMaster.Update(); } Response.Redirect("~/pages/Segments.aspx?name=" + txtSegmentName.Text + "&mode=update"); } else { if (rgdContacts.MasterTableView.Items.Count > 0) { listMaster.ListName = txtSegmentName.Text; listMaster.ListDesc = txtDescription.Text; listMaster.CreatedDate = System.DateTime.Now; listMaster.IsSegment = true; listMaster.InsertWithDefaultValues(true); Int64 listid = Convert.ToInt64(listMaster.ListMasterID); segmentMaster.ListMasterID = listid; segmentMaster.SegmentName = txtSegmentName.Text; segmentMaster.SelectCondition = SelectedIds.Value.Substring(0, SelectedIds.Value.Length); if (rbSegCamRecOnly.Checked) HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='QueryBuild(this);'"); else HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='ListQueryBuild(this);'"); HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorName\"", "\"ddlOperator\" onChange='getSearchKeys(this);'"); HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorDefault\"", "\"ddlOperatorCommon\" onChange='displayDefaultValues(this);'"); segmentMaster.SegmentFilter = HtmlContent.Value; segmentMaster.Type = SegmentType; segmentMaster.Insert(); foreach (string contactID in contactids) { DataRow rowListContactMaster = dtListContactMaster.NewRow(); rowListContactMaster["ListMasterID"] = listid; rowListContactMaster["ContactId"] = contactID; rowListContactMaster["CreatedDate"] = DateTime.Now.ToString(); rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString(); rowListContactMaster["IsActive"] = true; dtListContactMaster.Rows.Add(rowListContactMaster); } string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" }; string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" }; AdvanceListContactMaster.BulkCopy(dtListContactMaster, "AdvanceListContactMaster", SourceColumn, DestinationColumn, ConnectionString); } } Response.Redirect("~/pages/Segments.aspx?name=" + txtSegmentName.Text + "&mode=create"); } catch (Exception ex) { lblMainMsg.Text = "Error: " + ex.Message; //lblMainMsg.Visible = true; rtsAddSegment.SelectedIndex = 0; rtsAddSegment.MultiPage.SelectedIndex = 0; } }