/// <summary> /// 清除引用 /// </summary> /// <param name="model"></param> public static void ClearReferences(this MemberPay model) { model.tb_admin = null; model.tb_device = null; model.tb_member = null; model.tb_balance = null; }
public CommonPayModel(MemberPay model) { this.ParentId = model.MemberId; this.BalanceId = model.BalanceId; this.MemberId = model.MemberId; this.BalancePrice = model.BalancePrice; this.OriginalPrice = model.OriginalPrice; this.Price = model.Price; this.Member = model.tb_member; this.AddTime = model.AddTime; this.Remark = model.Remark; this.Type = "MemberPay"; this.PayId = model.MemberPayId; this.ParentBalancePrice = model.ParentBalancePrice; }
public MemberPay GetMemberPay() { MemberPay model = new MemberPay(); model.MemberId = ParentId; model.BalanceId = BalanceId ?? 0; model.BalancePrice = BalancePrice; model.OriginalPrice = OriginalPrice; model.Price = Price; model.AddTime = AddTime; model.Remark = Remark; model.MemberPayId = PayId; model.ParentBalancePrice = ParentBalancePrice; return(model); }
/// <summary> /// 删除数据 /// </summary> private void Delete() { long Id = -1; try { //确认删除 var confirm = KryptonMessageBox.Show(this, Resources.GetRes().GetString("SureDelete"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirm != DialogResult.Yes) { return; } Id = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmMemberPayId"].Value.ToString()); //如果是没添加过的记录,就直接删除 if (Id == -1) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("DeleteSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); krpdgList.Rows.Remove(krpdgList.SelectedRows[0]); return; } } catch (Exception ex) { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("DeleteFailt")); return; } StartLoad(this, null); Task.Factory.StartNew(() => { MemberPay memberpay = resultList.Where(x => x.MemberPayId == Id).FirstOrDefault(); double originalBalancePrice = Member.BalancePrice; ResultModel result = new ResultModel(); try { Member.BalancePrice = Member.BalancePrice - memberpay.Price; Member newMember; result = OperatesService.GetOperates().ServiceDelMemberPay(Member, memberpay, out newMember); this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("DeleteSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); MemberPay oldModel = resultList.Where(x => x.MemberPayId == Id).FirstOrDefault(); krpdgList.Rows.Remove(krpdgList.SelectedRows[0]); resultList.Remove(oldModel); CommonPayModel oldCommonModel = this.commonPayList.Where(x => x.PayId == Id && x.Type == "MemberPay").FirstOrDefault(); commonPayList.Remove(oldCommonModel); this.ReturnValue = newMember; this.Member = newMember; } 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("DeleteFailt"), 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) { Member.BalancePrice = originalBalancePrice; } KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("DeleteFailt")); })); } StopLoad(this, null); }); }
/// <summary> /// 保存新增或改动的数据 /// </summary> private void Save() { if (null != krpdgList.SelectedRows[0]) { //如果是插入 if (krpdgList.SelectedRows[0].Cells["krpcmMemberPayId"].Value.ToString().Equals("-1")) { MemberPay memberpay = new MemberPay(); try { memberpay.MemberPayId = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmMemberPayId"].Value.ToString()); memberpay.Price = Math.Round(double.Parse(krpdgList.SelectedRows[0].Cells["krpcmPrice"].Value.ToString()), 2); memberpay.BalanceId = GetBalanceTypeId(krpdgList.SelectedRows[0].Cells["krpcmBalanceType"].Value.ToString()); memberpay.Remark = GetValueOrNull(krpdgList.SelectedRows[0].Cells["krpcmRemark"].Value.ToString()); memberpay.MemberId = this.Member.MemberId; if (this.Member.IsAllowBorrow == 0 && this.Member.BalancePrice + memberpay.Price < 0) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("MemberBalanceNotEnough"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (OnlyIncrease && memberpay.Price < 0) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("MemberBalanceNotEnough"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); return; } StartLoad(this, null); Task.Factory.StartNew(() => { ResultModel result = new ResultModel(); double originalBalancePrice = Member.BalancePrice; try { Member.BalancePrice = Member.BalancePrice + memberpay.Price; Member newMember; MemberPay newMemberPay; result = OperatesService.GetOperates().ServiceAddMemberPay(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); krpdgList.SelectedRows[0].Cells["krpcmMemberPayId"].Value = newMemberPay.MemberPayId; krpdgList.SelectedRows[0].Cells["krpcmEdit"].Value = ""; //resultList.Insert(0, model); krpdgList.SelectedRows[0].Cells["krpcmAddTime"].Value = DateTime.ParseExact(newMemberPay.AddTime.ToString(), "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd HH:mm"); this.Member = newMember; this.ReturnValue = newMember; this.resultList.Insert(0, newMemberPay); this.commonPayList.Insert(0, new CommonPayModel(newMemberPay)); krpdgList.SelectedRows[0].Cells["krpcmPrice"].ReadOnly = true; krpdgList.SelectedRows[0].Cells["krpcmBalanceType"].ReadOnly = true; krpdgList.SelectedRows[0].Cells["krpcmRemark"].ReadOnly = true; krptbEndTime.Text = DateTime.Now.AddMinutes(5).ToString("yyyyMMddHHmm"); } 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) { Member.BalancePrice = originalBalancePrice; } KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); // 防止滚动条比例没准确显示导致不显示底部的数据 this.BeginInvoke(new Action(() => { krpdgList.PerformLayout(); })); }); } //如果是编辑 else { // 没有编辑, 也不能编辑 } } }
/// <summary> /// 增加会员支付 /// </summary> private void AddMemberPay() { MemberPay memberpay = new MemberPay(); memberpay.MemberPayId = -1; memberpay.Price = Math.Round(double.Parse(NewPrice), 2); memberpay.MemberId = this.member.MemberId; _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOn)); Task.Factory.StartNew(() => { ResultModel result = new ResultModel(); double originalBalancePrice = member.BalancePrice; try { member.BalancePrice = member.BalancePrice + memberpay.Price; Member newMember; MemberPay newMemberPay; result = OperatesService.GetOperates().ServiceAddMemberPay(member, memberpay, out newMember, out newMemberPay); _element.Dispatcher.BeginInvoke(new Action(() => { if (result.Result) { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("SaveSuccess"), null, PopupType.Information)); this.member = newMember; if (null != Recalc) { Recalc(this.member); } this.Hide(); } else { if (result.IsDataHasRefrence) { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("PropertyUsed"), null, PopupType.Warn)); } else if (result.UpdateModel) { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("PropertyUsed"), null, PopupType.Warn)); } else { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("SaveFailt"), null, PopupType.Warn)); } } })); } catch (Exception ex) { _element.Dispatcher.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { if (result.Result) { member.BalancePrice = originalBalancePrice; } _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, message, null, PopupType.Error)); }), false, Resources.GetRes().GetString("SaveFailt")); })); } _element.Dispatcher.BeginInvoke(new Action(() => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOff)); })); }); }
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); }); } } }