private void SendMail()
    {
        EmailDetails details = new EmailDetails();

        try
        {
            bool resultv = false;

            IncentiveBusiness b   = new IncentiveBusiness();
            SendMailObject    obj = new SendMailObject();

            string memberid = txtMemberId.Text.Trim();
            string emailid  = b.SelectAuthorEmailId(memberid);
            string point    = txtPointsAwarded.Text;
            string year     = DdlYear.SelectedValue;

            details.FromEmail = ConfigurationManager.AppSettings["FromAddress"].ToString();

            details.ToEmail      = emailid;
            details.Module       = "APA";
            details.EmailSubject = "Additional Point Award";
            details.Type         = "";
            details.Id           = "";
            string FooterText = ConfigurationManager.AppSettings["FooterText"].ToString();
            details.MsgBody = "<span style=\"font-size: 10pt; color: #3300cc; font-family: Verdana\"><h4>Dear Sir/Madam,</h4> <br>" +
                              "<p>An additional incentive point for the year '" + year + "' is awarded '" + point + "' for more than 6 publication.</p>" + "<br>" + "<br>" + FooterText +
                              " </b><br><b> </b></span>";


            resultv = obj.InsertIntoEmailQueue(details);



            if (resultv == true)
            {
                string CloseWindow1 = "alert('Mail Sent successfully')";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow", CloseWindow1, true);

                btnSave.Enabled = false;
            }
            else
            {
                string CloseWindow1 = "alert('Problem while sending mail')";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow", CloseWindow1, true);

                btnSave.Enabled = false;
            }
        }
        catch (Exception ex)
        {
            string CloseWindow1 = "alert('Problem while sending mail')";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow", CloseWindow1, true);
            log.Error(ex.Message);
            log.Error(ex.StackTrace);

            btnSave.Enabled = false;
        }
    }
    private void SendMail()
    {
        EmailDetails      details = new EmailDetails();
        IncentiveBusiness b       = new IncentiveBusiness();

        SendMailObject obj = new SendMailObject();
        Business       e   = new Business();

        try
        {
            bool   resultv  = false;
            int    rowIndex = 0;
            string emailid  = null;
            details.Module = "IPE";
            string AuthorName = null;
            string Isstudent  = null;
            details.EmailSubject = "Incentive Point Adjustment";
            string empcode = txtboxMemberId.Text;
            string type    = e.selectMemberType(empcode, txtReferenceId.Text);
            if (type == "M")
            {
                //Isstudent = "N";
                emailid               = b.SelectAuthorEmailId(empcode);
                AuthorName            = b.SelectAuthorName(empcode);
                Session["AuthorName"] = AuthorName;
                if (emailid == "")
                {
                    int result;
                    //string AuthorName;
                    AuthorName = b.SelectAuthorName(empcode);
                    result     = e.insertEmailtrackerIncentive(AuthorName, details, txtReferenceId.Text);
                }
            }
            else
            {
                //Isstudent = "S";
                emailid               = b.SelectStudentEmailId(empcode, txtReferenceId.Text);
                AuthorName            = b.SelectStudentAuthorName(empcode, txtReferenceId.Text);
                Session["AuthorName"] = AuthorName;
                if (emailid == "")
                {
                    int result;

                    AuthorName = b.SelectStudentAuthorName(empcode, txtReferenceId.Text);
                    result     = e.insertEmailtrackerIncentive(AuthorName, details, txtReferenceId.Text);
                    //Session["AuthorName"] = AuthorName;
                }
            }

            details.FromEmail = ConfigurationManager.AppSettings["FromAddress"].ToString();

            if (emailid != "")
            {
                details.ToEmail = emailid;
            }
            string hremailid = b.SelectHRMailID(empcode, type, txtReferenceId.Text);

            string InstWiseHRMailid = b.SelectInstwiseHRMailid(empcode, type, txtReferenceId.Text);
            if (details.ToEmail != null && details.ToEmail != "")
            {
                if (InstWiseHRMailid != null)
                {
                    if (InstWiseHRMailid != "")
                    {
                        if (details.ToEmail != null)
                        {
                            details.ToEmail = details.ToEmail + "," + InstWiseHRMailid;
                        }
                        else
                        {
                            details.ToEmail = InstWiseHRMailid;
                        }
                    }
                    else
                    {
                        // details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    // details.ToEmail = details.ToEmail;
                }
            }
            else
            {
                if (InstWiseHRMailid != null)
                {
                    if (InstWiseHRMailid != "")
                    {
                        if (details.ToEmail != null)
                        {
                            details.ToEmail = InstWiseHRMailid;
                        }
                        else
                        {
                            details.ToEmail = InstWiseHRMailid;
                        }
                    }
                    else
                    {
                        // details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    // details.ToEmail = details.ToEmail;
                }
            }
            ArrayList list = new ArrayList();
            list = b.SelectHODMailid(empcode, type, txtReferenceId.Text);
            for (int j = 0; j < list.Count; j++)
            {
                if (j == 0)
                {
                    if (list[j].ToString() != "")
                    {
                        details.HODmailid = list[j].ToString();
                    }
                }
                else
                {
                    if (list[j].ToString() != "")
                    {
                        details.HODmailid = details.HODmailid + ',' + list[j].ToString();
                    }
                }
            }
            if (details.ToEmail != null && details.ToEmail != "")
            {
                if (hremailid != null)
                {
                    if (hremailid != "")
                    {
                        details.ToEmail = details.ToEmail + "," + hremailid;
                    }
                    else
                    {
                        // details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    // details.ToEmail = details.ToEmail;
                }
            }
            else
            {
                if (hremailid != null)
                {
                    if (hremailid != "")
                    {
                        details.ToEmail = hremailid;
                    }
                    else
                    {
                        // details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    // details.ToEmail = details.ToEmail;
                }
            }
            if (details.ToEmail != null && details.ToEmail != "")
            {
                if (details.HODmailid != null)
                {
                    if (details.HODmailid != "")
                    {
                        details.ToEmail = details.ToEmail + "," + details.HODmailid;
                        //details.ToEmail = details.ToEmail + "," + hremailid + "," + details.HODmailid;
                    }
                    else
                    {
                        //details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    //details.ToEmail = details.ToEmail;
                }
            }
            else
            {
                if (details.HODmailid != null)
                {
                    if (details.HODmailid != "")
                    {
                        details.ToEmail = details.HODmailid;
                        //details.ToEmail = details.ToEmail + "," + hremailid + "," + details.HODmailid;
                    }
                    else
                    {
                        //details.ToEmail = details.ToEmail;
                    }
                }
                else
                {
                    //details.ToEmail = details.ToEmail;
                }
            }
            // details.CCEmail = hremailid;
            // details.CCEmail = Session["emailId"].ToString();
            details.Module       = "IPE";
            details.EmailSubject = "Incentive Point Adjustment";
            //details.Type = DropDownListPublicationEntry.SelectedValue;
            details.Id = txtReferenceId.Text;
            string FooterText = ConfigurationManager.AppSettings["FooterText"].ToString();
            string isStudent  = Session["IsStudent"].ToString();

            if (isStudent == "Y")
            {
                if (type == "S")
                {
                    details.MsgBody = "<span style=\"font-size: 10pt; color: #3300cc; font-family: Verdana\"><h4>Dear Sir/Madam,</h4> <br>" +
                                      "<p>For Certificate of Appreciation and encashment of research incentive points, request you to contact student research section of your institution/department along with the Bank detail form available in RMS Portal.</p>" + "<b>Incentive points with the rating  : " + txtTotalPoint.Text + "" + Session["Numbertype"].ToString() + "<br>" +
                                      "<br>" +
                                      "Author Name : " + Session["AuthorName"].ToString() + "<br>" +
                                      "Publication Id : " + txtReferenceId.Text + "<br>" +
                                      "Article Name :" + Session["Title"].ToString() + "<br>" + "<br>" + FooterText +
                                      " </b><br><b> </b></span>";
                }
                else
                {
                    details.MsgBody = "<span style=\"font-size: 10pt; color: #3300cc; font-family: Verdana\"><h4>Dear Sir/Madam,</h4> <br>" +
                                      //"<b> Incentive points with the rating '" + total.Text + "' added. <br> " +
                                      "<b>Incentive points with the rating  : " + txtTotalPoint.Text + " " + Session["Numbertype"].ToString() + "<br>" +
                                      "<br>" +
                                      "Author Name : " + Session["AuthorName"].ToString() + "<br>" +
                                      "Publication Id : " + txtReferenceId.Text + "<br>" +
                                      "Article Name :" + Session["Title"].ToString() + "<br>" + "<br>" + FooterText +
                                      " </b><br><b> </b></span>";
                }
            }

            else
            {
                if (type == "S")
                {
                    details.MsgBody = "<span style=\"font-size: 10pt; color: #3300cc; font-family: Verdana\"><h4>Dear Sir/Madam,</h4> <br>" +
                                      "<p>For encashment of research incentive points, request you to contact student research section of your institution/department along with the Bank detail form available in RMS Portal.</p>" + "<b>Incentive points with the rating  : " + txtTotalPoint.Text + " " + Session["Numbertype"].ToString() + "<br>" +
                                      //"<b> Incentive points with the rating '" + total.Text + "' added. <br> " +
                                      "<br>" +
                                      "Author Name : " + Session["AuthorName"].ToString() + "<br>" +
                                      "Publication Id : " + txtReferenceId.Text + "<br>" +
                                      "Article Name :" + Session["Title"].ToString() + "<br>" + "<br>" + FooterText +
                                      " </b><br><b> </b></span>";
                }
                else
                {
                    details.MsgBody = "<span style=\"font-size: 10pt; color: #3300cc; font-family: Verdana\"><h4>Dear Sir/Madam,</h4> <br>" +
                                      //"<b> Incentive points with the rating '" + total.Text + "' added. <br> " +
                                      "<b>Incentive points with the rating  : " + txtTotalPoint.Text + " " + Session["Numbertype"].ToString() + "<br>" +
                                      "<br>" +
                                      "Author Name : " + Session["AuthorName"].ToString() + "<br>" +
                                      "Publication Id : " + txtReferenceId.Text + "<br>" +
                                      "Article Name :" + Session["Title"].ToString() + "<br>" + "<br>" + FooterText +
                                      " </b><br><b> </b></span>";
                }
            }

            if (details.ToEmail != "" && details.ToEmail != null)
            {
                resultv = obj.InsertIntoEmailQueue(details);
            }
            IncentiveData     obj3 = new IncentiveData();
            IncentiveBusiness C    = new IncentiveBusiness();


            if (emailid == "")
            {
                string AuthorName1 = Session["AuthorName"].ToString();
                obj3 = C.CheckUniqueIdIncentive(txtReferenceId.Text, "JA", details);
                int data = C.updateEmailtrackerIncentive(txtReferenceId.Text, "JA", details, obj3, AuthorName1);
            }

            if (resultv == true)
            {
                string CloseWindow1 = "alert('Mail Sent successfully')";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow", CloseWindow1, true);
            }
            else
            {
                string CloseWindow1 = "alert('Problem while sending mail')";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow", CloseWindow1, true);
            }
        }


        catch (Exception ex)
        {
            string CloseWindow1 = "alert('Problem while sending mail')";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow", CloseWindow1, true);
            log.Error(ex.Message);
            log.Error(ex.StackTrace);
        }
    }
    protected void BtnSendMail_Click(object sender, EventArgs e)
    {
        try
        {
            IncentiveBusiness b       = new IncentiveBusiness();
            EmailDetails      details = new EmailDetails();
            SendMailObject    obj     = new SendMailObject();
            details.FromEmail = ConfigurationManager.AppSettings["FromAddress"].ToString();
            string finance_emailid = Session["emailId"].ToString();
            int    Index           = ((GridViewRow)((sender as Control)).NamingContainer).RowIndex;
            string employeeid      = Gridview.Rows[Index].Cells[0].Text;
            string referenceid     = Gridview.Rows[Index].Cells[1].Text;
            string transctiontype  = Gridview.Rows[Index].Cells[5].Text;
            Session["transctiontype"] = transctiontype;
            Session["MemberId"]       = employeeid;
            Session["referenceid"]    = referenceid;
            string membertype = Gridview.Rows[Index].Cells[6].Text;
            string emailid    = null;
            if (membertype == "M")
            {
                emailid = b.SelectAuthorEmailId(employeeid);
            }
            else
            {
                //emailid = b.SelectStudentAuthorEmailId(employeeid);
                string id = "";
                emailid = b.SelectStudentEmailId(employeeid, id);
            }
            string hr_emaild = b.SelectHREmailId(employeeid, referenceid, transctiontype);

            PanelSendMail.Visible = true;
            if (emailid != "")
            {
                txtTo.Text = hr_emaild + ',' + emailid;
            }
            else
            {
                txtTo.Text = hr_emaild;
            }
            txtCC.Text = finance_emailid;
            foreach (GridViewRow row in Gridview.Rows)
            {
                if (row.RowIndex == Index)
                {
                    row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
                }
                else
                {
                    row.BackColor = ColorTranslator.FromHtml("#FFFFFF");
                }
            }
        }


        catch (Exception ex)
        {
            log.Error(ex.StackTrace);
            log.Error(ex.Message);
            //return obj1;
        }
    }