private async void CarwashSell() { EnableCommand = false; //var socket = new Windows.Networking.Sockets.StreamSocket(); //var serverHost = new Windows.Networking.HostName(_cacheBussinessLogic.REWARDS_TpsIp); try { _AckCWStockCode = await _ackrooBusinessLogic.GetAckrooCarwashStockCode(SelectedCarwashCategory); if (string.IsNullOrEmpty(_AckCWStockCode)) { ShowNotification("The stock code for Ackroo Carwash is not available.~Ackroo Carwash", null, null, ApplicationConstants.ButtonWarningColor ); return; } if (string.IsNullOrEmpty(CarwashUnits)) { ShowNotification("Please enter the number of units for the carwash.~Ackroo Carwash", null, null, ApplicationConstants.ButtonWarningColor ); return; } int iUnit; if (!int.TryParse(CarwashUnits, out iUnit)) { ShowNotification("Please enter a number for Carwash unit.~Ackroo Carwash", null, null, ApplicationConstants.ButtonWarningColor ); return; } NotifyInfo = "Processing Ackroo Carwash..."; XDocument doc = await Helper.SockeRequest( _cacheBussinessLogic.REWARDS_TpsIp, _cacheBussinessLogic.REWARDS_TpsPort.ToString(), TPSRequest() ); if (doc == null) { ShowNotification("There is no response.~Ackroo Carwash", null, null, ApplicationConstants.ButtonWarningColor ); NotifyInfo = ""; return; } _AckBLInfo = GetBalaceInfo(doc); if (_AckBLInfo.TransactionStatus != "APPROVED") { NotifyInfo = _AckBLInfo.ResponseMessage; return; } //add product to current sale var result = await _saleBussinessLogic.AddStockToSale(_AckCWStockCode, int.Parse(CarwashUnits), false, null, false ); SoundService.Instance.PlaySoundFile(SoundTypes.stockFound); var sale = result.ToModel(); //update sale screen MessengerInstance.Send(sale, "UpdateSale"); NotifyInfo = "The Carwash service is activated."; EnablePrint = true; } catch (Exception ex) { ShowNotification(ex.Message + "~Ackroo Carwash", null, null, ApplicationConstants.ButtonWarningColor ); NotifyInfo = ""; } }
private AckrooBalanceInfo GetBalaceInfo(XDocument doc) { AckrooBalanceInfo ackbalance = new AckrooBalanceInfo(); XElement xe; xe = GetElement(doc, "TransactionStatus"); if (xe != null) { ackbalance.TransactionStatus = xe.Value; } xe = GetElement(doc, "ResponseMessage"); if (xe != null) { ackbalance.ResponseMessage = xe.Value; } switch (_CurrentType) { case AckReqType.ACTIVATION: xe = GetElement(doc, "AmountFunded"); if (xe != null) { if (!string.IsNullOrEmpty(xe.Value)) { ackbalance.AmountFunded = xe.Value; } } xe = GetElement(doc, "ElBalance"); if (xe != null && !string.IsNullOrEmpty(xe.Value)) { ackbalance.LoyaltyBalace = string.Format("{0:C2}", double.Parse(xe.Value)); } else { ackbalance.LoyaltyBalace = string.Format("{0:C2}", 0); } xe = GetElement(doc, "GcBalance"); if (xe != null && !string.IsNullOrEmpty(xe.Value)) { ackbalance.GiftBalance = string.Format("{0:C2}", double.Parse(xe.Value)); } else { ackbalance.GiftBalance = string.Format("{0:C2}", 0); } break; case AckReqType.BALANCE: xe = GetElement(doc, "Active"); if (xe != null) { if (Boolean.Parse(xe.Value) == true) { ackbalance.Active = "Active"; } else { ackbalance.Active = "InActive"; } } xe = GetElement(doc, "Gift"); if (xe != null) { ackbalance.GiftBalance = string.Format("{0:C2}", double.Parse(xe.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture)); } xe = GetElement(doc, "Loyalty"); if (xe != null) { ackbalance.LoyaltyBalace = string.Format("{0:C2}", double.Parse(xe.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture)); } XNamespace ns = doc.Root.GetDefaultNamespace(); IEnumerable <XElement> clist = from c in doc.Descendants(ns + "Carwash") select c; AckrooItem ackitem = null; int iCount; if (clist != null) { ackbalance.Categories = new List <AckrooItem>(); foreach (XElement item in clist) { iCount = 0; foreach (XElement xxe in item.Elements()) { if (iCount == 0 && ackitem == null) { ackitem = new AckrooItem(); } if (xxe.Name.LocalName == "Category") { ackitem.Name = xxe.Value; iCount++; } if (xxe.Name.LocalName == "Balance") { ackitem.Value = xxe.Value; iCount++; } if (iCount == 2) { iCount = 0; ackbalance.Categories.Add(ackitem); ackitem = null; } } } } break; case AckReqType.INCREASE: xe = GetElement(doc, "AmountFunded"); if (xe != null) { ackbalance.Increment = string.Format("{0:C2}", double.Parse(xe.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture)); } xe = GetElement(doc, "ElBalance"); if (xe != null) { ackbalance.LoyaltyBalace = string.Format("{0:C2}", double.Parse(xe.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture)); } xe = GetElement(doc, "GcBalance"); if (xe != null) { ackbalance.GiftBalance = string.Format("{0:C2}", double.Parse(xe.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture)); } break; case AckReqType.CARWASH: xe = GetElement(doc, "ElBalance"); if (xe != null) { ackbalance.LoyaltyBalace = string.Format("{0:C2}", double.Parse(xe.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture)); } xe = GetElement(doc, "GcBalance"); if (xe != null) { ackbalance.GiftBalance = string.Format("{0:C2}", double.Parse(xe.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture)); } break; } return(ackbalance); }
private async void ActivateCard() { NotifyInfo = ""; double dAmount = 0; try { if (string.IsNullOrEmpty(CardNumber)) { ShowNotification("Card number is not entered.~Activate Card", null, null, ApplicationConstants.ButtonWarningColor ); return; } if (!double.TryParse(AckrooAmount, out dAmount)) { ShowNotification("The amount format is invalid.~Activate Card", null, null, ApplicationConstants.ButtonWarningColor ); return; } EnableCommand = false; NotifyInfo = "Processing..."; XDocument doc = await Helper.SockeRequest( _cacheBussinessLogic.REWARDS_TpsIp, _cacheBussinessLogic.REWARDS_TpsPort.ToString(), TPSRequest() ); if (doc == null) { ShowNotification("There is no response.~Activate Card", null, null, ApplicationConstants.ButtonWarningColor ); NotifyInfo = ""; return; } _AckBLInfo = GetBalaceInfo(doc); if (_AckBLInfo.TransactionStatus != "APPROVED") { NotifyInfo = _AckBLInfo.ResponseMessage; return; } //add product to current sale if (dAmount > 0) { var result = await _saleBussinessLogic.AddStockToSale(_AckStockCode, 1, false, null, false ); SoundService.Instance.PlaySoundFile(SoundTypes.stockFound); var sale = result.ToModel(); SaleLineModel sl = (SaleLineModel)sale.SaleLines[sale.SaleLines.Count - 1]; var saleupdate = await _saleBussinessLogic.UpdateSale( sl.LineNumber, "", "", "1", string.Format("{0:0.00}", double.Parse(AckrooAmount)), "", "" ); //update sale screen MessengerInstance.Send(saleupdate.ToModel(), "UpdateSale"); } NotifyInfo = "The card is successfully activated."; EnablePrint = true; } catch (Exception ex) { ShowNotification(ex.Message + "~Activate Card", null, null, ApplicationConstants.ButtonWarningColor ); NotifyInfo = ""; } }
private async void AckrooCheckBalance() { BalanceInfo = ""; NotifyInfo = ""; if (string.IsNullOrEmpty(CardNumber)) { ShowNotification("Card number is not entered.~Balance Request", null, null, ApplicationConstants.ButtonWarningColor ); return; } EnableCommand = false; try { BalanceInfo = "Requesting Card Balance..."; XDocument doc = await Helper.SockeRequest( _cacheBussinessLogic.REWARDS_TpsIp, _cacheBussinessLogic.REWARDS_TpsPort.ToString(), TPSRequest() ); if (doc == null) { ShowNotification("There is no response.~Balance Request", null, null, ApplicationConstants.ButtonWarningColor ); BalanceInfo = ""; return; } _AckBLInfo = GetBalaceInfo(doc); if (_AckBLInfo.TransactionStatus != "APPROVED") { BalanceInfo = _AckBLInfo.ResponseMessage; return; } EnablePrint = true; StringBuilder sb = new StringBuilder(); string sVal = "Ackroo Card Status:".ToUpper(); string sTemp = string.Format("{0,25} {1,-15}", sVal, _AckBLInfo.Active); sb.Append(sTemp + Environment.NewLine); sVal = "Loyalty Balance:".ToUpper(); sTemp = string.Format("{0,30} {1,-15}", sVal, _AckBLInfo.LoyaltyBalace); sb.Append(sTemp + Environment.NewLine); sVal = "Gift Balance:".ToUpper(); sTemp = string.Format("{0,34} {1,-15}", sVal, _AckBLInfo.GiftBalance); sb.Append(sTemp + Environment.NewLine); foreach (var c in _AckBLInfo.Categories) { sTemp = string.Format("{0,27} {1,-15}", (c.Name.ToUpper() + ":"), c.Value); sb.Append(sTemp + Environment.NewLine); } BalanceInfo = sb.ToString(); } catch (Exception ex) { BalanceInfo = ""; ShowNotification(ex.Message + "~Balance Request", null, null, ApplicationConstants.ButtonWarningColor ); } }
private async void CardNumberEntered(object s) { if (!Helper.IsEnterKey(s)) { return; } NotifyInfo = ""; if (string.IsNullOrEmpty(CardNumber)) { ShowNotification("Card number is not entered.~Balance Request", null, null, ApplicationConstants.ButtonWarningColor ); return; } try { NotifyInfo = "Requesting Card Balance..."; XDocument doc = await Helper.SockeRequest( _cacheBussinessLogic.REWARDS_TpsIp, _cacheBussinessLogic.REWARDS_TpsPort.ToString(), TPSRequest(AckReqType.BALANCE) ); NotifyInfo = ""; if (doc == null) { ShowNotification("There is no response.~Balance Request", null, null, ApplicationConstants.ButtonWarningColor ); return; } _AckBLInfo = GetBalaceInfo(doc, AckReqType.BALANCE); if (_AckBLInfo.TransactionStatus != "APPROVED") { ShowNotification(_AckBLInfo.ResponseMessage + "~Balance Request", null, null, ApplicationConstants.ButtonWarningColor ); return; } if (!string.IsNullOrEmpty(_AckBLInfo.LoyaltyBalace)) { _loyaltyBalanceAmount = double.Parse(_AckBLInfo.LoyaltyBalace.Replace("$", "")); } else { _loyaltyBalanceAmount = 0; } if (!string.IsNullOrEmpty(_AckBLInfo.GiftBalance)) { _giftBalanceAmount = double.Parse(_AckBLInfo.GiftBalance.Replace("$", "")); } else { _giftBalanceAmount = 0; } if (_loyaltyBalanceAmount == 0 && _giftBalanceAmount == 0) { ShowNotification("The card is empty.~Balance Request", null, null, ApplicationConstants.ButtonWarningColor ); return; } } catch (Exception ex) { NotifyInfo = ""; ShowNotification(ex.Message + "~Balance Request", null, null, ApplicationConstants.ButtonWarningColor ); return; } PopupService.IsAckTenderPopOpen = false; PopupService.IsPopupOpen = false; PopupService.IsAckBalacePopOpen = true; IsEnabled = false; IsBalanceOKEnabled = false; MessengerInstance.Send(new AckrooAccoutBalanceMessage()); }