|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Threading;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Windows.Input;
|
|
|
using GummingCommon;
|
|
|
using GummingEntity;
|
|
|
using GummingSupport;
|
|
|
using GummingControl;
|
|
|
using System.Text;
|
|
|
using GummingBusiness;
|
|
|
using Newtonsoft.Json;
|
|
|
using GummingLine;
|
|
|
|
|
|
namespace Gumming
|
|
|
{
|
|
|
public class DispenseViewModule : ViewModelBase
|
|
|
{
|
|
|
#region base parameters
|
|
|
private int rows = 20;
|
|
|
private int pagenumber = 1;
|
|
|
public DispenseView View { get; set; }
|
|
|
private bool IsConfirm;
|
|
|
private bool isLoading;
|
|
|
private List<ComboEntity> modes;
|
|
|
private List<HardFormulaDispenseEntity> CopyDispenses;
|
|
|
#endregion
|
|
|
|
|
|
#region constructor
|
|
|
public DispenseViewModule()
|
|
|
{
|
|
|
View = new DispenseView();
|
|
|
View.DataContext = this;
|
|
|
|
|
|
InitializeCommands();
|
|
|
InitializeParameters();
|
|
|
}
|
|
|
|
|
|
private void InitializeCommands()
|
|
|
{
|
|
|
NewCommand = new DelegateCommand(OnNewCommand);
|
|
|
AddStepCommand = new DelegateCommand(OnAddStepCommand);
|
|
|
InsertStepCommand = new DelegateCommand(OnInsertStepCommand);
|
|
|
DeleteStepCommand = new DelegateCommand(OnDeleteStepCommand);
|
|
|
SaveStepCommand = new DelegateCommand(OnSaveStepCommand);
|
|
|
AllowCommand = new DelegateCommand(OnAllowCommand);
|
|
|
SelectStepCommand = new DelegateCommand(OnSelectStepCommand);
|
|
|
CopyStepCommand = new DelegateCommand(OnCopyStepCommand);
|
|
|
DisabledCommand = new DelegateCommand(OnDisabledCommand);
|
|
|
UnitClickCommand = new DelegateCommand(OnUnitClickCommand);
|
|
|
SelectFlowCommand = new DelegateCommand(OnSelectFlowCommand);
|
|
|
}
|
|
|
|
|
|
public override void InitializeParameters(object content = null)
|
|
|
{
|
|
|
IsConfirm = false;
|
|
|
WindowTitle = "";
|
|
|
AllowEdit = false;
|
|
|
CreateBy = Global.CurrentUserCode;
|
|
|
CopyDispenses = JsonConvert.DeserializeObject<List<HardFormulaDispenseEntity>>(JsonConvert.SerializeObject(Global.Dispenses));
|
|
|
Dispenses = new ObservableCollection<HardFormulaDispenseEntity>();
|
|
|
modes = new List<ComboEntity>();
|
|
|
modes.Clear();
|
|
|
modes.Add(new ComboEntity() { ComboCode = "None", ComboName = "", RecId = "0", Tag = 0 });
|
|
|
modes.Add(new ComboEntity() { ComboCode = "Interval", ComboName = "Interval", RecId = "1", Tag = 1 });
|
|
|
StartLoadFlow();
|
|
|
}
|
|
|
|
|
|
~DispenseViewModule()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
public void LoadDefaultValue()
|
|
|
{
|
|
|
LoadFlowUnit(false);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Binding Properties
|
|
|
public string WindowTitle { get; private set; }
|
|
|
|
|
|
private ObservableCollection<ComboEntity> _StationCodes;
|
|
|
public ObservableCollection<ComboEntity> StationCodes
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _StationCodes;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_StationCodes = value;
|
|
|
OnPropertyChanged("StationCodes");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ComboEntity _SelectedStationCode;
|
|
|
public ComboEntity SelectedStationCode
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _SelectedStationCode;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_SelectedStationCode = value;
|
|
|
OnPropertyChanged("SelectedStationCode");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ObservableCollection<HardFormulaDispenseEntity> _Dispenses;
|
|
|
public ObservableCollection<HardFormulaDispenseEntity> Dispenses
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _Dispenses;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_Dispenses = value;
|
|
|
OnPropertyChanged("Dispenses");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private HardFormulaDispenseEntity _SelectedDispense;
|
|
|
public HardFormulaDispenseEntity SelectedDispense
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _SelectedDispense;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_SelectedDispense = value;
|
|
|
OnPropertyChanged("SelectedDispense");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private string _StationCode;
|
|
|
public string StationCode
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _StationCode;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_StationCode = value;
|
|
|
OnPropertyChanged("StationCode");
|
|
|
}
|
|
|
}
|
|
|
private string _CreateBy;
|
|
|
public string CreateBy
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _CreateBy;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_CreateBy = value;
|
|
|
OnPropertyChanged("CreateBy");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private HardStationType _SelectedFormulaType;
|
|
|
public HardStationType SelectedFormulaType
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _SelectedFormulaType;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_SelectedFormulaType = value;
|
|
|
OnPropertyChanged("SelectedFormulaType");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private HardFormulaEntity _SelectedFormula;
|
|
|
public HardFormulaEntity SelectedFormula
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _SelectedFormula;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_SelectedFormula = value;
|
|
|
OnPropertyChanged("SelectedFormula");
|
|
|
}
|
|
|
}
|
|
|
private ComboEntity _SelecedMode;
|
|
|
public ComboEntity SelecedMode
|
|
|
{
|
|
|
get { return _SelecedMode; }
|
|
|
set
|
|
|
{
|
|
|
_SelecedMode = value;
|
|
|
OnPropertyChanged("SelecedMode");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<ComboEntity> _Modes;
|
|
|
public List<ComboEntity> Modes
|
|
|
{
|
|
|
get { return _Modes; }
|
|
|
set
|
|
|
{
|
|
|
_Modes = value;
|
|
|
OnPropertyChanged("Modes");
|
|
|
}
|
|
|
}
|
|
|
private bool _AllowEdit;
|
|
|
public bool AllowEdit
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _AllowEdit;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_AllowEdit = value;
|
|
|
OnPropertyChanged("AllowEdit");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Binding Commands
|
|
|
private ICommand _NewCommand;
|
|
|
public ICommand NewCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _NewCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_NewCommand = value;
|
|
|
OnPropertyChanged("NewCommand");
|
|
|
}
|
|
|
}
|
|
|
private ICommand _AddStepCommand;
|
|
|
public ICommand AddStepCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _AddStepCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_AddStepCommand = value;
|
|
|
OnPropertyChanged("AddStepCommand");
|
|
|
}
|
|
|
}
|
|
|
private ICommand _DeleteStepCommand;
|
|
|
public ICommand DeleteStepCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _DeleteStepCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_DeleteStepCommand = value;
|
|
|
OnPropertyChanged("DeleteStepCommand");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ICommand _SaveStepCommand;
|
|
|
public ICommand SaveStepCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _SaveStepCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_SaveStepCommand = value;
|
|
|
OnPropertyChanged("SaveStepCommand");
|
|
|
}
|
|
|
}
|
|
|
private ICommand _AllowCommand;
|
|
|
public ICommand AllowCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _AllowCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_AllowCommand = value;
|
|
|
OnPropertyChanged("AllowCommand");
|
|
|
}
|
|
|
}
|
|
|
private ICommand _InsertStepCommand;
|
|
|
public ICommand InsertStepCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _InsertStepCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_InsertStepCommand = value;
|
|
|
OnPropertyChanged("InsertStepCommand");
|
|
|
}
|
|
|
}
|
|
|
private ICommand _SelectStepCommand;
|
|
|
public ICommand SelectStepCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _SelectStepCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_SelectStepCommand = value;
|
|
|
OnPropertyChanged("SelectStepCommand");
|
|
|
}
|
|
|
}
|
|
|
private ICommand _CopyStepCommand;
|
|
|
public ICommand CopyStepCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _CopyStepCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_CopyStepCommand = value;
|
|
|
OnPropertyChanged("CopyStepCommand");
|
|
|
}
|
|
|
}
|
|
|
private ICommand _DisabledCommand;
|
|
|
public ICommand DisabledCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _DisabledCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_DisabledCommand = value;
|
|
|
OnPropertyChanged("DisabledCommand");
|
|
|
}
|
|
|
}
|
|
|
private ICommand _UnitClickCommand;
|
|
|
public ICommand UnitClickCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _UnitClickCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_UnitClickCommand = value;
|
|
|
OnPropertyChanged("UnitClickCommand");
|
|
|
}
|
|
|
}
|
|
|
private ICommand _SelectFlowCommand;
|
|
|
public ICommand SelectFlowCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _SelectFlowCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_SelectFlowCommand = value;
|
|
|
OnPropertyChanged("SelectFlowCommand");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Private Methods
|
|
|
public void StartLoadFlow()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
isLoading = true;
|
|
|
StationCodes = new ObservableCollection<ComboEntity>();
|
|
|
StationCodes.Add(new ComboEntity() { RecId = Constant.COT1, ComboCode = Constant.COT1, ComboName= Constant.COT1 });
|
|
|
StationCodes.Add(new ComboEntity() { RecId = Constant.COT2, ComboCode = Constant.COT2, ComboName = Constant.COT2 });
|
|
|
StationCodes.Add(new ComboEntity() { RecId = Constant.COT3, ComboCode = Constant.COT3, ComboName = Constant.COT3 });
|
|
|
StationCodes.Add(new ComboEntity() { RecId = Constant.COT4, ComboCode = Constant.COT4, ComboName = Constant.COT4 });
|
|
|
StationCodes.Add(new ComboEntity() { RecId = Constant.DEV1, ComboCode = Constant.DEV1, ComboName = Constant.DEV1 });
|
|
|
StationCodes.Add(new ComboEntity() { RecId = Constant.DEV2, ComboCode = Constant.DEV2, ComboName = Constant.DEV2 });
|
|
|
StationCodes.Add(new ComboEntity() { RecId = Constant.DEV3, ComboCode = Constant.DEV3, ComboName = Constant.DEV3 });
|
|
|
StationCodes.Add(new ComboEntity() { RecId = Constant.DEV4, ComboCode = Constant.DEV4, ComboName = Constant.DEV4 });
|
|
|
View.Dispatcher.Invoke((Action)(() =>
|
|
|
{
|
|
|
OnPropertyChanged("StationCodes");
|
|
|
isLoading = false;
|
|
|
}));
|
|
|
if (StationCodes != null && StationCodes.Count > 0)
|
|
|
{
|
|
|
SelectedStationCode = StationCodes[0];
|
|
|
LoadFlowUnit(false);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
OnNewCommand(null);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogService.WriteErrorLog(ex);
|
|
|
ShowErrorBox("Error:" + ex.Message);
|
|
|
return;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
CloseProgressView();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void LoadFlowUnit(bool force)
|
|
|
{
|
|
|
if (SelectedStationCode != null)
|
|
|
{
|
|
|
string flowId = SelectedStationCode.RecId;
|
|
|
StationCode = SelectedStationCode.ComboCode;
|
|
|
Dispenses.Clear();
|
|
|
if (force)
|
|
|
{
|
|
|
var stations = Global.Dispenses.FindAll(q=>q.StationCode == StationCode);
|
|
|
CopyDispenses.RemoveAll(q=>q.StationCode == StationCode);
|
|
|
for (int i = 0; i < stations.Count(); i++)
|
|
|
{
|
|
|
CopyDispenses.Add((HardFormulaDispenseEntity)stations[i].Clone());
|
|
|
}
|
|
|
}
|
|
|
var logs = CopyDispenses.Where(q => q.StationCode == StationCode).OrderBy(q => q.RecId);
|
|
|
View.Dispatcher.Invoke((Action)(() =>
|
|
|
{
|
|
|
foreach (var s in logs)
|
|
|
{
|
|
|
s.Modes = modes;
|
|
|
s.SelecedMode = s.Modes.FirstOrDefault(q => q.Tag == s.Mode);
|
|
|
if (s.Copy == null || force)
|
|
|
{
|
|
|
s.Copy = (HardFormulaDispenseEntity)s.Clone();
|
|
|
}
|
|
|
Dispenses.Add(s);
|
|
|
}
|
|
|
OnPropertyChanged("Dispenses");
|
|
|
isLoading = false;
|
|
|
}));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void OnAddStepCommand(Object sender)
|
|
|
{
|
|
|
}
|
|
|
private void OnInsertStepCommand(Object sender)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
private void OnDeleteStepCommand(Object sender)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
private void OnSaveStepCommand(Object sender)
|
|
|
{
|
|
|
foreach (var s in Dispenses.Where(q => q.StationCode == StationCode))
|
|
|
{
|
|
|
s.Mode = s.SelecedMode?.Tag;
|
|
|
s.Copy = (HardFormulaDispenseEntity)s.Clone();
|
|
|
HardFormulaDispenseDA.Update(s);
|
|
|
|
|
|
var dispenseSource = Global.Dispenses.FirstOrDefault(q=>q.RecId == s.RecId);
|
|
|
if (dispenseSource != null)
|
|
|
{
|
|
|
dispenseSource = s;
|
|
|
}
|
|
|
var dispenseSource2 = CopyDispenses.FirstOrDefault(q => q.RecId == s.RecId);
|
|
|
if (dispenseSource2 != null)
|
|
|
{
|
|
|
dispenseSource2 = s;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//ˢ<><CBA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
var dispense = HardFormulaDispenseDA.Load(new PagerEntity() { PageIndex = 1, Rows = 999, Conditions = " and 1=1 " });
|
|
|
Global.Dispenses = (List<HardFormulaDispenseEntity>)dispense.rows;
|
|
|
AllowEdit = false;
|
|
|
}
|
|
|
|
|
|
private void OnAllowCommand(Object sender)
|
|
|
{
|
|
|
AllowEdit = true;
|
|
|
}
|
|
|
|
|
|
private void OnDisabledCommand(Object sender)
|
|
|
{
|
|
|
AllowEdit = false;
|
|
|
LoadFlowUnit(true);
|
|
|
}
|
|
|
|
|
|
private void OnSelectStepCommand(Object sender)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
private void OnCopyStepCommand(Object sender)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
private void OnUnitClickCommand(Object sender)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
private void OnSelectFlowCommand(Object sender)
|
|
|
{
|
|
|
LoadFlowUnit(false);
|
|
|
}
|
|
|
private void OnNewCommand(Object sender)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
}
|