Esempio n. 1
0
 // ----------------------------------------------------------------------------------------
 /// <!-- Visible -->
 /// <summary>
 ///      Sets the visible field of the control
 /// </summary>
 /// <param name="form">allows no-op if the control is not on the form</param>
 /// <param name="control"></param>
 /// <param name="visible"></param>
 public static void Visible(Form form, Control control, bool visible)
 {
     if (Scrape.Active(form, control))
     {
         control.Visible = visible;
     }
 }
Esempio n. 2
0
 public static void Dates(Form form, TextBox txtDateTime, TimeDate_old date, string format)
 {
     if (Scrape.Active(form, txtDateTime))
     {
         txtDateTime.Text = date.ToString(format);
     }
 }
Esempio n. 3
0
 // ----------------------------------------------------------------------------------------
 /// <!-- Enabled -->
 /// <summary>
 ///      Sets the Enabled field of a control
 /// </summary>
 /// <param name="form"></param>
 /// <param name="control"></param>
 /// <param name="enabled"></param>
 public static void Enabled(Form form, Control control, bool enabled)
 {
     if (Scrape.Active(form, control))
     {
         control.Enabled = enabled;
     }
 }
Esempio n. 4
0
 // ----------------------------------------------------------------------------------------
 /// <!-- Value -->
 /// <summary>
 ///      Given a form and a named control try to set the control's value
 /// </summary>
 /// <param name="form">allows no-op if the control is not on the form</param>
 /// <param name="control"></param>
 /// <param name="value"></param>
 public static void Value(Form form, Control control, string value)
 {
     if (Scrape.Active(form, control))
     {
         ComboBox drop = (ComboBox)control;
         Value(form, ref drop, value);
     }
 }
Esempio n. 5
0
 // ----------------------------------------------------------------------------------------
 /// <!-- SetByIndex -->
 /// <summary>
 ///      Set what you can based on index
 /// </summary>
 /// <remarks>
 ///      SelectedValue can not be set until after the ComboBox is displayed to the user
 /// </remarks>
 /// <param name="drop"></param>
 /// <param name="idx"></param>
 private static void SetByIndex(Form form, ComboBox drop, int idx)
 {
     if (Scrape.Active(form, drop) && idx >= 0)
     {
         drop.SelectedIndex = idx;
         try { drop.SelectedValue = ((ListItem)drop.Items[idx]).ID; } catch { }
         drop.Text = drop.Items[idx].ToString();
     }
 }
Esempio n. 6
0
 // ----------------------------------------------------------------------------------------
 /// <!-- Dropdown -->
 /// <summary>
 ///      Fills a combo box with a binding list
 /// </summary>
 /// <param name="form">allows no-op if the control is not on the form</param>
 /// <param name="control"></param>
 /// <param name="blist"></param>
 public static void Dropdown(Form form, Control control
                             , BindingList <ListItem> blist, string valueMember, string displayMember)
 {
     if (Scrape.Active(form, control))
     {
         ComboBox drop = (ComboBox)control;
         BindTo(form, drop, blist, valueMember, displayMember);
     }
 }
Esempio n. 7
0
 // ----------------------------------------------------------------------------------------
 /// <!-- Radio -->
 /// <summary>
 ///
 /// </summary>
 /// <param name="form">allows no-action if the control is not on the form</param>
 /// <param name="control"></param>
 /// <param name="value"></param>
 public static void Radio(Form form, Control control, bool value)
 {
     if (Scrape.Active(form, control))
     {
         if (control.GetType() == typeof(RadioButton))
         {
             RadioButton r = ((RadioButton)control);
             r.Checked = value;
         }
     }
 }
Esempio n. 8
0
 // ----------------------------------------------------------------------------------------
 /// <!-- Text -->
 /// <summary>
 ///      Sets the text field of a control
 /// </summary>
 public static void Text(Form form, ComboBox drop, string value)
 {
     if (Scrape.Active(form, drop))
     {
         string text = "";
         try { drop.SelectedValue = value; text = drop.Text; }
         catch { text = ""; }
         if (string.IsNullOrEmpty(text))
         {
             drop.Text = value;
         }
     }
 }
Esempio n. 9
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Dates -->
        /// <summary>
        ///      Sets the date field of a control
        /// </summary>
        /// <param name="form">allows no-op if the control is not on the form</param>
        /// <param name="control"></param>
        /// <param name="date"></param>
        public static void Dates(Form form, Control control, TimeDate_old date, TimeDate_old defaultDate, Label nullImage)
        {
            if (Scrape.Active(form, control))
            {
                Type type = control.GetType();
                switch (type.Name.ToString())
                {
                case "DateTimePicker": Dates(form, ((DateTimePicker)control), date, defaultDate, nullImage); break;

                default: control.Text = date.ToString(); break;
                }
            }
        }
Esempio n. 10
0
        // ----------------------------------------------------------------------------------------
        /// <!-- DataSource -->
        /// <summary>
        ///      Sets the datasource for a control
        /// </summary>
        /// <param name="form">allows no-op if the control is not on the form</param>
        /// <param name="control"></param>
        /// <param name="ds"></param>
        public static void DataSource(Form form, Control control, object dataSource)
        {
            if (Scrape.Active(form, control))
            {
                Type type = control.GetType();
                switch (type.Name.ToString())
                {
                case "ComboBox": ((ComboBox)control).DataSource = dataSource; break;

                default: break;
                }
            }
        }
