Exemple #1
0
        private void Btn_EditService_Click(object sender, RoutedEventArgs e)
        {
            int selectedIndex;
            VetServiceDBInfo selectedItem = null;

            // Get the index from the UI
            selectedIndex = ListBox_ServiceDetails.SelectedIndex;

            if (selectedIndex >= 0 && selectedIndex < Veteran.ServiceDetails.Count)
            {
                selectedItem = Veteran.ServiceDetails[selectedIndex];

                ServiceDetails serviceWin = new ServiceDetails(selectedItem);

                serviceWin.ShowDialog();

                Veteran.ServiceDetails[selectedIndex] = serviceWin.ServiceInfo;

                ListBox_ServiceDetails.Items.Refresh();
            }
            else
            {
                MessageBox.Show(Tools.RecordSelectMessage, Tools.RecordSelectTitle);
            }
        }
Exemple #2
0
        private void Btn_DeleteService_Click(object sender, RoutedEventArgs e)
        {
            int selectedIndex;
            VetServiceDBInfo removeItem = null;

            // Get the index from the UI
            selectedIndex = ListBox_ServiceDetails.SelectedIndex;

            if (selectedIndex >= 0 && selectedIndex < Veteran.ServiceDetails.Count)
            {
                MessageBoxResult result;
                result = MessageBox.Show(Tools.deleteMessage, Tools.deleteTitle, MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    // Get the index from the UI
                    selectedIndex = ListBox_ServiceDetails.SelectedIndex;

                    removeItem = Veteran.ServiceDetails[selectedIndex];

                    // Remove from the database
                    removeItem.DeleteFromDatabase();

                    // Remove from the list
                    Veteran.ServiceDetails.Remove(removeItem);

                    ListBox_ServiceDetails.Items.Refresh();
                }
            }
            else
            {
                MessageBox.Show(Tools.RecordDeleteMessage, Tools.RecordSelectTitle);
            }
        }
Exemple #3
0
 // Copy Constructor
 public VetServiceDBInfo(VetServiceDBInfo other)
 {
     hasDataChanged = other.hasDataChanged;
     id             = other.id;
     sNum           = other.sNum;
     branch         = other.branch;
     rank           = other.rank;
     unitShip       = other.unitShip;
 }
        // Default Constructor
        public ServiceDetails()
        {
            InitializeComponent();

            ServiceInfo = new VetServiceDBInfo();

            IsOk = false;
            dataPreviouslyChanged = Tools.hasDataChanged;

            DataContext = this;

            BranchList = BranchDBInfo.LoadStringList();
            Ranks      = new ObservableCollection <string>();
        }
        // Loads the service details into a list
        private List <VetServiceDBInfo> LoadServiceDetails()
        {
            List <VetServiceDBInfo> records = new List <VetServiceDBInfo>();
            int serviceIdNum;

            try
            {
                using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString))
                {
                    conn.OpenAsync();

                    using (MySqlCommand command = conn.CreateCommand())
                    {
                        command.CommandText = "SELECT SNum FROM Services WHERE ID=@idNum;";
                        command.Parameters.Add("@idNum", MySqlDbType.Int32).Value = id;

                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                if (!reader.IsDBNull(0))
                                {
                                    serviceIdNum = reader.GetInt32(0);
                                    VetServiceDBInfo record = new VetServiceDBInfo(serviceIdNum);
                                    records.Add(record);
                                }
                            }
                        }
                    }
                }
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show(Tools.DBErrorMessage, Tools.DBErrorTitle);
            }
            catch (MySqlException e)
            {
                Tools.HandleSQLExceptions(e);
            }

            return(records);
        }
        private void Btn_DeleteService_Click(object sender, RoutedEventArgs e)
        {
            int selectedId;
            VetServiceDBInfo removeItem = null;
            bool             found      = false;

            // Get the sNum from the UI
            selectedId = Convert.ToInt32(ListBox_ServiceDetails.SelectedValue);

            MessageBoxResult result;

            result = MessageBox.Show(Tools.deleteMessage, Tools.deleteTitle, MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                // Find the record matching the selected ID
                foreach (VetServiceDBInfo service in Veteran.ServiceDetails)
                {
                    if (service.sNum == selectedId)
                    {
                        // Remove from the database
                        service.DeleteFromDatabase();

                        // Flag item for removal from list
                        found      = true;
                        removeItem = service;
                    }
                }

                if (found)
                {
                    // Remove from the list
                    Veteran.ServiceDetails.Remove(removeItem);
                }

                ListBox_ServiceDetails.Items.Refresh();
            }
        }
        private void Btn_EditService_Click(object sender, RoutedEventArgs e)
        {
            int selectedId;
            VetServiceDBInfo selectedItem = null;
            bool             found        = false;

            // Get the sNum from the UI
            selectedId = Convert.ToInt32(ListBox_ServiceDetails.SelectedValue);

            foreach (VetServiceDBInfo service in Veteran.ServiceDetails)
            {
                if (service.sNum == selectedId)
                {
                    selectedItem = service;
                    found        = true;
                }
            }

            // Should always be found, but if for some reason the record is not there, do nothing
            if (found)
            {
                ServiceDetails serviceWin = new ServiceDetails(selectedItem);

                serviceWin.ShowDialog();

                if (serviceWin.IsOk)
                {
                    // Remove the old listing of the item
                    Veteran.ServiceDetails.Remove(selectedItem);

                    // Insert the updated listing
                    Veteran.ServiceDetails.Add(serviceWin.ServiceInfo);
                }

                ListBox_ServiceDetails.Items.Refresh();
            }
        }