private void cardAdd() { //补卡 if (string.IsNullOrWhiteSpace(Detail.Card.SecondCardNo)) { Helper.ShowErrorMsg("请输入补卡卡号"); return; } if (Detail.Card.CardLevel == Guid.Empty || Detail.Card.CardLevel == null) { Helper.ShowErrorMsg("请选择卡级别"); return; } //DXInfo.Models.aspnet_CustomProfile user = this.Oper; //Guid userId = user.UserId; if (!ClientCommon.CheckUser(this.Oper)) { return; } var c = Uow.Cards.GetById(g => g.Id == Detail.Card.Id); if (!ClientCommon.CheckCard(c)) { return; } var d = Uow.CardLevels.GetById(g => g.Id == Detail.Card.CardLevel); if (d == null) { Helper.ShowErrorMsg("卡级别信息错误"); return; } if (!string.IsNullOrEmpty(d.BeginLetter)) { if (!Detail.Card.SecondCardNo.StartsWith(d.BeginLetter)) { Helper.ShowErrorMsg("卡号必须以" + d.BeginLetter + "字母开头"); return; } } var cardType = Uow.CardTypes.GetById(g => g.Id == Detail.Card.CardType); if (cardType == null) { Helper.ShowErrorMsg("卡型信息错误"); return; } string strComment; string strCardNoRule = ClientCommon.CardNoRule(cardType, out strComment); if (!Regex.IsMatch(Detail.Card.SecondCardNo, strCardNoRule)) { if (!string.IsNullOrEmpty(d.BeginLetter)) { Helper.ShowErrorMsg(strComment + ",且必须以" + d.BeginLetter + "字母开头"); return; } else { Helper.ShowErrorMsg(strComment); return; } } var c1 = Uow.Cards.GetAll().Where(w => w.CardNo == Detail.Card.SecondCardNo).FirstOrDefault(); if (c1 != null) { Helper.ShowErrorMsg("卡号已存在"); return; } StringBuilder sb = new StringBuilder(33); sb.Append(Detail.Card.SecondCardNo); //#if DEBUG // int st = 0; //#else int st = CardRef.CoolerPutCard(sb); //#endif if (st != 0) { MessageBox.Show(CardRef.GetStr(st)); return; } int value = Convert.ToInt32(Detail.Card.Balance * 100); //#if !DEBUG st = CardRef.CoolerRechargeCard(sb, value); //#endif //充值 if (st != 0) { MessageBox.Show(CardRef.GetStr(st)); return; } DateTime dtNow = DateTime.Now; using (TransactionScope transaction = new TransactionScope()) { DXInfo.Models.Cards newcard = new DXInfo.Models.Cards(); newcard.CardNo = Detail.Card.SecondCardNo; newcard.CardLevel = Detail.Card.CardLevel; newcard.CardType = Detail.Card.CardType; newcard.CreateDate = dtNow; newcard.UserId = this.Oper.UserId; newcard.DeptId = this.Dept.DeptId; newcard.Balance = Detail.Card.Balance; newcard.Member = Detail.Card.Member; newcard.CardPwd = Detail.Card.CardPwd; newcard.Comment = c.Comment; Uow.Cards.Add(newcard); Uow.Commit(); DXInfo.Models.CardsLog cardsLog = Mapper.Map <DXInfo.Models.Cards, DXInfo.Models.CardsLog>(newcard); cardsLog.CardId = newcard.Id; cardsLog.CreateDate = dtNow; cardsLog.UserId = this.Oper.UserId; cardsLog.DeptId = this.Dept.DeptId; Uow.CardsLog.Add(cardsLog); c.SecondCardNo = Detail.Card.SecondCardNo; c.AddDate = dtNow; c.AddDeptId = this.Dept.DeptId; c.AddUserId = this.Oper.UserId; c.Status = 2; Uow.Cards.Update(c); DXInfo.Models.CardsLog cardsLog1 = Mapper.Map <DXInfo.Models.Cards, DXInfo.Models.CardsLog>(c); cardsLog1.CardId = c.Id; cardsLog1.CreateDate = dtNow; cardsLog1.UserId = this.Oper.UserId; cardsLog1.DeptId = this.Dept.DeptId; Uow.CardsLog.Add(cardsLog1); DXInfo.Models.Recharges recharge = new DXInfo.Models.Recharges(); recharge.Amount = Detail.Card.Balance; recharge.Balance = Detail.Card.Balance; recharge.CreateDate = DateTime.Now; recharge.DeptId = this.Dept.DeptId; recharge.UserId = this.Oper.UserId; recharge.LastBalance = 0; recharge.Donate = 0; recharge.RechargeType = 1; recharge.Card = newcard.Id; Uow.Recharges.Add(recharge); if (Detail.Cost > 0) { recharge = new DXInfo.Models.Recharges(); recharge.Amount = Detail.Cost; recharge.Balance = 0; recharge.CreateDate = DateTime.Now; recharge.DeptId = this.Dept.DeptId; recharge.UserId = this.Oper.UserId; recharge.LastBalance = 0; recharge.Donate = 0; recharge.RechargeType = 3; recharge.Card = newcard.Id; Uow.Recharges.Add(recharge); } var qpt = Uow.CardPoints.GetAll().Where(w => w.Card == Detail.Card.Id); if (qpt.Count() > 0) { decimal pt = qpt.Sum(s => s.Point); if (pt != 0) { DXInfo.Models.CardPoints cp = new DXInfo.Models.CardPoints(); cp.Card = newcard.Id; cp.CreateDate = dtNow; cp.DeptId = this.Dept.DeptId; cp.Point = pt; cp.UserId = this.Oper.UserId; cp.PointType = 1; Uow.CardPoints.Add(cp); } } Uow.Commit(); transaction.Complete(); } MessageBox.Show("补卡成功"); this.query(); Detail = new CardAddPageDetail(); }
private void CardInMoneyExecute() { if (!this.Amount.HasValue) { throw new ArgumentNullException("请输入充值金额"); } decimal dAmount = this.Amount.Value; decimal dDonate = 0; if (this.Donate.HasValue) { dDonate = this.Donate.Value; } decimal dLastBalance = 0; if (this.CardBalance.HasValue) { dLastBalance = this.CardBalance.Value; } decimal dBalance = dAmount + dDonate + dLastBalance; DateTime dCreateDate = DateTime.Now; if (!this.CardType.IsVirtual) { StringBuilder sb = new StringBuilder(33); sb.Append(this.Card.CardNo); int value = Convert.ToInt32((dAmount + dDonate) * 100); //#if !DEBUG int st = CardRef.CoolerRechargeCard(sb, value); //#else // //string strCardNo = "12347"; // int st = 0; //#endif if (st != 0) { Helper.ShowErrorMsg(CardRef.GetStr(st)); return; } } DXInfo.Business.MemberManageFacade mb = new DXInfo.Business.MemberManageFacade(Uow); DXInfo.Business.CardInMoneyParaObj para = new DXInfo.Business.CardInMoneyParaObj(); para.DeptId = Dept.DeptId; para.DeptName = Dept.DeptName; para.UserId = User.UserId; para.UserName = User.UserName; para.FullName = Oper.FullName; para.PayTypeId = SelectedPayType.Id; para.PayTypeName = SelectedPayType.Name; para.CardId = Card.Id; para.LastBalance = dLastBalance; para.Balance = dBalance; para.MemberName = Member.MemberName; para.CreateDate = dCreateDate; para.Amount = dAmount; para.Donate = dDonate; para.RechargeType = (int)DXInfo.Models.RechargeType.PutCardInMoney; mb.CardInMoney(para); if (this.IsThree) { LocalReport report = new LocalReport(); report.ReportPath = GetThreePrintFile(DXInfo.Models.NameCodeType.ThreePrintInMoney); NoMemberThreePrintObject threePrintObject = new NoMemberThreePrintObject(); threePrintObject.Title = ClientCommon.PrintTicketTitle(DXInfo.Models.NameCodeType.PrintTicketTitleOfMember); threePrintObject.CardNo = this.Card.CardNo; threePrintObject.MemberName = this.Member.MemberName; threePrintObject.LastBalance = dLastBalance; threePrintObject.Amount = dAmount; threePrintObject.Donate = dDonate; threePrintObject.PayTypeName = this.SelectedPayType.Name; threePrintObject.Balance = dBalance; threePrintObject.FullName = this.Oper.FullName; threePrintObject.UserName = this.User.UserName; threePrintObject.DeptName = this.Dept.DeptName; threePrintObject.CreateDate = dCreateDate; threePrintObject.ButtomTitle = ClientCommon.PrintTicketButtomTitle(DXInfo.Models.NameCodeType.ThreeButtomTitleInMoney); DataTable dt = threePrintObject.ToDataTable(); report.DataSources.Add( new ReportDataSource("DataSet1", dt) ); PrintRDLC printRDLC = new PrintRDLC(); printRDLC.Run(report); } else { string title = ClientCommon.PrintTicketTitle(DXInfo.Models.NameCodeType.PrintTicketTitleOfMember); InMoneyPrintObject po = new InMoneyPrintObject(title, this.Card.CardNo, this.Member.MemberName, dLastBalance, dBalance, dAmount, dDonate, this.SelectedPayType.Name , this.Oper.FullName, this.User.UserName, this.Dept.DeptName, dCreateDate); po.Print(); } MessageBox.Show("充值成功"); this.ResetSwipingCard(); this.Amount = null; this.Donate = null; this.SelectedPayType = null; }