/// <summary> /// 修改焦点对象 /// </summary> public void UpdateObject() { //获取焦点对象 BurdenLineForecast obj = FocusedObject; if (obj == null) { return; } //创建对象的一个副本 BurdenLineForecast objCopy = new BurdenLineForecast(); DataConverter.CopyTo <BurdenLineForecast>(obj, objCopy); //执行修改操作 using (FrmBurdenLineForecastDialog dlg = new FrmBurdenLineForecastDialog()) { dlg.Object = objCopy; //绑定副本 if (dlg.ShowDialog() != DialogResult.OK) { return; } } //用副本更新焦点对象 DataConverter.CopyTo <BurdenLineForecast>(objCopy, obj); //刷新表格 gridControl.RefreshDataSource(); }
/// <summary> /// 添加对象 /// </summary> public void AddObject() { //检查对象链表是否已经加载 if (ObjectList == null) { return; } //新建对象 BurdenLineForecast obj = new BurdenLineForecast(); //执行添加操作 using (FrmBurdenLineForecastDialog dlg = new FrmBurdenLineForecastDialog()) { dlg.IsCreate = true; //设置新建标志 dlg.Object = obj; if (dlg.ShowDialog() != DialogResult.OK) { return; } } //将新对象加入到链表中 ObjectList.Add(obj); //刷新表格,并将焦点行定位到新对象上。 gridControl.RefreshDataSource(); GridHelper.FocuseRow(this.bandedGridView1, obj); }
protected bool SaveRecord() { //创建/修改 对象 try { if (_obj.BurdenYear == 0) { MsgBox.Show("请添加年份!"); return(false); } if (_isCreate) { BurdenLineForecast bl = new BurdenLineForecast(); bl.BurdenYear = _obj.BurdenYear; if ((int)Services.BaseService.GetObject("SelectBurdenLineForecastByYear", bl) > 0) { MsgBox.Show("已存在相同日期,请重新选择!"); return(false); } } if (IsCreate) { Services.BaseService.Create <BurdenLineForecast>(_obj); } else { Services.BaseService.Update <BurdenLineForecast>(_obj); } } catch (Exception exc) { Debug.Fail(exc.Message); HandleException.TryCatch(exc); return(false); } //操作已成功 return(true); }
/// <summary> /// 删除焦点对象 /// </summary> public void DeleteObject() { //获取焦点对象 BurdenLineForecast obj = FocusedObject; if (obj == null) { return; } //请求确认 if (MsgBox.ShowYesNo(Strings.SubmitDelete) != DialogResult.Yes) { return; } //执行删除操作 try { Services.BaseService.Delete <BurdenLineForecast>(obj); } catch (Exception exc) { Debug.Fail(exc.Message); HandleException.TryCatch(exc); return; } this.bandedGridView1.BeginUpdate(); //记住当前焦点行索引 int iOldHandle = this.bandedGridView1.FocusedRowHandle; //从链表中删除 ObjectList.Remove(obj); //刷新表格 gridControl.RefreshDataSource(); //设置新的焦点行索引 GridHelper.FocuseRowAfterDelete(this.bandedGridView1, iOldHandle); this.bandedGridView1.EndUpdate(); }