public static void UpdateTextBox(Object form, string message)
        {
            try
            {
                //目前读码器读出的数据格式一般分为两种,一种时读出的量具编号,另一种时接箍编号、炉号、批号的拼接(空格拼接)
                //如果当前读码器读出的是量具编号
                if (ThreadingForm.isMeasuringToolTabSelected)
                {
                    //判断是否是跨线程访问控件
                    if (AlphabetKeyboardForm.getForm().Textbox_display.InvokeRequired)
                    {
                        UpdateTextBoxDelegate md = new UpdateTextBoxDelegate(UpdateTextBox);
                        // AlphabetKeyboardForm.getForm().Textbox_display.Invoke(md, new object[] { (object)AlphabetKeyboardForm.getForm(), message });
                        AlphabetKeyboardForm.getForm().Textbox_display.BeginInvoke(new Action(() => { AlphabetKeyboardForm.getForm().Textbox_display.Text = message; }));
                    }
                    else
                    {
                        //设置英文输入法中输入的内容为读码器读出的内容
                        AlphabetKeyboardForm.getForm().Textbox_display.Text = message;
                    }
                }
                else
                {
                    //将读码器读出的数据以空格分隔
                    string[] strArr = Regex.Split(message, "\\s+");
                    string   argHeatNo = string.Empty, argBatchNo = string.Empty, argCoupingNo = string.Empty;
                    //如果读码器读接箍内容则读出的数据格式目前如:"12323 43434 5454 5454"
                    if (strArr.Length >= 1)
                    {
                        if (strArr.Length > 3)
                        {
                            argHeatNo    = strArr[1]; //炉号
                            argBatchNo   = strArr[2]; //批号
                            argCoupingNo = strArr[3]; //接箍编号

                            //判断是否是跨线程访问控件
                            if (ThreadingForm.getMyForm().txtCoupingNo.InvokeRequired)
                            {
                                UpdateTextBoxDelegate md = new UpdateTextBoxDelegate(UpdateTextBox);
                                //设置表单上接箍编号、炉号、批号控件内容
                                if (!string.IsNullOrWhiteSpace(argCoupingNo))
                                {
                                    ThreadingForm.getMyForm().txtCoupingNo.BeginInvoke(new Action(() => { ThreadingForm.getMyForm().txtCoupingNo.Text = argCoupingNo; }));
                                }
                                //ThreadingForm.getMyForm().txtCoupingNo.Invoke(md, new object[] { ThreadingForm.getMyForm(),  argCoupingNo });
                                if (!string.IsNullOrWhiteSpace(argHeatNo))
                                {
                                    ThreadingForm.getMyForm().txtHeatNo.BeginInvoke(new Action(() => { ThreadingForm.getMyForm().txtHeatNo.Text = argHeatNo; }));
                                }
                                //ThreadingForm.getMyForm().txtHeatNo.Invoke(md, new object[] { ThreadingForm.getMyForm(), argHeatNo });
                                if (!string.IsNullOrWhiteSpace(argBatchNo))
                                {
                                    ThreadingForm.getMyForm().txtBatchNo.BeginInvoke(new Action(() => { ThreadingForm.getMyForm().txtBatchNo.Text = argBatchNo; }));
                                }
                                //ThreadingForm.getMyForm().txtBatchNo.Invoke(md, new object[] { ThreadingForm.getMyForm(),  argBatchNo });
                            }
                            else
                            {
                                //设置表单上接箍编号、炉号、批号控件内容
                                if (!string.IsNullOrWhiteSpace(argCoupingNo))
                                {
                                    ThreadingForm.getMyForm().txtCoupingNo.Text = argCoupingNo;
                                }
                                if (!string.IsNullOrWhiteSpace(argHeatNo))
                                {
                                    ThreadingForm.getMyForm().txtHeatNo.Text = argHeatNo;
                                }
                                if (!string.IsNullOrWhiteSpace(argBatchNo))
                                {
                                    ThreadingForm.getMyForm().txtBatchNo.Text = argBatchNo;
                                }
                            }
                        }
                    }
                    else//数字键盘
                    {
                        //判断是否是跨线程访问控件
                        if (NumberKeyboardForm.getForm().Textbox_display.InvokeRequired)
                        {
                            UpdateTextBoxDelegate md = new UpdateTextBoxDelegate(UpdateTextBox);
                            NumberKeyboardForm.getForm().Textbox_display.BeginInvoke(new Action(() => { NumberKeyboardForm.getForm().Textbox_display.Text = message; }));
                            //NumberKeyboardForm.getForm().Textbox_display.Invoke(md, new object[] { (object)NumberKeyboardForm.getForm(), message });
                        }
                        else
                        {
                            //设置数值输入法中输入的内容为读码器读出的内容
                            NumberKeyboardForm.getForm().Textbox_display.Text = message;
                        }

                        //设置当前焦点所在文本框内容
                        if (ThreadingForm.fpcusTxt != null)
                        {
                            if (ThreadingForm.fpcusTxt.InvokeRequired)
                            {
                                UpdateTextBoxDelegate md = new UpdateTextBoxDelegate(UpdateTextBox);
                                ThreadingForm.fpcusTxt.BeginInvoke(new Action(() => { ThreadingForm.fpcusTxt.Text = message; }));
                                //ThreadingForm.fpcusTxt.Invoke(md, new object[] { (object)ThreadingForm.getMyForm(), message });
                            }
                            else
                            {
                                //设置英文输入法中输入的内容为读码器读出的内容
                                ThreadingForm.fpcusTxt.Text = message;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //加密当前mac地址
            string verification_code = CommonUtil.Encrypt();
            //操作工工号
            string employee_no = this.txtLoginName.Text.Trim();
            //密码
            string upwd = this.txtLoginPwd.Text.Trim();

            this.button1.Text    = "登录中...";
            this.button1.Enabled = false;
            try
            {
                this.label_msg.Text = "发送登录请求。。。";
                //封装客户端登录所传数据
                JObject json = new JObject {
                    { "employee_no", employee_no },
                    { "ppassword", upwd },
                    { "verification_code", verification_code }
                };
                ASCIIEncoding  encoding = new ASCIIEncoding();
                String         content  = "";
                byte[]         data     = encoding.GetBytes(json.ToString());
                string         url      = CommonUtil.getServerIpAndPort() + "Login/userLoginOfWinform.action";
                HttpWebRequest request  = (HttpWebRequest)HttpWebRequest.Create(url);
                request.KeepAlive     = false;
                request.Method        = "POST";
                request.ContentType   = "application/json;characterSet:UTF-8";
                request.ContentLength = data.Length;
                using (Stream sm = request.GetRequestStream())
                {
                    sm.Write(data, 0, data.Length);
                }
                this.label_msg.Text = "登录验证中。。。";
                HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
                Stream          streamResponse = response.GetResponseStream();
                using (StreamReader sr = new StreamReader(streamResponse))
                {
                    content = sr.ReadToEnd();
                }
                response.Close();
                if (content != null)
                {
                    //如果返回的数据为"{}"
                    this.label_msg.Text = "";
                    if (content.Trim().Contains("{}"))
                    {
                        this.label_msg.Text = "登录异常!";
                        MessagePrompt.Show("登录异常!");
                    }
                    else
                    {
                        //如果登录成功,返回的数据格式为{success:'True/False',msg:'',rowsData:''},rowsData存放的为当前登录用户的信息
                        JObject jobject   = JObject.Parse(content);
                        string  loginFlag = jobject["success"].ToString().Trim();
                        string  msg       = jobject["msg"].ToString().Trim();
                        if (loginFlag.Contains("True"))
                        {
                            string rowsJson = jobject["rowsData"].ToString();
                            if (rowsJson != null)
                            {
                                //登录成功返回当前登录用户的信息,将返回的json格式的信息转换成指定对象
                                this.label_msg.Text = "登录成功,初始化控件中...";
                                Person person = JsonConvert.DeserializeObject <Person>(rowsJson);
                                IndexWindow.getForm().Show();
                                NumberKeyboardForm.getForm();
                                AlphabetKeyboardForm.getForm();
                                ScanerHook.executeScanerHook();
                                this.Hide();
                            }
                            else
                            {
                                this.label_msg.Text = "系统繁忙,请稍后重试!";
                                MessagePrompt.Show("系统繁忙,请稍后重试!");
                            }
                        }
                        else
                        {
                            this.label_msg.Text = msg;
                            MessagePrompt.Show(msg);
                        }
                    }
                }
                this.button1.Enabled = true;
                this.button1.Text    = "登录";
            }
            catch (WebException ex) {
                MessagePrompt.Show("网络错误,错误信息:" + ex.Message);
                this.button1.Enabled = true;
                this.button1.Text    = "登录";
            }
            catch (Exception ec)
            {
                MessagePrompt.Show("连接服务器失败,失败原因:" + ec.Message);
                this.button1.Enabled = true;
                this.button1.Text    = "登录";
            }
        }