private void tsbSave_Click(object sender, EventArgs e) { if (m_haveSaved) { if (!ServiceProvider.GetService <IMessageBox>().ShowYesNoDefaultNo("已保存过一次,是否再次保存(会导致2份记录)?", "确认")) { return; } } int cnt = 0; IBatchDao batchDao = m_cm.Dao as IBatchDao; if (batchDao == null) { ServiceProvider.GetService <IMessageBox>().ShowWarning("不支持批量保存,将逐条保存!"); } try { m_cm.CancelEdit(); MyGrid.CancelEditCurrentDataRow(m_excelGrid); if (batchDao != null) { batchDao.SuspendOperation(); } foreach (Xceed.Grid.DataRow row in m_excelGrid.DataRows) { bool hasValue = false; foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(m_excelGrid.GridName)) { if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName)) { if (row.Cells[info.GridColumnName].ReadOnly) { continue; } if (row.Cells[info.GridColumnName].Value != null) { hasValue = true; } } } if (!hasValue) { continue; } object entity = m_cm.AddNew(); if (entity == null) { continue; } foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(m_excelGrid.GridName)) { if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName)) { if (row.Cells[info.GridColumnName].ReadOnly) { continue; } EntityScript.SetPropertyValue(entity, info.Navigator, info.PropertyName, row.Cells[info.GridColumnName].Value); } } m_cm.EndEdit(false); m_cm.Dao.Save(entity); cnt++; } if (batchDao != null) { batchDao.ResumeOperation(); } m_haveSaved = true; MessageForm.ShowInfo(string.Format("已保存{0}条记录!", cnt)); } catch (Exception ex) { if (batchDao != null) { batchDao.CancelSuspendOperation(); } ExceptionProcess.ProcessWithNotify(ex); } }
/// <summary> /// btnCancel_Click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void btnCancel_Click(System.Object sender, System.EventArgs e) { m_cm.CancelEdit(); }