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

260 lines
9.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SPC.Kiosk.Base;
using SPC.Kiosk.Common;
using SPC.Kiosk.PB.Model;
namespace SPC.Kiosk.PB
{
/// <summary>
/// DiscountAndValues.xaml에 대한 상호 작용 논리
/// </summary>
public partial class DiscountAndValues : UserControl
{
#region [ Members ]
/// <summary>
/// ListItems
/// </summary>
public static readonly DependencyProperty ListItemsProperty =
DependencyProperty.Register(nameof(ListItems), typeof(ObservableCollection<M_DiscountAndAddValues>), typeof(DiscountAndValues), new PropertyMetadata(null, new PropertyChangedCallback(OnListItemsPropertyChanged)));
/// <summary>
/// Vertical Scroll Offset
/// </summary>
public static readonly DependencyProperty VerticalOffsetProperty =
DependencyProperty.Register(nameof(VerticalOffset), typeof(double), typeof(DiscountAndValues), new PropertyMetadata(0d, new PropertyChangedCallback(OnVerticalOffsetPropertyChanged)));
/// <summary>
/// Display Language
/// </summary>
public static readonly DependencyProperty DisplayLanguagePropery =
DependencyProperty.Register(nameof(DisplayLanguage), typeof(SupportLanguageType), typeof(DiscountAndValues), new PropertyMetadata(SupportLanguageType.ko, new PropertyChangedCallback(OnDisplayLanguageProperyChanged)));
private double mouseDownYposition = -1;
private bool MoseDown = false;
/// <summary>
/// ListItems
/// </summary>
public ObservableCollection<M_DiscountAndAddValues> ListItems
{
get { return (ObservableCollection<M_DiscountAndAddValues>)GetValue(ListItemsProperty); }
set { SetValue(ListItemsProperty, value); }
}
/// <summary>
/// VerticalOffset
/// </summary>
public double VerticalOffset
{
get { return (double)GetValue(VerticalOffsetProperty); }
set { SetValue(VerticalOffsetProperty, value); }
}
/// <summary>
/// Display Language
/// </summary>
public SupportLanguageType DisplayLanguage
{
get { return (SupportLanguageType)GetValue(DisplayLanguagePropery); }
set { SetValue(DisplayLanguagePropery, value); }
}
#endregion Members
#region [ Ctor & Etc ]
/// <summary>
/// Ctor
/// </summary>
public DiscountAndValues()
{
InitializeComponent();
this.Unloaded += DiscountAndValues_Unloaded;
}
#endregion Ctor & Etc
#region [ Methods ]
private void FlipItem(FrameworkElement _target)
{
try
{
var targetAnimation = new Storyboard();
var getAnimations = Animations.GetMoveAnimation(_target, OpenCloseAnimationType.GotoDown, _target.ActualHeight *-1, 0, 0.5, 1, 0.5);
foreach (var aAnimation in getAnimations) targetAnimation.Children.Add(aAnimation);
targetAnimation.Begin();
}
catch (Exception ex)
{
CommonLog.ErrorLogWrite(this, "FlipItem()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
}
}
private void ItemsButtonCreate(object _listItems)
{
try
{
this.GridEventsRemove();
this.MainStack.Children.Clear();
if (_listItems is ObservableCollection<M_DiscountAndAddValues> lstItems && lstItems.Count > 0)
{
var index = 0;
foreach (var aItem in lstItems)
{
var newItemObject = new DiscountAndValue();
newItemObject.ItemData = aItem;
newItemObject.DisplayLanguage = this.DisplayLanguage;
newItemObject.Name = string.Format("ItemStack{0}", index);
this.ReregisterName(newItemObject.Name, newItemObject);
this.MainStack.Children.Add(newItemObject);
index++;
}
this.UpdateLayout();
CommonFunction.ReregisterName(this.Parent as FrameworkElement, this.Name, this);
this.GridEventsSet();
}
}
catch (Exception ex)
{
CommonLog.ErrorLogWrite(this, "ItemsButtonCreate()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
}
}
/// <summary>
/// Events Set
/// </summary>
public void GridEventsSet()
{
try
{
MainGrid.PreviewMouseDown += Grid_PreviewMouseDown;
MainGrid.PreviewMouseUp += Grid_PreviewMouseUp;
MainGrid.PreviewMouseMove += MainGrid_PreviewMouseMove;
MainGrid.MouseLeave += MainGrid_MouseLeave;
}
catch (Exception ex)
{
CommonLog.ErrorLogWrite(this, "GridEventsSet()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
}
}
/// <summary>
/// Events Remove
/// </summary>
public void GridEventsRemove()
{
try
{
MainGrid.PreviewMouseDown -= Grid_PreviewMouseDown;
MainGrid.PreviewMouseUp -= Grid_PreviewMouseUp;
MainGrid.PreviewMouseMove -= MainGrid_PreviewMouseMove;
MainGrid.MouseLeave -= MainGrid_MouseLeave;
this.MainStack.Children.Clear();
}
catch (Exception ex)
{
CommonLog.ErrorLogWrite(this, "GridEventsRemove()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
}
}
#endregion Methods
#region [ Event Handlers ]
private void DiscountAndValues_Unloaded(object sender, RoutedEventArgs e)
{
this.MainStack.Children.Clear();
this.ListItems = null;
}
private static void OnDisplayLanguageProperyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
try
{
if (e.NewValue is SupportLanguageType newValue && !e.NewValue.Equals(e.OldValue))
{
var target = d as DiscountAndValues;
foreach (var aItem in target.MainStack.Children)
{
if (aItem is MiniBasketItem ItemContent)
{
ItemContent.DisplayLanguage = newValue;
}
}
}
}
catch (Exception ex)
{
CommonLog.ErrorLogWrite(d, "OnDisplayLanguageProperyChanged()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
}
}
private static void OnVerticalOffsetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != e.OldValue)
{
var target = d as DiscountAndValues;
target.MainScroll.ScrollToVerticalOffset((double)e.NewValue);
}
}
private static void OnListItemsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var target = d as DiscountAndValues;
target.VerticalOffset = target.VerticalOffset + target.ActualHeight;
int oldCount = e.OldValue is ObservableCollection<M_DiscountAndAddValues> oldValue ? oldValue.Count : 0;
int newCount = e.NewValue is ObservableCollection<M_DiscountAndAddValues> newValue ? newValue.Count : 0;
target.ItemsButtonCreate(e.NewValue);
//if (newCount > oldCount )
//{
// if (target.VerticalOffset > 0) target.VerticalOffset = 0;
// if (newCount.Equals(oldCount + 1))
// {
// target.FlipItem(target.MainStack.Children[0] as FrameworkElement);
// }
// else
// {
// target.FlipItem(target.MainStack as FrameworkElement);
// }
//}
}
private void Grid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var requstGrid = sender as Grid;
mouseDownYposition = e.GetPosition(sender as Grid).Y;
MoseDown = true;
}
private void MainGrid_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (!MoseDown) return;
var requstGrid = sender as Grid;
var curMouseYposition = e.GetPosition(requstGrid).Y;
VerticalOffset = VerticalOffset + (mouseDownYposition - curMouseYposition) * 2;
mouseDownYposition = curMouseYposition;
}
private void Grid_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
MoseDown = false;
}
private void MainGrid_MouseLeave(object sender, MouseEventArgs e)
{
MoseDown = false;
}
#endregion Event Handlers
}
}