spc-kiosk-pb/Kiosk/Popup/SPC.Kiosk.Popup/OptionSelect.xaml.cs
2019-06-16 14:12:09 +09:00

163 lines
5.4 KiB
C#

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Drawing;
using SPC.Kiosk.Base;
using SPC.Kiosk.Common;
using System.Windows.Threading;
using SPC.Kiosk.Popup.Model;
using SPC.Kiosk.Popup.ViewModel;
namespace SPC.Kiosk.Popup
{
/// <summary>
/// OptionSelect.xaml에 대한 상호 작용 논리
/// </summary>
public partial class OptionSelect : Window
{
#region [ Members ]
private int ScreenNo { get; set; } = 0;
private VmOptionSelect ViewModel { get; set; }
private List<M_Language> GetItemName { get; set; }
private List<M_ItemOptionGroup> GetOptions { get; set; }
private string GetItemImage { get; set; }
private int GetItemCount { get; set; }
private double GetItemPrice { get; set; }
private bool GetEditMode { get; set; }
#endregion Members
#region [ Ctor ]
/// <summary>
/// Ctor
/// </summary>
public OptionSelect(List<M_Language> _getItemName
, List<M_ItemOptionGroup> _getOptions
, string _getItemImage
, int _getItemCount
, double _getItemPrice
, bool _editMode)
{
GetItemName = _getItemName;
GetOptions = _getOptions;
GetItemImage = _getItemImage;
GetItemCount = _getItemCount;
GetItemPrice = _getItemPrice;
GetEditMode = _editMode;
InitializeComponent();
this.ContentRendered += OptionSelect_ContentRendered;
this.Loaded += OptionSelect_Loaded;
this.Left = Screen.AllScreens[ScreenNo].WorkingArea.Left;
this.Top = Screen.AllScreens[ScreenNo].WorkingArea.Top;
this.Width = Screen.AllScreens[ScreenNo].Bounds.Width;
this.Height = Screen.AllScreens[ScreenNo].Bounds.Height;
}
#endregion Ctor
#region [ Methods ]
private void OpenWindow()
{
var OpenAnimations = Animations.GetOpenAnimation(this.FrameBase
, OpenCloseAnimationType.GotoLeft
, this.FrameBase.Width
, 0.5
, 0.2);
if (OpenAnimations != null)
{
OpenAnimations.Begin();
}
}
private void CloseWindow()
{
var CloseAnimation = Animations.GetCloseAnimation(this.FrameBase
, OpenCloseAnimationType.GotoRight
, this.FrameBase.Width
, 0.5
, 0.2);
if (CloseAnimation != null)
{
CloseAnimation.Completed += CloseAnimation_Completed;
CloseAnimation.Begin();
}
}
#endregion Methods
#region [ Event Handlers ]
private void CloseAnimation_Completed(object sender, EventArgs e)
{
this.ContentRendered -= OptionSelect_ContentRendered;
this.Loaded -= OptionSelect_Loaded;
this.ViewModel.Dispose();
this.Close();
}
private void OptionSelect_ContentRendered(object sender, EventArgs e)
{
this.FrameBase.Width = 1300;
this.FrameBase.Height = 1010;
OpenWindow();
}
private void OptionSelect_Loaded(object sender, RoutedEventArgs e)
{
try
{
if (this.DataContext is VmOptionSelect viewModel)
{
ViewModel = viewModel;
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
ViewModel.EditMode = GetEditMode;
ViewModel.ItemName = GetItemName;
ViewModel.Options = GetOptions;
ViewModel.ItemImageBrush = GetItemImage;
ViewModel.ItemCount = GetItemCount;
ViewModel.ItemPrice = GetItemPrice;
ViewModel.IsTimeoutPopup = false;
}
this.FrameBase.Width = 0;
this.FrameBase.Height = 0;
}
catch (Exception ex)
{
CommonLog.ErrorLogWrite(this, "OptionSelect_Loaded()", "Fail", string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
}
}
private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "CanWindowClose":
if (this.ViewModel.CanWindowClose)
{
CloseWindow();
}
break;
}
}
#endregion Event Handlers
}
}