/// <summary> /// 修改焦点对象 /// </summary> public void UpdateObject() { //获取焦点对象 PowerProjectList obj = FocusedObject; if (obj == null) { return; } //创建对象的一个副本 PowerProjectList objCopy = new PowerProjectList(); DataConverter.CopyTo <PowerProjectList>(obj, objCopy); //执行修改操作 using (FrmPowerProjectListDialog dlg = new FrmPowerProjectListDialog()) { dlg.Object = objCopy; //绑定副本 if (dlg.ShowDialog() != DialogResult.OK) { return; } } //用副本更新焦点对象 DataConverter.CopyTo <PowerProjectList>(objCopy, obj); //刷新表格 gridControl.RefreshDataSource(); }
/// <summary> /// 添加对象 /// </summary> public void AddObject() { //检查对象链表是否已经加载 if (ObjectList == null) { return; } //新建对象 PowerProjectList obj = new PowerProjectList(); //执行添加操作 using (FrmPowerProjectListDialog dlg = new FrmPowerProjectListDialog()) { dlg.IsCreate = true; //设置新建标志 dlg.Object = obj; if (dlg.ShowDialog() != DialogResult.OK) { return; } } //将新对象加入到链表中 ObjectList.Add(obj); //刷新表格,并将焦点行定位到新对象上。 gridControl.RefreshDataSource(); GridHelper.FocuseRow(this.gridView, obj); }
/// <summary> /// 删除焦点对象 /// </summary> public void DeleteObject() { //获取焦点对象 PowerProjectList obj = FocusedObject; if (obj == null) { return; } PowerProject pp = new PowerProject(); pp.PowerLineUID = obj.UID; IList <PowerProject> li = Services.BaseService.GetList <PowerProject>("SelectPowerProjectList", pp); if (li.Count > 0) { MsgBox.Show("该分类下面有输变电项目表记录,无法删除"); return; } //请求确认 if (MsgBox.ShowYesNo(Strings.SubmitDelete) != DialogResult.Yes) { return; } //执行删除操作 try { Services.BaseService.Delete <PowerProjectList>(obj); } catch (Exception exc) { Debug.Fail(exc.Message); HandleException.TryCatch(exc); return; } this.gridView.BeginUpdate(); //记住当前焦点行索引 int iOldHandle = this.gridView.FocusedRowHandle; //从链表中删除 ObjectList.Remove(obj); //刷新表格 gridControl.RefreshDataSource(); //设置新的焦点行索引 GridHelper.FocuseRowAfterDelete(this.gridView, iOldHandle); this.gridView.EndUpdate(); }