private bool Print(VIPPredepositTrack prestore) { var vp = new VIPPrestorePrintEntity { CreateTime = prestore.CreateTime, Remark = prestore.Remark, FreeMoney = prestore.FreeMoney, RefrenceBillCode = prestore.RefrenceBillCode, ShopAddress = OrganizationListVM.CurrentOrganization.Address, ShopName = OrganizationListVM.CurrentOrganization.Name, StoreMoney = prestore.StoreMoney, VIPCode = _vip.Code, VIPName = _vip.CustomerName }; decimal balance = 0; decimal.TryParse(tbBalance.Text, NumberStyles.Number | NumberStyles.AllowCurrencySymbol, CultureInfo.CreateSpecificCulture("zh-CN"), out balance); balance += prestore.StoreMoney + prestore.FreeMoney; vp.Balance = balance; try { View.Extension.UIHelper.Print("PreStorePrintTemplate.xaml", vp); } catch (Exception ex) { MessageBox.Show("打印凭证出错:" + ex.Message); return(false); } return(true); }
private void btnOK_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(txtCode.Text)) { MessageBox.Show("请扫描输入VIP卡号."); return; } if (txtCode.Text != _vip.Code) { MessageBox.Show("请输入正确的卡号."); txtCode.Clear(); _timeInputCode = null; txtCode.Focus(); return; } if (string.IsNullOrWhiteSpace(txtPassword.Password)) { MessageBox.Show("请输入预存密码."); return; } if (txtPassword.Password.ToMD5String() != _vip.PrestorePassword) { MessageBox.Show("预存密码错误."); return; } VIPPredepositTrack predeposit = this.DataContext as VIPPredepositTrack; if (predeposit.StoreMoney == 0) { MessageBox.Show("充值金额不能为0."); return; } if (string.IsNullOrWhiteSpace(predeposit.Remark)) { predeposit.Remark = "现金预存"; } predeposit.OrganizationID = VMGlobal.CurrentUser.OrganizationID; predeposit.CreatorID = VMGlobal.CurrentUser.ID; predeposit.Kind = true; var result = WebApiInvoker.Instance.Invoke <OPResult <VIPPredepositTrack>, VIPPredepositTrack>(predeposit, "BillRetail/SaveVIPPrestore"); MessageBox.Show(result.Message); if (result.IsSucceed) { predeposit = result.Result; _vip.Predeposits.Insert(0, predeposit); if (ckPrint.IsChecked.HasValue && ckPrint.IsChecked.Value) { this.Print(predeposit); } this.Close(); } }
public OPResult <VIPPredepositTrack> SaveVIPPrestore(VIPPredepositTrack prestore) { DateTime time = DateTime.Now; prestore.CreateTime = time; string timestr = "-" + time.ToString("yyyyMMdd"); string prefixion = "VP"; using (var dbContext = new DistributionEntities()) { try { //if (string.IsNullOrEmpty(prestore.RefrenceBillCode))//预存金额 var maxCode = dbContext.VIPPredepositTrack.Where(o => o.OrganizationID == prestore.OrganizationID && o.RefrenceBillCode.StartsWith(prefixion) && o.RefrenceBillCode.Contains(timestr)).Max(t => t.RefrenceBillCode); if (string.IsNullOrEmpty(maxCode)) { var ocode = dbContext.ViewOrganization.Where(b => b.ID == prestore.OrganizationID).Select(o => o.Code).First(); maxCode = prefixion + ocode + timestr + "000"; } int preLength = maxCode.Length - 3; prestore.RefrenceBillCode = maxCode.Substring(0, preLength) + (Convert.ToInt32(maxCode.Substring(preLength)) + 1).ToString("000"); var balance = dbContext.VIPPredepositTrack.Where(o => o.VIPID == prestore.VIPID).Sum(o => (decimal?)(o.StoreMoney + o.FreeMoney - o.ConsumeMoney)); dbContext.VIPPredepositTrack.Add(prestore); dbContext.SaveChanges(); return(new OPResult <VIPPredepositTrack> { IsSucceed = true, Message = string.Format("保存成功, 当前余额:{0:C2}", (balance ?? 0) + prestore.StoreMoney + prestore.FreeMoney), Result = prestore }); } catch (Exception e) { return(new OPResult <VIPPredepositTrack> { IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message }); } } }
public OPResult <BillRetail> SaveBillRetail(BillRetailBO bo) { //bo.Bill.CreateTime = DateTime.Now; using (var dbContext = new DistributionEntities()) { if (bo.RefrenseVIPUpTactics != null && bo.VIPPointRecord != null) { IEnumerable <int> kindIDs = bo.RefrenseVIPUpTactics.Select(o => o.Tactic.FormerKindID).ToList(); IEnumerable <VIPCardKindMapping> mappings = dbContext.VIPCardKindMapping.Where(o => o.CardID == bo.VIPPointRecord.VIPID && kindIDs.Contains(o.KindID)).ToList(); foreach (var mapping in mappings) { var t = bo.RefrenseVIPUpTactics.First(o => o.Tactic.FormerKindID == mapping.KindID); mapping.KindID = t.Tactic.AfterKindID; if (t.Tactic.CutPoint != 0) { dbContext.VIPPointTrack.Add(new VIPPointTrack { CreateTime = DateTime.Now, Point = (-1 * t.Tactic.CutPoint), VIPID = bo.VIPPointRecord.VIPID, Remark = "VIP升级产生," + t.Description }); } } } using (TransactionScope scope = new TransactionScope()) { try { bo.Bill.Code = BillHelper.GenerateBillCode <BillRetail>(bo.Bill.OrganizationID, dbContext); BillHelper.SaveBill <BillRetail, BillRetailDetails>(bo, dbContext, bo.SpecifcCreateTime); foreach (var storeout in bo.BillStoreOuts) { storeout.Bill.CreateTime = DateTime.Now; storeout.Bill.RefrenceBillCode = bo.Bill.Code; BillHelper.SaveBillStoreOut(storeout, dbContext); } foreach (var storing in bo.BillStorings) { storing.Bill.CreateTime = DateTime.Now; storing.Bill.RefrenceBillCode = bo.Bill.Code; BillHelper.SaveBillStoring(storing, dbContext); } if (bo.VIPPointRecord != null) { bo.VIPPointRecord.Remark = "零售单产生,小票号" + bo.Bill.Code; dbContext.VIPPointTrack.Add(bo.VIPPointRecord); if (bo.Bill.PredepositPay != 0) { VIPPredepositTrack predepositTrack = new VIPPredepositTrack { RefrenceBillCode = bo.Bill.Code, Kind = false, OrganizationID = bo.Bill.OrganizationID, CreatorID = bo.Bill.CreatorID, CreateTime = DateTime.Now, ConsumeMoney = bo.Bill.PredepositPay, VIPID = bo.VIPPointRecord.VIPID, Remark = "零售单产生" }; dbContext.VIPPredepositTrack.Add(predepositTrack); } } if (bo.VIPBirthdayConsumption != null) { bo.VIPBirthdayConsumption.ConsumeDay = DateTime.Now.Date; dbContext.VIPBirthdayConsumption.Add(bo.VIPBirthdayConsumption); } dbContext.SaveChanges(); scope.Complete(); } catch (Exception e) { return(new OPResult <BillRetail> { IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message }); } } } return(new OPResult <BillRetail> { IsSucceed = true, Message = "保存成功!", Result = bo.Bill }); }