TenderWebRequest


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text;
using BestHTTP;
using com.kleberswf.lib.core;
using UnityEngine;
using ModestTree;
using Google.Protobuf;
using Tenders.Protobuf;

enum InteractiveE
{
    ADD,
    Query,
    Delete,
    Modify,
    Update,
    /// 
    /// 请求标段资源价格
    /// 
    Tender_ZY_Query,
    /// 
    /// 提交资源价格数据
    /// 
    Tender_ZY_PostDate,
    /// 
    /// 提交固话信息
    /// 
    GuHua,
    /// 
    /// 查询符合条件的模拟标段信息 
    /// 
    MoNI_url_Modity,
    /// 
    /// 请求模拟标段信息 
    /// 
    MoNI_url_Query,
    /// 
    /// 请求回放数据
    /// 
    PB_Query,
    /// 
    /// 提交回放信息
    /// 
    PB_PostDate,
    /// 
    /// 查询回放 
    /// 
    PB_Modity,
    /// 
    /// 删除回放
    /// 
    PB_Delect,
    /// 
    /// 请求该回放的所有评论
    /// 
    CTD_Query,
    /// 
    /// 发送评论
    /// 
    CTD_PostDate
}

public enum GGTProE
{
    Tender,
    MoNi,
    PlayBack,
    comm
}
public class TenderWebRequest : Singleton
{
    public TenderMoNi tendermoni;
    private InteractiveE interactive;
    private GGTProE GgtState;
    public string url_getcookie;
    public string cookie;
    public string addressstr;
    public Uri address;

    public string url_Res;
    public string url_Query;
    public string url_Modity;
    public string url_delete;
    public string url_Update;
    public string url_ZY_Query;
    public string url_ZY_PostDate;
    public string url_GuHua;
    public string url_MoNi_Query;
    public string url_PB_PostDate;
    public string url_PB_Modity;
    public string url_PB_Delete;
    public string url_PB_Query;
    public string url_CTD_PostDate;
    public string url_CTD_Modity;
    private IMessage mesRequest;
    IMessage mesResponse;




    void Awake()
    {
        try
        {
            address = WebRequest.Instance.address;
            cookie = WebRequest.Instance.cookie;
            url_Res = new Uri(address, "sgcis/ggt_second/rest/ggttperipro/add").ToString();
            url_Query = new Uri(address, "sgcis/ggt_second/rest/ggttperipro/query").ToString();
            url_Modity = new Uri(address, "sgcis/ggt_second/rest/ggttperipro/queryZy").ToString();
            url_delete = new Uri(address, "sgcis/ggt_second/rest/ggttperipro/del").ToString();
            url_Update = new Uri(address, "sgcis/ggt_second/rest/ggttperipro/update").ToString();
            url_ZY_Query = new Uri(address, "sgcis/ggt_second/rest/ggttperipro/queryRes").ToString();
            url_ZY_PostDate = new Uri(address, "sgcis/ggt_second/rest/ggttperipro/updateRes").ToString();
            url_GuHua = new Uri(address, "sgcis/ggt_second/rest/ggttperipro/guhua").ToString();
            url_MoNi_Query = new Uri(address, "sgcis/ggt_second/rest/ggttperipro/queryZy").ToString();
            url_PB_PostDate = new Uri(address, "sgcis/ggt_second/rest/ggtproject/add").ToString();
            url_PB_Modity = new Uri(address, "sgcis/ggt_second/rest/ggtproject/query").ToString();
            url_PB_Delete = new Uri(address, "sgcis/ggt_second/rest/ggtproject/del").ToString();
            url_PB_Query = new Uri(address, "sgcis/ggt_second/rest/ggtproject/queryZy").ToString();
            url_CTD_PostDate = new Uri(address, "sgcis/ggt_second/rest/ggttpericomm/add").ToString();
            url_CTD_Modity = new Uri(address, "sgcis/ggt_second/rest/ggttpericomm/query").ToString();

        }
        catch (Exception ex)
        {
            UIControl._instance.TishiText("数据连接地址错误");
        }

    }

