Пример #1
0
        private void Btn_DeleteAward_Click(object sender, RoutedEventArgs e)
        {
            int            selectedIndex;
            VetAwardDBInfo removeItem = null;

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

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

                if (result == MessageBoxResult.Yes)
                {
                    removeItem = Veteran.AwardDetails[selectedIndex];

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

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

                    ListBox_AwardDetails.Items.Refresh();
                }
            }
            else
            {
                MessageBox.Show(Tools.RecordDeleteMessage, Tools.RecordSelectTitle);
            }
        }
Пример #2
0
        private void Btn_EditAward_Click(object sender, RoutedEventArgs e)
        {
            int            selectedIndex;
            VetAwardDBInfo selectedItem = null;

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

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

                AwardDetails awardWin = new AwardDetails(selectedItem);

                awardWin.ShowDialog();

                Veteran.AwardDetails[selectedIndex] = awardWin.AwardInfo;

                ListBox_AwardDetails.Items.Refresh();
            }
            else
            {
                MessageBox.Show(Tools.RecordSelectMessage, Tools.RecordSelectTitle);
            }
        }
Пример #3
0
        // Copy Constructor
        public VetAwardDBInfo(VetAwardDBInfo other)
        {
            hasDataChanged = other.hasDataChanged;

            id     = other.id;
            aNum   = other.aNum;
            award  = other.award;
            branch = other.branch;
        }
Пример #4
0
        // Default Constructor
        public AwardDetails()
        {
            InitializeComponent();

            AwardInfo = new VetAwardDBInfo();

            IsOk = false;
            dataPreviouslyChanged = Tools.hasDataChanged;

            DataContext = this;

            BranchList = BranchDBInfo.LoadStringList();
        }
Пример #5
0
        // Loads the award details into a list
        private List <VetAwardDBInfo> LoadAwardDetails()
        {
            List <VetAwardDBInfo> records = new List <VetAwardDBInfo>();
            int awardIdNum;

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

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

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

            return(records);
        }