protected override void Dispose(bool disposing) { if (disposing) { if (m_archiveGridHelper != null) { m_archiveGridHelper.RowSaving -= new System.ComponentModel.CancelEventHandler(row_Saving); m_archiveGridHelper.Dispose(); m_archiveGridHelper = null; } if (this.ControlManager != null) { this.ControlManager.ListChanged -= new ListChangedEventHandler(m_cm_ListChanged); this.ControlManager.Dispose(); this.ControlManager = null; } } base.Dispose(disposing); }
private static void OnBatchSetCellValueCommand(object sender, ExecutedEventArgs e) { Xceed.Grid.Cell contextMenuCell = sender as Xceed.Grid.DataCell; ArchiveGridHelper gridHelper = e.Parameter as ArchiveGridHelper; string fieldName = contextMenuCell.ParentColumn.FieldName; // 开始操作 gridHelper.m_grid.DisplayManager.BeginBatchOperation(); List <Xceed.Grid.DataRow> modifiedRows = new List <Xceed.Grid.DataRow>(); gridHelper.m_grid.GridControl.SuspendLayout(); //bool userBreak = false; foreach (Xceed.Grid.DataRow row in gridHelper.m_grid.GridControl.SelectedRows) { if (!row.Visible) { continue; } if (row == contextMenuCell.ParentRow) { continue; } if (row.Cells[fieldName].ReadOnly) { continue; } if (row.Cells[fieldName].Value == null && contextMenuCell.Value == null) { continue; } if (row.Cells[fieldName].Value != null && contextMenuCell.Value != null && row.Cells[fieldName].Value.ToString() == contextMenuCell.Value.ToString()) { continue; } bool doit = true; if (row.Cells[fieldName].Value != null) { if (gridHelper.m_allowSetListWarning) { DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("已有值 \"" + row.Cells[fieldName].GetDisplayText() + "\",是否改变?", "确认", System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Information); if (dialogResult == DialogResult.Cancel) { //userBreak = true; break; } else { doit = (dialogResult == DialogResult.Yes); } } } if (doit) { try { row.BeginEdit(); object oldValue = row.Cells[fieldName].Value; // 设置目标列值 row.Cells[fieldName].Value = contextMenuCell.Value; if (row.Cells[fieldName].Value == oldValue) { continue; } // 有些因为Combo的原因,设置值有限制 row.Cells[fieldName].EnterEdit(); row.Cells[fieldName].LeaveEdit(true); if (row.Cells[fieldName].Value == null && contextMenuCell.Value != null) { row.Cells[fieldName].Value = oldValue; row.CancelEdit(); continue; } try { row.EndEdit(); } catch (Exception) { // 当保存不进去的时候,cancel row.CancelEdit(); } modifiedRows.Add(row); gridHelper.m_grid.ControlManager.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, row.Index)); //CancelEventArgs ee = new CancelEventArgs(); //row_EndingEdit(row, ee); } // 不知道 //// when in 批量费用登记(有分组的界面) //catch (Xceed.Grid.GridValidationException) //{ //} catch (Exception ex) { row.CancelEdit(); ExceptionProcess.ProcessWithNotify(ex); if (!MessageForm.ShowYesNo("出现错误,是否继续?")) { break; } } } } // 即使用户取消,也要保存先前的内容 //if (userBreak) //{ //} //else //{ IBatchDao batchDao = gridHelper.m_grid.ControlManager.Dao as IBatchDao; if (batchDao == null) { ServiceProvider.GetService <IMessageBox>().ShowWarning("不支持批量保存,将逐条保存!"); } try { if (batchDao != null) { batchDao.SuspendOperation(); } foreach (Xceed.Grid.DataRow row in modifiedRows) { object entity = row.Tag; foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(gridHelper.m_grid.GridName)) { if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName)) { if (row.Cells[info.GridColumnName].ReadOnly) { continue; } if (info.GridColumnType == GridColumnType.Normal) { EntityScript.SetPropertyValue(entity, info.Navigator, info.PropertyName, row.Cells[info.GridColumnName].Value); } } } gridHelper.m_grid.ControlManager.Dao.Update(entity); } if (batchDao != null) { batchDao.ResumeOperation(); } } catch (Exception ex) { if (batchDao != null) { batchDao.CancelSuspendOperation(); } ExceptionProcess.ProcessWithNotify(ex); gridHelper.m_grid.ReloadData(); } finally { } gridHelper.m_grid.GridControl.ResumeLayout(); gridHelper.m_grid.DisplayManager.EndBatchOperation(); MyGrid.SetCurrentRow(gridHelper.m_grid.GridControl, gridHelper.m_grid.DataRows[gridHelper.m_grid.DisplayManager.Position]); MyGrid.SyncSelectedRowToCurrentRow(gridHelper.m_grid.GridControl); }