/// <summary> /// 添加数据 /// </summary> public void AddData(List <Expression> list, String str) { m_searchTable.BeginUpdate(); GridRow row = new GridRow(); m_searchTable.AddRow(row); String strEx = ""; for (int i = 0; i < list.Count; i++) { Expression expression = list[i]; strEx += expression.getExpression(); } GridCell cell1 = new GridCellExp(str); row.AddCell("colT1", cell1); GridCell cell = new GridCellExp(strEx); row.AddCell("colT2", cell); m_searchTable.EndUpdate(); m_searchTable.Invalidate(); }
/// <summary> /// 依据ID判断更新或者插入 /// </summary> /// <param name="jira">Jira对象</param> public void AddOrUpdate(Jira jira) { //设置样式 GridCellStyle gridStyle = new GridCellStyle(); gridStyle.BackColor = COLOR.DISABLEDCONTROL; List <GridRow> rows = m_gridDgvTable.m_rows; int size = rows.Count; //没有数据 if (size <= 0) { Addrows(jira); return; } bool isAddRow = true; for (int i = 0; i < size; i++) { //GridCellStyle gridStyle = new GridCellStyle(); //gridStyle.BackColor = COLOR.DISABLEDCONTR; GridRow row = rows[i]; String id = row.GetCell("colT1").Text; GridCellStyle gridStyle1 = new GridCellStyle(); gridStyle1.BackColor = COLOR.DISABLEDCONTROL; gridStyle1.ForeColor = COLOR.ARGB(255, 97, 0); row.GetCell("colT1").Style = gridStyle1; //根据ID来决定是插入还是更新 if (id == jira.JiraID) { isAddRow = false; GridCellStyle gridStyle2 = new GridCellStyle(); gridStyle2.BackColor = COLOR.DISABLEDCONTROL; gridStyle2.ForeColor = COLOR.ARGB(0, 255, 0); row.GetCell("colT2").Style = gridStyle2; row.GetCell("colT2").Text = jira.Title; row.GetCell("colT3").Text = jira.Creater; row.GetCell("colT4").Text = jira.Developer; int count = XmlHandle.Groups.Count; for (int m = 0; m < count; m++) { if (XmlHandle.Groups[m].Id == jira.GroupID) { GridCell cell5 = new GridCellExp(XmlHandle.Groups[m].Name); row.AddCell("colT5", cell5); GridCell cell6 = new GridCellExp(XmlHandle.Groups[m].Manager); row.AddCell("colT6", cell6); List <JCategory> categories = XmlHandle.Groups[m].Categories; int cateCount = categories.Count; for (int n = 0; n < cateCount; n++) { if (categories[n].Id == jira.CategoryID) { GridCell cell7 = new GridCellExp(categories[n].Name); row.AddCell("colT7", cell7); break; } } break; } } row.GetCell("colT8").Text = jira.DeveloperReceive ? "是" : "否"; row.GetCell("colT9").Text = jira.DeveloperPass ? "是" : "否"; row.GetCell("colT10").Text = jira.TestPass ? "是" : "否"; row.GetCell("colT11").Text = jira.ProductPass ? "是" : "否"; row.GetCell("colT12").Text = jira.WaitPublish ? "是" : "否"; row.GetCell("colT13").Text = jira.Published ? "是" : "否"; row.GetCell("colT14").Text = jira.CloseTask ? "是" : "否"; row.GetCell("colT15").Text = jira.Hurry; DateTime dt = DateTime.Now; String status = jira.EndDate.ToFileTime() > dt.ToFileTime() ? "(超时)" : "(正常)"; GridCell cell16 = new GridCellExp(status + jira.StartDate.ToLongDateString().ToString()); row.GetCell("colT16").Text = cell16.Text; GridCell cell17 = new GridCellExp(status + jira.StartDate.ToLongDateString().ToString()); row.GetCell("colT17").Text = cell17.Text; m_gridDgvTable.Update(); return; } } //新增 if (isAddRow) { Addrows(jira); return; } }
/// <summary> /// 插入行数据 /// </summary> /// <param name="jira">Jira对象</param> public void Addrows(Jira jira) { m_gridDgvTable.BeginUpdate(); //设置样式 GridCellStyle gridStyle = new GridCellStyle(); gridStyle.BackColor = COLOR.DISABLEDCONTROL; GridRow row = new GridRow(); m_gridDgvTable.AddRow(row); //设置边框线的颜色 m_gridDgvTable.GridLineColor = COLOR.EMPTY; m_gridDgvTable.HeaderHeight = 35; m_gridDgvTable.BackColor = COLOR.ARGB(31, 29, 40); row.Tag = jira; //设置行高 row.Height = 35; GridCell cell1 = new GridCellExp(jira.JiraID); row.AddCell("colT1", cell1); GridCellStyle gridStyle1 = new GridCellStyle(); gridStyle1.BackColor = COLOR.DISABLEDCONTROL; gridStyle1.ForeColor = COLOR.ARGB(255, 255, 255); cell1.Style = gridStyle1; GridCell cell2 = new GridCellExp(jira.Title); row.AddCell("colT2", cell2); GridCellStyle gridStyle2 = new GridCellStyle(); gridStyle2.BackColor = COLOR.DISABLEDCONTROL; gridStyle2.ForeColor = COLOR.ARGB(45, 142, 45); cell2.Style = gridStyle2; GridCell cell3 = new GridCellExp(jira.Creater); row.AddCell("colT3", cell3); GridCell cell4 = new GridCellExp(jira.Developer); row.AddCell("colT4", cell4); GridCellStyle gridStyle3 = new GridCellStyle(); gridStyle3.BackColor = COLOR.DISABLEDCONTROL; gridStyle3.ForeColor = COLOR.ARGB(47, 145, 145); cell3.Style = gridStyle3; cell4.Style = gridStyle3; int count = XmlHandle.Groups.Count; for (int j = 0; j < count; j++) { JGroup group = XmlHandle.Groups[j]; if (group.Id == jira.GroupID) { GridCell cell5 = new GridCellExp(group.Name); row.AddCell("colT5", cell5); GridCellStyle gridStyle5 = new GridCellStyle(); gridStyle5.BackColor = COLOR.DISABLEDCONTROL; gridStyle5.ForeColor = COLOR.ARGB(47, 145, 145); cell5.Style = gridStyle5; GridCell cell6 = new GridCellExp(group.Manager); row.AddCell("colT6", cell6); GridCellStyle gridStyle6 = new GridCellStyle(); gridStyle6.BackColor = COLOR.DISABLEDCONTROL; gridStyle6.ForeColor = COLOR.ARGB(255, 153, 153); cell6.Style = gridStyle6; List <JCategory> categories = group.Categories; int categoriesCount = categories.Count; for (int n = 0; n < categoriesCount; n++) { if (categories[n].Id == jira.CategoryID) { GridCell cell7 = new GridCellExp(categories[n].Name); row.AddCell("colT7", cell7); GridCellStyle gridStyle7 = new GridCellStyle(); gridStyle7.BackColor = COLOR.DISABLEDCONTROL; gridStyle7.ForeColor = COLOR.ARGB(45, 142, 45); cell7.Style = gridStyle7; break; } } break; } } String str = jira.DeveloperReceive ? "是" : "否"; GridCell cell8 = new GridCellExp(str); GridCellStyle gridStyle8 = new GridCellStyle(); gridStyle8.ForeColor = COLOR.ARGB(255, 255, 255); if (str == "是") { gridStyle8.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle8.BackColor = COLOR.ARGB(163, 5, 50); } cell8.Style = gridStyle8; row.AddCell("colT8", cell8); String str1 = jira.DeveloperPass ? "是" : "否"; GridCell cell9 = new GridCellExp(str1); GridCellStyle gridStyle9 = new GridCellStyle(); gridStyle9.ForeColor = COLOR.ARGB(255, 255, 255); if (str1 == "是") { gridStyle9.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle9.BackColor = COLOR.ARGB(163, 5, 50); } cell9.Style = gridStyle9; row.AddCell("colT9", cell9); String str2 = jira.TestPass ? "是" : "否"; GridCell cell10 = new GridCellExp(str2); GridCellStyle gridStyle10 = new GridCellStyle(); gridStyle10.ForeColor = COLOR.ARGB(255, 255, 255); if (str2 == "是") { gridStyle10.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle10.BackColor = COLOR.ARGB(163, 5, 50); } cell10.Style = gridStyle10; row.AddCell("colT10", cell10); String str3 = jira.ProductPass ? "是" : "否"; GridCell cell11 = new GridCellExp(str3); GridCellStyle gridStyle11 = new GridCellStyle(); gridStyle11.ForeColor = COLOR.ARGB(255, 255, 255); if (str3 == "是") { gridStyle11.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle11.BackColor = COLOR.ARGB(163, 5, 50); } cell11.Style = gridStyle11; row.AddCell("colT11", cell11); String str4 = jira.WaitPublish ? "是" : "否"; GridCell cell12 = new GridCellExp(str4); GridCellStyle gridStyle12 = new GridCellStyle(); gridStyle12.ForeColor = COLOR.ARGB(255, 255, 255); if (str4 == "是") { gridStyle12.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle12.BackColor = COLOR.ARGB(163, 5, 50); } cell12.Style = gridStyle12; row.AddCell("colT12", cell12); String str5 = jira.Published ? "是" : "否"; GridCell cell13 = new GridCellExp(str5); GridCellStyle gridStyle13 = new GridCellStyle(); gridStyle13.ForeColor = COLOR.ARGB(255, 255, 255); if (str5 == "是") { gridStyle13.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle13.BackColor = COLOR.ARGB(163, 5, 50); } cell13.Style = gridStyle13; row.AddCell("colT13", cell13); String str6 = jira.CloseTask ? "是" : "否"; GridCell cell14 = new GridCellExp(str6); GridCellStyle gridStyle14 = new GridCellStyle(); gridStyle14.ForeColor = COLOR.ARGB(255, 255, 255); if (str6 == "是") { gridStyle14.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle14.BackColor = COLOR.ARGB(163, 5, 50); } cell14.Style = gridStyle14; row.AddCell("colT14", cell14); GridCell cell15 = new GridCellExp(jira.Hurry); GridCellStyle gridStyle15 = new GridCellStyle(); gridStyle15.BackColor = COLOR.ARGB(0, 0, 0); if (jira.Hurry == "紧急") { gridStyle15.ForeColor = COLOR.ARGB(255, 0, 0); } else { gridStyle15.ForeColor = COLOR.ARGB(255, 255, 0); } cell15.Style = gridStyle15; row.AddCell("colT15", cell15); GridCellStyle gridStyle16 = new GridCellStyle(); gridStyle16.BackColor = COLOR.DISABLEDCONTROL; gridStyle16.ForeColor = COLOR.ARGB(255, 255, 0); DateTime dt1 = DateTime.Now; String status = jira.EndDate.ToFileTime() > dt1.ToFileTime() ? "(超时)" : "(正常)"; GridCell cells16 = new GridCellExp(status + jira.StartDate.ToLongDateString().ToString()); row.AddCell("colT16", cells16); cells16.Tag = jira.StartDate; GridCell cells17 = new GridCellExp(status + jira.StartDate.ToLongDateString().ToString()); row.AddCell("colT17", cells17); cells16.Style = gridStyle16; cells17.Style = gridStyle16; cells17.Tag = jira.EndDate; m_gridDgvTable.EndUpdate(); }
/// <summary> /// 刷新数据 /// </summary> public void Renovate() { //从服务端拿取数据 m_jiras = XmlHandle.GetJiras(); int count = m_jiras.Count; //创建Dictionary存放ID和数据 Dictionary <String, Jira> jiraIDs = new Dictionary <String, Jira>(); //遍历服务器的数据 for (int i = 0; i < count; i++) { Jira jira = m_jiras[i]; jiraIDs.Add(jira.JiraID, jira); } //获取表格所有行 List <GridRow> rows = m_gridDgvTable.GetRows(); int rowsCount = rows.Count; Dictionary <String, GridRow> gridRows = new Dictionary <String, GridRow>(); //遍历表格的数据 for (int i = 0; i < rowsCount; i++) { GridRow row = rows[i]; //取ID String id = row.GetCell("colT1").Text; //依据ID判断 if (!jiraIDs.ContainsKey(id)) { //ID不匹配删除行 m_gridDgvTable.RemoveRow(row); rowsCount--; i--; } else { //匹配则加到Dictionary gridRows.Add(id, row); } } m_gridDgvTable.Update(); m_gridDgvTable.BeginUpdate(); for (int i = 0; i < count; i++) { //遍历服务器数据 Jira jira = m_jiras[i]; bool newData = false; String key = jira.JiraID; GridRow row; if (gridRows.ContainsKey(key)) { row = gridRows[key]; } else { newData = true; row = new GridRow(); //row.Grid = m_gridDgvTable; //m_gridDgvTable.m_rows.Add(row); //row.OnAdd(); m_gridDgvTable.AddRow(row); } //遍历columns List <GridColumn> columns = m_gridDgvTable.GetColumns(); int countColumn = columns.Count; for (int j = 0; j < countColumn; j++) { GridColumn column = columns[j]; GridCell cell; if (newData) { cell = new GridCellExp(); row.AddCell(column.Index, cell); cell.Column = column; } else { cell = row.GetCell(column.Index); } DateTime dt = DateTime.Now; String status = jira.EndDate.ToFileTime() > dt.ToFileTime() ? "(超时)" : "(正常)"; int countGroup = XmlHandle.Groups.Count; switch (j) { case 0: GridCellStyle gridStyle1 = new GridCellStyle(); gridStyle1.BackColor = COLOR.DISABLEDCONTROL; gridStyle1.ForeColor = COLOR.ARGB(255, 255, 255); cell.Text = jira.JiraID; cell.Style = gridStyle1; //colT1 break; case 1: GridCellStyle gridStyle2 = new GridCellStyle(); gridStyle2.BackColor = COLOR.DISABLEDCONTROL; gridStyle2.ForeColor = COLOR.ARGB(45, 142, 45); cell.Text = jira.Title; cell.Style = gridStyle2; break; case 2: GridCellStyle gridStyle3 = new GridCellStyle(); gridStyle3.BackColor = COLOR.DISABLEDCONTROL; gridStyle3.ForeColor = COLOR.ARGB(47, 145, 145); cell.Text = jira.Creater; cell.Style = gridStyle3; break; case 3: GridCellStyle gridStyle4 = new GridCellStyle(); gridStyle4.BackColor = COLOR.DISABLEDCONTROL; gridStyle4.ForeColor = COLOR.ARGB(47, 145, 145);; cell.Style = gridStyle4; cell.Text = jira.Developer; break; case 4: { for (int m = 0; m < countGroup; m++) { if (XmlHandle.Groups[m].Id == jira.GroupID) { GridCellStyle gridStyle5 = new GridCellStyle(); gridStyle5.BackColor = COLOR.DISABLEDCONTROL; gridStyle5.ForeColor = COLOR.ARGB(47, 145, 145); cell.Style = gridStyle5; cell.Text = XmlHandle.Groups[m].Name; break; } } break; } case 5: { for (int m = 0; m < countGroup; m++) { if (XmlHandle.Groups[m].Id == jira.GroupID) { GridCellStyle gridStyle6 = new GridCellStyle(); gridStyle6.BackColor = COLOR.DISABLEDCONTROL; gridStyle6.ForeColor = COLOR.ARGB(255, 153, 153); cell.Style = gridStyle6; cell.Text = XmlHandle.Groups[m].Manager; break; } } break; } case 6: { for (int m = 0; m < countGroup; m++) { if (XmlHandle.Groups[m].Id == jira.GroupID) { List <JCategory> categories = XmlHandle.Groups[m].Categories; int cateCount = categories.Count; for (int n = 0; n < cateCount; n++) { if (categories[n].Id == jira.CategoryID) { GridCellStyle gridStyle7 = new GridCellStyle(); gridStyle7.BackColor = COLOR.DISABLEDCONTROL; gridStyle7.ForeColor = COLOR.ARGB(45, 142, 45); cell.Style = gridStyle7; cell.Text = categories[n].Name; break; } } break; } } break; } case 7: cell.Text = jira.DeveloperReceive ? "是" : "否"; GridCellStyle gridStyle8 = new GridCellStyle(); gridStyle8.ForeColor = COLOR.ARGB(255, 255, 255); if (cell.Text == "是") { gridStyle8.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle8.BackColor = COLOR.ARGB(163, 5, 50); } cell.Style = gridStyle8; break; case 8: cell.Text = jira.DeveloperPass ? "是" : "否"; GridCellStyle gridStyle9 = new GridCellStyle(); gridStyle9.ForeColor = COLOR.ARGB(255, 255, 255); if (cell.Text == "是") { gridStyle9.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle9.BackColor = COLOR.ARGB(163, 5, 50); } cell.Style = gridStyle9; break; case 9: cell.Text = jira.TestPass ? "是" : "否"; GridCellStyle gridStyle10 = new GridCellStyle(); gridStyle10.ForeColor = COLOR.ARGB(255, 255, 255); if (cell.Text == "是") { gridStyle10.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle10.BackColor = COLOR.ARGB(163, 5, 50); } cell.Style = gridStyle10; break; case 10: cell.Text = jira.ProductPass ? "是" : "否"; GridCellStyle gridStyle11 = new GridCellStyle(); gridStyle11.ForeColor = COLOR.ARGB(255, 255, 255); if (cell.Text == "是") { gridStyle11.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle11.BackColor = COLOR.ARGB(163, 5, 50); } cell.Style = gridStyle11; break; case 11: cell.Text = jira.WaitPublish ? "是" : "否"; GridCellStyle gridStyle12 = new GridCellStyle(); gridStyle12.ForeColor = COLOR.ARGB(255, 255, 255); if (cell.Text == "是") { gridStyle12.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle12.BackColor = COLOR.ARGB(163, 5, 50); } cell.Style = gridStyle12; break; case 12: cell.Text = jira.Published ? "是" : "否"; GridCellStyle gridStyle13 = new GridCellStyle(); gridStyle13.ForeColor = COLOR.ARGB(255, 255, 255); if (cell.Text == "是") { gridStyle13.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle13.BackColor = COLOR.ARGB(163, 5, 50); } cell.Style = gridStyle13; break; case 13: cell.Text = jira.CloseTask ? "是" : "否"; GridCellStyle gridStyle14 = new GridCellStyle(); gridStyle14.ForeColor = COLOR.ARGB(255, 255, 255); if (cell.Text == "是") { gridStyle14.BackColor = COLOR.ARGB(93, 146, 202); } else { gridStyle14.BackColor = COLOR.ARGB(163, 5, 50); } cell.Style = gridStyle14; break; case 14: cell.Text = jira.Hurry; GridCellStyle gridStyle15 = new GridCellStyle(); gridStyle15.BackColor = COLOR.ARGB(0, 0, 0); if (cell.Text == "紧急") { gridStyle15.ForeColor = COLOR.ARGB(163, 5, 50); } else { gridStyle15.ForeColor = COLOR.ARGB(227, 171, 26); } cell.Style = gridStyle15; break; case 15: GridCellStyle gridStyle16 = new GridCellStyle(); GridCell cell16 = new GridCellExp(status + jira.StartDate.ToLongDateString().ToString()); cell.Text = cell16.Text; gridStyle16.ForeColor = COLOR.ARGB(255, 255, 0); cell.Style = gridStyle16; break; case 16: GridCellStyle gridStyle17 = new GridCellStyle(); GridCell cell17 = new GridCellExp(status + jira.StartDate.ToLongDateString().ToString()); cell.Text = cell17.Text; gridStyle17.ForeColor = COLOR.ARGB(255, 255, 0); cell.Style = gridStyle17; break; } } } m_gridDgvTable.EndUpdate(); m_gridDgvTable.Invalidate(); }