public void ReplaceBooleanColumnTest()
        {
            DataSet    ds = new DataSet();
            DataTable  dt = new DataTable("Table");
            DataColumn dc = new DataColumn("BoolColumn", typeof(bool));

            dt.Columns.Add(dc);
            ds.Tables.Add(dt);
            DataRow newRow = dt.NewRow();

            newRow["BoolColumn"] = true;
            dt.Rows.Add(newRow);
            newRow = dt.NewRow();
            newRow["BoolColumn"] = true;
            dt.Rows.Add(newRow);
            newRow = dt.NewRow();
            newRow["BoolColumn"] = false;
            dt.Rows.Add(newRow);

            DataSet newDs = DSUtils.ReplaceBooleanColumn("BoolColumn", ds, 0);

            Assert.AreEqual(1, newDs.Tables.Count);
            Assert.AreEqual("Table", newDs.Tables[0].TableName);
            Assert.AreEqual(2, newDs.Tables[0].Columns.Count);
            Assert.AreEqual("BoolColumn", newDs.Tables[0].Columns[0].ColumnName);
            Assert.AreEqual(3, newDs.Tables[0].Rows.Count);
            Assert.AreEqual("Yes", newDs.Tables[0].Rows[0]["BoolColumn"]);
            Assert.AreEqual("Yes", newDs.Tables[0].Rows[1]["BoolColumn"]);
            Assert.AreEqual("No", newDs.Tables[0].Rows[2]["BoolColumn"]);
        }
Beispiel #2
0
        protected override DataSet PostGetEntities(DataSet ds)
        {
            DSUtils.ReplaceBooleanColumn("IsActive", ds, 0);

            DataColumn newStartDate       = new DataColumn("Start Date", typeof(string));
            DataColumn newEndDate         = new DataColumn("End Date", typeof(string));
            DataColumn newProjectCodeName = new DataColumn("Project", typeof(string));

            int oldStartDatePosition = ds.Tables[0].Columns["StartYearMonth"].Ordinal;
            int oldEndDatePosition   = ds.Tables[0].Columns["EndYearMonth"].Ordinal;

            ds.Tables[0].Columns.Add(newStartDate);
            newStartDate.SetOrdinal(oldStartDatePosition);

            ds.Tables[0].Columns.Add(newEndDate);
            newEndDate.SetOrdinal(oldEndDatePosition);

            //move old YearMonth columns to the end - since they will be hidded
            DataColumn startYearMonthColumn = ds.Tables[0].Columns["StartYearMonth"];
            DataColumn endYearMonthColumn   = ds.Tables[0].Columns["EndYearMonth"];

            startYearMonthColumn.SetOrdinal(ds.Tables[0].Columns.Count - 1);
            endYearMonthColumn.SetOrdinal(ds.Tables[0].Columns.Count - 1);

            ds.Tables[0].Columns.Add(newProjectCodeName);

            //transform the null values for StartYearMonth and EndYearMonth
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                int startYearMonth = (row["StartYearMonth"] == DBNull.Value) ? ApplicationConstants.INT_NULL_VALUE : (int)row["StartYearMonth"];
                int endYearMonth   = (row["EndYearMonth"] == DBNull.Value) ? ApplicationConstants.INT_NULL_VALUE : (int)row["EndYearMonth"];

                //Get the startyearmonth value
                if (startYearMonth == ApplicationConstants.INT_NULL_VALUE)
                {
                    row["Start Date"] = String.Empty;
                }
                else
                {
                    row["Start Date"] = DateTimeUtils.GetDateFromYearMonth(startYearMonth);
                }

                //Get the endyearmonth value
                if (endYearMonth == ApplicationConstants.INT_NULL_VALUE)
                {
                    row["End Date"] = String.Empty;
                }
                else
                {
                    row["End Date"] = DateTimeUtils.GetDateFromYearMonth(endYearMonth);
                }
            }
            return(ds);
        }
        protected override DataSet PostGetEntities(DataSet ds)
        {
            DSUtils.ReplaceBooleanColumn("IsActive", ds, 0);
            DSUtils.ReplaceBooleanColumn("IsInitialBudgetValidated", ds, 0);

            DataColumn newProjectCodeName = new DataColumn("CodeName", typeof(string));

            ds.Tables[0].Columns.Add(newProjectCodeName);

            //transform the null values for StartYearMonth and EndYearMonth
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                //Set column Project
                row["CodeName"] = row["Code"] + " - " + row["Name"];
            }
            return(ds);
        }
 protected override DataSet PostGetEntities(DataSet ds)
 {
     DSUtils.ReplaceBooleanColumn("IsActive", ds, 0);
     return(ds);
 }