using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Text; using System.Windows.Input; using System.Windows.Threading; using System.Reflection; using SPC.Kiosk.Base; using SPC.Kiosk.Common; using SPC.Kiosk.Popup.Model; using SPC.Kiosk.Payments; using System.Windows; using System.Threading.Tasks; using System.Threading; namespace SPC.Kiosk.Popup.ViewModel { /// /// MobileCompanyMemberCertify.xaml 의 ViewModel /// public class VmMobileCompanyMemberCertify : PopupViewModelBase { #region [ Members ] private MobileCompanyType mobileCompany; /// /// Mobile Company Type /// public MobileCompanyType MobileCompany { get { return mobileCompany; } set { mobileCompany = value; PropertyChange("MobileCompany"); } } private List mobileCompanyName; /// /// Mobile Company Name /// public List MobileCompanyName { get { return mobileCompanyName; } set { mobileCompanyName = value; PropertyChange("MobileCompanyName"); } } private double payments; /// /// Total Payments /// public double Payments { get { return payments; } set { payments = value; PropertyChange("Payments"); } } private List headerSubText; /// /// Top Sub Header Text /// public List HeaderSubText { get { return headerSubText; } set { headerSubText = value; PropertyChange("HeaderSubText"); } } private List scanGuidText; /// /// Second Sub Header Text /// public List ScanGuidText { get { return scanGuidText; } set { scanGuidText = value; PropertyChange("ScanGuidText"); } } private List processingGuide; /// /// Processing Guide Text /// public List ProcessingGuide { get { return processingGuide; } set { processingGuide = value; PropertyChange("ProcessingGuide"); } } private List errorGuide; /// /// Error Guide Text /// public List ErrorGuide { get { return errorGuide; } set { errorGuide = value; PropertyChange("ErrorGuide"); } } private List infoGuid1Text; /// /// Bootom first infomation text /// public List InfoGuid1Text { get { return infoGuid1Text; } set { infoGuid1Text = value; PropertyChange("InfoGuid1Text"); } } private List infoGuid2Text; /// /// Bottom second infomation text /// public List InfoGuid2Text { get { return infoGuid2Text; } set { infoGuid2Text = value; PropertyChange("InfoGuid2Text"); } } public bool certifyStartVisible = false; /// /// 인증 시작 화면 Visible /// public bool CertifyStartVisible { get { return certifyStartVisible; } set { certifyStartVisible = value; PropertyChange("CertifyStartVisible"); } } public bool certifyProcessingVisible = false; /// /// 인증 진행 화면 Visible /// public bool CertifyProcessingVisible { get { return certifyProcessingVisible; } set { certifyProcessingVisible = value; PropertyChange("CertifyProcessingVisible"); } } public bool processingErrorVisible = false; /// /// 인증 오류 화면 Visible /// public bool ProcessingErrorVisible { get { return processingErrorVisible; } set { processingErrorVisible = value; PropertyChange("ProcessingErrorVisible"); } } public bool certifySuccessVisible = false; /// /// 인증 완료 화면 Visible /// public bool CertifySuccessVisible { get { return certifySuccessVisible; } set { certifySuccessVisible = value; PropertyChange("CertifySuccessVisible"); } } private List processingMessageText; /// /// Number Pad Input Guide Text /// public List ProcessingMessageText { get { return processingMessageText; } set { processingMessageText = value; PropertyChange("ProcessingMessageText"); } } private string titileImage; /// /// Read Barcode Formated Text /// public string TitileImage { get { return titileImage; } set { titileImage = value; PropertyChange("TitileImage"); } } private string processingGIF; /// /// Processing GIF /// public string ProcessingGIF { get { return processingGIF; } set { processingGIF = value; PropertyChange("ProcessingGIF"); } } private string errorImage; /// /// Error Icon /// public string ErrorImage { get { return errorImage; } set { errorImage = value; PropertyChange("ErrorImage"); } } private string successImage; /// /// Sucess Icon /// public string SuccessImage { get { return successImage; } set { successImage = value; PropertyChange("SuccessImage"); } } private List errorText; /// /// Process Error Text /// public List ErrorText { get { return errorText; } set { errorText = value; PropertyChange("ErrorText"); } } private bool isErrorBlink = false; /// /// Is Error Text Blink /// public bool IsErrorBlink { get { return isErrorBlink; } set { isErrorBlink = value; PropertyChange("IsErrorBlink"); } } private string formatedBarCode; /// /// Read Barcode Formated Text /// 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"); } } private double discountValue = 0d; /// /// Number Pad Input Number /// public double DiscountValue { get { return discountValue; } set { discountValue = value; PropertyChange("DiscountValue"); } } private double cancelButtonWidth = 650d; /// /// Cancel Button Width /// public double CancelButtonWidth { get { return cancelButtonWidth; } set { cancelButtonWidth = value; PropertyChange("CancelButtonWidth"); } } private List cancelButtonText; /// /// Cancel Button Text /// public List CancelButtonText { get { return cancelButtonText; } set { cancelButtonText = value; PropertyChange("CancelButtonText"); } } private List okButtonText; /// /// Ok Button Text /// public List OkButtonText { get { return okButtonText; } set { okButtonText = value; PropertyChange("OkButtonText"); } } public bool oKButtonEnabled = false; /// /// OK Button enabled /// public bool OKButtonEnabled { get { return oKButtonEnabled; } set { oKButtonEnabled = value; PropertyChange("OKButtonEnabled"); } } private double okButtonWidth = 150d; /// /// OK Button Width /// public double OKButtonWidth { get { return okButtonWidth; } set { okButtonWidth = value; PropertyChange("OKButtonWidth"); } } private List successText; /// /// Cancel Button Text /// public List SuccessText { get { return successText; } set { successText = value; PropertyChange("SuccessText"); } } private CertifyWindowType certifyWindow = CertifyWindowType.CertifyStart; /// /// Current View Window /// public CertifyWindowType CertifyWindow { get { return certifyWindow; } set { certifyWindow = value; PropertyChange("CertifyWindow"); } } private double popupWidth = 1300; /// /// Popup Whidth (For Calculate OK Button Width) /// public double PopupWidth { get { return popupWidth; } set { popupWidth = value; PropertyChange("PopupWidth"); } } /// /// 통신사 할인 정보 /// public M_MobileCompanyReturn MobileCompanyReturnVlaue { get; set; } /// /// OK Click Command /// public ICommand OkCommand { get; protected set; } /// /// Cancel Click Command /// public ICommand CancelCommand { get; protected set; } private bool DiscountProcessStart = false; private posMobileCompanyDiscount posTelecomDiscount = null; private Task ProcessTask = null; private string certifyKey = string.Empty; #endregion #region [ Ctor ] /// /// Ctor /// public VmMobileCompanyMemberCertify() { OkCommand = new Command(OkCommandHandler); CancelCommand = new Command(CancelCommandHandler); this.PropertyChanged += VmMobileCompanyMemberCertify_PropertyChanged; TitileImage = ResourceManager.GetNximagePathAdd("img_gif_barcode.gif", CommonValue.PBdesignImagesPath); ProcessingGIF = ResourceManager.GetNximagePathAdd("ic_alert_ing2.gif", CommonValue.PBdesignImagesPath); ErrorImage = ResourceManager.GetNximagePathAdd("ic_alert_error.png", CommonValue.PBdesignImagesPath); SuccessImage = ResourceManager.GetNximagePathAdd("ic_alert_check.png", CommonValue.PBdesignImagesPath); HeaderSubText = new List { new M_Language { Type = SupportLanguageType.ko, LanguageData = "할인" }, new M_Language { Type = SupportLanguageType.en, LanguageData = "Discount" }, }; ProcessingMessageText = Languages.GetMessages("LBL0087"); ProcessingGuide = Languages.GetMessages("LBL0017"); ErrorGuide = Languages.GetMessages("LBL0028"); ErrorText = new List(); OkButtonText = Languages.GetMessages("BTN0024"); CancelButtonText = Languages.GetMessages("BTN0033"); posTelecomDiscount = new posMobileCompanyDiscount(); posTelecomDiscount.ReadStart += posTelecomDiscount_ReadStart; posTelecomDiscount.ReadEnd += posTelecomDiscount_ReadEnd; posTelecomDiscount.ErrorEvent += posTelecomDiscount_ErrorEvent; posTelecomDiscount.ErrorMessageEvent += posTelecomDiscount_ErrorMessageEvent; CertifyWindow = CertifyWindowType.CertifyStart; } ~VmMobileCompanyMemberCertify() { this.PropertyChanged -= VmMobileCompanyMemberCertify_PropertyChanged; if (ProcessTask != null) { ProcessTask.Dispose(); ProcessTask = null; } if (posTelecomDiscount != null) { posTelecomDiscount.ReadStart -= posTelecomDiscount_ReadStart; posTelecomDiscount.ReadEnd -= posTelecomDiscount_ReadEnd; posTelecomDiscount.ErrorEvent -= posTelecomDiscount_ErrorEvent; posTelecomDiscount.ErrorMessageEvent -= posTelecomDiscount_ErrorMessageEvent; posTelecomDiscount.Dispose(); posTelecomDiscount = null; } } #endregion Ctor #region [ Methods ] private void InitError() { LastAccessTime = DateTime.Now; ErrorText = new List(); IsErrorBlink = false; } private void TelecomCreateEvents() { if (posTelecomDiscount != null) { posTelecomDiscount.ReadStart += posTelecomDiscount_ReadStart; posTelecomDiscount.ReadEnd += posTelecomDiscount_ReadEnd; posTelecomDiscount.ErrorEvent += posTelecomDiscount_ErrorEvent; posTelecomDiscount.ErrorMessageEvent += posTelecomDiscount_ErrorMessageEvent; } } private void TelecomRemoveEvents() { if (posTelecomDiscount != null) { posTelecomDiscount.ReadStart -= posTelecomDiscount_ReadStart; posTelecomDiscount.ReadEnd -= posTelecomDiscount_ReadEnd; posTelecomDiscount.ErrorEvent -= posTelecomDiscount_ErrorEvent; posTelecomDiscount.ErrorMessageEvent -= posTelecomDiscount_ErrorMessageEvent; } } private void DoMobileCompanyMemberCertify() { if (posTelecomDiscount != null) { TelecomCreateEvents(); var processTask = new Task(() => posTelecomDiscount.StartCertifyProcessing(certifyKey,MobileCompany,Payments)); processTask.Start(); processTask.Wait(); TelecomRemoveEvents(); processTask = null; } } private void DoBarCodeMobileCompanyMemberCertify() { FormatedBarCode = ReadBarCode.GetEncriptCardNo(); certifyKey = ReadBarCode; CertifyWindow = CertifyWindowType.CertifyProcessing; } #endregion Methods #region [ Event Handlers ] private void posTelecomDiscount_ErrorMessageEvent(string _errorString) { ErrorText = new List { new M_Language { Type = SupportLanguageType.ko, LanguageData = _errorString.Replace("\n"," ").Replace("\r","") }, }; IsErrorBlink = true; CertifyWindow = CertifyWindowType.ProcessingError; } private void posTelecomDiscount_ErrorEvent(posMobileCompanyDiscount.ErrorCode _errorCode) { //TODO: 공통에 에러 메세지 등록 필요 //ErrorText = Languages.GetMessages(_errorCode.ToString()); ErrorText = new List { new M_Language { Type = SupportLanguageType.ko, LanguageData = _errorCode.ToString() }, }; IsErrorBlink = true; CertifyWindow = CertifyWindowType.ProcessingError; } private void posTelecomDiscount_ReadStart(object sender) { DiscountProcessStart = true; TimerEnabled = false; } private void posTelecomDiscount_ReadEnd(object sender) { if (sender is posMobileCompanyDiscount getTelecomDiscount) { if (getTelecomDiscount.ProcessOK) { MobileCompanyReturnVlaue = new M_MobileCompanyReturn { Company = getTelecomDiscount.MobileCompany, MemberCode = getTelecomDiscount.CertifyKey, ApprovalPayments = getTelecomDiscount.Payment, DiscountValue = getTelecomDiscount.DiscountValue, PaySEQ = getTelecomDiscount.PaySEQ, }; ReturnValue = new M_PopupReturn { OKAnswer = true, TimeOut = false, ReturnLanguage = ShowLanguageType, PopupArgs = MobileCompanyReturnVlaue }; DiscountValue = MobileCompanyReturnVlaue.DiscountValue; CertifyWindow = CertifyWindowType.CertifySuccess; } } TimerEnabled = true; DiscountProcessStart = false; } 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) { switch (CertifyWindow) { case CertifyWindowType.ProcessingError: CertifyWindow = CertifyWindowType.CertifyStart; break; case CertifyWindowType.CertifySuccess: if (ProcessTask != null) ProcessTask.Wait(); CanWindowClose = true; break; } } private void VmMobileCompanyMemberCertify_PropertyChanged(object sender, PropertyChangedEventArgs e) { try { switch (e.PropertyName) { case "IsTimeout": if (IsTimeout) { switch (CertifyWindow) { case CertifyWindowType.CertifyStart: case CertifyWindowType.ProcessingError: ReturnValue = new M_PopupReturn { OKAnswer = false, TimeOut = true, ReturnLanguage = ShowLanguageType, PopupArgs = null }; break; } if (ProcessTask != null) ProcessTask.Wait(); CanWindowClose = true; } break; case "ReadBarCode": if (!DiscountProcessStart) { switch (ReadBarCode.Length) { case 17: readBarCode = ReadBarCode.Substring(0, 16); FormatedBarCode = ReadBarCode.GetEncriptCardNo(); DoBarCodeMobileCompanyMemberCertify(); break; case 16: FormatedBarCode = ReadBarCode.GetEncriptCardNo(); DoBarCodeMobileCompanyMemberCertify(); break; default: FormatedBarCode = string.Empty; OKButtonEnabled = false; break; } } break; case "CertifyWindow": CertifyStartVisible = false; CertifyProcessingVisible = false; ProcessingErrorVisible = false; CertifySuccessVisible = false; switch (CertifyWindow) { case CertifyWindowType.CertifyStart: CertifyStartVisible = true; break; case CertifyWindowType.CertifyProcessing: CertifyProcessingVisible = true; break; case CertifyWindowType.ProcessingError: ProcessingErrorVisible = true; break; case CertifyWindowType.CertifySuccess: CertifySuccessVisible = true; break; } break; case "MobileCompany": MobileCompanyName = MobileCompany.GetMobileCompanyName(); break; case "CertifyStartVisible": if (CertifyStartVisible) { ScanGuidText = Languages.GetMessages("LBL0082"); InfoGuid1Text = new List(); InfoGuid2Text = Languages.GetMessages("LBL0003"); CancelButtonWidth = PopupWidth; OKButtonWidth = 0d; OKButtonEnabled = false; CancelButtonText = Languages.GetMessages("BTN0033"); TimeOutSeconds = CommonValue.TimeOutSeconds; } break; case "CertifyProcessingVisible": if (CertifyProcessingVisible) { ScanGuidText = new List(); InfoGuid1Text = new List(); InfoGuid2Text = new List(); CancelButtonWidth = 0d; OKButtonWidth = 0d; if (ProcessTask != null) ProcessTask.Wait(); ProcessTask = new Task(DoMobileCompanyMemberCertify); ProcessTask.Start(); } break; case "ProcessingErrorVisible": if (ProcessingErrorVisible) { ScanGuidText = Languages.GetMessages("LBL0077"); InfoGuid1Text = new List(); InfoGuid2Text = new List(); CancelButtonWidth = PopupWidth / 2; OKButtonWidth = PopupWidth / 2; OKButtonEnabled = true; OkButtonText = Languages.GetMessages("BTN0007"); CancelButtonText = Languages.GetMessages("BTN0033"); TimeOutSeconds = 10d; } break; case "CertifySuccessVisible": if (CertifySuccessVisible) { ScanGuidText = new List(); SuccessText = Languages.GetMessages("LBL0093"); InfoGuid1Text = new List(); InfoGuid2Text = new List(); CancelButtonWidth = 0d; OkButtonText = Languages.GetMessages("BTN0039"); OKButtonWidth = PopupWidth; OKButtonEnabled = true; TimeOutSeconds = 5d; } break; } } catch (Exception ex) { CommonLog.ErrorLogWrite(this, "VmMobileCompanyMemberCertify_PropertyChanged()", "Fail !!", string.Format("{0}\n{1}", ex.Message, ex.StackTrace)); } } #endregion Event Handlers } }