Esempio n. 1
0
        public frmWelcome()
            : base("embedded://www/index.html")             //设定启示页面,scheme是embedded就是我们在Main里注册的当前程序集资源
        {
            InitializeComponent();

            //在js中注册一个方法来打开About窗口
            GlobalObject.AddFunction("showAboutForm").Execute += (sender, args) =>
            {
                ShowAboutNanUI();
                //ShowAboutWindow();
            };

            GlobalObject.AddFunction("showDevTools").Execute += (sender, args) =>
            {
                ShowDevTools();
            };


            //网页加载完成时触发事件
            LoadHandler.OnLoadEnd += (sender, args) =>
            {
                //判断下触发的事件是不是主框架的
                if (args.Frame.IsMain)
                {
                    //执行JS,将当前的CEF运行版本等信息通过JS加载到网页上
                    var js = $"$client.setRuntimeInfo({{ api: ['{CfxRuntime.ApiHash(0)}', '{CfxRuntime.ApiHash(1)}'], cef:'{CfxRuntime.GetCefVersion()}', chrome:'{CfxRuntime.GetChromeVersion()}',os:'{CfxRuntime.PlatformOS}', arch:'{CfxRuntime.PlatformArch}'}});";
                    ExecuteJavascript(js);
                }
            };
        }
Esempio n. 2
0
        public Form1()
            : base("http://res.app.local/index.html")
        {
            InitializeComponent();

            //FormBorderStyle = FormBorderStyle.FixedDialog;


            GlobalObject.AddFunction("showDialog").Execute += (_, args) =>
            {
                this.RequireUIThread(() =>
                {
                    var form2 = new Form2();
                    form2.ShowDialog(this);
                });
            };

            GlobalObject.AddFunction("showWindow").Execute += (_, args) =>
            {
                this.RequireUIThread(() =>
                {
                    var form2 = new Form2();
                    form2.Show(this);
                });
            };

            GlobalObject.AddFunction("showDevTools").Execute += (func, args) => Chromium.ShowDevTools();
        }
Esempio n. 3
0
        public Form1()
            : base("http://res.app.local/asserts/index.html")
        {
            InitializeComponent();

            LoadHandler.OnLoadStart += LoadHandler_OnLoadStart;


            GlobalObject.AddFunction("showDialog").Execute += (_, args) =>
            {
                this.RequireUIThread(() =>
                {
                    var form2 = new Form2();
                    form2.ShowDialog(this);
                });
            };

            GlobalObject.AddFunction("showWindow").Execute += (_, args) =>
            {
                this.RequireUIThread(() =>
                {
                    var form2 = new Form2();
                    form2.Show(this);
                });
            };


            //this.Left = 0;
            //this.Top = 0;



            //form2.Left = Screen.AllScreens[1].WorkingArea.Left;
            //form2.Top = Screen.AllScreens[1].WorkingArea.Top;
        }
Esempio n. 4
0
        public Form1()
            : base("http://res.app.local/index.html")
        {
            InitializeComponent();

            GlobalObject.AddFunction("showDevTools").Execute += (func, args) => Chromium.ShowDevTools();
        }
Esempio n. 5
0
        public Form1(Package <AppState> store)
            : base(store, Config.BaseUrl + "index.html")//"http://res.app.local/index.html"
        {
            InitializeComponent();

            this.ConfigChartAction();
            this.ConfigCommunityActions();

            GlobalObject.AddFunction("showDialog").Execute += (_, args) =>
            {
                this.RequireUIThread(() =>
                {
                    var form2 = new Form2(store);
                    form2.ShowDialog(this);
                });
            };

            GlobalObject.AddFunction("showDevTools").Execute += (func, args) => Chromium.ShowDevTools();

            LoadHandler.OnLoadEnd += LoadHandler_OnLoadEnd;

            store.Subscribe((subscription, action) =>
            {
                var state  = store.GetState();
                string cmd = string.Format("app.updateData({0})", JsonConvert.SerializeObject(state));
                ExecuteJavascript(cmd);
            });

            Store.Dispatch(new loadCommunityList());
        }
Esempio n. 6
0
        public Form1() : base("about:blank")
        {
            InitializeComponent();

            Text        = "Hotel Management System";
            WindowState = FormWindowState.Maximized;
            GlobalObject.AddFunction("showDevTools").Execute   += (func, args) => Chromium.ShowDevTools();
            GlobalObject.AddFunction("windowMinimize").Execute += (func, args) => WindowState = FormWindowState.Minimized;
            GlobalObject.AddFunction("windowMaximize").Execute += (func, args) => WindowState = (WindowState == FormWindowState.Normal) ? FormWindowState.Maximized : FormWindowState.Normal;
            GlobalObject.AddFunction("windowClose").Execute    += CloseExecute;
            Chromium.BrowserCreated += Chromium_BrowserCreated;
            RegisterObject();
        }
