/// <summary> /// 添加信息 /// </summary> /// <param name="git">信息</param> public void AddGitToGrid(GitInfo git) { List <GridRow> rows = m_gridGit.m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { GridRow findRow = rows[i]; if (findRow.GetCell("colP1").GetString() == git.m_ID) { findRow.GetCell("colP2").SetString(git.m_name); findRow.GetCell("colP3").SetString(git.m_url); findRow.GetCell("colP4").SetString(git.m_createDate); return; } } GridRow row = new GridRow(); m_gridGit.AddRow(row); row.AddCell("colP1", new GridStringCell(git.m_ID)); row.AddCell("colP2", new GridStringCell(git.m_name)); row.AddCell("colP3", new GridStringCell(git.m_url)); row.AddCell("colP4", new GridStringCell(git.m_createDate)); List <GridCell> cells = row.GetCells(); int cellsSize = cells.Count; for (int j = 1; j < cellsSize; j++) { cells[j].AllowEdit = true; } }
/// <summary> /// 添加 /// </summary> public void Add() { GitInfo git = new GitInfo(); git.m_ID = DataCenter.GitService.GetNewID(); DataCenter.GitService.Save(git); AddGitToGrid(git); m_gridGit.Update(); if (m_gridGit.VScrollBar != null) { m_gridGit.VScrollBar.ScrollToEnd(); } m_gridGit.Invalidate(); }
/// <summary> /// 绑定员工 /// </summary> private void BindGits() { m_gridGit.CellEditMode = GridCellEditMode.DoubleClick; List <GitInfo> gits = DataCenter.GitService.m_gits; int gitsSize = gits.Count; m_gridGit.ClearRows(); m_gridGit.BeginUpdate(); for (int i = 0; i < gitsSize; i++) { GitInfo git = gits[i]; AddGitToGrid(git); } m_gridGit.EndUpdate(); m_gridGit.Invalidate(); }
/// <summary> /// 保存信息 /// </summary> /// <param name="server">信息</param> public void Save(GitInfo git) { bool modify = false; int gitsSize = m_gits.Count; for (int i = 0; i < gitsSize; i++) { if (m_gits[i].m_ID == git.m_ID) { m_gits[i] = git; modify = true; break; } } if (!modify) { m_gits.Add(git); } Save(); }
/// <summary> /// 单元格编辑结束事件 /// </summary> /// <param name="sender">调用者</param> /// <param name="cell">单元格</param> private void GridCellEditEnd(object sender, GridCell cell) { if (cell != null) { GitInfo git = DataCenter.GitService.GerGit(cell.Row.GetCell("colP1").GetString()); String colName = cell.Column.Name; String cellValue = cell.GetString(); if (colName == "colP2") { git.m_name = cellValue; } else if (colName == "colP3") { git.m_url = cellValue; } else if (colName == "colP4") { git.m_createDate = cellValue; } DataCenter.GitService.Save(git); } }