protected void Page_Load(object sender, EventArgs e)
    {
        if ((Request.QueryString["n"] != null))
        {
            code_s          = Request.QueryString["n"];
            Session["Fact"] = code_s;
        }
        else
        {
            Response.Redirect("perfact.aspx");
        }

        //for register btn
        btn.InnerHtml = "<a class='dark-2 common_font common_div' href='Default.aspx?code=" + code_s + "' onclick='deleteAllCookies();'>ثبت سفارش</a>";

        try
        {
            tblFactOnCollection list_fact = new tblFactOnCollection();
            list_fact.ReadList(Criteria.NewCriteria(tblFactOn.Columns.id_fact, CriteriaOperators.Equal, Convert.ToInt32(code_s)));

            string new_content = "";
            int    count_stuff = 0, Sum_price = 0;
            tblDetailStuffCollection list_detail = new tblDetailStuffCollection();
            list_detail.ReadList(Criteria.NewCriteria(tblDetailStuff.Columns.id_fact, CriteriaOperators.Equal, Convert.ToInt32(code_s)));

            string invoice_content = "<div style='text-align:right;direction: rtl;'>" +
                                     "<table border='1' style='width:100%;text-align: center;'><tr style='background-color: rgb(255, 200, 98);'><td style='padding: 0 15px;padding-right:0;color: rgb(119, 119, 226);width: 6%;'>کد کالا</td><td style='padding: 0 15px;color: rgb(119, 119, 226);width: 34%;'>نام محصول</td>" +
                                     "<td style='padding: 0 15px;color: rgb(119, 119, 226);width: 25%;'>قیمت واحد</td><td style='padding: 0 15px;color: rgb(119, 119, 226);width: 10%;'>تعداد</td><td style='padding: 0 15px;padding-left:0;color: rgb(119, 119, 226);width: 25%;'>جمع</td></tr>";

            for (int i = 0; i < list_detail.Count; i++)
            {
                count_stuff += 1;
                string stuff_id = list_detail[i].id_stuff.ToString();

                tblPorfolioCollection info_stuff = new tblPorfolioCollection();
                info_stuff.ReadList(Criteria.NewCriteria(tblPorfolio.Columns.id_profolio, CriteriaOperators.Like, stuff_id));

                new_content += "<tr><td style='padding: 10px 0;'>" + stuff_id + "</td>" +
                               "<td style='padding: 10px 0;'>" + info_stuff[0].title_prof + "</td>" +
                               "<td style='padding: 10px 0;'>" + info_stuff[0].pic_addr + "</td>" +
                               "<td style='padding: 10px 0;'>" + list_detail[i].no_stuff + "</td>" +
                               "<td style='padding: 10px 0;'>" + Convert.ToInt32(info_stuff[0].pic_addr) * list_detail[i].no_stuff + "</td></tr>";
                Sum_price += Convert.ToInt32((list_detail[i].pay_one * list_detail[i].no_stuff).ToString());
            }

            invoice_content += new_content;

            invoice_content += "</table><p style='margin-top: 15px;border-top: 1px solid;'>تعداد محصول خریداری: " + (count_stuff) + "</p>" +
                               "<p>جمع قابل پرداخت: " + Sum_price + "</p>" +
                               "<p>آدرس: " + list_fact[0].addr + "</p>" +
                               "<p>تلفن: " + list_fact[0].tel + "</p>" +
                               "</div>";
            invoice_box.InnerHtml  = invoice_content;
            sum_pay_show.InnerText = "ریال" + Sum_price;
        }
        catch (Exception)
        {
            invoice_box.InnerText = "خطا در اتصال به پایگاه داده!";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((Request.QueryString["n"] != null))
        {
            code_s          = Request.QueryString["n"];
            Session["Fact"] = code_s;
        }
        else
        {
            Response.Redirect("perfact.aspx");
        }


        try
        {
            tblFactOnCollection list_fact = new tblFactOnCollection();
            list_fact.ReadList(Criteria.NewCriteria(tblFactOn.Columns.id_fact, CriteriaOperators.Equal, Convert.ToInt32(code_s)));


            string new_content = "";
            int    count_stuff = 0;
            tblDetailStuffCollection list_detail = new tblDetailStuffCollection();
            list_detail.ReadList(Criteria.NewCriteria(tblDetailStuff.Columns.id_fact, CriteriaOperators.Equal, Convert.ToInt32(code_s)));

            string invoice_content = "<div class='icon'>" +
                                     "<p class='name'>صورتحساب</p>" +
                                     "<table border='1'><tr><td style='padding: 0 15px;padding-right:0;color: rgb(119, 119, 226);'>نام محصول</td><td style='padding: 0 15px;color: rgb(119, 119, 226);'>نام تجاری</td>" +
                                     "<td style='padding: 0 15px;color: rgb(119, 119, 226);'>قیمت مصوب</td><td style='padding: 0 15px;color: rgb(119, 119, 226);'>تخفیف</td><td style='padding: 0 15px;padding-left:0;color: rgb(119, 119, 226);'>قیمت بورس</td></tr>";

            for (int i = 0; i < list_detail.Count; i++)
            {
                count_stuff += 1;
                string             stuff_id   = list_detail[i].id_stuff.ToString();
                tblStuffCollection info_stuff = new tblStuffCollection();
                info_stuff.ReadList(Criteria.NewCriteria(tblStuff.Columns.id_stuff, CriteriaOperators.Like, stuff_id));

                new_content += "<tr><td style='padding: 10px 0;'>" + info_stuff[0].name_stuff + "</td>" +
                               "<td style='padding: 10px 0;'>" + info_stuff[0].detail + "</td>" +
                               "<td style='padding: 10px 0;'>" + info_stuff[0].price + "</td>" +
                               "<td style='padding: 10px 0;'>" + info_stuff[0].detail + "</td>" +
                               "<td style='padding: 10px 0;'>" + info_stuff[0].price + "</td></tr>" +
                               //"<p>جمع کل(بدون تخفیف): " + info_stuff[0].price_borse + "</p>" +
                               //"<p>جمع کل(با تخفیف): " + info_stuff[0].price_borse + "</p>" +
                               "<div class='separator_20'></div>";
                invoice_content += new_content;
            }

            invoice_content += "</table><p>تعداد محصول خریداری: " + (count_stuff + 1) + "</p>" +
                               "<p>جمع قابل پرداخت: " + list_fact[0].amount + "</p>" +
                               "<p>آدرس: " + list_fact[0].addr + "</p>" +
                               "<p>تلفن: " + list_fact[0].name + "</p>" +
                               "<form action='https://acquirer.samanepay.com/payment.aspx' method='post'>" +
                               "<input type='hidden' id='MID' name='MID' value='10085228'/>  " +
                               "<input type='hidden' id='Amount' name='Amount' value='" + list_fact[0].amount + "'/>" +
                               "<input type='hidden' id='ResNum' name='ResNum' value='" + list_fact[0].detail + "'/>" +
                               "<input type='hidden' id='RedirectURL' name='RedirectURL' value='http://boorsedaroo.ir/resultbuy.aspx'/>" +
                               "<p class='tal'>" +
                               "<button type='submit' name='Save' class='general_navigation_button back'>خرید اینترنتی</button>" +
                               "</p>" +
                               "</form>" +
                               "</div>";
            invoice_box.InnerHtml = invoice_content;

            //create form for bank
            //Literal amount = new Literal();
            //amount.Text = "<input type='hidden' id='Amount' name='Amount' value='10000'/>";// +list_fact[0].amount + "'/>";
            //amount.Text += "<input type='hidden' id='ResNum' name='ResNum' value='" + list_fact[0].detail + "'/>";
            //ph_bank.Controls.Add(amount);
        }
        catch (Exception)
        {
            invoice_box.InnerText = "خطا در اتصال به پایگاه داده!";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //Read Fact Number
        if ((Request.QueryString["n"] != null))
        {
            code_s          = Request.QueryString["n"];
            Session["Fact"] = code_s;
        }
        else
        {
            Response.Redirect("perfact.aspx");
        }

        //Select Data Value
        tblFactOnCollection list_fact = new tblFactOnCollection();

        list_fact.ReadList(Criteria.NewCriteria(tblFactOn.Columns.id_fact, CriteriaOperators.Equal, Convert.ToInt32(code_s)));

        string new_content = "";
        int    count_stuff = 0, Sum_price = 0;
        tblDetailStuffCollection list_detail = new tblDetailStuffCollection();

        list_detail.ReadList(Criteria.NewCriteria(tblDetailStuff.Columns.id_fact, CriteriaOperators.Equal, Convert.ToInt32(code_s)));

        for (int i = 0; i < list_detail.Count; i++)
        {
            count_stuff += 1;
            string             stuff_id   = list_detail[i].id_stuff.ToString();
            tblStuffCollection info_stuff = new tblStuffCollection();
            info_stuff.ReadList(Criteria.NewCriteria(tblStuff.Columns.id_stuff, CriteriaOperators.Like, stuff_id));

            new_content += info_stuff[0].id_stuff;

            Sum_price += Convert.ToInt32((list_detail[i].pay_one * list_detail[i].no_stuff).ToString());
        }

        PayAmountTextBox.Text  = Sum_price.ToString();
        PayOrderIdTextBox.Text = code_s;
        if (!IsPostBack)
        {
            SetDefaultDateTime();
            PayCallBackUrlTextBox.Text = CallBackUrl;
            TerminalIdTextBox.Text     = TerminalId;
            UserNameTextBox.Text       = UserName;
            UserPasswordTextBox.Text   = UserPassword;
        }
        //send data to the bank
        try
        {
            string result;

            BypassCertificateError();

            BPService.PaymentGatewayImplService bpService = new BPService.PaymentGatewayImplService();
            result = bpService.bpPayRequest(Int64.Parse(TerminalIdTextBox.Text),
                                            UserNameTextBox.Text,
                                            UserPasswordTextBox.Text,
                                            Int64.Parse(PayOrderIdTextBox.Text),
                                            Int64.Parse(PayAmountTextBox.Text),
                                            PayDateTextBox.Text,
                                            PayTimeTextBox.Text,
                                            PayAdditionalDataTextBox.Text,
                                            PayCallBackUrlTextBox.Text,
                                            Int64.Parse(PayPayerIdTextBox.Text));

            PayOutputLabel.Text = result;

            String[] resultArray = result.Split(',');
            if (resultArray[0] == "0")
            {
                ClientScript.RegisterStartupScript(typeof(Page), "ClientScript", "<script language='javascript' type='text/javascript'> postRefId('" + resultArray[1] + "');</script> ", false);
            }
        }
        catch (Exception exp)
        {
            PayOutputLabel.Text = "Error: " + exp.Message;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((Request.QueryString["n"] != null))
        {
            code_s          = Request.QueryString["n"];
            Session["Fact"] = code_s;
        }
        else
        {
            Response.Redirect("perfact.aspx");
        }


        try
        {
            tblFactOnCollection list_fact = new tblFactOnCollection();
            list_fact.ReadList(Criteria.NewCriteria(tblFactOn.Columns.id_fact, CriteriaOperators.Equal, Convert.ToInt32(code_s)));


            string new_content = "";
            int    count_stuff = 0, Sum_price = 0;
            tblDetailStuffCollection list_detail = new tblDetailStuffCollection();
            list_detail.ReadList(Criteria.NewCriteria(tblDetailStuff.Columns.id_fact, CriteriaOperators.Equal, Convert.ToInt32(code_s)));

            string invoice_content = "<div style='text-align:right;direction: rtl;'>" +
                                     "<table border='1' style='width:100%;text-align: center;'><tr style='background-color: rgb(255, 200, 98);'><td style='padding: 0 15px;padding-right:0;color: rgb(119, 119, 226);width: 6%;'>کد کالا</td><td style='padding: 0 15px;color: rgb(119, 119, 226);width: 34%;'>نام محصول</td>" +
                                     "<td style='padding: 0 15px;color: rgb(119, 119, 226);width: 25%;'>قیمت واحد</td><td style='padding: 0 15px;color: rgb(119, 119, 226);width: 10%;'>تعداد</td><td style='padding: 0 15px;padding-left:0;color: rgb(119, 119, 226);width: 25%;'>جمع</td></tr>";

            for (int i = 0; i < list_detail.Count; i++)
            {
                count_stuff += 1;
                string             stuff_id   = list_detail[i].id_stuff.ToString();
                tblStuffCollection info_stuff = new tblStuffCollection();
                info_stuff.ReadList(Criteria.NewCriteria(tblStuff.Columns.id_stuff, CriteriaOperators.Like, stuff_id));

                new_content += "<tr><td style='padding: 10px 0;'>" + info_stuff[0].id_stuff + "</td>" +
                               "<td style='padding: 10px 0;'>" + info_stuff[0].name_stuff + "</td>" +
                               "<td style='padding: 10px 0;'>" + list_detail[i].pay_one + "</td>" +
                               "<td style='padding: 10px 0;'>" + list_detail[i].no_stuff + "</td>" +
                               "<td style='padding: 10px 0;'>" + list_detail[i].pay_one * list_detail[i].no_stuff + "</td></tr>";
                //"<p>جمع کل(بدون تخفیف): " + info_stuff[0].price_borse + "</p>" +
                //"<p>جمع کل(با تخفیف): " + info_stuff[0].price_borse + "</p>" +
                Sum_price += Convert.ToInt32((list_detail[i].pay_one * list_detail[i].no_stuff).ToString());
                //invoice_content += new_content;
            }

            invoice_content += new_content;


            invoice_content += "</table><p style='margin-top: 15px;border-top: 1px solid;'>تعداد محصول خریداری: " + (count_stuff) + "</p>" +
                               "<p>جمع قابل پرداخت: " + Sum_price + "</p>" +
                               "<p>آدرس: " + list_fact[0].addr + "</p>" +
                               "<p>تلفن: " + list_fact[0].tel + "</p>" +
                               "<form action='https://acquirer.samanepay.com/payment.aspx' method='post'>" +
                               "<input type='hidden' id='MID' name='MID' value='10085228'/>  " +
                               "<input type='hidden' id='Amount' name='Amount' value='" + list_fact[0].amount + "'/>" +
                               "<input type='hidden' id='ResNum' name='ResNum' value='" + list_fact[0].detail + "'/>" +
                               "<input type='hidden' id='RedirectURL' name='RedirectURL' value='http://boorsedaroo.ir/resultbuy.aspx'/>" +
                               "<p class='tal'>" +
                               "<button type='submit' name='Save' class='dark-2 common_font common_div'>خرید اینترنتی</button>" +
                               "</p>" +
                               "</form>" +
                               "</div>";
            invoice_box.InnerHtml = invoice_content;



            sum_pay_show.InnerText = "ریال" + Sum_price;


            //create form for bank
            //Literal amount = new Literal();
            //amount.Text = "<input type='hidden' id='Amount' name='Amount' value='10000'/>";// +list_fact[0].amount + "'/>";
            //amount.Text += "<input type='hidden' id='ResNum' name='ResNum' value='" + list_fact[0].detail + "'/>";
            //ph_bank.Controls.Add(amount);
        }
        catch (Exception)
        {
            invoice_box.InnerText = "خطا در اتصال به پایگاه داده!";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //RefIdLabel.Text = Request.Params["RefId"];
            int status = Convert.ToInt32(Request.Params["ResCode"]);
            lbl_state.Text = status.ToString();

            if (Request.Params["SaleReferenceId"].Length > 0)
            {
                if (status == 17)
                {
                    lbl_state.Text = "كاربر از انجام تراكنش منصرف شده است";
                }
                else if (status == 0)
                {
                    lbl_state.Text = "تراكنش با موفقيت انجام شد";
                }
                else if (status == 12)
                {
                    lbl_state.Text = "موجودي كافي نيست";
                }
                else
                {
                    lbl_state.Text = "تراکنش با شکست متوقف شد.";
                }
            }


            switch (status)
            {
            case 0: lbl_state.Text = "تراكنش با موفقيت انجام شد"; break;

            case 11: lbl_state.Text = "شماره كارت نامعتبر است"; break;

            case 12: lbl_state.Text = "موجودي كافي نيست"; break;

            case 13: lbl_state.Text = "رمز نادرست است"; break;

            case 14: lbl_state.Text = "تعداد دفعات وارد كردن رمز بيش از حد مجاز است"; break;

            case 15: lbl_state.Text = "كارت نامعتبر است"; break;

            case 16: lbl_state.Text = "دفعات برداشت وجه بيش از حد مجاز است"; break;

            case 17: lbl_state.Text = "كاربر از انجام تراكنش منصرف شده است"; break;

            case 18: lbl_state.Text = "تاريخ انقضاي كارت گذشته است"; break;

            case 19: lbl_state.Text = "مبلغ برداشت وجه بيش از حد مجاز است"; break;

            case 111: lbl_state.Text = "مبلغ برداشت وجه بيش از حد مجاز است"; break;

            case 112: lbl_state.Text = "خطاي سوييچ صادر كننده كارت"; break;

            case 113: lbl_state.Text = "پاسخي از صادر كننده كارت دريافت نشد"; break;

            case 114: lbl_state.Text = "دارنده كارت مجاز به انجام اين تراكنش نيست"; break;

            case 21: lbl_state.Text = "پذيرنده نامعتبر است"; break;

            case 23: lbl_state.Text = "خطاي امنيتي رخ داده است"; break;

            case 24: lbl_state.Text = "اطلاعات كاربري پذيرنده نامعتبر است"; break;

            case 25: lbl_state.Text = "مبلغ نامعتبر است"; break;

            case 31: lbl_state.Text = "پاسخ نامعتبر است"; break;

            case 32: lbl_state.Text = "فرمت اطلاعات وارد شده صحيح نمي باشد"; break;

            case 33: lbl_state.Text = "حساب نامعتبر است"; break;

            case 34: lbl_state.Text = "خطاي سيستمي"; break;

            case 35: lbl_state.Text = "تاريخ نامعتبر است"; break;

            case 41: lbl_state.Text = "شماره درخواست تكراري است"; break;

            case 42: lbl_state.Text = "تراكنش sale یافت نشد"; break;

            case 43: lbl_state.Text = "قبلا درخواست verify داده شده است"; break;

            case 44: lbl_state.Text = "درخواست verify یافت نشد"; break;

            case 45: lbl_state.Text = "تراکنش settle یافت شده است"; break;

            case 46: lbl_state.Text = "تراکنش settle یافت نشده است"; break;

            case 47: lbl_state.Text = "تراکنش settle یافت نشد"; break;

            default: lbl_state.Text = "کار با خطا متوقف شد."; break;
            }


            lbl_no_fact.Text = Request.Params["SaleOrderId"];

            lbl_resid.Text = Request.Params["SaleReferenceId"]; //Receipt Number From Bank

            //save into DB
            try
            {
                tblFactOnCollection list_fact = new tblFactOnCollection();
                list_fact.ReadList(Criteria.NewCriteria(tblFactOn.Columns.id_fact, CriteriaOperators.Equal, Convert.ToInt32(lbl_no_fact.Text)));

                list_fact[0].state = lbl_state.Text;

                if (lbl_resid.Text.Length > 0)
                {
                    list_fact[0].ref_num = lbl_resid.Text;
                }
                else
                {
                    list_fact[0].ref_num = "cancel";
                }

                list_fact[0].res_num = lbl_no_fact.Text;

                list_fact.UpdateList(true);
            }
            catch (Exception)
            {
            }
        }

        catch (Exception ex)
        {
        }
    }