using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;
namespace wcfControlMonitorClient
{
    /// <summary>
    /// Creator:Richard.liu
    /// ºÚÏ»×Óά»¤
    /// </summary>
    public partial class FrmTransportTimeout : Form
    {
        private static FrmTransportTimeout _formInstance;

        public static FrmTransportTimeout FormInstance
        {
            get
            {
                if (_formInstance == null)
                {
                    _formInstance = new FrmTransportTimeout();
                }
                return _formInstance;
            }
            set { _formInstance = value; }
        }
        public FrmTransportTimeout()
        {
            InitializeComponent();
            _formInstance = this;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int a = 0;
                if (int.TryParse(this.tbWaitTime.Text.Trim(),out a) == false)
                {
                    MessageBox.Show("ÊäËͳ¬Ê±×î´óÔÊÐíʱ¼ä±ØÐëΪÊý×Ö£¡", "²Ù×÷Ìáʾ£º", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbWaitTime.Focus();
                    return;
                }
                int ts = 0;
                int.TryParse(tbWaitTime.Text.Trim(), out ts);
                if (ts < 1)
                {
                    MessageBox.Show("ÊäËͳ¬Ê±×î´óÔÊÐíʱ¼ä±ØÐëΪ´óÓÚ1µÄÕûÐÍÊý×Ö£¡", "²Ù×÷Ìáʾ£º", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.tbWaitTime.Focus();
                    return;
                }
                string errtext=string.Empty;
                CStaticClass.WcfControl.BeginSetConveyorTimeOutTime(Convert.ToInt32(this.tbWaitTime.Text), new AsyncCallback(CallbackSetConveyorTimeOutTime),null );
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        void CallbackSetConveyorTimeOutTime(IAsyncResult ar)
        {
            string errtext=string.Empty;
            if (CStaticClass.WcfControl.EndSetConveyorTimeOutTime(out errtext, ar) == false)
            {
                MessageBox.Show(errtext, "²Ù×÷Ìáʾ£º", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                CStaticClass.TransportTimeout = this.tbWaitTime.Text;
                MessageBox.Show("±£´æ³É¹¦£¡", "²Ù×÷Ìáʾ£º", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
            }
        }
        private void FrmDarkCasket_Load(object sender, EventArgs e)
        {
            string errtext=string.Empty;
            this.tbWaitTime.Text = CStaticClass.WcfControl.GetConveyorTimeOutTime(out errtext).ToString();
        }

        private void FrmTransportTimeout_FormClosing(object sender, FormClosingEventArgs e)
        {
            _formInstance = null;
        }
    }
}