// This method checks to see if the database exists, and if it doesn't, it creates
        // it and inserts some data. It also sets our database to be the default database
        // connection.
        protected void CheckAndCreateDatabase(string dbName)
        {
            // determine whether or not the database exists
            bool dbExists = File.Exists(GetDBPath(dbName));

            // configure the current database, create if it doesn't exist, and then run the anonymous
            // delegate method after it's created
            CSConfig.SetDB(GetDBPath(dbName), SqliteOption.CreateIfNotExists, () => {
                CSDatabase.ExecuteNonQuery("CREATE TABLE People (PersonID INTEGER PRIMARY KEY AUTOINCREMENT, FirstName text, LastName text)");

                // if the database had to be created, let's populate with initial data
                if (!dbExists)
                {
                    // declare vars
                    CSList <Person> people = new CSList <Person> ();
                    Person person;

                    // create a list of people that we're going to insert
                    person = new Person()
                    {
                        FirstName = "Peter", LastName = "Gabriel"
                    };
                    people.Add(person);
                    person = new Person()
                    {
                        FirstName = "Thom", LastName = "Yorke"
                    };
                    people.Add(person);
                    person = new Person()
                    {
                        FirstName = "J", LastName = "Spaceman"
                    };
                    people.Add(person);
                    person = new Person()
                    {
                        FirstName = "Benjamin", LastName = "Gibbard"
                    };
                    people.Add(person);

                    // save the people collection to the database
                    people.Save();
                }
            });
        }
Esempio n. 2
0
        private void Open()
        {
            var mdlg = new OpenFileDialog();

            mdlg.CheckFileExists = true;
            mdlg.Multiselect     = false;
            mdlg.Filter          = "Tvtest channel file(*.ch2)|*.ch2|All file(*.*)|*.*";
            if (mdlg.ShowDialog() == true)
            {
                foreach (var item in Ch2.ReadChe2File(mdlg.FileName))
                {
                    switch (item.Type)
                    {
                    case CHType.GR:
                        if (!GRList.Any(x => x.ServiceID == item.ServiceID))
                        {
                            GRList.Add(new ChannelViewModel(item));
                        }
                        break;

                    case CHType.BS:
                        if (!BSList.Any(x => x.ServiceID == item.ServiceID))
                        {
                            BSList.Add(new ChannelViewModel(item));
                        }
                        break;

                    case CHType.CS:
                        if (!CSList.Any(x => x.ServiceID == item.ServiceID))
                        {
                            CSList.Add(new ChannelViewModel(item));
                        }
                        break;

                    default:
                        if (!SKList.Any(x => x.ServiceID == item.ServiceID))
                        {
                            SKList.Add(new ChannelViewModel(item));
                        }
                        break;
                    }
                }
                GRList.Sort((x, y) => x.Channel == y.Channel ? x.ServiceID.CompareTo(y.ServiceID) : x.Channel.CompareTo(y.Channel));
                BSList.Sort((x, y) => x.Channel == y.Channel ? x.ServiceID.CompareTo(y.ServiceID) : x.Channel.CompareTo(y.Channel));
                CSList.Sort((x, y) => x.Channel == y.Channel ? x.ServiceID.CompareTo(y.ServiceID) : x.Channel.CompareTo(y.Channel));
                SKList.Sort((x, y) => x.Channel == y.Channel ? x.ServiceID.CompareTo(y.ServiceID) : x.Channel.CompareTo(y.Channel));
                ChannelList  = new ObservableCollection <ChannelViewModel>(GRList.Concat(BSList).Concat(CSList).Concat(SKList));
                this.isSaved = false;
                this.NotifyPropertyChanged(nameof(this.Caption));
            }
            else
            {
                return;
            }
        }