/// <summary> /// 清除引用 /// </summary> /// <param name="model"></param> public static void ClearReferences(this AdminPay model) { model.tb_admin = null; model.tb_admin1 = null; model.tb_device = null; model.tb_balance = null; }
public CommonPayModel(AdminPay model) { this.ParentId = model.AdminId; this.BalanceId = model.BalanceId; this.BalancePrice = model.BalancePrice; this.OriginalPrice = model.OriginalPrice; this.Price = model.Price; this.AddTime = model.AddTime; this.Remark = model.Remark; this.Type = "AdminPay"; this.PayId = model.AdminPayId; this.ParentBalancePrice = model.ParentBalancePrice; }
/// <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["krpcmAdminPayId"].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(() => { AdminPay adminPay = resultList.Where(x => x.AdminPayId == Id).FirstOrDefault(); ResultModel result = new ResultModel(); try { Admin newAdmin; result = OperatesService.GetOperates().ServiceDelAdminPay(Admin, adminPay, out newAdmin); this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("DeleteSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); AdminPay oldModel = resultList.Where(x => x.AdminPayId == Id).FirstOrDefault(); krpdgList.Rows.Remove(krpdgList.SelectedRows[0]); resultList.Remove(oldModel); } 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) => { 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["krpcmAdminPayId"].Value.ToString().Equals("-1")) { AdminPay adminpay = new AdminPay(); try { adminpay.AdminPayId = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmAdminPayId"].Value.ToString()); adminpay.Price = Math.Round(double.Parse(krpdgList.SelectedRows[0].Cells["krpcmPrice"].Value.ToString()), 2); adminpay.BalanceId = GetBalanceTypeId(krpdgList.SelectedRows[0].Cells["krpcmBalanceType"].Value.ToString()); adminpay.Remark = GetValueOrNull(krpdgList.SelectedRows[0].Cells["krpcmRemark"].Value.ToString()); adminpay.AdminId = this.Admin.AdminId; } 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(); try { Admin newAdmin; AdminPay newAdminPay; result = OperatesService.GetOperates().ServiceAddAdminPay(Admin, adminpay, out newAdmin, out newAdminPay); 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["krpcmAdminPayId"].Value = newAdminPay.AdminPayId; krpdgList.SelectedRows[0].Cells["krpcmEdit"].Value = ""; krpdgList.SelectedRows[0].Cells["krpcmAddTime"].Value = DateTime.ParseExact(newAdminPay.AddTime.ToString(), "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd HH:mm"); this.resultList.Insert(0, newAdminPay); 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) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); }); } //如果是编辑 else { // 没有编辑, 也不能编辑 } } }