using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LYFZ.Web.WeiXinAPP.Satisfaction
{
    public partial class SatisfactionOrderDetail : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)        
        {
            ViewState["StrSatisfactionID"] = "OrderPerson";
            
            string cusId = Request.QueryString["cusid"];
            string appId = Request.QueryString["appid"];
            string openId = Request.QueryString["openId"];
           
            string ordernumber = Request.QueryString["OrdNumber"];

            if (string.IsNullOrEmpty(cusId) || string.IsNullOrEmpty(cusId.Trim()))
            {
                Response.Write("非法访问!");
                Response.End();
                return;
            }
            else
            {
                LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces cusModel = LYFZ.WeixinServers.Global.GetCustomerModelById(cusId);

                string getCheckText = LYFZ.WinAPI.HttpClientHelper.GetResponse(cusModel.GetRequestUrl()
                   + "/Api/WXApi.ashx/CheckWXCustomerHaveChangeOrder?openid=" + openId + "&appid=" + appId + "&ordernumber=" + ordernumber);
                dynamic dyCheckObject = Newtonsoft.Json.JsonConvert.DeserializeObject(getCheckText);

                if (Convert.ToBoolean(dyCheckObject.data))
                {
                    if (!IsPostBack)
                    {
                        string Types = "";
                        if (!string.IsNullOrEmpty(Request.QueryString["type"]))
                        { Types = Request.QueryString["type"].ToString().Trim(); }
                        if (Types.Trim() == "2")
                        {


                            string queryData = "";
                            string postData = "";
                            foreach (string key in Request.QueryString.AllKeys)
                            {
                                if (!string.IsNullOrEmpty(queryData))
                                {
                                    queryData += "&";
                                }
                                queryData += key + "=" + Request.QueryString[key];
                            }

                            foreach (string key in Request.Form.AllKeys)
                            {
                                if (!string.IsNullOrEmpty(postData))
                                {
                                    postData += "&";
                                }
                                postData += key + "=" + Request.Form[key];
                            }
                            if (!string.IsNullOrEmpty(Request.QueryString["btnType"]))
                            {
                                ViewState["StrSatisfactionID"] = Request.QueryString["btnType"];
                            }


                            string getText = LYFZ.WinAPI.HttpClientHelper.PostResponse(cusModel.GetRequestUrl()
                          + "/Api/WXApi.ashx/SaveSatisfactionData?" + queryData, postData, "application/x-www-form-urlencoded");

                            dynamic dyObject = Newtonsoft.Json.JsonConvert.DeserializeObject(getText);


                            Response.Write("<script type='text/javascript'>alert('" + dyObject.data + "');</script>");
                            // LYFZ.WeixinServiceDate.Model.Model_CustomerInterfaces cusModel = LYFZ.WeixinServers.Global.GetCustomerModelById(Request["cusid"]);
                        }
                    }
                }
                else
                {
                    Response.Write("您无权对订单编号:" + ordernumber+"的订单进行评价!");
                    Response.End();
                }
            }
            
        }
    }
}