using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using US.Browser.IE.BLL;
using System.Reflection;

namespace US.Browser.IE
{
    [System.Runtime.InteropServices.ComVisible(true)]
    public partial class ftp : Form
    {

        private WebBrowser WB;
        private RespondWeb rwf;
        public static ftp uft;
        string json;

        #region 初始化加载ftp


        /// <summary>
        /// 
        /// </summary>
        /// <param name="json"></param>
        public static void snews(string json, WebBrowser WB, RespondWeb rf)
        {
            if (uft != null) { }
            else { uft = new ftp(json, WB, rf); }
        }

        /// <summary>
        /// ftp加载
        /// </summary>
        public ftp(string json, RespondWeb rf)
        {
            init(json); rwf = rf;
        }

        /// <summary>
        /// ftp加载
        /// </summary>
        /// <param name="json"></param>
        public ftp(string json, WebBrowser WB, RespondWeb rf)
        {
            this.WB = WB; init(json); rwf = rf;
        }

        /// <summary>
        /// 页面生成
        /// </summary>
        public void init(string json)
        {
            InitializeComponent(); ftpBinit(); this.Hide(); this.json = json;
            ftpB.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(ftpB_DocumentCompleted);
        }

        /// <summary>
        /// 加载完毕
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ftpB_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            completed(this.json); this.json = null;
        }

        /// <summary>
        /// 加载提示页面
        /// </summary>
        public void ftpBinit()
        {
            ftpB.ObjectForScripting = this; ftpB.ScriptErrorsSuppressed = true;
            this.ftpB.Url = new System.Uri(Application.StartupPath + "\\html\\ftp.html");
        }

        /// <summary>
        /// 加载成功
        /// </summary>
        /// <param name="json"></param>
        public void completed(string json)
        {
            this.ftpB.Document.InvokeScript("_setT", new object[] { json });
        }

        #endregion

        #region 窗口显示和消失

        /// <summary>
        /// 显示窗口
        /// </summary>
        public void _fs()
        {
            Size s = Screen.PrimaryScreen.WorkingArea.Size; Point WZ = new Point((Int32)(s.Width) - 5, (Int32)(s.Height - this.Height - 20));
            this.Show(); this.Location = WZ; animate(false, -this.Width - 20, this);
        }

        /// <summary>
        /// 窗口消失
        /// </summary>
        public void _fh()
        {
            animate(true, this.Width, this);
        }

        /// <summary>
        /// 动画函数
        /// </summary>
        /// <param name="e"></param>
        public static void animate(bool tf, int c, Form uf)
        {
            System.Windows.Forms.Timer _tt = new System.Windows.Forms.Timer(); int u, k = c < 0 ? -30 : 30, i = c / k, m = uf.Location.X + c;
            _tt.Tick += new EventHandler(delegate(object sender, EventArgs g)
            {
                u = i == 0 ? m : uf.Location.X + k; uf.Location = new Point(u, uf.Location.Y);
                if (i-- == 0) { _tt.Stop(); _tt.Dispose(); _tt = null; if (tf) { uf.Hide(); uf.Dispose(); } };
            });
            _tt.Interval = 10; _tt.Start();
        }

        /// <summary>
        /// 释放窗体
        /// </summary>
        public void dis()
        {
            this.Hide(); this.Dispose();
        }

        /// <summary>
        /// 窗口闪烁
        /// </summary>
        /// <param name="img"></param>
        public void xxs(string img, string tf, string ue)
        {
            try
            {
                StaticClass._twstart(img, tf, ue, WB, rwf);
                this.Dispose(); BLL.WindowHWND.freem();
            }
            catch (Exception e) { }
        }


        /// <summary>
        /// 查看内容提示
        /// </summary>
        public void cknr(string tf, string ue)
        {
            rwf.OpenLook(new object[] { tf, ue }, WB);
        }

        /// <summary>
        /// 设置id
        /// </summary>
        /// <param name="id"></param>
        public void setxx(string id)
        {
            USMain.id = id;
        }

        #endregion


    }
}
