コード例 #1
0
        private void Btn_DeleteAward_Click(object sender, RoutedEventArgs e)
        {
            string selectedAward;

            selectedAward = Convert.ToString(ListBox_AwardDetails.SelectedValue);

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

                if (result == MessageBoxResult.Yes)
                {
                    foreach (AwardDBInfo award in awardList)
                    {
                        if (award.Award == selectedAward)
                        {
                            // Remove from the database
                            award.DeleteFromDatabase();
                        }
                    }

                    awardList = AwardDBInfo.LoadObjectList(CurrentBranch);

                    ListBox_AwardDetails.DataContext = awardList;
                }
            }
            else
            {
                MessageBox.Show(Tools.RecordDeleteMessage, Tools.RecordSelectTitle);
            }
        }
コード例 #2
0
        // Copy Constructor
        public AwardDBInfo(AwardDBInfo other)
        {
            branch   = other.branch;
            award    = other.award;
            oldaward = other.oldaward;

            hasDataChanged = other.hasDataChanged;
            isNewRecord    = other.isNewRecord;
        }
コード例 #3
0
        private void CmbBox_Service_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Enable buttons if actual branch selected, disable on blank branch item
            Btn_AddAward.IsEnabled    = !string.IsNullOrEmpty(CurrentBranch);
            Btn_EditAward.IsEnabled   = !string.IsNullOrEmpty(CurrentBranch);
            Btn_DeleteAward.IsEnabled = !string.IsNullOrEmpty(CurrentBranch);

            awardList = AwardDBInfo.LoadObjectList(CurrentBranch);

            ListBox_AwardDetails.DataContext = awardList;
        }
コード例 #4
0
        private void Save()
        {
            CurrentAward.WriteDataToDatabase();

            awardList = AwardDBInfo.LoadObjectList(CurrentBranch);

            ListBox_AwardDetails.DataContext = awardList;

            HideControls();

            CurrentAward = null;
        }
コード例 #5
0
        private void Btn_EditAward_Click(object sender, RoutedEventArgs e)
        {
            string selectedAward;

            selectedAward = Convert.ToString(ListBox_AwardDetails.SelectedValue);

            // Verify the user selected a record to edit
            if (!string.IsNullOrEmpty(selectedAward))
            {
                CurrentAward = new AwardDBInfo(CurrentBranch, selectedAward);

                ShowControls();
            }
            else
            {
                MessageBox.Show(Tools.RecordSelectMessage, Tools.RecordSelectTitle);
            }
        }
コード例 #6
0
        // Loads the awards for a given branch into a list of objects
        public static List <AwardDBInfo> LoadObjectList(string Branch)
        {
            List <AwardDBInfo> records = new List <AwardDBInfo>();
            AwardDBInfo        current;

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

                    using (MySqlCommand command = conn.CreateCommand())
                    {
                        command.CommandText = "SELECT AwardName FROM AwardsList 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 AwardDBInfo(Branch, reader.GetString(0));

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

            return(records);
        }
コード例 #7
0
        private void Btn_AddAward_Click(object sender, RoutedEventArgs e)
        {
            CurrentAward = new AwardDBInfo(currentBranch);

            ShowControls();
        }
コード例 #8
0
 // Loads data into the ranks observable collection for the dropdown for the selected branch
 private void CmbBox_Service_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     AwardList = AwardDBInfo.LoadStringList(AwardInfo.Branch);
 }