示例#1
0
        public Node GetNodeByID(string ID)
        {
            TableQuery <Node> table = connection.Table <Node>().Where(x => x.ID == ID);

            if (table.Count() == 0)
            {
                return(null);
            }
            return(table.First());
        }
示例#2
0
 internal static T RetrieveFirst <T>(this TableQuery <T> query)
 {
     if (query.Count() == 0)
     {
         throw new Database.NotFoundException();
     }
     else
     {
         return(query.First());
     }
 }
示例#3
0
 public Task <T> FirstAsync(CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Task.Factory.StartNew(() =>
     {
         cancellationToken.ThrowIfCancellationRequested();
         using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock())
         {
             cancellationToken.ThrowIfCancellationRequested();
             return _innerQuery.First();
         }
     }, cancellationToken, _taskCreationOptions, _taskScheduler ?? TaskScheduler.Default));
 }
示例#4
0
        public string GetSettings(string Name)
        {
            TableQuery <SettingsItem> results = db.Table <SettingsItem>().Where(s => s.name == Name);

            if (results.Count() > 0)
            {
                return(results.First().value);
            }
            else
            {
                return("");
            }
        }
示例#5
0
        public string GetUserPasswd(string username, string hash)
        {
            TableQuery <User> found = _connection.Table <User>().
                                      Where(v => v.name == username && v.passwd == hash);

            if (found.Count() == 1)
            {
                return(found.First().passwd);
            }
            else
            {
                return(string.Empty);
            }
        }
示例#6
0
    public void UseSail(Sail s)
    {
        TableQuery <Sail> activeSails = MainGameController.instance.databaseController.connection.Table <Sail>().Where(x => x.Active == true);

        if (activeSails.Count() > 0)
        {
            Sail curActive = activeSails.First();
            curActive.Active = false;
            curActive.Save();
        }
        s.Active = true;
        s.Save();
        UpdateSailBuyPanels();
    }
        public static Localisation GetLocation()
        {
            Initialisation BDD = new Initialisation();

            BDD.DBConnection();

            TableQuery <Localisation> LocationList = BDD.BDDConnection.Table <Localisation>();

            Localisation Location = null;

            if (LocationList.Count() != 0)
            {
                Location = LocationList.First();
            }


            BDD.BDDConnection.Close();

            return(Location);
        }
示例#8
0
 public Production GetProductionByDate(DateTime date)
 {
     if (database.Table <Production>().Count() == 0)
     {
         return(null);
     }
     else
     {
         TableQuery <Production> prod = from p in database.Table <Production>()
                                        where p.year.Equals(date.Year) && p.month.Equals(date.Month) && p.day.Equals(date.Day)
                                        select p;
         if (prod.Count() == 0)
         {
             return(null);
         }
         else
         {
             return(prod.First());
         }
     }
 }
示例#9
0
        static public void FillDatas(string username)
        {
            SQLiteConnection connection = DataBase.CheckConnection();
            //query the username for customer account
            TableQuery <CustomerAccount> customerAccountQuery = connection.Table <CustomerAccount>().Where(x => x.UserName == username);
            CustomerAccount _customerAccount = customerAccountQuery.First();

            if (_customerAccount != null)
            {
                customerAccount = _customerAccount;
            }

            //query the user name for customer personal info
            TableQuery <CustomerPersonal> customerPersonalQuery = connection.Table <CustomerPersonal>().Where(x => x.UserName == username);
            CustomerPersonal _customerPersonal = customerPersonalQuery.First();

            if (_customerAccount != null)
            {
                customerPersonal = _customerPersonal;
            }
            UserConnected = true;
        }
示例#10
0
    public void UseBoat(Boat b)
    {
        TableQuery <Boat> activeBoats = MainGameController.instance.databaseController.connection.Table <Boat>().Where(x => x.Active == true);

        if (activeBoats.Count() > 0)
        {
            Boat curActive = activeBoats.First();
            curActive.Active = false;
            curActive.Save();
            Sail activeSail = curActive.GetSailsBought().Where(x => x.Active).First();
            if (!b.GetSailsBought().Contains(activeSail))
            {
                activeSail.Active = false;
                activeSail.Save();
                Sail s = b.GetSailsBought().Where(x => x.Bought).First();
                s.Active = true;
                s.Save();
            }
        }
        b.Active = true;
        b.Save();
        UpdateBoatBuyPanels();
    }