Esempio n. 7
0
        public MainForm() : base("embedded://www/index3.html")
        {
            InitializeComponent();
            //在js中注册一个方法来打开About窗口
            GlobalObject.AddFunction("showAboutForm").Execute += (sender, args) =>
            {
                ShowAboutNanUI();
                //ShowAboutWindow();
            };

            GlobalObject.AddFunction("showDevTools").Execute += (sender, args) =>
            {
                ShowDevTools();
            };

            LifeSpanHandler.OnBeforePopup += (sender, args) =>
            {
            };

            LifeSpanHandler.OnAfterCreated += (sender, args) =>
            {
            };


            //网页加载完成时触发事件
            LoadHandler.OnLoadEnd += (sender, args) =>
            {
                //判断下触发的事件是不是主框架的
                if (args.Frame.IsMain)
                {
                    //执行JS,将当前的CEF运行版本等信息通过JS加载到网页上
                    //var js = string.Format("$client.setRuntimeInfo({{ api: ['{CfxRuntime.ApiHash(0)}', '{CfxRuntime.ApiHash(1)}'], cef:'{CfxRuntime.GetCefVersion()}', chrome:'{CfxRuntime.GetChromeVersion()}',os:'{CfxRuntime.PlatformOS}', arch:'{CfxRuntime.PlatformArch}'}});");

                    var    js = string.Format("alert('{0}')", CfxRuntime.ApiHash(1));
                    object a  = CfxRuntime.GetCefVersion();
                    //ExecuteJavascript(js);



                    this.UpdateUI(() =>
                    {
                        //显示字窗体的过程,不解释
                        SubForm su = new SubForm();
                        su.Show();
                    });
                }
            };
        }
Esempio n. 8
0
 private void RegisterJSFunc()
 {
     if (uiProxy == null)
     {
         uiProxy = new UiProxy();
         GlobalObject.AddFunction("OnNewFile").Execute        += uiProxy.OnNewFile;
         GlobalObject.AddFunction("OnOpenFile").Execute       += uiProxy.OnOpenFile;
         GlobalObject.AddFunction("OnSaveFile").Execute       += uiProxy.OnSaveFile;
         GlobalObject.AddFunction("OnRun").Execute            += uiProxy.OnRun;
         GlobalObject.AddFunction("OnPause").Execute          += uiProxy.OnPause;
         GlobalObject.AddFunction("OnStop").Execute           += uiProxy.OnStop;
         GlobalObject.AddFunction("OnMouseHover").Execute     += uiProxy.OnMouseMove;
         GlobalObject.AddFunction("BeginAddFlowItem").Execute += uiProxy.OnBeginAddFlowItem;
         GlobalObject.AddFunction("EndAddFlowItem").Execute   += uiProxy.OnEndAddFlowItem;
         GlobalObject.AddFunction("GetFlowPicSize").Execute   += uiProxy.GetFlowPicSize;
         GlobalObject.AddFunction("GetLiveMaxWidth").Execute  += uiProxy.GetLiveMaxWidth;
         GlobalObject.AddFunction("OnRemoveProcess").Execute  += uiProxy.OnRemoveProcess;
     }
 }
