コード例 #1
0
        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadedData(DataRow[] rows)
        {
            ObservableCollection <DataColumn_1> data = new ObservableCollection <DataColumn_1>();

            foreach (DataRow dr in rows)
            {
                //第一列
                var column1 = dr["项目"].ToString();
                var row1    = data.SingleOrDefault(r => r.ColumnContent_1 == column1);
                if (row1 == null)
                {
                    row1 = new DataColumn_1();
                    row1.ColumnContent_1 = column1;
                    data.Add(row1);
                }

                //第二列
                var column2 = dr["项目"].ToString();
                var row2    = row1.Rows.SingleOrDefault(r => r.ColumnContent_2 == column2);
                if (row2 == null)
                {
                    row2 = new DataColumn_2_5();
                    row2.ColumnContent_2 = column2;
                    row1.Rows.Add(row2);
                }

                //第三列
                var column3 = dr["项目"].ToString();
                var row3    = row2.Rows.SingleOrDefault(r => r.ColumnContent_3 == column3);
                if (row3 == null)
                {
                    row3 = new DataColumn_3();
                    row3.ColumnContent_3 = column3;
                    row2.Rows.Add(row3);
                }

                //第四列
                var dd   = dr["地点"].ToString();
                var xmzj = dr["项目总监"].ToString();
                var khjl = dr["客户经理"].ToString();
                var djlx = dr["工单类型"].ToString();
                var zczj = dr["支撑总监"].ToString();
                var fazj = dr["方案专家"].ToString();
                var cjr  = dr["承接人"].ToString();

                var gdlx = dr["工单类型"].ToString();
                var sx   = dr["事项"].ToString();
                var gdzt = dr["工单状态"].ToString();
                var t1   = dr["开始时间"].ToString();
                var t2   = dr["结束时间"].ToString();
                var at   = dr["实际工时"].ToString();
                var pt   = dr["工时"].ToString();
                if (pt == "0.00")
                {
                    pt = "1";
                }

                var startTime = DateTime.Parse(t1);
                var endTime   = DateTime.Parse(t2);
                //var row4 = row3.FindCanAddCell(startTime.Day, endTime.Day);
                var row4 = row3.FindCanAddCell(startTime, endTime);

                if (row4 != null)
                {
                    //row4.Cells[startTime.Day - 1].LeftThickness = base.PageControl.Gantt.Controller.CellLineWidth;
                    //row4.Cells[endTime.Day - 1].RightThickness = base.PageControl.Gantt.Controller.CellLineWidth;
                    ////公司(蓝色)、外勤(橙色)、出差(红色)、终止(灰色)、完成(绿色)
                    //var color = gdlx == "产出" ? "#1E90FF" : gdlx == "外勤" ? "#FFA500" : gdlx == "出差" ? "#FF4500" : gdlx == "终止" ? "#D3D3D3" : gdlx == "完成" ? "#92D050" : "#FFFFFF";

                    //for (int i = startTime.Day - 1; i < endTime.Day; i++)
                    //{
                    //    row4.Cells[i].Color = color;
                    //    row4.Cells[i].ActualTime = double.Parse(at) / 480;
                    //    row4.Cells[i].PrjCount = 1;
                    //    if ((endTime - startTime).TotalDays == 0)
                    //    {
                    //        row4.Cells[i].PlanTime = double.Parse(pt);
                    //    }
                    //    else
                    //    {
                    //        row4.Cells[i].PlanTime = double.Parse(pt) / (endTime - startTime).TotalDays;
                    //    }
                    //    row4.Cells[i].TipContent = $"{cjr}\t{sx}";
                    //    row4.Cells[i].ShowContent = row4.Cells[i].PrjCount + "/" + String.Format("{0:F}", row4.Cells[i].PlanTime / row4.Cells[i].PrjCount) + "/" + String.Format("{0:F}", row4.Cells[i].ActualTime / row4.Cells[i].PrjCount);
                    //}

                    row4.Cells[(startTime - GanttViewModel.StartDay).Days].LeftThickness = base.PageControl.Gantt.Controller.CellLineWidth;
                    row4.Cells[(endTime - GanttViewModel.StartDay).Days].RightThickness  = base.PageControl.Gantt.Controller.CellLineWidth;
                    //公司(蓝色)、外勤(橙色)、出差(红色)、终止(灰色)、完成(绿色)
                    var color = gdlx == "产出" ? "#1E90FF" : gdlx == "外勤" ? "#FFA500" : gdlx == "出差" ? "#FF4500" : gdlx == "终止" ? "#D3D3D3" : gdlx == "完成" ? "#92D050" : "#FFFFFF";

                    for (int i = (startTime - GanttViewModel.StartDay).Days; i < (endTime - GanttViewModel.StartDay).Days + 1; i++)
                    {
                        row4.Cells[i].Color      = color;
                        row4.Cells[i].ActualTime = double.Parse(at) / 480;
                        row4.Cells[i].PrjCount   = 1;
                        if ((endTime - startTime).TotalDays == 0)
                        {
                            row4.Cells[i].PlanTime = double.Parse(pt);
                        }
                        else
                        {
                            row4.Cells[i].PlanTime = double.Parse(pt) / (endTime - startTime).TotalDays;
                        }
                        row4.Cells[i].TipContent  = $"{cjr}\t{sx}";
                        row4.Cells[i].ShowContent = row4.Cells[i].PrjCount + "/" + String.Format("{0:F}", row4.Cells[i].PlanTime / row4.Cells[i].PrjCount) + "/" + String.Format("{0:F}", row4.Cells[i].ActualTime / row4.Cells[i].PrjCount);
                    }
                }
                else
                {
                    row4 = row3.Rows[0];
                    //公司(蓝色)、外勤(橙色)、出差(红色)、终止(灰色)、完成(绿色)
                    var color = gdlx == "产出" ? "#1E90FF" : gdlx == "外勤" ? "#FFA500" : gdlx == "出差" ? "#FF4500" : gdlx == "终止" ? "#D3D3D3" : gdlx == "完成" ? "#92D050" : "#FFFFFF";

                    //for (int i = startTime.Day - 1; i < endTime.Day; i++)
                    for (int i = (startTime - GanttViewModel.StartDay).Days; i < (endTime - GanttViewModel.StartDay).Days + 1; i++)
                    {
                        if (color == "#92D050")
                        {
                            row4.Cells[i].Color = color;
                        }
                        else if (color == "#D3D3D3")
                        {
                            if (row4.Cells[i].Color == "#92D050")
                            {
                            }
                            else
                            {
                                row4.Cells[i].Color = color;
                            }
                        }
                        else if (color == "#FF4500")
                        {
                            if (row4.Cells[i].Color == "#92D050" || row4.Cells[i].Color == "#D3D3D3")
                            {
                            }
                            else
                            {
                                row4.Cells[i].Color = color;
                            }
                        }
                        else if (color == "#FFA500")
                        {
                            if (row4.Cells[i].Color == "#92D050" || row4.Cells[i].Color == "#D3D3D3" || row4.Cells[i].Color == "#FF4500")
                            {
                            }
                            else
                            {
                                row4.Cells[i].Color = color;
                            }
                        }
                        else if (color == "#1E90FF")
                        {
                            if (row4.Cells[i].Color == "#92D050" || row4.Cells[i].Color == "#D3D3D3" || row4.Cells[i].Color == "#FF4500" || row4.Cells[i].Color == "#FFA500")
                            {
                            }
                            else
                            {
                                row4.Cells[i].Color = color;
                            }
                        }

                        row4.Cells[i].ActualTime += double.Parse(at) / 480;
                        row4.Cells[i].PrjCount   += 1;
                        if ((endTime - startTime).TotalDays == 0)
                        {
                            row4.Cells[i].PlanTime = double.Parse(pt);
                        }
                        else
                        {
                            row4.Cells[i].PlanTime = double.Parse(pt) / (endTime - startTime).TotalDays;
                        }
                        if (row4.Cells[i].TipContent == null)
                        {
                            row4.Cells[i].TipContent += $"{cjr}\t{sx}";
                        }
                        else
                        {
                            row4.Cells[i].TipContent += $"\n{cjr}\t{sx}";
                        }
                        row4.Cells[i].ShowContent = row4.Cells[i].PrjCount + "/" + String.Format("{0:F}", row4.Cells[i].PlanTime / row4.Cells[i].PrjCount) + "/" + String.Format("{0:F}", row4.Cells[i].ActualTime / row4.Cells[i].PrjCount);
                    }
                }

                //第五列
                var ts = endTime - startTime;
                row2.ColumnContent_5 += ts.TotalDays;
            }

            var rankTable = new DataTable();

            rankTable.Columns.Add("项目");
            rankTable.Columns.Add("人日");

            foreach (var dataColumn1 in data)
            {
                foreach (var dataColumn2_5 in dataColumn1.Rows)
                {
                    var newRow = rankTable.NewRow();
                    newRow["项目"] = dataColumn2_5.ColumnContent_2;
                    newRow["人日"] = string.Format("{0:F2}", dataColumn2_5.ColumnContent_5);
                    rankTable.Rows.Add(newRow);

                    for (int i = 0; i < dataColumn2_5.Rows[0].Rows[0].Cells.Count - 1; i++)
                    {
                        for (int j = i + 1; j < dataColumn2_5.Rows[0].Rows[0].Cells.Count; j++)
                        {
                            if (dataColumn2_5.Rows[0].Rows[0].Cells[i].ShowContent == dataColumn2_5.Rows[0].Rows[0].Cells[j].ShowContent)
                            {
                                dataColumn2_5.Rows[0].Rows[0].Cells[j].ShowContent = "";
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }

            base.PageControl.Gantt.Controller.Rows = new ObservableCollection <DataColumn_1>(data.OrderBy(dc => dc.ColumnContent_1));

            base.PageControl.Gantt.Screening.Controller.Rows = new DataView(rankTable);
        }
コード例 #2
0
        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadedData(DataRow[] rows)
        {
            ObservableCollection <DataColumn_1> data = new ObservableCollection <DataColumn_1>();

            foreach (DataRow dr in rows)
            {
                //第一列
                var column1 = dr["项目"].ToString();
                var row1    = data.SingleOrDefault(r => r.ColumnContent_1 == column1);
                if (row1 == null)
                {
                    row1 = new DataColumn_1();
                    row1.ColumnContent_1 = column1;
                    data.Add(row1);
                }

                //第二列
                var column2 = dr["承接人"].ToString();
                var row2    = row1.Rows.SingleOrDefault(r => r.ColumnContent_2 == column2);
                if (row2 == null)
                {
                    row2 = new DataColumn_2_5();
                    row2.ColumnContent_2 = column2;
                    row1.Rows.Add(row2);
                }

                //第三列
                var column3 = dr["承接人"].ToString();
                var row3    = row2.Rows.SingleOrDefault(r => r.ColumnContent_3 == column3);
                if (row3 == null)
                {
                    row3 = new DataColumn_3();
                    row3.ColumnContent_3 = column3;
                    row2.Rows.Add(row3);
                }

                //第四列
                var dd   = dr["地点"].ToString();
                var xmzj = dr["项目总监"].ToString();
                var khjl = dr["客户经理"].ToString();
                var djlx = dr["工单类型"].ToString();
                var zczj = dr["支撑总监"].ToString();
                var fazj = dr["方案专家"].ToString();
                var sxbz = dr["事项备注"].ToString();

                var gdlx = dr["工单类型"].ToString();
                var sx   = dr["事项"].ToString();
                var gdzt = dr["工单状态"].ToString();
                var t1   = dr["开始时间"].ToString();
                var t2   = dr["结束时间"].ToString();

                var startTime = DateTime.Parse(t1);
                var endTime   = DateTime.Parse(t2);
                var row4      = row3.FindCanAddCell(startTime, endTime);

                if (row4 == null)
                {
                    row4 = new DataColumn_4();
                    row3.Rows.Add(row4);
                }
                row4.Cells[(startTime - GanttViewModel.StartDay).Days].LeftThickness = base.PageControl.Gantt.Controller.CellLineWidth;
                row4.Cells[(endTime - GanttViewModel.StartDay).Days].RightThickness  = base.PageControl.Gantt.Controller.CellLineWidth;
                row4.Cells[(startTime - GanttViewModel.StartDay).Days].ShowContent   = sx;

                //公司(蓝色)、外勤(橙色)、出差(红色)、终止(灰色)、完成(绿色)
                var color = gdlx == "产出" ? "#1E90FF" : gdlx == "外勤" ? "#FFA500" : gdlx == "出差" ? "#FF4500" : gdlx == "终止" ? "#D3D3D3" : gdlx == "完成" ? "#92D050" : "#FFFFFF";

                for (int i = (startTime - GanttViewModel.StartDay).Days; i < (endTime - GanttViewModel.StartDay).Days + 1; i++)
                {
                    row4.Cells[i].Color      = color;
                    row4.Cells[i].TipContent = $"{sxbz}";
                }

                //第五列
                var ts = endTime - startTime;
                row2.ColumnContent_5 += ts.TotalDays;
            }

            var rankTable = new DataTable();

            rankTable.Columns.Add("项目");
            rankTable.Columns.Add("承接人");
            rankTable.Columns.Add("人日");

            foreach (var dataColumn1 in data)
            {
                foreach (var dataColumn2_5 in dataColumn1.Rows)
                {
                    var newRow = rankTable.NewRow();
                    newRow["项目"]  = dataColumn1.ColumnContent_1;
                    newRow["承接人"] = dataColumn2_5.ColumnContent_2;
                    newRow["人日"]  = string.Format("{0:F2}", dataColumn2_5.ColumnContent_5);
                    rankTable.Rows.Add(newRow);
                }
            }

            base.PageControl.Gantt.Controller.Rows           = new ObservableCollection <DataColumn_1>(data.OrderBy(dc => dc.ColumnContent_1));
            base.PageControl.Gantt.Screening.Controller.Rows = new DataView(rankTable);
        }