/// <summary> /// Creates a new instance of the <see cref="ScanQrCodePage"/> class. /// For unit tests. /// </summary> /// <param name="viewModel">The view model to use.</param> protected internal ScanQrCodePage(ScanQrCodeViewModel viewModel) { this.ViewModel = viewModel ?? new ScanQrCodeViewModel(); this.navigationService = DependencyService.Resolve <INavigationService>(); this.uiDispatcher = DependencyService.Resolve <IUiDispatcher>(); InitializeComponent(); }
public MainViewModel( IUserDialogs userDialogs, INavigationService navigationService, IEventAggregator eventAggregator, IAgentProvider agentContextProvider, IWalletRecordService walletRecordService, ILifetimeScope lifetimeScope, ConnectionsViewModel connectionsViewModel, CredentialsViewModel credentialsViewModel, AccountViewModel accountViewModel, CreateInvitationViewModel createInvitationViewModel, ProofRequestsViewModel proofRequestsViewModel, ScanQrCodeViewModel scanQrCodeViewModel ) : base(nameof(MainViewModel), userDialogs, navigationService) { Connections = connectionsViewModel; Credentials = credentialsViewModel; Account = accountViewModel; CreateInvitation = createInvitationViewModel; ProofRequests = proofRequestsViewModel; ScanQrCode = scanQrCodeViewModel; _eventAggregator = eventAggregator; _walletRecordService = walletRecordService; _agentContextProvider = agentContextProvider; _lifetimeScope = lifetimeScope; //for prompting dialog on connection events //WalletEventService.Init(navigationService); }
private void ContentPage_Appearing(object sender, EventArgs e) { //ScannerView.IsScanning = true; //ScannerView.IsAnalyzing = true; _vm = BindingContext as ScanQrCodeViewModel; //_vm?.PageAppearingCommand.Execute(null); CreateScannerView("QrCodeScanner", new List <BarcodeFormat> { BarcodeFormat.QR_CODE }, ZXingScannerView_OnScanResult); if (Scanner != null) { Scanner.IsAnalyzing = true; } base.OnAppearing(); }
/// <summary> /// 二维码扫描处理方法 /// </summary> /// <param name="p">二维码所属包ID</param> /// <param name="sn">二维码的信息编码</param> /// <param name="userId">扫描人的用户ID</param> /// <param name="userType">扫描人的用户类型</param> /// <returns>二维码扫描结果</returns> public string ScanQrCode(string sn = "", int userId = 0, int userType = 0) { ScanQrCodeViewModel scanResult = new ScanQrCodeViewModel(); scanResult.IsSuccess = false; scanResult.Msg = "扫描二维码无效,请换一瓶"; if (string.IsNullOrEmpty(sn)) { scanResult.ReturnUrl = "二维码不存在"; } var totalIntegral = 0; var rowNumber = 0; //var memberInfo = _memberService.Find(userId); RegistMember memberInfo = (from o in db.RegistMember where o.MemberId == userId select o).FirstOrDefault(); string isChance = ""; //标识,判断是否为活动概率规则 if (!string.IsNullOrEmpty(sn)) { var code = EncryptHelper.Confusion(sn); if (!string.IsNullOrEmpty(code) && code.Length == 18) { //获取二维码 IntegralGoodsQrc qrc = (from o in db.IntegralGoodsQrc where o.Code == code select o).FirstOrDefault(); if (qrc.State == 1) { var wrapCode = code.Substring(0, 2); var categoryCode = code.Substring(2, 2); var factoryCode = code.Substring(4, 2); var monthCode = code.Substring(6, 2); var productCode = code.Substring(8); //获取积分规则 DateTime date = DateTime.Now; var integralModel = (from o in db.IntegralRule join c in db.IntegralGoods on o.GoodsId equals c.GoodsId where o.RuleState != 100 && c.GoodsState != 100 && c.GoodsNo == categoryCode && o.StartDate <date && o.EndDate> date orderby o.RuleType descending select o).FirstOrDefault(); if (memberInfo.IsEnable == 0 && (memberInfo.RecommendId > 0 || integralModel.RuleId == 83)) { if (integralModel != null) { int count = 0; int scanIntegral = 0; //使用二维码;添加商品积分记录;增加积分 var flag = Scan(integralModel.GoodsId, userId, qrc.QrcId, integralModel.Integral, (int)integralModel.RuleType, code, memberInfo.MemberCode, memberInfo.HotelName, out count, out scanIntegral, out isChance); if (flag) { //操作成功 scanResult.IsSuccess = true; if (integralModel.ScanLimit > 0) { if (count >= integralModel.ScanLimit) { //int score = integralModel.Integral / 2; scanResult.Msg = string.Format("恭喜您!成功增加{0}积分", scanIntegral); } else { scanResult.Msg = string.Format("恭喜您!成功增加{0}积分", scanIntegral); } } else { scanResult.Msg = string.Format("恭喜您!成功增加{0}积分", scanIntegral); } } else { //操作失败 scanResult.Msg = "增加积分失败,请换一瓶。"; } } else { scanResult.Msg = "该产品不存在或者还没有对应的积分规则。"; } } else { scanResult.Msg = "产品积分扫码活动只针对已认证会员开展,未认证会员暂时无法扫描积分卡片。"; } } else { scanResult.Msg = string.Format("该二维码已被使用过。"); } } } scanResult.TotalIntegral = totalIntegral; scanResult.RowNumber = rowNumber; return(scanResult.Msg + isChance.ToString()); }