예제 #1
0
        public void GetUnitLabel_without_Setting_Name_Returns_Default_If_Specified()
        {
            cUnit  unit      = new cUnit(eUnitType.Force, unitPower: "5", unitIsNumerator: false);
            string unitLabel = unit.GetUnitLabel(parseSchema: false, withPowers: true, asList: true, useDefaultsIfNA: true);

            Assert.That(unitLabel, Is.EqualTo("1/lb^5"));
        }
예제 #2
0
        private void InitcboUnit()
        {
            cUnit     oUnit = new cUnit();
            string    strMessage = string.Empty, strCriteria = string.Empty;
            string    strUnit_code     = cboUnit.SelectedValue;
            string    strDirector_code = cboDirector.SelectedValue;
            string    strYear          = ((DataSet)Application["xmlconfig"]).Tables["default"].Rows[0]["yearnow"].ToString();
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            strCriteria = " and unit.unit_year = '" + strYear + "'  and  unit.c_active='Y' " +
                          " and unit.director_code = '" + strDirector_code + "' ";
            if (oUnit.SP_SEL_UNIT(strCriteria, ref ds, ref strMessage))
            {
                dt = ds.Tables[0];
                cboUnit.Items.Clear();
                cboUnit.Items.Add(new ListItem("---- เลือกข้อมูลทั้งหมด ----", ""));
                int i;
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    cboUnit.Items.Add(new ListItem(dt.Rows[i]["unit_name"].ToString(), dt.Rows[i]["unit_code"].ToString()));
                }
                if (cboUnit.Items.FindByValue(strUnit_code) != null)
                {
                    cboUnit.SelectedIndex = -1;
                    cboUnit.Items.FindByValue(strUnit_code).Selected = true;
                }
            }
        }
예제 #3
0
        public string GetUnitLabel(string name, string power, bool unitIsNumerator, bool parseSchema, bool withPowers, bool asList)
        {
            cUnit unit = new cUnit(eUnitType.Force, unitPower: power, unitIsNumerator: unitIsNumerator);

            unit.SetUnitName(name);
            return(unit.GetUnitLabel(parseSchema, withPowers, asList));
        }
예제 #4
0
        public void Initialization_by_Unit_Type(eUnitType type, string expectedName)
        {
            cUnit unit = new cUnit(type);

            Assert.That(unit.Type, Is.EqualTo(type));
            Assert.That(unit.Name, Is.EqualTo(expectedName));
        }
예제 #5
0
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string strMessage   = string.Empty;
            string strCheck     = string.Empty;
            string strScript    = string.Empty;
            string strUpdatedBy = Session["username"].ToString();
            Label  lblunit_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblunit_code");
            cUnit  oUnit        = new cUnit();

            try
            {
                if (!oUnit.SP_DEL_UNIT(lblunit_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    string strScript1 = "RefreshMain('" + ViewState["page"].ToString() + "');";
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "OpenPage", strScript1, true);
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oUnit.Dispose();
            }
            BindGridView();
        }
예제 #6
0
        public void Get_Set_Properties_Gets_Sets_Properties()
        {
            cUnit unit = new cUnit();

            Assert.That(unit.Type, Is.EqualTo(eUnitType.None));
            Assert.That(unit.Name, Is.EqualTo(string.Empty));
            Assert.That(unit.Numerator, Is.EqualTo(true));
            Assert.That(unit.UnitsList.Count, Is.EqualTo(0));

            unit.Numerator = false;
            unit.Type      = eUnitType.Force;

            Assert.That(unit.Type, Is.EqualTo(eUnitType.Force));
            Assert.That(unit.Name, Is.EqualTo("lb"));
            Assert.That(unit.Numerator, Is.EqualTo(false));
            Assert.That(unit.UnitsList.Count, Is.EqualTo(9));
            Assert.IsTrue(unit.UnitsList.Contains(""));
            Assert.IsTrue(unit.UnitsList.Contains("lb"));
            Assert.IsTrue(unit.UnitsList.Contains("Kip"));
            Assert.IsTrue(unit.UnitsList.Contains("N"));
            Assert.IsTrue(unit.UnitsList.Contains("kN"));
            Assert.IsTrue(unit.UnitsList.Contains("MN"));
            Assert.IsTrue(unit.UnitsList.Contains("GN"));
            Assert.IsTrue(unit.UnitsList.Contains("kgf"));
            Assert.IsTrue(unit.UnitsList.Contains("tf"));
        }
