private void buttonUpdateDatabase_Click(object sender, RoutedEventArgs e) { try { if (this.dropDownApplications.SelectedItem == null) { throw new Exception("No application was selected!"); } var name = this.textboxName.Text; var bitIndex = (byte)this.sliderBitIndex.Value; var path = this.textboxPath.Text; if (string.IsNullOrEmpty(name)) { throw new Exception("No name has been given"); } if (path.Length > this._maxPathLength) { throw new Exception($"The output path is too large, it has ${path.Length} characters while the limit is ${this._maxPathLength} characters"); } if (!Directory.Exists(path)) { throw new Exception("The output path does not exist"); } using (var db = new DatabaseCon()) { if (this.dropDownApplications.SelectedItem.ToString() == NEW_ITEM_TEXT) { db.enforceNameIsUnique <application>(name); db.enforceBitIndexIsUnique <application>(bitIndex); this._addApplication(db, name, bitIndex, path); } else { var cached = this._applications.Single(a => a.description == this.dropDownApplications.SelectedItem.ToString()); if (name != cached.description) { db.enforceNameIsUnique <application>(name); } if (bitIndex != cached.bit_index) { db.enforceBitIndexIsUnique <application>(bitIndex); } this._updateApplication(db, name, bitIndex, path); } } } catch (Exception ex) { this._window.updateStatus($"[ERROR] {ex.ToString()}"); } }
private void buttonUpdateDatabase_Click(object sender, RoutedEventArgs e) { try { if (this.dropDownDevices.SelectedItem == null) { throw new Exception("No device was selected!"); } var name = this.textboxName.Text; var bitIndex = (byte)this.sliderBitIndex.Value; if (string.IsNullOrEmpty(name)) { throw new Exception("No name has been given"); } using (var db = new DatabaseCon()) { if (this.dropDownDevices.SelectedItem.ToString() == NEW_ITEM_TEXT) { db.enforceNameIsUnique <device_type>(name); db.enforceBitIndexIsUnique <device_type>(bitIndex); this._addDevice(db, name, bitIndex); } else { var cached = this._devices.Single(d => d.description == this.dropDownDevices.SelectedItem.ToString()); if (name != cached.description) { db.enforceNameIsUnique <device_type>(name); } if (bitIndex != cached.bit_index) { db.enforceBitIndexIsUnique <device_type>(bitIndex); } this._updateDevice(db, name, bitIndex); } } } catch (Exception ex) { this._window.updateStatus($"[ERROR] {ex.ToString()}"); } }