Exemplo n.º 1
0
 public bool Update(VI_Data data)
 {
     if (DB.ContainsKey(data.name))
     {
         DB[data.name] = data;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
 public bool Insert(VI_Data data)
 {
     if (!DB.ContainsKey(data.name))
     {
         DB.Add(data.name, data);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 3
0
 public bool Remove(VI_Data data)
 {
     if (DB.ContainsKey(data.name))
     {
         DB.Remove(data.name);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 // Delete DataItem
 private void deleteToolStripMenuItem3_Click(object sender, EventArgs e)
 {
     if (dgDatabase.MultiSelect == true)
     {
         throw new NotImplementedException("Editing mutliple data items at once is unsupported.");
     }
     foreach (DataGridViewRow row in this.dgDatabase.SelectedRows)
     {
         VI_Data selected_data = row.DataBoundItem as VI_Data;
         if (selected_data != null)
         {
             GAVPI.vi_profile.ProfileDB.Remove(selected_data);
             ProfileEdited();
             refresh_dgDatabase();
         }
     }
 }
Exemplo n.º 5
0
 // Edit DataItem
 private void editToolStripMenuItem2_Click(object sender, EventArgs e)
 {
     if (dgDatabase.MultiSelect == true)
     {
         throw new NotImplementedException("Editing mutliple data items at once is unsupported.");
     }
     foreach (DataGridViewRow row in this.dgDatabase.SelectedRows)
     {
         VI_Data selected_data = row.DataBoundItem as VI_Data;
         if (selected_data != null)
         {
             frm_AddEdit_Data newData = new frm_AddEdit_Data(selected_data);
             if (newData.ShowDialog() == DialogResult.OK)
             {
                 ProfileEdited();
                 refresh_dgDatabase();
             }  //  if()
         }
     }
 }
Exemplo n.º 6
0
 public Data_Increment(VI_Data data, string value)
     : base(value)
 {
     this.value = value;
 }
Exemplo n.º 7
0
        public bool Update(VI_Data data)
        {
            if (DB.ContainsKey(data.name)) 
            {
                DB[data.name] = data;
                return true;
            }
            else
            { 
                return false; 
            }

        }
Exemplo n.º 8
0
 public frm_AddEdit_Data(VI_Data data_item)
 {
     InitializeComponent();
     this.data_to_edit = data_item;
     populate_fields();
 }
Exemplo n.º 9
0
 public Data_Set(VI_Data data, string value)
     : base(value)
 {
     this.value = value;
 }
Exemplo n.º 10
0
 public Data_Increment(VI_Data data, string value)
     : base(value)
 {
     this.value = value;
 }
Exemplo n.º 11
0
 public Data_Speak(SpeechSynthesizer Profile_Synthesis, VI_Data data)
 {
     this.Profile_Synthesis = Profile_Synthesis;
     this.data  = data;
     this.value = data.value.ToString();
 }
Exemplo n.º 12
0
 public Data_Set(VI_Data data, string value)
     : base(value)
 {
 }
Exemplo n.º 13
0
 public Data_Increment(VI_Data data, string value)
     : base(value)
 {
 }
Exemplo n.º 14
0
 public frm_AddEdit_Data(VI_Data data_item)
 {
     InitializeComponent();
     this.data_to_edit = data_item;
     populate_fields();
 }
Exemplo n.º 15
0
 public bool Insert(VI_Data data)
 {
     if (!DB.ContainsKey(data.name)){
         DB.Add(data.name,data);
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 16
0
 public Data_Set(VI_Data data, string value)
     : base(value)
 {
     this.value = value;
 }
Exemplo n.º 17
0
 public Data_Speak(SpeechSynthesizer Profile_Synthesis, VI_Data data)
 {
     this.Profile_Synthesis = Profile_Synthesis;
     this.data  = data;
 }
Exemplo n.º 18
0
 public Data_Speak(SpeechSynthesizer Profile_Synthesis, VI_Data data)
 {
     this.Profile_Synthesis = Profile_Synthesis;
     this.data = data;
 }
Exemplo n.º 19
0
        private void btnTriggerOk_Click(object sender, EventArgs e)
        {
            string data_name    = txtDataName.Text.Trim();
            string data_type    = "GAVPI." + cbDataType.SelectedItem.ToString();
            string data_value   = txtDataValue.Text.Trim();
            string data_comment = txtDataComment.Text.Trim();

            // Basic Validation
            if ((data_name.Length == 0) ||
                (data_value.Length == 0) ||
                (data_type.Length == 0))
            {
                MessageBox.Show("Data name, type or value cannot be blank.");
                return;
            }


            // Case 1: New Data Item
            if (data_to_edit == null)
            {
                // Check if data with this name already exists
                if (GAVPI.vi_profile.ProfileDB.isDataNameTaken(data_name))
                {
                    MessageBox.Show("A data item with this name already exisits.");
                    return;
                }
                else
                {
                    /*
                     * VI_Data.validate returns true if it is possible to call ?.Parse on the data value
                     * We then use reflection to dynamically call the appropriate cast method of VI_Data
                     * and return the proper object type.
                     *
                     */

                    /*
                     *  I leave the try catch redudantly, I think I have all execution branches
                     *  covered so that it is not needed, however it is probably good practice
                     *  to sandwhich all calls to VI_Data initialization in try catch
                     *  this is because ToObject will call (?).Parse
                     */
                    try
                    {
                        if (VI_Data.validate(data_type, data_value))
                        {
                            // ex: GAVPI.VI_INT
                            Type new_data_type = Type.GetType(data_type);

                            // (ToObject) is static method which will cast a string value to
                            // the appropriate value type.
                            MethodInfo method = new_data_type.GetMethod("ToObject");

                            // invokes the static method, cast_data_value will match value of VI_Data, ex: VI_INT.value is an int
                            object cast_data_value = method.Invoke(null, new string[] { data_value });

                            object data_instance = Activator.CreateInstance(new_data_type, data_name, cast_data_value, data_comment);

                            GAVPI.vi_profile.ProfileDB.Insert((VI_Data)data_instance);
                        }
                        else
                        {
                            invalid_data_value_msg(data_value);
                            return;
                        }
                    }
                    catch
                    {
                        invalid_data_value_msg(data_value);
                        return;
                    }
                }
            }
            // Case 2: Existing item (edit mode)
            else
            {
                data_to_edit.type    = cbDataType.SelectedItem.ToString();
                data_to_edit.comment = data_comment;

                // Now cast, this is necessary if the type has changed.
                try
                {
                    Type new_data_type = Type.GetType(data_type);

                    if (VI_Data.validate(data_type, data_value))
                    {
                        // ex: GAVPI.VI_INT
                        Type thisType = Type.GetType(data_type);

                        // (ToObject) is static method which will cast a string value to
                        // the appropriate value type.
                        MethodInfo method = thisType.GetMethod("ToObject");

                        // invokes the static method, cast_data_value will match value of VI_Data, ex: VI_INT.value is an int
                        object cast_data_value = method.Invoke(null, new string[] { data_value });

                        data_to_edit.value = cast_data_value;

                        //object data_instance = Activator.CreateInstance(new_data_type, data_name, cast_data_value, data_comment);
                        //GAVPI.vi_profile.ProfileDB.Insert((VI_Data)data_instance);
                    }
                    else
                    {
                        invalid_data_value_msg(data_value);
                        return;
                    }
                }
                catch
                {
                    invalid_data_value_msg(data_value);
                    return;
                }
                // end-cast


                if (data_to_edit.name == data_name)
                {
                    // The current data element name is unchanged.
                    GAVPI.vi_profile.ProfileDB.DB[data_name] = data_to_edit;
                }
                else
                {
                    // The name has been changed, check if the name is taken.
                    if (GAVPI.vi_profile.ProfileDB.isDataNameTaken(data_name))
                    {
                        // Name is taken.
                        MessageBox.Show("A data element with this name already exists.");
                        return;
                    }
                    else
                    {
                        // There is no way to edit the key, remove the old entry and make a new one.

                        // BUG : Action.value will not be updated automatically here
                        GAVPI.vi_profile.ProfileDB.DB.Remove(data_name);
                        data_to_edit.name = data_name;
                        GAVPI.vi_profile.ProfileDB.Insert(data_to_edit);
                    }
                }
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 20
0
 public bool Remove(VI_Data data)
 {
     if (DB.ContainsKey(data.name))
     {
         DB.Remove(data.name);
         return true;
     }
     else
     {
         return false;
     }
 }