using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Core.Mes.ClientFrameWork;
using System.Net;
using Core.Mes.IBaseInterface;
using System.Threading;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Configuration;
using System.Diagnostics;

namespace XinYuConnectionServer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();



            string url = ConfigurationManager.AppSettings["RemoteServerUrl"];

            ClientCommon._RemotingHelp.InitServerUrlList("ServerCommon", url);
            string strOut = string.Empty;
            ClientCommon._RemotingHelp.ServerUrlList = (DataSet)ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetServerList",
                    null, out strOut);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            QueryData();

            //Thread th = new Thread(new ThreadStart(QueryData));
            //th.IsBackground = true;
            //th.Start();
            //Application.DoEvents();

            //Thread th2 = new Thread(new ThreadStart(UserLogin2));
            //th2.IsBackground = true;
            //th2.Start();
            //Application.DoEvents();


        }

        int SuccessIndex = 0;
        int ErrorIndex = 0;
        #region QueryData
        private void QueryData()
        {


            AsyncExecute AsyncExecute = ClientCommon._RemotingHelp.AsyncExecute;
            try
            {
                AsyncExecute.OnComplete += new AsyncExecute.CompleteEventHandler(_RemotingHelp_OnComplete1);

                AsyncExecute.AsyncExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetTestData",
                   null);
            }
            catch (Exception ex)
            {
            }
            /*
              AsyncExecute = ClientCommon._RemotingHelp.AsyncExecute;
            try
            {
                AsyncExecute.OnComplete += new AsyncExecute.CompleteEventHandler(_RemotingHelp_OnComplete2);

                AsyncExecute.AsyncExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetTestData",
                   null);
            }
            catch (Exception ex)
            {
            }
              AsyncExecute = ClientCommon._RemotingHelp.AsyncExecute;
            try
            {
                AsyncExecute.OnComplete += new AsyncExecute.CompleteEventHandler(_RemotingHelp_OnComplete3);

                AsyncExecute.AsyncExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetTestData",
                   null);
            }
            catch (Exception ex)
            {
            }
              AsyncExecute = ClientCommon._RemotingHelp.AsyncExecute;
            try
            {
                AsyncExecute.OnComplete += new AsyncExecute.CompleteEventHandler(_RemotingHelp_OnComplete4);

                AsyncExecute.AsyncExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetTestData",
                   null);
            }
            catch (Exception ex)
            {
            }
              AsyncExecute = ClientCommon._RemotingHelp.AsyncExecute;
            try
            {
                AsyncExecute.OnComplete += new AsyncExecute.CompleteEventHandler(_RemotingHelp_OnComplete5);

                AsyncExecute.AsyncExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetTestData",
                   null);
            }
            catch (Exception ex)
            {
            }
              AsyncExecute = ClientCommon._RemotingHelp.AsyncExecute;
            try
            {
                AsyncExecute.OnComplete += new AsyncExecute.CompleteEventHandler(_RemotingHelp_OnComplete6);

                AsyncExecute.AsyncExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetTestData",
                   null);
            }
            catch (Exception ex)
            {
            }
             */
        }
        static void _RemotingHelp_OnComplete1(object returnObj, string returnMsg)
        {
            if (returnObj == null)
            {
                return;
            }
            if ((returnObj as DataSet).Tables.Count > 0)
            {
                MessageBox.Show(returnMsg + "1");
            }
            else
            {
                MessageBox.Show(returnMsg + "0");

            }
        }
        static void _RemotingHelp_OnComplete2(object returnObj, string returnMsg)
        {
            if (returnObj == null)
            {
                return;
            }
            if ((returnObj as DataSet).Tables.Count > 0)
            {
                MessageBox.Show(returnMsg + "1");
            }
            else
            {
                MessageBox.Show(returnMsg + "0");

            }
        }
        static void _RemotingHelp_OnComplete3(object returnObj, string returnMsg)
        {
            if (returnObj == null)
            {
                return;
            }
            if ((returnObj as DataSet).Tables.Count > 0)
            {
                MessageBox.Show(returnMsg + "1");
            }
            else
            {
                MessageBox.Show(returnMsg + "0");

            }
        }
        static void _RemotingHelp_OnComplete4(object returnObj, string returnMsg)
        {
            if (returnObj == null)
            {
                return;
            }
            if ((returnObj as DataSet).Tables.Count > 0)
            {
                MessageBox.Show(returnMsg + "1");
            }
            else
            {
                MessageBox.Show(returnMsg + "0");

            }
        }
        static void _RemotingHelp_OnComplete5(object returnObj, string returnMsg)
        {
            if (returnObj == null)
            {
                return;
            }
            if ((returnObj as DataSet).Tables.Count > 0)
            {
                MessageBox.Show(returnMsg + "1");
            }
            else
            {
                MessageBox.Show(returnMsg + "0");

            }
        }
        static void _RemotingHelp_OnComplete6(object returnObj, string returnMsg)
        {
            if (returnObj == null)
            {
                return;
            }
            if ((returnObj as DataSet).Tables.Count > 0)
            {
                MessageBox.Show(returnMsg + "1");
            }
            else
            {
                MessageBox.Show(returnMsg + "0");

            }
        }
        #endregion
        private void QueryData2()
        {
            AsyncExecute AsyncExecute = ClientCommon._RemotingHelp.AsyncExecute;
            try
            {
                AsyncExecute.ParentBusy = this;
                AsyncExecute.BusyLocation = new Point(160, 260);
                AsyncExecute.OnComplete += new AsyncExecute.CompleteEventHandler(_RemotingHelp_OnComplete2);

                AsyncExecute.AsyncExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetTestData",
                   null);
            }
            catch (Exception ex)
            {
            }
        }
        private void QueryData3()
        {

            try
            {
                string err = string.Empty;
                DataSet obj = (DataSet)ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetTestData",
                    null, out err);
                if (obj != null)
                {

                }



                DataSet ds = Core.Mes.ClientFrameWork.ClientCommon._RemotingHelp.ExecuteMethod("HBZY", "Core.XgMes.Server.HBZY.HotCutManager",
                    "SelectForCut", new object[] { "" }, out err) as DataSet;


            }
            catch (Exception ex)
            {
            }
        }
        delegate void dlgWriteText(string text);

        public void WriteText(string text)
        {
            this.textBox1.Text = text;
        }
        private static void UserLogin2()
        {


        }

        static void _RemotingHelp_OnComplete(object returnObj, string returnMsg)
        {
            MessageBox.Show(returnMsg + "1");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            QueryData2();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();
            //for (int i = 0; i < 20; i++)
            //{
            QueryData3();
            //}
            watch.Stop();
            this.Text = watch.ElapsedMilliseconds.ToString() + "MS";
        }
    }
}
