V1版本
This commit is contained in:
@@ -4,14 +4,11 @@ using CapMachine.Model;
|
||||
using CapMachine.Wpf.Models;
|
||||
using CapMachine.Wpf.Services;
|
||||
using ImTools;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Prism.Commands;
|
||||
using Prism.Services.Dialogs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
|
||||
namespace CapMachine.Wpf.ViewModels
|
||||
@@ -24,7 +21,7 @@ namespace CapMachine.Wpf.ViewModels
|
||||
|
||||
//加载曲线数据源
|
||||
ChartSrcDataListViewItems = new ObservableCollection<ChartSrcData>();
|
||||
|
||||
|
||||
ChartYAxisDataListViewItems = new ObservableCollection<ChartYAxisDto>()
|
||||
{
|
||||
new ChartYAxisDto(){
|
||||
@@ -53,7 +50,7 @@ namespace CapMachine.Wpf.ViewModels
|
||||
this.Mapper = mapper;
|
||||
MachineRtDataService = machineRtDataService;
|
||||
LoadChartSourceData();
|
||||
RefreshChartSelectedData();
|
||||
//RefreshChartSelectedData();
|
||||
RefreshChartYAxisData();
|
||||
}
|
||||
|
||||
@@ -72,25 +69,32 @@ namespace CapMachine.Wpf.ViewModels
|
||||
/// </summary>
|
||||
public MachineRtDataService MachineRtDataService { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前的TabIndex
|
||||
/// </summary>
|
||||
private int CurGroupTabIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前的Machine
|
||||
/// </summary>
|
||||
private string CurSelectedMachine { get; set; } = "M1";
|
||||
|
||||
/// <summary>
|
||||
/// 加载ChartSourceData
|
||||
/// </summary>
|
||||
private void LoadChartSourceData()
|
||||
{
|
||||
foreach (var item in MachineRtDataService.ListMeterRtData)
|
||||
foreach (var item in MachineRtDataService.TagManger.DicTags)
|
||||
{
|
||||
ChartSrcDataListViewItems.Add(new ChartSrcData()
|
||||
{
|
||||
Index=1,
|
||||
Name=item.MeterName,
|
||||
Selected=false,
|
||||
Index = ChartSrcDataListViewItems.Count + 1,
|
||||
Name = item.Key,
|
||||
Selected = false,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载数据
|
||||
/// </summary>
|
||||
@@ -108,11 +112,16 @@ namespace CapMachine.Wpf.ViewModels
|
||||
/// </summary>
|
||||
private void RefreshChartSelectedData()
|
||||
{
|
||||
var ChartSelectedData = FreeSql.Select<ConfigChartSelect>().Include(a => a.ConfigChartYAxis).ToList();
|
||||
var ChartSelectedData = FreeSql.Select<ConfigChart>().Where(a => a.Machine == CurSelectedMachine && a.GroupTabIndex == CurGroupTabIndex).Include(a => a.ConfigChartYAxis).ToList();
|
||||
ChartSelectDataListViewItems.Clear();
|
||||
var Index = 1;
|
||||
foreach (var item in ChartSelectedData)
|
||||
{
|
||||
//序号变成硬编码
|
||||
item.Index = Index;
|
||||
ChartSelectDataListViewItems.Add(Mapper.Map<ChartSelectDto>(item));
|
||||
|
||||
Index++;
|
||||
}
|
||||
|
||||
//选中后源数据状态被选中
|
||||
@@ -126,7 +135,6 @@ namespace CapMachine.Wpf.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//SelectedChartSelectData = null;
|
||||
|
||||
//Mapper.Map<List<ChartSelectDto>>(data);
|
||||
@@ -266,12 +274,14 @@ namespace CapMachine.Wpf.ViewModels
|
||||
}
|
||||
|
||||
//数据库增加
|
||||
FreeSql.Insert<ConfigChartSelect>(new ConfigChartSelect()
|
||||
FreeSql.Insert<ConfigChart>(new ConfigChart()
|
||||
{
|
||||
Name = SelectedChartSrcData.Name,
|
||||
Category = "Default",
|
||||
Index = 1,
|
||||
ConfigChartYAxis = new ConfigChartYAxis() { Name = "无单位", Unit = "无" },
|
||||
Machine = CurSelectedMachine,
|
||||
GroupTabIndex = CurGroupTabIndex,
|
||||
Index = ChartSelectDataListViewItems.Count + 1,
|
||||
ConfigChartYAxis = GetDefaultYAxis(SelectedChartSrcData.Name),
|
||||
ConfigChartYAxisId = GetDefaultYAxis(SelectedChartSrcData.Name).Id,
|
||||
}).ExecuteAffrows();
|
||||
|
||||
//刷新图表
|
||||
@@ -286,8 +296,8 @@ namespace CapMachine.Wpf.ViewModels
|
||||
if (SelectedChartSelectData != null)
|
||||
{
|
||||
//数据库删除
|
||||
FreeSql.Delete<ConfigChartSelect>()
|
||||
.Where(a => a.Name == SelectedChartSelectData.Name)
|
||||
FreeSql.Delete<ConfigChart>()
|
||||
.Where(a => a.Name == SelectedChartSelectData.Name && a.Machine == CurSelectedMachine && a.GroupTabIndex == CurGroupTabIndex)
|
||||
.ExecuteAffrows();
|
||||
|
||||
//刷新图表
|
||||
@@ -311,11 +321,104 @@ namespace CapMachine.Wpf.ViewModels
|
||||
/// 获取默认的Y轴设置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private ChartYAxisDto GetDefaultYAxis()
|
||||
private ConfigChartYAxis GetDefaultYAxis()
|
||||
{
|
||||
return new ChartYAxisDto() { Name = "温度", Unit = "℃" };
|
||||
var Default = ChartYAxisDataListViewItems.ToList().FirstOrDefault()!;
|
||||
|
||||
return new ConfigChartYAxis()
|
||||
{
|
||||
Index = Default.Index,
|
||||
Id = Default.Id,
|
||||
Max = Default.Max,
|
||||
Min = Default.Min,
|
||||
Name = Default.Name,
|
||||
Unit = Default.Unit,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据名称获取Y轴设置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private ConfigChartYAxis GetDefaultYAxis(string Name)
|
||||
{
|
||||
foreach (var item in ChartYAxisDataListViewItems)
|
||||
{
|
||||
//匹配单位
|
||||
if (Name.Contains("[") && Name.Contains("]"))
|
||||
{
|
||||
var Unit = MidStrEx(Name, "[", "]");
|
||||
//匹配单位
|
||||
if (Unit == item.Unit)
|
||||
{
|
||||
return new ConfigChartYAxis()
|
||||
{
|
||||
Index = item.Index,
|
||||
Id = item.Id,
|
||||
Max = item.Max,
|
||||
Min = item.Min,
|
||||
Name = item.Name,
|
||||
Unit = item.Unit,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//匹配名称
|
||||
if (Name.Contains(item.Name))
|
||||
{
|
||||
return new ConfigChartYAxis()
|
||||
{
|
||||
Index = item.Index,
|
||||
Id = item.Id,
|
||||
Max = item.Max,
|
||||
Min = item.Min,
|
||||
Name = item.Name,
|
||||
Unit = item.Unit,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//如果都没有的话,就选择第一个
|
||||
var Default = ChartYAxisDataListViewItems.ToList().FirstOrDefault()!;
|
||||
return new ConfigChartYAxis()
|
||||
{
|
||||
Index = Default.Index,
|
||||
Id = Default.Id,
|
||||
Max = Default.Max,
|
||||
Min = Default.Min,
|
||||
Name = Default.Name,
|
||||
Unit = Default.Unit,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 截取中间的字符串
|
||||
/// </summary>
|
||||
/// <param name="sourse"></param>
|
||||
/// <param name="startstr"></param>
|
||||
/// <param name="endstr"></param>
|
||||
/// <returns></returns>
|
||||
private string MidStrEx(string sourse, string startstr, string endstr)
|
||||
{
|
||||
string result = string.Empty;
|
||||
int startindex, endindex;
|
||||
try
|
||||
{
|
||||
startindex = sourse.IndexOf(startstr);
|
||||
if (startindex == -1)
|
||||
return result;
|
||||
string tmpstr = sourse.Substring(startindex + startstr.Length);
|
||||
endindex = tmpstr.IndexOf(endstr);
|
||||
if (endindex == -1)
|
||||
return result;
|
||||
result = tmpstr.Remove(endindex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Log.WriteLog("MidStrEx Err:" + ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private DelegateCommand<string> _ChartYAxisSelectCmd;
|
||||
/// <summary>
|
||||
@@ -358,7 +461,7 @@ namespace CapMachine.Wpf.ViewModels
|
||||
}
|
||||
|
||||
//数据库保存
|
||||
FreeSql.Update<ConfigChartSelect>()
|
||||
FreeSql.Update<ConfigChart>()
|
||||
.Where(a => a.Id == SelectedChartSelectData.Id)
|
||||
.Set(a => a.ConfigChartYAxisId, SelectedChartYAxisData.Id)
|
||||
.ExecuteAffrows();
|
||||
@@ -562,6 +665,8 @@ namespace CapMachine.Wpf.ViewModels
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void SaveCmdMethod()
|
||||
{
|
||||
|
||||
|
||||
DialogParameters pars = new DialogParameters
|
||||
{
|
||||
{ "Name", Name }
|
||||
@@ -572,7 +677,7 @@ namespace CapMachine.Wpf.ViewModels
|
||||
|
||||
private DelegateCommand cancelCmd;
|
||||
/// <summary>
|
||||
/// 保存命令
|
||||
/// 取消命令
|
||||
/// </summary>
|
||||
public DelegateCommand CancelCmd
|
||||
{
|
||||
@@ -608,7 +713,8 @@ namespace CapMachine.Wpf.ViewModels
|
||||
/// <param name="parameters"></param>
|
||||
public override void OnDialogOpened(IDialogParameters parameters)
|
||||
{
|
||||
var info = parameters.GetValue<string>("par");
|
||||
CurGroupTabIndex = parameters.GetValue<int>("TabIndex");
|
||||
RefreshChartSelectedData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user