protected void drlCampaign_SelectedIndexChanged(object sender, EventArgs e)
 {
     int readMail = 0;
     try
     {
         srBUS = new SendRegisterBUS();
         srdBus = new SendRegisterDetailBUS();
         sendContentBus = new SendContentBUS();
         mgBus = new MailGroupBUS();
         int sendId = int.Parse(drlCampaign.SelectedValue.ToString());
         DataTable campain = srdBus.GetByID(sendId);
         DataTable errSend = srdBus.GetByStatus(false, sendId);
         DataTable unreceve = srdBus.GetByNotReceve(sendId);
         int err = errSend.Rows.Count;
         this.lblTotalMailSend.Text = campain.Rows.Count.ToString();
         int notreceve = unreceve.Rows.Count;
         lblEmailSend.Text = new MailConfigBUS().GetByID(int.Parse(srBUS.GetByID(sendId).Rows[0]["mailconfigid"]+"")).Rows[0]["eMail"].ToString();
         if (campain.Rows.Count > 0)
         {
             foreach (DataRow row in campain.Rows)
             {
                 if (row["isOpenMail"].ToString() == "True")
                 {
                     readMail++;
                 }
             }
             lblNotOpen2.Text = (campain.Rows.Count - readMail).ToString();
         }
         lblNotOpen2.Text = "0";
         lblOpened.Text = readMail.ToString();
         DataTable sendregisteDetail = srBUS.GetByID(sendId);
         if (sendregisteDetail.Rows.Count > 0)
         {
             int contentID = int.Parse(sendregisteDetail.Rows[0]["SendContentId"].ToString());
             lblDateStart.Text = sendregisteDetail.Rows[0]["StartDate"].ToString();
             lblDateEnd.Text = sendregisteDetail.Rows[0]["EndDate"].ToString();
             int groupSend = int.Parse(sendregisteDetail.Rows[0]["GroupTo"].ToString());
             if (groupSend == -3)
                 lblGroupEmailTo.Text = "Tất cả";
             else lblGroupEmailTo.Text = mgBus.GetByID(groupSend).Rows[0]["Name"].ToString();
             if (sendContentBus.GetByID(contentID).Rows.Count > 0)
             {
                 lblCampianName.Text = sendContentBus.GetByID(contentID).Rows[0]["Subject"].ToString();
             }
         }
         if (campain.Rows.Count > 0)
             CreateChart(campain.Rows.Count, err, readMail, 1, notreceve, lblCampianName.Text);
         else lblChart.Text = "";
         LoadOpenEmail(sendId);
     }
     catch (Exception ex)
     {
         //pnError.Visible = true;
         //lblError.Text = ex.Message;
     }
 }
    protected void loadListContentHasSend()
    {
        try
        {
            int groupId = int.Parse(Request.Params["groupId"]);
            PartSendBUS psBus = new PartSendBUS();
            SendContentBUS scBus = new SendContentBUS();
            MailGroupBUS mgBus = new MailGroupBUS();
            DataTable tblPartSend = psBus.GetByUserIdAndGroupId(getUserLogin().UserId, groupId);
            if (tblPartSend.Rows.Count > 0)
            {
                string hasContentSend = tblPartSend.Rows[0]["hasContentSend"].ToString();
                string[] arrayContentSend = hasContentSend.Split(',');
                dlContentList.DataSource = arrayContentSend;
                dlContentList.DataBind();
                for (int i = 0; i < arrayContentSend.Length; i++)
                {
                    Label lblSubject = (Label)dlContentList.Items[i].FindControl("lblSubject");
                    Label lblContent = (Label)dlContentList.Items[i].FindControl("lblContent");
                    string contentId = arrayContentSend[i];
                    DataTable tblContent = scBus.GetByID(int.Parse(contentId));
                    if (tblContent.Rows.Count > 0)
                    {
                        lblSubject.Text = tblContent.Rows[0]["Subject"].ToString();
                        lblContent.Text = tblContent.Rows[0]["Body"].ToString();
                    }

                }
            }

            DataTable tblMailGroup = mgBus.GetByID(groupId);
            if (tblMailGroup.Rows.Count > 0)
            {
                lblGroupName.Text = tblMailGroup.Rows[0]["Name"].ToString();
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
    protected string LoadChart(object id)
    {
        int readMail = 0;
        try
        {
            //int i=0;
            for (int i = 0; i < dlContentSendEvent.Items.Count; i++)
            {
                HiddenField hdfId = (HiddenField)dlContentSendEvent.Items[i].FindControl("hdfId");
                if (hdfId.Value + "" == id + "")
                {
                    SendRegisterBUS srBUS = new SendRegisterBUS();
                    SendRegisterDetailBUS srdBus = new SendRegisterDetailBUS();
                    SendContentBUS sendContentBus = new SendContentBUS();
                    MailGroupBUS mgBus = new MailGroupBUS();
                    int sendId = int.Parse(id + "");
                    DataTable campain = srdBus.GetByContentID(sendId);
                    DataTable errSend = srdBus.GetContentSendEventDetailByStatus(false, sendId);
                    DataTable unreceve = srdBus.GetByNotReceve(sendId);
                    int err = errSend.Rows.Count;
                    Label lblTotalMailSend = (Label)dlContentSendEvent.Items[i].FindControl("lblTotalMailSend");
                    Label lblEmailSend = (Label)dlContentSendEvent.Items[i].FindControl("lblEmailSend");
                    Label lblNotOpen2 = (Label)dlContentSendEvent.Items[i].FindControl("lblNotOpen2");
                    Label lblOpened = (Label)dlContentSendEvent.Items[i].FindControl("lblOpened");
                    Label lblDateStart = (Label)dlContentSendEvent.Items[i].FindControl("lblDateStart");
                    Label lblDateEnd = (Label)dlContentSendEvent.Items[i].FindControl("lblDateEnd");
                    Label lblGroupEmailTo = (Label)dlContentSendEvent.Items[i].FindControl("lblGroupEmailTo");
                    Label lblCampianName = (Label)dlContentSendEvent.Items[i].FindControl("lblCampianName");
                    Label lblChart = (Label)dlContentSendEvent.Items[i].FindControl("lblChart");
                    lblTotalMailSend.Text = campain.Rows.Count.ToString();
                    int notreceve = unreceve.Rows.Count;
                    if (campain.Rows.Count > 0)
                    {
                        lblEmailSend.Text = campain.Rows[0]["MailSend"].ToString();
                        foreach (DataRow row in campain.Rows)
                        {
                            if (row["isOpenMail"].ToString() == "True")
                            {
                                readMail++;
                            }
                        }
                        lblNotOpen2.Text = (campain.Rows.Count - readMail).ToString();
                    }
                    lblOpened.Text = readMail.ToString();
                    DataTable sendregisteDetail = cseBus.GetById(sendId);
                    if (sendregisteDetail.Rows.Count > 0)
                    {
                        int contentID = int.Parse(sendregisteDetail.Rows[0]["id"].ToString());
                        //lblDateStart.Text = sendregisteDetail.Rows[0]["StartDate"].ToString();
                        //lblDateEnd.Text = sendregisteDetail.Rows[0]["EndDate"].ToString();
                        int groupSend = int.Parse(sendregisteDetail.Rows[0]["GroupTo"].ToString());
                        if (groupSend == -3)
                            lblGroupEmailTo.Text = "Tất cả";
                        else lblGroupEmailTo.Text = mgBus.GetByID(groupSend).Rows[0]["Name"].ToString();
                        if (sendContentBus.GetByID(contentID).Rows.Count > 0)
                        {
                            lblCampianName.Text = sendContentBus.GetByID(contentID).Rows[0]["Subject"].ToString();
                        }
                    }
                    CreateChart(campain.Rows.Count, err, readMail, 1, notreceve, lblCampianName.Text, lblChart);
                }
            }
        }
        catch (Exception ex)
        {
            pnError.Visible = true;
            lblError.Text = ex.Message;

        }
        return "";
    }
    protected void getRegisterSendList()
    {
        try
        {
            cateBUs = new CategoryBUS();
            srBUS = new SendRegisterBUS();
            srdBus = new SendRegisterDetailBUS();
            mailConfigBus = new MailConfigBUS();
            mailGroupBus = new MailGroupBUS();
            sendContentBus = new SendContentBUS();
            dsgBus = new DetailGroupBUS();
            UserLoginDTO userLogin = getUserLogin();
            DataTable tblSendRegister = new DataTable();
            if (userLogin.DepartmentId == 1)
            {
                tblSendRegister = srBUS.GetAll();
            }
            else
            {
                tblSendRegister = srBUS.GetAll(userLogin.UserId);
            }
            if (tblSendRegister.Rows.Count > 0)
            {
                dlWaitSend.DataSource = tblSendRegister;
                dlWaitSend.DataBind();
                for (int i = 0; i < tblSendRegister.Rows.Count; i++)
                {
                    try
                    {

                        DataRow row = tblSendRegister.Rows[i];
                        int Sendtype = int.Parse(row["Sendtype"].ToString());
                        HiddenField hdfId = (HiddenField)dlWaitSend.Items[i].FindControl("hdfId");
                        hdfId.Value = row["Id"].ToString();
                        int contentId = int.Parse(row["SendContentId"].ToString());
                        //DataTable tblContent = sendContentBus.GetByID(contentId);
                        Label lblSubject = (Label)dlWaitSend.Items[i].FindControl("lblSubject");
                        //if (tblContent.Rows.Count > 0)
                        //{
                        //    lblSubject.Text = tblContent.Rows[0]["Subject"].ToString();
                        //}
                        //else
                        lblSubject.Text = row["Subject"] + "";

                        int mailConfig = int.Parse(row["MailConfigID"].ToString());
                        DataTable tblMailConfig = mailConfigBus.GetByID(mailConfig);
                        if (tblMailConfig.Rows.Count > 0)
                        {
                            Label lblMailConfig = (Label)dlWaitSend.Items[i].FindControl("lblMailConfig");
                            lblMailConfig.Text = tblMailConfig.Rows[0]["Email"].ToString();
                        }
                        int groupTo = int.Parse(row["GroupTo"].ToString());
                        if (groupTo == -3)
                        {
                            Label lblGroupTo = (Label)dlWaitSend.Items[i].FindControl("lblGroupTo");
                            lblGroupTo.Text = "Tất cả khách hàng";
                        }
                        else if (groupTo == -2)
                        {
                            Label lblGroupTo = (Label)dlWaitSend.Items[i].FindControl("lblGroupTo");
                            lblGroupTo.Text = "Nhóm mua nhiều lần";
                        }
                        else if (groupTo == -1)
                        {
                            Label lblGroupTo = (Label)dlWaitSend.Items[i].FindControl("lblGroupTo");
                            lblGroupTo.Text = "Nhóm mua lần đầu";
                        }
                        else
                        {
                            DataTable tblGroupTo = new DataTable();
                            if (Sendtype == 1)
                            {
                                tblGroupTo = mailGroupBus.GetByID(groupTo);

                                if (tblGroupTo.Rows.Count > 0)
                                {
                                    Label lblGroupTo = (Label)dlWaitSend.Items[i].FindControl("lblGroupTo");
                                    lblGroupTo.Text = tblGroupTo.Rows[0]["Name"].ToString();
                                }
                            }
                            else
                            {
                                tblGroupTo = cateBUs.GetByID(groupTo);
                                if (tblGroupTo.Rows.Count > 0)
                                {
                                    Label lblGroupTo = (Label)dlWaitSend.Items[i].FindControl("lblGroupTo");
                                    lblGroupTo.Text = tblGroupTo.Rows[0]["Title"].ToString();
                                }
                            }

                        }

                        Label lblStartDate = (Label)dlWaitSend.Items[i].FindControl("lblStartDate");
                        lblStartDate.Text = row["StartDate"].ToString();

                        Label lblEndDate = (Label)dlWaitSend.Items[i].FindControl("lblEndDate");

                        int status = int.Parse(row["Status"].ToString());

                        Panel panel = (Panel)dlWaitSend.Items[i].FindControl("Panel1");
                        TextBox progressbar = (TextBox)dlWaitSend.Items[i].FindControl("progressbar");
                        LinkButton lbtDetail = (LinkButton)dlWaitSend.Items[i].FindControl("lbtDetail");

                        //get list detail
                        DataTable listDetail = srdBus.GetByID(int.Parse(row["Id"].ToString()));
                        int hasSend = 0, sumSend = dsgBus.GetByID(groupTo).Rows.Count;
                        for (int k = 0; k < listDetail.Rows.Count; k++)
                        {
                            hasSend++;
                        }

                        //calc percent has send
                        int percent = 0;
                        if (sumSend != 0)
                        {
                            percent = (hasSend * 100) / sumSend;
                        }

                        if (status == 0)
                        {
                            //display process bar
                            panel.Visible = true;
                            progressbar.BackColor = System.Drawing.Color.Cornsilk;
                            progressbar.Width = percent + 20;
                            progressbar.Text = percent + "%";

                            lbtDetail.Visible = false;
                            lbtDetail.Text = "";
                            lblEndDate.Text = "Chưa xác định ";
                        }
                        else
                        {
                            //hidden process bar
                            panel.Visible = false;
                            lbtDetail.Text = "Xem chi tiết";
                            lbtDetail.PostBackUrl = "reportSend.aspx?campaign-id=" + row["Id"].ToString();
                            lblEndDate.Text = row["EndDate"].ToString();
                        }

                        LinkButton lbtDelete = (LinkButton)dlWaitSend.Items[i].FindControl("lbtDelete");
                        lbtDelete.CommandArgument = row["Id"].ToString();
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

        }
        catch (Exception)
        {

        }
    }