protected void GV_DeleteProfile_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "DeleteProfile")
     {
         string[] IDs = e.CommandArgument.ToString().Split('|');
         oclsEligibilityDBAccess = new clsEligibilityDBAccess();
         string          sRet = string.Empty;
         Classes.clsUser user = (Classes.clsUser)Session["User"];
         //
         //DeleteDanglingStudent(uniID, year, studentID, userID, New identity);
         //
         sRet = oclsEligibilityDBAccess.DeleteDanglingStudent(IDs[0], IDs[1], IDs[2], user.User_ID, string.Empty);
         if (sRet == "Y")
         {
             lblMsg.Text     = "Profile deleted successfully.";
             lblMsg.CssClass = "saveNote";
             GetRecords(hid_pindex.Value);
         }
         else
         {
             lblMsg.Text     = "Profile could be deleted. Please contact the administrator.";
             lblMsg.CssClass = "errorNote";
         }
     }
 }
        void CancelStudentAdmission(string UniStudID, string sCancelReason)
        {
            string[] StudentIDs = UniStudID.Split('|');
            string   sResult    = string.Empty;

            //string sISDirectAdmission = string.Empty;
            Classes.clsUser user = (Classes.clsUser)Session["User"];

            Hashtable oHt = new Hashtable();

            oHt["pk_Uni_ID"]          = StudentIDs[0];
            oHt["pk_Year"]            = StudentIDs[1];
            oHt["pk_Student_ID"]      = StudentIDs[2];
            oHt["pk_Fac_ID"]          = StudentIDs[3];
            oHt["pk_Cr_ID"]           = StudentIDs[4];
            oHt["pk_MoLrn_ID"]        = StudentIDs[5];
            oHt["pk_Ptrn_ID"]         = StudentIDs[6];
            oHt["pk_Brn_ID"]          = StudentIDs[7];
            oHt["pk_CrPr_Details_ID"] = StudentIDs[9];
            oHt["pk_CrPrCh_ID"]       = StudentIDs[10];
            oHt["CrPr_Seq"]           = StudentIDs[8];
            oHt["CrPrCh_Seq"]         = StudentIDs[11];
            //oHt["Admission_Form_No"] = StudentIDs[12];
            //oHt["AdmissionMode"] = StudentIDs[13];
            //oHt["CrPr_OrderNo"] = StudentIDs[14];
            //oHt["MINumber"] = StudentIDs[15];
            //oHt["IsDirectAdmission"] = sISDirectAdmission;

            //oHt["Prn_number "] = ((Label)((Repeater)(source)).Items[e.Item.ItemIndex].FindControl("lblPRN")).Text;
            oHt["User"] = user.User_ID;
            oHt["CancellationReason"] = sCancelReason;

            //string sAdmissionFormNo = StudentIDs[12];
            //string sAdmissionMode = StudentIDs[13];
            //int sCrPr_OrderNo = Convert.ToInt16(StudentIDs[14]);
            //string sMINumber = StudentIDs[15];

            //bool isDirectAdmission = StudentIDs[16].Equals("1") ? true : false;

            //oHt["CancellationReason"]=txtReasonforCancellation.
            clsStudent oStudent = new clsStudent();
            clsOthers  sOthers  = new clsOthers();

            sResult = oStudent.CancelAdmission(oHt);
            switch (sResult)
            {
            case "N":

                //#region Followng code is added to cancel the admission at OA side, call to API

                //string OaMessage = string.Empty;

                //Hashtable oHs = new Hashtable();
                //oHs.Add("pk_Uni_ID", StudentIDs[0]);

                //if (sOthers.Allow_CancelAdmissionAtOASide(oHs))
                //{
                //    if (sAdmissionMode == "11" || sAdmissionMode == "12") //OA unregistered
                //    {
                //        if (sCrPr_OrderNo.Equals(1) || isDirectAdmission)
                //        {
                //            clsUserLogin userLogin = new clsUserLogin();

                //            DataSet ds = new DataSet();

                //            DataTable dt = new DataTable("CancelAdmissionTable");
                //            dt.Columns.Add(new DataColumn("ApplicationID", typeof(string)));
                //            dt.Columns.Add(new DataColumn("DUDCFlag", typeof(string)));
                //            dt.Columns.Add(new DataColumn("Username", typeof(string)));
                //            dt.Columns.Add(new DataColumn("MINumber", typeof(string)));

                //            DataRow dr = dt.NewRow();
                //            dr["ApplicationID"] = sAdmissionFormNo;
                //            dr["DUDCFlag"] = "DU";
                //            dr["Username"] = user.User_Name;
                //            dr["MINumber"] = sMINumber;
                //            dt.Rows.Add(dr);
                //            ds.Tables.Add(dt);

                //            string dtToJson = string.Empty;

                //            dtToJson = JsonConvert.SerializeObject(ds, Formatting.Indented);

                //            //old Code commented for API CALL

                //            /*
                //            try
                //            {
                //                string apiPath = userLogin.getSyncURL() + "PostStudentCancelAdmission";
                //                using (ExtendedWebClient client = new ExtendedWebClient())
                //                {
                //                    client.Headers.Add("content-type", "application/json; charset=utf-8");
                //                    client.Encoding = System.Text.Encoding.UTF8;
                //                    OaMessage = client.UploadString(apiPath, "POST", dtToJson);
                //                }

                //            }*/

                //            try
                //            {
                //                string apiPath = userLogin.getSyncURL() + "PostStudentCancelAdmission";
                //                var httpWebRequest = (HttpWebRequest)WebRequest.Create(apiPath);
                //                httpWebRequest.Method = "POST";
                //                httpWebRequest.ContentType = "application/json";

                //                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                //                {
                //                    streamWriter.Write(dtToJson);
                //                    streamWriter.Flush();
                //                    streamWriter.Close();

                //                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                //                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                //                    {
                //                        OaMessage = streamReader.ReadToEnd();
                //                    }
                //                }
                //            }

                //            catch (Exception exOA)
                //            {
                //                //Log the error in database Table

                //                Hashtable oHsErrorLog = new Hashtable();

                //                string[] sStudentIDs = UniStudID.Split('|');
                //                oHsErrorLog.Add("pk_Uni_ID", sStudentIDs[0]);
                //                oHsErrorLog.Add("pk_Year", sStudentIDs[1]);
                //                oHsErrorLog.Add("pk_Student_ID", sStudentIDs[2]);
                //                oHsErrorLog.Add("pk_Fac_ID", sStudentIDs[3]);
                //                oHsErrorLog.Add("pk_Cr_ID", sStudentIDs[4]);
                //                oHsErrorLog.Add("pk_MoLrn_ID", sStudentIDs[5]);
                //                oHsErrorLog.Add("pk_Ptrn_ID", sStudentIDs[6]);
                //                oHsErrorLog.Add("pk_Brn_ID", sStudentIDs[7]);
                //                oHsErrorLog.Add("pk_CrPr_Details_ID", sStudentIDs[8]);
                //                oHsErrorLog.Add("CrPr_Seq", sStudentIDs[9]);
                //                oHsErrorLog.Add("CrPrCh_ID", sStudentIDs[10]);
                //                oHsErrorLog.Add("CrPrCh_Seq", sStudentIDs[11]);
                //                oHsErrorLog.Add("Error_Msg", exOA.Message);
                //                oHsErrorLog.Add("UserName", user.User_Name);

                //                sOthers.WriteOAErrorLog(oHsErrorLog);

                //                OaMessage = "There is some issue while updating at OA side, Please contact Administrator.";
                //            }
                //        }
                //    }
                //}
                ///*******************************************************************************************/
                //#endregion

                lblMsg.Text     = "Admission of the selected term cancelled successfully.";
                lblMsg.CssClass = "saveNote";
                break;

            case "Y":
                lblMsg.Text     = "Admission of the selected term cannot be cancelled.";
                lblMsg.CssClass = "errorNote";
                break;

            case "E":
                lblMsg.Text     = "Admission of the selected term could not be cancelled as the Seat number is generated for this Term.";
                lblMsg.CssClass = "errorNote";
                break;

            case "I":
                lblMsg.Text     = "Admission of the selected term could not be cancelled as the Invoice is generated for this Term.";
                lblMsg.CssClass = "errorNote";
                break;

            case "":
                lblMsg.Text     = "Admission of the selected term cannot be cancelled.";
                lblMsg.CssClass = "errorNote";
                break;

            default:
                break;
            }
            DisplayStudentDetails();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int iMaxPaperLimit = 0;

            if (HasChange())
            {
                if (hid_SelectedPapers.Value != "")
                {
                    //hid_SelectedPapers.Value = hid_SelectedPapers.Value.Replace('_', ',');

                    string[] IDs_List = hid_SelectedPapers.Value.Split(',');
                    try
                    {
                        //MaxPaper Limit is the no. of papers defined at course part child level
                        iMaxPaperLimit = Convert.ToInt32(MaxPaperLimit.Value);
                    }
                    catch
                    {
                    }
                    if (IDs_List.Length <= iMaxPaperLimit && IDs_List.Length >= Convert.ToInt32(MinPaperLimit.Value))
                    {
                        string   StatusFlag      = "";
                        string[] listOldPpIDsArr = hidOldPpList.Value.Split(",".ToCharArray());
                        hid_SelectedPapers.Value = hid_SelectedPapers.Value.Replace('_', ',');
                        string[] listNewPpIDsArr = hid_SelectedPapers.Value.Split(",".ToCharArray());
                        string   DelPpStr        = "";
                        string   InsPpStr        = "";
                        int      DelFlag         = 0;
                        int      InsFlag         = 0;

                        //For Deleted Papers List
                        for (int i = 0; i < listOldPpIDsArr.Length; i++)
                        {
                            DelFlag = 0;
                            for (int j = 0; j < listNewPpIDsArr.Length; j++)
                            {
                                if (listOldPpIDsArr[i] == listNewPpIDsArr[j])
                                {
                                    DelFlag = 1;
                                    break;
                                }
                            }
                            if (DelFlag == 0)
                            {
                                DelPpStr += listOldPpIDsArr[i] + ",";
                            }
                        }
                        if (DelPpStr != "")
                        {
                            DelPpStr = DelPpStr.Remove(DelPpStr.LastIndexOf(","), 1);
                        }

                        //For Newly Inserted Papers List
                        for (int i = 0; i < listNewPpIDsArr.Length; i++)
                        {
                            InsFlag = 0;
                            for (int j = 0; j < listOldPpIDsArr.Length; j++)
                            {
                                if (listNewPpIDsArr[i] == listOldPpIDsArr[j])
                                {
                                    InsFlag = 1;
                                    break;
                                }
                            }
                            if (InsFlag == 0)
                            {
                                InsPpStr += listNewPpIDsArr[i] + ",";
                            }
                        }
                        if (InsPpStr != "")
                        {
                            InsPpStr = InsPpStr.Remove(InsPpStr.LastIndexOf(","), 1);
                        }

                        Classes.clsUser user = new Classes.clsUser();
                        user = (Classes.clsUser)Session["user"];

                        Hashtable objHT = new Hashtable();

                        objHT.Add("UniID", hidUniID.Value);
                        objHT.Add("InstID", hidInstID.Value);
                        objHT.Add("FacID", hidFacID.Value);
                        objHT.Add("CrID", hidCrID.Value);
                        objHT.Add("MoLrnID", hidMoLrnID.Value);
                        objHT.Add("PtrnID", hidPtrnID.Value);
                        objHT.Add("BrnID", hidBrnID.Value);
                        objHT.Add("CrPrDetailsID", hidCrPrDetailsID.Value);
                        objHT.Add("CrPrChID", hidCrPrChID.Value);
                        objHT.Add("StudentYear", hidStudentYear.Value);
                        objHT.Add("StudentID", hidStudentID.Value);
                        objHT.Add("AcademicYearID", hidAcademicYear.Value);
                        objHT.Add("DelPpStr", DelPpStr);
                        objHT.Add("InsPpStr", InsPpStr);
                        objHT.Add("Created_By", user.User_ID.ToString());


                        StatusFlag = clsPaperChange.SaveChangedPapers(objHT);

                        if (StatusFlag == "S")
                        {
                            lblNote.Visible  = true;
                            lblNote.Text     = "Information Saved Successfully !!!";
                            lblNote.CssClass = "saveNote";
                            DisplayPaperList();
                            FillDataGrid();
                        }

                        else if (StatusFlag == "U")
                        {
                            lblNote.Text = "Information Can not be Processed<br> If you get this message again please contact ADMINSTRATOR";
                            DisplayPaperList();
                        }
                    }
                    else
                    {
                        lblNote.CssClass = "errorNote";
                        lblNote.Text     = "Information can not be processed.<br>Required number of " + lblPaper.Text + "(s) are not selected.";
                        DisplayPaperList();
                    }
                }

                else
                {
                    lblNote.CssClass = "errorNote";
                    lblNote.Text     = "Information can not be processed.<br>Select " + lblPaper.Text + "(s).<br>";
                    DisplayPaperList();
                }
            }

            else
            {
                lblNote.Visible  = true;
                lblNote.Text     = "Information canonot be Updated as there is no change!";
                lblNote.CssClass = "errorNote";
                DisplayPaperList();
            }


            // lblMsg.Visible = false;
        }