Exemple #1
0
    protected void gridCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Allotte")
        {
            long id;
            Int64.TryParse(e.CommandArgument.ToString(), out id);

            var gridRow = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;


            HiddenField hidApplicationId = gridRow.FindControl("hidApplicationId") as HiddenField;

            //AllotementApplications.UpdateApplicationStaus(id, ApplicationStatus.Allotted);
            Response.Redirect("~/admin/Allottee.aspx?appid=" + hidApplicationId.Value + "&ChangeRequestID=" + id + "&returnurl=admin/ViewChangeRequest.aspx");
        }
        else if (e.CommandName == "Withdraw")
        {
            long id;
            Int64.TryParse(e.CommandArgument.ToString(), out id);
            DataClassesDataContext dataContext = new DataClassesDataContext();
            var requests = from request in dataContext.tblChangeRequests where request.Id == id select request;
            tblChangeRequest tblreject = requests.FirstOrDefault();
            if (tblreject != null)
            {
                //Added on January 24,2017
                tblAllottee allottee = Allottee.GetAllotteeByAAN(tblreject.AAN);
                Quarters.UpdateQuarterStatus(allottee.QuarterNumber, QuarterStatus.Vacant);

                //update allottee
                //Reset the quarter to previous one at the time of change request
                allottee.QuarterNumber = tblreject.QuarterNumber;
                Allottee.Update(allottee);
                //Added on January 24,2017 end

                dataContext.tblChangeRequests.DeleteOnSubmit(tblreject);
                dataContext.SubmitChanges();
            }
            BindGrid();
            AllotementApplications.UpdateApplicationStaus(id, ApplicationStatus.rejected);
            //Quarters.UpdateQuarterStatus(tblreject.QuarterNumber, QuarterStatus.Vacant); //Commented on Dec 12,2016 purposely
        }
        else if (e.CommandName == "Possesed")
        {
            var        gridRow    = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;
            LinkButton lnkAllotte = gridRow.FindControl("lnkAllotte") as LinkButton;
            hdnChangeRequestId.Value = lnkAllotte.CommandArgument;

            hdnSelected.Value = e.CommandArgument.ToString();
            tblAllottee _allotte = Allottee.getAllotteByApplicationid(Convert.ToInt64(e.CommandArgument));
            txtName.Text = AllotementApplications.GetApplication(Convert.ToInt64(e.CommandArgument)).tblUser.fullName;
            if (_allotte != null)
            {
                txtQuarternumber.Text = _allotte.QuarterNumber;
            }

            pop.Show();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["applicationId"] == null)
        {
            Response.Redirect("~/user/application.aspx");
        }
        else if (Request["applicationId"] != null)
        {
            applicationId = Convert.ToString(Request["applicationId"]);
        }
        tbAllotmentApplication application = AllotementApplications.GetApplication(Convert.ToInt64(applicationId));

        categoryId = application.QuarterCategory.Value;

        if (!Page.IsPostBack)
        {
            tblUser user = Users.getUser(application.Userid.Value);

            DateTime?dt = null;
            //Check if user is debarred or deferred
            if (Users.IsUserDeferred(user.Id, out dt))
            {
                Response.Redirect("~/user/notallowed.aspx");
            }

            if (Users.IsUserDebarred(user.Id, out dt))
            {
                Response.Redirect("~/user/notallowed.aspx?debar=true");
            }


            lblFullname.Text        = user.fullName;
            lblDesignation.Text     = Users.GetUserDesignation(user.Id);
            lblAllottedQuarter.Text = "N/A";

            var allottee = Allottee.GetAllotteeByAAN(user.AAN);
            if (allottee != null && (allottee.Status.Value == ((int)AllotementStatus.Possessed) || allottee.Status.Value == ((int)AllotementStatus.ChangeRequested)))
            {
                string allottedQuarter = allottee.QuarterNumber;
                lblAllottedQuarter.Text = allottedQuarter;
            }

            if (application.QuarterCategory.HasValue && !Quarters.IsQuarterCategoryActive(application.QuarterCategory.Value))
            {
                submissionClosedPanel.Visible = true;
                return;
            }
            else
            {
                //Quarter category is active
                if (lblAllottedQuarter.Text == "N/A" || application.Status == (int)ApplicationStatus.Pending) //New allottment cases
                {
                    if (application.MedicalCategory.HasValue && application.MedicalCategory.Value >= 0)       //Medical grounds
                    {
                        applyForQuarterMedicalGroundsPanel.Visible = true;
                        btnNewAllottmentMedical.Enabled            = true;
                    }
                    else
                    {
                        applyForQuarterPanel.Visible = true;
                        btnNewAllottment.Enabled     = true;
                    }
                }
                else
                {
                    if (application.MedicalCategory.HasValue && application.MedicalCategory.Value >= 0) //Medical grounds
                    {
                        applyForQuarterMedicalGroundsPanel.Visible = true;
                        btnChangeRequestMedical.Enabled            = true;
                    }
                    else
                    {
                        applyForQuarterPanel.Visible = true;
                        btnChangeRequest.Enabled     = true;
                    }
                }

                DataClassesDataContext dataContext = new DataClassesDataContext();

                string aan = Users.getUserByUserName(HttpContext.Current.User.Identity.Name).AAN;
                var    _alreadyRequested = from _requested in dataContext.tblChangeRequests
                                           where _requested.AAN == aan &&
                                           (_requested.Status == (int)ChangeRequestStatus.Pending ||
                                            _requested.Status == (int)ChangeRequestStatus.Approved)
                                           select _requested;

                if (_alreadyRequested.FirstOrDefault() != null)
                {
                    var changeRequest = _alreadyRequested.FirstOrDefault();
                    pnlChangeRequestInformation.Visible = true;
                    btnChangeRequest.Enabled            = false;
                    btnChangeRequestMedical.Enabled     = false;

                    lblRequestID.Text        = changeRequest.Id.ToString();
                    lblFirstPreference.Text  = changeRequest.FirstPerference ?? "N/A";
                    lblSecondPreference.Text = changeRequest.SecondPerference ?? "N/A";
                    lblThirdPreference.Text  = changeRequest.ThirdPerference ?? "N/A";
                }
                else
                {
                    pnlChangeRequestInformation.Visible = false;
                }
            }
            BindData();
        }

        changeRequests            = new DataClassesDataContext().tblChangeRequests.ToList();
        grdQuarters.RowDataBound += new GridViewRowEventHandler(grdQuarters_RowDataBound);
    }