Esempio n. 9
0
        public Main()
            : base("http://res.app.local/main.html")
        {
            InitializeComponent();
            GetMain = this;

            this.Load += OnLoadForm;

            LoadHandler.OnLoadEnd += (sender, args) =>
            {
                PortMonitor.StartMonitor();
            };

            GlobalObject.AddFunction("ShowDevTools").Execute += (sender, args) =>
            {
                Chromium.ShowDevTools();
            };

            GlobalObject.AddFunction("HostOpenAndCloseSerialDevice").Execute += (sender, args) =>
            {
                try
                {
                    var          callback   = args.Arguments.FirstOrDefault(e => e.IsFunction);
                    string       deviceName = args.Arguments[0].StringValue;
                    SerialPortEx serial     = SelectSerialDevice(deviceName);
                    string       portName   = args.Arguments[1].StringValue;
                    if (!serial.IsOpen)
                    {
                        SerialPortManager.OpenSerialPort(serial, portName);
                    }
                    else
                    {
                        SerialPortManager.CloseSerialPort(serial);
                    }
                    string json = Utility.JsonSerializerBySingleData(serial);
                    callback.ExecuteFunction(null, new Chromium.Remote.CfrV8Value[] { json });
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                    ViewCallFunction.ViewAlert(ex.Message);
                }
            };

            GlobalObject.AddFunction("HostAutoConnectionDeviced").Execute += (sender, args) =>
            {
                try
                {
                    bool autoConnection = args.Arguments[0].BoolValue;
                    if (autoConnection)
                    {
                        ConnectionSerialDevice.Start();
                    }
                    else
                    {
                        ConnectionSerialDevice.Stop();
                    }
                    ConnectionSerialDevice.AutoConnectioinDevice = autoConnection;
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                    ViewCallFunction.ViewAlert(ex.Message);
                }
            };

            CardManagerEvh.InitEvent();
            PwdManagerEvh.InitEvent();
            ConfigureManagerEvh.InitEvent();
            WirelessManagerEvh.InitEvent();
            UserManagerEvh.InitEvent();
        }
Esempio n. 10
0
        public Mian()
            : base(AnimationType.Center, "wwwroot/Pages/Main2.html", false)
        {
            InitializeComponent();
            base.ContextMenuHandler.OnBeforeContextMenu += (sender, e_) => e_.Model.Clear();  //禁用右键
            this.MinimumSize     = new Size(1000, 700);
            this.MaximumSize     = new Size(1000, 700);
            this.FormBorderStyle = FormBorderStyle.FixedToolWindow;

            //注册显示注册界面事件到JS
            base.GlobalObject.AddFunction("showRegistered").Execute += (_, args) =>
            {
                this.RequireUIThread(() =>
                {
                });
            };

            //注册显示主界    面窗体到JS
            base.GlobalObject.AddFunction("viewMain").Execute += (_, args) =>
            {
                this.RequireUIThread(() =>
                {
                    //Application.Run(new Main());
                    //this.Close();
                    //this.Dispose();
                    //this.DialogResult = DialogResult.OK;
                    //new Main(this).Show();
                    //this.Close();
                });
            };
            var FuncExport = GlobalObject.AddFunction("Func_Export");

            FuncExport.Execute += (func, args) =>
            {
                var stringArgument = args.Arguments.FirstOrDefault(p => p.IsString);
                if (stringArgument != null)
                {
                    var str = stringArgument.StringValue;
                    str = str.Replace("ind", "序号");
                    str = str.Replace("one", "数字");
                    str = str.Replace("two", "排序");
                    str = str.Replace("three", "正负");
                    ExportList tables = Newtonsoft.Json.JsonConvert.DeserializeObject <ExportList>(str);

                    //导出五个表
                    var saveDir = System.Environment.CurrentDirectory;

                    string currDate = DateTime.Now.ToString("yyyy-MM-dd");
                    string currTime = DateTime.Now.ToString("HH-mm");
                    if (!Directory.Exists(saveDir + "\\数据表格"))
                    {
                        Directory.CreateDirectory(saveDir + "\\数据表格");
                    }
                    if (!Directory.Exists(saveDir + "\\数据表格\\" + currDate))
                    {
                        Directory.CreateDirectory(saveDir + "\\数据表格\\" + currDate);
                    }
                    try
                    {
                        var path = saveDir + "\\数据表格\\" + currDate;
                        //if (tables.table1 != null && tables.table1.Rows.Count > 0) FileHelper.ExportExcel(path + "\\千位" + currTime + "正比率" + GetPrecent(tables.table1) + ".xls", tables.table1, "");
                        //if (tables.table2 != null && tables.table2.Rows.Count > 0) FileHelper.ExportExcel(path + "\\百位" + currTime + "正比率" + GetPrecent(tables.table2) + ".xls", tables.table2, "");
                        //if (tables.table3 != null && tables.table3.Rows.Count > 0) FileHelper.ExportExcel(path + "\\十位" + currTime + "正比率" + GetPrecent(tables.table3) + ".xls", tables.table3, "");
                        //if (tables.table4 != null && tables.table4.Rows.Count > 0) FileHelper.ExportExcel(path + "\\个位" + currTime + "正比率" + GetPrecent(tables.table4) + ".xls", tables.table4, "");
                        //if (tables.table5 != null && tables.table5.Rows.Count > 0) FileHelper.ExportExcel(path + "\\球五" + currTime + "正比率" + GetPrecent(tables.table5) + ".xls", tables.table5, "");
                        var resultStr = CfrV8Value.CreateString(Newtonsoft.Json.JsonConvert.SerializeObject(true));
                        args.SetReturnValue(resultStr);
                    }
                    catch {
                        var resultStr = CfrV8Value.CreateString(Newtonsoft.Json.JsonConvert.SerializeObject(false));
                        args.SetReturnValue(resultStr);
                    }
                }
            };

            //注册最小化事件到JS
            base.GlobalObject.AddFunction("minForm").Execute += (_, args) => this.RequireUIThread(() => this.WindowState = FormWindowState.Minimized);

            //注册最大化事件到JS
            base.GlobalObject.AddFunction("maxForm").Execute += (_, args) => this.RequireUIThread(() => this.WindowState = FormWindowState.Maximized);

            //注册默认大小事件到JS
            base.GlobalObject.AddFunction("normalForm").Execute += (_, args) => this.RequireUIThread(() => this.WindowState = FormWindowState.Normal);

            //注册关闭窗体事件到JS
            base.GlobalObject.AddFunction("closeForm").Execute += (_, args) =>
            {
                this.RequireUIThread(() =>
                {
                    this.Close();
                    this.Dispose();
                    Application.Exit();
                });
            };
            this.Visible = true;

            //#if DEBUG
            //            base.LoadHandler.OnLoadStart += (sender, e) =>
            //            {
            //                base.Chromium.ShowDevTools();
            //            };
            //#endif
        }