Esempio n. 11
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Dates -->
        /// <summary>
        ///      Sets the date field of a control
        /// </summary>
        /// <param name="form">allows no-op if the control is not on the form</param>
        /// <param name="control"></param>
        /// <param name="date"></param>
        public static void Dates(Form form, Control control, TimeDate_old date)
        {
            if (Scrape.Active(form, control))
            {
                DateTime clrDate = TimeDate_old.ClrDate(date);
                Type     type    = control.GetType();
                switch (type.Name.ToString())
                {
                case "DateTimePicker": Dates(form, ((DateTimePicker)control), clrDate, new Label()); break;

                default: control.Text = date.ToString(); break;
                }
            }
        }
Esempio n. 12
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Text -->
        /// <summary>
        ///      Puts text values into controls on a form given the control
        /// </summary>
        /// <param name="form">allows no-op if the control is not on the form</param>
        /// <param name="control"></param>
        /// <param name="text"></param>
        public static void Text(Form form, Control control, string text)
        {
            if (Scrape.Active(form, control))
            {
                Type type = control.GetType();
                switch (type.Name.ToString())
                {
                case "ComboBox": ComboBox drop = (ComboBox)control; Value(form, ref drop, text); break;

                case "GroupBox": control.Text = text; break;     // radio buttons

                case "TextBox": control.Text = text; break;

                default:         control.Text = text; break;
                }
            }
        }
Esempio n. 13
0
        // ----------------------------------------------------------------------------------------
        /// <!-- FromTo -->
        /// <summary>
        ///      Adds the selected item from the source list if it is not already in the destination list
        /// </summary>
        /// <param name="form">allows no-action if the controls are not on the form</param>
        /// <param name="drop"></param>
        /// <param name="list"></param>
        public static void FromTo(Form form, ComboBox dropFrom, CheckedListBox listTo)
        {
            if (Scrape.Active(form, dropFrom) && Scrape.Active(form, listTo))
            {
                // ---------------------------------------------------------------------90
                //  Find the item in the 'From' list
                // ---------------------------------------------------------------------90
                int idxFrom = dropFrom.SelectedIndex;
                if (idxFrom >= 0)
                {
                    ListItem itemFrom = (ListItem)dropFrom.Items[idxFrom];


                    // -----------------------------------------------------------------90
                    //  Add the item to the 'To' list
                    // -----------------------------------------------------------------90
                    int idxTo = listTo.FindString(itemFrom.Display);
                    if (idxTo < 0)
                    {
                        idxTo = listTo.FindString(itemFrom.Descr);
                    }
                    if (idxTo < 0)
                    {
                        string codeFrom = itemFrom.Code;
                        for (int i = 0; i < listTo.Items.Count; ++i)
                        {
                            ListItem item = (ListItem)listTo.Items[i];
                            if (codeFrom == item.Code)
                            {
                                idxTo = i;
                            }
                        }
                    }
                    if (idxTo < 0)
                    {
                        string   idFrom  = dropFrom.SelectedValue.ToString();
                        string   code    = itemFrom.Code;
                        string   descr   = itemFrom.Descr;
                        string   display = itemFrom.Display;
                        string   idTo    = (listTo.Items.Count + 1).ToString();
                        ListItem itemTo  = new ListItem(idTo, code, descr, display);
                        listTo.Items.Add(itemTo, true);
                    }
                }
            }
        }
Esempio n. 14
0
 // ----------------------------------------------------------------------------------------
 /// <!-- Toggle -->
 /// <summary>
 ///      Toggles the particular checked item specified
 /// </summary>
 /// <param name="clb"></param>
 /// <param name="idx"></param>
 public static void Toggle(Form form, CheckedListBox clb, int idx)
 {
     if (Scrape.Active(form, clb))
     {
         //if (_.InRange(-1, idx, clb.Items.Count))
         if (-1 < idx && idx <= clb.Items.Count)
         {
             if (clb.GetItemCheckState(idx) == CheckState.Checked)
             {
                 clb.SetItemCheckState(idx, CheckState.Unchecked);
             }
             else
             {
                 clb.SetItemCheckState(idx, CheckState.Checked);
             }
         }
         else
         {
             Pause();
         }
     }
 }
Esempio n. 15
0
        //public static void DataSource(Form form, string controlName, object dataSource) { DataSource(form, Scrape.Control(form, controlName), dataSource); }


        // ----------------------------------------------------------------------------------------
        /// <!-- Date -->
        /// <summary>
        ///      Sets the date time picker date, defaulting to Now
        /// </summary>
        /// <param name="pick"></param>
        /// <param name="date"></param>
        public static void Dates(Form form, DateTimePicker pick, TimeDate_old date, TimeDate_old defaultDate, Label nullImage)
        {
            if (Scrape.Active(form, pick))
            {
                pick.Visible      = true;
                nullImage.Visible = false;
                if (date.IsNull || date.CLRFormat < pick.MinDate || date.CLRFormat > pick.MaxDate)
                {
                    if (defaultDate.IsNull)
                    {
                        nullImage.Visible = true; // this is broken
                    }
                    else
                    {
                        pick.Value = defaultDate.CLRFormat;
                    }
                }
                else
                {
                    pick.Value = Scrape.ValidPickerDate(date.CLRFormat);
                }
            }
        }
Esempio n. 16
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;
                        }
                    }
                }
            }
        }