/// <summary>
        /// 根据雷达信息查询窗体,找到则在TabPage页中加载窗体对象,没有雷达信息则显示默认窗体
        /// </summary>
        /// <param name="radar">雷达信息</param>
        /// <param name="form">没有雷达信息为空时显示的窗体</param>
        private void ShowForm(Radar radar, Form form)
        {
            if (this.tabControl_Main.InvokeRequired)
            {
                ShowFormHandler handler = new ShowFormHandler(this.ShowForm);
                this.Invoke(handler, radar);
                return;
            }

            //假如雷达信息与窗体对象均为空,不作处理
            if (radar == null && form == null)
            {
                MessageBox.Show("雷达信息无效,无法显示窗体", "提示消息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            //string name = radar != null ? radar.Name : form.Text;
            string name = radar != null ? radar.Name : form.Name;

            //假如Tab页已存在,选中该页面
            foreach (TabPage tabPage in this.tabControl_Main.TabPages)
            {
                //if (tabPage.Name.Equals(string.Format("{0}:{1}", radar.IpAddress, radar.Port)))
                if (tabPage.Name.Equals(name))
                {
                    this.tabControl_Main.SelectedTab = tabPage;
                    return;
                }
            }

            Form display = radar != null ? DictForms[radar] : form;

            //在TabControl中显示包含该页面的TabPage
            TabPage page = new TabPage();

            display.TopLevel        = false;                                           //不置顶
            display.Dock            = radar != null ? DockStyle.Fill : DockStyle.None; //控件停靠方式
            display.FormBorderStyle = FormBorderStyle.None;                            //页面无边框
            page.Controls.Add(display);
            page.Text = display.Text;
            //page.Name = display.Text;
            page.Name       = name;
            page.AutoScroll = true;

            this.tabControl_Main.TabPages.Add(page);
            this.tabControl_Main.SelectedTab = page;
            display.Show();
            if (display is FormDisplay)
            {
                ((FormDisplay)display).IsShown = true;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 在TabControl页集合中加载窗体对象,指定停靠方式,假如已存在名称(Name)相同的TabPage则放弃操作
        /// </summary>
        /// <param name="tabControl">需加载Form窗体的TabControl控件</param>
        /// <param name="form">需在TabPage页中加载或显示的窗体对象</param>
        /// <param name="dock">停靠方式,假如为null则不停靠</param>
        public static void ShowForm(this TabControl tabControl, Form form, DockStyle?dock)
        {
            if (tabControl == null || form == null)
            {
                return;
            }

            if (tabControl.InvokeRequired)
            {
                ShowFormHandler handler = new ShowFormHandler(tabControl.ShowForm);
                tabControl.Invoke(handler, form, dock);
                return;
            }

            //假如Tab页已存在,选中该页面
            foreach (TabPage tabPage in tabControl.TabPages)
            {
                if (tabPage.Name == form.Name)
                {
                    tabControl.SelectedTab = tabPage;
                    return;
                }
            }

            //在TabControl中显示包含该页面的TabPage
            form.TopLevel = false; //不置顶
            if (dock != null)
            {
                form.Dock = dock.Value;                  //控件停靠方式
            }
            form.FormBorderStyle = FormBorderStyle.None; //页面无边框
            TabPage page = new TabPage
            {
                Text       = form.Text,
                Name       = form.Name,
                AutoScroll = true
            };

            page.Controls.Add(form);
            tabControl.TabPages.Add(page);
            tabControl.SelectedTab = page;
            form.Show();
            //tabControl.Invoke(new MethodInvoker(delegate
            //{
            //    tabControl.TabPages.Add(page);
            //    tabControl.SelectedTab = page;
            //    form.Show();
            //}));
        }
Ejemplo n.º 3
0
        private void GetInfoFromMySql(string barcode)
        {
            if (conn == null)
            {
                return;
            }
            ShowFormHandler delShowForm = new ShowFormHandler(ShowMyDialog);

            if (barcode.Length != 18)
            {
                this.BeginInvoke(delShowForm, new Object[] { this, "条码长度不匹配!", 3000, Color.Red, Color.WhiteSmoke });
                return;
            }
            else if (!barcode.StartsWith("A"))
            {
                this.BeginInvoke(delShowForm, new Object[] { this, "条码不是A开始!", 3000, Color.Red, Color.WhiteSmoke });
                return;
            }
            string fac_code    = barcode.Substring(0, 1);
            string prc_code    = barcode.Substring(1, 2);
            string custom_code = barcode.Substring(3, 3);
            string amp_code    = barcode.Substring(6, 3);

            year = barcode.Substring(9, 2);
            week = barcode.Substring(11, 2);
            string sn = barcode.Substring(13, 5);

            SetLabelText(label_date, "生产日期:" + year.Trim() + "年," + week.Trim() + "周");
            SetLabelText(label_sn, "流水号:" + sn);

            if (barcode.Length != 18)
            {
                return;
            }
            else if (!barcode.StartsWith("A"))
            {
                return;
            }

            MySqlDataReader reader = null;
            string          str    = string.Format("SELECT fac_name,prc_name,amp_name FROM web_manager_line.hgc_barcode_rule where fac_code=\"{0}\" and prc_code=\"{1}\" and amp_code=\"{2}\"", fac_code, prc_code, amp_code);

            try {
                MySqlCommand cmd = new MySqlCommand(str, conn);
                reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    fac_name = reader.GetString(0);
                    prc_name = reader.GetString(1);
                    //custom_name = reader.GetString(2);
                    amp_name = reader.GetString(2);
                    SetLabelText(label_amp, "机种名称:" + amp_name);
                    //SetLabelText(label_custom, "客户名称:" + custom_name);
                    SetLabelText(label_type, "产品类别:" + prc_name);
                }
                else
                {
                    this.BeginInvoke(delShowForm, new Object[] { this, "未查询到此机种相关代码!", 3000, Color.Red, Color.WhiteSmoke });
                    SetLabelText(label_amp, "机种名称:");
                    //SetLabelText(label_custom, "客户名称:");
                    SetLabelText(label_type, "产品类别:");
                    SetLabelText(label_date, "生产日期:");
                    SetLabelText(label_sn, "流水号:");
                    return;
                }
            } catch (MySqlException ex) {
                Console.WriteLine("Failed to populate database list: " + ex.Message);
            } finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            //return msg;
        }
Ejemplo n.º 4
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (conn.State == ConnectionState.Closed)
            {
                Connect_DataBase();
            }
            timer2.Enabled = false;
            string path_ok_save = "";
            string path_ng_save = "";
            string path_deleted = @"\\10.28.3.18\01 测试结果\AP-Deleted";

            if (System.IO.Directory.Exists(TextBox_Path_Watch.Text))
            {
                string[] files = System.IO.Directory.GetFiles(TextBox_Path_Watch.Text);
                for (int i = 0; i < files.Length; i++)
                {
                    //仅返回路径字符串的文件名及后缀
                    string fileName = System.IO.Path.GetFileName(files[i]);
                    //string destFile = System.IO.Path.Combine(targetPath, fileName);
                    Console.WriteLine(fileName);
                    string barcode = fileName.Substring(0, fileName.Length - 4);
                    barcode = barcode.ToUpper();
                    if (!CheckBox_Local.Checked)
                    {
                        if (barcode.Length != 18)
                        {
                            try
                            {
                                //File.Delete(Path.Combine(path_watch, fileName));
                                File.Move(Path.Combine(path_watch, fileName), Path.Combine(path_deleted, barcode) + "---长度不够.pdf");
                            }
                            catch (Exception)
                            {
                                ;
                            }
                            continue;
                        }
                        else if (!barcode.StartsWith("A"))
                        {
                            try
                            {
                                //File.Delete(Path.Combine(path_watch, fileName));
                                File.Move(Path.Combine(path_watch, fileName), Path.Combine(path_deleted, barcode) + "---不是A开头.pdf");
                            }
                            catch (Exception)
                            {
                                ;
                            }
                            continue;
                        }
                        SetLabelText(textBox_BarCode, barcode);

                        GetInfoFromMySql(textBox_BarCode.Text);
                        path_ok_save = path_ok + @"\" + amp_name + @"\" + year + "年" + week + "周";
                        path_ng_save = path_ng + @"\" + amp_name + @"\" + year + "年" + week + "周";
                        SetLabelText(TextBox_Path_Ok, path_ok_save);
                        SetLabelText(TextBox_Path_Ng, path_ng_save);
                    }
                    else
                    {
                        path_ok_save = path_ok + @"\" + amp_name + @"\" + DateTime.Now.ToLongDateString();
                        path_ng_save = path_ng + @"\" + amp_name + @"\" + DateTime.Now.ToLongDateString();
                        SetLabelText(TextBox_Path_Ok, path_ok_save);
                        SetLabelText(TextBox_Path_Ng, path_ng_save);
                    }
                    //// Create a new PDF document
                    string result = "PASSED";
                    ////Thread.Sleep(2000);
                    //// WaitForFile(e.FullPath);
                    ////FileStream fs = new FileStream(e.FullPath, FileMode.Open, FileAccess.Write, FileShare.Read);
                    PdfDocument doc = new PdfDocument();
                    try {
                        doc.LoadFromFile(Path.Combine(path_watch, fileName));
                        StringBuilder buffer = new StringBuilder();
                        foreach (PdfPageBase page in doc.Pages)
                        {
                            buffer.Clear();
                            string str = page.ExtractText();
                            buffer.Append(str);
                            if (str.Contains("FAILED"))
                            {
                                result = "FAILED";
                                break;
                            }
                        }
                        Console.WriteLine("识别结果:" + result);
                    } catch (Exception ee) {
                        result = "";
                        try
                        {
                            File.Move(Path.Combine(path_watch, fileName), Path.Combine(path_deleted, barcode) + "---文件加密.pdf");
                        }
                        catch (Exception x)
                        {
                            Console.WriteLine(x.Message);;
                        }
                        Console.WriteLine(ee.Message);
                    } finally {
                        doc.Close();
                        doc.Dispose();
                    }
                    timer2.Enabled = true;
                    //2020.06.19  修复在文件不能正常打开时,PASSED文件会被移动到FAILED文件夹中
                    if (result == "")
                    {
                        return;
                    }
                    if (Directory.Exists(path_ok_save) == false)
                    {
                        Directory.CreateDirectory(path_ok_save);
                    }
                    if (Directory.Exists(path_ng_save) == false)
                    {
                        Directory.CreateDirectory(path_ng_save);
                    }
                    // Model.ShowMsg show = new Model.ShowMsg();
                    //myDialog.Owner = this;
                    if (result == "PASSED")
                    {
                        //if (CheckBox_Local.Checked) {
                        //    File.Copy(e.FullPath, Path.Combine(result_path, e.Name),true);
                        //} else {
                        //   // UpLoadFile(e.FullPath, result_path, "sonavox", "123456");

                        //}
                        //WaitForFile(e.FullPath);
                        // 确认目标文件不存在

                        // 移动
                        try {
                            string _path_ok = Path.Combine(path_ok_save, fileName);
                            if (File.Exists(_path_ok))
                            {
                                File.Delete(_path_ok);
                            }
                            FileInfo fi = new FileInfo(Path.Combine(path_watch, fileName));

                            Console.WriteLine(fi.CreationTime.ToString());
                            File.Copy(Path.Combine(path_watch, fileName), Path.Combine(path_ok_save, fileName.ToUpper()), true);
                            File.Delete(Path.Combine(path_watch, fileName));
                            //File.Move(Path.Combine(path_watch, fileName), Path.Combine(path_ok_save, fileName));
                            //Console.WriteLine(Path.Combine(path_watch, fileName));
                            //Console.WriteLine(Path.Combine(path_ok_save, fileName));
                            if (GetProductDataFromMySql(barcode))
                            {
                                UpdateProductDataToMySql("PASSED", string.Format("{0:yyyy-MM-dd HH:mm:ss}", fi.CreationTime), barcode);
                            }
                            Console.WriteLine("PASSED-文件移动完成");
                            count_ok++;
                            SetLabelText(Label_Count_OK, count_ok + "");
                        } catch (Exception) {
                            timer2.Enabled = true;
                        } finally {
                            timer2.Enabled = true;
                        }

                        //File.Copy(e.FullPath, Path.Combine(result_path, e.Name), true);
                        ShowFormHandler delShowForm = new ShowFormHandler(ShowMyDialog);
                        this.BeginInvoke(delShowForm, new Object[] { this, "识别结果---PASSED!", 2000, Color.Green, Color.White });
                        //show.ShowMessageBoxTimeout("识别结果---PASSED!", "提示", MessageBoxButtons.OK, 2000); //单位毫秒
                    }
                    else if (result == "FAILED")
                    {
                        //WaitForFile(e.FullPath);

                        try {
                            string _path_ng = Path.Combine(path_ng_save, fileName);
                            if (File.Exists(_path_ng))
                            {
                                File.Delete(_path_ng);
                            }
                            File.Copy(Path.Combine(path_watch, fileName), Path.Combine(path_ng_save, fileName.ToUpper()), true);
                            File.Delete(Path.Combine(path_watch, fileName));
                            //File.Move(Path.Combine(path_watch, fileName), Path.Combine(path_ng_save, fileName));
                            Console.WriteLine("FAILED-文件移动完成");
                            count_ng++;
                            SetLabelText(Label_Count_NG, count_ng + "");
                        } catch (Exception) {
                            timer2.Enabled = true;
                        } finally {
                            timer2.Enabled = true;
                        }


                        //File.Copy(e.FullPath, Path.Combine(result_path_ng, e.Name), true);
                        ShowFormHandler delShowForm = new ShowFormHandler(ShowMyDialog);
                        this.BeginInvoke(delShowForm, new Object[] { this, "识别结果---FAILED!", 2000, Color.Red, Color.White });
                        //show.ShowMessageBoxTimeout("识别结果---FAILED!", "提示", MessageBoxButtons.OK, 2000); //单位毫秒
                        //UpLoadFile(e.FullPath, result_path, "sonavox", "123456");
                    }
                }
            }
            label_last_time.Text = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
            timer2.Enabled       = true;
        }