using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
using SPC.Kiosk.Base;
using SPC.Kiosk.Common;
using SPC.Kiosk.Popup.Model;
namespace SPC.Kiosk.Popup.ViewModel
{
///
/// PkCashBagCertify.xaml에 대한 ViewModel
///
public class VmOkCashBagUsing : PopupViewModelBase
{
#region [ Members ]
private List headerText;
///
/// Top Header Text (Memebr login)
///
public List HeaderText
{
get { return headerText; }
set { headerText = value; PropertyChange("HeaderText"); }
}
private List afterHeaderText;
///
/// Top Header Text (Using Points)
///
public List AfterHeaderText
{
get { return afterHeaderText; }
set { afterHeaderText = value; PropertyChange("AfterHeaderText"); }
}
private List scanGuidText;
///
/// Second Header Text (Memebr login)
///
public List ScanGuidText
{
get { return scanGuidText; }
set { scanGuidText = value; PropertyChange("ScanGuidText"); }
}
private List infoGuid1Text;
///
/// Bottom first Infomation Text (Memebr login)
///
public List InfoGuid1Text
{
get { return infoGuid1Text; }
set { infoGuid1Text = value; PropertyChange("InfoGuid1Text"); }
}
private List infoGuid2Text;
///
/// Bottom second Infomation Text (Memebr login)
///
public List InfoGuid2Text
{
get { return infoGuid2Text; }
set { infoGuid2Text = value; PropertyChange("InfoGuid2Text"); }
}
private List infoGuid3Text;
///
/// Bottom first Infomation Text (Using Points)
///
public List InfoGuid3Text
{
get { return infoGuid3Text; }
set { infoGuid3Text = value; PropertyChange("InfoGuid3Text"); }
}
private List infoGuid4Text;
///
/// Bottom second Infomation Text (Using Points)
///
public List InfoGuid4Text
{
get { return infoGuid4Text; }
set { infoGuid4Text = value; PropertyChange("InfoGuid4Text"); }
}
public int numPadMaxLength;
///
/// Number Pad Max Length
///
public int NumPadMaxLength
{
get { return numPadMaxLength; }
set { numPadMaxLength = value; PropertyChange("NumPadMaxLength"); }
}
private List numPadGuidText;
///
/// Number Pad Input Guide Text
///
public List NumPadGuidText
{
get { return numPadGuidText; }
set { numPadGuidText = value; PropertyChange("NumPadGuidText"); }
}
private List numPadCancelText;
///
/// Number Pad Cancel Button Text
///
public List NumPadCancelText
{
get { return numPadCancelText; }
set { numPadCancelText = value; PropertyChange("NumPadCancelText"); }
}
private bool pointPadVisible;
///
/// Point Pad Visible
///
public bool PointPadVisible
{
get { return pointPadVisible; }
set { pointPadVisible = value; PropertyChange("PointPadVisible"); }
}
private int pointPadMaxLength;
///
/// Point Pad Max Length
///
public int PointPadMaxLength
{
get { return pointPadMaxLength; }
set { pointPadMaxLength = value; PropertyChange("PointPadMaxLength"); }
}
private List pointPadGuidText;
///
/// Point Pad Input Guide Text
///
public List PointPadGuidText
{
get { return pointPadGuidText; }
set { pointPadGuidText = value; PropertyChange("PointPadGuidText"); }
}
private List pointPadCancelText;
///
/// Point Pad Cancel Button Text
///
public List PointPadCancelText
{
get { return pointPadCancelText; }
set { pointPadCancelText = value; PropertyChange("PointPadCancelText"); }
}
private List cancelButtonText;
///
/// Cancel Button Text (Member Login)
///
public List CancelButtonText
{
get { return cancelButtonText; }
set { cancelButtonText = value; PropertyChange("CancelButtonText"); }
}
private List okButtonText;
///
/// OK Button Text (Member Login)
///
public List OkButtonText
{
get { return okButtonText; }
set { okButtonText = value; PropertyChange("OkButtonText"); }
}
public bool oKButtonEnabled = false;
///
/// OK Button Enabled (Member Login)
///
public bool OKButtonEnabled
{
get { return oKButtonEnabled; }
set { oKButtonEnabled = value; PropertyChange("OKButtonEnabled"); }
}
private List cancelButton2Text;
///
/// Cancel Button Text (Point Using)
///
public List CancelButton2Text
{
get { return cancelButton2Text; }
set { cancelButton2Text = value; PropertyChange("CancelButton2Text"); }
}
private List okButton2Text;
///
/// OK Button Text (Point Using)
///
public List OkButton2Text
{
get { return okButton2Text; }
set { okButton2Text = value; PropertyChange("OkButton2Text"); }
}
public bool oKButton2Enabled = false;
///
/// OK Button Enabled (Point using)
///
public bool OKButton2Enabled
{
get { return oKButton2Enabled; }
set { oKButton2Enabled = value; PropertyChange("OKButton2Enabled"); }
}
private List switchAnswer1Text;
///
/// Point Reserve Check Button Text
///
public List SwitchAnswer1Text
{
get { return switchAnswer1Text; }
set { switchAnswer1Text = value; PropertyChange("SwitchAnswer1Text"); }
}
public bool switchAnswer1Switch = false;
///
/// Point Reserve Check Button Switch
///
public bool SwitchAnswer1Switch
{
get { return switchAnswer1Switch; }
set { switchAnswer1Switch = value; PropertyChange("SwitchAnswer1Switch"); }
}
private List switchAnswer2Text;
///
/// Point using Check Button Text
///
public List SwitchAnswer2Text
{
get { return switchAnswer2Text; }
set { switchAnswer2Text = value; PropertyChange("SwitchAnswer2Text"); }
}
public bool switchAnswer2Switch = false;
///
/// Point Using Button Switch
///
public bool SwitchAnswer2Switch
{
get { return switchAnswer2Switch; }
set { switchAnswer2Switch = value; PropertyChange("SwitchAnswer2Switch"); }
}
private List allUseButtonText;
///
/// All using Points Button Text
///
public List AllUseButtonText
{
get { return allUseButtonText; }
set { allUseButtonText = value; PropertyChange("AllUseButtonText"); }
}
private List totalPayHeaderText;
///
/// Payments Total Header Text
///
public List TotalPayHeaderText
{
get { return totalPayHeaderText; }
set { totalPayHeaderText = value; PropertyChange("TotalPayHeaderText"); }
}
private string formatedBarCode;
///
/// Formated Read Barcode
///
public string FormatedBarCode
{
get { return formatedBarCode; }
set { formatedBarCode = value; PropertyChange("FormatedBarCode"); }
}
private string readBarCode;
///
/// Read Barcode
///
public string ReadBarCode
{
get { return readBarCode; }
set { readBarCode = value; PropertyChange("ReadBarCode"); }
}
///
/// Point Reserve Check Flag
///
private bool reservepoint;
public bool ReservePoint
{
get { return reservepoint; }
set { reservepoint = value; PropertyChange("ReservePoint"); }
}
private double payments;
///
/// Total Payments
///
public double Payments
{
get { return payments; }
set { payments = value; PropertyChange("Payments"); }
}
private string showPayment;
///
/// Total Payments Show Text
///
public string ShowPayment
{
get { return showPayment; }
set { showPayment = value; PropertyChange("ShowPayment"); }
}
private string memberName;
///
/// Login Memeber Name
///
public string MemberName
{
get { return memberName; }
set { memberName = value; PropertyChange("MemberName"); }
}
private double queryPoints;
///
/// Member Useable All Points
///
public double QueryPoints
{
get { return queryPoints; }
set { queryPoints = value; PropertyChange("QueryPoints"); }
}
private List errorText;
///
/// Error Text (Member login)
///
public List ErrorText
{
get { return errorText; }
set { errorText = value; PropertyChange("ErrorText"); }
}
private bool isErrorBlink = false;
///
/// Is Error Text Blink (Member login)
///
public bool IsErrorBlink
{
get { return isErrorBlink; }
set { isErrorBlink = value; PropertyChange("IsErrorBlink"); }
}
private List errorText2;
///
/// Error Text (Point Using)
///
public List ErrorText2
{
get { return errorText2; }
set { errorText2 = value; PropertyChange("ErrorText2"); }
}
private bool isErrorBlink2 = false;
///
/// Is Error Text Blink (Point using)
///
public bool IsErrorBlink2
{
get { return isErrorBlink2; }
set { isErrorBlink2 = value; PropertyChange("IsErrorBlink2"); }
}
private bool toAfterBase = false;
///
/// Change Grid to Point Using Grid Flag (true => to to Point Using)
///
public bool ToAfterBase
{
get { return toAfterBase; }
set { toAfterBase = value; PropertyChange("ToAfterBase"); }
}
private List memberInfo;
///
/// Login Memner Info
///
public List MemberInfo
{
get { return memberInfo; }
set { memberInfo = value; PropertyChange("MemberInfo"); }
}
private string inputNumbers = string.Empty;
///
/// Number pad input Numbers
///
public string InputNumbers
{
get { return inputNumbers; }
set { inputNumbers = value; PropertyChange("InputNumbers"); }
}
private string inputPoints = string.Empty;
///
/// Point pad Input Points
///
public string InputPoints
{
get { return inputPoints; }
set { inputPoints = value; PropertyChange("InputPoints"); }
}
private M_OkCashBagReturn okCashBagReturn;
///
/// Ok Chash bag Return Value
///
public M_OkCashBagReturn OkCashBagReturn
{
get { return okCashBagReturn; }
set { okCashBagReturn = value; PropertyChange("OkCashBagReturn"); }
}
///
/// OK Click Command (Member Login)
///
public ICommand OkCommand { get; protected set; }
///
/// Cancel Click Command (Member Login & Point Using)
///
public ICommand CancelCommand { get; protected set; }
///
/// Ok Click Command (Point Using)
///
public ICommand Ok2Command { get; protected set; }
///
/// Point Reserve Click Command
///
public ICommand SwitchAnswer1Command { get; protected set; }
///
/// Point Using Click Command
///
public ICommand SwitchAnswer2Command { get; protected set; }
///
/// All Using Points Click Command
///
public ICommand AllUseCommand { get; protected set; }
private List PointUsingGuid3 = new List
{
new M_Language
{
Type = SupportLanguageType.ko,
LanguageData = "* 해피포인트 적립시 OK캐쉬백은 적립할 수 없습니다."
},
new M_Language
{
Type = SupportLanguageType.en,
LanguageData = "en* 해피포인트 적립시 OK캐쉬백은 적립할 수 없습니다."
},
};
private List PointUsingGuid4 = new List
{
new M_Language
{
Type = SupportLanguageType.ko,
LanguageData = "* 1000P 이상 10P 단위 사용가능."
},
new M_Language
{
Type = SupportLanguageType.en,
LanguageData = "en* * 1000P 이상 10P 단위 사용가능."
},
};
private List ReservePoint3 = new List
{
new M_Language
{
Type = SupportLanguageType.ko,
LanguageData = "* 최종 결제후 자동 적립됩니다."
},
new M_Language
{
Type = SupportLanguageType.en,
LanguageData = "en* 최종 결제후 자동 적립됩니다."
},
};
private List ReservePoint4 = new List();
private bool MemberProcessStart = false;
private Task ProcessTask = null;
#endregion Members
#region [ Ctor ]
///
/// Ctor
///
public VmOkCashBagUsing()
{
OkCommand = new Command(OkCommandHandler);
CancelCommand = new Command(CancelCommandHandler);
Ok2Command = new Command(Ok2CommandHandler);
SwitchAnswer1Command = new Command(SwitchAnswer1CommandHandler);
SwitchAnswer2Command = new Command(SwitchAnswer2CommandHandler);
AllUseCommand = new Command(AllUseCommandHandler);
this.PropertyChanged += VmOkCashBagCertify_PropertyChanged;
HeaderText = new List
{
new M_Language
{
Type = SupportLanguageType.ko,
LanguageData = "OK 캐쉬백 회원인증"
},
new M_Language
{
Type = SupportLanguageType.en,
LanguageData = "OK CASHBAG Member Certify"
},
};
AfterHeaderText = new List
{
new M_Language
{
Type = SupportLanguageType.ko,
LanguageData = "OK 캐쉬백"
},
new M_Language
{
Type = SupportLanguageType.en,
LanguageData = "OK CASHBAG"
},
};
ScanGuidText = new List
{
new M_Language
{
Type = SupportLanguageType.ko,
LanguageData = "바코드 스켄 또는 전화 번호를 입력하세요."
},
new M_Language
{
Type = SupportLanguageType.en,
LanguageData = "en바코드 스켄 또는 전화 번호를 입력하세요."
},
};
InfoGuid1Text = new List
{
new M_Language
{
Type = SupportLanguageType.ko,
LanguageData = "* 해피포인트 적립시 OK캐쉬백은 적립할 수 없습니다."
},
new M_Language
{
Type = SupportLanguageType.en,
LanguageData = "en* 해피포인트 적립시 OK캐쉬백은 적립할 수 없습니다."
},
};
InfoGuid2Text = new List
{
new M_Language
{
Type = SupportLanguageType.ko,
LanguageData = "* 수집된 개인정보는 활용 후 자동 폐기 됩니다."
},
new M_Language
{
Type = SupportLanguageType.en,
LanguageData = "en* 수집된 개인정보는 활용 후 자동 폐기 됩니다."
},
};
NumPadMaxLength = 11;
NumPadGuidText = Languages.GetMessages("MobileNumberMessage");
NumPadCancelText = Languages.GetMessages("CommonClear");
PointPadMaxLength = 9;
PointPadGuidText = Languages.GetMessages("InputUsingPoints");
PointPadCancelText = Languages.GetMessages("CommonClear");
CancelButtonText = Languages.GetMessages("CommonCancel");
OkButtonText = Languages.GetMessages("CommonOK");
CancelButton2Text = Languages.GetMessages("CommonCancel");
OkButton2Text = Languages.GetMessages("CommonOK");
SwitchAnswer1Text = Languages.GetMessages("CommonReserve");
SwitchAnswer2Text = Languages.GetMessages("CommonUsing");
AllUseButtonText = Languages.GetMessages("CommonUsingAll");
TotalPayHeaderText = Languages.GetMessages("PriceForPayment");
if (!ReservePoint) PointPadVisible = true;
}
~VmOkCashBagUsing()
{
this.PropertyChanged -= VmOkCashBagCertify_PropertyChanged;
}
#endregion Ctor
#region [ Methods ]
private bool PointValueCheck()
{
bool result = false;
try
{
if (!Payments.Equals(0) && QueryPoints >= 1000)
{
var checkValue = int.Parse(InputPoints);
if (checkValue >= 1000)
{
result = (checkValue % 10).Equals(0)
&& checkValue <= QueryPoints
&& checkValue <= Payments;
}
}
}
catch
{
result = false;
}
return result;
}
private void DoOkCashBagCertify()
{
TimerEnabled = false;
MemberProcessStart = true;
//TODO : OK CASHBAG Point 조회
OkCashBagReturn = new M_OkCashBagReturn
{
MemberName = "홍길동",
MemberPoint = 120501,
MemberCode = ReadBarCode.Equals(string.Empty) ? InputNumbers : ReadBarCode,
};
MemberName = OkCashBagReturn.MemberName;
QueryPoints = OkCashBagReturn.MemberPoint;
ToAfterBase = true;
TimerEnabled = true;
}
#endregion Methods
#region [ Event Handlers ]
private void AllUseCommandHandler(object obj)
{
if (QueryPoints > 1000)
{
var canUseAllPoints = QueryPoints - QueryPoints % 10;
if (!Payments.Equals(0))
{
if (Payments < canUseAllPoints)
{
InputPoints = Payments.ToString();
}
else
{
InputPoints = canUseAllPoints.ToString();
}
}
}
}
private void CancelCommandHandler(object obj)
{
TimerEnabled = false;
ReturnValue = new M_PopupReturn
{
OKAnswer = false,
TimeOut = false,
ReturnLanguage = ShowLanguageType,
PopupArgs = null
};
CanWindowClose = true;
}
private void OkCommandHandler(object obj)
{
DoOkCashBagCertify();
}
private void Ok2CommandHandler(object obj)
{
TimerEnabled = false;
OkCashBagReturn.ReservePoint = SwitchAnswer1Switch;
OkCashBagReturn.PointUse = SwitchAnswer2Switch;
OkCashBagReturn.UsingPoints = string.IsNullOrEmpty(InputPoints)
? 0 : int.Parse(InputPoints);
ReturnValue = new M_PopupReturn
{
OKAnswer = true,
TimeOut = false,
ReturnLanguage = ShowLanguageType,
PopupArgs = OkCashBagReturn
};
if (ProcessTask != null) ProcessTask.Wait();
CanWindowClose = true;
}
private void SwitchAnswer1CommandHandler(object obj)
{
if (SwitchAnswer2Switch)
{
OKButton2Enabled = PointValueCheck();
}
else
{
OKButton2Enabled = ReservePoint ? SwitchAnswer1Switch : false;
}
}
private void SwitchAnswer2CommandHandler(object obj)
{
if (!ReservePoint) SwitchAnswer2Switch = true;
if (SwitchAnswer2Switch)
{
InfoGuid3Text = PointUsingGuid3;
InfoGuid4Text = PointUsingGuid4;
if (!Payments.Equals(0))
{
PointPadVisible = true;
OKButton2Enabled = PointValueCheck();
}
else
{
SwitchAnswer2Switch = false;
}
}
else
{
InfoGuid3Text = ReservePoint3;
InfoGuid4Text = ReservePoint4;
InputPoints = string.Empty;
PointPadVisible = false;
OKButton2Enabled = ReservePoint ? SwitchAnswer1Switch : false;
}
}
private void VmOkCashBagCertify_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "IsTimeout":
if (IsTimeout)
{
ReturnValue = new M_PopupReturn
{
OKAnswer = false,
TimeOut = true,
ReturnLanguage = ShowLanguageType,
PopupArgs = null
};
if (ProcessTask != null) ProcessTask.Wait();
CanWindowClose = true;
}
break;
case "ReservePoint":
if (ReservePoint)
{
InfoGuid3Text = ReservePoint3;
InfoGuid4Text = ReservePoint4;
PointPadVisible = false;
}
else
{
SwitchAnswer2Switch = true;
OKButton2Enabled = false;
InfoGuid3Text = PointUsingGuid3;
InfoGuid4Text = PointUsingGuid4;
}
break;
case "InputNumbers":
if (InputNumbers.Length > 0) ReadBarCode = string.Empty;
OKButtonEnabled = NumPadMaxLength.Equals(InputNumbers.Length);
break;
case "InputPoints":
OKButton2Enabled = PointValueCheck();
break;
case "Payments":
ShowPayment = string.Format(@"\{0}", Payments.ToString("#,##0"));
break;
case "MemberName":
case "QueryPoints":
var memberInfo = string.Format("{0}({1}P)"
, MemberName.GetEncriptName(), QueryPoints.ToString("#,###0"));
MemberInfo = new List
{
new M_Language { Type=SupportLanguageType.ko, LanguageData = memberInfo }
};
break;
case "ReadBarCode":
if (!MemberProcessStart)
{
switch (ReadBarCode.Length)
{
case 16:
InputNumbers = string.Empty;
FormatedBarCode = ReadBarCode.GetEncriptCardNo();
DoOkCashBagCertify();
break;
default:
FormatedBarCode = string.Empty;
OKButtonEnabled = false;
break;
}
}
break;
}
}
#endregion Event Handlers
}
}