/// <summary> /// 添加信息 /// </summary> /// <param name="level">信息</param> public void AddDialogToGrid(DialogInfo level) { List <GridRow> rows = m_gridDialogs.m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { GridRow findRow = rows[i]; if (findRow.GetCell("colP1").GetString() == level.m_ID) { findRow.GetCell("colP2").SetString(level.m_name); findRow.GetCell("colP3").SetString(level.m_date); return; } } GridRow row = new GridRow(); m_gridDialogs.AddRow(row); row.AddCell("colP1", new GridStringCell(level.m_ID)); row.AddCell("colP2", new GridStringCell(level.m_name)); row.AddCell("colP3", new GridStringCell(level.m_date)); 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="paint">绘图</param> /// <param name="clipRect">裁剪区域</param> private void PaintDiv(object sender, CPaint paint, RECT clipRect) { List <DialogInfo> dialogs = DataCenter.DialogService.m_dialogs; int dialogsSize = dialogs.Count; Dictionary <String, int> names = new Dictionary <String, int>(); for (int i = 0; i < dialogsSize; i++) { DialogInfo dialog = dialogs[i]; if (names.ContainsKey(dialog.m_name)) { names[dialog.m_name] = names[dialog.m_name] + 1; } else { names[dialog.m_name] = 1; } } List <DialogData> datas = new List <DialogData>(); foreach (String key in names.Keys) { DialogData data = new DialogData(); data.m_name = key; data.m_times = names[key]; datas.Add(data); } datas.Sort(new DialogDataCompare()); int width = m_divDialogs.Width, height = m_divDialogs.Height; int datasSize = datas.Count; if (datasSize > 0) { int paddingLeft = 50, paddingRight = 50, paddingTop = 20, paddingBottom = 20; int top = paddingTop; int pSize = (height - paddingTop - paddingBottom) / datasSize; double max = 0; for (int i = 0; i < datasSize; i++) { DialogData data = datas[i]; if (i == 0) { max = data.m_times; } int wSize = (int)((width - paddingLeft - paddingRight) * data.m_times / max); CDraw.DrawText(paint, data.m_name, COLOR.ARGB(0, 0, 0), m_divDialogs.Font, 5, top); paint.FillGradientRect(m_sysColors[i % m_sysColors.Length], m_sysColors[(i + 1) % m_sysColors.Length], new RECT(paddingLeft, top + 2, paddingLeft + wSize, top + 12), 2, 0); FONT font = new FONT("微软雅黑", 14, false, false, false); CDraw.DrawText(paint, data.m_times.ToString(), COLOR.ARGB(0, 0, 0), font, paddingLeft + wSize, top); top += pSize; } } }
/// <summary> /// 添加 /// </summary> public void Add() { DialogInfo dialog = new DialogInfo(); dialog.m_ID = DataCenter.DialogService.GetNewID(); dialog.m_date = DateTime.Now.ToString("yyyyMMdd"); DataCenter.DialogService.Save(dialog); AddDialogToGrid(dialog); m_gridDialogs.Update(); if (m_gridDialogs.VScrollBar != null) { m_gridDialogs.VScrollBar.ScrollToEnd(); } m_gridDialogs.Invalidate(); }
/// <summary> /// 单元格编辑结束事件 /// </summary> /// <param name="sender">调用者</param> /// <param name="cell">单元格</param> private void GridCellEditEnd(object sender, GridCell cell) { if (cell != null) { DialogInfo dialog = DataCenter.DialogService.GetDialog(cell.Row.GetCell("colP1").GetString()); String colName = cell.Column.Name; String cellValue = cell.GetString(); if (colName == "colP2") { dialog.m_name = cellValue; } else if (colName == "colP3") { dialog.m_date = cellValue; } DataCenter.DialogService.Save(dialog); BindChart(); m_divDialogs.Invalidate(); } }
/// <summary> /// 保存信息 /// </summary> /// <param name="award">信息</param> public void Save(DialogInfo level) { bool modify = false; int dialogsSize = m_dialogs.Count; for (int i = 0; i < dialogsSize; i++) { if (m_dialogs[i].m_ID == level.m_ID) { m_dialogs[i] = level; modify = true; break; } } if (!modify) { m_dialogs.Add(level); } Save(); }
/// <summary> /// 绑定指示 /// </summary> private void BindDialogs() { m_gridDialogs.CellEditMode = GridCellEditMode.DoubleClick; List <DialogInfo> dialogs = DataCenter.DialogService.m_dialogs; int dialogsSize = dialogs.Count; m_gridDialogs.ClearRows(); m_gridDialogs.BeginUpdate(); for (int i = 0; i < dialogsSize; i++) { DialogInfo dialog = dialogs[i]; dialog.m_date = dialog.m_date.Replace("-", ""); AddDialogToGrid(dialog); } m_gridDialogs.EndUpdate(); if (m_gridDialogs.VScrollBar != null && m_gridDialogs.VScrollBar.Visible) { m_gridDialogs.VScrollBar.ScrollToEnd(); } m_gridDialogs.Invalidate(); }