//protected void grd_Info_PageIndexChanging(object sender, GridViewPageEventArgs e)
        //{
        //    dt = (DataTable)ViewState["dt"];
        //    grd_Info.PageIndex = e.NewPageIndex;
        //    grd_Info.DataSource = dt;
        //    grd_Info.DataBind();
        //}

        protected void grd_Info_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Add")
            {
                FeraghatTahsilBusiness bFeraghat = new FeraghatTahsilBusiness();
                int         reqID;
                GridViewRow curruntRow = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
                stcode = curruntRow.Cells[1].Text;
                //string note = "تایید فارغ التحصیلان";
                string note       = "درحال بررسی";
                string CreateDate = DateTime.Now.ToPeString();
                reqID = business.InsertInToStudentRequest(stcode, (int)CheckOutStatusEnum.CheckOutType.fareq_tahsil, Convert.ToInt32(CheckOutStatusEnum.CheckOutAllStatusEnum.takmil_parvande), CheckOutStatusEnum.CheckOutAllStatusEnum.vrood_moavenat.ToString(), "", CreateDate, note, 0, true);//حذف_دبیرخانه  امکان ثبت درخواست در کدام مرحله؟
                setLog("ثبت درخواست تسویه حساب فارغ التحصیلی از صفحه وضعیت مدارک دانشجو", reqID, (int)DTO.eventEnum.ثبت_درخواست_تسویه);
                oFeraghat.Id               = 0;
                oFeraghat.RizNomarat       = 0;
                oFeraghat.GovahiMovaghat   = 0;
                oFeraghat.DaneshNameh      = 0;
                oFeraghat.Stcode           = stcode;
                oFeraghat.StudentRequestId = reqID;

                bFeraghat.UpdateMadarekStatus(oFeraghat, Convert.ToInt32(Session[sessionNames.userID_Karbar]), true /*chkLoan.Checked*/);

                string msg = "با موفقیت ثبت گردید";

                RadWindowManager1.RadAlert(msg, 300, 100, "پیام", "closeStatusPopup", "");

                btnSearch_Click(sender, e);
            }
        }
        protected void grd_Info_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "Add")
            {
                stcode = ViewState["stcode"].ToString();
                DataTable check;
                check = business.checkExistingRequest(stcode);

                if (check.Rows.Count == 0)//condition //////
                {
                    FeraghatTahsilBusiness bFeraghat = new FeraghatTahsilBusiness();
                    int          reqID;
                    GridDataItem itemAmount = (GridDataItem)e.Item;
                    TableCell    st         = (TableCell)itemAmount["stcode"];
                    stcode = st.Text;
                    //string note = "تایید فارغ التحصیلان";
                    string note       = "درحال بررسی";
                    string CreateDate = DateTime.Now.ToPeString();
                    reqID = business.InsertInToStudentRequest(stcode, (int)CheckOutStatusEnum.CheckOutType.fareq_tahsil, Convert.ToInt32(CheckOutStatusEnum.CheckOutAllStatusEnum.takmil_parvande), Convert.ToInt32(CheckOutStatusEnum.CheckOutAllStatusEnum.vrood_moavenat).ToString(), "", CreateDate, note, 0, true);//حذف_دبیرخانه  امکان ثبت درخواست تسویه در کدام مرحله؟
                    setLog("ثبت درخواست تسویه حساب فارغ التحصیلی از صفحه وضعیت مدارک دانشجو", reqID, (int)DTO.eventEnum.ثبت_درخواست_تسویه);

                    oFeraghat.Id               = 0;
                    oFeraghat.RizNomarat       = 0;
                    oFeraghat.GovahiMovaghat   = 0;
                    oFeraghat.DaneshNameh      = 0;
                    oFeraghat.Stcode           = stcode;
                    oFeraghat.StudentRequestId = reqID;

                    bFeraghat.UpdateMadarekStatus(oFeraghat, Convert.ToInt32(Session[sessionNames.userID_Karbar]), true /*chkLoan.Checked*/);

                    string msg = "با موفقیت ثبت گردید";

                    RadWindowManager1.RadAlert(msg, 300, 100, "پیام", "closeStatusPopup", "");

                    btnSearch_Click(sender, e);
                }
                else
                {
                    string alert = "این درخواست قبلا ثبت شده است";
                    RadWindowManager1.RadAlert(alert, 0, 200, "هشدار", "");
                    return;
                }
            }
        }
        private void setFeraghatPopup(int reqId, string studentName, string stcode)
        {
            txtRizNomre.Text             = "";
            txtGovahiMovaghat.Text       = "";
            txtDaneshname.Text           = "";
            txtSodoorDaneshname.Text     = "";
            TxtSodoorGovahiMovaghat.Text = "";
            txtSodoorRizNomre.Text       = "";
            txtErsalRizNomre.Text        = "";
            if (Convert.ToBoolean(bsn.ExistRiz(reqId)))
            {
                btnReceiptRiz.Enabled       = false;
                hdnRiznomre.Value           = signatureImage(1, reqId);
                dvSignatureRiznomre.Visible = true;
            }
            else
            {
                btnReceiptRiz.Enabled       = true;
                hdnRiznomre.Value           = "";
                dvSignatureRiznomre.Visible = false;
            }
            if (Convert.ToBoolean(bsn.ExistGovahi(reqId)))
            {
                btnReceiptGovahi.Enabled  = false;
                hdnGovahi.Value           = signatureImage(2, reqId);
                dvSignatureGovahi.Visible = true;
            }
            else
            {
                btnReceiptGovahi.Enabled  = true;
                hdnGovahi.Value           = null;
                dvSignatureGovahi.Visible = false;
            }
            if (Convert.ToBoolean(bsn.ExistDanesh(reqId)))
            {
                btnReceiptDanesh.Enabled      = false;
                hdnDaneshname.Value           = signatureImage(3, reqId);
                dvSignatureDaneshname.Visible = true;
            }
            else
            {
                btnReceiptDanesh.Enabled      = true;
                hdnDaneshname.Value           = "";
                dvSignatureDaneshname.Visible = false;
            }
            lblStName.Text = studentName;
            lblStcode.Text = stcode;
            ViewState.Add("reqId", reqId.ToString());
            hdnfReqId.Value      = reqId.ToString();
            hdnfFeraghatId.Value = 0.ToString();
            FeraghatTahsilBusiness bFeraghat = new FeraghatTahsilBusiness();
            FeraghatTahsilDTO      oFeraghat = bFeraghat.GetFeraghatMadrekStatus(reqId);


            hdnReqID.Value = reqId.ToString();
            if (oFeraghat != null)
            {
                lblArchiveDanesh.Text   = oFeraghat.archiveCode_daneshname == 0 ? "-" : oFeraghat.archiveCode_daneshname.ToString();
                lblArchiveMovaghat.Text = oFeraghat.archiveCode_movaghat == 0 ? "-" : oFeraghat.archiveCode_movaghat.ToString();
                lblArchiveRiz.Text      = oFeraghat.archiveCode_rizNomre == 0 ? "-" : oFeraghat.archiveCode_rizNomre.ToString();
                if (oFeraghat.RizNomarat > 0)
                {
                    chbkRizNomarat.Checked = true;

                    if (oFeraghat.DateRizNomarat != null)
                    {
                        txtRizNomre.Text = oFeraghat.DateRizNomarat;
                    }
                    if (oFeraghat.dateSodoorRizNomre != null)
                    {
                        txtSodoorRizNomre.Text = oFeraghat.dateSodoorRizNomre;
                    }
                    if (oFeraghat.dateErsalRizNomre != null)
                    {
                        txtErsalRizNomre.Text = oFeraghat.dateErsalRizNomre;
                    }
                }
                else
                {
                    chbkRizNomarat.Checked = false;
                    if (oFeraghat.dateErsalRizNomre != null)
                    {
                        txtErsalRizNomre.Text = oFeraghat.dateErsalRizNomre.ToString();
                    }
                    if (oFeraghat.dateSodoorRizNomre != null)
                    {
                        txtSodoorRizNomre.Text = oFeraghat.dateSodoorRizNomre.ToString();
                    }
                    if (oFeraghat.DateRizNomarat != null)
                    {
                        txtRizNomre.Text = oFeraghat.DateRizNomarat.ToString();
                    }
                }

                if (oFeraghat.GovahiMovaghat > 0)
                {
                    chbkGovahiMovaghat.Checked = true;
                    if (oFeraghat.DateGovahiMovaghat != null)
                    {
                        txtGovahiMovaghat.Text = oFeraghat.DateGovahiMovaghat;
                    }
                    if (oFeraghat.dateSodoorGovahi != null)
                    {
                        TxtSodoorGovahiMovaghat.Text = oFeraghat.dateSodoorGovahi;
                    }
                }
                else
                {
                    chbkGovahiMovaghat.Checked = false;

                    if (oFeraghat.DateGovahiMovaghat != null)
                    {
                        txtGovahiMovaghat.Text = oFeraghat.DateGovahiMovaghat.ToString();
                    }
                    if (oFeraghat.dateSodoorGovahi != null)
                    {
                        TxtSodoorGovahiMovaghat.Text = oFeraghat.dateSodoorGovahi.ToString();
                    }
                }

                if (oFeraghat.DaneshNameh > 0)
                {
                    chbkDaneshNameh.Checked = true;
                    if (oFeraghat.DateDaneshNameh != null)
                    {
                        txtDaneshname.Text = oFeraghat.DateDaneshNameh;
                    }
                    if (oFeraghat.dateSodoorDaneshname != null)
                    {
                        txtSodoorDaneshname.Text = oFeraghat.dateSodoorDaneshname;
                    }
                }
                else
                {
                    chbkDaneshNameh.Checked = false;
                    if (oFeraghat.DateDaneshNameh != null)
                    {
                        txtDaneshname.Text = oFeraghat.DateDaneshNameh.ToString();
                    }
                    if (oFeraghat.dateSodoorDaneshname != null)
                    {
                        txtSodoorDaneshname.Text = oFeraghat.dateSodoorDaneshname.ToString();
                    }
                }

                hdnfFeraghatId.Value = oFeraghat.Id.ToString();
                btnCreateArchiveCode_MadrakMovaghat.Visible = (oFeraghat.archiveCode_movaghat == 0 && oFeraghat.DateGovahiMovaghat == "");
                btnCreateArchiveCode_Daneshname.Visible     = (oFeraghat.archiveCode_daneshname == 0 && oFeraghat.DateDaneshNameh == "");
                btnCreateArchiveCode_Riznomre.Visible       = (oFeraghat.archiveCode_rizNomre == 0 && oFeraghat.DateRizNomarat == "");
            }
            else
            {
                chbkRizNomarat.Checked     = false;
                chbkGovahiMovaghat.Checked = false;
                chbkDaneshNameh.Checked    = false;
                btnCreateArchiveCode_MadrakMovaghat.Visible = true;
                btnCreateArchiveCode_Daneshname.Visible     = true;
                btnCreateArchiveCode_Riznomre.Visible       = true;
                lblArchiveDanesh.Text   = "-";
                lblArchiveMovaghat.Text = "-";
                lblArchiveRiz.Text      = "-";
            }
            CheckOutMaliBusiness MaliBusiness = new CheckOutMaliBusiness();

            if (MaliBusiness.HasAnyRefahDebit(lblStcode.Text))
            {
                vamdarBanner.Visible = true;
            }
            else
            {
                vamdarBanner.Visible = false;
            }
            CheckOutRequestBusiness reqBus = new CheckOutRequestBusiness();
            var mash = reqBus.isMashmoolferaghat(lblStcode.Text);

            if (mash != null)
            {
                if (mash > 0)
                {
                    mashmoolBanner.Visible = true;
                }
                else
                {
                    mashmoolBanner.Visible = false;
                }
            }
        }
        protected void btnSubmitStatus_Click(object sender, EventArgs e)
        {
            var btn = (Button)sender;

            if (Page.IsValid)
            {
                FeraghatTahsilBusiness bFeraghat = new FeraghatTahsilBusiness();
                FeraghatTahsilDTO      oFeraghat = new FeraghatTahsilDTO();
                oFeraghat.Id                   = Convert.ToInt32(hdnfFeraghatId.Value); //Convert.ToInt32(ViewState["feraghatId"]);
                oFeraghat.Stcode               = lblStcode.Text;
                oFeraghat.StudentRequestId     = Convert.ToInt32(hdnfReqId.Value);      //Convert.ToInt32(ViewState["reqId"]);
                oFeraghat.RizNomarat           = Convert.ToInt32(chbkRizNomarat.Checked);
                oFeraghat.GovahiMovaghat       = Convert.ToInt32(chbkGovahiMovaghat.Checked);
                oFeraghat.DaneshNameh          = Convert.ToInt32(chbkDaneshNameh.Checked);
                oFeraghat.DateDaneshNameh      = txtDaneshname.Text.Trim().formatDateString();
                oFeraghat.DateGovahiMovaghat   = txtGovahiMovaghat.Text.Trim().formatDateString();
                oFeraghat.DateRizNomarat       = txtRizNomre.Text.Trim().formatDateString();
                oFeraghat.dateSodoorDaneshname = txtSodoorDaneshname.Text.Trim().formatDateString();
                oFeraghat.dateSodoorGovahi     = TxtSodoorGovahiMovaghat.Text.Trim().formatDateString();
                oFeraghat.dateSodoorRizNomre   = txtSodoorRizNomre.Text.Trim().formatDateString();
                //oFeraghat.dateVoroodDaneshname = (bFeraghat.GetFeraghatMadrekStatus(oFeraghat.StudentRequestId).dateVoroodDaneshname.ToString()== null ? "" : bFeraghat.GetFeraghatMadrekStatus(oFeraghat.StudentRequestId).dateVoroodDaneshname.ToString());
                //oFeraghat.dateVoroodGovahi = (bFeraghat.GetFeraghatMadrekStatus(oFeraghat.StudentRequestId).dateVoroodGovahi.ToString() == null ? "" : bFeraghat.GetFeraghatMadrekStatus(oFeraghat.StudentRequestId).dateVoroodGovahi.ToString());
                //oFeraghat.dateVoroodRizNomre = (bFeraghat.GetFeraghatMadrekStatus(oFeraghat.StudentRequestId).dateVoroodRizNomre.ToString() == null ? "" : bFeraghat.GetFeraghatMadrekStatus(oFeraghat.StudentRequestId).dateVoroodGovahi.ToString());
                var madrakStatus = bFeraghat.GetFeraghatMadrekStatus(oFeraghat.StudentRequestId);
                oFeraghat.dateVoroodDaneshname = ((madrakStatus == null || string.IsNullOrEmpty(madrakStatus.dateVoroodDaneshname)) ? string.Empty : bFeraghat.GetFeraghatMadrekStatus(oFeraghat.StudentRequestId).dateVoroodDaneshname.ToString()).Trim().formatDateString();
                oFeraghat.dateVoroodGovahi     = ((madrakStatus == null || string.IsNullOrEmpty(madrakStatus.dateVoroodGovahi)) ? string.Empty : bFeraghat.GetFeraghatMadrekStatus(oFeraghat.StudentRequestId).dateVoroodGovahi.ToString()).Trim().formatDateString();
                oFeraghat.dateVoroodRizNomre   = ((madrakStatus == null || string.IsNullOrEmpty(madrakStatus.dateVoroodRizNomre)) ? string.Empty : bFeraghat.GetFeraghatMadrekStatus(oFeraghat.StudentRequestId).dateVoroodRizNomre.ToString()).Trim().formatDateString();


                oFeraghat.dateErsalRizNomre = txtErsalRizNomre.Text.Trim().formatDateString();



                int    id  = bFeraghat.UpdateMadarekStatus(oFeraghat, Convert.ToInt32(Session[sessionNames.userID_Karbar]), true, !Convert.ToBoolean(ViewState["fromGraduateDoc"]));
                string msg = "";
                if (id > 0)
                {
                    msg = "بروز رسانی انجام شد.";
                    var oCommon     = new CommonBusiness();
                    var yes         = "بلی";
                    var no          = "خیر";
                    var checkRiz    = "ندارد";
                    var checkDanesh = "ندارد";
                    var checkGovahi = "ندارد";
                    if (chbkDaneshNameh.Checked)
                    {
                        checkDanesh = "دارد";
                    }
                    if (chbkGovahiMovaghat.Checked)
                    {
                        checkGovahi = "دارد";
                    }
                    if (chbkRizNomarat.Checked)
                    {
                        checkRiz = "دارد";
                    }

                    setLog($"صدور ریز نمرات : {txtSodoorRizNomre.Text} --" + " " + $"صدور گواهی موقت : {TxtSodoorGovahiMovaghat.Text} --" + " " + $"صدور دانشنامه : {txtSodoorDaneshname.Text} --" + $"ارسال ریز نمره: {txtErsalRizNomre.Text}" + $"تحویل ریز نمرات : {txtRizNomre.Text} --" + $"تحویل گواهی موقت : {txtGovahiMovaghat.Text} --" + $"تحویل دانشنامه : {txtDaneshname.Text} --" + $"تیک ریز نمره : {checkRiz} --" + $"تیک گواهی موقت : {checkGovahi} --" + $"تیک دانشنامه : {checkDanesh} ",
                           oFeraghat.StudentRequestId,
                           (int)DTO.eventEnum.ویرایش_وضعیت_مدرک_دانشجو);
                    if (Session["stcode_GraduateDoc"] != null)
                    {
                        Response.Redirect("showGraduateDocument.aspx");
                    }
                }
                switch (ViewState["howToBindGrid"].ToString())
                {
                case "searchStudent(oFeraghat)":
                    searchStudent(new FeraghatTahsilDTO()
                    {
                        Stcode = txtStcode.Text, family = txtFamily.Text
                    });
                    break;

                default:

                    BindGrid();
                    break;
                }

                RadWindowManager1.RadAlert(msg, 300, 100, "پیام", "closeStatusPopup", "");
                //ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseAndRebind", "CloseAndRebind(true);", true);
                //ClientScript.RegisterClientScriptBlock(GetType(), "ardalertdone", scrp);
                //chkLoan.Checked = false;
            }
            else
            {
                var msg = "تاریخ وارد شده باید قبل از تاریخ امروز باشد";
                switch (ViewState["howToBindGrid"].ToString())
                {
                case "searchStudent(oFeraghat)":
                    searchStudent(new FeraghatTahsilDTO()
                    {
                        Stcode = txtStcode.Text, family = txtFamily.Text
                    });
                    break;

                default:

                    BindGrid();
                    break;
                }

                RadWindowManager1.RadAlert(msg, 300, 100, "پیام", "closeradwindow4", "");
            }
        }