Beispiel #1
0
        private void textChanged(object sender, TextChangedEventArgs e)
        {
            string searching = searchBox.Text.ToUpper();

            using (var db = new LiteDatabase(LiteDbConnection.getDbName()))
            {
                var bands      = db.GetCollection <Band>("Bands");
                var queryBands = bands.FindAll();
                if (searching != null)
                {
                    List <Band> findBands = new List <Band>();
                    foreach (Band theBand in queryBands)
                    {
                        if (theBand.name.ToUpper().Contains(searching))
                        {
                            findBands.Add(theBand);
                        }
                    }
                    var bandList = findBands.OrderBy(x => x.name);
                    bandListView.ItemsSource = bandList;
                }

                else
                {
                    var allBandList = queryBands.OrderBy(x => x.name).ToList();
                    bandListView.ItemsSource = allBandList;
                }
            }
        }
Beispiel #2
0
        private void deleteContactButtonClick(object sender, RoutedEventArgs e)
        {
            BandContact contactToDelete = (BandContact)contactListView.SelectedItem;

            if (contactToDelete != null)
            {
                try
                {
                    using (var db = new LiteDatabase(LiteDbConnection.getDbName()))
                    {
                        var contacts = db.GetCollection <BandContact>("BandContacts");
                        MessageBoxResult myResult;
                        myResult = MessageBox.Show("Opravdu chcete smazat kontakt " + contactToDelete.fName + " " +
                                                   contactToDelete.lName + " ?", "Delete Confirmation", MessageBoxButton.OKCancel);
                        if (myResult == MessageBoxResult.OK)
                        {
                            contacts.Delete(contactToDelete._id);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Není vybrán kontakt!");
            }

            this.NavigationService.Navigate(new BandDetail(bandDetail));
        }
Beispiel #3
0
        /// <summary>
        /// Export data tables to PDF.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exportPDF(object sender, RoutedEventArgs e)
        {
            try
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Filter = "PDF(*.pdf)|*.pdf";
                dialog.ShowDialog();
                string path = dialog.FileName;



                List <Band> bands;
                ArrayList   bandsToPdf = new ArrayList();

                using (var db = new LiteDatabase(LiteDbConnection.getDbName()))
                {
                    var dbBands = db.GetCollection <Band>("Bands");
                    bands = dbBands.FindAll().ToList();

                    foreach (Band bandToProcess in bands)
                    {
                        bandsToPdf.Add(bandToProcess);
                    }

                    PdfExport.processBandsToPdf(bandsToPdf, path, 12);
                }
            }
            catch (Exception ex)
            {
                this.NavigationService.Navigate(new BandsAdmin());
            }
        }
Beispiel #4
0
 public void saveBandToDb(Band band)
 {
     try
     {
         using (var db = new LiteDatabase(LiteDbConnection.getDbName()))
         {
             var bands = db.GetCollection <Band>("Bands");
             bands.Upsert(band);
         }
     }
     catch (Exception ex)
     {
         System.Windows.MessageBox.Show(ex.Message);
     }
 }
Beispiel #5
0
 /// <summary>
 /// Naplneni bandlistu datama z DB
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void bandListInitialize(object sender, EventArgs e)
 {
     try
     {
         using (var db = new LiteDatabase(LiteDbConnection.getDbName()))
         {
             var bands      = db.GetCollection <Band>("Bands");
             var queryBands = bands.FindAll();
             var bandList   = queryBands.OrderBy(x => x.name).ToList();
             bandListView.ItemsSource = bandList;
         }
     }
     catch (Exception ex)
     {
         System.Windows.MessageBox.Show(ex.Message);
     }
 }
Beispiel #6
0
        public AddContact(int bandId)
        {
            contactBandId = bandId;
            try
            {
                using (var db = new LiteDatabase(LiteDbConnection.getDbName()))
                {
                    var bands = db.GetCollection <Band>("Bands");
                    band = bands.FindById(contactBandId);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            InitializeComponent();
        }
Beispiel #7
0
        private void ListView_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new LiteDatabase(LiteDbConnection.getDbName()))
                {
                    var bands         = db.GetCollection <Band>("Bands");
                    var contacts      = db.GetCollection <BandContact>("BandContacts");
                    var queryContacts = contacts.Find(x => x.bandId == bandDetail._id);


                    contactListView.ItemsSource = queryContacts;
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Mazani kapely.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteBandButton_Click(object sender, RoutedEventArgs e)
        {
            object selectedRow = bandListView.SelectedItem;
            Band   band        = (Band)selectedRow;

            if (band != null)
            {
                try
                {
                    using (var db = new LiteDatabase(LiteDbConnection.getDbName()))
                    {
                        MessageBoxResult myResult;
                        myResult = MessageBox.Show("Opravdu chcete smazat kapelu " + band.name + " ?", "Delete Confirmation", MessageBoxButton.OKCancel);
                        if (myResult == MessageBoxResult.OK)
                        {
                            var bands    = db.GetCollection <Band>("Bands");
                            var contacts = db.GetCollection <BandContact>("BandContacts");
                            List <BandContact> contactsQuery    = contacts.FindAll().ToList();
                            List <BandContact> contactsToDelete = contactsQuery.FindAll(delegate(BandContact bk)
                            {
                                return(bk.bandId == band._id);
                            });
                            foreach (BandContact contact in contactsToDelete)
                            {
                                contacts.Delete(contact._id);
                            }
                            bands.Delete(band._id);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Není vybrána kapela!");
            }

            this.NavigationService.Navigate(new BandsAdmin());
        }
Beispiel #9
0
        public Boolean checkIfBandExists(Band band)
        {
            Boolean bandExists = false;

            try
            {
                using (var db = new LiteDatabase(LiteDbConnection.getDbName()))
                {
                    var bands      = db.GetCollection <Band>("Bands");
                    var queryBands = bands.FindAll();

                    if (bands.Find(lookingBand => lookingBand.name == band.name).Any())
                    {
                        bandExists = true;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }
            return(bandExists);
        }
Beispiel #10
0
        public static ArrayList findBandContacts(Band band)
        {
            ArrayList contacts = new ArrayList();

            using (var db = new LiteDatabase(LiteDbConnection.getDbName()))
            {
                var dbContacts = db.GetCollection <BandContact>("BandContacts");
                List <BandContact> contactsToReturn;
                ArrayList          bandContacts  = new ArrayList();
                List <BandContact> queryContacts = dbContacts.FindAll().ToList();

                contactsToReturn = queryContacts.FindAll(delegate(BandContact bk)
                {
                    return(bk.bandId == band._id);
                });

                foreach (BandContact contact in contactsToReturn)
                {
                    contacts.Add(contact);
                }
            }

            return(contacts);
        }