Пример #1
0
        /// <summary>
        /// Download the record data from database.
        /// </summary>
        /// <param name="recordDownloadException"></param>
        /// <returns></returns>
        public static bool RecordsDataDownload()
        {
            recordDataList.Clear();

            try
            {
                using (SqlConnection connection = new SqlConnection(Operations.QueryStringData.ServerAddress))
                {
                    SqlCommand command = new SqlCommand(Operations.QueryStringData.RecordDataDownload, connection);

                    connection.Open();

                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        recordDataList.Add(new RecordData(Convert.ToInt32(reader[0]), Convert.ToInt32(reader[1]), Convert.ToDateTime(reader[2])
                                                          , Convert.ToInt32(reader[3]), Convert.ToInt32(reader[4]), Convert.ToInt32(reader[5])));
                    }
                }
            }
            catch (Exception anException)
            {
                if (ErrorHandle != null)
                {
                    ErrorHandle.Invoke(errorMessageText(ErrorMessage.RecordDataDownload, anException.Message));
                }
                return(false);
            }
            return(true);
        }
Пример #2
0
 void NofityError(Exception ex)
 {
     if (IgnoreError)
     {
         if (ForceAwaiterCompleteIfError)
         {
             m_AwaiterComplete?.Invoke();
         }
         ClearEvent();
         return;
     }
     Error = ex;
     if (ErrorHandle == null)
     {
         m_AwaiterComplete?.Invoke();
     }
     else
     {
         ErrorHandle.Invoke(ex);
         if (ForceAwaiterCompleteIfError)
         {
             m_AwaiterComplete?.Invoke();
         }
     }
     ClearEvent();
 }
Пример #3
0
        /// <summary>
        /// This void saves a new gamer name.
        /// </summary>
        /// <param name="aNewGamerName"></param>
        public static bool SaveNewGamerName(string aNewGamerName, out int newGamerID)
        {
            newGamerID = 0;

            try
            {
                using (SqlConnection connection = new SqlConnection(Operations.QueryStringData.ServerAddress))
                {
                    SqlCommand command = new SqlCommand(Operations.QueryStringData.GamerNameSave, connection);

                    command.Parameters.Add("@NewGamerName", SqlDbType.NChar);
                    command.Parameters["@NewGamerName"].Value = aNewGamerName;

                    connection.Open();

                    newGamerID = (int)command.ExecuteScalar();

                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }
            }
            catch (Exception anException)
            {
                if (ErrorHandle != null)
                {
                    ErrorHandle.Invoke(errorMessageText(ErrorMessage.GamerNameSave, anException.Message));
                }
                return(false);
            }
            return(true);
        }
Пример #4
0
        /// <summary>
        /// This void saves the buttons belongst to a former game.
        /// </summary>
        /// <param name="aSelectedFormerGameButton"></param>
        public static bool SaveASelectedFormerGameButtons(List <ButtonData> selectedGameButtons)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(Operations.QueryStringData.ServerAddress))
                {
                    connection.Open();

                    foreach (ButtonData aButtonData in selectedGameButtons)
                    {
                        SqlCommand command = new SqlCommand(Operations.QueryStringData.SelectedFormerGameButtonsUpload, connection);

                        command.Parameters.Add("@SelectedGameButtonVisible", SqlDbType.Int);
                        command.Parameters["@SelectedGameButtonVisible"].Value = aButtonData.ButtonVisible;

                        command.Parameters.Add("@SelectedGameID", SqlDbType.Int);
                        command.Parameters["@SelectedGameID"].Value = aButtonData.GameID;

                        command.Parameters.Add("@SelectedGameButtonNumber", SqlDbType.Int);
                        command.Parameters["@SelectedGameButtonNumber"].Value = aButtonData.ButtonNumber;

                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception anException)
            {
                if (ErrorHandle != null)
                {
                    ErrorHandle.Invoke(errorMessageText(ErrorMessage.SelectedFormerGameButtonsUpload, anException.Message));
                }
                return(false);
            }
            return(true);
        }
Пример #5
0
        /// <summary>
        /// Download the Buttons data about a game selection (GameID).
        /// </summary>
        /// <param name="selectedGameID"></param>
        /// <returns></returns>
        public static bool SelectedFormerGameButtonsDownload(int selectedGameID, out List <ButtonData> selectedSavedGameButtonList)
        {
            selectedSavedGameButtonList = new List <ButtonData>();

            try
            {
                using (SqlConnection connection = new SqlConnection(Operations.QueryStringData.ServerAddress))
                {
                    SqlCommand command = new SqlCommand(Operations.QueryStringData.SelectedFormerGameButtonsQuery, connection);

                    command.Parameters.Add("@SelectedGameID", SqlDbType.Int);
                    command.Parameters["@SelectedGameID"].Value = selectedGameID;

                    connection.Open();

                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        selectedSavedGameButtonList.Add(new ButtonData(Convert.ToInt32(reader[0]), Convert.ToInt32(reader[1]),
                                                                       Convert.ToInt32(reader[2]), Convert.ToInt32(reader[3])));
                    }
                }
            }
            catch (Exception anException)
            {
                if (ErrorHandle != null)
                {
                    ErrorHandle.Invoke(errorMessageText(ErrorMessage.SelectedFormerGameButtonsQuery, anException.Message));
                }
                return(false);
            }
            return(true);
        }
