285 lines
10 KiB
C#
285 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.ComponentModel;
|
|
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 SPC.Kiosk.Base;
|
|
using SPC.Kiosk.Common;
|
|
using SPC.Kiosk.Popup.Model;
|
|
namespace SPC.Kiosk.Popup
|
|
{
|
|
/// <summary>
|
|
/// MiniBasketItem.xaml에 대한 상호 작용 논리
|
|
/// </summary>
|
|
public partial class VirtureMobileHappyCoupons : UserControl
|
|
{
|
|
#region [ Members ]
|
|
/// <summary>
|
|
/// ItemData
|
|
/// </summary>
|
|
public static readonly DependencyProperty CouponDataProperty =
|
|
DependencyProperty.Register(nameof(CouponData), typeof(M_MobileCouponReturn), typeof(VirtureMobileHappyCoupons), new PropertyMetadata(null, new PropertyChangedCallback(OnCouponDataPropertyChanged)));
|
|
|
|
|
|
/// <summary>
|
|
/// Display Language
|
|
/// </summary>
|
|
public static readonly DependencyProperty DisplayLanguagePropery =
|
|
DependencyProperty.Register(nameof(DisplayLanguage), typeof(SupportLanguageType), typeof(VirtureMobileHappyCoupons), new PropertyMetadata(SupportLanguageType.ko, new PropertyChangedCallback(OnDisplayLanguageProperyChanged)));
|
|
/// <summary>
|
|
/// Vertical Scroll Offset
|
|
/// </summary>
|
|
public static readonly DependencyProperty VerticalOffsetProperty =
|
|
DependencyProperty.Register(nameof(VerticalOffset), typeof(double), typeof(VirtureMobileHappyCoupons), new PropertyMetadata(0d, new PropertyChangedCallback(OnVerticalOffsetPropertyChanged)));
|
|
|
|
/// <summary>
|
|
/// Command
|
|
/// </summary>
|
|
public static readonly DependencyProperty CommandProperty =
|
|
DependencyProperty.Register(nameof(Command), typeof(ICommand), typeof(VirtureMobileHappyCoupons), new UIPropertyMetadata(null));
|
|
|
|
/// <summary>
|
|
/// Command
|
|
/// </summary>
|
|
public ICommand Command
|
|
{
|
|
get { return (ICommand)GetValue(CommandProperty); }
|
|
set { SetValue(CommandProperty, value); }
|
|
}
|
|
/// <summary>
|
|
/// Vertical Scroll Offset
|
|
/// </summary>
|
|
public double VerticalOffset
|
|
{
|
|
get { return (double)GetValue(VerticalOffsetProperty); }
|
|
set { SetValue(VerticalOffsetProperty, value); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// ItemData
|
|
/// </summary>
|
|
public M_MobileCouponReturn CouponData
|
|
{
|
|
get { return (M_MobileCouponReturn)GetValue(CouponDataProperty); }
|
|
set { SetValue(CouponDataProperty, value); }
|
|
}
|
|
/// <summary>
|
|
/// Display Language
|
|
/// </summary>
|
|
public SupportLanguageType DisplayLanguage
|
|
{
|
|
get { return (SupportLanguageType)GetValue(DisplayLanguagePropery); }
|
|
set { SetValue(DisplayLanguagePropery, value); }
|
|
}
|
|
#region [ RoutedEvent 'CouponSelect' ]
|
|
|
|
/// <summary>
|
|
/// MouseClicked Event
|
|
/// </summary>
|
|
public static readonly RoutedEvent CouponSelectEvent = EventManager.RegisterRoutedEvent(nameof(CouponSelect), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(VirtureMobileHappyCoupons));
|
|
/// <summary>
|
|
/// MouseClicked Routed Event Handler
|
|
/// </summary>
|
|
public event RoutedEventHandler CouponSelect
|
|
{
|
|
add { AddHandler(CouponSelectEvent, value); }
|
|
remove { RemoveHandler(CouponSelectEvent, value); }
|
|
}
|
|
#endregion RoutedEvent 'SelectChange'
|
|
private double mouseDownYposition = -1;
|
|
private bool MoseDown = false;
|
|
|
|
#endregion Members
|
|
|
|
#region [ Ctor & Etc ]
|
|
/// <summary>
|
|
/// Ctor
|
|
/// </summary>
|
|
public VirtureMobileHappyCoupons()
|
|
{
|
|
InitializeComponent();
|
|
CouponGrid.PreviewMouseDown += CouponGrid_PreviewMouseDown;
|
|
CouponGrid.PreviewMouseUp += CouponGrid_PreviewMouseUp;
|
|
CouponGrid.PreviewMouseMove += CouponGrid_PreviewMouseMove;
|
|
CouponGrid.MouseLeave += CouponGrid_MouseLeave;
|
|
|
|
}
|
|
|
|
#endregion Ctor & Etc
|
|
|
|
#region [ Methods ]
|
|
/// <summary>
|
|
/// Raise MouseClicked Event
|
|
/// </summary>
|
|
private void RaiseCouponSelectEvent(object _sender)
|
|
{
|
|
if (Command != null && Command.CanExecute(_sender))
|
|
{
|
|
Command.Execute(_sender);
|
|
}
|
|
RoutedEventArgs newEventArgs = new RoutedEventArgs(VirtureMobileHappyCoupons.CouponSelectEvent, _sender);
|
|
RaiseEvent(newEventArgs);
|
|
}
|
|
private void SetCouponStack(M_MobileCouponReturn newValue)
|
|
{
|
|
foreach (var aGrid in CouponStack.Children)
|
|
{
|
|
if (aGrid is Grid aCoupons)
|
|
{
|
|
foreach (var aStack in aCoupons.Children)
|
|
{
|
|
if (aStack is StackPanel aItems)
|
|
{
|
|
foreach (var aItem in aItems.Children)
|
|
{
|
|
if (aItem is VirtureMobileHappyCoupon aCoupon)
|
|
{
|
|
aCoupon.MouseClicked -= ACoupon_MouseClicked;
|
|
}
|
|
}
|
|
aItems.Children.Clear();
|
|
}
|
|
}
|
|
aCoupons.Children.Clear();
|
|
}
|
|
}
|
|
CouponStack.Children.Clear();
|
|
if (newValue.VirtureCoupons.Count.Equals(0)) return;
|
|
var index = 0;
|
|
Grid lineGrid = null;
|
|
StackPanel lineStack = null;
|
|
foreach (var aCouponDetail in newValue.VirtureCoupons)
|
|
{
|
|
var newCoupon = new VirtureMobileHappyCoupon
|
|
{
|
|
ItemData = aCouponDetail,
|
|
Enabled = aCouponDetail.Status.Equals(MobileCouponStatusType.CanUse),
|
|
DisplayLanguage = this.DisplayLanguage
|
|
};
|
|
if ((index % 3).Equals(0))
|
|
{
|
|
lineGrid = new Grid
|
|
{
|
|
VerticalAlignment = VerticalAlignment.Top,
|
|
HorizontalAlignment = HorizontalAlignment.Left,
|
|
Width = newCoupon.Width * 3,
|
|
Height = newCoupon.Height,
|
|
};
|
|
lineStack = new StackPanel
|
|
{
|
|
VerticalAlignment = VerticalAlignment.Top,
|
|
HorizontalAlignment = HorizontalAlignment.Left,
|
|
Orientation = Orientation.Horizontal,
|
|
};
|
|
|
|
}
|
|
newCoupon.MouseClicked += ACoupon_MouseClicked;
|
|
newCoupon.Name = string.Format("MobileCoupon{0}", index);
|
|
this.ReregisterName(newCoupon.Name, newCoupon);
|
|
lineStack.Children.Add(newCoupon);
|
|
index++;
|
|
if ((index % 3).Equals(0))
|
|
{
|
|
lineGrid.Children.Add(lineStack);
|
|
CouponStack.Children.Add(lineGrid);
|
|
}
|
|
}
|
|
if (!(index % 3).Equals(0))
|
|
{
|
|
lineGrid.Children.Add(lineStack);
|
|
CouponStack.Children.Add(lineGrid);
|
|
}
|
|
}
|
|
#endregion Methods
|
|
|
|
#region [ Event Handlers ]
|
|
private void ACoupon_MouseClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
RaiseCouponSelectEvent(e.OriginalSource);
|
|
}
|
|
private static void OnVerticalOffsetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if (e.NewValue != e.OldValue)
|
|
{
|
|
var target = d as VirtureMobileHappyCoupons;
|
|
target.MainScroll.ScrollToVerticalOffset((double)e.NewValue);
|
|
}
|
|
}
|
|
|
|
private static void OnCouponDataPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if (e.NewValue is M_MobileCouponReturn newValue)
|
|
{
|
|
var target = d as VirtureMobileHappyCoupons;
|
|
target.SetCouponStack(newValue);
|
|
}
|
|
}
|
|
|
|
|
|
private static void OnDisplayLanguageProperyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if (e.NewValue is SupportLanguageType newValue)
|
|
{
|
|
var target = d as VirtureMobileHappyCoupons;
|
|
foreach (var aGrid in target.CouponStack.Children)
|
|
{
|
|
if (aGrid is Grid aCoupons)
|
|
{
|
|
foreach (var aStack in aCoupons.Children)
|
|
{
|
|
if (aStack is StackPanel aItems)
|
|
{
|
|
foreach (var aItem in aItems.Children)
|
|
{
|
|
if (aItem is VirtureMobileHappyCoupon aCoupon)
|
|
{
|
|
aCoupon.DisplayLanguage = newValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void CouponGrid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
var requstGrid = sender as Grid;
|
|
mouseDownYposition = e.GetPosition(sender as Grid).Y;
|
|
MoseDown = true;
|
|
}
|
|
|
|
private void CouponGrid_PreviewMouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
MoseDown = false;
|
|
}
|
|
|
|
private void CouponGrid_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 CouponGrid_MouseLeave(object sender, MouseEventArgs e)
|
|
{
|
|
MoseDown = false;
|
|
}
|
|
#endregion Event Handlers
|
|
|
|
}
|
|
}
|