/// <summary> /// Builds the phases table of validation dataset /// </summary> /// <param name="tblPhasesHours">the phases table in the hours dataset</param> /// <param name="tblPhasesCosts">the phases table in the costs & sales dataset</param> /// <returns>the phases table of validation dataset</returns> private DataTable BuildValidationPhasesTable(DataTable tblPhasesHours, DataTable tblPhasesCosts) { if (tblPhasesHours.Rows.Count != tblPhasesCosts.Rows.Count) { throw new IndException(ApplicationMessages.EXCEPTION_NO_ROWS_DIFFERENT); } DataTable tblPhases = new DataTable("tblPhases"); //Create the columns DataColumn newCol = new DataColumn("IdProject", typeof(int)); tblPhases.Columns.Add(newCol); newCol = new DataColumn("IdPhase", typeof(int)); tblPhases.Columns.Add(newCol); newCol = new DataColumn("PhaseName", typeof(string)); tblPhases.Columns.Add(newCol); newCol = new DataColumn("TotHours", typeof(int)); tblPhases.Columns.Add(newCol); newCol = new DataColumn("Averate", typeof(decimal)); tblPhases.Columns.Add(newCol); newCol = new DataColumn("ValHours", typeof(decimal)); tblPhases.Columns.Add(newCol); newCol = new DataColumn("OtherCost", typeof(decimal)); tblPhases.Columns.Add(newCol); newCol = new DataColumn("Sales", typeof(decimal)); tblPhases.Columns.Add(newCol); newCol = new DataColumn("NetCost", typeof(decimal)); tblPhases.Columns.Add(newCol); tblPhases.PrimaryKey = new DataColumn[] { tblPhases.Columns["IdPhase"] }; foreach (DataRow hoursRow in tblPhasesHours.Rows) { DataRow costsRow = tblPhasesCosts.Rows.Find(hoursRow["IdPhase"]); if (costsRow == null) { throw new IndException(ApplicationMessages.EXCEPTION_ROWS_DO_NOT_MATCH); } DataRow phasesRow = tblPhases.NewRow(); phasesRow["IdProject"] = hoursRow["IdProject"]; phasesRow["IdPhase"] = hoursRow["IdPhase"]; phasesRow["PhaseName"] = hoursRow["PhaseName"]; phasesRow["TotHours"] = hoursRow["NewHours"]; if (hoursRow["NewVal"] != DBNull.Value && hoursRow["NewHours"] != DBNull.Value) { phasesRow["Averate"] = ((int)hoursRow["NewHours"] == 0) ? 0 : decimal.Divide((decimal)hoursRow["NewVal"], (int)hoursRow["NewHours"]); } else { phasesRow["Averate"] = DBNull.Value; } phasesRow["ValHours"] = hoursRow["NewVal"]; phasesRow["OtherCost"] = costsRow["NewCost"]; phasesRow["Sales"] = costsRow["NewSales"]; phasesRow["NetCost"] = DSUtils.SumNullableDecimals(hoursRow["NewVal"], costsRow["NewCost"], costsRow["NewSales"]); tblPhases.Rows.Add(phasesRow); } return(tblPhases); }