void PrepareProjsUI()
        {
            String ApplyUserPriority = CompactDB.FetchValue(App.ApplyUserPriority);

            if (int.Parse(ApplyUserPriority) > 0)
            {
                cbx_ApplyPriority.Checked = true;
            }
            else
            {
                cbx_ApplyPriority.Checked = false;
            }
            cmbx_CurrentProjectName.Items.Clear();
            cmbx_DeleteProject.Items.Clear();
            cmbx_NewProjectBaseOnWhichProject.Items.Clear();
            String[] strArr = null;
            if (!Directory.Exists("Projs"))
            {
                Directory.CreateDirectory("Projs");
            }

            strArr = Directory.GetDirectories("Projs");

            for (int i = 0; i < strArr.Length; i++)
            {
                strArr[i] = Path.GetFileNameWithoutExtension(strArr[i]);
            }
            this.cmbx_CurrentProjectName.Items.AddRange(strArr);
            cmbx_CurrentProjectName.Text = Path.GetFileNameWithoutExtension(CompactDB.FetchValue("Current_Project"));
            cmbx_DeleteProject.Items.AddRange(strArr);
            cmbx_NewProjectBaseOnWhichProject.Items.AddRange(strArr);
            cmbx_NewProjectBaseOnWhichProject.Text = cmbx_CurrentProjectName.Text;
        }
        protected override void prepareCtrls()
        {
            base.prepareCtrls();
            InitializeComponent();
            CheckProjectFolder();
            DspWndLayoutManager = new dotNetLab.Vision.DspWndLayout();
            cc :;
            String str = CompactDB.FetchValue("AppName");

            if (str == null)
            {
                CompactDB.Write("AppName", "视觉检测应用");
                goto cc;
            }
            this.Text = str;
            if (-99999 == CompactDB.FetchIntValue("DisplayWndNum"))
            {
                CompactDB.Write("DisplayWndNum", "1");
            }
            DspWndLayoutManager.PrepareDspWnds(typeof(MVDisplay), this.canvasPanel1, CompactDB.FetchIntValue("DisplayWndNum"));

            this.Load += (sender, e) =>
            {
                //必须使用这个方法来最大化窗体
                this.MaxWindow();
            };
            // PrepareVision();
        }
        protected override void prepareData()
        {
            base.prepareData();
            String str = CompactDB.FetchValue(App.AutoCleanTime);

            if (str == null)
            {
                CompactDB.Write(App.AutoCleanTime, "0");
            }
            String ApplyUserPriority = CompactDB.FetchValue(App.ApplyUserPriority);

            if (ApplyUserPriority == null)
            {
                CompactDB.Write(App.ApplyUserPriority, "0");
            }
            String HideMainForm = CompactDB.FetchValue(App.HideMainForm);

            if (HideMainForm == null)
            {
                CompactDB.Write(App.HideMainForm, "0");
            }

            //to do 添加通讯支持
            //factoryServer = new TCPFactoryServer();

            //factoryServer.Boot();

            //factoryServer.Route = (nWhichClient, byts) =>
            //{

            //};
        }
        public Form  ShowQuickBuildForm()
        {
            String HideMainForm = CompactDB.FetchValue(App.HideMainForm);

            if (HideMainForm == "1")
            {
                //PatternForm frm = new PatternForm();
                //frm.Owner = this;
                //frm.Text = "作业管理器";
                //JobToolEditV2 editV2 = new JobToolEditV2();
                //editV2.Subject = App.job;
                //editV2.Dock = DockStyle.Fill;
                //frm.Size = new System.Drawing.Size(editV2.Width + 20, editV2.Height + 20);

                //frm.Controls.Add(editV2);

                Form frm = AppManager.ShowFixedPage(typeof(MenuForm));


                frm.FormClosed += (sender, e) =>
                {
                    this.Close();
                };
                return(frm);
            }

            else if (HideMainForm == "2")
            {
                return(ShowJobWindow());
            }
            else
            {
                return(this);
            }
        }
 private void cbx_ApplyPriority_Click(object sender, EventArgs e)
 {
     if (cbx_ApplyPriority.Checked)
     {
         CompactDB.Write(App.ApplyUserPriority, "1");
     }
     else
     {
         CompactDB.Write(App.ApplyUserPriority, "0");
     }
 }
        protected override void prepareEvents()
        {
            base.prepareEvents();
            this.txb_NewProject.txb.KeyDown += (s, e) =>
            {
                if (e.KeyData == Keys.Enter)
                {
                    String strDirPath = String.Format("Projs\\{0}", txb_NewProject.Text.Trim());
                    Directory.CreateDirectory(strDirPath);
                    Thread.Sleep(500);
                    String [] arr = Directory.GetFiles(Path.Combine("Projs", cmbx_NewProjectBaseOnWhichProject.Text));
                    for (int i = 0; i < arr.Length; i++)
                    {
                        File.Copy(arr[i], Path.Combine(strDirPath, Path.GetFileName(arr[i])));
                    }

                    dotNetLab.Tipper.Info = "创建项目完成";
                    PrepareProjsUI();
                }
            };

            this.btn_DeleteProject.Click += (s, e) =>
            {
                if (cmbx_DeleteProject.Text == cmbx_CurrentProjectName.Text)
                {
                    dotNetLab.Tipper.Error = "不能删除当前正在运行的项目";
                    return;
                }
                else
                {
                    String[] arr = Directory.GetFiles(String.Format("Projs\\{0}", cmbx_DeleteProject.Text));
                    for (int i = 0; i < arr.Length; i++)
                    {
                        File.Delete(arr[i]);
                    }
                    Directory.Delete(String.Format("Projs\\{0}", cmbx_DeleteProject.Text));
                }
                PrepareProjsUI();
            };

            //to do 切换项目,务必重写此方法
            //! 注意务必使用ToolBlockEditV2.LoadShikii 来重新载入shikii
            cmbx_CurrentProjectName.SelectedIndexChanged += (s, e) =>
            {
                String strPath = String.Format("Projs\\{0}", cmbx_CurrentProjectName.Text);
                CompactDB.Write("Current_Project", strPath);
                // strPath =Path.Combine( Path.GetDirectoryName(Application.ExecutablePath),strPath);
                //使用作业管理器来切换项目
                App.job.Deserialize();
            };
        }
 void CheckProjectFolder()
 {
     if (!Directory.Exists(App.ProjsFolderName))
     {
         Directory.CreateDirectory(App.ProjsFolderName);
         if (!Directory.Exists(App.OriginProjectPath))
         {
             Directory.CreateDirectory(App.OriginProjectPath);
             String str = CompactDB.FetchValue(App.CurrentProject);
             if (String.IsNullOrEmpty(str) || str.Equals("0"))
             {
                 CompactDB.Write(App.CurrentProject, App.OriginProjectPath);
             }
         }
     }
 }
        private void btn_More_Click(object sender, EventArgs e)
        {
            int n = 0;

            try
            {
                String ApplyUserPriority = CompactDB.FetchValue(App.ApplyUserPriority);
                n = int.Parse(ApplyUserPriority);
            }
            catch
            {
                Tipper.Error = "检测到你可能启用了权限管理,但是可能配置不正确!";
            }
            if (n > 0)
            {
                LogInForm logIn = new LogInForm();
                logIn.ShowDialog();
                if (!logIn.bCloseWindow)
                {
                    return;
                }
            }

            foreach (Form item in Application.OpenForms)
            {
                if (item is MenuForm)
                {
                    if (item.Owner != this)
                    {
                        return;
                    }
                    if (item.WindowState == FormWindowState.Minimized)
                    {
                        item.WindowState = FormWindowState.Normal;
                    }
                    item.BringToFront();
                    return;
                }
            }
            Form frm = AppManager.ShowFixedPage(typeof(MenuForm));

            frm.Owner = this;
        }
        public void AutoSaveClearImage(HImage bmp, bool isNG)
        {
            //自动保存及清理图片
            //保存
            List <String> lst         = CompactDB.GetNameColumnValues(CompactDB.DefaultTable);
            String        picturePath = "图片";

            if (!Directory.Exists("图片"))
            {
                Directory.CreateDirectory(picturePath);
            }
            //当前图片保存到哪个位置
            String strNowPictureToGo = String.Format("图片\\{0}", DateTime.Now.ToString("yyyy-MM-dd"));

            if (!Directory.Exists(strNowPictureToGo))
            {
                Directory.CreateDirectory(strNowPictureToGo);
            }
            string strNGPictureToGo = String.Format("{0}\\NG", strNowPictureToGo);

            if (!Directory.Exists(strNGPictureToGo))
            {
                Directory.CreateDirectory(strNGPictureToGo);
            }
            string strOKPictureToGo = String.Format("{0}\\OK", strNowPictureToGo);

            if (!Directory.Exists(strOKPictureToGo))
            {
                Directory.CreateDirectory(strOKPictureToGo);
            }

            if (isNG)
            {
                bmp.Save(Path.Combine(strNGPictureToGo, DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss") + ".bmp"));
            }
            else
            {
                bmp.Save(Path.Combine(strOKPictureToGo, DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss") + ".bmp"));
            }


            int      nGapDays           = CompactDB.FetchIntValue("AutoClearTime");
            DateTime dt                 = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")).AddDays(-nGapDays);
            string   deletingFolderName = dt.ToString("yyyy-MM-dd");

            if (!Directory.Exists(Path.Combine(picturePath, deletingFolderName)))
            {
                return;
            }

            string directoryName = Path.Combine(picturePath, deletingFolderName);

            String[] strDirs_OK_NG = Directory.GetDirectories(directoryName);
            //
            for (int j = 0; j < strDirs_OK_NG.Length; j++)
            {
                String[] strFiles = Directory.GetFiles(strDirs_OK_NG[j]);
                for (int i = 0; i < strFiles.Length; i++)
                {
                    File.Delete(strFiles[j]);
                }
            }
            Directory.Delete(directoryName);
        }