Exemple #3
0
    protected void gridCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Allotte")
        {
            long   id;
            string aan           = string.Empty;
            string quarterNumber = string.Empty;
            Int64.TryParse(e.CommandArgument.ToString(), out id);
            //AllotementApplications.UpdateApplicationStaus(id, ApplicationStatus.Allotted);

            tblAllottee _Allottee = null;
            //if (id > 0)
            //{
            //  _Allottee = Allottee.GetAllottee(id);
            //}
            //else
            //{
            var gridRow = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;

            var hidAAN = gridRow.FindControl("hidAAN") as HiddenField;
            aan = hidAAN.Value;
            tblAllottee a = Allottee.GetAllotteeByAAN(aan);

            if (a != null)
            {
                //lblMessage.Text = "User has already allotted quarter!";
                //lblMessage.Visible = true;
                //return;
                _Allottee = a;
            }
            else
            {
                _Allottee = new tblAllottee();
            }
            Label lblQuarterNumber = gridRow.FindControl("lblQuarterNumber") as Label;
            quarterNumber = lblQuarterNumber.Text;

            tblQuarter quarter = Quarters.GetQuarter(quarterNumber);
            if (quarter == null)
            {
                lblMessage.Text    = "Quarter number selected is not valid";
                lblMessage.Visible = true;
                return;
            }
            else if (quarter.Status.HasValue && quarter.Status != (int)QuarterStatus.Vacant)
            {
                lblMessage.Text    = "Quarter is not vacant!";
                lblMessage.Visible = true;
                return;
            }
            quarter.DateOfAllottement = DateTime.Now;
            quarter.Status            = (int)QuarterStatus.Alloted;
            Quarters.Save(quarter);

            //_Allottee = new tblAllottee();

            //}
            _Allottee.QuarterNumber    = quarterNumber;
            _Allottee.AAN              = aan;
            _Allottee.ApplicationId    = id;
            _Allottee.Status           = (int)AllotementStatus.Allotted;
            _Allottee.DateOfAllotement = DateTime.Now;
            //_Allottee.OfficeId = Convert.ToInt32(drpOffice.SelectedValue);
            //_Allottee.Designation =Convert.ToInt32( drpDesignation.SelectedValue);
            //_Allottee.DateOfJoining = Convert.ToDateTime(txtDoj.Text);
            //_Allottee.DateOfRetirement = Convert.ToDateTime(txtDor.Text);
            //_Allottee.Name = txtAllotteeName.Text;
            tbluserhistory _userhistory = new tbluserhistory();
            _userhistory.Action      = "Allotement";
            _userhistory.description = _user.Username + " has allotted quarter " + _Allottee.QuarterNumber + " to user " + _Allottee.AAN;
            _userhistory.time        = DateTime.Now;
            _userhistory.useraan     = _user.AAN;
            userHistory.Save(_userhistory);

            Allottee.Save(_Allottee);
            if (id > 0)
            {
                AllotementApplications.UpdateApplicationStaus(id, ApplicationStatus.Allotted);

                try
                {
                    //SEND SMS
                    new IntegratedMessageSender().SendMessage("QUARTER_ALLOTTED", _Allottee.QuarterNumber, AllotementApplications.GetApplicationByAAN(aan).ContactNumber);
                }
                catch (Exception)
                {
                    throw;
                }
            }

            BindData();

            ///Response.Redirect("~/admin/Allottee.aspx?Applicationid="+id+"&returnurl=admin/Prioritizeapplications.aspx");
        }
        else if (e.CommandName == "Withdraw")
        {
            long id;
            Int64.TryParse(e.CommandArgument.ToString(), out id);
            AllotementApplications.UpdateApplicationStaus(id, ApplicationStatus.withdraw);
            BindData();
            // AllotementApplications.UpdateApplicationStaus(id, ApplicationStatus.Pos);
        }
        else if (e.CommandName == "Allotte")
        {
            long id;
            Int64.TryParse(e.CommandArgument.ToString(), out id);
            //AllotementApplications.UpdateApplicationStaus(id, ApplicationStatus.withdraw);
            Response.Redirect("~/admin/Allottee.aspx?Applicationid=" + id + "&returnurl=admin/Prioritizeapplications.aspx");
        }
        else if (e.CommandName == "AllotteManual")
        {
            //Manual allocation
            long id;
            Int64.TryParse(e.CommandArgument.ToString(), out id);
            //AllotementApplications.UpdateApplicationStaus(id, ApplicationStatus.withdraw);
            Response.Redirect("~/admin/Allottee.aspx?Applicationid=" + id + "&returnurl=admin/Prioritizeapplications.aspx?selectedCategory=" + drpQuarterCatergory.SelectedValue);
        }
        //DataNavigateUrlFormatString="~/admin/Allottee.aspx?Applicationid={0}&returnurl=admin/Prioritizeapplications.aspx"
    }
    protected void btnadd_Click(object sender, EventArgs e)
    {
        tblAllottee _Allottee = null;

        if (id > 0)
        {
            _Allottee = Allottee.GetAllottee(id);
        }
        else
        {
            tblAllottee a = Allottee.GetAllotteeByAAN(txtAllotteeName.Text);
            if (a != null)
            {
                _Allottee = a;
                //lblmessage.Text = "User has already allotted quarter!";
                //lblmessage.Visible = true;
                //return;
            }

            if (a == null)
            {
                _Allottee = new tblAllottee();
            }

            tblQuarter quarter = Quarters.GetQuarter(drpQuarter.SelectedValue);
            if (quarter == null)
            {
                lblmessage.Text    = "Please enter valid number";
                lblmessage.Visible = true;
                return;
            }
            else if (quarter.Status.HasValue && quarter.Status != (int)QuarterStatus.Vacant)
            {
                lblmessage.Text    = "Quarter is not vacant!";
                lblmessage.Visible = true;
                return;
            }
            quarter.DateOfAllottement = DateTime.Now;
            quarter.Status            = (int)QuarterStatus.Alloted;
            Quarters.Save(quarter);

            //_Allottee = new tblAllottee();
        }
        _Allottee.QuarterNumber    = drpQuarter.SelectedValue;
        _Allottee.AAN              = txtAllotteeName.Text;
        _Allottee.ApplicationId    = applicationid;
        _Allottee.Status           = btnAddUpdate.Text == "Add Change Request" ? (int)AllotementStatus.ChangeRequested : (int)AllotementStatus.Possessed;
        _Allottee.DateOfAllotement = DateTime.Now;
        //_Allottee.OfficeId = Convert.ToInt32(drpOffice.SelectedValue);
        //_Allottee.Designation =Convert.ToInt32( drpDesignation.SelectedValue);
        //_Allottee.DateOfJoining = Convert.ToDateTime(txtDoj.Text);
        //_Allottee.DateOfRetirement = Convert.ToDateTime(txtDor.Text);
        //_Allottee.Name = txtAllotteeName.Text;
        tbluserhistory _userhistory = new tbluserhistory();

        _userhistory.Action      = "Allotement";
        _userhistory.description = _user.Username + " has allotted quarter " + _Allottee.QuarterNumber + " to user " + _Allottee.AAN;
        _userhistory.time        = DateTime.Now;
        _userhistory.useraan     = _user.AAN;
        userHistory.Save(_userhistory);

        Allottee.Save(_Allottee);
        if (applicationid > 0)
        {
            AllotementApplications.UpdateApplicationStaus(applicationid, btnAddUpdate.Text == "Add Change Request" ? ApplicationStatus.ChangeRequested : ApplicationStatus.Allotted);
        }
        if (!string.IsNullOrEmpty(Request["returnurl"]))
        {
            Response.Redirect("~/" + Request["returnurl"]);
        }
        else
        {
            Response.Redirect("~/admin/Allottees.aspx");
        }
    }