Example #1
0
 private IndexWindow()
 {
     InitializeComponent();
     try
     {
         //获取模糊查询所需要的参数
         getSearchParam();
         //获取螺纹检验记录
         getThreadingProcessData();
         //设置datagridView字体
         this.dataGridView1.RowsDefaultCellStyle.Font = new Font("宋体", 18, FontStyle.Bold);
         DataGridViewCellStyle style = new DataGridViewCellStyle();
         style.Font = new Font("宋体", 18, FontStyle.Bold);
         //设置datagridView列和头部样式
         foreach (DataGridViewColumn col in this.dataGridView1.Columns)
         {
             col.HeaderCell.Style = style;
         }
         this.dataGridView1.EnableHeadersVisualStyles = false;
         myForm = this;
         //开启上传视频线程
         thread = new Thread(UploadVideo);
         thread.Start();
         thread.IsBackground = true;
     }
     catch (Exception e)
     {
         //thread.Abort();
     }
     finally {
         try
         {
             //初始化录像窗体
             MainWindow.getForm();
             //开启录像机
             if (MainWindow.recordStatus == 0)
             {
                 MainWindow.getForm().btnLogin_Click(null, null);
             }
             if (MainWindow.recordStatus == 1)
             {
                 MainWindow.getForm().btnPreview_Click_1(null, null);
             }
             //初始化读码器窗体
             YYKeyenceReaderConsole.getForm();
             //连接读码器
             if (YYKeyenceReaderConsole.readerStatus == 0)
             {
                 YYKeyenceReaderConsole.codeReaderConnect();
             }
             YYKeyenceReaderConsole.getForm().Show();
             YYKeyenceReaderConsole.getForm().Hide();
             //开启读码器,此处开启无法读码
             //if (YYKeyenceReaderConsole.readerStatus == 1)
             //    YYKeyenceReaderConsole.codeReaderLon();
             //初始化螺纹检验表单窗体
             ThreadingForm.getMyForm();
         }
         catch (Exception ex) {
             MessagePrompt.Show("初始化窗体异常,异常信息:" + ex.Message);
         }
     }
 }
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    = "登录";
            }
        }