private void btnSave_Click(object sender, EventArgs e) { scene_commands scmd; using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString)) { if (editing) scmd = db.scene_commands.FirstOrDefault(c => c.id == scenecmd_id_to_edit.Value); else { scmd = new scene_commands(); scmd.device_id = device_id; scmd.scene_id = scene_id.Value; scmd.sort_order = positionInList; } //Update the command type, command id, and arg if (radioBtnTypeCommand.Checked) { device_type_commands selected_cmd = (device_type_commands)comboBoxCommands.SelectedItem; if (selected_cmd == null) { MessageBox.Show("Please select a command!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } scmd.command_id = selected_cmd.id; scmd.command_type_id = (int)command_types.device_type_command; string userInput = GetUserInput((Data_Types)selected_cmd.arg_data_type); if (userInput == null) return; else scmd.arg = userInput; } else { device_commands selected_cmd = (device_commands)comboBoxCommands.SelectedItem; if (selected_cmd == null) { MessageBox.Show("Please select a command!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } scmd.command_id = selected_cmd.id; scmd.command_type_id = (int)command_types.device_command; string userInput = GetUserInput((Data_Types)selected_cmd.arg_data_type); if (userInput == null) return; else scmd.arg = userInput; } if (!editing) db.scene_commands.AddObject(scmd); db.SaveChanges(); } zvsEntityControl.CallSceneModified(this, null); this.Close(); }
/// <summary> /// Deprecated Method for adding a new object to the scene_commands EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToscene_commands(scene_commands scene_commands) { base.AddObject("scene_commands", scene_commands); }
private void btnSave_Click(object sender, EventArgs e) { builtin_commands selected_cmd = (builtin_commands)comboBoxCommand.SelectedItem; scene_commands scmd; using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString)) { if (editing) scmd = db.scene_commands.FirstOrDefault(c => c.id == scenecmd_id_to_edit.Value); else { scmd = new scene_commands(); scmd.scene_id = selected_scene_id.Value; } scmd.command_type_id = (int)command_types.builtin; scmd.command_id = selected_cmd.id; //Do Custom things for some Builtin Commands switch (selected_cmd.name) { case "REPOLL_ME": { device d = (device)cmbo.SelectedItem; if (d == null) { MessageBox.Show("Please select a deice!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else scmd.arg = d.id.ToString(); break; } case "GROUP_ON": case "GROUP_OFF": { group g = (group)cmbo.SelectedItem; if (g == null) { MessageBox.Show("Please select a group!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else scmd.arg = g.id.ToString(); break; } default: switch ((Data_Types)selected_cmd.arg_data_type) { case Data_Types.NONE: scmd.arg = string.Empty; break; case Data_Types.BOOL: scmd.arg = cb.Checked.ToString(); break; case Data_Types.LIST: if (String.IsNullOrEmpty(cmbo.Text)) { MessageBox.Show("Please select a vaule!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } scmd.arg = cmbo.Text; break; case Data_Types.STRING: if (String.IsNullOrEmpty(tbx.Text)) { MessageBox.Show("Please enter a vaule!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } scmd.arg = tbx.Text; break; case Data_Types.BYTE: case Data_Types.DECIMAL: case Data_Types.INTEGER: case Data_Types.SHORT: scmd.arg = Numeric.Value.ToString(); break; } break; } if (!editing) db.scene_commands.AddObject(scmd); db.SaveChanges(); } zvsEntityControl.CallSceneModified(this, null); this.Close(); }
/// <summary> /// Create a new scene_commands object. /// </summary> /// <param name="id">Initial value of the id property.</param> /// <param name="scene_id">Initial value of the scene_id property.</param> /// <param name="command_type_id">Initial value of the command_type_id property.</param> /// <param name="command_id">Initial value of the command_id property.</param> /// <param name="arg">Initial value of the arg property.</param> public static scene_commands Createscene_commands(global::System.Int64 id, global::System.Int64 scene_id, global::System.Int64 command_type_id, global::System.Int64 command_id, global::System.String arg) { scene_commands scene_commands = new scene_commands(); scene_commands.id = id; scene_commands.scene_id = scene_id; scene_commands.command_type_id = command_type_id; scene_commands.command_id = command_id; scene_commands.arg = arg; return scene_commands; }