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.

447 lines
13 KiB

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 FormulaHPViewModule : ViewModelBase
{
#region base parameters
private int rows = 20;
private int pagenumber = 1;
public FormulaHPView View { get; set; }
private bool IsConfirm;
private bool isLoading;
#endregion
#region constructor
public FormulaHPViewModule()
{
View = new FormulaHPView();
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);
}
public override void InitializeParameters(object content = null)
{
IsConfirm = false;
WindowTitle = "";
AllowEdit = false;
CreateBy = Global.CurrentUserCode;
HardFormulaHPs = new ObservableCollection<HardFormulaHPEntity>();
//ĬÈÏ×·¼ÓÁù²½¿Õ°×²½Öè
InitializeEmptyFormula(false);
}
~FormulaHPViewModule()
{
}
#endregion
#region Binding Properties
public string WindowTitle { get; private set; }
private ObservableCollection<HardFormulaHPEntity> _HardFormulaHPs;
public ObservableCollection<HardFormulaHPEntity> HardFormulaHPs
{
get
{
return _HardFormulaHPs;
}
set
{
_HardFormulaHPs = value;
OnPropertyChanged("HardFormulaHPs");
}
}
private HardFormulaHPEntity _SelectedStep;
public HardFormulaHPEntity 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");
}
}
#endregion
#region Private Methods
public void InitializeEmptyFormula(bool canEdit)
{
FormulaName = string.Empty;
AllowEdit = canEdit;
HardFormulaHPs.Clear();
//ĬÈÏ×·¼ÓÁù²½¿Õ°×²½Öè
for (int i = 0; i < 6; i++)
{
HardFormulaHPEntity hp = new HardFormulaHPEntity();
hp.StepIndex = i + 1;
hp.Blow = false;
hp.Cover = false;
hp.Empty = false;
hp.Copy = (HardFormulaHPEntity)hp.Clone();
HardFormulaHPs.Add(hp);
}
}
public void StartLoadTestItem(string formulaId)
{
try
{
isLoading = true;
HardFormulaHPs = new ObservableCollection<HardFormulaHPEntity>();
var record = HardFormulaHPDA.Load(new PagerEntity() { PageIndex = pagenumber, Rows = rows, Conditions = " and FormulaId='"+ formulaId + "' " });
List<HardFormulaHPEntity> logs = (List<HardFormulaHPEntity>)record.rows;
View.Dispatcher.Invoke((Action)(() =>
{
foreach (var s in logs)
{
s.Copy = (HardFormulaHPEntity)s.Clone();
HardFormulaHPs.Add(s);
}
OnPropertyChanged("HartFormulaHP");
isLoading = false;
}));
}
catch (Exception ex)
{
LogService.WriteErrorLog(ex);
ShowErrorBox("Error:" + ex.Message);
return;
}
finally
{
CloseProgressView();
}
}
private void OnAddStepCommand(Object sender)
{
if (HardFormulaHPs.Count == 20)
{
ShowMessageBox("²½Öè²»Äܳ¬¹ý20Ìõ");
return;
}
var hp = new HardFormulaHPEntity();
hp.StepIndex = HardFormulaHPs.Count + 1;
hp.Blow = false;
hp.Cover = false;
hp.Empty = false;
hp.Copy = (HardFormulaHPEntity)hp.Clone();
HardFormulaHPs.Add(hp);
}
private void OnInsertStepCommand(Object sender)
{
if (HardFormulaHPs.Count == 20)
{
ShowMessageBox("²½Öè²»Äܳ¬¹ý20Ìõ");
return;
}
if (SelectedStep == null)
{
ShowMessageBox("ÇëÑ¡ÔñÒ»¸ö²½ÖèÔÙ½øÐвåÈ룡");
return;
}
int curIndex = HardFormulaHPs.IndexOf(SelectedStep);
var hp = new HardFormulaHPEntity();
hp.Blow = false;
hp.Cover = false;
hp.Empty = false;
hp.Copy = (HardFormulaHPEntity)hp.Clone();
HardFormulaHPs.Insert(curIndex, hp);
for (int i = 0; i < HardFormulaHPs.Count; i++)
{
HardFormulaHPs[i].StepIndex = i + 1;
}
}
private void OnDeleteStepCommand(Object sender)
{
if (SelectedStep == null)
{
ShowMessageBox("ÇëÑ¡ÔñÒ»¸ö²½ÖèÔÙ½øÐÐɾ³ý£¡");
return;
}
HardFormulaHPs.Remove(SelectedStep);
for (int i = 0; i < HardFormulaHPs.Count; i++)
{
HardFormulaHPs[i].StepIndex = i + 1;
}
}
public void OnSaveStepCommand(Object sender)
{
if (string.IsNullOrWhiteSpace(FormulaName))
{
ShowMessageBox("Åä·½Ãû³Æ²»ÄÜΪ¿Õ");
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.RecId = SelectedFormula?.RecId;
hfe.RecId = HardFormulaDA.Save(hfe, HardFormulaHPs.ToList());
hfe.CreateTime = DateTime.Now;
SelectedFormula = hfe;
AllowEdit = false;
for (int i = 0; i < HardFormulaHPs.Count; i++)
{
HardFormulaHPs[i].Copy = (HardFormulaHPEntity)HardFormulaHPs[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 OnSelectStepCommand(Object sender)
{
}
private void OnCopyStepCommand(Object sender)
{
if (HardFormulaHPs.Count == 20)
{
ShowMessageBox("²½Öè²»Äܳ¬¹ý20Ìõ");
return;
}
if (SelectedStep == null)
{
ShowMessageBox("ÇëÑ¡ÔñÒ»¸ö²½ÖèÔÙ½øÐп½±´£¡");
return;
}
var hp = (HardFormulaHPEntity)SelectedStep.Clone();
hp.Copy = (HardFormulaHPEntity)hp.Clone();
HardFormulaHPs.Add(hp);
for (int i = 0; i < HardFormulaHPs.Count; i++)
{
HardFormulaHPs[i].StepIndex = i + 1;
}
}
#endregion
}
}