You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

562 lines
17 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 FormulaCOTViewModule : ViewModelBase
{
#region base parameters
private int rows = 20;
private int pagenumber = 1;
public FormulaCOTView View { get; set; }
private bool IsConfirm;
private bool isLoading;
private List<ArmPrsEntity> armPrs;
private List<ArmEbrEntity> armEbrs;
#endregion
#region constructor
public FormulaCOTViewModule()
{
View = new FormulaCOTView();
View.DataContext = this;
InitializeCommands();
InitializeParameters();
}
private void InitializeCommands()
{
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);
PRCommand = new DelegateCommand(OnPRCommand);
}
public override void InitializeParameters(object content = null)
{
IsConfirm = false;
WindowTitle = "";
AllowEdit = false;
CreateBy = Global.CurrentUserCode;
HardFormulaCOTs = new ObservableCollection<HardFormulaCOTEntity>();
armPrs = new List<ArmPrsEntity>();
armPrs.Clear();
armPrs.Add(new ArmPrsEntity() { ArmPr = "", Tag = 0 });
armPrs.Add(new ArmPrsEntity() { ArmPr = "PR1", Tag = 1 });
armPrs.Add(new ArmPrsEntity() { ArmPr = "PR2", Tag = 2 });
armEbrs = new List<ArmEbrEntity>();
armEbrs.Clear();
armEbrs.Add(new ArmEbrEntity() { ArmEbr = "", Tag = 0 });
armEbrs.Add(new ArmEbrEntity() { ArmEbr = "EBR", Tag = 1 });
//armEbrs.Add(new ArmEbrEntity() { ArmEbr = "EBR2", Tag = 2 });
//Ĭ<><C4AC>׷<EFBFBD><D7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>հײ<D5B0><D7B2><EFBFBD>
InitializeEmptyFormula(false);
}
~FormulaCOTViewModule()
{
}
#endregion
#region Binding Properties
public string WindowTitle { get; private set; }
/// <summary>
/// InjectPosition
/// </summary>
private decimal _InjectPosition;
public decimal InjectPosition
{
get { return _InjectPosition; }
set
{
_InjectPosition = value;
OnPropertyChanged("InjectPosition");
}
}
private ObservableCollection<HardFormulaCOTEntity> _HardFormulaCOTs;
public ObservableCollection<HardFormulaCOTEntity> HardFormulaCOTs
{
get
{
return _HardFormulaCOTs;
}
set
{
_HardFormulaCOTs = value;
OnPropertyChanged("HardFormulaCOTs");
}
}
private HardFormulaCOTEntity _SelectedStep;
public HardFormulaCOTEntity SelectedStep
{
get
{
return _SelectedStep;
}
set
{
_SelectedStep = value;
OnPropertyChanged("SelectedStep");
}
}
private string _FormulaName;
public string FormulaName
{
get
{
return _FormulaName;
}
set
{
_FormulaName = value;
OnPropertyChanged("FormulaName");
}
}
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 bool _AllowEdit;
public bool AllowEdit
{
get
{
return _AllowEdit;
}
set
{
_AllowEdit = value;
OnPropertyChanged("AllowEdit");
}
}
#endregion
#region Binding Commands
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 _PRCommand;
public ICommand PRCommand
{
get
{
return _PRCommand;
}
set
{
_PRCommand = value;
OnPropertyChanged("PRCommand");
}
}
#endregion
#region Private Methods
public void InitializeEmptyFormula(bool canEdit)
{
FormulaName = string.Empty;
AllowEdit = canEdit;
HardFormulaCOTs.Clear();
//Ĭ<><C4AC>׷<EFBFBD><D7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>հײ<D5B0><D7B2><EFBFBD>
for (int i = 0; i < 6; i++)
{
HardFormulaCOTEntity cot = new HardFormulaCOTEntity();
cot.StepIndex = i + 1;
cot.ArmPrs = armPrs;
cot.ArmEbrs = armEbrs;
cot.ArmScanTimer = 1;
cot.MainAxisAcc = 100;
cot.Stillicide = false;
cot.Bsr = false;
cot.ArmUD = false;
cot.Copy = (HardFormulaCOTEntity)cot.Clone();
HardFormulaCOTs.Add(cot);
}
}
public void StartLoadTestItem(string formulaId)
{
try
{
isLoading = true;
HardFormulaCOTs = new ObservableCollection<HardFormulaCOTEntity>();
var record = HardFormulaCOTDA.Load(new PagerEntity() { PageIndex = pagenumber, Rows = rows, Conditions = " and FormulaId='"+ formulaId + "' " });
List<HardFormulaCOTEntity> logs = (List<HardFormulaCOTEntity>)record.rows;
View.Dispatcher.Invoke((Action)(() =>
{
foreach (var s in logs)
{
s.ArmPrs = armPrs;
s.SelecedArmPr = s.ArmPrs.FirstOrDefault(q=>q.Tag == s.ArmPr);
s.ArmEbrs = armEbrs;
s.SelecedArmEbr = s.ArmEbrs.FirstOrDefault(q => q.Tag == s.ArmEbr);
s.Copy = (HardFormulaCOTEntity)s.Clone();
HardFormulaCOTs.Add(s);
}
OnPropertyChanged("HartFormulaCOT");
isLoading = false;
}));
}
catch (Exception ex)
{
LogService.WriteErrorLog(ex);
ShowErrorBox("Error:" + ex.Message);
return;
}
finally
{
CloseProgressView();
}
}
private void OnAddStepCommand(Object sender)
{
if (HardFormulaCOTs.Count == 20)
{
ShowMessageBox("<22><><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>20<32><30>");
return;
}
var cot = new HardFormulaCOTEntity();
cot.StepIndex = HardFormulaCOTs.Count + 1;
cot.ArmPrs = armPrs;
cot.ArmEbrs = armEbrs;
cot.Stillicide = false;
cot.ArmScanTimer = 1;
cot.MainAxisAcc = 100;
cot.Bsr = false;
cot.ArmUD = false;
cot.Copy = (HardFormulaCOTEntity)cot.Clone();
HardFormulaCOTs.Add(cot);
}
private void OnInsertStepCommand(Object sender)
{
if (HardFormulaCOTs.Count == 20)
{
ShowMessageBox("<22><><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>20<32><30>");
return;
}
if (SelectedStep == null)
{
ShowMessageBox("<22><>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٽ<EFBFBD><D9BD>в<EFBFBD><D0B2>룡");
return;
}
int curIndex = HardFormulaCOTs.IndexOf(SelectedStep);
var cot = new HardFormulaCOTEntity();
cot.ArmPrs = armPrs;
cot.ArmEbrs = armEbrs;
cot.ArmScanTimer = 1;
cot.MainAxisAcc = 100;
cot.Stillicide = false;
cot.Bsr = false;
cot.ArmUD = false;
cot.Copy = (HardFormulaCOTEntity)cot.Clone();
HardFormulaCOTs.Insert(curIndex, cot);
for (int i = 0; i < HardFormulaCOTs.Count; i++)
{
HardFormulaCOTs[i].StepIndex = i + 1;
}
}
private void OnDeleteStepCommand(Object sender)
{
if (SelectedStep == null)
{
ShowMessageBox("<22><>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٽ<EFBFBD><D9BD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>");
return;
}
HardFormulaCOTs.Remove(SelectedStep);
for (int i = 0; i < HardFormulaCOTs.Count; i++)
{
HardFormulaCOTs[i].StepIndex = i + 1;
}
}
public void OnSaveStepCommand(Object sender)
{
if (string.IsNullOrWhiteSpace(FormulaName))
{
ShowMessageBox("<22><EFBFBD><E4B7BD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>Ϊ<EFBFBD><CEAA>");
return;
}
if (HardFormulaCOTs.Any(q => q.SelecedArmEbr != null && q.SelecedArmPr != null && q.SelecedArmEbr.Tag != 0 && q.SelecedArmPr.Tag != 0))
{
ShowMessageBox("<22><><EFBFBD><EFBFBD>ͬʱѡ<CAB1><D1A1>PR<50><52>EBR<42><52>");
return;
}
var SafeStartPr = Common.ToDecimal(HardParameters.Read(SelectedFormulaType.StationCode + Constant.PrSafeStart));
var SafeEndPr = Common.ToDecimal(HardParameters.Read(SelectedFormulaType.StationCode + Constant.PrSafeEnd));
var SafeStartEbr = Common.ToDecimal(HardParameters.Read(SelectedFormulaType.StationCode + Constant.EbrSafeStart));
var SafeEndEbr = Common.ToDecimal(HardParameters.Read(SelectedFormulaType.StationCode + Constant.EbrSafeEnd));
for (int i = 0; i < HardFormulaCOTs.Count; i++)
{
var cot = HardFormulaCOTs[i];
var SafeStart = (cot.SelecedArmPr != null && cot.SelecedArmPr.Tag > 0) ? SafeStartPr : SafeStartEbr;
var SafeEnd = (cot.SelecedArmPr != null && cot.SelecedArmPr.Tag > 0) ? SafeEndPr : SafeEndEbr;
if (cot.ArmPosition1 < SafeStart)
{
cot.ArmPosition1 = 0;
ShowMessageBox("<22>ֱ<EFBFBD>λ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD>С<EFBFBD>ڰ<EFBFBD>ȫʼλ");
return;
}
if (cot.ArmPosition2 < SafeStart)
{
cot.ArmPosition2 = 0;
ShowMessageBox("<22>ֱ<EFBFBD>λ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD>С<EFBFBD>ڰ<EFBFBD>ȫʼλ");
return;
}
if (cot.ArmPosition1 > SafeEnd)
{
cot.ArmPosition1 = SafeEnd;
ShowMessageBox("<22>ֱ<EFBFBD>λ<EFBFBD>ò<EFBFBD><C3B2>ܴ<EFBFBD><DCB4>ڰ<EFBFBD>ȫֹλ");
return;
}
if (cot.ArmPosition2 > SafeEnd)
{
cot.ArmPosition2 = SafeEnd;
ShowMessageBox("<22>ֱ<EFBFBD>λ<EFBFBD>ò<EFBFBD><C3B2>ܴ<EFBFBD><DCB4>ڰ<EFBFBD>ȫֹλ");
return;
}
}
HardFormulaEntity hfe = new HardFormulaEntity();
hfe.FormulaCode = FormulaName;
hfe.FormulaName = FormulaName;
hfe.CreateBy = Global.CurrentUserCode;
hfe.StationCode = SelectedFormulaType.StationCode;
hfe.StationName = SelectedFormulaType.StationName;
hfe.StationType = (int)SelectedFormulaType.StationType;
hfe.StillicideAmount = InjectPosition;
hfe.RecId = SelectedFormula?.RecId;
hfe.RecId = HardFormulaDA.Save(hfe, HardFormulaCOTs.ToList());
hfe.CreateTime = DateTime.Now;
SelectedFormula = hfe;
AllowEdit = false;
for (int i = 0; i < HardFormulaCOTs.Count; i++)
{
HardFormulaCOTs[i].Copy = (HardFormulaCOTEntity)HardFormulaCOTs[i].Clone();
}
AppEventAggregator.GetEventAggregator().GetEvent<FormulaChangedEvent>().Publish(new NotifyEventParameter() { NotifyType = CallbackType.Formula, NotifyContent = SelectedFormula });
}
private void OnAllowCommand(Object sender)
{
AllowEdit = true;
}
private void OnDisabledCommand(Object sender)
{
AllowEdit = false;
StartLoadTestItem(SelectedFormula?.RecId);
}
private void OnPRCommand(Object sender)
{
if (StationLockControl.StationIsLock(SelectedFormulaType.StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
ControlCOTPrViewModule ccvm = new ControlCOTPrViewModule();
ccvm.FormulaId = SelectedFormula?.RecId;
ccvm.StationCode = SelectedFormulaType.StationCode;
ccvm.LoadDefaultValue(1);
ccvm.ShowDialog();
}
private void OnSelectStepCommand(Object sender)
{
}
private void OnCopyStepCommand(Object sender)
{
if (HardFormulaCOTs.Count == 20)
{
ShowMessageBox("<22><><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>20<32><30>");
return;
}
if (SelectedStep == null)
{
ShowMessageBox("<22><>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٽ<EFBFBD><D9BD>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD>");
return;
}
var cot = (HardFormulaCOTEntity)SelectedStep.Clone();
cot.ArmPrs = armPrs;
cot.ArmEbrs = armEbrs;
cot.Copy = (HardFormulaCOTEntity)cot.Clone();
HardFormulaCOTs.Add(cot);
for (int i = 0; i < HardFormulaCOTs.Count; i++)
{
HardFormulaCOTs[i].StepIndex = i + 1;
}
}
#endregion
}
}