Example #1
0
        private void Btn_DeleteRank_Click(object sender, RoutedEventArgs e)
        {
            string selectedRank;

            selectedRank = Convert.ToString(ListBox_RankDetails.SelectedValue);

            // Verify the user selected a record to delete
            if (!string.IsNullOrEmpty(selectedRank))
            {
                MessageBoxResult result;
                result = MessageBox.Show(Tools.deleteMessage, Tools.deleteTitle, MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    foreach (RankDBInfo rank in rankList)
                    {
                        if (rank.Rank == selectedRank)
                        {
                            // Remove from the database
                            rank.DeleteFromDatabase();
                        }
                    }

                    rankList = RankDBInfo.LoadObjectList(CurrentBranch);

                    ListBox_RankDetails.DataContext = rankList;
                }
            }
            else
            {
                MessageBox.Show(Tools.RecordDeleteMessage, Tools.RecordSelectTitle);
            }
        }
Example #2
0
        // Copy Constructor
        public RankDBInfo(RankDBInfo other)
        {
            branch    = other.branch;
            rank      = other.rank;
            oldRank   = other.oldRank;
            rankAbrev = other.rankAbrev;

            hasDataChanged = other.hasDataChanged;
            isNewRecord    = other.isNewRecord;
        }
        // Loads data into the ranks observable collection for the dropdown for the selected branch
        private void CmbBox_Service_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            RankList = RankDBInfo.LoadStringList(ServiceInfo.Branch);

            Ranks.Clear();

            foreach (string rank in RankList)
            {
                Ranks.Add(rank);
            }
        }
Example #4
0
        private void CmbBox_Service_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Enable buttons if actual branch selected, disable on blank branch item
            Btn_AddRank.IsEnabled    = !string.IsNullOrEmpty(CurrentBranch);
            Btn_EditRank.IsEnabled   = !string.IsNullOrEmpty(CurrentBranch);
            Btn_DeleteRank.IsEnabled = !string.IsNullOrEmpty(CurrentBranch);

            rankList = RankDBInfo.LoadObjectList(CurrentBranch);

            ListBox_RankDetails.DataContext = rankList;
        }
Example #5
0
        private void Save()
        {
            CurrentRank.WriteDataToDatabase();

            rankList = RankDBInfo.LoadObjectList(CurrentBranch);

            ListBox_RankDetails.DataContext = rankList;

            HideControls();

            CurrentRank = null;
        }
Example #6
0
        private void Btn_EditRank_Click(object sender, RoutedEventArgs e)
        {
            string selectedRank;

            selectedRank = Convert.ToString(ListBox_RankDetails.SelectedValue);

            // Verify the user selected a record to edit
            if (!string.IsNullOrEmpty(selectedRank))
            {
                CurrentRank = new RankDBInfo(CurrentBranch, selectedRank);

                ShowControls();
            }
            else
            {
                MessageBox.Show(Tools.RecordSelectMessage, Tools.RecordSelectTitle);
            }
        }
Example #7
0
        // Loads the ranks for a given branch into a list of objects
        public static List <RankDBInfo> LoadObjectList(string Branch)
        {
            List <RankDBInfo> records = new List <RankDBInfo>();
            RankDBInfo        current;

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

                    using (MySqlCommand command = conn.CreateCommand())
                    {
                        command.CommandText = "SELECT RankName FROM RanksList WHERE BranchName = @BName;";
                        command.Parameters.Add("@BName", MySqlDbType.VarChar).Value = Branch;

                        using (MySqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                if (!reader.IsDBNull(0))
                                {
                                    current = new RankDBInfo(Branch, reader.GetString(0));

                                    records.Add(current);
                                }
                            }
                        }
                    }
                }
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show(Tools.DBErrorMessage, Tools.DBErrorTitle);
            }
            catch (MySqlException e)
            {
                Tools.HandleSQLExceptions(e);
            }

            return(records);
        }
Example #8
0
        private void Btn_AddRank_Click(object sender, RoutedEventArgs e)
        {
            CurrentRank = new RankDBInfo(CurrentBranch);

            ShowControls();
        }