private async void SaveDevice(object para) { DeviceTreeItemViewModel device = para as DeviceTreeItemViewModel; if (device != null) { try { WaitInfo = "模型保存中"; Status = ViewModelStatus.Querying; T_Diagnosis_Model t_model = DeviceDiagnoseComponent.ConvertToDB(device.DeviceDiagnoseComponent); if (device.DeviceDiagnoseComponent.id == -1) { device.DeviceDiagnoseComponent.id = await _deviceDiagnoseTemplateService.AddDeviceDiagnoseComponent(device.ServerIP, t_model); } else { await _deviceDiagnoseTemplateService.ModifyDeviceDiagnoseComponent(device.ServerIP, t_model); } } catch (Exception ex) { _eventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("设备诊断模型保存", ex)); } finally { Status = ViewModelStatus.None; } } }
private async Task <List <DeviceHourlyDataInfo> > GetDeviceHourlyData(DeviceTreeItemViewModel deviceTree, DateTime start, int day) { List <Guid> guids = new List <Guid>(); foreach (var child in deviceTree.Children) { if (child is ItemTreeItemViewModel) { ItemTreeItemViewModel itemTree = child as ItemTreeItemViewModel; if (itemTree.T_Item != null && itemTree.T_Item.ItemType == (int)ChannelType.WirelessVibrationChannelInfo) { guids.Add(itemTree.T_Item.Guid); } } } var result = await _databaseComponent.GetHistoryData <D_WirelessVibrationSlot>(deviceTree.ServerIP, guids.ToArray(), new string[] { "T_Item_Guid", "ACQDatetime", "Result", "Unit", "AlarmGrade", "RPM", "RecordLab", "IsValidWave", "ExtraInfoJSON" }, start, start.AddDays(day), null, null); if (result == null || result.Count == 0) { return(GetSubDeviceHourlyData(result, start, day)); } var infoList = result.GroupBy(p => p.T_Item_Guid, (key, group) => new { Key = key, Value = group }).Select(p => GetSubDeviceHourlyData(p.Value.ToList(), start, day)).OrderBy(p => p.FirstOrDefault().HourlyData1).ToList(); if (infoList.Count > 0) { int count = infoList.Count; var midinfo = infoList[count / 2]; return(midinfo); } else { return(GetSubDeviceHourlyData(result, start, day)); } }
public void GotoDevice(DeviceTreeItemViewModel device) { if (ViewModel != null) { ViewModel.Init(device); } }
public void GotoDevice(DeviceTreeItemViewModel device, DateTime dt) { if (ViewModel != null) { ViewModel.Init(device, dt); } }
private void SaveToFile(object para) { DeviceTreeItemViewModel device = para as DeviceTreeItemViewModel; if (device != null && device.DeviceDiagnoseComponent != null) { string json = JsonConvert.SerializeObject(device.DeviceDiagnoseComponent); using (StreamWriter sw = new StreamWriter("设备" + device.Name.Replace(@"\", "").Replace(@"/", "") + "诊断模型文件" + DateTime.Now.ToString("yyyy-MM-dd") + ".json", false)) { sw.Write(json); sw.Close(); string dir = System.AppDomain.CurrentDomain.BaseDirectory; System.Diagnostics.Process.Start("explorer.exe", Path.GetFullPath(dir)); } } }
private void EditShaft(object para) { DeviceTreeItemViewModel devicemodel = para as DeviceTreeItemViewModel; if (devicemodel != null && devicemodel.DeviceDiagnoseComponent != null && devicemodel.DeviceDiagnoseComponent.Component.SelectedShaft != null && devicemodel.DeviceDiagnoseComponent.Component.SelectedShaft.Component != null && devicemodel.DeviceDiagnoseComponent.Component.SelectedShaft.Component.MachComponents.Count == 0) { BearingComponent bear = NewComponent(); devicemodel.DeviceDiagnoseComponent.Component.SelectedShaft.Component.AddBearingComponent(bear); devicemodel.DeviceDiagnoseComponent.Component.SelectedShaft.Component.SelectedComponent = bear; ComponentSelectionChanged(devicemodel.DeviceDiagnoseComponent.Component.SelectedShaft); } else { ShaftSelectionChanged(para); } }
private void ClearDevice(object para) { DeviceTreeItemViewModel device = para as DeviceTreeItemViewModel; if (device == null) { return; } #if XBAP MessageBoxResult result = MessageBox.Show("确定要重置" + SelectedDeviceTreeItemViewModel.Name + "?", "重置", MessageBoxButton.OK, MessageBoxImage.Warning); #else MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show("确定要重置" + SelectedDeviceTreeItemViewModel.Name + "?", "重置", MessageBoxButton.OKCancel, MessageBoxImage.Warning); #endif if (result == MessageBoxResult.OK) { _deviceDiagnoseTemplateService.DeleteDeviceDiagnoseComponent(device.ServerIP, device.DeviceDiagnoseComponent.id); device.IntiDeviceDiagnoseComponent(); } }
private void ShaftSelectionChanged(object para) { if (editComponentDoubleClick)//避免EditShaft编辑事件 { editComponentDoubleClick = false; return; } DeviceTreeItemViewModel devicemodel = para as DeviceTreeItemViewModel; if (devicemodel != null && devicemodel.DeviceDiagnoseComponent != null && devicemodel.DeviceDiagnoseComponent.Component.SelectedShaft != null) { var navigationParameters = new NavigationParameters(); navigationParameters.Add("DeviceDiagnoseComponent", devicemodel.DeviceDiagnoseComponent); _regionManager.RequestNavigate(RegionNames.EditComponentRegion, editShaftComponentView, navigationParameters); } else { _regionManager.RequestNavigate(RegionNames.EditComponentRegion, nullView); } }
private async void Load(object para) { DeviceTreeItemViewModel device = para as DeviceTreeItemViewModel; if (device != null && device.DeviceDiagnoseComponent != null) { try { WaitInfo = "模板加载中"; Status = ViewModelStatus.Querying; await _deviceDiagnoseTemplateService.GetClasses(device.ServerIP); } catch (Exception ex) { _eventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("设备诊断模板加载", ex)); } finally { Status = ViewModelStatus.None; } } }
private void getTree() { node1 = new OrganizationTreeItemViewModel("北京航天智控测试工厂", 0, "192.168.0.210"); node1_1 = new OrganizationTreeItemViewModel("厂区1", 2, node1); node1_2 = new OrganizationTreeItemViewModel("厂区2", 1, node1); node1_3 = new OrganizationTreeItemViewModel("厂区3", 0, node1); node1_1_1 = new DeviceTreeItemViewModel("设备1", 2, node1_1); node1_1_2 = new DeviceTreeItemViewModel("设备2", 1, node1_1); node1_1_3 = new DeviceTreeItemViewModel("设备3", 0, node1_1); node1_1_1_1 = new ItemTreeItemViewModel("测点1", 2, node1_1_1); node1_1_1_2 = new ItemTreeItemViewModel("测点2", 1, node1_1_1); node1_1_1_3 = new ItemTreeItemViewModel("测点3", 0, node1_1_1); node1_1_2_1 = new ItemTreeItemViewModel("测点4", 2, node1_1_2); node1_1_2_2 = new ItemTreeItemViewModel("测点5", 1, node1_1_2); node1_1_2_3 = new ItemTreeItemViewModel("测点6", 0, node1_1_2); node1_1_3_1 = new ItemTreeItemViewModel("测点7", 2, node1_1_3); node1_1_3_2 = new ItemTreeItemViewModel("测点8", 1, node1_1_3); node1_1_3_3 = new ItemTreeItemViewModel("测点9", 0, node1_1_3); node2 = new OrganizationTreeItemViewModel("测试工厂1", 3, ""); node3 = new OrganizationTreeItemViewModel("测试工厂2", 2, ""); node4 = new OrganizationTreeItemViewModel("测试工厂3", 1, ""); OrganizationTreeItems.Clear(); List <ItemTreeItemViewModel> item1 = new List <ItemTreeItemViewModel>(); item1.Add(node1_1_1_1); item1.Add(node1_1_1_2); item1.Add(node1_1_1_3); node1_1_1.AddChildRange(from p in item1 orderby p.T_Organization.Sort_No select p as OrganizationTreeItemViewModel); List <ItemTreeItemViewModel> item2 = new List <ItemTreeItemViewModel>(); item2.Add(node1_1_2_1); item2.Add(node1_1_2_2); item2.Add(node1_1_2_3); node1_1_2.AddChildRange(from p in item2 orderby p.T_Organization.Sort_No select p as OrganizationTreeItemViewModel); List <ItemTreeItemViewModel> item3 = new List <ItemTreeItemViewModel>(); item3.Add(node1_1_3_1); item3.Add(node1_1_3_2); item3.Add(node1_1_3_3); node1_1_3.AddChildRange(from p in item3 orderby p.T_Organization.Sort_No select p as OrganizationTreeItemViewModel); List <DeviceTreeItemViewModel> device = new List <DeviceTreeItemViewModel>(); device.Add(node1_1_1); device.Add(node1_1_2); device.Add(node1_1_3); node1_1.AddChildRange(from p in device orderby p.T_Organization.Sort_No select p as OrganizationTreeItemViewModel); List <OrganizationTreeItemViewModel> organization = new List <OrganizationTreeItemViewModel>(); organization.Add(node1_1); organization.Add(node1_2); organization.Add(node1_3); node1.AddChildRange(from p in organization orderby p.T_Organization.Sort_No select p as OrganizationTreeItemViewModel); List <OrganizationTreeItemViewModel> root = new List <OrganizationTreeItemViewModel>(); root.Add(node1); root.Add(node2); root.Add(node3); root.Add(node4); OrganizationTreeItems.AddRange(from p in root orderby p.T_Organization.Sort_No select p); RecycledTreeItems.Clear(); OrganizationTreeItemViewModel recyclednode = new OrganizationTreeItemViewModel("回收站", 0, "192.168.0.1"); recyclednode.IsExpanded = true; RecycledTreeItems.Add(recyclednode); //SaveOrganizationToDatabase(); //SaveItemToDatabase(); }
private void GetSubOrganization(OrganizationTreeItemViewModel parent_organization, string ip, bool isadmin) { if (parent_organization == null) { return; } var childs = from p in _databaseComponent.GetOrganizationData(ip) where p.Parent_Guid == parent_organization.T_Organization.Guid && p.Is_Disabled == false orderby p.Sort_No select p; foreach (var child in childs) { if (child.NodeType == 0 && child.Is_Disabled == false) { T1_OrganizationPrivilege t_organization = null; if (isadmin == false) { t_organization = (from p in T_OrganizationPrivilege[ip] where p.T_Organization_Guid == child.Guid select p).FirstOrDefault(); } if (t_organization != null || isadmin == true) { OrganizationTreeItemViewModel organization = new OrganizationTreeItemViewModel(child, parent_organization); //organization.T_Organization = child; parent_organization.AddChild(organization); GetSubOrganization(organization, ip, isadmin); } } else if (child.NodeType == 1 && child.Is_Disabled == false) { T1_OrganizationPrivilege t_organization = null; if (isadmin == false) { t_organization = (from p in T_OrganizationPrivilege[ip] where p.T_Organization_Guid == child.Guid select p).FirstOrDefault(); } if (t_organization != null || isadmin == true) { DeviceTreeItemViewModel organization = new DeviceTreeItemViewModel(child, parent_organization); parent_organization.AddChild(organization); GetSubOrganization(organization, ip, isadmin); } } else if (child.NodeType == 2 && child.Is_Disabled == false) { ItemTreeItemViewModel organization = new ItemTreeItemViewModel(child, parent_organization as DeviceTreeItemViewModel); parent_organization.AddChild(organization); //测点数据 var t_item = _databaseComponent.GetItemData(ip).Where(p => p.Is_Disabled == false && p.Guid == organization.T_Organization.Guid).FirstOrDefault(); if (t_item != null) { organization.RecoverBind(t_item); t_item.ServerIP = parent_organization.ServerIP;//改为初始化时候填充,覆盖数据库的ServerIP。 //如果彻底删除此项,必须修改//服务器IP匹配20180306 } ItemTreeItems.Add(organization); GetSubOrganization(organization, ip, isadmin); } else if (child.NodeType == 3 && child.Is_Disabled == false) { DivFreTreeItemViewModel organization = new DivFreTreeItemViewModel(child, parent_organization as ItemTreeItemViewModel); //分频数据 var t_divfre = T_DivFreInfo[ip].Where(p => p.Guid == organization.T_Organization.Guid).FirstOrDefault(); if (t_divfre != null) //分频一定不为空 { parent_organization.AddChild(organization); //否则丢弃无效分频数据 organization.T_DivFreInfo = t_divfre; DivFreTreeItems.Add(organization); //GetSubOrganization(organization, ip, isadmin);//分频下无节点 } } } }
public void Init(DeviceTreeItemViewModel device) { SelectedDeviceTreeItemViewModel = device; SelectedDeviceTreeItemViewModel.IsSelected = true; }
//public int id { get; set; }//自增ID //public string Organization { get; set; }//组织机构 //public string T_Device_Name { get; set; }//设备名称 //public string T_Device_Code { get; set; }//设备编号 //public Guid T_Device_Guid { get; set; }//设备Guid //public string T_Item_Name { get; set; }//测点名称 //public string T_Item_Code { get; set; }//测点编号 //public Guid T_Item_Guid { get; set; }//测点Guid //public int CHNum { get; set; }//通道号 //public int SubCHNum { get; set; }//子通道号 //public bool IsUploadData { get; set; }//是否上传 //public string Unit { get; set; }// //public string SVTypeCategory { get; set; }//单值类型种类 //public int SVTypeCode { get; set; }//单值类型代码 //public string LocalSaveCategory { get; set; }//本地存储策略 //public int LocalSaveCode { get; set; }//本地存储代码 //public bool IsBypass { get; set; }//是否旁路 //public int DelayAlarmTime { get; set; }//延时报警 //public int NotOKDelayAlarmTime { get; set; }//NotOK延时报警 //public bool IsLogic { get; set; }//启用逻辑表达式 //public string LogicExpression { get; set; }//逻辑表达式 //public string Remarks { get; set; }//备注 //public string Extra_Information { get; set; }//附加信息 //public string AlarmStrategy { get; set; }//报警策略 //public string Code { get; set; }//抽象信息通道代号 //public string T_AbstractSlotInfo_Code { get; set; }//抽象槽代号 public void BindTemp(ItemTreeItemViewModel item, List <Organization> organizations, DeviceTreeItemViewModel device) { SaveTempData(); TempData.Organization = JsonConvert.SerializeObject(organizations); TempData.T_Item_Name = organizations[0].Name;//item.T_Item.Name; TempData.T_Item_Code = item.T_Item.Code; TempData.T_Item_Guid = item.T_Item.Guid; TempData.T_Device_Name = device.T_Organization.Name;//htzk123,可能有问题 TempData.T_Device_Code = device.T_Organization.Code; TempData.T_Device_Guid = device.T_Organization.Guid; }