Пример #1
0
        /// <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="ImportJobPrimaryKey">Primary Key information based on which data is to be fetched.</param>
        ///
        /// <returns>object of class FieldMaps</returns>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			11/21/2009 4:19:24 PM				Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        public static FieldMaps SelectAllByForeignKeyFromImportJob(ImportJobPrimaryKey pk, String ConnectionString)
        {
            DatabaseHelper oDatabaseHelper = new DatabaseHelper(ConnectionString);
            bool ExecutionState = false;
            FieldMaps 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_FieldMap_SelectAllByForeignKeyImportJob", ref ExecutionState);
            obj = new FieldMaps();
            obj = FieldMap.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;
            }
        }
Пример #3
0
        /// <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="ImportJobPrimaryKey">Primary Key information based on which data is to be fetched.</param>
        ///
        /// <returns>object of class ImportJob</returns>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			1/27/2010 1:09:45 PM				Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        public static ImportJob SelectOneWithImportHistoryUsingImportJobID(ImportJobPrimaryKey pk, string ConnectionString)
        {
            DatabaseHelper oDatabaseHelper = new DatabaseHelper(ConnectionString);
            bool ExecutionState = false;
            ImportJob 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_ImportJob_SelectOneWithImportHistoryUsingImportJobID", ref ExecutionState);
            if (dr.Read())
            {
                obj= new ImportJob(ConnectionString);
                PopulateObjectFromReader(obj,dr);

                dr.NextResult();

                //Get the child records.
                obj.ImportHistories=ImportHistory.PopulateObjectsFromReader(dr,ConnectionString);
            }
            dr.Close();
            oDatabaseHelper.Dispose();
            return obj;
        }
        //this method is used to insert the recipients of a single ImportJob into ListContactMaster and ContactMaster table
        public void ProcessSingleImportRecipients(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 ProcessSingleImportRecipients(..) method **************");
                Logger.logdata(logforimportrecipients, string.Format("ProcessSingleImportRecipients(..) 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
                    ImportJobPrimaryKey objImportJobPrimaryKey = new ImportJobPrimaryKey(Convert.ToInt64(ImportJobID));
                    ImportJob objImportJob = ImportJob.SelectOne(objImportJobPrimaryKey, connectionString);
                    objImportJob.Status = Common.ImportStatus.InProcess.ToString();
                    objImportJob.Update();
                    //Insert Import History
                    ReplyPositiveBL.ImportHistory objImportHistory = new ReplyPositiveBL.ImportHistory(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)"))
                    {
                        if (filename.EndsWith(".xls"))
                            dtFileData = getDataTableOfExcel(Stream, filename, false);
                        else
                        {
                            string path = Path.Combine(importFilePath, filename);
                            System.Data.DataTable Contacts = new System.Data.DataTable();

                            ReadXlsx.Application xlApp;
                            ReadXlsx.Workbook xlWorkBook;
                            ReadXlsx.Worksheet xlWorkSheet;

                            xlApp = new ReadXlsx.ApplicationClass();
                            xlWorkBook = xlApp.Workbooks.Open(path, 0, true, 5, "", "", true, ReadXlsx.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                            xlWorkSheet = (ReadXlsx.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                            int r;
                            int c;
                            int intRows;
                            int intCols;
                            ReadXlsx.Range excelCell = xlWorkSheet.UsedRange;
                            Object[,] values = (Object[,])excelCell.Value2;
                            intRows = values.GetLength(0);
                            if (intRows != 0)
                            {
                                intCols = values.GetLength(1);
                                if (intCols != 0)
                                {
                                    for (c = 1; c <= intCols; c++)
                                    {
                                        Contacts.Columns.Add(new DataColumn("Column" + c));
                                    }
                                    for (r = 1; r <= intRows; r++)
                                    {
                                        DataRow tblRow = Contacts.NewRow();
                                        for (c = 0; c < Contacts.Columns.Count; c++)
                                        {
                                            tblRow[c] = (values[r, (c + 1)] == null) ? string.Empty : values[r, (c + 1)];

                                        }
                                        Contacts.Rows.Add(tblRow);
                                    }
                                }
                            }
                            dtFileData = Contacts;
                            xlWorkSheet = null;
                            xlWorkBook.Close(Missing.Value, Missing.Value, Missing.Value);
                            xlWorkBook = null;
                            xlApp.Quit();
                            xlApp = null;
                        }
                    }
                    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 Fieldmap 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);
                        }
                    }
                    //Bulk insert the import file content in to temp table.
                    //insertImportingContactsInToTemp(dtFileData, dtFieldMap, ImportJobID);

                    //Logger.logdata(logforimportrecipients, string.Format("imported file records are bulk inserted to temp table: {0}", dtFileData.Rows.Count));

                    // 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();

                        var v = from item in dtFieldMap.AsEnumerable() where item["DestinationField"].ToString() == "IsActive" select item;
                        foreach (var obj in v)
                        {
                            IsActiveField = dtFieldMap.Select("DestinationField='IsActive'")[0]["SourceField"].ToString();
                        }

                        DataTable dtValidEmailData = checkInValidEmailAddresses(dtFileData, emailAddressColumn, IsActiveField);
                        //to select distinct rows
                        //dtValidEmailData = dtValidEmailData.DefaultView.ToTable(true, Columns);
                        dtValidEmailData = RemoveDuplicateRows(dtValidEmailData, emailAddressColumn, dtFieldMap);
                        Logger.logdata(logforimportrecipients, string.Format("valid recipients count in selected file: {0}", dtValidEmailData.Rows.Count));
                        int totalRecipientsFound = dtFileData.Rows.Count;
                        int validRecipientsFound = dtValidEmailData.Rows.Count;
                        int inValidRecipientsFound = totalRecipientsFound - validRecipientsFound;
                        int insertedCount = 0;
                        int updatedCount = 0;
                        if (dtValidEmailData.Rows.Count == 0)
                        {
                            //throw new Exception("Please select proper file to import.");
                        }
                        //upsert into contactmaster and listcontactmaster based on importlimit.
                        var AllRecords = from item in dtValidEmailData.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 = dtValidEmailData.Clone();
                                top1000.CopyToDataTable(dtContacts, LoadOption.PreserveChanges);
                                DataTable dtListContactMasterResult = ImportRecordsToContactMaster(dtContacts, dtFieldMap, dr);
                                insertedCount += Convert.ToInt32(dtListContactMasterResult.Compute("Count(Status)", "Status='INSERT' and ListMasterID=" + Convert.ToInt64(dr["ListID"].ToString())));
                                updatedCount += Convert.ToInt32(dtListContactMasterResult.Compute("Count(Status)", "Status='UPDATE' 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``````````````
                        ListMasterPrimaryKey objListMasterPrimaryKey = new ListMasterPrimaryKey(Convert.ToInt64(dr["ListID"]));
                        ListMaster objListmaster = ListMaster.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
                        objImportJobPrimaryKey = new ImportJobPrimaryKey(Convert.ToInt64(ImportJobID));
                        //ImportJob
                        objImportJob = ImportJob.SelectOne(objImportJobPrimaryKey, connectionString);
                        objImportJob.Status = Common.ImportStatus.Success.ToString();
                        objImportJob.Update();

                        //Insert Import History
                        //ReplyPositiveBL.ImportHistory
                        objImportHistory = new ReplyPositiveBL.ImportHistory(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("ProcessSingleImportRecipients(..) 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;
            }
        }
Пример #5
0
        /// <summary>
        /// This method will Delete one row from the database using the primary key information
        /// </summary>
        ///
        /// <param name="pk" type="ImportJobPrimaryKey">Primary Key information based on which data is to be fetched.</param>
        ///
        /// <returns>True if succeeded</returns>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			1/27/2010 1:09:45 PM		Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        public static bool Delete(ImportJobPrimaryKey pk,string ConnectionString)
        {
            DatabaseHelper oDatabaseHelper = new DatabaseHelper(ConnectionString);
            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_ImportJob_Delete", ref ExecutionState);
            oDatabaseHelper.Dispose();
            return ExecutionState;
        }