void SaveVendorDevice(VendorDevice vendorDevice, bool isNew) { SystemMessages sm; try { string result = CommonFunctions.SaveVendorDevice(null, vendorDevice, isNew); sm = new SystemMessages(new Message() { UserMessage = result, SystemMessage = string.Empty, UserMessageType = MessageType.Success }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.WindowStartupLocation = WindowStartupLocation.CenterOwner; sm.ShowPopup(); GetVendorDevices(); //ClearForm(); //make this newly added or updated item as default selected. So user can click initialize right away. ListBoxVendorDeviceList.SelectedItem = ((List<VendorDevice>)ListBoxVendorDeviceList.ItemsSource).Find(c => c.Name == vendorDevice.Name); } catch (Exception ex) { CommonFunctions.LogException(null, "WPF.SaveVendorDevice", ex); sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Vendor Device Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.WindowStartupLocation = WindowStartupLocation.CenterOwner; sm.ShowPopup(); } }
public static string SaveVendorDevice(DataConnection connection, VendorDevice vendorDevice, bool isNew) { bool createdConnection = false; try { if (connection == null) { connection = new DataConnection(); createdConnection = true; } IDbCommand command = connection.Connection.CreateCommand(); command.CommandType = CommandType.Text; if (isNew) command.CommandText = "Insert Into VendorDevice (VendorID, Name, Description, URL, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) Values (@vendorID, @name, @description, @url, @updatedBy, @updatedOn, @createdBy, @createdOn)"; else command.CommandText = "Update VendorDevice Set VendorID = @vendorID, Name = @name, Description = @description, URL = @url, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn Where ID = @id"; command.Parameters.Add(AddWithValue(command, "@vendorID", vendorDevice.VendorID)); command.Parameters.Add(AddWithValue(command, "@name", vendorDevice.Name)); command.Parameters.Add(AddWithValue(command, "@description", vendorDevice.Description)); command.Parameters.Add(AddWithValue(command, "@url", vendorDevice.URL)); command.Parameters.Add(AddWithValue(command, "@updatedBy", s_currentUser)); command.Parameters.Add(AddWithValue(command, "@updatedOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow)); if (isNew) { command.Parameters.Add(AddWithValue(command, "@createdBy", s_currentUser)); command.Parameters.Add(AddWithValue(command, "@createdOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow)); } else command.Parameters.Add(AddWithValue(command, "@id", vendorDevice.ID)); command.ExecuteNonQuery(); return "Vendor Device Information Saved Successfully"; } finally { if (createdConnection && connection != null) connection.Dispose(); } }