Ejemplo n.º 1
0
        public ucToolEmpSum()
        {
            InitializeComponent();

            luProject.Properties.DataSource   = Project.AccessibleList().Select(p => new { Project = p.Name, Code = p.Code, MatchId = p.MatchId, DisplayName = p.DisplayName });
            luLemNumber.Properties.DataSource = LemHeader.GetAllLemNumber().Select(x => new { LemNum = x });

            Func <string, string, int, GridColumn> CreateColumn = new Func <string, string, int, GridColumn>((field, caption, visibleIndex) =>
            {
                GridColumn column   = gvSummary.Columns.AddVisible(field, caption);
                column.VisibleIndex = visibleIndex;
                return(column);
            });

            int visionIndex = 0;

            new List <string> {
                ColName.EmpNum, ColName.EmployeeName, ColName.WorkClass, ColName.Project
            }.ForEach(
                x => gvSummary.Columns[x].VisibleIndex = visionIndex++
                );

            foreach (var timecode in TimeCode.SubList(EnumValueType.Hours))
            {
                tableLabour.Columns.Add(ColName.BillRateI(timecode), Type.GetType("System.Decimal"));
                var rateCol = CreateColumn(ColName.BillRateI(timecode), $"{timecode.Desc} Bill Rate", visionIndex++);
                rateCol.DisplayFormat.FormatType   = FormatType.Numeric;
                rateCol.DisplayFormat.FormatString = "c2";
                rateCol.OptionsColumn.AllowEdit    = false;

                tableLabour.Columns.Add(ColName.EnterValueI(timecode), Type.GetType("System.Decimal"));
                var hourCol = CreateColumn(ColName.EnterValueI(timecode), $"{timecode.Desc} Hours", visionIndex++);
                hourCol.DisplayFormat.FormatType   = FormatType.Numeric;
                hourCol.DisplayFormat.FormatString = "n2";
                hourCol.OptionsColumn.AllowEdit    = false;
                hourCol.Summary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
                    new DevExpress.XtraGrid.GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum, hourCol.FieldName, "{0:n2}")
                });
            }

            foreach (var timecode in TimeCode.SubList(TimeCode.EnumValueType.Dollars))
            {
                tableLabour.Columns.Add(ColName.EnterValueI(timecode), Type.GetType("System.Decimal"));
                var amountCol = CreateColumn(ColName.EnterValueI(timecode), timecode.Desc, visionIndex++);
                amountCol.DisplayFormat.FormatType   = FormatType.Numeric;
                amountCol.DisplayFormat.FormatString = "c2";
                amountCol.OptionsColumn.AllowEdit    = false;
                amountCol.Summary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
                    new DevExpress.XtraGrid.GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum, amountCol.FieldName, "{0:c2}")
                });
            }

            gvSummary.Columns[ColName.TotalHours].VisibleIndex = visionIndex++;
            gvSummary.Columns[ColName.BillAmount].VisibleIndex = visionIndex++;
            gvSummary.BestFitColumns(true);
        }
Ejemplo n.º 2
0
        public void SetData(List <LemHeader> headerList)
        {
            tableLabour.Clear();

            var table = LemHeader.GetCostCodeSummary(headerList.Select(x => x.Id).ToList());
            var list  = table.Select().Select(r => new
            {
                EmpNum        = Convert.ToInt32(r["EmpNum"]),
                WorkClassCode = Convert.ToString(r["WorkClassCode"]),
                Billable      = Convert.ToBoolean(r["Billable"]),
                ProjectId     = Convert.ToInt32(r["ProjectId"]),
                ChangeOrderId = ConvertEx.ToNullable <int>(r["ChangeOrderId"]),
                Level1Id      = ConvertEx.ToNullable <int>(r["Level1Id"]),
                Level2Id      = ConvertEx.ToNullable <int>(r["Level2Id"]),
                Level3Id      = ConvertEx.ToNullable <int>(r["Level3Id"]),
                Level4Id      = ConvertEx.ToNullable <int>(r["Level4Id"]),
                TimeCodeId    = Convert.ToInt32(r["TimeCodeId"]),
                SumWorkHour   = ConvertEx.ToNullable <decimal>(r["SumWorkHour"]),
                SumAmount     = ConvertEx.ToNullable <decimal>(r["SumAmount"]),
            });

            var groupList = list.ToLookup(x => new
            {
                x.EmpNum,
                x.WorkClassCode,
                x.Billable,
                x.ProjectId,
                x.ChangeOrderId,
                x.Level1Id,
                x.Level2Id,
                x.Level3Id,
                x.Level4Id,
                EmpName     = Employee.GetEmployee(x.EmpNum)?.DisplayName,
                WorkClass   = WorkClass.GetWorkClass(x.WorkClassCode).DisplayName,
                Project     = Project.GetProject(x.ProjectId),
                ChangeOrder = ChangeOrder.GetChangeOrder(x.ProjectId, x.ChangeOrderId)?.DisplayName,
                Level1      = LevelOneCode.GetLevelCode(x.Level1Id)?.DisplayName,
                Level2      = LevelTwoCode.GetLevelCode(x.Level2Id)?.DisplayName,
                Level3      = LevelThreeCode.GetLevelCode(x.Level3Id)?.DisplayName,
                Level4      = LevelFourCode.GetLevelCode(x.Level4Id)?.DisplayName
            }).OrderBy(x => x.Key.Level1).ThenBy(x => x.Key.Level2).ThenBy(x => x.Key.Level3).ThenBy(x => x.Key.Level4).ThenBy(x => x.Key.EmpName).ThenBy(x => x.Key.Project).ThenBy(x => x.Key.ChangeOrder).ThenBy(x => x.Key.WorkClass).ThenBy(x => x.Key.Billable).ToList();

            groupList.ForEach(g =>
            {
                DataRow row = tableLabour.Rows.Add(
                    g.Key.EmpNum,
                    g.Key.EmpName,
                    g.Key.WorkClass,
                    g.Key.Project,
                    g.Key.ChangeOrder,
                    g.Key.Level1,
                    g.Key.Level2,
                    g.Key.Level3,
                    g.Key.Level4,
                    g.Key.Billable,
                    null,
                    null);

                decimal?billRate;
                decimal totalHours  = 0;
                decimal billAmounts = 0;
                foreach (var timecode in TimeCode.ListForCompany())
                {
                    if (timecode.ValueType == EnumValueType.Hours)
                    {
                        billRate = ProjectWorkClass.GetBillRate(g.Key.ProjectId, timecode.MatchId, g.Key.WorkClassCode);
                        row[ColName.BillRateI(timecode)] = (object)billRate ?? DBNull.Value;

                        decimal hours = g.Where(x => x.TimeCodeId == timecode.MatchId).Sum(x => x.SumWorkHour) ?? 0;
                        row[ColName.EnterValueI(timecode)] = hours != 0 ? (object)hours : DBNull.Value;

                        totalHours  += hours;
                        billAmounts += (billRate ?? 0) * hours;
                    }
                    else
                    {
                        decimal amount = g.Where(x => x.TimeCodeId == timecode.MatchId).Sum(x => x.SumAmount) ?? 0;
                        row[ColName.EnterValueI(timecode)] = amount != 0 ? (object)amount : DBNull.Value;
                        billAmounts += amount;
                    }

                    row[ColName.TotalHours] = totalHours != 0 ? (object)totalHours : DBNull.Value;
                    row[ColName.BillAmount] = billAmounts != 0 ? (object)billAmounts : DBNull.Value;
                }
            });
        }