コード例 #1
0
        protected void lnkapprove_Click(object sender, EventArgs e)
        {
            chk = 0;
            ct  = 0;
            LinkButton  lnk = sender as LinkButton;
            GridViewRow row = lnk.NamingContainer as GridViewRow;
            int         id  = int.Parse(grdcancelappr.DataKeys[row.RowIndex].Value.ToString());

            a      = row.Cells[5].Text.ToString().Trim();
            period = row.Cells[6].Text.ToString().Trim();
            idate  = row.Cells[8].Text.ToString().Trim();
            string[]  values = a.Split(',');
            DataTable nc     = new DataTable();

            nc.Columns.Add("Date", typeof(string));
            for (int i = 0; i < values.Length; i++)
            {
                a1  = values[i].ToString();
                dt1 = DateTime.Parse(a1);
                dt2 = DateTime.Parse(idate);
                if (dt1 < dt2)
                {
                    //can't cancel that leave
                    // get the count of the leaves, update the days requested to these days
                    nc.Rows.Add(a1);
                    ct  = ct + 1;
                    chk = 1;
                }
                else
                {
                    // can cancel that leave dont do anything
                }
            }

            if (chk == 0)
            {
                // cancel all leaves
                bus.lid = id;
                int r = bus.cancel_all_approved();
                if (r == 1)
                {
                    // send email
                    fetch_mail_details_hr();
                    mailbody = "<table  border='1' cellpadding='0' cellspacing='0' style='width: 850px; border-color: black;'><tr><td colspan='9'><br>&nbsp &nbspDear " + row.Cells[1].Text.ToString() + ",<br /><br />&nbsp&nbsp&nbsp&nbsp&nbspCancellation of leave submitted by you is <b>Approved </b> on " + DateTime.Now.ToString("dd/MM/yyyy") + ".</b> The details are as follows.<br /><br /></td></tr><tr style='font-weight: 700;'></tr><tr><td colspan='9'><br/><p></p><p> &nbsp&nbsp&nbspName:   " + row.Cells[1].Text.ToString() + "</p><p>&nbsp&nbsp&nbspDepartment:   " + row.Cells[2].Text.ToString() + "</p><p>&nbsp&nbsp&nbspDesignation:   " + row.Cells[3].Text.ToString() + " </p><p>&nbsp&nbsp&nbspLeave Type:   " + row.Cells[4].Text.ToString() + " </p><p>&nbsp&nbsp&nbspPeriod:   " + row.Cells[6].Text.ToString() + " </p><p>&nbsp&nbsp&nbspReason:   " + row.Cells[7].Text.ToString() + " </p><p>&nbsp&nbsp&nbspclick<a href=" + url2 + "> here </a>to login into the application (UOA)</p><p>&nbsp&nbsp&nbspclick<a href=" + url + "> here </a>to login into the application</p><br/></td></tr><tr></tr><td colspan='9' style='font-weight: bold' align='right'><br /><br />Regards,<br />Team e-leave</td></tr><tr><td align='center'><p style='color:blue;'> This is a system generated response. Please do not respond to this email id.</p></td></tr></table>";
                    bool check = SendWebMail(row.Cells[9].Text.ToString(), "Leave Application Notification", mailbody, toemail, "", "*****@*****.**");
                    if (check == true)
                    {
                        fillcancapprl();
                        ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "success();", true);
                    }
                    else
                    {
                        fillcancapprl();
                        ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "warningemail();", true);
                    }
                }
                else
                {
                    fillcancapprl();
                    ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "error();", true);
                }
            }
            else
            {
                // cancel the leaves that are not in datatable and update the dates requested with the dates in datatable and the count

                for (int i = 0; i < nc.Rows.Count; i++)
                {
                    output  = output + nc.Rows[i]["Date"].ToString();
                    output += (i < nc.Rows.Count - 1) ? "," : string.Empty;
                }

                bus.lid   = id;
                bus.dates = output;
                if (period == "Full Day")
                {
                    bus.rdays = ct;
                }
                else
                {
                    bus.rdays = ct / 2;
                }
                int r = bus.cancel_av_approved();
                if (r == 1)
                {
                    // send email
                    fetch_mail_details_hr();
                    mailbody = "<table  border='1' cellpadding='0' cellspacing='0' style='width: 850px; border-color: black;'><tr><td colspan='9'><br>&nbsp &nbspDear " + row.Cells[1].Text.ToString() + ",<br /><br />&nbsp&nbsp&nbsp&nbsp&nbspCancellation of leave submitted by you is <b>Approved </b> on " + DateTime.Now.ToString("dd/MM/yyyy") + ".</b> The details are as follows.<br /><br /></td></tr><tr style='font-weight: 700;'></tr><tr><td colspan='9'><br/><p></p><p> &nbsp&nbsp&nbspName:   " + row.Cells[1].Text.ToString() + "</p><p>&nbsp&nbsp&nbspDepartment:   " + row.Cells[2].Text.ToString() + "</p><p>&nbsp&nbsp&nbspDesignation:   " + row.Cells[3].Text.ToString() + " </p><p>&nbsp&nbsp&nbspLeave Type:   " + row.Cells[4].Text.ToString() + " </p><p>&nbsp&nbsp&nbspPeriod:   " + row.Cells[6].Text.ToString() + " </p><p>&nbsp&nbsp&nbspReason:   " + row.Cells[7].Text.ToString() + " </p><p>&nbsp&nbsp&nbspclick<a href=" + url2 + "> here </a>to login into the application (UOA)</p><p>&nbsp&nbsp&nbspclick<a href=" + url + "> here </a>to login into the application</p><br/></td></tr><tr></tr><td colspan='9' style='font-weight: bold' align='right'><br /><br />Regards,<br />Team e-leave</td></tr><tr><td align='center'><p style='color:blue;'> This is a system generated response. Please do not respond to this email id.</p></td></tr></table>";
                    bool check = SendWebMail(row.Cells[9].Text.ToString(), "Leave Application Notification", mailbody, toemail, "", "*****@*****.**");
                    if (check == true)
                    {
                        fillcancapprl();
                        ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "success();", true);
                    }
                    else
                    {
                        fillcancapprl();
                        ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "warningemail();", true);
                    }
                }
                else
                {
                    fillcancapprl();
                    ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "error();", true);
                }
            }
        }