private void CompletedReadScanBdPropertyCallBack(CompletedReadScanBdPropInfo info)
 {
     if (info.ReadRes == ReadConfigRes.Succeed)
     {
         ScanBoardProperty scanBdProperty = new ScanBoardProperty();
         info.ScanBdProperty.CopyTo(scanBdProperty);
         SetBright(true, scanBdProperty.Brightness);
         _autoReadEvent.Set();
     }
     else
     {
         if (_current_ScannerInfo.IsUserRedundancy)
         {
             SetBright(false, 0);
             _autoReadEvent.Set();
         }
         else
         {
             _current_ScannerInfo.IsUserRedundancy = true;
             _current_ScannerInfo.ScannerProperty.ReadScanBd200ParasInfo(_current_ScannerInfo.ScanRedundancyPosition, CompletedReadScanBdPropertyCallBack);
         }
     }
 }
        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);
            }
        }
        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 bool SaveScanBdConfig(string saveFileName,ScanBoardProperty scanBdProperty)
        {
            XmlSerializer xmls = null;
            StreamWriter sw = null;
            bool res = false;
            string msg = string.Empty;
            try
            {
                xmls = new XmlSerializer(typeof(ScanBoardProperty));
                sw = new StreamWriter(saveFileName);
                //XmlWriterSettings setting = new XmlWriterSettings();
                //setting.CloseOutput = true;

                XmlWriter xmlWriter = XmlWriter.Create(sw);
                xmls.Serialize(sw, scanBdProperty);
                sw.Close();
                res = true;
                return res;
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.ToString());

                res = false;
                return res;
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                    sw.Dispose();
                }
            }
        }
        private bool LoadScanProFile(string openFileName, out ScanBoardProperty scanBDproData)
        {
            scanBDproData = new ScanBoardProperty();
            XmlSerializer xmls = null;
            StreamReader sr = null;
            XmlReader xmlReader = null;
            string msg = string.Empty;
            bool res = false;
            try
            {
                xmls = new XmlSerializer(typeof(ScanBoardProperty));
                sr = new StreamReader(openFileName);
                xmlReader = XmlReader.Create(sr);
                if (!xmls.CanDeserialize(xmlReader))
                {
                    res = false;
                    return res;
                }
                else
                {
                    ScanBoardProperty scanBDpro = (ScanBoardProperty)xmls.Deserialize(xmlReader);
                    if (!scanBDpro.CopyTo(scanBDproData))
                    {
                        res = false;
                        scanBDproData = null;
                        return res;
                    }
                    else
                    {
                        res = true;

                        return res;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                res = false;
                return res;
            }
            finally
            {

                if (sr != null)
                {
                    sr.Close();
                    sr.Dispose();
                }
                if (xmlReader != null)
                {
                    xmlReader.Close();
                }
            }
        }
        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 void UpdateScanBdPropToUI(ScanBoardProperty scanBdProp)
        {
            #region 更新亮度
            //_isUpdating = true;
            if (scanBdProp.RedBright == scanBdProp.GreenBright &&
                scanBdProp.RedBright == scanBdProp.BlueBright)
            {
                IsSyncBright = true;
            }
            else
            {
                IsSyncBright = false;
            }

            GlobalBright = scanBdProp.Brightness;
            RedBright = scanBdProp.RedBright;
            GreenBright = scanBdProp.GreenBright;
            BlueBright = scanBdProp.BlueBright;
            #endregion

            #region 更新色温
            ColorTempRGBMapping findMap = _colorTempRGBMapDict.Values.FirstOrDefault(delegate(ColorTempRGBMapping map)
            {
                if (map.RedBright == RedBright &&
                    map.GreenBright == GreenBright &&
                    map.BlueBright == BlueBright)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            });
            if (findMap != null)
            {
                IsCustomRGBBright = false;
                ColorTemp = findMap.ColorTemp;
            }
            else
            {
                IsCustomRGBBright = true;
            }
            #endregion

            #region 更新电流增益
            if (_curChipInfo != null
                && IsSupportCurrentGain)
            {
                MaxGainStep = _curChipInfo.CurrentGainStepInfo.TotalStep - 1;


                int redStep = 0;
                float redCurGain = 0.0f;
                int greenStep = 0;
                float greenCurGain = 0.0f;
                int blueStep = 0;
                float blueCurGain = 0.0f;

                _curChipInfo.GetStepCurrentGain(scanBdProp.RedGain, out redStep, out redCurGain);
                _curChipInfo.GetStepCurrentGain(scanBdProp.GreenGain, out greenStep, out greenCurGain);
                _curChipInfo.GetStepCurrentGain(scanBdProp.BlueGain, out blueStep, out blueCurGain);

                if (redStep == greenStep &&
                    redStep == blueStep)
                {
                    IsSyncGain = true;
                }
                else
                {
                    IsSyncGain = false;
                }

                RedGain = redStep;
                GreenGain = greenStep;
                BlueGain = blueStep;
            }
            #endregion

            #region 更新Gamma
            bool isCustomGamma = false;
            bool isEhancedMode = false;
            bool isModeB = false;
            byte realGamma = CustomTransform.RealGammaToLogicalGamma(scanBdProp.GammaValue, out isCustomGamma, out isEhancedMode, out isModeB);

            GammaValue = realGamma;

            if (isEhancedMode)
            {
                ScreenDisplayQuality = ScreenQuality.Enhance; 
            }
            else
            {
                ScreenDisplayQuality = ScreenQuality.Soft;
            }

            if (isModeB)
            {
                GammaDisplayABMode = GammaABMode.GammaB;
            }
            else
            {
                GammaDisplayABMode = GammaABMode.GammaA;
            }
            #endregion

            #region 更新芯片类型
            string key = scanBdProp.StandardLedModuleProp.DriverChipType.ToString();
            string chipName = "";
            CommonStaticMethod.GetLanguageString(key, key, out chipName);
            ChipName = chipName;
            #endregion
        }
        private void CompletedReadScanBoardProp(CompletedReadScanBdPropInfo info)
        {
            string operateStr = "";

            CommMsgType commType = CommMsgType.Information;

            if (info.ReadRes == ReadConfigRes.Succeed)
            {
                _scanBdProp = info.ScanBdProperty;
                ChipType chipType = _scanBdProp.StandardLedModuleProp.DriverChipType;
                _chipConfig = ChipRegistorConfigFactory.GetChipRegistorConfig(chipType);

                if (ChipInherDict.ContainsKey(chipType))
                {
                    _curChipInfo = ChipInherDict[chipType];
                    IsSupportCurrentGain = _curChipInfo.IsSupportCurrentGain;
                }
                else
                {
                    IsSupportCurrentGain = false;
                }
                UpdateScanBdPropToUI(info.ScanBdProperty);

                CommonStaticMethod.GetLanguageString("读取参数成功!", "Lang_Bright_ReadParams_Succeed", out operateStr);
                commType = CommMsgType.Information;
            }
            else
            {
                _scanBdProp = new ScanBoardProperty();
                IsSupportCurrentGain = false;
                string msg = "";
                CommonStaticMethod.GetLanguageString("读取芯片类型失败!", "Lang_Bright_ReadChipFailed", out msg);
                ChipName = msg;

                CommonStaticMethod.GetLanguageString("读取参数失败!", "Lang_Bright_ReadParams_Failed", out operateStr);
                commType = CommMsgType.Error;
            }

            //NotifyMessage(this, new NotifyMessageEventArgs(new CommMsg() { Msg = operateStr, MsgType = commType }));
        }