private void FindItemAndAddToPayModel(BalanceItemModel item, double changePriceDouble) { CommonPayModel model = new CommonPayModel(); if (item.IsBalance) { model.BalanceId = item.Balance.BalanceId; model.OriginalPrice = changePriceDouble; model.Rate = item.Balance.RemoveRate; if (model.Rate != 0) { model.Price = Math.Round(model.OriginalPrice * model.Rate, 2); model.RemovePrice = model.OriginalPrice - model.Price; } else { model.Price = model.OriginalPrice; } } else if (!item.IsBalance) { if (this.IsMember) { model.MemberId = item.Member.MemberId; model.Rate = item.Member.OfferRate; model.Member = item.Member; } else { model.SupplierId = item.Supplier.SupplierId; model.Rate = item.Supplier.OfferRate; model.Supplier = item.Supplier; } model.IsChange = item.IsChange; model.OriginalPrice = changePriceDouble; if (model.Rate != 0) { model.Price = Math.Round(model.OriginalPrice / 100.0 * model.Rate, 2); model.RemovePrice = model.OriginalPrice - model.Price; } else { model.Price = model.OriginalPrice; } } PayModel.Add(model); }
/// <summary> /// 去掉会员 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMemberRemove_Click(object sender, EventArgs e) { BalanceItemModel model = krpcbBalancePay.SelectedItem as BalanceItemModel; long id = 0; if (null != model.Member) { id = model.Member.MemberId; } else if (null != model.Supplier) { id = model.Supplier.SupplierId; } List <CommonPayModel> removeModel = new List <CommonPayModel>(); foreach (var item in PayModel.Where(x => x.IsChange)) { if (IsMember && item.MemberId == id) { removeModel.Add(item); } else if (!IsMember && item.SupplierId == id) { removeModel.Add(item); } } foreach (var item in removeModel) { this.PayModel.Remove(item); } krpcbBalancePay.Items.Remove(model); IsAddedMemberOrSupplier = false; ReloadBalanceList(); Calc(); if (IsCheckout) { Recalc(); } }
private void krplMemberName_MouseClick(object sender, MouseEventArgs e) { if (krpcbBalancePay.Items.Count > 0 && null != CurrentBalance && CurrentBalance.IsBalance && null != CurrentBalance.Balance) { BalanceItemModel model = krpcbBalancePay.Items[krpcbBalancePay.Items.Count - 1] as BalanceItemModel; double changePrice = double.Parse(this.krptChangePrice.Text); if (changePrice != 0 && null != model && null != model.Member && model.IsChange) { string memberName = ""; string balanceName = ""; if (Resources.GetRes().MainLangIndex == 0) { memberName = model.Member.MemberName0; } else if (Resources.GetRes().MainLangIndex == 1) { memberName = model.Member.MemberName1; } else if (Resources.GetRes().MainLangIndex == 2) { memberName = model.Member.MemberName2; } if (Resources.GetRes().MainLangIndex == 0) { balanceName = CurrentBalance.Balance.BalanceName0; } else if (Resources.GetRes().MainLangIndex == 1) { balanceName = CurrentBalance.Balance.BalanceName1; } else if (Resources.GetRes().MainLangIndex == 2) { balanceName = CurrentBalance.Balance.BalanceName2; } var confirm = KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("ConfirmAddPay"), Resources.GetRes().PrintInfo.PriceSymbol, ChangePrice, balanceName, memberName), Resources.GetRes().GetString("Warn"), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirm != DialogResult.Yes) { return; } MemberPay memberpay = new MemberPay(); memberpay.Price = changePrice; memberpay.BalanceId = CurrentBalance.Balance.BalanceId; memberpay.MemberId = model.Member.MemberId; // 开始支付 StartLoad(this, null); Task.Factory.StartNew(() => { ResultModel result = new ResultModel(); double originalBalancePrice = model.Member.BalancePrice; try { // 更新会员信息 model.Member.BalancePrice = model.Member.BalancePrice + memberpay.Price; Member newMember; MemberPay newMemberPay; result = OperatesService.GetOperates().ServiceAddMemberPay(model.Member, memberpay, out newMember, out newMemberPay); this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); // 去掉当前最后一个会员并重新添加 btnMemberRemove_Click(null, null); AddMember(newMember, null); } else { if (result.IsDataHasRefrence) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUsed"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (result.UpdateModel) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUnSame"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveFailt"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { // 失败了就复原会员信息 if (result.Result) { model.Member.BalancePrice = originalBalancePrice; } KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); }); } else if (changePrice != 0 && null != model && null != model.Supplier && model.IsChange) { string supplierName = ""; string balanceName = ""; if (Resources.GetRes().MainLangIndex == 0) { supplierName = model.Supplier.SupplierName0; } else if (Resources.GetRes().MainLangIndex == 1) { supplierName = model.Supplier.SupplierName1; } else if (Resources.GetRes().MainLangIndex == 2) { supplierName = model.Supplier.SupplierName2; } if (Resources.GetRes().MainLangIndex == 0) { balanceName = CurrentBalance.Balance.BalanceName0; } else if (Resources.GetRes().MainLangIndex == 1) { balanceName = CurrentBalance.Balance.BalanceName1; } else if (Resources.GetRes().MainLangIndex == 2) { balanceName = CurrentBalance.Balance.BalanceName2; } var confirm = KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("ConfirmAddPay"), Resources.GetRes().PrintInfo.PriceSymbol, ChangePrice, balanceName, supplierName), Resources.GetRes().GetString("Warn"), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirm != DialogResult.Yes) { return; } SupplierPay supplierpay = new SupplierPay(); supplierpay.Price = changePrice; supplierpay.BalanceId = CurrentBalance.Balance.BalanceId; supplierpay.SupplierId = model.Supplier.SupplierId; // 开始支付 StartLoad(this, null); Task.Factory.StartNew(() => { ResultModel result = new ResultModel(); double originalBalancePrice = model.Supplier.BalancePrice; try { // 更新供应者信息 model.Supplier.BalancePrice = model.Supplier.BalancePrice + supplierpay.Price; Supplier newSupplier; SupplierPay newSupplierPay; result = OperatesService.GetOperates().ServiceAddSupplierPay(model.Supplier, supplierpay, out newSupplier, out newSupplierPay); this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); // 去掉当前最后一个供应者并重新添加 btnMemberRemove_Click(null, null); AddMember(null, newSupplier); } else { if (result.IsDataHasRefrence) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUsed"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (result.UpdateModel) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUnSame"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveFailt"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { // 失败了就复原供应者信息 if (result.Result) { model.Supplier.BalancePrice = originalBalancePrice; } KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); }); } } }
/// <summary> /// 会员变化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void krpcbBalancePay_SelectedIndexChanged(object sender, EventArgs e) { krpbSave.Enabled = true; krpbAdd.Enabled = true; BalanceItemModel item = krpcbBalancePay.SelectedItem as BalanceItemModel; CurrentBalance = item; if (!item.IsBalance) { flpMember.Visible = true; if (item.IsChange) { btnMemberAdd.Visible = false; btnMemberRemove.Visible = true; krplMemberNameValue.Visible = true; if (IsMember) { if (Resources.GetRes().MainLangIndex == 0) { krplMemberNameValue.Text = item.Member.MemberName0; } else if (Resources.GetRes().MainLangIndex == 1) { krplMemberNameValue.Text = item.Member.MemberName1; } else if (Resources.GetRes().MainLangIndex == 2) { krplMemberNameValue.Text = item.Member.MemberName2; } } else { if (Resources.GetRes().MainLangIndex == 0) { krplMemberNameValue.Text = item.Supplier.SupplierName0; } else if (Resources.GetRes().MainLangIndex == 1) { krplMemberNameValue.Text = item.Supplier.SupplierName1; } else if (Resources.GetRes().MainLangIndex == 2) { krplMemberNameValue.Text = item.Supplier.SupplierName2; } } } else { krpbSave.Enabled = false; krpbAdd.Enabled = false; flpMember.Visible = false; } } else { if (IsAddedMemberOrSupplier) { flpMember.Visible = false; } else { flpMember.Visible = true; btnMemberAdd.Visible = true; btnMemberRemove.Visible = false; krplMemberNameValue.Visible = false; } } if (IsMember && !Common.GetCommon().IsBindMemberByNo()) { flpMember.Visible = false; } else if (!IsMember && !Common.GetCommon().IsBindSupplierByNo()) { flpMember.Visible = false; } }
private bool FindItemAndAddPrice(Action _action = null) { double changePriceDouble = double.Parse(ChangePrice); // 去掉的钱不能超出总支付金额 if (Mark == "-") { if (!Common.GetCommon().IsReturnMoney() && changePriceDouble > Math.Round(PayModel.Sum(x => x.OriginalPrice), 2)) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("CanNotExceed"), Math.Round(PayModel.Sum(x => x.OriginalPrice), 2)), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } if (0 != changePriceDouble) { if (krpcbBalancePay.SelectedIndex == -1) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("OperateFaild"), Resources.GetRes().GetString("Save")), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } BalanceItemModel item = krpcbBalancePay.SelectedItem as BalanceItemModel; if (!item.IsChange) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("OperateFaild"), Resources.GetRes().GetString("Save")), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (!item.IsBalance) { if (null != item.Member) { double originalPrice = PayModel.Where(x => x.IsChange && x.MemberId == item.Member.MemberId).Sum(x => x.OriginalPrice); // 输入的钱不能多于余额 if (Mark == "+") { if (Math.Round(originalPrice / 100.0 * item.Member.OfferRate, 2) + Math.Round(changePriceDouble / 100.0 * item.Member.OfferRate, 2) > item.Member.BalancePrice) { if (item.Member.IsAllowBorrow == 1 || Resources.GetRes().AdminModel.Mode == 2) { if (KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("ConfirmItemBalanceNotEnough"), Resources.GetRes().GetString("Member")), Resources.GetRes().GetString("Warn"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return(false); } } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("MemberBalanceNotEnough"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } } originalPrice = PayModel.Where(x => x.MemberId == item.Member.MemberId).Sum(x => x.OriginalPrice); // 去掉的钱不能多于该会员为这个订单总共消耗的金额 if (!Common.GetCommon().IsReturnMoney() && Mark == "-" && originalPrice + (-changePriceDouble) < 0) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("MemberBalanceNotEnough"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } else if (null != item.Supplier) { double originalPrice = PayModel.Where(x => x.IsChange && x.SupplierId == item.Supplier.SupplierId).Sum(x => x.OriginalPrice); // 输入的钱不能多于余额 if (Mark == "+") { if (Math.Round(originalPrice / 100.0 * item.Supplier.OfferRate, 2) + Math.Round(changePriceDouble / 100.0 * item.Supplier.OfferRate, 2) > item.Supplier.BalancePrice) { if (item.Supplier.IsAllowBorrow == 1 || Resources.GetRes().AdminModel.Mode == 2) { if (KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("ConfirmItemBalanceNotEnough"), Resources.GetRes().GetString("Supplier")), Resources.GetRes().GetString("Warn"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return(false); } } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SupplierBalanceNotEnough"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } } originalPrice = PayModel.Where(x => x.SupplierId == item.Supplier.SupplierId).Sum(x => x.OriginalPrice); // 去掉的钱不能多于该会员为这个订单总共消耗的金额 if (!Common.GetCommon().IsReturnMoney() && Mark == "-" && originalPrice + (-changePriceDouble) < 0) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SupplierBalanceNotEnough"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } } if (Mark == "-") { changePriceDouble = -changePriceDouble; } FindItemAndAddToPayModel(item, changePriceDouble); ChangePrice = "0"; this.krptChangePrice.Text = "0"; ReloadBalanceList(); Calc(); krptChangePrice.Focus(); krptChangePrice.SelectionStart = krptChangePrice.TextLength; krptChangePrice.SelectAll(); } if (null != _action) { _action(); } return(true); }