Esempio n. 11
0
        public Main()
            : base("http://my.resource.local/pages/Index.html")
        {
            InitializeComponent();
            this.MinimumSize = new Size(1100, 690);
            //this.MaximumSize = new Size(1000, 690);
            this.StartPosition = FormStartPosition.CenterParent;
            GlobalObject.AddFunction("exit").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    Application.Exit();
                    GC.Collect();
                });
            };

            GlobalObject.AddFunction("toGithub").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    Process.Start("https://github.com/sunkaixuan/sqlsugar/");
                });
            };

            GlobalObject.AddFunction("toHome").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    Process.Start("http://www.codeisbug.com/");
                });
            };

            GlobalObject.AddFunction("toWord").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    Process.Start("http://www.codeisbug.com/Doc/8");
                });
            };

            GlobalObject.AddFunction("showCreateEntity").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    CreateEntity.ShowWindow();
                });
            };

            GlobalObject.AddFunction("showDBMove").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    DBMove.ShowWindow();
                });
            };

            var qq       = base.GlobalObject.AddObject("qq");
            var addedQun = qq.AddFunction("addedQun");

            addedQun.Execute += (func, args) =>
            {
                var url = ((args.Arguments.FirstOrDefault(p => p.IsString)?.StringValue) ?? string.Empty).Trim();
                if (!string.IsNullOrEmpty(url))
                {
                    Process.Start(url);
                }
            };

            base.LoadHandler.OnLoadStart += LoadHandler_OnLoadStart;
        }
