예제 #1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- IntValue -->
        /// <summary>
        ///      returns an integer or the default if it can not parse one
        /// </summary>
        /// <param name="xPath"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public int IntValue(string xPath, int defaultValue)
        {
            string str = StrValue(xPath, "");
            int    num = TreatAs.IntValue(str, defaultValue);

            return(num);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- FindDsmCodesLike -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="all"></param>
        /// <returns></returns>
        private static RichDataTable FindDsmCodesLike(string keyword, RichDataTable all)
        {
            int id = TreatAs.IntValue(keyword, 0);

            string whereClause = "    ConditionName    LIKE '%" + keyword + "%'"
                                 + " OR ConditionCode4TR LIKE  '" + keyword + "%'"
                                 + " OR ConditionCode5   LIKE  '" + keyword + "%'"
            ;

            return(all._Select(whereClause));
        }
예제 #3
0
        private static void TreatAs_IntValue_testcase(object obj, int defaultValue, int target)
        {
            int value = TreatAs.IntValue(obj, defaultValue);

            Assert.That(value, Is.equal_to, target);
        }
예제 #4
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Value -->
        /// <summary>
        ///      Given a combo box and a value select the item in the drop list that matches if any
        /// </summary>
        /// <remarks>
        ///      This gets complicated because SelectedValue can not be set or retrieved until after
        ///      the ComboBox is displayed to the user
        /// </remarks>
        /// <param name="form">allows no-op if the control is not on the form</param>
        /// <param name="drop"></param>
        /// <param name="value"></param>
        public static void Value(Form form, ref ComboBox drop, object value)
        {
            if (Scrape.Active(form, drop))
            {
                if (Is.Null(value))
                {
                    drop.Text = "";
                }
                else
                {
                    string str = TreatAs.StrValue(value, "");


                    int oldIndex = drop.SelectedIndex;
                    drop.SelectedIndex = -1;
                    string oldText = drop.Text;
                    drop.Text = "";


                    // ---------------------------------------------------------------------90
                    //  Try to select by value (this should work under optimal conditions)
                    // ---------------------------------------------------------------------90
                    try { drop.SelectedValue = value; }
                    catch { }
                    if (drop.SelectedValue == null || drop.SelectedValue.ToString() == "")
                    {
                        try { drop.SelectedValue = (object)str; }
                        catch { }
                    }
                    if (drop.SelectedValue == null || drop.SelectedValue.ToString() == "")
                    {
                        try { drop.SelectedValue = TreatAs.IntValue(value, -1); }
                        catch { }
                    }


                    // ---------------------------------------------------------------------90
                    //  Try to select item by value, by item and by a sequential search
                    // ---------------------------------------------------------------------90
                    if (drop.SelectedIndex < 0)
                    {
                        SetByIndex(form, drop, drop.Items.IndexOf(value));
                    }
                    if (drop.SelectedIndex < 0)
                    {
                        try { drop.SelectedItem = value; }
                        catch { }
                    }
                    if (drop.SelectedIndex < 0)
                    {
                        try { drop.SelectedItem = (object)str; }
                        catch { }
                    }
                    if (drop.SelectedIndex < 0)
                    {
                        SetByIndex(form, drop, Scrape.FindIndexOf(form, drop, value));
                    }


                    // ---------------------------------------------------------------------90
                    //  Give up and just set the text to the value
                    // ---------------------------------------------------------------------90
                    if (drop.SelectedIndex < 0)
                    {
                        SetByIndex(form, drop, drop.FindStringExact(str));
                    }
                    if (drop.SelectedIndex < 0 && str.Length > 6)
                    {
                        SetByIndex(form, drop, drop.FindString(str));
                    }
                    if (drop.SelectedIndex < 0)
                    {
                        if (drop.SelectedText == null || drop.SelectedText == "")
                        {
                            try { drop.SelectedText = str; }
                            catch { }
                        }
                        if (drop.Text == null || drop.Text == "")
                        {
                            drop.Text = str;
                        }
                    }
                }
            }
        }
예제 #5
0
 // ----------------------------------------------------------------------------------------
 /// <!-- XdY -->
 /// <summary>
 ///
 /// </summary>
 /// <param name="xdy"></param>
 /// <returns></returns>
 /// <remarks>production ready</remarks>
 public static int XdY(string xdy)
 {
     string[] hi = xdy.Split("d".ToCharArray());
     return(XdY(TreatAs.IntValue(hi[0], 1), TreatAs.IntValue(hi[1], 1)));
 }