/// <summary> /// Calculates the Date Interval column for a given budget table /// </summary> /// <param name="sourceTable">the source table</param> /// <param name="dateIntervalCol">The column that contains the Date Interval value</param> /// <param name="startYearMonthCol">The column that contains the StartYearMonth value</param> /// <param name="endYearMonthCol">The column that contains the EndYearMonth value</param> protected void CalculateDateIntervalColumn(DataTable sourceTable, string dateIntervalCol, string startYearMonthCol, string endYearMonthCol) { if (!sourceTable.Columns.Contains(startYearMonthCol)) { throw new IndException(ApplicationMessages.EXCEPTION_COLUMN_MISSING); } if (!sourceTable.Columns.Contains(endYearMonthCol)) { throw new IndException(ApplicationMessages.EXCEPTION_COLUMN_MISSING); } sourceTable.Columns.Add(new DataColumn(dateIntervalCol, typeof(string))); foreach (DataRow row in sourceTable.Rows) { if ((row[startYearMonthCol] == DBNull.Value) || (row[endYearMonthCol] == DBNull.Value)) { continue; } YearMonth startYearMonth = new YearMonth(row[startYearMonthCol].ToString()); YearMonth endYearMonth = new YearMonth(row[endYearMonthCol].ToString()); string firstPart = startYearMonth.GetMonthRepresentation() + "-" + startYearMonth.Year.ToString().Substring(2); string lastPart = endYearMonth.GetMonthRepresentation() + "-" + endYearMonth.Year.ToString().Substring(2); row[dateIntervalCol] = firstPart + " to " + lastPart; } }
private void LoadHeader() { ImportDetails impDetails = new ImportDetails(CurrentConnectionManager); impDetails.IdImport = IdImport; DataSet dsHeader = impDetails.SelectHeaderInformation(); if (dsHeader.Tables.Count != 3) { throw new IndException(ApplicationMessages.EXCEPTION_DATA_SET_CORRUPTED); } DataRow sourceRow = dsHeader.Tables[0].Rows[0]; txtCountry.Text = sourceRow["Country"].ToString(); txtFileName.Text = sourceRow["FileName"].ToString(); txtDate.Text = ((DateTime)sourceRow["Date"]).ToShortDateString(); txtUserName.Text = sourceRow["UserName"].ToString(); string TotalNoOfRows = sourceRow["Lines"].ToString(); txtLines.Text = TotalNoOfRows; //set IDSource to be used in new file name IdSource = Int32.Parse(sourceRow["IdSource"].ToString()); DataRow sourceRow1 = dsHeader.Tables[1].Rows[0]; string NoOfErrors = sourceRow1["NoOfErrors"].ToString(); txtNoOfErrors.Text = NoOfErrors; DataRow sourceRow2 = dsHeader.Tables[2].Rows[0]; string NoOfRowsOK = sourceRow2["NoOfRowsOk"].ToString(); txtNoOfRowsOK.Text = NoOfRowsOK; int NoOfRowsIgnored = int.Parse(TotalNoOfRows) - int.Parse(NoOfRowsOK); txtNoOfRowsIgnored.Text = NoOfRowsIgnored.ToString(); YearMonth yearMonth = new YearMonth(sourceRow["Period"].ToString()); if (yearMonth.Value == ApplicationConstants.YEAR_MONTH_SQL_MIN_VALUE) { txtPeriod.Text = ApplicationConstants.NOT_AVAILABLE; } else { txtPeriod.Text = yearMonth.GetMonthRepresentation() + " - " + yearMonth.Year; } }
/// <summary> /// Adds a new column to sourceTable which contains the data from yearMonthCol which is represented in YYYYMM format (like in the database) /// in the format YYYY/MM /// </summary> /// <param name="sourceTable">the table on which to perform the transformation</param> /// <param name="yearMonthCol">the name of the column containing yearmonth data in the fomat YYYYMM</param> /// <param name="dateCol">the name of the column that will contain yearmonth data in the fomat YYYY/MM</param> private void ConvertYMToDate(DataTable sourceTable, string yearMonthCol, string dateCol) { if (!sourceTable.Columns.Contains(yearMonthCol)) { throw new IndException(ApplicationMessages.EXCEPTION_COLUMN_MISSING); } sourceTable.Columns.Add(new DataColumn(dateCol, typeof(string))); foreach (DataRow row in sourceTable.Rows) { if (row[yearMonthCol] == DBNull.Value) { continue; } YearMonth yearMonth = new YearMonth(row[yearMonthCol].ToString()); string dateVal = yearMonth.GetMonthRepresentation() + "-" + yearMonth.Year.ToString().Substring(2); //string date = row[yearMonthCol].ToString().Insert(4, "/"); row[dateCol] = dateVal; } }