public UC_WHControlConfig_Tem(UC_WHControlConfig_Tem_VM stratInfo) { InitializeComponent(); UpdateLang(CommonUI.ControlConfigLangPath); _temVM = new UC_WHControlConfig_Tem_VM(stratInfo.SN, stratInfo.ID, stratInfo.ConditionAlgor, stratInfo.LessThan, stratInfo.GreaterThan, stratInfo.IsControlBrightness, stratInfo.Brightness, stratInfo.PowerCtrlDic); InitialTemMV(); if (_temVM.PowerCtrlDic.Count != 0) { groupBox_PwoerManager.Controls.Add(_uc_powerCtrlCfg); _uc_powerCtrlCfg.Dock = DockStyle.Fill; _uc_powerCtrlCfg.Visible = true; } else _uc_powerCtrlCfg.Visible = false; }
public UC_WHControlConfig_VM_Base CreateStrategy(StrategyType type) { UC_WHControlConfig_VM_Base strategy = null; if (type == StrategyType.SmokeStrategy) { strategy = new UC_WHControlConfig_Smoke_VM(_selectedScreenSN); } else if (type == StrategyType.TemperatureStrategy) { strategy = new UC_WHControlConfig_Tem_VM(_selectedScreenSN); } else if (type == StrategyType.LightStrategy) { //处理亮度控制初始化 return(null); } return(strategy); }
public ControlConfigSaveRes IsTemOk(UC_WHControlConfig_Tem_VM tem_VM) { if (_temStrategyList == null) { return(ControlConfigSaveRes.ok); } if (tem_VM == null) { return(ControlConfigSaveRes.tem_objIsNull); } bool isAllInvalid = true; foreach (var item in tem_VM.PowerCtrlDic.Values) { if (item != PowerCtrl_Type.still) { isAllInvalid = false; } } if (isAllInvalid && !tem_VM.IsControlBrightness) { return(ControlConfigSaveRes.tem_CtrlCfgIsInvalid); } if (tem_VM.GreaterThan + 5 > tem_VM.LessThan) { return(ControlConfigSaveRes.tem_ConditionError); } List <UC_WHControlConfig_Tem_VM> tem = _temStrategyList.FindAll(a => (a.LessThan + 5 > tem_VM.GreaterThan && a.GreaterThan - 5 < tem_VM.GreaterThan) || (a.LessThan + 5 > tem_VM.LessThan && a.GreaterThan - 5 < tem_VM.LessThan) || (a.GreaterThan - 5 > tem_VM.GreaterThan && a.LessThan + 5 < tem_VM.LessThan)); if (tem.Count != 0) { return(ControlConfigSaveRes.tem_CtrlCfgIsExist); } return(ControlConfigSaveRes.ok); }
private ControlConfigSaveRes IsTemOk(UC_WHControlConfig_Tem_VM tem_VM) { if (tem_VM == null) return ControlConfigSaveRes.tem_objIsNull; bool isAllInvalid = true; foreach (var item in tem_VM.PowerCtrlDic.Values) { if (item != PowerCtrl_Type.still) isAllInvalid = false; } if (isAllInvalid && !tem_VM.IsControlBrightness) return ControlConfigSaveRes.tem_CtrlCfgIsInvalid; if (tem_VM.GreaterThan + 5 > tem_VM.LessThan) return ControlConfigSaveRes.tem_ConditionError; List<UC_WHControlConfig_Tem_VM> tem = _temStrategyList.FindAll(a => (a.LessThan + 5 > tem_VM.GreaterThan && a.GreaterThan - 5 < tem_VM.GreaterThan) || (a.LessThan + 5 > tem_VM.LessThan && a.GreaterThan - 5 < tem_VM.LessThan) || (a.GreaterThan - 5 > tem_VM.GreaterThan && a.LessThan + 5 < tem_VM.LessThan)); if (tem.Count != 0) return ControlConfigSaveRes.tem_CtrlCfgIsExist; return ControlConfigSaveRes.ok; }
public void Initialize(string sn) { try { _selectedScreenSN = sn; //_mode = MonitorDataManager.Mode.add; if (MonitorAllConfig.Instance().LedInfoList.FindAll(a => a.Sn == _selectedScreenSN).Count == 0) { _isEnableCtrl = false; return; } else _isEnableCtrl = true; _temStrategyList.Clear(); _smokeStrategyList.Clear(); _vm_BaseList.Clear(); if (MonitorAllConfig.Instance().StrategyConfigDic.Keys.Contains(_selectedScreenSN)) { //已配置过策略 UC_WHControlConfig_Smoke_VM smoke_VM; UC_WHControlConfig_Tem_VM tem_VM; List<Strategy> straList = MonitorAllConfig.Instance().StrategyConfigDic[_selectedScreenSN]; Dictionary<string, PowerCtrl_Type> powerCtrlDic; foreach (var item in straList) { if (item.Type == StrategyType.LightStrategy) continue; foreach (var rule in item.RuleTable) { //if (!_strategyDic.Keys.Contains(item.Type)) // _strategyDic.Add(item.Type, new List<Strategy_Tem_Smoke_VM>()); if (rule.RuleAction.ActionCommandCollection.FindIndex(a => a.ActionTarget.TargetType == ActionTargetType.SmartFunction) >= 0) continue; List<ActionCommand> aCmdList = rule.RuleAction.ActionCommandCollection.FindAll(a => (a.ActionType != ActionType.Set && a.ActionTarget.TargetType != ActionTargetType.SmartFunction)); powerCtrlDic = new Dictionary<string, PowerCtrl_Type>(); if (aCmdList.Count != 0) { PowerCtrl_Type pType = PowerCtrl_Type.still; foreach (var cmd in aCmdList) { if (cmd.ActionType == ActionType.Open) pType = PowerCtrl_Type.open; else if (cmd.ActionType == ActionType.Close) pType = PowerCtrl_Type.close; if (cmd.ActionTarget.DeviceTarget != null) { foreach (var target in cmd.ActionTarget.DeviceTarget) { if (!powerCtrlDic.ContainsKey(target)) { powerCtrlDic.Add(target, pType); } } } } } var action = rule.RuleAction.ActionCommandCollection.Find(a => a.ActionType == ActionType.Set && item.Type == StrategyType.TemperatureStrategy); bool isBrightness = false; int brightnessValue = 0; if (action != null) { isBrightness = true; int.TryParse(action.ActionTarget.ParameterTarget.Value.ToString(), out brightnessValue); } if (item.Type == StrategyType.SmokeStrategy) { smoke_VM = new UC_WHControlConfig_Smoke_VM(item.SN, Guid.NewGuid(), rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.GreaterThan).RightExpression, powerCtrlDic); _smokeStrategyList.Add(smoke_VM); _vm_BaseList.Add(smoke_VM); } else if (item.Type == StrategyType.TemperatureStrategy) { var lessRule = rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.LessThan); var greaterRule = rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.GreaterThan); int lessRightEx = 0, greaterRightEx = 0; if (lessRule != null) lessRightEx = lessRule.RightExpression; if (greaterRule != null) greaterRightEx = greaterRule.RightExpression; tem_VM = new UC_WHControlConfig_Tem_VM(item.SN, Guid.NewGuid(), rule.RuleCondition.ConditionCollection[0].Algorithm, lessRightEx, greaterRightEx, isBrightness, brightnessValue, powerCtrlDic); _temStrategyList.Add(tem_VM); _vm_BaseList.Add(tem_VM); } } } //if (_temStrategyList.Count != 0 || _smokeStrategyList.Count != 0) _mode = MonitorDataManager.Mode.modify; } } catch (Exception ex) { MonitorAllConfig.Instance().WriteLogToFile("ExistCatch:策略主页面初始化异常:" + ex.ToString(), true); } }
public UC_WHControlConfig_VM_Base CreateStrategy(StrategyType type) { UC_WHControlConfig_VM_Base strategy = null; if (type == StrategyType.SmokeStrategy) { strategy = new UC_WHControlConfig_Smoke_VM(_selectedScreenSN); } else if (type == StrategyType.TemperatureStrategy) { strategy = new UC_WHControlConfig_Tem_VM(_selectedScreenSN); } else if (type == StrategyType.LightStrategy) { //处理亮度控制初始化 return null; } return strategy; }
public void Initialize(string sn) { try { _selectedScreenSN = sn; //_mode = MonitorDataManager.Mode.add; if (MonitorAllConfig.Instance().LedInfoList.FindAll(a => a.Sn == _selectedScreenSN).Count == 0) { _isEnableCtrl = false; return; } else { _isEnableCtrl = true; } _temStrategyList.Clear(); _smokeStrategyList.Clear(); _vm_BaseList.Clear(); if (MonitorAllConfig.Instance().StrategyConfigDic.Keys.Contains(_selectedScreenSN)) { //已配置过策略 UC_WHControlConfig_Smoke_VM smoke_VM; UC_WHControlConfig_Tem_VM tem_VM; List <Strategy> straList = MonitorAllConfig.Instance().StrategyConfigDic[_selectedScreenSN]; Dictionary <string, PowerCtrl_Type> powerCtrlDic; foreach (var item in straList) { if (item.Type == StrategyType.LightStrategy) { continue; } foreach (var rule in item.RuleTable) { //if (!_strategyDic.Keys.Contains(item.Type)) // _strategyDic.Add(item.Type, new List<Strategy_Tem_Smoke_VM>()); if (rule.RuleAction.ActionCommandCollection.FindIndex(a => a.ActionTarget.TargetType == ActionTargetType.SmartFunction) >= 0) { continue; } List <ActionCommand> aCmdList = rule.RuleAction.ActionCommandCollection.FindAll(a => (a.ActionType != ActionType.Set && a.ActionTarget.TargetType != ActionTargetType.SmartFunction)); powerCtrlDic = new Dictionary <string, PowerCtrl_Type>(); if (aCmdList.Count != 0) { PowerCtrl_Type pType = PowerCtrl_Type.still; foreach (var cmd in aCmdList) { if (cmd.ActionType == ActionType.Open) { pType = PowerCtrl_Type.open; } else if (cmd.ActionType == ActionType.Close) { pType = PowerCtrl_Type.close; } if (cmd.ActionTarget.DeviceTarget != null) { foreach (var target in cmd.ActionTarget.DeviceTarget) { if (!powerCtrlDic.ContainsKey(target)) { powerCtrlDic.Add(target, pType); } } } } } var action = rule.RuleAction.ActionCommandCollection.Find(a => a.ActionType == ActionType.Set && item.Type == StrategyType.TemperatureStrategy); bool isBrightness = false; int brightnessValue = 0; if (action != null) { isBrightness = true; int.TryParse(action.ActionTarget.ParameterTarget.Value.ToString(), out brightnessValue); } if (item.Type == StrategyType.SmokeStrategy) { smoke_VM = new UC_WHControlConfig_Smoke_VM(item.SN, Guid.NewGuid(), rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.GreaterThan).RightExpression, powerCtrlDic); _smokeStrategyList.Add(smoke_VM); _vm_BaseList.Add(smoke_VM); } else if (item.Type == StrategyType.TemperatureStrategy) { var lessRule = rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.LessThan); var greaterRule = rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.GreaterThan); int lessRightEx = 0, greaterRightEx = 0; if (lessRule != null) { lessRightEx = lessRule.RightExpression; } if (greaterRule != null) { greaterRightEx = greaterRule.RightExpression; } tem_VM = new UC_WHControlConfig_Tem_VM(item.SN, Guid.NewGuid(), rule.RuleCondition.ConditionCollection[0].Algorithm, lessRightEx, greaterRightEx, isBrightness, brightnessValue, powerCtrlDic); _temStrategyList.Add(tem_VM); _vm_BaseList.Add(tem_VM); } } } //if (_temStrategyList.Count != 0 || _smokeStrategyList.Count != 0) _mode = MonitorDataManager.Mode.modify; } } catch (Exception ex) { MonitorAllConfig.Instance().WriteLogToFile("ExistCatch:策略主页面初始化异常:" + ex.ToString(), true); } }