Пример #6
0
        private IEnumerator _download()
        {
            //避免下载完了,但是生成文件问题
            if (DownloadCacheFileLenght >= ServeLength)
            {
                Complete();
                yield break;
            }

            var result = webRequest.SendWebRequest();

            if (IsContinueDownload)
            {
                while (webRequest.responseCode != 206)
                {
                    Debug.LogError($"无法继续下载,本地大小:{DownloadCacheFileLenght}," +
                                   $"文件总大小:{ServeLength}");
                    yield return(null);
                }
            }
            while (!result.isDone)
            {
                DownloadInfo.SetDownloadLenght(DownloadCacheFileLenght + webRequest.downloadedBytes);
                ProgressHandle?
                .Invoke(
                    new DownloadProgressInfo(webRequest.downloadedBytes - oldLenght,
                                             GetProgress(webRequest.downloadedBytes), DownloadInfo),
                    DownloadMessageCode.GetMessage((int)DownloadMessageCodeTable.载中));

                oldLenght = webRequest.downloadedBytes;
                yield return(null);
            }

            if (!string.IsNullOrEmpty(webRequest.error))
            {
                ErrorHandle?.Invoke($"下载失败.\n" +
                                    $"错误信息为:{webRequest.error}\n" +
                                    $"网络状态码:{webRequest.responseCode}");
                yield break;
            }

            Complete();
        }
Пример #7
0
        /// <summary>
        /// Save the gamescor presented by TimeBonus and GameClickScoreMaker
        /// </summary>
        /// <param name="finishedGameRecord"></param>
        /// <param name="recordSaveException"></param>
        public static bool RecordSave(RecordData finishedGameRecord)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(Operations.QueryStringData.ServerAddress))
                {
                    SqlCommand command = new SqlCommand(Operations.QueryStringData.GameRecordSave, connection);

                    connection.Open();

                    command.Parameters.Add("@GamerID", SqlDbType.Int);
                    command.Parameters["@GamerID"].Value = finishedGameRecord.GamerID;

                    command.Parameters.Add("@RecordDateTime", SqlDbType.DateTime);
                    command.Parameters["@RecordDateTime"].Value = finishedGameRecord.RecordDateTime;

                    command.Parameters.Add("@ClickNumber", SqlDbType.Int);
                    command.Parameters["@ClickNumber"].Value = finishedGameRecord.ClickNumber;

                    command.Parameters.Add("@GameTime", SqlDbType.Int);
                    command.Parameters["@GameTime"].Value = finishedGameRecord.GameTime;

                    command.Parameters.Add("@Score", SqlDbType.Int);
                    command.Parameters["@Score"].Value = finishedGameRecord.Score;

                    command.ExecuteNonQuery();
                }
            }
            catch (Exception anException)
            {
                if (ErrorHandle != null)
                {
                    ErrorHandle.Invoke(errorMessageText(ErrorMessage.GameRecordSave, anException.Message));
                }
                return(false);
            }
            return(true);
        }
Пример #8
0
        /// <summary>
        /// This void updates a former game.
        /// </summary>
        /// <param name="selectedGameData"></param>
        /// <param name="selectedFormerGameDataUpdateException"></param>
        public static bool SelectedFormerGameDataUpdate(GameData selectedGameData)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(Operations.QueryStringData.ServerAddress))
                {
                    SqlCommand command = new SqlCommand(Operations.QueryStringData.SelectedFormerGameUpdate, connection);

                    command.Parameters.Add("@GameID", SqlDbType.Int);
                    command.Parameters["@GameID"].Value = selectedGameData.GameID;

                    connection.Open();

                    command.Parameters.Add("@SaveGameTime", SqlDbType.Int);
                    command.Parameters["@SaveGameTime"].Value = selectedGameData.SaveGameTime;

                    command.Parameters.Add("@SaveDateTime", SqlDbType.DateTime);
                    command.Parameters["@SaveDateTime"].Value = selectedGameData.SaveDateTime;

                    command.Parameters.Add("@GamerID", SqlDbType.Int);
                    command.Parameters["@GamerID"].Value = selectedGameData.GamerID;

                    command.Parameters.Add("@GamerClickCount", SqlDbType.Int);
                    command.Parameters["@GamerClickCount"].Value = selectedGameData.GamerClickCount;

                    command.ExecuteNonQuery();
                }
            }
            catch (Exception anException)
            {
                if (ErrorHandle != null)
                {
                    ErrorHandle.Invoke(errorMessageText(ErrorMessage.SelectedFormerGameUpdate, anException.Message));
                }
                return(false);
            }
            return(true);
        }