using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using System.Web.Security;

namespace norke.admin
{
	/// <summary>
	/// singleReckoningS 的摘要说明。
	/// </summary>
	public partial class singleReckoningS : System.Web.UI.Page
	{
        protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;
    
		protected void Page_Load(object sender, System.EventArgs e)
		{
            //权限检查
            if( Session["adminName"]==null || Session["adminName"].ToString() == String.Empty )
            {
                Response.Write("<font color=#ff0000 style='FONT-SIZE: 12px'>对不起,您没足够权限访问此页!!</font><br>");
                Response.Write("<a href=Default.aspx target=_top style='FONT-SIZE: 12px'>重新登陆</a><br>");
                Response.End();
                return;
            }

            if( !IsPostBack )
            {
                if( Request.QueryString["orderid"] == null )
                {
                    Response.Redirect("singleReckoning.aspx");
                    return;
                }

                string strOrderid = Request.QueryString["orderid"].ToString(); //商户订单编号
                string strMerchant_id = getMerchantID();//获取 商户编号
                string strMerchant_url = getMerchantCURL();//获取 商户接收查账结果URL
                string strMac = "";
                string strKey = getMerchantKey();//获取 私钥值
                string strSac = "merchant_id=" + strMerchant_id + "&orderid=" + strOrderid + "&merchant_url=" + 
                    strMerchant_url + "&merchant_key=" +  strKey;

                //md5加密
                strMac = FormsAuthentication.HashPasswordForStoringInConfigFile( strSac ,"MD5");

                orderid.Value = strOrderid;
                merchant_id.Value = strMerchant_id;
                merchant_url.Value = strMerchant_url;
                mac.Value = strMac;
                
                lblOrderid.Text = strOrderid;
            }
        }

        private string getMerchantCURL()//获取 商户接收查账结果URL
        {
            string s = "";

            DBConn myDB = new DBConn();
            string mySql="select [text] from [wangguan] where [id]='3'";
            SqlDataReader mydr  = myDB.getDataReader( mySql );
            if( mydr.Read() )
            {
                s = mydr["text"].ToString();
            }
            mydr.Close();
            myDB.Close();

            return s;
        }

        private string getMerchantKey()//获取 私钥值
        {
            string s = "";

            DBConn myDB = new DBConn();
            string mySql="select [text] from [wangguan] where [id]='1'";
            SqlDataReader mydr  = myDB.getDataReader( mySql );
            if( mydr.Read() )
            {
                s = mydr["text"].ToString();
            }
            mydr.Close();
            myDB.Close();

            //加密对象
            DCard.Encode myEncode = new DCard.Encode();
            try
            { 
                s = myEncode.DecryptString( s );
            }
            catch
            {
                //如果不是已加密字符串 就会出错
            }

            return s;
        }

        private string getMerchantID()//获取 商户编号
        {
            string s = "";

            DBConn myDB = new DBConn();
            string mySql="select [text] from [wangguan] where [id]='0'";
            SqlDataReader mydr  = myDB.getDataReader( mySql );
            if( mydr.Read() )
            {
                s = mydr["text"].ToString();
            }
            mydr.Close();
            myDB.Close();

            return s;
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
		
        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {    

        }
		#endregion
	}
}