    public void SerialDataTes(T types, string requrl, string Type)
    {
        byte[] bytes;
        MemoryStream output;
        using (output = new MemoryStream())
        {
            ((IMessage)types).WriteTo(output);
            bytes = output.ToArray();

        }
        switch (Type)
        {
            case "ADD":
                interactive = InteractiveE.ADD;
                break;
            case "Query":
                interactive = InteractiveE.Query;
                break;
            case "Delete":
                interactive = InteractiveE.Delete;
                break;
            case "Modify":
                interactive = InteractiveE.Modify;
                break;
            case "Update":
                interactive = InteractiveE.Update;
                break;
            case "ZY_PostDate":
                interactive = InteractiveE.Tender_ZY_PostDate;
                break;
            case "GuHua":
                interactive = InteractiveE.GuHua;
                break;
            case "PB_PostDate":
                interactive = InteractiveE.PB_PostDate;
                break;
            case "CTD_PostDate":
                interactive = InteractiveE.CTD_PostDate;
                break;
            default:
                break;
        }
        SendData(bytes, requrl);
    }

    /// 
    /// 增 发送数据,删
    /// 
    /// 类序列化为流
    /// 请求的地址
    void SendData(byte[] bytes, string requrl)
    {
        HTTPRequest request = new HTTPRequest(new Uri(requrl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.RawData = bytes;
        request.Send();
    }

    /// 
    /// 请求数据
    /// 
    /// 服务器地址
    /// 发送需要查询的文本
    /// 查询类型
    public void QueryData(string queryurl, string TenderName, string QueryType)
    {
        interactive = InteractiveE.Query;
        HTTPRequest request = new HTTPRequest(new Uri(queryurl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.AddField("TenderName", TenderName);
        request.AddField("Type", QueryType);
        request.Send();
    }

    public void QueryDataModity(string queryurl, string GUID)
    {
        interactive = InteractiveE.Modify;

        HTTPRequest request = new HTTPRequest(new Uri(queryurl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.AddField("id", GUID);
        request.Send();
    }

    public void QueryDataZY(string queryurl, string Guid)
    {
        {
            interactive = InteractiveE.Tender_ZY_Query;
        }
        HTTPRequest request = new HTTPRequest(new Uri(queryurl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.AddField("id", Guid);
        request.Send();
    }
    GuHuaImage gh;
    public void QueryDataGuHua(string queryurl, string Guid, GuHuaImage GI)
    {
        {
            gh = GI;
            interactive = InteractiveE.GuHua;
        }
        HTTPRequest request = new HTTPRequest(new Uri(queryurl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.AddField("id", Guid);
        request.Send();
    }

    /// 
    /// 请求模拟演练数据
    /// 
    /// Queryurl.
    /// Imesg.
    /// Res type.
    /// Query type.
    public void QueryDataMoNiModify(string queryurl, string TenderName, string QueryType)
    {
        interactive = InteractiveE.MoNI_url_Modity;
        HTTPRequest request = new HTTPRequest(new Uri(queryurl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.AddField("TenderName", TenderName);
        request.AddField("Type", QueryType);
        request.Send();
    }
    public void QueryDataMoNiQuery(string queryurl, string GUID)
    {
        interactive = InteractiveE.MoNI_url_Query;

        HTTPRequest request = new HTTPRequest(new Uri(queryurl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.AddField("id", GUID);
        request.Send();
    }

    //回放请求与查询
    public void QueryDataPBModify(string queryurl, string TenderName, string Date)
    {
        interactive = InteractiveE.PB_Modity;
        HTTPRequest request = new HTTPRequest(new Uri(queryurl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.AddField("TenderName", TenderName);
        request.AddField("Date", Date);
        request.Send();
    }
    public void QueryDataPBDelete(string queryurl, string GUID)
    {
        interactive = InteractiveE.PB_Delect;

        HTTPRequest request = new HTTPRequest(new Uri(queryurl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.AddField("id", GUID);
        request.Send();
    }
    public void QueryDataPBQuery(string queryurl, string GUID)
    {
        interactive = InteractiveE.PB_Query;

        HTTPRequest request = new HTTPRequest(new Uri(queryurl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.AddField("id", GUID);
        request.Send();
    }
    //请求评论,发送评论
    public void QueryDataCTDModify(string queryurl, string GUID)
    {
        interactive = InteractiveE.CTD_Query;
        HTTPRequest request = new HTTPRequest(new Uri(queryurl), HTTPMethods.Post, OnRequestData);
        request.SetHeader("Cookie", cookie);
        request.AddField("id", GUID);
        request.Send();
    }

    TendeInfo tenderinfo = new TendeInfo();

    void OnRequestData(HTTPRequest request, HTTPResponse response)
    {
        try
        {
            Debug.Log(response.IsSuccess);
            Debug.Log(response.Data.Length);
        }
        catch (Exception ex)
        {
            UIControl._instance.TishiText("获取数据失败");
            return;
        }
        switch (interactive)
        {
            //标段添加之后,返回首页,执行标段查询事件
            case InteractiveE.ADD:

                UIControl._instance.ExitStart();
                TenderWebRequest.Instance.QueryData(TenderWebRequest.Instance.url_Query, "-1", "0");
                break;

            //请求标段数据,并显示
            case InteractiveE.Query:
                try
                {
                    mesResponse = new TenderDateClass();
                    TenderDateClass imesRes1 = (TenderDateClass)mesResponse.Descriptor.Parser.ParseFrom(response.Data);
                    TenderSceneControl._instance.TDC = imesRes1;
                    UIControl._instance.ShowTenderProGL_Before();
                    // UIControl._instance.chaxunText.text = "";
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("请求数据失败");
                }


                break;

            //删除标段数据
            case InteractiveE.Delete:

                try
                {
                    UIControl._instance.ExitStart();
                    TenderWebRequest.Instance.QueryData(TenderWebRequest.Instance.url_Query, "-1", "0");
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("数据删除失败");
                }

                break;

            //请求单个标段数据,点击修改的时候
            case InteractiveE.Modify:

                try
                {
                    UIControl._instance.isAdd = false;
                    mesResponse = new TenderDateClass();
                    TenderDateClass imesRes4 = (TenderDateClass)mesResponse.Descriptor.Parser.ParseFrom(response.Data);
                    for (int i = 0; i < imesRes4.TDInfo.Count; i++)
                    {
                        TenderSceneControl._instance.tenderinfo = imesRes4.TDInfo[i];
                    }
                    ProjectSettingView._instance.ProjectSettingStart(TenderSceneControl._instance.tenderinfo);
                    UIControl._instance.TenderProjectUI_Panel.SetActive(false);
                    UIControl._instance.ProjectSetting.SetActive(true);
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("请求数据失败");
                }

                break;

            case InteractiveE.Update:
                try
                {
                    UIControl._instance.ExitStart();
                    TenderWebRequest.Instance.QueryData(TenderWebRequest.Instance.url_Query, "-1", "0");
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("数据更新失败");
                }

                break;

            case InteractiveE.Tender_ZY_Query:

                try
                {
                    mesResponse = new TenderDateClass();
                    TenderDateClass ZY_Query1 = (TenderDateClass)mesResponse.Descriptor.Parser.ParseFrom(response.Data);
                    TenderDateClass ZY_Query2 = (TenderDateClass)mesResponse.Descriptor.Parser.ParseFrom(response.Data);
                    for (int i = 0; i < ZY_Query1.TDInfo.Count; i++)
                    {
                        for (int j = 0; j < ZY_Query1.TDInfo[i].TenderZY.Count; j++)
                        {
                            ZY_Query1.TDInfo[i].TenderZY[j].ID = j;
                            ZY_Query2.TDInfo[i].TenderZY[j].ID = j;
                            UIControl._instance.Tenderzy = ZY_Query1.TDInfo[i];
                            UIControl._instance.TenderTempzy = ZY_Query2.TDInfo[i];
                            tenderinfo = ZY_Query1.TDInfo[i];
                        }
                    }
                    //UIControl._instance.QuaryResources("-1", "");
                    UIControl._instance.QuaryResources((UIControl._instance.JJleibie.value - 1).ToString(), UIControl._instance.JJNmae.text);
                    UIControl._instance.ShowTenderZY_Before();
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("请求资源数据失败");
                }

                break;

            case InteractiveE.Tender_ZY_PostDate:
                TenderWebRequest.Instance.QueryDataZY(TenderWebRequest.Instance.url_ZY_Query, UIControl._instance.TenderGUID);
                UIControl._instance.TishiText("保存成功");
                //Debug.Log("提交"); 
                break;

            case InteractiveE.GuHua:

                //Debug.Log("已固话");
                gh.GuaHuaCallBack();
                break;

            case InteractiveE.MoNI_url_Modity:

                try
                {
                    mesResponse = new TenderDateClass();
                    TenderDateClass MoNIModity = (TenderDateClass)mesResponse.Descriptor.Parser.ParseFrom(response.Data);
                    TenderSceneControl._instance.TDC = MoNIModity;
                    UIControl._instance.ShowTenderMoNi_Before();
                    // UIControl._instance.chaxunText_moni.text = "";
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("请求数据失败");
                }

                break;

            //标段模拟查询
            case InteractiveE.MoNI_url_Query:

                try
                {
                    mesResponse = new TenderDateClass();
                    TenderDateClass MoNIQuery = (TenderDateClass)mesResponse.Descriptor.Parser.ParseFrom(response.Data);

                    for (int i = 0; i < MoNIQuery.TDInfo.Count; i++)
                    {
                        TenderSceneControl._instance.tenderinfo = MoNIQuery.TDInfo[i];
                        if (TenderSceneControl._instance.tenderinfo.TenderZY == null)
                        {

                            //获取一份资源列表
                            for (int j = 0; j < TenderSceneControl._instance.tenderinfo.TenderZY.Count; j++)
                            {
                                TenderSceneControl._instance.tenderinfo.TenderZY[j] = tenderinfo.TenderZY[j];
                            }
                        }

                        //进入下一个UI面板
                        UIControl._instance.TenderMoNiUI_Panel.SetActive(false);
                        UIControl._instance.ShiGongFangAnCheHua_Panel.SetActive(true);

                        //初始化状态
                        Resources.UnloadUnusedAssets();
                        Application.targetFrameRate = 50;
                        Time.timeScale = 1;
                        UIControl._instance.IsPlayBack = true;
                        ReTenderPlay._instance.ZhenSum = 0;
                        ReTenderPlay._instance.Hd.Ht.Clear();
                        UIControl._instance.isToogleType = false;
                        UIControl._instance.isAllEnd = false;
                        UIControl._instance.StartYLTime = DateTime.Now;
                        UIControl._instance.isAdd = true;

                        TenderMoNi._instance.dixingliulan();
                        TenderMoNi._instance.RYPeiZhi();
                        TenderMoNi._instance.JJPeiZhi();
                    }
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("请求数据失败");
                }
                break;

            //请求回放信息
            case InteractiveE.PB_Query:

                try
                {
                    mesResponse = new TenderPlayBack();
                    TenderPlayBack PB_Query = (TenderPlayBack)mesResponse.Descriptor.Parser.ParseFrom(response.Data);
                    for (int i = 0; i < PB_Query.PBI.Count; i++)
                    {
                        ReTenderPlay._instance.rd = PB_Query.PBI[i].SPB.RPD;
                        TenderSceneControl._instance.tenderinfo = PB_Query.PBI[i].SPB.TDInfo;
                    Debug.Log("GUID="+PB_Query.PBI[i].SPB.TDInfo.GUID.ToString());
                    Debug.Log("TowerNumber="+PB_Query.PBI[i].SPB.TDInfo.TowerNumber.ToString());
                    Debug.Log("TenderTower="+PB_Query.PBI[i].SPB.TDInfo.TD.TenderTower.Count.ToString());
                    }
                    PlayBackList._instance.SL.SetActive(true);
                    ReTenderPlay._instance.CurrentmaxZhen = Time.frameCount;
                    ReTenderplayWnd._instance.speedSlider.value = 0;
                    ReTenderplayWnd._instance.positionSlider.value = 0;

                    UIControl._instance.PlayBack_Panel.SetActive(false);
                    tendermoni.DataClear();
                    ReTenderPlay._instance.flag = true;
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("请求回放数据失败");
                }

                break;


            //提交回放信息
            case InteractiveE.PB_PostDate:

                try
                {
                    UIControl._instance.YLEnd_Pane.SetActive(false);
                    ReTenderPlay._instance.Hd.Ht.Clear();
                    UIControl._instance.IsPlayBack = false;
                    ReTenderPlay._instance.flag = false;
                    UIControl._instance.StartUI_MNYL();
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("回放数据提交失败");
                }

                break;

            case InteractiveE.PB_Modity:

                try
                {
                    PlayBackControl._instance.GCName.text = "";
                    PlayBackControl._instance.YLTime.text = "";
                    //获得数据,开始排序
                    mesResponse = new TenderPlayBack();
                    TenderPlayBack TPBQuery = (TenderPlayBack)mesResponse.Descriptor.Parser.ParseFrom(response.Data);

                    PlayBackControl._instance.TPB.PBI.Clear();
                    PlayBackControl._instance.TPB.TenderNumber = TPBQuery.TenderNumber.ToString();
                    PlayBackControl._instance.TPB.YLRecordNumber = TPBQuery.YLRecordNumber.ToString();
                    for (int i = 0; i < TPBQuery.PBI.Count; i++)
                    {
                        PlayBackControl._instance.TPB.PBI.Add(TPBQuery.PBI[i]);
                    }
                    PlayBackList._instance.rectBar.value = 0;
                    PlayBackList._instance.BarSizeChange();
                    PlayBackList._instance.updateRows();
                    PlayBackList._instance.onBarChange();
                    PlayBackControl._instance.ShowRecordInfo();
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("查询回放数据失败");
                }

                break;

            //获得新的数据,从新排版
            case InteractiveE.PB_Delect:

                try
                {
                    PlayBackControl._instance.YLRecord.SetActive(true);
                    PlayBackControl._instance.ComentariosContent.SetActive(false);
                    if (PlayBackControl._instance.GC == "")
                    {
                        PlayBackControl._instance.GC = "-1";
                    }
                    if (PlayBackControl._instance.YL == "")
                    {
                        PlayBackControl._instance.YL = "-1";
                    }
                    TenderWebRequest.Instance.QueryDataPBModify(TenderWebRequest.Instance.url_PB_Modity, PlayBackControl._instance.GC, PlayBackControl._instance.YL);
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("删除回放数据失败");
                }

                break;

            //请求当前回放的所有评论
            case InteractiveE.CTD_Query:

                try
                {
                    mesResponse = new TenderPlayBack();
                    TenderPlayBack CTD_Query = (TenderPlayBack)mesResponse.Descriptor.Parser.ParseFrom(response.Data);

                    PlayBackControl._instance.TPB.CTD.Clear();

                    for (int i = 0; i < CTD_Query.CTD.Count; i++)
                    {
                        PlayBackControl._instance.TPB.CTD.Add(CTD_Query.CTD[i]);
                    }

                    PlayBackControl._instance.YLRecord.SetActive(false);
                    PlayBackControl._instance.ComentariosContent.SetActive(true);
                    PlayBackControl._instance.ComentariosText.text = "";
                    ComentariosList._instance.rectBar.value = 0;
                    ComentariosList._instance.BarSizeChange();
                    ComentariosList._instance.updateRows();
                    ComentariosList._instance.onBarChange();
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("请求评论数据失败");
                }

                break;

            //发送评论,返回评论数据
            case InteractiveE.CTD_PostDate:
                try
                {
                    TenderWebRequest.Instance.QueryDataCTDModify(TenderWebRequest.Instance.url_CTD_Modity, PlayBackControl._instance.Guid);
                }
                catch (Exception ex)
                {
                    UIControl._instance.TishiText("发送评论数据失败");
                }

                break;
        }

    }

}

你可能感兴趣的:(TenderWebRequest)