public void InsterScannerConfig(ScannerCofigInfo sci)
        {
            string sql =string.Empty;
            if (!_helper.IsTableExist("ScannerConfig"))
            {
                sql = @"create table ScannerConfig(ScannerName varchar(0,25) not null UNIQUE,ScannerCofigInfo BLOB)";
                _helper.ExecuteNonQuery(sql);
            }
            XmlSerializer xmlSer = new XmlSerializer(typeof(ScannerCofigInfo));
            MemoryStream ms = new MemoryStream();
            xmlSer.Serialize(ms, sci);
            string xmlSci = Encoding.UTF8.GetString(ms.ToArray());

            sql = "insert into ScannerConfig(ScannerName,ScannerCofigInfo)values('" + sci.DisplayName + "','" + xmlSci + "')";
            _helper.ExecuteNonQuery(sql);
        }
 public void DeleteScannerConfig(ScannerCofigInfo sci)
 {
     string sql = string.Empty;
     if (_helper.IsTableExist("ScannerConfig"))
     {
         sql = "delete from ScannerConfig where ScannerName='"+ sci.DisplayName+"'";
         _helper.ExecuteNonQuery(sql);
     }
 }
        private void SetCustomReceiveNotifycationCallBack(CustomReceiveResult info)
        {
            if (info.IsOK != true)
            {
                if (ScannerCofigCollection != null && ScannerCofigCollection.Count == 1)
                {
                    this.SelectedScannerConfigInfo = null;
                }
                else
                {
                    this.SelectedScannerConfigInfo = ScannerCofigCollection[0];
                }
            }
            else
            {
                ScannerCofigInfo scanConfig = new ScannerCofigInfo();
                ScanBoardProperty scanBdProp = new ScanBoardProperty();
                scanBdProp.StandardLedModuleProp.DriverChipType = ChipType.Unknown;
                scanBdProp.ModCascadeType = ModuleCascadeDiretion.Unknown;
                scanBdProp.Width = info.Width;
                scanBdProp.Height = info.Height;
                scanConfig.ScanBdProp = scanBdProp;
                scanConfig.DisplayName = info.Width.ToString() + "_" + info.Height.ToString();
                scanConfig.ScanBdSizeType = ScannerSizeType.NoCustom;
                int index = -1;
                for (int i = 0; i < ScannerCofigCollection.Count; i++)
                {
                    if (ScannerCofigCollection[i].DisplayName == scanConfig.DisplayName)
                    {
                        index = i;
                        break;

                    }
                }
                if (index >= 0)
                {
                    SelectedScannerConfigInfo = ScannerCofigCollection[index];
                }
                else
                {
                    ScannerCofigCollection.Insert(ScannerCofigCollection.Count - 1, scanConfig);
                }
                SelectedScannerConfigInfo = scanConfig;
            }
        }
        private void LoadScanFileLib()
        {
            string dir = SCANCONFIGFILES_LIB_PATH;
            if (Directory.Exists(dir))
            {
                DirectoryInfo dirInfo = new DirectoryInfo(dir);
                FileInfo[] fileInfoList = dirInfo.GetFiles();

                foreach (FileInfo fileInfo in fileInfoList)
                {
                    string fileName = fileInfo.FullName;
                    _globalParams.OriginalScanFiles.Add(fileInfo.FullName);

                    ScanBoardProperty scanBdProp = new ScanBoardProperty();
                    if (CustomTransform.LoadScanProFile(fileName, ref scanBdProp))
                    {
                        ScannerCofigInfo info = new ScannerCofigInfo();
                        info.DataGroup = scanBdProp.StandardLedModuleProp.DataGroup;
                        info.DisplayName = Path.GetFileNameWithoutExtension(fileName);
                        info.ScanBdProp = scanBdProp;
                        
                        string strCascade = scanBdProp.ModCascadeType.ToString();
                        CommonStaticMethod.GetLanguageString(strCascade, strCascade, out strCascade);
                        info.StrCascadeType = strCascade;

                        string strDriverChip = scanBdProp.StandardLedModuleProp.DriverChipType.ToString();
                        CommonStaticMethod.GetLanguageString(strDriverChip, strDriverChip, out strDriverChip);
                        info.StrChipType = strDriverChip;

                        string strScanType = scanBdProp.StandardLedModuleProp.ScanType.ToString();
                        CommonStaticMethod.GetLanguageString(strScanType, strScanType, out strScanType);
                        info.StrScanType = strScanType;
                        info.ScanBdSizeType = ScannerSizeType.NoCustom;
                        _globalParams.ScannerConfigCollection.Add(info);
                    }
                }
                //ScannerCofigInfo customScannerConfigInfo = new ScannerCofigInfo();
                //customScannerConfigInfo.DisplayName = "自定义";
                //customScannerConfigInfo.ScanBdSizeType = ScannerSizeType.Custom;
                //_globalParams.ScannerConfigCollection.Add(customScannerConfigInfo);
            }
        }
        public Frm_Guide_two_VM()
        {
            if (!this.IsInDesignMode)
            {
                ProjectLocationPath = Function.GetDefaultCurrentProjectPath(_globalParams.RecentProjectPaths);
                ProjectName = Function.GetDefaultProjectName(SmartLCTViewModeBase.DefaultProjectMainName, ".xml", ProjectLocationPath);
                CmdProjectNameChanged = new RelayCommand<TextChangedEventArgs>(OnProjectNameChanged);
                CmdBrowseProjectLocation = new RelayCommand(OnBrowseProjectLocation);
                CmdCustomSizeDropDownClosed = new RelayCommand(OnCustomReceiveSize);
                CmdShowScanBoardConfigManager = new RelayCommand(OnShowScanBoardConfigManager);
                CmdCreate = new RelayCommand(OnCreate, CanCreate);
                CmdCancel = new RelayCommand(OnCancel);
                CmdArrangeScanner = new RelayCommand<string>(OnCmdArrangeScanner);
                
                SenderConfigCollection = _globalParams.SenderConfigCollection;
                if (SenderConfigCollection != null && SenderConfigCollection.Count != 0)
                {
                    SelectedSenderConfigInfo = SenderConfigCollection[0];
                }

                ScannerCofigCollection = _globalParams.ScannerConfigCollection;
                if (ScannerCofigCollection == null ||
                    ScannerCofigCollection.Count == 0)
                {
                    ScannerCofigInfo customScannerConfigInfo = new ScannerCofigInfo();
                    string strCustom = "";
                    CommonStaticMethod.GetLanguageString("自定义", "Lang_Global_Custom", out strCustom);
                    customScannerConfigInfo.DisplayName = strCustom;
                    customScannerConfigInfo.ScanBdSizeType = ScannerSizeType.Custom;
                    //ScannerCofigCollection = new ObservableCollection<ScannerCofigInfo>();
                    ScannerCofigCollection.Add(customScannerConfigInfo);
                }
                else
                {
                    bool isHaveCustom = false;
                    for (int i = 0; i < ScannerCofigCollection.Count; i++)
                    {
                        if (ScannerCofigCollection[i].ScanBdSizeType == ScannerSizeType.Custom)
                        {
                            isHaveCustom = true;
                            break;
                        }
                    }
                    if (!isHaveCustom)
                    {
                        ScannerCofigInfo customScannerConfigInfo = new ScannerCofigInfo();
                        string strCustom = "";
                        CommonStaticMethod.GetLanguageString("自定义", "Lang_Global_Custom", out strCustom);
                        customScannerConfigInfo.DisplayName = strCustom;
                        customScannerConfigInfo.ScanBdSizeType = ScannerSizeType.Custom;
                        ScannerCofigCollection.Insert(ScannerCofigCollection.Count, customScannerConfigInfo);
                    }
                }
                if (ScannerCofigCollection != null)
                {
                    if (ScannerCofigCollection.Count == 1)
                    {
                        SelectedScannerConfigInfo = null;
                    }
                    else
                    {
                        SelectedScannerConfigInfo = ScannerCofigCollection[0];
                    }
                }
                // 在此点下面插入创建对象所需的代码。
            }
        }
 private void InsertImportCfgToDB(ScannerCofigInfo scanConfig)
 {
     SQLiteAccessor sqlLite = SQLiteAccessor.Instance;
     if (!sqlLite.IsScannerNameExist(scanConfig.DisplayName))
     {
         sqlLite.InsterScannerConfig(scanConfig);
     }
 }
        private void ImportCfgFileNotifycationCallBack(ObservableCollection<DataGradItemInfo> info)
        {
            if (_saveFilePath==string.Empty)
            {
                return;
            }
            if (!Directory.Exists(_saveFilePath))
            {
                Directory.CreateDirectory(_saveFilePath);
            }
            string sourceDirName = "";
            DataGradItemInfo dataInfo = null;
            for (int i = 0; i < info.Count; i++)
            {
                DataGradItemInfo data = info[i];
                if ((data.DataHandleWay == HandleWay.Add ||
                    data.DataHandleWay == HandleWay.Replace) &&
                    data.DataHandelSatate != DataSatate.None)
                {
                    sourceDirName = Path.GetDirectoryName(data.FileName);
                    CopyDirectory(data.FileName, _saveFilePath);
                    dataInfo = new DataGradItemInfo();
                    dataInfo.IsCheckedEvent += new IsCheckedDel(OnIsCheckedChanged);
                    dataInfo.CascadeType = data.CascadeType;
                    dataInfo.ChipType = data.ChipType;
                    dataInfo.DataHandelSatate = data.DataHandelSatate;
                    dataInfo.DataHandleWay = data.DataHandleWay;
                    dataInfo.FileName = data.FileName;
                    dataInfo.SaveFilePath = data.SaveFilePath;
                    dataInfo.ScanBoardName = data.ScanBoardName;
                    dataInfo.ScanBoardSize = data.ScanBoardSize;
                    if (data.DataHandleWay == HandleWay.Add)
                    {
                        DataGradItemInfoList.Add(dataInfo);
                        _initializeFileNameList.Add(dataInfo.SaveFilePath);
                    }
                    else if (data.DataHandleWay == HandleWay.Replace)
                    {
                        int count = DataGradItemInfoList.Count;
                        int index = -1;
                        for (int m = 0; m < count; m++ )
                        {
                            if (DataGradItemInfoList[m].ScanBoardName == dataInfo.ScanBoardName)
                            {
                                index = m;
                                break;
                            }
                        }
                        DataGradItemInfoList[index] = dataInfo;
                    }

                    #region 添加到箱体库
                    string originalFile = info[i].FileName;
                    ScanBoardProperty scanBdProp = new ScanBoardProperty();

                    if (CustomTransform.LoadScanProFile(originalFile, ref scanBdProp))
                    {
                        ScannerCofigInfo scanConfig = new ScannerCofigInfo();
                        scanConfig.DataGroup = scanBdProp.StandardLedModuleProp.DataGroup;
                        scanConfig.DisplayName = Path.GetFileNameWithoutExtension(originalFile);
                        scanConfig.ScanBdProp = scanBdProp;

                        string strCascade = scanBdProp.ModCascadeType.ToString();
                        CommonStaticMethod.GetLanguageString(strCascade, strCascade, out strCascade);
                        scanConfig.StrCascadeType = strCascade;

                        string strDriverChip = scanBdProp.StandardLedModuleProp.DriverChipType.ToString();
                        CommonStaticMethod.GetLanguageString(strDriverChip, strDriverChip, out strDriverChip);
                        scanConfig.StrChipType = strDriverChip;

                        string strScanType = scanBdProp.StandardLedModuleProp.ScanType.ToString();
                        CommonStaticMethod.GetLanguageString(strScanType, strScanType, out strScanType);
                        scanConfig.StrScanType = strScanType;

                        if (info[i].DataHandleWay == HandleWay.Add)
                        {
                            int index = _globalParams.ScannerConfigCollection.IndexOf(scanConfig);
                            if (_globalParams.ScannerConfigCollection.Count == 0)
                            {
                                _globalParams.ScannerConfigCollection.Add(scanConfig);
                            }
                            else
                            {
                                _globalParams.ScannerConfigCollection.Insert(_globalParams.ScannerConfigCollection.Count - 1, scanConfig);
                            }
                        }
                        else if (info[i].DataHandleWay == HandleWay.Replace)
                        {
                            //ObservableCollection<ScannerCofigInfo> find =
                            int count = _globalParams.ScannerConfigCollection.Count;
                            int index = -1;
                            for (int m = 0; m < count; m++)
                            {
                                if (_globalParams.ScannerConfigCollection[m].DisplayName == data.ScanBoardName)
                                {
                                    index = m;
                                    break;
                                }
                            }
                            if (index >= 0 && _globalParams.ScannerConfigCollection != null && _globalParams.ScannerConfigCollection.Count != 0)
                            {

                                _globalParams.ScannerConfigCollection.RemoveAt(index);
                                _globalParams.ScannerConfigCollection.Insert(index, scanConfig);
                            }
                        }
                    }
                    #endregion
                }
            }
            OnIsCheckedChanged(false);
        }
 private bool InsertImportCfgToDB(ScannerCofigInfo scanConfig)
 {
     bool bInsertOk = false;
     SQLiteAccessor sqlLite = SQLiteAccessor.Instance;
     if (!sqlLite.IsScannerNameExist(scanConfig.DisplayName))
     {
         sqlLite.InsterScannerConfig(scanConfig);
         bInsertOk = true;
     }
     else
     {
         bInsertOk = false;
         string msg = "";
         CommonStaticMethod.GetLanguageString("", "Lang_ScanBoardConfigManager_Exist", out msg);
         ShowGlobalDialogMessage(msg, System.Windows.MessageBoxImage.Error);
     }
     return bInsertOk;
 }
        private void ResetScannnerSetCustom()
        {
            //if (ScannerCofigCollection == null ||
            //    ScannerCofigCollection.Count == 0)
            //{
            //    ScannerCofigInfo customScannerConfigInfo = new ScannerCofigInfo();
            //    string strCustom = "";
            //    CommonStaticMethod.GetLanguageString("自定义", "Lang_Global_Custom", out strCustom);
            //    customScannerConfigInfo.DisplayName = strCustom;
            //    customScannerConfigInfo.ScanBdSizeType = ScannerSizeType.Custom;
            //    ScannerCofigCollection = new ObservableCollection<ScannerCofigInfo>();
            //    ScannerCofigCollection.Add(customScannerConfigInfo);
            //}
            //else
       
            bool isHaveCustom = false;
            for (int i = 0; i < ScannerCofigCollection.Count; i++)
            {
                if (ScannerCofigCollection[i].ScanBdSizeType == ScannerSizeType.Custom)
                {
                    isHaveCustom = true;
                    break;
                }
            }
            if (!isHaveCustom)
            {
                ScannerCofigInfo customScannerConfigInfo = new ScannerCofigInfo();
                string strCustom = "";
                CommonStaticMethod.GetLanguageString("自定义", "Lang_Global_Custom", out strCustom);
                customScannerConfigInfo.DisplayName = strCustom;
                customScannerConfigInfo.ScanBdSizeType = ScannerSizeType.Custom;
                ScannerCofigCollection.Insert(ScannerCofigCollection.Count, customScannerConfigInfo);
            }

            if (ScannerCofigCollection != null && ScannerCofigCollection.Count == 1)
            {
                SelectedScannerConfig = null;
            }
            else if (ScannerCofigCollection != null && ScannerCofigCollection.Count > 1)
            {
                SelectedScannerConfig = ScannerCofigCollection[0];
            }
        }
 private void InsertImportCfgToDB(ScannerCofigInfo scanConfig)
 {
     SQLiteAccessor sqlLite = SQLiteAccessor.Instance;
     if (!sqlLite.IsScannerNameExist(scanConfig.DisplayName))
     {
         sqlLite.InsterScannerConfig(scanConfig);
     }
     else
     {
         string msg = "";
         CommonStaticMethod.GetLanguageString("", "Lang_ScanBoardConfigManager_Exist", out msg);
         _smartLCTViewModeBase.ShowGlobalDialogMessage(msg, System.Windows.MessageBoxImage.Error);
     }
 }
        private void NotifyScannerConfigInfoChanged()
        {
            if (ScannerRealParametersValue.ScannerConfig != null)
            {
                ScannerCofigInfo scannerCfigInfo = new ScannerCofigInfo();
                scannerCfigInfo = ScannerRealParametersValue.ScannerConfig;
                if (!scannerCfigInfo.StrCascadeType.EndsWith("_"))
                {
                    scannerCfigInfo.StrCascadeType += "_";
                    scannerCfigInfo.StrChipType += "_";
                    scannerCfigInfo.StrScanType += "_";
                }
                else
                {
                    scannerCfigInfo.StrCascadeType = scannerCfigInfo.StrCascadeType.TrimEnd(new char[] { '_' });
                    scannerCfigInfo.StrChipType = scannerCfigInfo.StrChipType.TrimEnd(new char[] { '_' });
                    scannerCfigInfo.StrScanType = scannerCfigInfo.StrScanType.TrimEnd(new char[] { '_' });
                }
                _selectedScannerConfigInfo = scannerCfigInfo;
                _screenMapRealParametersValue.RectLayerType = _screenMapRealParametersValue.RectLayerType;
                OnSelectedEnvironmentChanged();

                foreach (var item in MyScreen.SenderConnectInfoList)
                {
                    item.SenderIndex = item.SenderIndex;
                    item.SelectedPortIndex = item.SelectedPortIndex;
                   // item.PortConnectInfoList = item.PortConnectInfoList;
                    for (int portindex = 0; portindex < item.PortConnectInfoList.Count; portindex++)
                    {
                        item.PortConnectInfoList[portindex].PortIndex = portindex;
                    }
                    
                }
            }
        }