Example #1
0
    private bool SaveChangeDetails(bool isSubmit, out string strMessage)
    {
        char[] ch = new char[1];
        ch[0] = Convert.ToChar("$");
        CamperApplication   objCamperApplication = new CamperApplication();
        structChangeDetails ChangeDetails = new structChangeDetails();
        string oldGrant, newGrant, oldSession, newSession, reqComments, strCamperAnswers;
        bool   bGrantChange, bFJCAmountPaid, sameAsExistingSession;
        int    requestID = 0;

        sameAsExistingSession = bGrantChange = bFJCAmountPaid = false;
        strCamperAnswers      = oldGrant = newGrant = oldSession = newSession = reqComments = string.Empty;

        ChangeDetails.FJCID       = long.Parse(strFJCID);
        ChangeDetails.RequestType = rdBtnLstAdjustmentType.SelectedItem != null?Int32.Parse(rdBtnLstAdjustmentType.SelectedValue) : 0;

        ChangeDetails.Current_Status  = UpdateStatus(out bGrantChange, out bFJCAmountPaid);
        ChangeDetails.Original_Status = Int32.TryParse(lblCurrStatus.Text, out ChangeDetails.Original_Status) ? Int32.Parse(lblCurrStatus.Text) : 0;
        //added by sreevani to get campyear id based on fjcid from database.
        string campYearId = objCamperApplication.getCampYearId(strFJCID);

        ChangeDetails.CampYearID = Convert.ToInt32(campYearId);


        if (ChangeDetails.RequestType == 1) //Cancellation request
        {
            ChangeDetails.Cancellation_Reason = txtCancelComments.Text.Trim();
            if (iUserRole.ToString() == FJCAdminUserRole)
            {
                reqComments = txtComments.Text.Trim() != string.Empty ? txtComments.Text.Trim() : txtCancelComments.Text.Trim();
            }
            else if (iUserRole.ToString() == FEDAdminUserRole)
            {
                reqComments = txtCancelComments.Text.Trim();
            }
        }
        else if (ChangeDetails.RequestType == 2) //Session change request
        {
            if (!txtCampSession.Text.Equals(string.Empty))
            {
                ChangeDetails.NewSession           = txtCampSession.Text.Trim();
                ChangeDetails.NewSession_StartDate = txtNewStartDate.Text.Trim();
                ChangeDetails.NewSession_EndDate   = txtNewEndDate.Text.Trim();
            }
            else if (ddlCampSession.SelectedValue != "0" && ddlCampSession.SelectedIndex != -1)
            {
                ChangeDetails.NewSession           = ddlCampSession.SelectedValue;
                ChangeDetails.NewSession_StartDate = lblSysNewStartDate.Text;
                ChangeDetails.NewSession_EndDate   = lblSysNewEndDate.Text;
            }

            ChangeDetails.OldSession           = lblSession.Text;
            ChangeDetails.OldSession_StartDate = lblStartDate.Text;
            ChangeDetails.OldSession_EndDate   = lblEndDate.Text;

            sameAsExistingSession = IsNewSessionDetailsSameAsExisting();
            if (sameAsExistingSession)
            {
                valobj.InnerHtml = "<ul><li>New session is the same as existing session, please change the session name or dates again.</li></ul>"; strMessage = ""; return(false);
            }

            ChangeDetails.NewGrantAmount = lblNewGrant.Text.TrimStart(ch) != string.Empty ? Convert.ToDouble(lblNewGrant.Text.TrimStart(ch)) : 0.0;
            ChangeDetails.OldGrantAmount = lblGrant.Text.TrimStart(ch) != string.Empty ? Convert.ToDouble(lblGrant.Text.TrimStart(ch)) : 0.0;

            oldSession = lblStartDate.Text + " - " + lblEndDate.Text;
            newSession = ChangeDetails.NewSession_StartDate + " - " + ChangeDetails.NewSession_EndDate;
        }

        if (isSubmit && (hdnRequestStatus.Value == "0" || String.IsNullOrEmpty(hdnRequestStatus.Value))) //Request not submitted
        {
            ChangeDetails.SubmittedDate = DateTime.Now.ToString();
        }

        ChangeDetails.RequestStatus = isSubmit ? int.Parse(Enum.Format(typeof(RequestStatus), RequestStatus.Submitted, "D")):0; //Is submit clicked or save & exit
        ChangeDetails.RequestID     = String.IsNullOrEmpty(hdnRequestID.Value) ? 0 : Int32.Parse(hdnRequestID.Value);

        if (hdnRequestStatus.Value == "0" || String.IsNullOrEmpty(hdnRequestStatus.Value))
        {
            if (ChangeDetails.RequestID != 0)
            {
                objCamperApplication.UpdateChangeDetails(ChangeDetails); //update changerequest table
            }
            else
            {
                ChangeDetails.CreatedDate = DateTime.Now.ToString();
                objCamperApplication.InsertChangeDetails(ChangeDetails, out requestID); //insert changerequest table
                hdnRequestID.Value = requestID.ToString();
            }
            if (ChangeDetails.RequestStatus == 1) //if it is submit request
            {
                string strType = ChangeDetails.RequestType == 1 ? "Cancellation Request Submitted" : "Session Change Request Submitted";

                if (ChangeDetails.Current_Status == ChangeDetails.Original_Status)//if the there is no change in status (session change request) then update new session details in tblcamperanswer table
                {
                    if (pnlSystemSessionDates.Visible == true)
                    {
                        strCamperAnswers = ConstructCamperAnswers(ddlCampSession.SelectedValue, ChangeDetails.NewSession_StartDate, ChangeDetails.NewSession_EndDate);
                    }
                    else if (pnlManualSessionDates.Visible == true)
                    {
                        strCamperAnswers = ConstructCamperAnswers(txtCampSession.Text, ChangeDetails.NewSession_StartDate, ChangeDetails.NewSession_EndDate);
                    }

                    strCamperAnswers = string.IsNullOrEmpty(strCamperAnswers) ? null : strCamperAnswers;
                }
                objCamperApplication.UpdateDetailsOnRequestType(strFJCID, string.Empty, ChangeDetails.RequestID, strCamperAnswers, strType, iUserID, null, null, ChangeDetails.RequestStatus);

                strMessage = "Request has been submitted successfully.";
            }
            else
            {
                strMessage = "Request has been saved successfully.";
            }
        }
        else
        {
            strMessage = "Request " + lblRequestStatus.Text.ToLower() + ", cannot do any modifications.";
        }
        hdnNewRequest.Value = string.Empty;
        return(true);
    }