示例#11
0
        private void BtnLogin_Click(object sender, System.EventArgs e)
        {
            //Make validations and connect to database and check is this user is exists and infos are correct
            if (Validator.ValidUserName(txtUserName.Text) && Validator.ValidPassWord(txtPassword.Text))//
            {
                //this is a test validation
                //email is valid
                SQLiteConnection             connection = DataBase.CheckConnection();
                TableQuery <CustomerAccount> customer   = connection.Table <CustomerAccount>().Where(x => x.UserName == txtUserName.Text);
                CustomerAccount foundCustomer           = null;
                if (customer.Count() > 0)
                {
                    foundCustomer = customer.First();

                    if (foundCustomer != null && foundCustomer.Password != string.Empty && foundCustomer.Password == txtPassword.Text)
                    {   //anasayfaya yönlendirme
                        GeneralInfo.UserConnected = true;
                        GeneralInfo.FillDatas(txtUserName.Text);
                        StartActivity(typeof(MainActivity));
                        MessageBoxShort("Correct Username and Password");
                    }
                    else
                    {
                        MessageBoxShort("Username or Password is wrong!");
                    }
                }
                else
                {
                    MessageBoxShort("There is no user found.");
                }
            }
            else
            {
                MessageBoxShort("User name or password was not valid.");
            }
        }
        internal bool SaveFilmography <T>(T entity, bool newFilmographyToUser) where T : Filmography, new()
        {
            Filmography existing = null;

            FilmographyType.Value type;

            TableQuery <T> query = Connection.Table <T>().Where(f => f.TmdbId == entity.TmdbId);

            existing = query.Count() > 0 ? query.First() : null;

            if (entity is Series)
            {
                type = FilmographyType.Value.SERIES;
            }
            else if (entity is Season)
            {
                type = FilmographyType.Value.SEASON;
            }
            else if (entity is Episode)
            {
                type = FilmographyType.Value.EPISODE;
            }
            else
            {
                throw new NotSupportedException();
            }

            if (existing == null)
            {
                if (Connection.Insert(entity) == 0)
                {
                    return(false);
                }
            }
            else
            {
                entity.Id = existing.Id;
                if (Connection.Update(entity) == 0)
                {
                    return(false);
                }
            }

            if (newFilmographyToUser)
            {
                FilmographyToUser ftu = new FilmographyToUser();
                ftu.FilmographyId     = entity.GetId();
                ftu.FilmographyTypeId = (int)type;
                ftu.UserId            = App.Instance.User.GetId();
                ftu.Finished          = false;
                ftu.SecondsWatched    = 0;
                ftu.SetLastActivityDate(DateTime.Now);

                ftu.PrintValues();

                TableQuery <FilmographyToUser> ftuQuery = Connection.Table <FilmographyToUser>().Where(
                    f => f.UserId == ftu.UserId &&
                    f.FilmographyId == ftu.FilmographyId &&
                    f.FilmographyTypeId == ftu.FilmographyTypeId);

                FilmographyToUser existingFtu = ftuQuery.Count() > 0 ? ftuQuery.First() : null;

                if (existingFtu == null)
                {
                    if (Connection.Insert(ftu) == 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    ftu.Id = existingFtu.Id;
                    if (Connection.Update(ftu) == 0)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#13
0
 /// <summary>
 /// Returns the first element of this query.
 /// </summary>
 public Task <T> FirstAsync()
 {
     return(ReadAsync(conn => _innerQuery.First()));
 }
示例#14
0
        internal void WatchEpisode(Episode episode)
        {
            if (Settings.Default.OpenMediaInApp)
            {
                MediaPlayerForm mediaPLayerForm = new MediaPlayerForm();
                mediaPLayerForm.Show();
                mediaPLayerForm.UpdateView(episode);
            }
            else
            {
                string mediaPlayer = Settings.Default.ExternalMediaPlayerPath;

                if (mediaPlayer != null)
                {
                    Process.Start(mediaPlayer, "\"" + Files.GetEpisodeFile(episode) + "\"");

                    Thread.Sleep(1000);

                    switch (MessageBox.Show("Have you finished the episode?", "", MessageBoxButtons.YesNo))
                    {
                    case DialogResult.Yes:

                        // marks episode finished and sets seconds watched (not punctual)
                        FilmographyToUser toUser = episode.ToUser;
                        toUser.Finished       = true;
                        toUser.SecondsWatched = episode.Season.Series.EpisodeRunTime * 60;                                      // in seconds
                        DbManager.Connection.Update(toUser);

                        // if episode is last ine is season, marks season finished
                        if (DbManager.IsLastEpisodeInSeason(episode))
                        {
                            FilmographyToUser sToUser = episode.Season.ToUser;
                            sToUser.Finished = true;
                            DbManager.Connection.Update(sToUser);
                        }

                        // updates user statistics
                        string date = DateTime.Today.ToShortDateString();
                        TableQuery <UserStatistics> query = DbManager.Connection.Table <UserStatistics>()
                                                            .Where(us => us.UserId == User.Id && us.Date == date);
                        UserStatistics stat = query != null && query.Count() > 0 ? query.First() : null;

                        if (stat == null)
                        {
                            stat        = new UserStatistics();
                            stat.UserId = User.GetId();
                            stat.SetDate(DateTime.Today);
                            stat.TimeWatching = 0;
                        }

                        stat.TimeWatching += toUser.SecondsWatched;
                        DbManager.Connection.InsertOrReplace(stat);

                        // udpates series panel (new next episode)
                        mainForm.UpdatePanel(PanelId.Series, episode.Season.Series, true);
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("Please select external media player in Settings page.");
                }
            }
        }