Example #1
0
        // Загрузить список матчей игры
        void DB_OpenGame()
        {
            loadingFromDB = true;
            Cursor.Current = Cursors.WaitCursor;

            // Загрузить ids матчей в DB_Matches_Ids_ALL
            System.Data.SqlServerCe.SqlCeCommand sqlQuery = DB.CreateQuery();

            //sql_optimize
            //sqlQuery.CommandText = "SELECT Matches.id as mid, Matches.SCORE_NS, Matches.SCORE_EW, COUNT(" + DB_Deals_TableName + ".id) FROM Matches INNER JOIN " + DB_Deals_TableName + " ON (Matches.id = " + DB_Deals_TableName + ".fk_Match_id) WHERE (Matches.fk_Game_id=" + DB_Game_Id + ") GROUP BY Matches.id, Matches.SCORE_NS, Matches.SCORE_EW ORDER BY mid";
            //sqlQuery.CommandText = "SELECT m.id as mid, Matches.SCORE_NS, Matches.SCORE_EW FROM (SELECT DISTINCT Matches.id FROM Matches INNER JOIN " + DB_Deals_TableName + " ON (Matches.id = " + DB_Deals_TableName + ".fk_Match_id) WHERE (Matches.fk_Game_id=" + DB_Game_Id + ")) m INNER JOIN Matches ON (m.id = Matches.id) ORDER BY mid";
            sqlQuery.CommandText = "SELECT id as mid, SCORE_NS, SCORE_EW FROM Matches m WHERE fk_Game_id = " + DB_Game_Id + " AND EXISTS (SELECT id FROM " + DB_Deals_TableName + " WHERE fk_Match_id = m.id) ORDER BY mid";

            System.Data.SqlServerCe.SqlCeDataReader sqlReader = DB.ExecuteReader(sqlQuery);
            DB_Matches_Ids_ALL = new ArrayOfInt();
            while (sqlReader.Read())
            {
                // Взять total-score из БД:
                if (sqlReader.IsDBNull(sqlReader.GetOrdinal("SCORE_NS")) || sqlReader.IsDBNull(sqlReader.GetOrdinal("SCORE_EW")))
                {
                    DB_Matches_TotalScores.Add(new DealScore(0, 0));
                }
                else
                {
                    DB_Matches_TotalScores.Add(new DealScore(sqlReader.GetInt32(sqlReader.GetOrdinal("SCORE_NS")), sqlReader.GetInt32(sqlReader.GetOrdinal("SCORE_EW"))));
                }

                // ids:
                DB_Matches_Ids_ALL.Add(sqlReader.GetInt32(sqlReader.GetOrdinal("mid")));
            }
            sqlReader.Close();

            // Загрузить ids матчей в селектор
            match_in_combo m = new match_in_combo();
            m.isrob = isRobber;
            for (int i = 0; i < DB_Matches_Ids_ALL.Count; i++)
            {
                m.no = i;
                m.id = DB_Matches_Ids_ALL[i];
                m.score_NS = ((DealScore)DB_Matches_TotalScores[i]).NS;
                m.score_EW = ((DealScore)DB_Matches_TotalScores[i]).EW;
                PAGE__ComboBox.Items.Add(m);
            }

            TS_SHOW();

            Cursor.Current = Cursors.Default;
            loadingFromDB = false;
        }
Example #2
0
        bool AddNewMatch_PAGE_MODE(bool loadFromDB)
        {
            if (loadFromDB == true) //wtf??? use openpage()!
                return false;

            System.Data.SqlServerCe.SqlCeCommand sqlQuery = DB.CreateQuery();
            sqlQuery.CommandText = "INSERT INTO Matches(fk_Game_id) VALUES(" + DB_Game_Id + ")";
            int new_match_id;

            while (DB.ExecuteNonQuery(sqlQuery, true, out new_match_id) == 0)
            {
                if (MessageBox.Show("Матч не был создан!", "db error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Retry)
                {
                    DB.sqlConnection.Close();
                    DB.sqlConnection.Open();
                }
                else
                {
                    return false;
                }
            }

            DB_Matches_Ids_ALL.Add(new_match_id);

            DB_Matches_TotalScores.Add(new DealScore(0, 0));

            // + в combo
            match_in_combo m = new match_in_combo();
            m.isrob = isRobber;
            m.no = DB_Matches_Ids_ALL.Count - 1;
            m.id = new_match_id;
            PAGE__ComboBox.Items.Add(m);

            DB_OpenPage(DB_Matches_Ids_ALL.Count - 1);

            return true;
        }