public XmlDocument SingleCampaignReports(string UserID, string Password, int CampaignID)
        {
            XmlDocument doc = new XmlDocument();
            StringBuilder str = new StringBuilder();
            str.Append("<ReportInfo>");
            string ConnectionString = GetConnectionString(UserID, Password);
            if (ConnectionString.Trim().Length != 0 && CampaignID>0)
            {
                CampaignMasterPrimaryKey objCampaignMasterPrimaryKey = new CampaignMasterPrimaryKey(CampaignID);
                CampaignMaster objCampaignMaster = CampaignMaster.SelectOneWithCampaignJobUsingCampaignMasterID(objCampaignMasterPrimaryKey, ConnectionString);
                CampaignJobPrimaryKey pk=new CampaignJobPrimaryKey(CampaignID);
                CampaignJobs objCampaignjob = CampaignJob.SelectByField("CampaignMasterID", CampaignID, ConnectionString);
                //CampaignJob job = CampaignJob.SelectOne(pk, ConnectionString);

                str.Append("<CampaignMasterID>" + objCampaignMaster.CampaignId.ToString() + "</CampaignMasterID> ");
                str.Append("<CampaignMasterName>" + objCampaignMaster.CampaignName.ToString() + "</CampaignMasterName> ");
                str.Append("<ResultsAsOf>" + DateTime.Now.ToString() + "</ResultsAsOf> ");
                str.Append("<Subject>" + objCampaignMaster.Subject.ToString() + "</Subject> ");

                ListContactMaster objListContactMaster = new ListContactMaster(ConnectionString);
                DataTable dtcontacts = objListContactMaster.getContactsWithCampaignID(objCampaignMaster.SelectCondition, CampaignID.ToString());
                int ForwardCount = -1;
                int Fcount = LinkDetailBase.RecipientsForwardCount(ConnectionString, CampaignID, out ForwardCount);
                long ActiveCount = Convert.ToInt64(dtcontacts.Rows.Count);
                str.Append("<TotalRecipientsCount>" + ActiveCount.ToString() + "</TotalRecipientsCount> ");
                str.Append("<ContactsTargetd>" + ActiveCount.ToString() + "</ContactsTargetd> ");
                foreach (CampaignJob job in objCampaignjob)
                {
                    str.Append("<SucessfulDeliverdCount>" + job.DeliveredCount.ToString() + "</SucessfulDeliverdCount> ");
                    str.Append("<BounceCount>" + job.BounceCount.ToString() + "</BounceCount> ");
                    str.Append("<OpenCount>" + job.OpenCount.ToString() + "</OpenCount> ");
                    str.Append("<ClickCount>" + job.ClickCount.ToString() + "</ClickCount> ");
                    str.Append("<UnsubscribeCount>" + job.UnSubscribeCount.ToString() + "</UnsubscribeCount> ");
                    str.Append("<ForwardCount>" + Fcount .ToString()+ "</ForwardCount>");
                }

                str.Append("<SucessfulDeliverdCount>");
                DataTable ListSuccessfulDelivered = ContactMaster.SelectSuccessfulDeliveredByCampId(ConnectionString, CampaignID);
                if (ListSuccessfulDelivered != null)
                {
                    for (int i = 0; i < ListSuccessfulDelivered.Rows.Count; i++)
                    {
                        str.Append("<Row>" + i.ToString() + "</Row>");
                        str.Append("<EmailAddress>" + ListSuccessfulDelivered.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                    }
                }
                str.Append("</SucessfulDeliverdCount>");

                str.Append("<BounceCount>");
                int TotalBounceCount, SoftBounceCount, HardBounceCount = -1;
                DataTable BounceRecipients = ContactMaster.SelectRecipientsBounceRecByCampId(ConnectionString, CampaignID, out TotalBounceCount, out SoftBounceCount, out HardBounceCount);
                if (BounceRecipients != null)
                {
                    for (int i = 0; i < BounceRecipients.Rows.Count; i++)
                    {
                        str.Append("<Row>" + i.ToString() + "</Row>");
                        str.Append("<EmailAddress>" + BounceRecipients.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                    }
                }
                str.Append("</BounceCount>");

                str.Append("<OpenCount>");
                DataTable emailsOpened = ContactMaster.EmailOpendByCampId(ConnectionString, CampaignID);
                if (emailsOpened != null)
                {
                    for (int i = 0; i < emailsOpened.Rows.Count; i++)
                    {
                        str.Append("<Row>" + i.ToString() + "</Row>");
                        str.Append("<EmailAddress>" + emailsOpened.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                    }
                }
                str.Append("</OpenCount>");

                str.Append("<ClickCount>");
                DataTable emailsClicked = ContactMaster.EmailClickedRecByCampId(ConnectionString, CampaignID);
                if (emailsClicked != null)
                {
                    for (int i = 0; i < emailsClicked.Rows.Count; i++)
                    {
                        str.Append("<Row>" + i.ToString() + "</Row>");
                        str.Append("<EmailAddress>" + emailsClicked.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                    }
                }
                str.Append("</ClickCount>");

                str.Append("<UnsubscribeCount>");
                int NeverOptedCount, CommCount, NotInterestedCount, OtherCount = -1;
                DataTable ListUnsubScribeRecipients = ContactMaster.SelectUnsubscribeRecipients(ConnectionString, CampaignID, out NeverOptedCount, out CommCount, out NotInterestedCount, out OtherCount);
                if (ListUnsubScribeRecipients != null)
                {
                    for (int i = 0; i < ListUnsubScribeRecipients.Rows.Count; i++)
                    {
                        str.Append("<Row>" + i.ToString() + "</Row>");
                        str.Append("<EmailAddress>" + ListUnsubScribeRecipients.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                    }
                }
                str.Append("</UnsubscribeCount>");

                str.Append("<ForwardCount>");
                DataTable forwardRecipients = ContactMaster.SelectForwardRecipients(ConnectionString, CampaignID);
                if (forwardRecipients != null)
                {
                    for (int i = 0; i < forwardRecipients.Rows.Count; i++)
                    {
                        str.Append("<Row>" + i.ToString() + "</Row>");
                        str.Append("<EmailAddress>" + forwardRecipients.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                    }
                }
                str.Append("</ForwardCount>");

                string ss = str.ToString();
            }
            str.Append("</ReportInfo>");
            doc.LoadXml(str.ToString());
            return doc;
        }
Beispiel #2
0
        public XmlDocument GetMailingReportByMailingID(string UserID, string Password, int MailingID)
        {
            XmlDocument doc = new XmlDocument();
            StringBuilder str = new StringBuilder();
            str.Append("<MailingReportInfo>");
            string ConnectionString = GetConnectionString(UserID, Password);
            if (ConnectionString.Trim().Length != 0 && MailingID > 0)
            {
                CampaignMasterPrimaryKey objCampaignMasterPrimaryKey = new CampaignMasterPrimaryKey(MailingID);
                CampaignMaster objCampaignMaster = CampaignMaster.SelectOneWithCampaignJobUsingCampaignMasterID(objCampaignMasterPrimaryKey, ConnectionString);
                if (objCampaignMaster != null)
                {
                    CampaignJobPrimaryKey pk = new CampaignJobPrimaryKey(MailingID);
                    CampaignJobs objCampaignjob = CampaignJob.SelectByField("CampaignMasterID", MailingID, ConnectionString);
                    str.Append("<MailingID>" + objCampaignMaster.CampaignId.ToString() + "</MailingID> ");
                    str.Append("<MailingName>" + objCampaignMaster.CampaignName.ToString() + "</MailingName> ");
                    str.Append("<MailingCreatedDate>" + objCampaignMaster.CreatedDate + "</MailingCreatedDate> ");
                    str.Append("<ResultsAsOf>" + DateTime.Now.ToString() + "</ResultsAsOf> ");
                    str.Append("<Subject>" + objCampaignMaster.Subject.ToString() + "</Subject> ");
                    ListMasterPrimaryKey pkList = new ListMasterPrimaryKey(Convert.ToInt32(objCampaignMaster.SelectCondition));
                    ListMaster listMaster = ListMaster.SelectOne(pkList, ConnectionString);
                    str.Append("<ListName>" + listMaster.ListName + "</ListName> ");

                    ListContactMaster objListContactMaster = new ListContactMaster(ConnectionString);
                    DataTable dtcontacts = objListContactMaster.getContactsWithCampaignID(objCampaignMaster.SelectCondition, MailingID.ToString());
                    int ForwardCount = -1;
                    int Fcount = LinkDetailBase.RecipientsForwardCount(ConnectionString, MailingID, out ForwardCount);
                    long ActiveCount = Convert.ToInt64(dtcontacts.Rows.Count);
                    str.Append("<TotalRecipientsCount>" + ActiveCount.ToString() + "</TotalRecipientsCount> ");
                    str.Append("<ContactsTargetd>" + ActiveCount.ToString() + "</ContactsTargetd> ");

                    foreach (CampaignJob job in objCampaignjob)
                    {
                        str.Append("<ScheduledTime>" + job.ScheduledDatetime.ToString() + "</ScheduledTime> ");
                        str.Append("<CompletionTime>" + job.CompletionTime.ToString() + "</CompletionTime> ");

                        long SentCount = (string.IsNullOrEmpty(job.DeliveredCount.ToString()) == true) ? 0 : Convert.ToInt64(job.DeliveredCount.ToString());
                        str.Append("<SucessfulDeliverdCount>" + SentCount + "</SucessfulDeliverdCount> ");

                        long BCount = (string.IsNullOrEmpty(job.BounceCount.ToString()) == true) ? 0 : Convert.ToInt64(job.BounceCount.ToString());
                        str.Append("<BounceCount>" + BCount + "</BounceCount> ");

                        long OCount = (string.IsNullOrEmpty(job.OpenCount.ToString()) == true) ? 0 : Convert.ToInt64(job.OpenCount.ToString());
                        str.Append("<OpenCount>" + OCount + "</OpenCount> ");

                        long ClickCount = (string.IsNullOrEmpty(job.ClickCount.ToString()) == true) ? 0 : Convert.ToInt64(job.ClickCount.ToString());
                        str.Append("<ClickCount>" + ClickCount + "</ClickCount> ");

                        long UCount = (string.IsNullOrEmpty(job.UnSubscribeCount.ToString()) == true) ? 0 : Convert.ToInt64(job.UnSubscribeCount.ToString());
                        str.Append("<UnsubscribeCount>" + UCount + "</UnsubscribeCount> ");

                        long FCount = (string.IsNullOrEmpty(Fcount.ToString()) == true) ? 0 : Convert.ToInt64(Fcount.ToString());
                        str.Append("<ForwardCount>" + FCount + "</ForwardCount>");
                    }

                    str.Append("<SucessfulDeliverd>");
                    DataTable ListSuccessfulDelivered = ContactMaster.SelectSuccessfulDeliveredByCampId(ConnectionString, MailingID);
                    if (ListSuccessfulDelivered != null)
                    {
                        for (int i = 0; i < ListSuccessfulDelivered.Rows.Count; i++)
                        {
                            str.Append("<EmailAddress>" + ListSuccessfulDelivered.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                        }
                    }
                    str.Append("</SucessfulDeliverd>");

                    str.Append("<BounceContacts>");
                    int TotalBounceCount, SoftBounceCount, HardBounceCount = -1;
                    DataTable BounceRecipients = ContactMaster.SelectRecipientsBounceRecByCampId(ConnectionString, MailingID, out TotalBounceCount, out SoftBounceCount, out HardBounceCount);
                    if (BounceRecipients != null)
                    {
                        for (int i = 0; i < BounceRecipients.Rows.Count; i++)
                        {
                            str.Append("<EmailAddress>" + BounceRecipients.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                        }
                    }
                    str.Append("</BounceContacts>");

                    str.Append("<OpenedContacts>");
                    DataTable emailsOpened = ContactMaster.EmailOpendByCampId(ConnectionString, MailingID);
                    if (emailsOpened != null)
                    {
                        for (int i = 0; i < emailsOpened.Rows.Count; i++)
                        {
                            str.Append("<EmailAddress>" + emailsOpened.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                        }
                    }
                    str.Append("</OpenedContacts>");

                    str.Append("<ClickedContacts>");
                    DataTable emailsClicked = ContactMaster.EmailClickedRecByCampId(ConnectionString, MailingID);
                    if (emailsClicked != null)
                    {
                        for (int i = 0; i < emailsClicked.Rows.Count; i++)
                        {
                            str.Append("<EmailAddress>" + emailsClicked.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                        }
                    }
                    str.Append("</ClickedContacts>");

                    str.Append("<UnsubscribedContacts>");
                    int NeverOptedCount, CommCount, NotInterestedCount, OtherCount = -1;
                    DataTable ListUnsubScribeRecipients = ContactMaster.SelectUnsubscribeRecipients(ConnectionString, MailingID, out NeverOptedCount, out CommCount, out NotInterestedCount, out OtherCount);
                    if (ListUnsubScribeRecipients != null)
                    {
                        for (int i = 0; i < ListUnsubScribeRecipients.Rows.Count; i++)
                        {
                            str.Append("<EmailAddress>" + ListUnsubScribeRecipients.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                        }
                    }
                    str.Append("</UnsubscribedContacts>");

                    str.Append("<ForwardedContacts>");
                    DataTable forwardRecipients = ContactMaster.SelectForwardRecipients(ConnectionString, MailingID);
                    if (forwardRecipients != null)
                    {
                        for (int i = 0; i < forwardRecipients.Rows.Count; i++)
                        {
                            str.Append("<EmailAddress>" + forwardRecipients.Rows[i]["EmailAddress"].ToString() + "</EmailAddress> ");
                        }
                    }
                    str.Append("</ForwardedContacts>");

                    string ss = str.ToString();
                }
                else
                    str.Append("<Message>Mailing with id: " + MailingID + " not exist</Message>");
            }
            else
                str.Append("<Message>Invalid UserName/Password</Message>");


            str.Append("</MailingReportInfo>");
            doc.LoadXml(str.ToString());
            return doc;
        }
        protected void SingleMailingCounts(string campaignID, string mailingId)
        {
            if (ddlMailingNames.SelectedItem.Text != defaultMailingItem)
                lblCampaignTitle.Text = ddlMailingNames.SelectedItem.Text.ToString();
            else if (ddlCampaignsNames.SelectedItem.Text != defaultCampItem)
                lblCampaignTitle.Text = ddlCampaignsNames.SelectedItem.Text.ToString();
            else
            {
                lblCampaignTitle.Text = string.Empty;
            }
            Session["TitleName"] = lblCampaignTitle.Text;

            string selectedList = string.Empty;
            if (mailingId != string.Empty || campaignID != string.Empty)
            {
                long ActiveCount = 0;
                lblContactsTargeted.Text = "0";
                lblSuccessfulDeliveries.Text = "0";
                lblUnsubscribe.Text = "0";
                lblTotalOpens.Text = "0";
                lblUniqueopens.Text = "0";
                lblBounces.Text = "0";
                lblTotalClicks.Text = "0";
                lblUniqueClicks.Text = "0";
                lblForwrds.Text = "0";
                List<string> listsSelected = new List<string>();
                List<string> xValues = new List<string>();
                List<double> yValues = new List<double>();

                string startMailingId = string.Empty;
                string endingMailingId = string.Empty;
                if (ddlCampaignsNames.SelectedItem.Text != defaultCampItem || ddlMailingNames.SelectedItem.Text!=defaultMailingItem)
                {
                    if (ddlMailingNames.SelectedItem.Text == defaultMailingItem)
                    {
                        //Get the Latest Sent Mailing.
                        startMailingId = ddlMailingNames.Items[1].Value.ToString();
                        CampaignMasterPrimaryKey objCampaignMasterPrimaryKey = new CampaignMasterPrimaryKey(Convert.ToInt64(startMailingId));
                        objCampaignMaster = CampaignMaster.SelectOneWithCampaignJobUsingCampaignMasterID(objCampaignMasterPrimaryKey, ConnectionString);

                        objCampaignjob = CampaignJob.SelectByField("CampaignMasterID", Convert.ToInt64(startMailingId), ConnectionString);
                        lblSendCompletionDate.Text = objCampaignjob[0].CompletionTime.ToString();

                        //Get the First Sent Mailing.
                        endingMailingId = ddlMailingNames.Items[ddlMailingNames.Items.Count - 1].Value.ToString();
                        if (ddlCampaignsNames.SelectedItem.Text != defaultCampItem)
                        {
                            objEndCampaignjob = CampaignJob.SelectByField("CampaignMasterID", Convert.ToInt64(endingMailingId), ConnectionString);
                            lblSendStartDate.Text = objEndCampaignjob[0].StartTime.ToString();
                        }
                        else
                        {
                            lblSendStartDate.Text = objCampaignjob[0].StartTime.ToString();
                        }
                    }
                    else
                    {
                        CampaignMasterPrimaryKey objCampaignMasterPrimaryKey = new CampaignMasterPrimaryKey(Convert.ToInt64(mailingId));
                        objCampaignMaster = CampaignMaster.SelectOneWithCampaignJobUsingCampaignMasterID(objCampaignMasterPrimaryKey, ConnectionString);

                        objCampaignjob = CampaignJob.SelectByField("CampaignMasterID", Convert.ToInt64(mailingId), ConnectionString);
                        lblSendStartDate.Text = objCampaignjob[0].StartTime.ToString();
                        lblSendCompletionDate.Text = objCampaignjob[0].CompletionTime.ToString();
                    }
                }
                if (mailingId.Length != 0)
                {

                    if (objCampaignMaster.Subject.Length > 30)
                        lblSubject.Text = objCampaignMaster.Subject.Substring(0, 30) + "..";
                    else
                        lblSubject.Text = objCampaignMaster.Subject.ToString();
                    lblSubject.ToolTip = objCampaignMaster.Subject.ToString();
                    lblsentDateTime.Text = "Sent: " + objCampaignjob[0].CompletionTime.ToString();
                    Session["SentDateTime"] = lblsentDateTime.Text;

                    string SelectCondition = objCampaignMaster.SelectCondition;
                    string[] ListIds = SelectCondition.Split(',');

                    StringBuilder selectedListExport = new StringBuilder();

                    //Commented by Swaroop no need to touch the db iam take the count form indivitual tables code written bellow
                    ListContactMaster objListContactMaster = new ListContactMaster(ConnectionString);
                    DataTable dtcontacts = objListContactMaster.getContactsWithCampaignID(objCampaignMaster.SelectCondition, mailingId.ToString());
                    Session["ContactsTargeted"] = dtcontacts;
                    foreach (var Id in ListIds)
                    {
                        if (Id != "")
                        {
                            ListMasterPrimaryKey pk = new ListMasterPrimaryKey(Convert.ToInt64(Id));
                            ListMaster list = ListMaster.SelectOne(pk, ConnectionString);
                            if (list != null)
                            {
                                bool IsListRemoved = true;
                                if (list.IsDeleted == null || list.IsDeleted == false)
                                    IsListRemoved = false;

                                if (!IsListRemoved)
                                    selectedList += list.ListName.ToString() + ",";
                                else
                                {
                                    selectedList += list.ListName.ToString() + "(List has been removed),";
                                }

                                listsSelected.Add(list.ListName);
                            }
                        }
                    }
                    if (selectedList != "")
                        selectedList = selectedList.TrimEnd(',');
                    if (selectedList.Length > 0)
                    {
                        lblSelectedList.Style.Add("color", "#717171");
                        selectedList.Remove(selectedList.Length - 2, 1);
                        lblSelectedList.Text = selectedList.ToString();
                        Session["ListNames"] = selectedList.ToString();
                    }
                    else
                    {
                        selectedList = "The List has been moved or removed";
                        Session["ListNames"] = selectedList.ToString();
                        lblSelectedList.Text = string.Empty;
                        lblSelectedList.Style.Add("color", "red");
                        lblSelectedList.Text = "The List has been moved or removed";
                    }
                    if (selectedList.Length >= 30)
                    {
                        lblSelectedList.Text = selectedList.Substring(0, 30) + "...";
                        lblSelectedList.ToolTip = selectedList;
                    }
                }
                lblResultsAsOf.Text = DateTime.Now.ToString();
                //Bellow mailingId become to empty bcz. when iam selecting only Campaign not Mailing at that time only we want to disply latest sent Mailing Info of particular Campaign.
                if (hdfMailingID.Value == string.Empty)
                    mailingId = string.Empty;

                #region Swaroop
                //Get the values form Individual Tables Link EmailOpenDatils Developed By Swaroop etc...

                DataTable ListSuccessfulDelivered, emailsOpened, emailsClicked, BounceRecipients, forwardRecipients, ListUnsubScribeRecipients = null;

                if (mailingId != string.Empty)
                {
                    ListSuccessfulDelivered = ContactMaster.SelectSuccessfulDeliveredByCampId(ConnectionString, Convert.ToInt32(mailingId));
                    sentcount = ListSuccessfulDelivered.Rows.Count;
                }
                else
                {
                    ListSuccessfulDelivered = ContactMaster.SelectSuccessfulDeliveredByAssignCampId(ConnectionString, Convert.ToInt32(campaignID));
                    sentcount = ListSuccessfulDelivered.Rows.Count;
                }

                if (mailingId != string.Empty)
                {
                    emailsOpened = ContactMaster.EmailOpendRecByCampId_PageWise(ConnectionString, mailingId, "ContactId", "desc", 0, 10, out Count, out TotalOpenCounts, out UniqueOpenCounts);
                    opencount = UniqueOpenCounts;
                }
                else
                {
                    emailsOpened = ContactMaster.EmailOpendRecByAssignCampId_PageWise(ConnectionString, campaignID, "ContactId", "desc", 0, 10, out Count, out TotalOpenCounts, out UniqueOpenCounts);
                    opencount = UniqueOpenCounts;
                }
                if (mailingId != string.Empty)
                {
                    emailsClicked = ContactMaster.EmailClickedRecByCampId_PageWise(ConnectionString, mailingId, "ContactId", "desc", 0, 10, out Count, out TotalClickCounts, out UniqueClickCounts);
                }
                else
                {
                    emailsClicked = ContactMaster.EmailClickedRecByAssignCampId_PageWise(ConnectionString, campaignID, "ContactId", "desc", 0, 10, out Count, out TotalClickCounts, out UniqueClickCounts);
                }
                if (mailingId != string.Empty)
                {
                    BounceRecipients = ContactMaster.SelectRecipientsBounceRecByCampId(ConnectionString, Convert.ToInt32(mailingId), out TotalBounceCount, out SoftBounceCount, out HardBounceCount);
                    bouncecount = BounceRecipients.Rows.Count;
                }
                else
                {
                    BounceRecipients = ContactMaster.SelectRecipientsBounceRecByAssignCampId(ConnectionString, Convert.ToInt32(campaignID), out TotalBounceCount, out SoftBounceCount, out HardBounceCount);
                    bouncecount = TotalBounceCount;
                }

                unopencount = sentcount - opencount;
                if (mailingId != string.Empty)
                {
                    forwardRecipients = ContactMaster.SelectForwardRecipients(ConnectionString, Convert.ToInt32(mailingId));
                    Fcount = forwardRecipients.Rows.Count;
                }
                else
                {
                    forwardRecipients = ContactMaster.SelectForwardRecipientsByAssignId(ConnectionString, Convert.ToInt32(campaignID), out TotalForwardCount);
                    Fcount = TotalForwardCount;
                }
                if (mailingId != string.Empty)
                {
                    ListUnsubScribeRecipients = ContactMaster.SelectUnsubscribeRecipients(ConnectionString, Convert.ToInt32(mailingId), out NeverOptedCount, out CommCount, out NotInterestedCount, out OtherCount);
                    UnSubscribeCount = ListUnsubScribeRecipients.Rows.Count;
                }
                else
                {
                    ListUnsubScribeRecipients = ContactMaster.SelectUnsubscribeRecipientsByAssignedCampId(ConnectionString, Convert.ToInt32(campaignID), out NeverOptedCount, out CommCount, out NotInterestedCount, out OtherCount, out TotalUnsubCount);
                    UnSubscribeCount = TotalUnsubCount;
                }

                yValues.Clear();
                if (sentcount != 0)
                {
                    yValues.Add(Convert.ToDouble(opencount));
                    yValues.Add(Convert.ToDouble(bouncecount));
                    yValues.Add(Convert.ToDouble(unopencount));
                }

                #endregion

                lblRecipients.Text = (sentcount + bouncecount).ToString();
                ActiveCount = sentcount + bouncecount;
                double TotalCount = sentcount + bouncecount;
                double plotY = 0;
                ShowCampaignCountChart.Series["Series1"].Points.Clear();
                if (yValues.Count != 0)
                {
                    for (int pointIndex = 0; pointIndex < yValues.Count; pointIndex++)
                    {
                        plotY = yValues[pointIndex];
                        ShowCampaignCountChart.Series["Series1"].Points.AddY(plotY);
                        ShowCampaignCountChart.Series["Series1"].Points[pointIndex].LabelForeColor = System.Drawing.Color.White;
                    }

                    ShowCampaignCountChart.Series["Series1"].Points[0].LegendText = "Open" + " " + ((Convert.ToDouble(yValues[0].ToString()) / TotalCount) * 100).ToString("###########0.00") + "%" + " (" + yValues[0].ToString() + ")";
                    ShowCampaignCountChart.Series["Series1"].Points[1].LegendText = "Bounce" + " " + ((Convert.ToDouble(yValues[1].ToString()) / TotalCount) * 100).ToString("###########0.00") + "%" + " (" + yValues[1].ToString() + ")";
                    ShowCampaignCountChart.Series["Series1"].Points[2].LegendText = "Unopen" + " " + ((Convert.ToDouble(yValues[2].ToString()) / TotalCount) * 100).ToString("###########0.00") + "%" + " (" + yValues[2].ToString() + ")";

                    //Display tooltip for the chart
                    ShowCampaignCountChart.Series["Series1"].Points[0].ToolTip = "Open Count:" + yValues[0].ToString() + " (" + Math.Round((double.Parse(yValues[0].ToString()) * 100 / TotalCount)).ToString() + "%" + ")";
                    ShowCampaignCountChart.Series["Series1"].Points[1].ToolTip = "Bounce Count:" + yValues[1].ToString() + " (" + Math.Round((double.Parse(yValues[1].ToString()) * 100 / TotalCount)).ToString() + "%" + ")";
                    ShowCampaignCountChart.Series["Series1"].Points[2].ToolTip = "Unopen Count:" + yValues[2].ToString() + " (" + Math.Round((double.Parse(yValues[2].ToString()) * 100 / TotalCount)).ToString() + "%" + ")";
                    //Applying colors
                    ShowCampaignCountChart.Series["Series1"].Points[0].Color = System.Drawing.Color.Green;
                    ShowCampaignCountChart.Series["Series1"].Points[1].Color = System.Drawing.Color.Red;
                    ShowCampaignCountChart.Series["Series1"].Points[2].Color = System.Drawing.Color.DarkBlue;

                    //show Chart
                    ShowCampaignCountChart.Series["Series1"].ChartType = SeriesChartType.Pie;
                    ShowCampaignCountChart.Series["Series1"]["PieStartAngle"] = "30";

                    //get sum of sentcount for selected campaign .
                    double sendcount = Convert.ToDouble(sentcount);
                    double targetcount = sendcount + yValues[1];
                    //showing value in table
                    lblContactsTargeted.Text = lblContactsTargeted.Text != null ? ActiveCount.ToString() : "0";
                    lblSuccessfulDeliveries.Text = sendcount.ToString() != "" ? sendcount + "(" + Math.Round((sendcount) * 100 / ActiveCount).ToString() + "%" + ")" : "0";
                    lblBounces.Text = yValues[1].ToString() != null ? yValues[1].ToString() + "(" + Math.Round((double.Parse(yValues[1].ToString()) * 100 / ActiveCount)).ToString() + "%" + ")" : "0";

                    lblUnsubscribe.Text = UnSubscribeCount.ToString();
                    lblForwrds.Text = Fcount.ToString() != null ? Fcount.ToString() : "0";

                    lblTotalOpens.Text = TotalOpenCounts.ToString();
                    lblUniqueopens.Text = UniqueOpenCounts.ToString() != null ? UniqueOpenCounts.ToString() + "(" + Math.Round((double.Parse(UniqueOpenCounts.ToString()) * 100 / sendcount)).ToString() + "%" + ")" : "0";

                    lblUniqueClicks.Text = UniqueClickCounts.ToString();
                    lblTotalClicks.Text = TotalClickCounts.ToString();
                }
                else
                    Session["allCounts"] = null;
                # region DataExportToExcel
                string str = selectedList.ToString(); //.Replace(",", ";");
                DataTable dtExportSummary = new DataTable();
                DataColumn s1;
                if (ddlMailingNames.SelectedItem.ToString() != defaultMailingItem)
                    s1 = new DataColumn("Dashboard: Mailing Report Summary");
                else
                    s1 = new DataColumn("Dashboard: Campaign Report Summary");

                DataColumn s2 = new DataColumn("  ");
                DataColumn s3 = new DataColumn(" ");
                dtExportSummary.Columns.Add(s1);
                dtExportSummary.Columns.Add(s2);
                dtExportSummary.Columns.Add(s3);

                DataRow row1 = dtExportSummary.NewRow();
                if (ddlMailingNames.SelectedItem.ToString() != defaultMailingItem)
                    row1[s1] = "Mailing Name:";
                else
                    row1[s1] = "Campaign Name:";

                if (ddlMailingNames.SelectedItem.ToString() != defaultMailingItem)
                    row1[s2] = ddlMailingNames.SelectedItem.ToString();
                else
                    row1[s2] = ddlCampaignsNames.SelectedItem.ToString();
                row1[s3] = "";
                dtExportSummary.Rows.Add(row1);

                DataRow row2 = dtExportSummary.NewRow();
                row2[s1] = "Subject Line:";
                row2[s2] = lblSubject.ToolTip.ToString();
                row2[s3] = "";
                dtExportSummary.Rows.Add(row2);

                DataRow row3 = dtExportSummary.NewRow();
                row3[s1] = "Results as of :";
                row3[s2] = lblResultsAsOf.Text.ToString();
                row3[s3] = "";
                dtExportSummary.Rows.Add(row3);

                DataRow row4 = dtExportSummary.NewRow();
                row4[s1] = "Send Start Date : ";
                row4[s2] = lblSendStartDate.Text.ToString();
                row4[s3] = "";
                dtExportSummary.Rows.Add(row4);

                DataRow row5 = dtExportSummary.NewRow();
                row5[s1] = "Send Completion Date : ";
                row5[s2] = lblSendCompletionDate.Text.ToString();
                row5[s3] = "";
                dtExportSummary.Rows.Add(row5);

                DataRow row6 = dtExportSummary.NewRow();
                row6[s1] = "List(s) Selected : ";
                row6[s2] = str.ToString();
                row6[s3] = "";
                dtExportSummary.Rows.Add(row6);

                DataRow row7 = dtExportSummary.NewRow();
                row7[s1] = "Overall Stats";
                row7[s2] = "";
                row7[s3] = "";
                dtExportSummary.Rows.Add(row7);

                DataRow row8 = dtExportSummary.NewRow();
                row8[s1] = "Contacts Targeted:";
                row8[s2] = lblContactsTargeted.Text;
                row8[s3] = "";
                dtExportSummary.Rows.Add(row8);

                DataRow row9 = dtExportSummary.NewRow();
                row9[s1] = "Successful Deliveries:";
                row9[s2] = lblSuccessfulDeliveries.Text;
                row9[s3] = "";
                dtExportSummary.Rows.Add(row9);

                DataRow row10 = dtExportSummary.NewRow();
                row10[s1] = "Bounced:";
                row10[s2] = lblBounces.Text;
                row10[s3] = "";
                dtExportSummary.Rows.Add(row10);

                DataRow row11 = dtExportSummary.NewRow();
                row11[s1] = "Unsubscribes:";
                row11[s2] = lblUnsubscribe.Text;
                row11[s3] = "";
                dtExportSummary.Rows.Add(row11);

                DataRow row12 = dtExportSummary.NewRow();
                row12[s1] = "Unique Opens:";
                row12[s2] = lblUniqueopens.Text;
                row12[s3] = "";
                dtExportSummary.Rows.Add(row12);

                DataRow row13 = dtExportSummary.NewRow();
                row13[s1] = "Total Opens:";
                row13[s2] = lblTotalOpens.Text;
                row13[s3] = "";
                dtExportSummary.Rows.Add(row13);

                DataRow row14 = dtExportSummary.NewRow();
                row14[s1] = "Unique Clicks:";
                row14[s2] = lblUniqueClicks.Text;
                row14[s3] = "";
                dtExportSummary.Rows.Add(row14);

                DataRow row15 = dtExportSummary.NewRow();
                row15[s1] = "Total Clicks:";
                row15[s2] = lblTotalClicks.Text;
                row15[s3] = "";
                dtExportSummary.Rows.Add(row15);

                DataRow row16 = dtExportSummary.NewRow();
                row16[s1] = "Forwards:";
                row16[s2] = lblForwrds.Text;
                row16[s3] = "";
                dtExportSummary.Rows.Add(row16);

                ViewState["CampaignExportSummary"] = dtExportSummary;
                #endregion
            }
            else
            {
                lblContactsTargeted.Text = "0";
                lblSuccessfulDeliveries.Text = "0";
                lblTotalOpens.Text = "0";
                lblUnsubscribe.Text = "0";
                lblUniqueopens.Text = "0";
                lblBounces.Text = "0";
                lblUniqueClicks.Text = "0";
                lblForwrds.Text = "0";
                lblTotalClicks.Text = "0";
                lblCampaignTitle.Text = string.Empty;
                lblSubject.Text = string.Empty;
                lblResultsAsOf.Text = string.Empty;
                lblSendStartDate.Text = string.Empty;
                lblSendCompletionDate.Text = string.Empty;
                lblsentDateTime.Text = string.Empty;
                lblRecipients.Text = string.Empty;
                lblSelectedList.Text = string.Empty;
                ShowCampaignCountChart.Series["Series1"].Points.Clear();
            }
        }
        protected void imgbtnExport_Click(object sender, ImageClickEventArgs e)
        {
            try
            {

                #region Ex1
                //CrystalDecisions.Shared.ExportFormatType formateType = ExportFormatType.PortableDocFormat;
                //if (dpExport.SelectedValue == "PDF")
                //{
                //    formateType = ExportFormatType.PortableDocFormat;
                //}
                //else if (dpExport.SelectedValue == "Excel")
                //{
                //    formateType = ExportFormatType.Excel;
                //}
                //else if (dpExport.SelectedValue == "Word")
                //{
                //    formateType = ExportFormatType.WordForWindows;
                //}
                //else if (dpExport.SelectedValue == "RichText")
                //{
                //    formateType = ExportFormatType.RichText;
                //}
                //else if (dpExport.SelectedValue == "CrystalReport")
                //{
                //    formateType = ExportFormatType.CrystalReport;
                //}
                //if (ContactRptname == "Contacts Targeted")
                //{
                //    SetDatabase(TargetedRpt, Request.QueryString["ListIds"].ToString());
                //    TargetedRpt.SetParameterValue("@ListID", Request.QueryString["ListIds"].ToString());
                //    TargetedRpt.SetParameterValue("@CampaignID", Request.QueryString["CampId"].ToString());
                //    TargetedRpt.ExportToHttpResponse(formateType, Response, true, "ContactsTargeted");
                //}
                //else if (ContactRptname == "Advanced")
                //{
                //    SetDatabase(AdvancedRpt, Request.QueryString["ListIds"].ToString());
                //    AdvancedRpt.SetParameterValue("@ListIds", Request.QueryString["ListIds"].ToString());
                //    AdvancedRpt.SetParameterValue("@CampaignId", Request.QueryString["CampId"].ToString());
                //    AdvancedRpt.ExportToHttpResponse(formateType, Response, true, "Advanced");
                //}
                //else if (ContactRptname == "Successful Delivered")
                //{
                //    SetDatabase(SuccessDRpt, string.Empty);
                //    SuccessDRpt.SetParameterValue("@CampaignId", Request.QueryString["CampId"].ToString());
                //    SuccessDRpt.ExportToHttpResponse(formateType, Response, true, "SuccessfulDeliveredContacts");
                //}
                //else if (ContactRptname == "Clicked")
                //{
                //    SetDatabase(ClickedRpt, string.Empty);
                //    ClickedRpt.SetParameterValue("@CampaignId", Request.QueryString["CampId"].ToString());
                //    ClickedRpt.ExportToHttpResponse(formateType, Response, true, "ClickedContacts");
                //}

                //else if (ContactRptname == "Forwards")
                //{
                //    SetDatabase(ForwardRpt, string.Empty);
                //    ForwardRpt.SetParameterValue("@CampaignId", Request.QueryString["CampId"].ToString());
                //    ForwardRpt.ExportToHttpResponse(formateType, Response, true, "ForwardContacts");
                //}
                //else if (ContactRptname == "Opened")
                //{
                //    SetDatabase(OpenMailRpt, string.Empty);
                //    OpenMailRpt.SetParameterValue("@CampaignId", Request.QueryString["CampId"].ToString());
                //    OpenMailRpt.ExportToHttpResponse(formateType, Response, true, "OpenedContacts");
                //}
                //else if (ContactRptname == "Unopened")
                //{
                //    SetDatabase(UnopenRpt, string.Empty);
                //    UnopenRpt.SetParameterValue("@CampaignId", Request.QueryString["CampId"].ToString());
                //    UnopenRpt.ExportToHttpResponse(formateType, Response, true, "UnopenedContacts");
                //}
                //else if (ContactRptname == "Unsubscribed")
                //{
                //    SetDatabase(UnsubRpt, string.Empty);
                //    UnsubRpt.SetParameterValue("@CampaignId", Request.QueryString["CampId"].ToString());
                //    UnsubRpt.ExportToHttpResponse(formateType, Response, true, "UnsubscribedContacts");
                //}
                //else if (ContactRptname == "Bounced")
                //{
                //    SetDatabase(BouncedRpt, string.Empty);
                //    BouncedRpt.SetParameterValue("@CampaignId", Request.QueryString["CampId"].ToString());
                //    BouncedRpt.ExportToHttpResponse(formateType, Response, true, "BounceContacts");
                //}
                #endregion

                #region Ex2
                //SetDatabase(TargetedRpt, Request.QueryString["ListIds"].ToString());
                //if (dpExport.SelectedValue == "PDF")
                //{
                //    oStream = (MemoryStream)TargetedRpt.ExportToStream(ExportFormatType.PortableDocFormat);
                //    Response.Clear();
                //    Response.Buffer = true;
                //    Response.ContentType = "application/pdf";
                //    Response.BinaryWrite(oStream.ToArray());
                //    Response.AddHeader("Content-disposition", "Attachment;filename=" + filename.ToString().Trim()+ ".pdf");
                //    Response.End();
                //    //TargetedRpt.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, true, Page.Title);
                //}
                //else if (dpExport.SelectedValue == "Excel")
                //{
                //    oStream = (MemoryStream)TargetedRpt.ExportToStream(ExportFormatType.Excel);
                //    Response.Clear();
                //    Response.Buffer = true;
                //    Response.ContentType = "application/vnd.xls";
                //    Response.BinaryWrite(oStream.ToArray());
                //    Response.AddHeader("Content-disposition", "Attachment;filename=" + filename.ToString().Trim()+ ".xls");
                //    Response.End();
                //}
                //else if (dpExport.SelectedValue == "Word")
                //{
                //    oStream = (MemoryStream)TargetedRpt.ExportToStream(ExportFormatType.WordForWindows);
                //    Response.Clear();
                //    Response.Buffer = true;
                //    Response.ContentType = "application/vnd.doc";
                //    Response.BinaryWrite(oStream.ToArray());
                //    Response.AddHeader("Content-disposition", "Attachment;filename=" + filename.ToString().Trim()+ ".doc");
                //    Response.End();
                //}
                //else if (dpExport.SelectedValue == "RichText")
                //{
                //    oStream = (MemoryStream)TargetedRpt.ExportToStream(ExportFormatType.RichText);
                //    Response.Clear();
                //    Response.Buffer = true;
                //    Response.ContentType = "application/rtf";
                //    Response.BinaryWrite(oStream.ToArray());
                //    Response.AddHeader("Content-disposition", "Attachment;filename=" + filename.ToString().Trim()+ ".rtf");
                //    Response.End();
                //}
                //else if (dpExport.SelectedValue == "CrystalReport")
                //{
                //    oStream = (MemoryStream)TargetedRpt.ExportToStream(ExportFormatType.CrystalReport);
                //    Response.Clear();
                //    Response.Buffer = true;
                //    Response.ContentType = "application/rpt";
                //    Response.BinaryWrite(oStream.ToArray());
                //    Response.AddHeader("Content-disposition", "Attachment;filename=" + filename.ToString().Trim()+ ".rpt");
                //    Response.End();
                //}

                #endregion
                string CampName = string.Empty;
                string campId = HttpContext.Current.Request.QueryString["CampId"] != null ? HttpContext.Current.Request.QueryString["CampId"].ToString() : string.Empty;
                string mailingId = HttpContext.Current.Request.QueryString["MailingID"] != null ? HttpContext.Current.Request.QueryString["MailingID"].ToString() : string.Empty;
                //Get the MailingName Using MailingId
                if (mailingId != string.Empty)
                {
                    CampaignMasterPrimaryKey pk = new CampaignMasterPrimaryKey(Convert.ToInt64(mailingId));
                    CampaignMaster objCampMaster = CampaignMaster.SelectOneWithCampaignJobUsingCampaignMasterID(pk, ConnectionString);
                    CampName = objCampMaster.CampaignName.ToString().Trim();
                }
                else
                {
                    CampaignPrimaryKey pk = new CampaignPrimaryKey(Convert.ToInt64(campId));
                    Campaign Campaign = Campaign.SelectOne(pk, ConnectionString);
                    CampName = Campaign.CampaignsName;
                }
                string listIds = HttpContext.Current.Request.QueryString["ListIds"] != null ? HttpContext.Current.Request.QueryString["ListIds"].ToString() : string.Empty;
                //string CampName = HttpContext.Current.Request.QueryString["CampName"] != null ? HttpContext.Current.Request.QueryString["CampName"].ToString() : string.Empty;
                string TabName = string.Empty;
                DataTable table = new DataTable();
                int TotalBounceCount, SoftBounceCount, HardBounceCount = -1;
                int NeverOptedCount, CommCount, NotInterestedCount, OtherCount = -1, TotalUnsubCount = -1;
                Export Export = new Export("Web");
                #region download using Dll
                if (ContactRptname == "Contacts Targeted")
                {
                    TabName = "ContactsTargeted";
                    ListContactMaster objListContactMaster = new ListContactMaster(ConnectionString);
                    if (listIds != string.Empty && mailingId != string.Empty)
                        table = objListContactMaster.getContactsWithCampaignID(listIds, mailingId);
                    else
                        table = objListContactMaster.getContactsWithAssignCampaignID(campId);
                }
                else if (ContactRptname == "Successful Delivered")
                {
                    TabName = "SuccessfulDelivered";
                    if (campId != string.Empty)
                        table = ContactMaster.SelectSuccDeliveredByAssignCampIdwithDistinct(ConnectionString, Convert.ToInt32(campId));
                    else
                        table = ContactMaster.SelectSuccessfulDeliveredByCampId(ConnectionString, Convert.ToInt32(mailingId));

                }
                else if (ContactRptname == "Bounced")
                {
                    TabName = "Bounced";
                    if (campId != string.Empty)
                        table = ContactMaster.SelectRecipientsBounceRecByAssignCampId(ConnectionString, Convert.ToInt32(campId), out TotalBounceCount, out SoftBounceCount, out HardBounceCount);
                    else
                        table = ContactMaster.SelectRecipientsBounceRecByCampId(ConnectionString, Convert.ToInt32(mailingId), out TotalBounceCount, out SoftBounceCount, out HardBounceCount);
                }
                else if (ContactRptname == "Opened")
                {
                    TabName = "Opened"; int TotalOpenCounts = -1;
                    if (campId != string.Empty)
                        table = ContactMaster.EmailOpendByAssignCampId(ConnectionString, Convert.ToInt32(campId), out TotalOpenCounts);
                    else
                        table = ContactMaster.EmailOpendByCampId(ConnectionString, Convert.ToInt32(mailingId));
                }
                else if (ContactRptname == "Unopened")
                {
                    TabName = "Unopened";
                    if (campId != string.Empty)
                        table = ContactMaster.EmailUnopendRecByAssignCampId(ConnectionString, campId);
                    else
                        table = ContactMaster.EmailUnopendByCampId(ConnectionString, Convert.ToInt32(mailingId));
                }
                else if (ContactRptname == "Clicked")
                {
                    TabName = "Clicked"; int TotalClickCounts = -1;
                    if (campId != string.Empty)
                        table = ContactMaster.EmailClickedRecByAssignCampId(ConnectionString, Convert.ToInt32(campId), out TotalClickCounts);
                    else
                        table = ContactMaster.EmailClickedRecByCampId(ConnectionString, Convert.ToInt32(mailingId));
                }
                else if (ContactRptname == "Forwards")
                {
                    TabName = "Forwards"; int TotalForwardCount = -1;
                    if (campId != string.Empty)
                        table = ContactMaster.SelectForwardRecipientsByAssignId(ConnectionString, Convert.ToInt32(campId), out TotalForwardCount);
                    else
                        table = ContactMaster.SelectForwardRecipients(ConnectionString, Convert.ToInt32(mailingId));
                }
                else if (ContactRptname == "Unsubscribed")
                {
                    TabName = "Unsubscribed";
                    if (campId != string.Empty)
                        table = ContactMaster.SelectUnsubscribeRecipientsByAssignedCampId(ConnectionString, Convert.ToInt32(campId), out NeverOptedCount, out CommCount, out NotInterestedCount, out OtherCount, out TotalUnsubCount);
                    else
                        table = ContactMaster.SelectUnsubscribeRecipients(ConnectionString, Convert.ToInt32(mailingId), out NeverOptedCount, out CommCount, out NotInterestedCount, out OtherCount);
                }
                else if (ContactRptname == "Advanced")
                {
                    TabName = "Advanced";
                    if (campId != string.Empty)
                        table = ContactMaster.SelectRecipientsDomainCountsByAssign(ConnectionString, Convert.ToInt32(campId), "TargetedDomain", string.Empty);
                    else
                        table = ContactMaster.SelectRecipientsDomainCounts(ConnectionString, listIds, Convert.ToInt32(mailingId), "TargetedDomain", string.Empty);
                    table.Columns["TargetedDomain"].ColumnName = "Domains";
                    table.Columns["Unsubs"].ColumnName = "Unsubscribe";
                }
                if (dpExport.SelectedValue.Equals("CSV"))
                    Export.ExportDetails(table, Export.ExportFormat.CSV, TabName + "_" + CampName + "_" + DateTime.Now.ToShortDateString() + ".csv");
                else if (dpExport.SelectedValue.Equals("Excel"))
                    Export.ExportDetails(table, Export.ExportFormat.Excel, TabName + "_" + CampName + "_" + DateTime.Now.ToShortDateString() + ".xls");
                else if (dpExport.SelectedValue.Equals("Text"))
                {
                    Export.ExportDetails(table, Export.ExportFormat.Text, TabName + "_" + CampName + "_" + DateTime.Now.ToShortDateString() + ".txt");
                }
                else
                    ExportToPDF(table, TabName + "_" + CampName + "_" + DateTime.Now.ToShortDateString() + ".pdf");
                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void getMailingRpt(DataRow dr, int RptSenthr)
        {
            Logger.logdata(logforemailbuilder, "************** in getMailingRpt(..) method **************");
            Logger.logdata(logforemailbuilder,
                           string.Format("getMailingRpt(..) has been started at {0}", DateTime.Now.ToString()));

            string message = string.Empty;

            int MailingId = Convert.ToInt32(dr["MailingID"].ToString());
            Logger.logdata(logforemailbuilder, string.Format("Mailing Id:{0}", MailingId.ToString()));

            //string[] rptMailIds= dr["ReportMailTo"].ToString().Split(',');

            string rptMailTo = dr["ReportMailTo"].ToString();

            CampaignMasterPrimaryKey objCampaignMasterPrimaryKey = new CampaignMasterPrimaryKey(MailingId);
            CampaignMaster objCampaignMaster = CampaignMaster.SelectOneWithCampaignJobUsingCampaignMasterID(objCampaignMasterPrimaryKey, clientConnectionString);
            CampaignJobPrimaryKey pk = new CampaignJobPrimaryKey(MailingId);
            CampaignJobs objCampaignjob = CampaignJob.SelectByField("CampaignMasterID", MailingId, clientConnectionString);
            string MailinName = objCampaignMaster.CampaignName.ToString();
            Logger.logdata(logforemailbuilder, string.Format("MailingName:{0}", MailinName.ToString()));

            string Subject = objCampaignMaster.Subject.ToString();
            string sentTime = objCampaignjob[0].ScheduledDatetime.ToString();
            string completionTime = objCampaignjob[0].CompletionTime.ToString();

            string DeliveredCount = objCampaignjob[0].DeliveredCount.ToString();
            string BounceCount = objCampaignjob[0].BounceCount.ToString();
            string OpenCount = objCampaignjob[0].OpenCount.ToString();
            string ClickCount = objCampaignjob[0].ClickCount.ToString();
            string UnsubscribeCount = objCampaignjob[0].UnSubscribeCount.ToString();

            ListMasterPrimaryKey pkList = new ListMasterPrimaryKey(Convert.ToInt32(objCampaignMaster.SelectCondition));
            ListMaster listMaster = ListMaster.SelectOne(pkList, connectionString);
            string listName = listMaster.ListName;

            ListContactMaster objListContactMaster = new ListContactMaster(clientConnectionString);
            DataTable dtcontacts = objListContactMaster.getContactsWithCampaignID(objCampaignMaster.SelectCondition, MailingId.ToString());
            string TargetedCount = dtcontacts.Rows.Count.ToString();

            int ForwardCount = -1;
            int Fcount = LinkDetailBase.RecipientsForwardCount(clientConnectionString, MailingId, out ForwardCount);
            string forwardCount = Fcount.ToString();

            #region MailBody
            StringBuilder mailContent = new StringBuilder();
            mailContent.Append("<table width=\"600px\">");
            mailContent.Append("<tr><td style=\"font-weight: bold\">Mailing Report Summary</td></tr>");
            mailContent.Append("<tr><td width=\"250px\">Mailing Name:</td><td>" + MailinName + "</td></tr>");
            mailContent.Append("<tr><td>Subject Line:</td><td>" + Subject + "</td></tr>");
            mailContent.Append("<tr><td>Send Start Date:</td><td>" + sentTime + "</td></tr>");
            mailContent.Append("<tr><td>Send Completion Date :</td><td>" + completionTime + "</td></tr>");
            mailContent.Append("<tr><td>List Name:</td><td>" + listName + "</td></tr>");
            mailContent.Append("<tr><td style=\"height:20px\"></td><td></td></tr>");
            mailContent.Append("<tr><td style=\"font-weight:bold\">Overall Stats</td></tr>");
            mailContent.Append("<tr><td>Contacts Targeted</td><td>" + TargetedCount + "</td></tr>");
            mailContent.Append("<tr><td>Successful Delivered</td> <td>" + DeliveredCount + "</td></tr>");
            mailContent.Append("<tr><td>BounceCount</td> <td>" + BounceCount + "</td></tr>");
            mailContent.Append("<tr><td>OpenCount</td> <td>" + OpenCount + "</td></tr>");
            mailContent.Append("<tr><td>ClickCount</td> <td>" + ClickCount + "</td></tr>");
            mailContent.Append("<tr><td>UnsubscribeCount</td><td>" + UnsubscribeCount + "</td></tr>");
            mailContent.Append("<tr><td>ForwardCount</td><td>" + forwardCount + "</td></tr>");
            mailContent.Append("</table>");

            Logger.logdata(logforemailbuilder, string.Format("MailingBody :{0}", mailContent.ToString()));
            #endregion

            try
            {

                #region Build Mail Body DataTable

                DataTable mailRptDt = new DataTable();
                DataColumn s1 = new DataColumn("Mailing Report Summary");
                DataColumn s2 = new DataColumn(" ");
                mailRptDt.Columns.Add(s1);
                mailRptDt.Columns.Add(s2);

                DataRow row1 = mailRptDt.NewRow();
                row1[s1] = "Mailing Name:";
                row1[s2] = MailinName;
                mailRptDt.Rows.Add(row1);

                DataRow row2 = mailRptDt.NewRow();
                row2[s1] = "Subject Line:";
                row2[s2] = Subject;
                mailRptDt.Rows.Add(row2);

                DataRow row3 = mailRptDt.NewRow();
                row3[s1] = "Send Start Date:";
                row3[s2] = sentTime;
                mailRptDt.Rows.Add(row3);

                DataRow row4 = mailRptDt.NewRow();
                row4[s1] = "Send Completion Date :";
                row4[s2] = completionTime;
                mailRptDt.Rows.Add(row4);

                DataRow row5 = mailRptDt.NewRow();
                row5[s1] = "List Name:";
                row5[s2] = listName;
                mailRptDt.Rows.Add(row5);

                DataRow row6 = mailRptDt.NewRow();
                row6[s1] = "";
                row6[s2] = "";
                mailRptDt.Rows.Add(row6);

                DataRow row7 = mailRptDt.NewRow();
                row7[s1] = "Overall Stats";
                row7[s2] = "";
                mailRptDt.Rows.Add(row7);

                DataRow row8 = mailRptDt.NewRow();
                row8[s1] = "Contacts Targeted:";
                row8[s2] = TargetedCount;
                mailRptDt.Rows.Add(row8);

                DataRow row9 = mailRptDt.NewRow();
                row9[s1] = "Successful Delivered:";
                row9[s2] = DeliveredCount;
                mailRptDt.Rows.Add(row9);

                DataRow row10 = mailRptDt.NewRow();
                row10[s1] = "Bounce Count:";
                row10[s2] = BounceCount;
                mailRptDt.Rows.Add(row10);

                DataRow row11 = mailRptDt.NewRow();
                row11[s1] = "Open Count:";
                row11[s2] = OpenCount;
                mailRptDt.Rows.Add(row11);

                DataRow row12 = mailRptDt.NewRow();
                row12[s1] = "Click Count:";
                row12[s2] = ClickCount;
                mailRptDt.Rows.Add(row12);

                DataRow row13 = mailRptDt.NewRow();
                row13[s1] = "Unsubscribe Count:";
                row13[s2] = UnsubscribeCount;
                mailRptDt.Rows.Add(row13);

                DataRow row14 = mailRptDt.NewRow();
                row14[s1] = "Forward Count:";
                row14[s2] = forwardCount;
                mailRptDt.Rows.Add(row14);
                #endregion

                string dat = DateTime.Now.ToString("ddMMMyyyyhhmmssTT");
                string pPath = ConfigurationSettings.AppSettings["AttachFilePath"].ToString();
                string apiFromMail = ConfigurationSettings.AppSettings["ApiFromMail"].ToString();
                DirectoryInfo dirInfo = new DirectoryInfo(pPath);
                if (!dirInfo.Exists)
                    dirInfo.Create();
                pPath = Path.Combine(pPath, "MailingReport" + dat + ".csv");
                Logger.logdata(logforemailbuilder, string.Format("Attachment Path: {0}", pPath.ToString()));
                CreateCSVFile(mailRptDt, pPath);

                Logger.logdata(logforemailbuilder, string.Format("sendEmail(..) has been started at {0}", DateTime.Now.ToString()));

                bool status = sendEmail(apiFromMail, rptMailTo.ToString().Trim(), string.Empty, "Report", false, mailContent.ToString(), pPath, out message);
                if (status)
                {
                    Logger.logdata(logforemailbuilder, "Report Mail Sent Successfully to:'" + rptMailTo + "'");
                    #region Update Hours status in MailApproval Table

                    MailApproval objMailApproval = new MailApproval(clientConnectionString);
                    bool updateStatus = objMailApproval.UpdateHoursStatus(MailingId, RptSenthr);
                    if (updateStatus)
                        Logger.logdata(logforemailbuilder, string.Format("{0} Hours Status Updated Successfully at {1}", RptSenthr.ToString(), DateTime.Now.ToString()));
                    else
                        Logger.logdata(logforemailbuilder, string.Format("{0} Hours Status Updated Failed at {1}", RptSenthr.ToString(), DateTime.Now.ToString()));
                    #endregion
                }
                else
                {
                    Logger.logdata(logforemailbuilder, "Report Mail Sending Failed");
                }
                Logger.logdata(logforemailbuilder, string.Format("sendEmail(..) method has been ended at {0}", DateTime.Now.ToString()));
            }
            catch (Exception ex)
            {
            }
            Logger.logdata(logforemailbuilder, string.Format("getMailingRpt(..) method has been ended at {0}", DateTime.Now.ToString()));
            Logger.logdata(logforemailbuilder, "************** Exit getMailingRpt(..) method **************");
        }