private void BtnDel_Click(object sender, EventArgs e) { var current = 源房缴费明细BindingSource.Current; if (current != null) { //因为绑定数据源和context 之间没有消息订阅,所以必须手动删除对应项。 源房缴费明细 delItem = (current as ObjectView <源房缴费明细>).Object; //! 注意,这里获取方式有点特别。http://blw.sourceforge.net/ context.源房缴费明细.DeleteObject(delItem); 源房缴费明细BindingSource.RemoveCurrent(); } CaculateSumMoney(); }
private void kryptonDataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { //双击,编辑 if (e.Button == System.Windows.Forms.MouseButtons.Left) { 源房缴费明细 cur = 源房缴费明细BindingSource.Current as 源房缴费明细; if (cur != null) { using (源房缴费Form jf = new 源房缴费Form(cur)) { jf.ShowDialog(this); } } } }
private void btnOK_Click(object sender, EventArgs e) { 源房缴费明细BindingSource.EndEdit(); var changes = Main.context.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted | EntityState.Modified); if (changes.Count() > 0) { //校验 StringBuilder sb = new StringBuilder(); Dictionary <Guid, string> errors = new Dictionary <Guid, string>();//记录错误的ID号,和对应错误信息。 foreach (ObjectStateEntry change in changes) { //校验每一条更改的实体,最后联合显示错误信息。 源房缴费明细 entity = change.Entity as 源房缴费明细; string result = entity.CheckRules(); if (!string.IsNullOrEmpty(result))//证明有错误 { string err = string.Format("-----[{0}][{1}][{2}]:该记录有误-----\r\n{3}", entity.源房.房名, entity.缴费时间.ToShortDateString(), entity.缴费项, result); sb.Append(err); errors.Add(entity.ID, err); } } if (!string.IsNullOrEmpty(sb.ToString())) { highLightRow(errors);//高亮错误行 KryptonMessageBox.Show(sb.ToString(), "数据校验失败"); return; } string msg; if (Helper.saveData(Main.context.源房缴费明细, out msg)) { KryptonMessageBox.Show(msg, "成功保存"); Close(); } else { KryptonMessageBox.Show(msg, "失败"); } } else//未做更改 { Close(); } }
private void 缴费Form_Load(object sender, EventArgs e) { Text = string.Format("源房缴费[{0}]", isNew? "新增":"编辑"); 源房BindingSource.DataSource = 源房.GetYF(context).Execute(MergeOption.NoTracking); if (isNew) //新增 { BtnOkAndContinue.Visible = true; //保存并继续按钮可见 payDetail = new 源房缴费明细(); payDetail.源房ID = this.yfID; context.源房缴费明细.AddObject(payDetail);//此操作后可实现外键同步 } else//编辑 { //cmbYF.SelectedValue = payDetail.源房ID;//已经直接绑定了 } 源房缴费明细BindingSource.DataSource = payDetail; }
private void BtnOkAndContinue_Click(object sender, EventArgs e) { 源房缴费明细BindingSource.EndEdit(); string check = payDetail.CheckRules(); if (!string.IsNullOrEmpty(check)) { KryptonMessageBox.Show(check, "数据校验失败"); return; } #if DEBUG System.Diagnostics.Debug.Assert(isNew);//只有新增状态才有此按钮 #endif string msg; if (Helper.saveData(context, payDetail, out msg)) { KryptonMessageBox.Show(string.Format("成功新增缴费信息。您可以继续添加!"), "成功新增缴费信息"); if (this.Owner is Main) { (this.Owner as Main).RefreshAndLocateTree(payDetail.源房);//刷新TreeView,并定位到kf节点。 } 源房缴费明细 old = payDetail; payDetail = new 源房缴费明细(); payDetail.源房ID = old.源房ID; context.源房缴费明细.AddObject(payDetail);//此操作后可实现外键同步 源房缴费明细BindingSource.DataSource = payDetail; } else { KryptonMessageBox.Show(msg, "失败"); } }
public 源房缴费Form(源房缴费明细 payDetail) { InitializeComponent(); isNew = false; this.payDetail = context.源房缴费明细.FirstOrDefault(m => m.ID == payDetail.ID); }
public 源房缴费Form(源房缴费明细 payDetail) { InitializeComponent(); isNew = false; this.payDetail = payDetail; }