添加项目文件。
This commit is contained in:
@@ -0,0 +1,656 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Models.Const;
|
||||
using Models.Models;
|
||||
using SamplePre.Common;
|
||||
using SamplePre.Models;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.Models.Models;
|
||||
using SamplePre.ProcessBll.BLL;
|
||||
using SamplePre.ProcessBll.SampleSequence;
|
||||
using SamplePre.UIWpf.ParamManager.chirld;
|
||||
using SamplePre.UIWpf.SampleManager.chirld;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using static MaterialDesignThemes.Wpf.Theme.ToolBar;
|
||||
|
||||
namespace SamplePreSystem.UI.ViewModel.SampleManager
|
||||
{
|
||||
public partial class SampleExecViewModel : ObservableObject
|
||||
{
|
||||
SampleSequenceBll sampleSequenceBll = new SampleSequenceBll();
|
||||
|
||||
CommunicationBll communicationBll = new CommunicationBll();
|
||||
|
||||
MonitorBll monitorBll = new MonitorBll();
|
||||
|
||||
// 关闭窗口的委托
|
||||
public Action<bool> CloseAction { get; set; }
|
||||
|
||||
public SampleExecViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
private tube_input _tubeInput = new tube_input();
|
||||
/// <summary>
|
||||
/// 样品录入实体
|
||||
/// </summary>
|
||||
public tube_input TubeInput
|
||||
{
|
||||
get { return _tubeInput; }
|
||||
set {
|
||||
SetProperty(ref _tubeInput, value);
|
||||
}
|
||||
}
|
||||
|
||||
private List<sys_dict> _sampleTypeDict;
|
||||
|
||||
/// <summary>
|
||||
/// 样品类型字典
|
||||
/// </summary>
|
||||
public List<sys_dict> SampleTypeDict
|
||||
{
|
||||
get { return _sampleTypeDict; }
|
||||
set {
|
||||
SetProperty(ref _sampleTypeDict, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化绑定下拉框数据
|
||||
/// </summary>
|
||||
public void InitComboxData()
|
||||
{
|
||||
//绑定样本类型
|
||||
SampleTypeDict = SystemConst.dictDatas.Where(p => p.class_id == 3).ToList();
|
||||
|
||||
//二维码样本序号
|
||||
string strdate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
|
||||
TubeInput.qrcode = strdate + GetQrcode();
|
||||
|
||||
}
|
||||
|
||||
private List<sys_standard_ext> _standardList = new List<sys_standard_ext>();
|
||||
|
||||
/// <summary>
|
||||
/// 执行标准列表
|
||||
/// </summary>
|
||||
public List<sys_standard_ext> StandardList
|
||||
{
|
||||
get { return _standardList; }
|
||||
set {
|
||||
SetProperty(ref _standardList, value);
|
||||
}
|
||||
}
|
||||
|
||||
private sys_standard _selectStandard;
|
||||
|
||||
/// <summary>
|
||||
/// 选中的标准
|
||||
/// </summary>
|
||||
public sys_standard SelectStandard
|
||||
{
|
||||
get { return _selectStandard; }
|
||||
set {
|
||||
SetProperty(ref _selectStandard, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private sys_dict _selectSampleType;
|
||||
|
||||
public sys_dict SelectSampleType
|
||||
{
|
||||
get { return _selectSampleType; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _selectSampleType, value);
|
||||
//绑定标准
|
||||
BangdingComboxStandard();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 绑定执行标准下拉框
|
||||
/// </summary>
|
||||
public void BangdingComboxStandard()
|
||||
{
|
||||
|
||||
if (SelectSampleType == null) return;
|
||||
|
||||
StandardList.Clear();
|
||||
|
||||
List<sys_standard_ext> templist = new List<sys_standard_ext>();
|
||||
|
||||
var standardList_temp = sampleSequenceBll.QuerySysStandards(SelectSampleType.id);
|
||||
foreach(var item in standardList_temp)
|
||||
{
|
||||
sys_standard_ext ext = new sys_standard_ext();
|
||||
ext.id = item.id;
|
||||
ext.IsSelected = false;
|
||||
ext.standard_name = item.standard_name;
|
||||
ext.sample_id = item.sample_id;
|
||||
|
||||
templist.Add(ext);
|
||||
}
|
||||
|
||||
StandardList = templist;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 二维码编号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetQrcode()
|
||||
{
|
||||
//string qrcode = dbHepler.QueryQrcode();
|
||||
string qrcode = sampleSequenceBll.QueryQrcode();
|
||||
|
||||
if (string.IsNullOrEmpty(qrcode))
|
||||
{
|
||||
MessageBox.Show("二维码编号获取失败!");
|
||||
}
|
||||
|
||||
return qrcode;
|
||||
}
|
||||
|
||||
private List<tube_input> _tubeInputs = new List<tube_input>();
|
||||
|
||||
public List<tube_input> TubeInputs
|
||||
{
|
||||
get { return _tubeInputs; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _tubeInputs, value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取样品批次
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetBathNo()
|
||||
{
|
||||
//批次号
|
||||
string bachNo = "";
|
||||
|
||||
|
||||
if (TubeInputs == null || TubeInputs.Count <= 0)
|
||||
{
|
||||
//产生新的批次
|
||||
bachNo = DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
bachNo = TubeInputs[0].bach_no;
|
||||
}
|
||||
|
||||
//设置新的批次
|
||||
TubeInput.bach_no = bachNo;
|
||||
|
||||
return bachNo;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存样品
|
||||
/// </summary>
|
||||
public bool SaveSample()
|
||||
{
|
||||
List<tube_input> tempList = new List<tube_input>();
|
||||
|
||||
////二维码序号
|
||||
int sqno = int.Parse(TubeInput.qrcode.Substring(8));// int.Parse(txtSampleSeqno2.Text);
|
||||
string strDate = TubeInput.qrcode.Substring(0, 8);
|
||||
for (int i = 0; i < TubeInput.tube_count; i++)
|
||||
{
|
||||
tube_input qRcode = new tube_input();
|
||||
qRcode.qrcode = strDate + sqno.ToString(); //TubeInput.qrcode;
|
||||
qRcode.item_name = TubeInput.item_name;
|
||||
//qRcode.seqno = txtSampleSeqno.Text + txtSampleSeqno2.Text;
|
||||
//执行标准
|
||||
//ComboBoxListItem item1 = SelectStandard.//cmbStrand.SelectedItem as ComboBoxListItem;
|
||||
|
||||
List<string> ids = new List<string>();
|
||||
List<string> standNames = new List<string>();
|
||||
foreach (var item in StandardList)
|
||||
{
|
||||
if(item.IsSelected)
|
||||
{
|
||||
ids.Add(item.id);
|
||||
standNames.Add(item.standard_name);
|
||||
}
|
||||
}
|
||||
qRcode.standrad_id = string.Join(",", ids.ToArray());
|
||||
qRcode.standrad = string.Join(",", standNames.ToArray());
|
||||
|
||||
|
||||
|
||||
qRcode.input_user = TubeInput.input_user;
|
||||
qRcode.input_date = DateTime.Now;
|
||||
//试管类型
|
||||
//ComboBoxListItem item = cmbTubeType.SelectedItem as ComboBoxListItem;
|
||||
qRcode.bach_no = TubeInput.bach_no;
|
||||
|
||||
//qRcode.weight = textBox5.Text;
|
||||
qRcode.tube_count = TubeInput.tube_count; //int.Parse(txtCount.Text);
|
||||
|
||||
//保持数据库
|
||||
sys_dict sys_Dict = new sys_dict();
|
||||
//int sqno = int.Parse(txtSampleSeqno2.Text);
|
||||
sys_Dict.data_value = sqno.ToString();
|
||||
sqno++;
|
||||
//放入list
|
||||
tempList.Add(qRcode);
|
||||
|
||||
|
||||
//保存数据,更新二维码编号
|
||||
if (sampleSequenceBll.SaveDataAndQrcode(qRcode, sys_Dict) <= 0)
|
||||
{
|
||||
MessageBox.Show("保存失败!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//MessageBox.Show("保存成功!");
|
||||
|
||||
//合并已有数据
|
||||
tempList.AddRange(TubeInputs);
|
||||
//通知更新
|
||||
TubeInputs = tempList;
|
||||
|
||||
return true;
|
||||
|
||||
//this.DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
|
||||
private tube_input _selectSample;
|
||||
|
||||
/// <summary>
|
||||
/// 选中的样品
|
||||
/// </summary>
|
||||
public tube_input SelectSample
|
||||
{
|
||||
get { return _selectSample; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _selectSample, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除样品
|
||||
/// </summary>
|
||||
public void DeleSelectSample()
|
||||
{
|
||||
|
||||
tube_input[] tube_Inputs = new tube_input[TubeInputs.Count];
|
||||
|
||||
TubeInputs.CopyTo(tube_Inputs);
|
||||
|
||||
if (SelectSample != null)
|
||||
{
|
||||
if (MessageBox.Show($"确定删除:{SelectSample.qrcode}", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||||
{
|
||||
|
||||
sampleSequenceBll.DelTubeInputByCode(SelectSample.qrcode);
|
||||
|
||||
var tubes = tube_Inputs.ToList();
|
||||
tubes.Remove(SelectSample);
|
||||
|
||||
TubeInputs = tubes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<sample_exec_ext> _cmdList = new List<sample_exec_ext>();
|
||||
|
||||
public List<sample_exec_ext> CmdList
|
||||
{
|
||||
get { return _cmdList; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _cmdList, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建指令集合
|
||||
/// </summary>
|
||||
public void CreateCmdList()
|
||||
{
|
||||
List<sample_exec_ext> temp_CmdList = new List<sample_exec_ext>();
|
||||
|
||||
//this.tubes = gridSamples.DataSource as List<tube_input>;
|
||||
|
||||
var groups = TubeInputs.GroupBy(p => new { p.standrad_id, p.standrad });
|
||||
|
||||
foreach (var g in groups)
|
||||
{
|
||||
sample_exec_ext sampleCmdExec = new sample_exec_ext();
|
||||
sampleCmdExec.id = Guid.NewGuid().ToString();
|
||||
sampleCmdExec.standrad_id = g.Key.standrad_id;
|
||||
sampleCmdExec.standradName = g.Key.standrad;
|
||||
|
||||
List<sample_exec_detail> details = new List<sample_exec_detail>();
|
||||
foreach (var item in g)
|
||||
{
|
||||
sampleCmdExec.sample_count++;
|
||||
sampleCmdExec.qrcodes += item.qrcode + "|";
|
||||
sample_exec_detail sample_Exec_Detail = new sample_exec_detail();
|
||||
details.Add(new sample_exec_detail() { master_id = sampleCmdExec.id, qrcode = item.qrcode });
|
||||
}
|
||||
|
||||
sampleCmdExec.sampleExecDetails = details;
|
||||
sampleCmdExec.exec_state = "未执行";
|
||||
temp_CmdList.Add(sampleCmdExec);
|
||||
|
||||
}
|
||||
CmdList = temp_CmdList;
|
||||
//BadingSopData(cmds);
|
||||
}
|
||||
|
||||
private sample_exec_ext _selectItemCmd;
|
||||
|
||||
public sample_exec_ext SelectItemCmd
|
||||
{
|
||||
get { return _selectItemCmd; }
|
||||
set {
|
||||
|
||||
SetProperty(ref _selectItemCmd,value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<string> sopList = new List<string>();
|
||||
/// <summary>
|
||||
/// 初始化指令集合
|
||||
/// </summary>
|
||||
public void InitCmdData()
|
||||
{
|
||||
actionParmList.Clear();
|
||||
sopList.Clear();
|
||||
|
||||
if (SelectItemCmd.standrad_id.Contains(","))
|
||||
{
|
||||
string[] standradIds = SelectItemCmd.standrad_id.Split(',');
|
||||
sopList.AddRange(standradIds);
|
||||
|
||||
foreach (var id in standradIds)
|
||||
{
|
||||
CreateData(id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sopList.Add(SelectItemCmd.standrad_id);
|
||||
CreateData(SelectItemCmd.standrad_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void CreateData(string standrad_id)
|
||||
{
|
||||
//查询标准下的动作
|
||||
var standardActions = sampleSequenceBll.GetStrandActionByStrandId(standrad_id);
|
||||
//动作排序
|
||||
standardActions = standardActions.OrderBy(p => p.process_no).ToList(); ;
|
||||
|
||||
//查询动作参数
|
||||
var sys_standard_process_parms = sampleSequenceBll.GetStrandActionParamByStrandId(standrad_id);
|
||||
|
||||
|
||||
if (sys_standard_process_parms.Count <= 0)
|
||||
{
|
||||
MessageBox.Show("没有流程数据!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
GetData(standardActions, sys_standard_process_parms);
|
||||
}
|
||||
|
||||
public void GetData(List<sys_standard_action_ext> actions, List<sys_standard_action_parm_ext> standardProcessParmList)
|
||||
{
|
||||
|
||||
foreach (var actionItem in actions)
|
||||
{
|
||||
//判断是否有重复的【进样】动作
|
||||
if (actionItem.action_name == "进样" && actionParmList.Find(p => p.action_name == "进样") != null)
|
||||
{
|
||||
continue; //跳过
|
||||
}
|
||||
|
||||
//查询动作下的参数配置
|
||||
var paramData = standardProcessParmList.Where(p => p.action_id == actionItem.process_id && p.action_seqno == actionItem.process_no).ToList();
|
||||
if (paramData.Count <= 0)
|
||||
{
|
||||
sys_standard_action_parm_ext temp = new sys_standard_action_parm_ext();
|
||||
temp.action_name = actionItem.action_name;
|
||||
temp.action_seqno = actionItem.process_no;
|
||||
temp.title = "无";
|
||||
actionParmList.Add(temp);
|
||||
continue;
|
||||
}
|
||||
|
||||
actionParmList.AddRange(paramData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<sys_standard_action_parm_ext> actionParmList = new List<sys_standard_action_parm_ext>();
|
||||
|
||||
public List<sys_standard_action_parm_ext> ActionParmList
|
||||
{
|
||||
get { return actionParmList; }
|
||||
set {
|
||||
SetProperty(ref actionParmList, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string sopStr = "";
|
||||
public void CmdDo()
|
||||
{
|
||||
if (!CmdExec()) return;
|
||||
|
||||
//保存下发记录
|
||||
|
||||
SelectItemCmd.exec_state = "执行中";
|
||||
SelectItemCmd.cmd_content = sopStr;
|
||||
SelectItemCmd.exec_date = DateTime.Now;
|
||||
MessageBox.Show("下发成功!");
|
||||
//保存主表
|
||||
sampleSequenceBll.SaveCmdExec(SelectItemCmd);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送测试指令
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private bool CmdExec()
|
||||
{
|
||||
//查询所有动作
|
||||
List<sys_action_ext> sysAction = sampleSequenceBll.QuerySysAction();
|
||||
////查询所有参数,及修改
|
||||
List<sys_standard_action_parm_ext> standardProcessParms = actionParmList;// GetEditVal();
|
||||
if (standardProcessParms == null)
|
||||
{
|
||||
//MessageBox.Show("指令生成错误!");
|
||||
return false;
|
||||
}
|
||||
sopStr = "";
|
||||
|
||||
//S7协议
|
||||
List<byte> sop = sampleSequenceBll.CreateCmdBytes(sysAction, sopList, standardProcessParms);
|
||||
|
||||
////modbus协议
|
||||
//List<ushort> sop = this.sampleSequenceBll.CreateCmdUshorts(sysAction, standardActions, standardProcessParms);
|
||||
|
||||
if (sop == null)
|
||||
{
|
||||
MessageBox.Show("指令生成错误!");
|
||||
return false;
|
||||
}
|
||||
|
||||
sopStr = string.Join("-", sop.ToArray());
|
||||
|
||||
//写入PLC
|
||||
bool val = communicationBll.WritePlcData(100, 0, sop.ToArray());
|
||||
|
||||
//bool val = monitorBll.WritePlcData(1, 0, sop.ToArray());
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 总复位
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void InitPlcState()
|
||||
{
|
||||
Task.Run(() => {
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
int a = i+1;
|
||||
communicationBll.WriteSingleData("DB19.DBX0.0", true);
|
||||
Task.Delay(1000).Wait();
|
||||
LoggerHelper.Logger.Error("发生复位指令");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 导入样品
|
||||
///// </summary>
|
||||
///// <param name="list"></param>
|
||||
//public void ImportSamples(List<tube_input> list)
|
||||
//{
|
||||
// TubeInputs = list;
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新增样品
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnAddSampleClick()
|
||||
{
|
||||
|
||||
GetBathNo();
|
||||
|
||||
InitComboxData();
|
||||
|
||||
NewSampleWindow frm = new NewSampleWindow(this);
|
||||
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除样品
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnDelSampleClick()
|
||||
{
|
||||
|
||||
DeleSelectSample();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入样品
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnImportSampleClick()
|
||||
{
|
||||
ImportSampleWindow frm = new ImportSampleWindow(this);
|
||||
if (frm.ShowDialog() == true)
|
||||
{
|
||||
//ImportSamples(frm.samples);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建指令
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnCreateCmdClick()
|
||||
{
|
||||
CreateCmdList();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开命令下发
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void RowDoubleClick()
|
||||
{
|
||||
ActionShowWindow frm = new ActionShowWindow(this);
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 命令下发
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void CmdDoClick()
|
||||
{
|
||||
|
||||
CmdDo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存样本
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void BtnOKClick()
|
||||
{
|
||||
|
||||
if (SaveSample())
|
||||
{
|
||||
this.CloseAction?.Invoke(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user