void ButtonSave_Click(object sender, RoutedEventArgs e)
 {
     #if SILVERLIGHT
     Storyboard sb = new Storyboard();
     sb = Application.Current.Resources["ButtonPressAnimation"] as Storyboard;
     sb.Completed += new EventHandler(delegate(object obj, EventArgs es) { sb.Stop(); });
     Storyboard.SetTarget(sb, ButtonSaveTransform);
     sb.Begin();
     #endif
     if (IsValid())
     {
         OtherDevice otherDevice = new OtherDevice();
         otherDevice.Acronym = TextBoxAcronym.Text.CleanText();
         otherDevice.Name = TextBoxName.Text.CleanText();
         otherDevice.IsConcentrator = (bool)CheckboxConcentrator.IsChecked;
         otherDevice.CompanyID = ((KeyValuePair<int, string>)ComboboxCompany.SelectedItem).Key == 0 ? (int?)null : ((KeyValuePair<int, string>)ComboboxCompany.SelectedItem).Key;
         otherDevice.VendorDeviceID = ((KeyValuePair<int, string>)ComboboxVendorDevice.SelectedItem).Key == 0 ? (int?)null : ((KeyValuePair<int, string>)ComboboxVendorDevice.SelectedItem).Key;
         otherDevice.Longitude = TextBoxLongitude.Text.ToNullableDecimal();
         otherDevice.Latitude = TextBoxLatitude.Text.ToNullableDecimal();
         otherDevice.InterconnectionID = ((KeyValuePair<int, string>)ComboboxInterconnection.SelectedItem).Key == 0 ? (int?)null : ((KeyValuePair<int, string>)ComboboxInterconnection.SelectedItem).Key;
         otherDevice.Planned = (bool)CheckboxPlanned.IsChecked;
         otherDevice.Desired = (bool)CheckboxDesired.IsChecked;
         otherDevice.InProgress = (bool)CheckboxInProgress.IsChecked;
         if (m_inEditMode == false && m_deviceID == 0)
             SaveOtherDevice(otherDevice, true);
         else
         {
             otherDevice.ID = m_deviceID;
             SaveOtherDevice(otherDevice, false);
         }
     }
 }
 public void GetOtherDeviceByDeviceID(int deviceID)
 {
     try
     {
         OtherDevice deviceToEdit = new OtherDevice();
         deviceToEdit = CommonFunctions.GetOtherDeviceByDeviceID(null, deviceID);
         GridOtherDeviceDetail.DataContext = deviceToEdit;
         if (deviceToEdit.CompanyID.HasValue)
             ComboboxCompany.SelectedItem = new KeyValuePair<int, string>((int)deviceToEdit.CompanyID, deviceToEdit.CompanyName);
         else
             ComboboxCompany.SelectedIndex = 0;
         if (deviceToEdit.InterconnectionID.HasValue)
             ComboboxInterconnection.SelectedItem = new KeyValuePair<int, string>((int)deviceToEdit.InterconnectionID, deviceToEdit.InterconnectionName);
         else
             ComboboxInterconnection.SelectedIndex = 0;
         if (deviceToEdit.VendorDeviceID.HasValue)
             ComboboxVendorDevice.SelectedItem = new KeyValuePair<int, string>((int)deviceToEdit.VendorDeviceID, deviceToEdit.VendorDeviceName);
         else
             ComboboxVendorDevice.SelectedIndex = 0;
     }
     catch (Exception ex)
     {
         CommonFunctions.LogException(null, "WPF.GetOtherDeviceByDeviceID", ex);
         SystemMessages sm = new SystemMessages(new Message() { UserMessage = "Failed to Retrieve Other Device Information by ID", SystemMessage = ex.Message, UserMessageType = MessageType.Error },
                 ButtonType.OkOnly);
         sm.Owner = Window.GetWindow(this);
         sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
         sm.ShowPopup();
     }
 }
 public void SaveOtherDevice(OtherDevice otherDevice, bool isNew)
 {
     SystemMessages sm;
     try
     {
         string result = CommonFunctions.SaveOtherDevice(null, otherDevice, isNew);
         ClearForm();
         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();
         OtherDevicesUserControl otherDevicesUserControl = new OtherDevicesUserControl();
         ((MasterLayoutWindow)Window.GetWindow(this)).ContentFrame.Navigate(otherDevicesUserControl);
     }
     catch (Exception ex)
     {
         CommonFunctions.LogException(null, "WPF.SaveOtherDevice", ex);
         sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Other Device Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error },
                 ButtonType.OkOnly);
         sm.Owner = Window.GetWindow(this);
         sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
         sm.ShowPopup();
     }
 }
Example #4
0
        public static string SaveOtherDevice(DataConnection connection, OtherDevice otherDevice, 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 OtherDevice (Acronym, Name, IsConcentrator, CompanyID, VendorDeviceID, Longitude, Latitude, InterconnectionID, Planned, Desired, InProgress, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) Values " +
                        "(@acronym, @name, @isConcentrator, @companyID, @vendorDeviceID, @longitude, @latitude, @interconnectionID, @planned, @desired, @inProgress, @updatedBy, @updatedOn, @createdBy, @createdOn)";
                else
                    command.CommandText = "Update OtherDevice Set Acronym = @acronym, Name = @name, IsConcentrator = @isConcentrator, CompanyID = @companyID, VendorDeviceID = @vendorDeviceID, Longitude = @longitude, " +
                        "Latitude = @latitude, InterconnectionID = @interconnectionID, Planned = @planned, Desired = @desired, InProgress = @inProgress, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn Where ID = @id";

                command.Parameters.Add(AddWithValue(command, "@acronym", otherDevice.Acronym.Replace(" ", "").ToUpper()));
                command.Parameters.Add(AddWithValue(command, "@name", otherDevice.Name));
                command.Parameters.Add(AddWithValue(command, "@isConcentrator", otherDevice.IsConcentrator));
                command.Parameters.Add(AddWithValue(command, "@companyID", otherDevice.CompanyID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@vendorDeviceID", otherDevice.VendorDeviceID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@longitude", otherDevice.Longitude ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@latitude", otherDevice.Latitude ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@interconnectionID", otherDevice.InterconnectionID ?? (object)DBNull.Value));
                command.Parameters.Add(AddWithValue(command, "@planned", otherDevice.Planned));
                command.Parameters.Add(AddWithValue(command, "@desired", otherDevice.Desired));
                command.Parameters.Add(AddWithValue(command, "@inProgress", otherDevice.InProgress));
                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", otherDevice.ID));

                command.ExecuteScalar();
                return "Other Device Information Saved Successfully";
            }
            finally
            {
                if (createdConnection && connection != null)
                    connection.Dispose();
            }
        }