using System.Collections.Generic;
|
using System.Linq;
|
using TProduct.Model;
|
|
namespace TProduct.WinFrmUI.TestBench
|
{
|
public partial class SetWorkBenchInstrument701Ctrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public SetWorkBenchInstrument701Ctrl()
|
{
|
InitializeComponent();
|
InitialComPortList();
|
}
|
private void InitialComPortList()
|
{
|
var list = System.IO.Ports.SerialPort.GetPortNames();
|
if (list != null && list.Count() > 1)
|
{
|
this.plC701ParasControl1.InitialComPortList(list);
|
|
}
|
else
|
{
|
var names = new List<string>();
|
for (int i = 1; i <= 12; i++)
|
{
|
names.Add(string.Format("COM{0}", i));
|
}
|
this.plC701ParasControl1.InitialComPortList(names);
|
|
}
|
}
|
private List<Model.WorkBenchInstrumentKedi> _instruments = null;
|
private Model.WorkBenchBase _workBench = null;
|
public void SetBindingData(Model.WorkBenchBase workBench)
|
{
|
if (workBench == null)
|
return;
|
_workBench = workBench;
|
_instruments = new List<WorkBenchInstrumentKedi>();
|
//torqueParasControl1.SetBindingData(workBench.LinkTag, null);
|
}
|
|
public void SetBindingData(Model.WorkBenchBase workBench, List<Model.WorkBenchInstrumentKedi> instruments)
|
{
|
if (workBench == null)
|
return;
|
_workBench = workBench;
|
|
if (instruments != null)
|
{
|
foreach (var instrument in instruments)
|
{
|
if (instrument.InstrumentType ==
|
(int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.PLC)
|
{
|
this.plC701ParasControl1.SetBindingData(workBench.LinkTag, instrument);
|
}
|
|
}
|
|
_instruments = instruments;
|
}
|
else
|
{
|
SetBindingData(workBench);
|
}
|
}
|
|
public List<WorkBenchInstrumentKedi> GetData()
|
{
|
if (_workBench == null)
|
return null;
|
if (_instruments == null)
|
_instruments = new List<WorkBenchInstrumentKedi>();
|
|
|
|
|
|
|
var model = _instruments.Find(x => x.InstrumentType ==
|
(int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.PLC);
|
if (model == null)
|
{
|
model = new WorkBenchInstrumentKedi();
|
model.ID = 0; model.BenchID = this._workBench.ID;
|
}
|
model.InstrumentType =
|
(int)TProduct.Model.WorkBenchInstrumentKedi.eKediInstrumentType.PLC;
|
|
model.Reset4UI(this.plC701ParasControl1.GetData());
|
|
if (model.ID == 0)
|
{
|
model.ID = new BLL.WorkBenchInstrumentKedi().Insert(model);
|
_instruments.Add(model);
|
}
|
|
|
|
|
|
return _instruments;
|
}
|
|
|
|
|
}
|
}
|