/// <summary> /// 添加信息 /// </summary> /// <param name="report">信息</param> public void AddExamToGrid(ExamInfo report) { List <GridRow> rows = m_gridExams.m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { GridRow findRow = rows[i]; if (findRow.GetCell("colP1").GetString() == report.m_ID) { findRow.GetCell("colP2").SetString(report.m_title); findRow.GetCell("colP3").SetString(report.m_type); findRow.GetCell("colP4").SetString(report.m_interval); findRow.GetCell("colP5").SetString(report.m_answer); findRow.GetCell("colP6").SetString(report.m_createDate); return; } } GridRow row = new GridRow(); m_gridExams.AddRow(row); row.AddCell("colP1", new GridStringCell(report.m_ID)); row.AddCell("colP2", new GridStringCell(report.m_title)); row.AddCell("colP3", new GridStringCell(report.m_type)); row.AddCell("colP4", new GridStringCell(report.m_interval)); row.AddCell("colP5", new GridStringCell(report.m_answer)); row.AddCell("colP6", new GridStringCell(report.m_createDate)); List <GridCell> cells = row.GetCells(); int cellsSize = cells.Count; for (int j = 1; j < cellsSize; j++) { cells[j].AllowEdit = true; } }
/// <summary> /// 单元格编辑结束事件 /// </summary> /// <param name="sender">调用者</param> /// <param name="cell">单元格</param> private void GridCellEditEnd(object sender, GridCell cell) { if (cell != null) { ExamInfo report = DataCenter.ExamService.GetExam(cell.Row.GetCell("colP1").GetString()); String colName = cell.Column.Name; String cellValue = cell.GetString(); if (colName == "colP2") { report.m_title = cellValue; } else if (colName == "colP3") { report.m_type = cellValue; } else if (colName == "colP4") { report.m_interval = cellValue; } else if (colName == "colP5") { report.m_answer = cellValue; } else if (colName == "colP6") { report.m_createDate = cellValue; } DataCenter.ExamService.Save(report); } }
/// <summary> /// 添加 /// </summary> public void Add() { ExamInfo exam = new ExamInfo(); exam.m_ID = DataCenter.ExamService.GetNewID(); DataCenter.ExamService.Save(exam); AddExamToGrid(exam); m_gridExams.Update(); if (m_gridExams.VScrollBar != null) { m_gridExams.VScrollBar.ScrollToEnd(); } m_gridExams.Invalidate(); }
/// <summary> /// 绑定指示 /// </summary> private void BindMasters() { m_gridExams.CellEditMode = GridCellEditMode.DoubleClick; List <ExamInfo> masters = DataCenter.ExamService.m_exams; int mastersSize = masters.Count; m_gridExams.ClearRows(); m_gridExams.BeginUpdate(); for (int i = 0; i < mastersSize; i++) { ExamInfo report = masters[i]; AddExamToGrid(report); } m_gridExams.EndUpdate(); m_gridExams.Invalidate(); }
/// <summary> /// 保存信息 /// </summary> /// <param name="master">信息</param> public void Save(ExamInfo exam) { bool modify = false; int examsSize = m_exams.Count; for (int i = 0; i < examsSize; i++) { if (m_exams[i].m_ID == exam.m_ID) { m_exams[i] = exam; modify = true; break; } } if (!modify) { m_exams.Add(exam); } Save(); }