Esempio n. 12
0
        public Form1()
            : base("http://res.app.local/www/index.html")
        {
            InitializeComponent();

            LoadHandler.OnLoadEnd += LoadHandler_OnLoadEnd;

            //register the "my" object
            var myObject = GlobalObject.AddObject("my");

            //add property "name" to my, you should implemnt the getter/setter of name property by using PropertyGet/PropertySet events.
            var nameProp = myObject.AddDynamicProperty("name");

            nameProp.PropertyGet += (prop, args) =>
            {
                // getter - if js code "my.name" executes, it'll get the string "NanUI".
                args.Retval = CfrV8Value.CreateString("NanUI");
                args.SetReturnValue(true);
            };
            nameProp.PropertySet += (prop, args) =>
            {
                // setter's value from js context, here we do nothing, so it will store or igrone by your mind.
                var value = args.Value;
                args.SetReturnValue(true);
            };


            //add a function showCSharpMessageBox
            var showMessageBoxFunc = myObject.AddFunction("showCSharpMessageBox");

            showMessageBoxFunc.Execute += (func, args) =>
            {
                //it will be raised by js code "my.showCSharpMessageBox(`some text`)" executed.
                //get the first string argument in Arguments, it pass by js function.
                var stringArgument = args.Arguments.FirstOrDefault(p => p.IsString);

                if (stringArgument != null)
                {
                    MessageBox.Show(this, stringArgument.StringValue, "C# Messagebox", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            };

            //add a function getArrayFromCSharp, this function has an argument, it will combind C# string array with js array and return to js context.
            var friends = new string[] { "Mr.JSON", "Mr.Lee", "Mr.BONG" };

            var getArrayFromCSFunc = myObject.AddFunction("getArrayFromCSharp");

            getArrayFromCSFunc.Execute += (func, args) =>
            {
                var jsArray = args.Arguments.FirstOrDefault(p => p.IsArray);



                if (jsArray == null)
                {
                    jsArray = CfrV8Value.CreateArray(friends.Length);
                    for (int i = 0; i < friends.Length; i++)
                    {
                        jsArray.SetValue(i, CfrV8Value.CreateString(friends[i]));
                    }
                }
                else
                {
                    var newArray = CfrV8Value.CreateArray(jsArray.ArrayLength + friends.Length);

                    for (int i = 0; i < jsArray.ArrayLength; i++)
                    {
                        newArray.SetValue(i, jsArray.GetValue(i));
                    }

                    var jsArrayLength = jsArray.ArrayLength;

                    for (int i = 0; i < friends.Length; i++)
                    {
                        newArray.SetValue(i + jsArrayLength, CfrV8Value.CreateString(friends[i]));
                    }


                    jsArray = newArray;
                }


                //return the array to js context

                args.SetReturnValue(jsArray);

                //in js context, use code "my.getArrayFromCSharp()" will get an array like ["Mr.JSON", "Mr.Lee", "Mr.BONG"]
            };

            //add a function getObjectFromCSharp, this function has no arguments, but it will return a Object to js context.
            var getObjectFormCSFunc = myObject.AddFunction("getObjectFromCSharp");

            getObjectFormCSFunc.Execute += (func, args) =>
            {
                //create the CfrV8Value object and the accssor of this Object.
                var jsObjectAccessor = new CfrV8Accessor();
                var jsObject         = CfrV8Value.CreateObject(jsObjectAccessor);

                //create a CfrV8Value array
                var jsArray = CfrV8Value.CreateArray(friends.Length);

                for (int i = 0; i < friends.Length; i++)
                {
                    jsArray.SetValue(i, CfrV8Value.CreateString(friends[i]));
                }

                jsObject.SetValue("libName", CfrV8Value.CreateString("NanUI"), CfxV8PropertyAttribute.ReadOnly);
                jsObject.SetValue("friends", jsArray, CfxV8PropertyAttribute.DontDelete);


                args.SetReturnValue(jsObject);

                //in js context, use code "my.getObjectFromCSharp()" will get an object like { friends:["Mr.JSON", "Mr.Lee", "Mr.BONG"], libName:"NanUI" }
            };


            //add a function with callback

            var callbackTestFunc = GlobalObject.AddFunction("callbackTest");

            callbackTestFunc.Execute += (func, args) => {
                var callback = args.Arguments.FirstOrDefault(p => p.IsFunction);
                if (callback != null)
                {
                    var callbackArgs = CfrV8Value.CreateObject(new CfrV8Accessor());
                    callbackArgs.SetValue("success", CfrV8Value.CreateBool(true), CfxV8PropertyAttribute.ReadOnly);
                    callbackArgs.SetValue("text", CfrV8Value.CreateString("Message from C#"), CfxV8PropertyAttribute.ReadOnly);

                    callback.ExecuteFunction(null, new CfrV8Value[] { callbackArgs });
                }
            };


            //add a function with async callback
            var asyncCallbackTestFunc = GlobalObject.AddFunction("asyncCallbackTest");

            asyncCallbackTestFunc.Execute += async(func, args) => {
                //save current context
                var v8Context = CfrV8Context.GetCurrentContext();
                var callback  = args.Arguments.FirstOrDefault(p => p.IsFunction);

                //simulate async methods.
                await Task.Delay(5000);

                if (callback != null)
                {
                    //get render process context
                    var rc = callback.CreateRemoteCallContext();

                    //enter render process
                    rc.Enter();

                    //create render task
                    var task = new CfrTask();
                    task.Execute += (_, taskArgs) =>
                    {
                        //enter saved context
                        v8Context.Enter();

                        //create callback argument
                        var callbackArgs = CfrV8Value.CreateObject(new CfrV8Accessor());
                        callbackArgs.SetValue("success", CfrV8Value.CreateBool(true), CfxV8PropertyAttribute.ReadOnly);
                        callbackArgs.SetValue("text", CfrV8Value.CreateString("Message from C#"), CfxV8PropertyAttribute.ReadOnly);

                        //execute callback
                        callback.ExecuteFunction(null, new CfrV8Value[] { callbackArgs });


                        v8Context.Exit();

                        //lock task from gc
                        lock (task)
                        {
                            Monitor.PulseAll(task);
                        }
                    };

                    lock (task)
                    {
                        //post task to render process
                        v8Context.TaskRunner.PostTask(task);
                    }

                    rc.Exit();

                    GC.KeepAlive(task);
                }
            };
        }
Esempio n. 13
0
        public Main()
            : base("http://res.app.local/index.html")
        {
            InitializeComponent();

            MainForm = this;

            LoadHandler.OnLoadEnd += HtmlLoadEnd;

            GlobalObject.AddFunction("ShowDevTools").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    Chromium.ShowDevTools();
                });
            };

            GlobalObject.AddFunction("ChangeSerialConnection").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    string portName = args.Arguments[0].StringValue;
                    if (SerialPortManager.Device.IsOpen)
                    {
                        SerialPortManager.Close();
                    }
                    else
                    {
                        SerialPortManager.Open(portName);
                    }
                    args.SetReturnValue(SerialPortManager.Device.IsOpen);
                });
            };

            GlobalObject.AddFunction("ChangeConnectionState").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    bool state = args.Arguments[0].BoolValue;
                    if (state)
                    {
                        ConnectionManager.Start();
                    }
                    else
                    {
                        ConnectionManager.Stop();
                    }
                });
            };

            GlobalObject.AddFunction("ReconnectDevice").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    ConnectionManager.Start();
                });
            };

            GlobalObject.AddFunction("RefreshClick").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    bool ret = false;
                    try
                    {
                        DataManager.Params.Clear();
                        string deal = PortAgreement.ReadAllCard();
                        SerialPortManager.Write(deal);
                        OverTimer.start();

                        ret = true;
                    }
                    catch (Exception ex)
                    {
                        Log4Helper.ErrorInfo(ex.Message, ex);
                        JavascriptEvent.ErrorMessage(ex.Message);
                    }
                    args.SetReturnValue(ret);
                });
            };


            GlobalObject.AddFunction("DownloadClick").Execute += (func, args) =>
            {
                int count = DataManager.Params.Where(e => e.State != "设置成功" && e.DataType == "正常").Count();
                if (count == 0)
                {
                    args.SetReturnValue(count);
                    return;
                }
                this.RequireUIThread(() =>
                {
                    string strClientNumber = args.Arguments[0].StringValue;

                    Task.Factory.StartNew(() =>
                    {
                        foreach (Param item in DataManager.Params)
                        {
                            if (item.State != "设置成功" && item.DataType == "正常")
                            {
                                string deal = PortAgreement.WriteClientNumber(item.CardNumber, strClientNumber);
                                bool ret    = SerialPortManager.Write(deal);
                                if (ret)
                                {
                                    SerialPortManager.OperationResult = OperationResults.None;
                                    for (int i = 0; i < 500; i++)
                                    {
                                        Thread.Sleep(10);
                                        if (SerialPortManager.OperationResult != OperationResults.None)
                                        {
                                            if (SerialPortManager.OperationResult == OperationResults.Success)
                                            {
                                                item.State = "设置成功";

                                                DataManager.ViewListDisplay();
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        JavascriptEvent.OperationOver();
                    });
                });
                args.SetReturnValue(-1);
            };

            GlobalObject.AddFunction("SetDeviceClient").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    string strClientNumber = args.Arguments[0].StringValue;
                    string deal            = PortAgreement.EncryptionDevice(strClientNumber);
                    bool ret = SerialPortManager.Write(deal);
                    args.SetReturnValue(ret);
                });
            };

            GlobalObject.AddFunction("SetCardNumber").Execute += (func, args) =>
            {
                this.RequireUIThread(() =>
                {
                    string strOldNumber  = args.Arguments[0].StringValue;
                    string strCardNumber = args.Arguments[1].StringValue;
                    string strType       = args.Arguments[2].StringValue;
                    string deal          = PortAgreement.WriteCardNumber(strOldNumber, strCardNumber, strType);
                    bool ret             = SerialPortManager.Write(deal);
                    if (ret)
                    {
                        if (strCardNumber != "797979" || strCardNumber != "123456")
                        {
                            ConfigManager.SetConfig("Number", strCardNumber);
                        }
                    }
                    args.SetReturnValue(ret);
                });
            };
        }