예제 #7
0
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string strMessage   = string.Empty;
            string strCheck     = string.Empty;
            string strScript    = string.Empty;
            string strUpdatedBy = Session["username"].ToString();
            Label  lblunit_code = (Label)GridView1.Rows[e.RowIndex].FindControl("lblunit_code");
            cUnit  oUnit        = new cUnit();

            try
            {
                if (!oUnit.SP_DEL_UNIT(lblunit_code.Text, "N", strUpdatedBy, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oUnit.Dispose();
            }
            BindGridView(0);
        }
예제 #8
0
        public void Clone_Clones_Object()
        {
            eUnitType unitType     = eUnitType.Length;
            string    unitPower    = "2";
            bool      isNumerator  = false;
            cUnit     unitOriginal = new cUnit(unitType, unitPower, isNumerator);

            Assert.That(unitOriginal.Type, Is.EqualTo(unitType));
            Assert.That(unitOriginal.Name, Is.EqualTo("in"));
            Assert.That(unitOriginal.Power, Is.EqualTo(unitPower));
            Assert.That(unitOriginal.Numerator, Is.EqualTo(isNumerator));
            Assert.That(unitOriginal.UnitsList.Count, Is.EqualTo(10));
            Assert.That(unitOriginal.UnitsList.Contains("ft"));

            object unitClone = unitOriginal.Clone();

            Assert.That(unitClone is cUnit);
            cUnit unitCloneCast = (cUnit)unitClone;

            Assert.That(unitCloneCast.Type, Is.EqualTo(unitType));
            Assert.That(unitCloneCast.Name, Is.EqualTo("in"));
            Assert.That(unitCloneCast.Power, Is.EqualTo(unitPower));
            Assert.That(unitCloneCast.Numerator, Is.EqualTo(isNumerator));
            Assert.That(unitCloneCast.UnitsList.Count, Is.EqualTo(10));
            Assert.That(unitCloneCast.UnitsList.Contains("ft"));
        }
        private void BindGridView3()
        {
            cUnit   oUnit       = new cUnit();
            DataSet ds          = new DataSet();
            string  strMessage  = string.Empty;
            string  strCriteria = string.Empty;
            string  strActive   = string.Empty;

            strCriteria = strCriteria + "  And  (c_active ='Y') and director_code= '" + this.myDirectorCode + "' ";
            try
            {
                if (!oUnit.SP_SEL_UNIT(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    GridView3.DataSource = ds.Tables[0];
                    GridView3.DataBind();
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oUnit.Dispose();
                ds.Dispose();
            }
        }
예제 #10
0
        public string SetUnitName_Of_Unit_Type_Sets_Unit_Name(string name, double type)
        {
            cUnit unit = new cUnit((eUnitType)type);

            unit.SetUnitName(name);

            return(unit.Name);
        }
예제 #11
0
        public void MultiplyUnitPowers2b()
        {
            cUnit  unit1         = new cUnit(eUnitType.Force, unitPower: "6", unitIsNumerator: true);
            cUnit  unit2         = new cUnit(eUnitType.Force, unitPower: "-4", unitIsNumerator: true);
            string newPowerLabel = unit1.MultiplyUnitPowers(unit2);

            Assert.That(newPowerLabel, Is.EqualTo("2"));
        }
예제 #12
0
        public void DivideUnitPowers3()
        {
            cUnit  unit1         = new cUnit(eUnitType.Force, unitPower: "6", unitIsNumerator: true);
            cUnit  unit2         = new cUnit(eUnitType.Force, unitPower: "4", unitIsNumerator: false);
            string newPowerLabel = unit1.DivideUnitPowers(unit2);

            Assert.That(newPowerLabel, Is.EqualTo("10"));
        }
예제 #13
0
        public void Convert_Units_As_Null_Objects_Returns_Zero()
        {
            cUnit  unit     = new cUnit(eUnitType.Force);
            cUnit  unitFrom = null;
            cUnit  unitTo   = null;
            double result   = unit.Convert(unitFrom, unitTo);

            Assert.That(result, Is.EqualTo(0));
        }
예제 #14
0
        public void SetUnitName_Maintains_Default_Unit_Name_For_Empty_Names_and_Known_Types(string name)
        {
            cUnit unit = new cUnit(eUnitType.Force);

            Assert.That(unit.Name, Is.EqualTo("lb"));

            unit.SetUnitName(name);

            Assert.That(unit.Name, Is.EqualTo("lb"));
        }
예제 #15
0
        public void Initialization_Basic_Sets_Defaults()
        {
            cUnit unit = new cUnit();

            Assert.That(unit.Type, Is.EqualTo(eUnitType.None));
            Assert.That(unit.Name, Is.EqualTo(string.Empty));
            Assert.That(unit.Numerator, Is.EqualTo(true));
            Assert.That(unit.Power, Is.EqualTo("1"));
            Assert.That(unit.UnitsList.Count, Is.EqualTo(0));
        }
예제 #16
0
        public string Set_Power_Limited_To_Numerical(string power)
        {
            cUnit unit = new cUnit();

            Assert.That(unit.Power, Is.EqualTo("1"));

            unit.SetUnitPower(power);

            return(unit.Power);
        }
예제 #17
0
        public string SetUnitName_Sets_Unit_Name(string name)
        {
            cUnit unit = new cUnit();

            Assert.That(unit.Name, Is.EqualTo(string.Empty));

            unit.SetUnitName(name);

            return(unit.Name);
        }
예제 #18
0
        public void Set_Power_With_Negative_Number_Changes_Unit_To_Denominator(string power, string expectedPower, bool expectedAsNumerator)
        {
            cUnit unit = new cUnit();

            Assert.That(unit.Power, Is.EqualTo("1"));

            unit.SetUnitPower(power);
            Assert.That(unit.Power, Is.EqualTo(expectedPower));
            Assert.That(unit.Numerator, Is.EqualTo(expectedAsNumerator));
        }
예제 #19
0
        [TestCase(100, null, null, 1, 0.1)] // Out of range
        public void Convert_Units_As_Strings_Converts_Units(
            eUnitType unitType,
            string unitToConvertFrom,
            string unitToConvertTo,
            double expected,
            double tolerance)
        {
            cUnit  unit   = new cUnit(unitType);
            double result = unit.Convert(unitToConvertFrom, unitToConvertTo);

            Assert.AreEqual(expected, result, tolerance);
        }
예제 #20
0
        private void BindGridView()
        {
            cUnit   oUnit            = new cUnit();
            DataSet ds               = new DataSet();
            string  strMessage       = string.Empty;
            string  strCriteria      = string.Empty;
            string  strDirector_code = string.Empty;

            strDirector_code = cboDirector.SelectedValue;
            strCriteria      = strCriteria + "  And  (unit.Director_code = '" + strDirector_code + "') ";
            if (this.BudgetType == "B")
            {
                strCriteria = strCriteria + "  And  (unit.budget_type <> 'R') ";
            }
            else
            {
                strCriteria = strCriteria + "  And  (unit.budget_type = 'R') ";
            }
            try
            {
                if (!oUnit.SP_SEL_UNIT(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    try
                    {
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                    catch
                    {
                        GridView1.PageIndex           = 0;
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oUnit.Dispose();
                ds.Dispose();
            }
        }
예제 #21
0
        public void Convert_Units_From_Object_To_Null_Converts_To_Callee_Unit()
        {
            cUnit unitFrom = new cUnit(eUnitType.Force);

            unitFrom.SetUnitName("kN");

            cUnit unitTo = new cUnit(eUnitType.Force);

            unitTo.SetUnitName("kip");

            double result = unitTo.Convert(unitFrom, null);

            Assert.That(result, Is.EqualTo(0.2248).Within(0.0001));
        }
예제 #22
0
        public void Convert_Units_As_Objects_Converts_Units()
        {
            cUnit unitFrom = new cUnit(eUnitType.Force);

            unitFrom.SetUnitName("kN");

            cUnit unitTo = new cUnit(eUnitType.Force);

            unitTo.SetUnitName("kip");

            double result = unitTo.Convert(unitFrom, unitTo);

            Assert.That(result, Is.EqualTo(0.2248).Within(0.0001));
        }
예제 #23
0
        public void Convert_Units_As_Incompatible_Objects_Returns_Zero()
        {
            cUnit unitFrom = new cUnit(eUnitType.Force);

            unitFrom.SetUnitName("kN");

            cUnit unitTo = new cUnit(eUnitType.Length);

            unitTo.SetUnitName("ft");

            double result = unitTo.Convert(unitFrom, unitTo);

            Assert.That(result, Is.EqualTo(0));
        }
예제 #24
0
        public void Convert_Units_From_Null_Object_Returns_Zero()
        {
            cUnit unitFrom = new cUnit(eUnitType.Force);

            unitFrom.SetUnitName("kN");

            cUnit unitTo = new cUnit(eUnitType.Force);

            unitTo.SetUnitName("kip");

            double result = unitTo.Convert(null, unitTo);

            Assert.That(result, Is.EqualTo(0));
        }
        public void Units_Is_Immutable()
        {
            cUnitsController unitsController = new cUnitsController();

            Assert.That(unitsController.Units, Is.EqualTo(new cUnits()));

            cUnit illegalUnit = new cUnit(eUnitType.Force);

            illegalUnit.SetUnitName("lb");

            cUnits immutableUnits = unitsController.Units;

            immutableUnits.AddUnit(illegalUnit);

            Assert.IsTrue(unitsController.Units.Equals(new cUnits()));
        }
예제 #26
0
        public void UnitsList_Is_Immutable()
        {
            cUnit unit = new cUnit();

            Assert.That(unit.Type, Is.EqualTo(eUnitType.None));
            Assert.That(unit.Name, Is.EqualTo(string.Empty));
            Assert.That(unit.UnitsList.Count, Is.EqualTo(0));

            unit.Type = eUnitType.Force;
            Assert.That(unit.UnitsList.Count, Is.EqualTo(9));

            string invalidUnits = "invalid";

            unit.UnitsList.Add(invalidUnits);
            Assert.That(unit.UnitsList.Count, Is.EqualTo(9));
        }
예제 #27
0
        public void Equals_Compares_Objects_By_Properties()
        {
            eUnitType unitType    = eUnitType.Length;
            string    unitPower   = "2";
            bool      isNumerator = false;
            cUnit     unit1       = new cUnit(unitType, unitPower, isNumerator);

            Assert.That(unit1.Type, Is.EqualTo(unitType));
            Assert.That(unit1.Name, Is.EqualTo("in"));
            Assert.That(unit1.Power, Is.EqualTo(unitPower));
            Assert.That(unit1.Numerator, Is.EqualTo(isNumerator));
            Assert.That(unit1.UnitsList.Count, Is.EqualTo(10));
            Assert.That(unit1.UnitsList.Contains("ft"));

            cUnit unit2 = new cUnit(unitType, unitPower, isNumerator);

            Assert.That(unit2.Type, Is.EqualTo(unitType));
            Assert.That(unit2.Name, Is.EqualTo("in"));
            Assert.That(unit2.Power, Is.EqualTo(unitPower));
            Assert.That(unit2.Numerator, Is.EqualTo(isNumerator));
            Assert.That(unit2.UnitsList.Count, Is.EqualTo(10));
            Assert.That(unit2.UnitsList.Contains("ft"));

            // Method Under Test
            Assert.That(unit1.Equals(unit2));

            unit2.SetUnitPower("3");
            Assert.That(!unit1.Equals(unit2));

            unit2.SetUnitPower("2");
            Assert.That(unit1.Equals(unit2));

            unit2.Numerator = true;
            Assert.That(!unit1.Equals(unit2));

            unit2.Numerator = false;
            Assert.That(unit1.Equals(unit2));

            unit2.Type = eUnitType.Force;
            Assert.That(!unit1.Equals(unit2));

            unit2.Type = eUnitType.Length;
            Assert.That(unit1.Equals(unit2));


            Assert.That(!unit1.Equals(null));
        }
예제 #28
0
        private void InitcboUnit()
        {
            cUnit     oUnit = new cUnit();
            string    strMessage = string.Empty, strCriteria = string.Empty;
            string    strUnit_code     = cboUnit.SelectedValue;
            string    strDirector_code = cboDirector.SelectedValue;
            string    strYear          = cboYear.SelectedValue;
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();

            strCriteria  = " and unit.unit_year = '" + strYear + "'  and  unit.c_active='Y' ";
            strCriteria += " and unit.director_code = '" + strDirector_code + "' ";
            if (UnitLock == "Y")
            {
                strCriteria += " and substring(unit.unit_code,4,5) in (" + this.UnitCodeList + ") ";
            }

            if (this.BudgetType == "R")
            {
                strCriteria = strCriteria + " and unit.budget_type <> 'B' ";
            }
            else
            {
                strCriteria = strCriteria + " and unit.budget_type <> 'R' ";
            }
            if (oUnit.SP_SEL_UNIT(strCriteria, ref ds, ref strMessage))
            {
                dt = ds.Tables[0];
                cboUnit.Items.Clear();
                cboUnit.Items.Add(new ListItem("--- เลือกทั้งหมด ---", ""));
                int i;
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    cboUnit.Items.Add(new ListItem(dt.Rows[i]["unit_name"].ToString(), dt.Rows[i]["unit_code"].ToString()));
                }
                if (cboUnit.Items.FindByValue(strUnit_code) != null)
                {
                    cboUnit.SelectedIndex = -1;
                    cboUnit.Items.FindByValue(strUnit_code).Selected = true;
                }
            }
        }
예제 #29
0
        public eUnitType SetUnitTypeFromName_Sets_Type_From_Name_If_Matching(string name)
        {
            cUnit unit = new cUnit();

            Assert.That(unit.Type, Is.EqualTo(eUnitType.None));
            Assert.That(unit.Name, Is.EqualTo(string.Empty));

            unit.SetUnitName(name);
            string expectedName = name;

            if (string.IsNullOrWhiteSpace(expectedName))
            {
                expectedName = string.Empty;
            }
            else if (expectedName == "Inch")
            {
                expectedName = "in";
            }
            Assert.That(unit.Name, Is.EqualTo(expectedName));
            return(unit.SetUnitTypeFromName());
        }
예제 #30
0
        public void Initialization_With_Parameters_Sets_Properties_By_Parameters()
        {
            eUnitType unitTypeBasic = eUnitType.Force;
            cUnit     unitBasic     = new cUnit(unitTypeBasic);

            Assert.That(unitBasic.Type, Is.EqualTo(unitTypeBasic));
            Assert.That(unitBasic.Name, Is.EqualTo("lb"));
            Assert.That(unitBasic.Numerator, Is.EqualTo(true));
            Assert.That(unitBasic.UnitsList.Count, Is.EqualTo(9));

            eUnitType unitType    = eUnitType.Length;
            string    unitPower   = "2";
            bool      isNumerator = false;
            cUnit     unitFull    = new cUnit(unitType, unitPower, isNumerator);

            Assert.That(unitFull.Type, Is.EqualTo(unitType));
            Assert.That(unitFull.Name, Is.EqualTo("in"));
            Assert.That(unitFull.Power, Is.EqualTo(unitPower));
            Assert.That(unitFull.Numerator, Is.EqualTo(isNumerator));
            Assert.That(unitFull.UnitsList.Count, Is.EqualTo(10));
        }