protected void gvLeaveStatus_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        LeaveBAL       balLeave       = new LeaveBAL();
        LeaveENT       entLeave       = new LeaveENT();
        LeaveStatusBAL balLeaveStatus = new LeaveStatusBAL();
        UserENT        entUser        = new UserENT();
        UserBAL        balUser        = new UserBAL();

        entUser = balUser.SelectUserName(Convert.ToInt32(Session["UserID"].ToString().Trim()));

        if (e.CommandName == "Approved")
        {
            if (e.CommandArgument != null)
            {
                #region Collect Data
                entLeave.LeaveStatus     = e.CommandName.ToString().Trim();
                entLeave.LeaveResponseBy = entUser.UserName;
                #endregion Collect Data

                if (!balLeave.UpdateLeaveStatusInLeave(entLeave, Convert.ToInt32(e.CommandArgument)))
                {
                    PanelErrorMesseage.Visible = true;
                    lblErrorMesseage.Text      = balLeave.Message;
                }
            }
        }
        else if (e.CommandName == "Rejected")
        {
            if (e.CommandArgument != null)
            {
                #region Collect Data
                entLeave.LeaveStatus     = e.CommandName.ToString().Trim();
                entLeave.LeaveResponseBy = entUser.UserName;
                #endregion Collect Data

                if (!balLeave.UpdateLeaveStatusInLeave(entLeave, Convert.ToInt32(e.CommandArgument)))
                {
                    PanelErrorMesseage.Visible = true;
                    lblErrorMesseage.Text      = balLeave.Message;
                }
            }
        }
        balLeaveStatus.Delete(Convert.ToInt32(e.CommandArgument));
        FillGridViewLeave();
    }
Beispiel #2
0
    protected void gvLeave_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        LeaveBAL       balLeave = new LeaveBAL();
        LeaveENT       entLeave = new LeaveENT();
        LeaveENT       entLeaveforRemainingLeave = new LeaveENT();
        LeaveStatusBAL balLeaveStatus            = new LeaveStatusBAL();
        LeaveTypeENT   entLeaveType = new LeaveTypeENT();
        LeaveTypeBAL   balLeaveType = new LeaveTypeBAL();

        entLeave = balLeave.SelectLeaveStatusByPK(Convert.ToInt32(e.CommandArgument.ToString().Trim()));

        if (e.CommandName == "DeleteRecord")
        {
            if (e.CommandArgument != null)
            {
                entLeaveforRemainingLeave = balLeave.SelectByPK(Convert.ToInt32(e.CommandArgument.ToString().Trim()), Convert.ToInt32(Session["UserID"].ToString()));
                if (balLeaveStatus.Delete(Convert.ToInt32(e.CommandArgument.ToString().Trim())))
                {
                    if (!balLeave.Delete(Convert.ToInt32(e.CommandArgument.ToString().Trim()), Convert.ToInt32(Session["UserID"].ToString().Trim())))
                    {
                        lblErrorMesseage.Text = balLeave.Message;
                    }

                    FillGridViewLeave();
                    displayRemainingLeave();
                }
                else
                {
                    PanelErrorMesseage.Visible = true;
                    lblErrorMesseage.Text      = balLeaveStatus.Message;
                }
                if (entLeave.LeaveResponseBy == "Pending" && entLeave.LeaveStatus == "Pending")
                {
                    if (entLeaveforRemainingLeave.LeaveEndDate != "")
                    {
                        string   strStartDate    = entLeaveforRemainingLeave.LeaveStartDate.ToString();
                        string[] StartDateString = strStartDate.Split('-');
                        DateTime startdate       = Convert.ToDateTime(StartDateString[0] + "-" + StartDateString[1] + "-" + StartDateString[2]);

                        string   strEndDate    = entLeaveforRemainingLeave.LeaveEndDate.ToString();
                        string[] EndDateString = strEndDate.Split('-');
                        DateTime enddate       = Convert.ToDateTime(EndDateString[0] + "-" + EndDateString[1] + "-" + EndDateString[2]);

                        entLeaveType = balLeaveType.SelectByPK(entLeave.LeaveTypeID);
                        if (entLeaveType.LeaveType == "Casual Leave")
                        {
                            entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1;
                        }
                        else if (entLeaveType.LeaveType == "Medical Leave")
                        {
                            entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1;
                        }
                        else if (entLeaveType.LeaveType == "LOP")
                        {
                            entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1;
                        }
                        else if (entLeaveType.LeaveType == "Other Leave")
                        {
                            entLeaveType.TotalDays = entLeaveType.TotalDays + Convert.ToInt32((enddate - startdate).TotalDays) + 1;
                        }
                    }
                    else
                    {
                        entLeaveType = balLeaveType.SelectByPK(entLeave.LeaveTypeID);
                        if (entLeaveType.LeaveType == "Casual Leave")
                        {
                            entLeaveType.TotalDays = entLeaveType.TotalDays + 1;
                        }
                        else if (entLeaveType.LeaveType == "Medical Leave")
                        {
                            entLeaveType.TotalDays = entLeaveType.TotalDays + 1;
                        }
                        else if (entLeaveType.LeaveType == "LOP")
                        {
                            entLeaveType.TotalDays = entLeaveType.TotalDays + 1;
                        }
                        else if (entLeaveType.LeaveType == "Other Leave")
                        {
                            entLeaveType.TotalDays = entLeaveType.TotalDays + 1;
                        }
                    }
                    entLeaveType.UserID = Convert.ToInt32(Session["UserID"].ToString().Trim());
                    if (balLeaveType.UpdateTotalDaysByLeaveType(entLeaveType))
                    {
                        displayRemainingLeave();
                    }
                    else
                    {
                        PanelErrorMesseage.Visible = true;
                        lblErrorMesseage.Text      = balLeaveType.Message;
                    }
                }
            }
        }
        else if (e.CommandName == "EditRecord")
        {
            if (entLeave.LeaveResponseBy != "Pending" && entLeave.LeaveStatus != "Pending")
            {
                PanelErrorMesseage.Visible = true;
                lblErrorMesseage.Text      = "You can not edit leave after Responsed";
            }
            else
            {
                if (e.CommandArgument != null)
                {
                    Response.Redirect("~/Content/Leave/LeaveAddEdit.aspx?LeaveID=" + e.CommandArgument.ToString().Trim());
                }
            }
        }
    }