示例#1
0
        public List<DisplaySmartBrightEasyConfig> GetAllNeedEasyConfig(SmartBrightSeleCondition condition)
        {
            List<DisplaySmartBrightEasyConfig> dataList = new List<DisplaySmartBrightEasyConfig>();

            string sql = "SELECT rowid, DisplayUDID, LastModifyTime, ConfigurationFile, ConfigFileVersion, BrightAdjustMode FROM DisplaySSmartBrightEasyConfig ";
            sql += " WHERE BrightAdjustMode=" + (int)condition.BrightAdjMode;

            DataTable dt = _helper.ExecuteDataTable(sql);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                byte[] fileData = (byte[])dt.Rows[i]["ConfigurationFile"];

                MemoryStream stream = new MemoryStream(fileData);
                DisplaySmartBrightEasyConfig config;
                bool res = CustomTransform.LoadSmartBrightEasyConfig(stream, out config);

                if (res)
                {
                    dataList.Add(config);
                }
            }

            return dataList;
        }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     SQLiteAccessor accessor = SQLiteAccessor.Instance;
     
     if (accessor == null)
     {
         MessageBox.Show("初始化数据库失败!");
         return;
     }
     DisplaySmartBrightEasyConfig cfg = GetConfig();
     SmartBrightSeleCondition condition = new SmartBrightSeleCondition()
     {
         BrightAdjMode = BrightAdjustMode.SmartBright,
         DataVersion = 1,
         EasyConfig = cfg
     };
     accessor.SaveDisplayEasyConfig(cfg.DisplayUDID, condition);
     accessor.Dispose();
 }
        public SmartBrightSeleCondition LoadDisplayEasyConfig(string displayUDID)
        {
            string sql = "SELECT rowid, DisplayUDID, LastModifyTime, ConfigurationFile, ConfigFileVersion, BrightAdjustMode FROM DisplaySSmartBrightEasyConfig";
            
            {
                sql += " WHERE DisplayUDID='" + displayUDID + "'";
            }

            DataTable dt = _helper.ExecuteDataTable(sql);
            
            if (dt.Rows.Count == 0)
            {
                return null;
            }
            DataRow row = dt.Rows[0];

            byte[] fileData = (byte[])row["ConfigurationFile"];

            MemoryStream stream = new MemoryStream(fileData);
            DisplaySmartBrightEasyConfig config;
            bool res = CustomTransform.LoadSmartBrightEasyConfig(stream, out config);
           
            if (!res)
            {
                return null;
            }

            SmartBrightSeleCondition condition = null;
            try
            {
                condition = new SmartBrightSeleCondition()
                {
                    BrightAdjMode = (BrightAdjustMode)((int)(short)row["BrightAdjustMode"]),
                    DataVersion = (int)(short)row["ConfigFileVersion"],
                    EasyConfig = config
                };
            }
            catch (Exception e)
            {

            }

            return condition;
        }
        public bool SaveDisplayEasyConfig(string displayUDID, SmartBrightSeleCondition condition)
        {
            MemoryStream stream = new MemoryStream();
            bool res = CustomTransform.SaveSmartBrightEasyConfig(stream, condition.EasyConfig);
            if (!res)
            {
                return false;
            }

            string sql = "SELECT rowid, DisplayUDID, LastModifyTime, ConfigurationFile, ConfigFileVersion, BrightAdjustMode FROM DisplaySSmartBrightEasyConfig WHERE DisplayUDID='" + displayUDID + "'";
            DataTableUpdate dtUpdate = _helper.ExecuteDataTableUpdate(sql);
            
            DataRow row = null;
            bool isAdd = false;
            if (dtUpdate.DtResult.Rows.Count == 0)
            {
                row = dtUpdate.DtResult.NewRow();
                isAdd = true;
            }
            else
            {
                row = dtUpdate.DtResult.Rows[0];
            }

            row["DisplayUDID"] = condition.EasyConfig.DisplayUDID;
            row["LastModifyTime"] = DateTime.Now;
            row["ConfigurationFile"] = stream.ToArray();
            row["ConfigFileVersion"] = condition.DataVersion;
            row["BrightAdjustMode"] = (int)condition.BrightAdjMode;

            if (isAdd)
            {
                dtUpdate.DtResult.Rows.Add(row);
            }
            dtUpdate.DtResult.TableName = "DisplaySSmartBrightEasyConfig";
            int isOK = _helper.DataTableUpdateToDB(dtUpdate);
            if (isOK == -5)
            {
                return false;
            }
            return true;
        }
        private bool SaveConfigToDB()
        {
            DisplaySmartBrightEasyConfig easyConfig = GetEasyConfigFromUI();

            ApplyHWBrightMode(easyConfig);

            SQLiteAccessor accessor = SQLiteAccessor.Instance;
            
            if (accessor == null)
            {
                return false;
            }
            SmartBrightSeleCondition condition = new SmartBrightSeleCondition()
            {
                BrightAdjMode = SelectedBrightAdjustMode,
                DataVersion = 0,
                EasyConfig = easyConfig
            };
            return accessor.SaveDisplayEasyConfig(easyConfig.DisplayUDID, condition);
        }