Exemple #1
0
        /// <summary>
        /// 获取所有熟悉的单词
        /// </summary>
        /// <returns>The all familiar word.</returns>
        public List <HLHWord> GetAllFamiliarWord()
        {
            List <HLHWord> familiarWords = new List <HLHWord>();

            string tableName = GetCurrentLearningWordsTabelName();

            MySQLiteHelper sql = MySQLiteHelper.Instance;

            sql.GetConnectionWith(CommonData.dataBaseName);

            string[] graspedCondition = { "learnedTimes>0", "isFamiliar=1" };

            IDataReader reader = sql.ReadSpecificRowsOfTable(tableName, null, graspedCondition, true);

            while (reader.Read())
            {
                if (reader == null)
                {
                    sql.CloseConnection(CommonData.dataBaseName);
                    return(null);
                }

                HLHWord word = HLHWord.GetWordFromReader(reader);

                familiarWords.Add(word);
            }


            sql.CloseConnection(CommonData.dataBaseName);

            return(familiarWords);
        }
        /// <summary>
        /// 更新数据库中变更单词掌握状态的单词信息
        /// </summary>
        private void UpdateChangeStatusWords()
        {
            MySQLiteHelper sql = MySQLiteHelper.Instance;

            sql.GetConnectionWith(CommonData.dataBaseName);

            string currentWordsTableName = LearningInfo.Instance.GetCurrentLearningWordsTabelName();

            string[] colFields = { "isFamiliar" };

            HLHWord word = null;

            // 更新数据库中的单词数据
            // 更新所有待转移到熟悉列表的单词
            for (int i = 0; i < changeToFamiliarWords.Count; i++)
            {
                word = changeToFamiliarWords[i];
                word.learnedTimes++;
                string[] conditions = { "wordId=" + word.wordId };
                string[] values     = { "1" };
                sql.UpdateValues(currentWordsTableName, colFields, values, conditions, true);
            }
            // 更新所有待转移到不熟悉列表的单词
            for (int i = 0; i < changeToUnfamiliarWords.Count; i++)
            {
                word = changeToUnfamiliarWords[i];
                word.learnedTimes++;
                word.ungraspTimes++;
                string[] conditions = { "wordId=" + word.wordId };
                string[] values     = { "0" };
                sql.UpdateValues(currentWordsTableName, colFields, values, conditions, true);
            }

            sql.CloseConnection(CommonData.dataBaseName);
        }
        private void UpdateDataBase()
        {
            mySql.GetConnectionWith(CommonData.dataBaseName);

            mySql.BeginTransaction();

            for (int i = 0; i < singleLearnWordsCount; i++)
            {
                LearnWord word           = wordsToLearnArray [i];
                string    condition      = string.Format("wordId={0}", word.wordId);
                string    newLearnedTime = (word.learnedTimes).ToString();
                string    newUngraspTime = (word.ungraspTimes).ToString();

                // 更新数据库中当前背诵单词的背诵次数和背错次数
                mySql.UpdateValues(currentWordsTableName, new string[] { "learnedTimes", "ungraspTimes" }, new string[] {
                    newLearnedTime,
                    newUngraspTime
                }, new string[] {
                    condition
                }, true);
            }

            mySql.EndTransaction();

            mySql.CloseConnection(CommonData.dataBaseName);
        }
        public static FuseStone CreateFuseStoneIfExist(string spell)
        {
            /************从单词数据库中获取物品名称**************/
            MySQLiteHelper sql = MySQLiteHelper.Instance;

            sql.GetConnectionWith(CommonData.dataBaseName);

            IDataReader reader = sql.ReadSpecificRowsOfTable("AllWordsData", "*",
                                                             new string[] { string.Format("Spell='{0}'", spell) },
                                                             true);

            if (!reader.Read())
            {
                Debug.Log("不存在");
                return(null);
            }

            bool valid = reader.GetBoolean(4);

            if (!valid)
            {
                Debug.Log("已使用");
                return(null);
            }

            int id = reader.GetInt32(0);

            string explaination = reader.GetString(2);

            string firstExplaination = explaination.Split(new string[] { ";" }, System.StringSplitOptions.RemoveEmptyEntries)[0];

            string[] strings = firstExplaination.Split(new string[] { ".", "," }, System.StringSplitOptions.RemoveEmptyEntries);

            string fuseStoneName = strings [strings.Length - 1];

//			string fuseStoneName = explaination.Split (new string[]{ ".", "," ,";"},
//				System.StringSplitOptions.RemoveEmptyEntries)[1];

            fuseStoneName = fuseStoneName.Replace(" ", string.Empty);
            fuseStoneName = fuseStoneName.Replace("的", string.Empty);

            fuseStoneName = string.Format("{0}之石", fuseStoneName);

            sql.UpdateValues("AllWordsData",
                             new string[] { "Valid" },
                             new string[] { "0" },
                             new string[] { string.Format("Id={0}", id) },
                             true);

            sql.CloseConnection(CommonData.dataBaseName);

            FuseStone fuseStone = new FuseStone(fuseStoneName, spell);

            Debug.Log(fuseStone);

            return(fuseStone);
        }
Exemple #5
0
        /// <summary>
        /// 获取当前词库的单词总数
        /// </summary>
        /// <returns>The total words count.</returns>
        private int GetTotalWordsCount()
        {
            string tableName = GetCurrentLearningWordsTabelName();

            MySQLiteHelper sql = MySQLiteHelper.Instance;

            // 连接数据库
            sql.GetConnectionWith(CommonData.dataBaseName);

            // 检查存放指定单词类型的表是否存在(目前只做了测试用的CET4这一个表,添加表使用参考editor文件夹下的DataBaseManager)
            if (!sql.CheckTableExist(tableName))
            {
                sql.CloseConnection(CommonData.dataBaseName);
                return(0);
            }

            // 查询当前学习的单词类型中的所有单词数量
            int count = sql.GetItemCountOfTable(tableName, null, true);

            sql.CloseConnection(CommonData.dataBaseName);

            return(count);
        }
Exemple #6
0
        /// <summary>
        /// 获取当前词库已学习单词总数
        /// </summary>
        /// <returns>The current learned words count.</returns>
        private int GetCurrentLearnedWordsCount()
        {
            string tableName = GetCurrentLearningWordsTabelName();

            MySQLiteHelper sql = MySQLiteHelper.Instance;

            // 连接数据库
            sql.GetConnectionWith(CommonData.dataBaseName);

            if (!sql.CheckTableExist(tableName))
            {
                sql.CloseConnection(CommonData.dataBaseName);
                return(0);
            }

            // 查询当前学习的单词类型中的所有单词数量
            string[] learnedCondition = { "learnedTimes>0" };
            int      count            = sql.GetItemCountOfTable(tableName, learnedCondition, true);

            sql.CloseConnection(CommonData.dataBaseName);

            return(count);
        }
Exemple #7
0
        /// <summary>
        /// 更新单词数据库
        /// </summary>
        public void UpdateWordDataBase()
        {
            // 连接到数据库
            MySQLiteHelper sql = MySQLiteHelper.Instance;

            sql.GetConnectionWith(CommonData.dataBaseName);

            // 开启事务
            sql.BeginTransaction();

            // 获取当前单词的表单
            string currentWordsTableName = LearningInfo.Instance.GetCurrentLearningWordsTabelName();

            // 更新项
            string[] colFields = { "learnedTimes", "ungraspTimes", "isFamiliar" };

            HLHWord word = null;

            // 正确单词列表中所有单词数据更新进数据库
            for (int i = 0; i < correctWordList.Count; i++)
            {
                word = correctWordList[i];

                string familiarStr = word.isFamiliar ? "1" : "0";

                string[] conditions = { "wordId=" + word.wordId };
                string[] values     = { word.learnedTimes.ToString(), word.ungraspTimes.ToString(), familiarStr };
                sql.UpdateValues(currentWordsTableName, colFields, values, conditions, true);
            }

            // 错误单词列表中所有单词数据更新进数据库
            for (int i = 0; i < wrongWordList.Count; i++)
            {
                word = wrongWordList[i];

                string   familiarStr = word.isFamiliar ? "1" : "0";
                string[] conditions  = { "wordId=" + word.wordId };
                string[] values      = { word.learnedTimes.ToString(), word.ungraspTimes.ToString(), familiarStr };
                sql.UpdateValues(currentWordsTableName, colFields, values, conditions, true);
            }

            // 清理工作
            correctWordList.Clear();
            wrongWordList.Clear();

            sql.EndTransaction();

            sql.CloseConnection(CommonData.dataBaseName);
        }
        public static void InitSimpleLevelWords()
        {
            WordDataHelper wdh = new WordDataHelper();

            MySQLiteHelper sql = MySQLiteHelper.Instance;

            sql.GetConnectionWith(CommonData.dataBaseName, CommonData.originDataPath);

            wdh.WordsDataToDataBase(filePathOfSimpleLevelWords, CommonData.simpleWordsTable, sql);

            wdh.WordsDataToDataBase(filePathOfMediumLevelWords, CommonData.mediumWordsTabel, sql);

            wdh.WordsDataToDataBase(filePathOfMasterLevelWords, CommonData.masterWordsTabel, sql);

            sql.CloseConnection(CommonData.dataBaseName);
        }
        /// <summary>
        /// 持久化数据
        /// </summary>
        public void PersistData()
        {
            DirectoryInfo persistDi = new DirectoryInfo(CommonData.persistDataPath);

            IEnumerator initDataCoroutine = null;

            CheckDataModel checkData = new CheckDataModel();

            MySQLiteHelper sql = MySQLiteHelper.Instance;

            // 检查数据的完整性
            bool dataComplete = CheckDataComplete();

            // 如果原始玩家数据存在的话
            if (File.Exists(CommonData.playerDataFilePath))
            {
                // 记录原始玩家数据
                checkData.playerData = DataHandler.LoadDataToSingleModelWithPath <PlayerData>(CommonData.playerDataFilePath);
                checkData.playerData.needChooseDifficulty = false;

                if (ApplicationInfo.Instance != null)
                {
                    checkData.versionUpdate = ApplicationInfo.Instance.currentVersion + 0.001f < GameManager.Instance.currentVersion;
                }
                else
                {
                    checkData.versionUpdate = true;
                }
            }

            if (checkData.versionUpdate)
            {
                if (File.Exists(CommonData.dataBaseFilePath))
                {
                    sql.GetConnectionWith(CommonData.dataBaseName);

                    sql.BeginTransaction();

                    checkData.learnedWordsInSimple = GetWordRecordsInDataBase(sql, 0);
                    checkData.learnedWordsInMedium = GetWordRecordsInDataBase(sql, 1);
                    checkData.learnedWordsInMaster = GetWordRecordsInDataBase(sql, 2);

                    sql.EndTransaction();
                    sql.CloseConnection(CommonData.dataBaseName);
                }

                checkData.playerData.isNewPlayer = true;

                if (File.Exists(CommonData.buyRecordFilePath))
                {
                    checkData.buyRecord = BuyRecord.Instance;
                }

                if (File.Exists(CommonData.chatRecordsFilePath))
                {
                    checkData.chatRecords = GameManager.Instance.gameDataCenter.chatRecords;
                }

                if (File.Exists(CommonData.mapEventsRecordFilePath))
                {
                    checkData.mapEventsRecords = GameManager.Instance.gameDataCenter.mapEventsRecords;
                }

                if (File.Exists(CommonData.gameSettingsDataFilePath))
                {
                    checkData.gameSettings = GameManager.Instance.gameDataCenter.gameSettings;
                }

                if (File.Exists(CommonData.miniMapRecordFilePath))
                {
                    checkData.miniMapRecord = GameManager.Instance.gameDataCenter.currentMapMiniMapRecord;
                }
                if (File.Exists(CommonData.currentMapEventsRecordFilePath))
                {
                    checkData.currentMapEventsRecord = GameManager.Instance.gameDataCenter.currentMapEventsRecord;
                }
                if (File.Exists(CommonData.playRecordsFilePath))
                {
                    checkData.playRecords = GameManager.Instance.gameDataCenter.allPlayRecords;
                }
            }



#if UNITY_IOS
            if (!persistDi.Exists || checkData.versionUpdate || !dataComplete)
            {
                bool dataValidate = CheckDataValidate();

                if (!dataValidate)
                {
                    return;
                }

                GameManager.Instance.persistDataManager.BackUpDataWhenUpdataVersion(checkData);

                DataHandler.CopyDirectory(CommonData.originDataPath, CommonData.persistDataPath, true);

                if (!persistDi.Exists)
                {
                    OnNewInstall();
                }

                else if (checkData.versionUpdate || !dataComplete)
                {
                    GameManager.Instance.persistDataManager.versionUpdateWhenLoad = checkData.versionUpdate;

                    OnVersionUpdate(checkData, sql);
                }

                initDataCoroutine = InitData();

                StartCoroutine(initDataCoroutine);

                return;
            }
            else if (alwaysPersistData)
            {
                bool dataValidate = CheckDataValidate();

                if (!dataValidate)
                {
                    return;
                }

                GameManager.Instance.persistDataManager.BackUpDataWhenUpdataVersion(checkData);

                DataHandler.CopyDirectory(CommonData.originDataPath, CommonData.persistDataPath, true);

                if (!persistDi.Exists)
                {
                    OnNewInstall();
                }

                else if (checkData.versionUpdate || !dataComplete)
                {
                    GameManager.Instance.persistDataManager.versionUpdateWhenLoad = checkData.versionUpdate;

                    OnVersionUpdate(checkData, sql);
                }
            }

            initDataCoroutine = InitData();

            StartCoroutine(initDataCoroutine);
#elif UNITY_ANDROID
            if (!persistDi.Exists || checkData.versionUpdate || !dataComplete)
            {
                bool dataValidate = CheckDataValidate();

                if (!dataValidate)
                {
                    return;
                }

                GameManager.Instance.persistDataManager.BackUpDataWhenUpdataVersion(checkData);

                IEnumerator copyDataCoroutine = CopyDataForPersist(delegate {
                    if (!persistDi.Exists)
                    {
                        OnNewInstall();
                    }
                    else if (checkData.versionUpdate || !dataComplete)
                    {
                        GameManager.Instance.persistDataManager.versionUpdateWhenLoad = checkData.versionUpdate;
                        OnVersionUpdate(checkData, sql);
                    }
                });
                StartCoroutine(copyDataCoroutine);
                return;
            }
            else if (alwaysPersistData)
            {
                bool dataValidate = CheckDataValidate();

                if (!dataValidate)
                {
                    return;
                }

                if (DataHandler.DirectoryExist(CommonData.persistDataPath + "/Data"))
                {
                    DataHandler.DeleteDirectory(CommonData.persistDataPath + "/Data");
                }

                GameManager.Instance.persistDataManager.BackUpDataWhenUpdataVersion(checkData);

                IEnumerator copyDataCoroutine = CopyDataForPersist(delegate {
                    if (!persistDi.Exists)
                    {
                        OnNewInstall();
                    }
                    else if (checkData.versionUpdate || !dataComplete)
                    {
                        GameManager.Instance.persistDataManager.versionUpdateWhenLoad = checkData.versionUpdate;
                        OnVersionUpdate(checkData, sql);
                    }
                });
                StartCoroutine(copyDataCoroutine);
            }
            else
            {
                initDataCoroutine = InitData();

                StartCoroutine(initDataCoroutine);
            }
#endif
        }
        /// <summary>
        /// 版本更新时数据处理
        /// </summary>
        /// <param name="checkData">Check data.</param>
        /// <param name="sql">Sql.</param>
        private void OnVersionUpdate(CheckDataModel checkData, MySQLiteHelper sql)
        {
            //更新原始数据
            if (checkData.chatRecords != null && checkData.chatRecords.Count > 0)
            {
                DataHandler.SaveInstanceListToFile <HLHNPCChatRecord>(checkData.chatRecords, CommonData.chatRecordsFilePath);
            }
            if (checkData.mapEventsRecords != null && checkData.mapEventsRecords.Count > 0)
            {
                DataHandler.SaveInstanceListToFile <MapEventsRecord>(checkData.mapEventsRecords, CommonData.mapEventsRecordFilePath);
            }
            if (checkData.gameSettings != null)
            {
                DataHandler.SaveInstanceDataToFile <GameSettings>(checkData.gameSettings, CommonData.gameSettingsDataFilePath);
            }
            if (checkData.miniMapRecord != null)
            {
                DataHandler.SaveInstanceDataToFile <MiniMapRecord>(checkData.miniMapRecord, CommonData.miniMapRecordFilePath);
            }
            if (checkData.currentMapEventsRecord != null)
            {
                DataHandler.SaveInstanceDataToFile <CurrentMapEventsRecord>(checkData.currentMapEventsRecord, CommonData.currentMapEventsRecordFilePath);
            }
            if (checkData.playRecords != null)
            {
                DataHandler.SaveInstanceListToFile <PlayRecord>(checkData.playRecords, CommonData.playRecordsFilePath);
            }
            if (checkData.buyRecord != null)
            {
                DataHandler.SaveInstanceDataToFile <BuyRecord>(checkData.buyRecord, CommonData.buyRecordFilePath, true);
            }

            sql.GetConnectionWith(CommonData.dataBaseName);
            sql.BeginTransaction();

            if (checkData.learnedWordsInSimple.Count > 0)
            {
                Debug.Log(checkData.learnedWordsInSimple.Count);
                UpdateWordsDataBase(sql, 0, checkData.learnedWordsInSimple);
            }

            if (checkData.learnedWordsInMedium.Count > 0)
            {
                UpdateWordsDataBase(sql, 1, checkData.learnedWordsInMedium);
            }

            if (checkData.learnedWordsInMaster.Count > 0)
            {
                UpdateWordsDataBase(sql, 2, checkData.learnedWordsInMaster);
            }


            sql.EndTransaction();

            sql.CloseConnection(CommonData.dataBaseName);

            WordType wordType = WordType.Simple;

            if (checkData.gameSettings != null)
            {
                wordType = checkData.gameSettings.wordType;
            }

            // 更新版本信息
            ApplicationInfo.Instance.currentVersion = GameManager.Instance.currentVersion;

            DataHandler.SaveInstanceDataToFile <ApplicationInfo>(ApplicationInfo.Instance, CommonData.applicationInfoFilePath);

            if (checkData.playerData == null)
            {
                GameManager.Instance.persistDataManager.SaveCompletePlayerData();
                return;
            }

            if (checkData.playerData.currentExploreStartDateString == null ||
                checkData.playerData.currentExploreStartDateString == string.Empty)
            {
                string dateString = DateTime.Now.ToShortDateString();

                Player.mainPlayer.currentExploreStartDateString = dateString;

                checkData.playerData.currentExploreStartDateString = dateString;
            }

            // 更新单词数据
            if (checkData.playerData.maxWordContinuousRightRecord > 0)
            {
                switch (wordType)
                {
                case WordType.Simple:
                    Player.mainPlayer.maxSimpleWordContinuousRightRecord    = checkData.playerData.maxWordContinuousRightRecord;
                    checkData.playerData.maxSimpleWordContinuousRightRecord = checkData.playerData.maxWordContinuousRightRecord;
                    break;

                case WordType.Medium:
                    Player.mainPlayer.maxMediumWordContinuousRightRecord    = checkData.playerData.maxWordContinuousRightRecord;
                    checkData.playerData.maxMediumWordContinuousRightRecord = checkData.playerData.maxWordContinuousRightRecord;
                    break;

                case WordType.Master:
                    Player.mainPlayer.maxMasterWordContinuousRightRecord    = checkData.playerData.maxWordContinuousRightRecord;
                    checkData.playerData.maxMasterWordContinuousRightRecord = checkData.playerData.maxWordContinuousRightRecord;
                    break;
                }
                checkData.playerData.maxWordContinuousRightRecord = 0;
            }


            if (checkData.playerData.wordContinuousRightRecord > 0)
            {
                switch (wordType)
                {
                case WordType.Simple:
                    Player.mainPlayer.simpleWordContinuousRightRecord    = checkData.playerData.wordContinuousRightRecord;
                    checkData.playerData.simpleWordContinuousRightRecord = checkData.playerData.wordContinuousRightRecord;
                    break;

                case WordType.Medium:
                    Player.mainPlayer.mediumWordContinuousRightRecord    = checkData.playerData.wordContinuousRightRecord;
                    checkData.playerData.mediumWordContinuousRightRecord = checkData.playerData.wordContinuousRightRecord;
                    break;

                case WordType.Master:
                    Player.mainPlayer.masterWordContinuousRightRecord    = checkData.playerData.wordContinuousRightRecord;
                    checkData.playerData.masterWordContinuousRightRecord = checkData.playerData.wordContinuousRightRecord;
                    break;
                }
                checkData.playerData.wordContinuousRightRecord = 0;
            }

            if (checkData.playerData.titleQualifications != null)
            {
                bool hasOldVersionTitle = false;

                for (int i = 0; i < checkData.playerData.titleQualifications.Length; i++)
                {
                    if (checkData.playerData.titleQualifications[i])
                    {
                        hasOldVersionTitle = true;
                        break;
                    }
                }

                if (checkData.playerData.titleQualificationsOfSimple == null || checkData.playerData.titleQualificationsOfSimple.Length == 0)
                {
                    checkData.playerData.titleQualificationsOfSimple = new bool[] { false, false, false, false, false, false };
                }

                if (checkData.playerData.titleQualificationsOfMedium == null || checkData.playerData.titleQualificationsOfMedium.Length == 0)
                {
                    checkData.playerData.titleQualificationsOfMedium = new bool[] { false, false, false, false, false, false };
                }

                if (checkData.playerData.titleQualificationsOfMaster == null || checkData.playerData.titleQualificationsOfMaster.Length == 0)
                {
                    checkData.playerData.titleQualificationsOfMaster = new bool[] { false, false, false, false, false, false };
                }

                Player.mainPlayer.titleQualificationsOfSimple = checkData.playerData.titleQualificationsOfSimple;
                Player.mainPlayer.titleQualificationsOfMedium = checkData.playerData.titleQualificationsOfMedium;
                Player.mainPlayer.titleQualificationsOfMaster = checkData.playerData.titleQualificationsOfMaster;

                if (hasOldVersionTitle)
                {
                    switch (wordType)
                    {
                    case WordType.Simple:
                        Player.mainPlayer.titleQualificationsOfSimple    = checkData.playerData.titleQualifications;
                        checkData.playerData.titleQualificationsOfSimple = checkData.playerData.titleQualifications;
                        break;

                    case WordType.Medium:
                        Player.mainPlayer.titleQualificationsOfMedium    = checkData.playerData.titleQualifications;
                        checkData.playerData.titleQualificationsOfMedium = checkData.playerData.titleQualifications;
                        break;

                    case WordType.Master:
                        Player.mainPlayer.titleQualificationsOfMaster    = checkData.playerData.titleQualifications;
                        checkData.playerData.titleQualificationsOfMaster = checkData.playerData.titleQualifications;
                        break;
                    }
                    checkData.playerData.titleQualifications = new bool[] { false, false, false, false, false, false };
                }
            }

            DataHandler.SaveInstanceDataToFile <PlayerData>(checkData.playerData, CommonData.playerDataFilePath, true);
        }
Exemple #11
0
        // 从指定文件(txt/csv等文本文件)中读取数据 csv为从excel中导出的文本文件,导入unity之后需要选择结尾格式(mono里是这样的,在mono中打开csv文件后会有提示),否则在读取数据库时会报字段名不同的错误
//		private static void LoadWordsData(string dataPaths){
//
//			string itemsString = DataHandler.LoadDataString (dataPaths);
//
//			string[] stringsByLine = itemsString.Split (new string[]{ "\n" }, System.StringSplitOptions.RemoveEmptyEntries);
//
//			fieldNames = stringsByLine [0].Split (new char[]{ ',' });
//
//			for (int i = 1; i < stringsByLine.Length; i++) {
//				itemsProperties.Add(stringsByLine [i].Split (new char[]{ ',' }));
//			}
//
//		}



//		private void ToLower(){
//			MySQLiteHelper sql = MySQLiteHelper.Instance;
//			sql.GetConnectionWith (CommonData.dataBaseName);
//
//			string tableName = "AllWordsTable";
//
//			int wordsCount = sql.GetItemCountOfTable (tableName,null,true);
//
//			for (int i = 0; i < 37336; i++) {
//
//				IDataReader reader = sql.ReadSpecificRowsOfTable (
//					"AllWordsData",
//					"Spell",
//					new string[]{ string.Format ("Id={0}", i) },
//					true);
//				reader.Read ();
//
//				string spell = reader.GetString (0);
//
//				string lowerSpell = spell.ToLower ();
//
//				if (lowerSpell == spell) {
//					continue;
//				}
//
//				lowerSpell = lowerSpell.Replace("'","''");
//
//				sql.UpdateValues ("AllWordsData",
//					new string[]{ "Spell" },
//					new string[]{ string.Format("'{0}'",lowerSpell) },
//					new string[]{string.Format("Id = {0}",i)},
//					true);
//
//				reader.Close ();
//
//			}
//
//
//
//			sql.CloseConnection (CommonData.dataBaseName);
//		}

        private void MoveData()
        {
            MySQLiteHelper sql = MySQLiteHelper.Instance;

            sql.GetConnectionWith(CommonData.dataBaseName);

            sql.CreateTable("AllWordsData",
                            new string[] { "wordId", "Spell", "Explaination", "Valid" },
                            new string[] { "PRIMARY KEY NOT NULL", "UNIQUE NOT NULL", "NOT NULL", "NOT NULL", "NOT NULL" },
                            new string[] { "INTEGER", "TEXT", "TEXT", "INTEGER DEFAULT 1" });

            sql.DeleteAllDataFromTable("AllWordsData");

            IDataReader reader = null;
            int         pad    = 0;

            for (int i = 0; i < 39286; i++)
            {
                if (i == 34250)
                {
                    pad++;
                    continue;
                }

                reader = sql.ReadSpecificRowsOfTable("AllWords", "*",
                                                     new string[] { string.Format("ID={0}", i) },
                                                     true);

                reader.Read();



                int    id           = i - pad;
                string spell        = reader.GetString(1);
                string explaination = reader.GetString(2);
                int    type         = 0;
                int    valid        = 1;

                if (spell == string.Empty || explaination == string.Empty || spell == null || explaination == null)
                {
                    pad++;
                    continue;
                }

                spell        = spell.Replace("'", "''");
                explaination = explaination.Replace("'", "''");

                sql.InsertValues("AllWordsData",
                                 new string[] { id.ToString(),
                                                "'" + spell + "'",
                                                "'" + explaination + "'",
                                                type.ToString(),
                                                valid.ToString() });

                reader.Close();
            }


            Debug.Log("Finished");

            sql.CloseConnection(CommonData.dataBaseName);
        }
Exemple #12
0
        public static void BuildItemsDataBase()
        {
            MySQLiteHelper sql = MySQLiteHelper.Instance;

            sql.GetConnectionWith(CommonData.dataBaseName, "/Users/houlianghong/Desktop/Unityfolder/TestOnSkills/Assets/StreamingAssets/Data");



            //		sql.CreatTable (CommonData.itemsTable,
            //			new string[] {"itemId","itemName","itemGeneralDescription","spriteName","itemType","itemNameInEnglish",
            //				"attackGain","powerGain","magicGain","critGain","armorGain","manaResistGain",
            //				"dodgeGain","healthGain","strengthGain"},
            //			new string[] {"PRIMARY Key","UNIQUE NOT NULL","NOT NULL","NOT NULL","","UNIQUE","","","","","","","","",""},
            //			new string[] {"INTEGER","TEXT","TEXT","TEXT","INTEGER","TEXT","INTEGER","INTEGER","INTEGER",
            //				"INTEGER","INTEGER","INTEGER","INTEGER","INTEGER","INTEGER" });
            //
            //		int[] stringTypeCols = new int[]{ 1, 2, 3, 5 };
            //
            //		itemsProperties.Clear ();
            //
            //		LoadItemsData ("itemsData.csv");
            //
            //		sql.CheckFiledNames (CommonData.itemsTable,fieldNames);
            //
            //		sql.DeleteAllDataFromTable (CommonData.itemsTable);
            //
            //		for(int i = 0;i<itemsProperties.Count;i++){
            //			string[] values = itemsProperties [i];
            //
            //			foreach (int j in stringTypeCols) {
            //				values [j] = "'" + values[j] + "'";
            //
            //			}
            //
            //			sql.InsertValues (CommonData.itemsTable, values);
            //		}
            //
            if (sql.CheckTableExist(CommonData.CET4Table))
            {
                sql.DeleteTable(CommonData.CET4Table);
            }

            sql.CreateTable(CommonData.CET4Table,
                            new string[] { "wordId", "spell", "phoneticSymbol", "explaination", "example", "learnedTimes", "ungraspTimes" },
                            new string[] { "PRIMARY KEY NOT NULL", "NOT NULL", "NOT NULL", "NOT NULL", "NOT NULL", "NOT NULL", "NOT NULL" },
                            new string[] { "INTEGER", "TEXT", "TEXT", "TEXT", "TEXT", "INTEGER DEFAULT 0", "INTEGER DEFAULT 0" });

//			sql.CreateTable (CommonData.CET4Table,
//				new string[]{ "wordId", "spell", "phoneticSymbol", "explaination", "example","learnedTimes","ungraspTimes" },
//				new string[]{ "PRIMARY KEY NOT NULL", "UNIQUE NOT NULL", "", "NOT NULL", "","",""},
//				new string[]{ "INTEGER", "TEXT", "TEXT", "TEXT", "TEXT","INTEGER DEFAULT 0","INTEGER DEFAULT 0" });


            // 为单词表创建索引,以id为索引
            sql.CreateIndex("wordId_index", CommonData.CET4Table, new string[] { "wordId" }, true);
            // 为单词表创建索引,以学习次数为索引
            sql.CreateIndex("learnedTimes_index", CommonData.CET4Table, new string[] { "learnedTimes" }, false);
            // 为单词表创建索引,以点击 不熟悉&选错 的次数 为索引
            sql.CreateIndex("ungraspTimes_index", CommonData.CET4Table, new string[] { "ungraspTimes" }, false);


            int[] stringTypeCols = new int[] { 1, 2, 3, 4 };

            itemsProperties.Clear();

            LoadCET4WordsData();

//			sql.CheckFiledNames (CommonData.CET4Table, fieldNames);

            sql.BeginTransaction();

            for (int i = 0; i < itemsProperties.Count; i++)
            {
                string[] values = itemsProperties [i];

                foreach (int j in stringTypeCols)
                {
//					string sqliteStr = SqliteEscape (values [j]);
                    string sqliteStr = values [j];
                    values [j] = "'" + sqliteStr + "'";
                }

                sql.InsertValues(CommonData.CET4Table, values);
            }

            sql.EndTransaction();

            sql.CloseConnection(CommonData.dataBaseName);
        }
        /// <summary>
        /// 初始化指定数量的未学习单词
        /// 使用该方法需注意
        /// </summary>
        /// <returns>The learn words in map.</returns>
        public HLHWord[] GetUnlearnedWordsOfCount(int count)
        {
            MySQLiteHelper mySql = MySQLiteHelper.Instance;

            mySql.GetConnectionWith(CommonData.dataBaseName);

            HLHWord[] words = new HLHWord[count];

            string currentWordsTableName = LearningInfo.Instance.GetCurrentLearningWordsTabelName();

            string query = string.Format("SELECT learnedTimes FROM {0} ORDER BY learnedTimes ASC", currentWordsTableName);

            IDataReader reader = mySql.ExecuteQuery(query);

            reader.Read();

            int wholeLearnTime = reader.GetInt16(0);

            query = string.Format("SELECT COUNT(*) FROM {0} WHERE learnedTimes=ungraspTimes AND learnedTimes>0", currentWordsTableName);

            reader = mySql.ExecuteQuery(query);

            reader.Read();

            int wrongWordCount = reader.GetInt32(0);

            if (wrongWordCount >= count)
            {
                query = string.Format("SELECT * FROM {0} WHERE learnedTimes=ungraspTimes AND learnedTimes>0 LIMIT {1}", currentWordsTableName, count);

                int index = 0;

                reader = mySql.ExecuteQuery(query);

                for (int i = 0; i < count; i++)
                {
                    reader.Read();

                    HLHWord word = HLHWord.GetWordFromReader(reader);

                    words[index] = word;

                    index++;
                }
            }
            else
            {
                query = string.Format("SELECT COUNT(*) FROM {0} WHERE learnedTimes={1}", currentWordsTableName, wholeLearnTime);

                reader = mySql.ExecuteQuery(query);

                reader.Read();

                int validWordCount = reader.GetInt32(0);

                if (validWordCount < count - wrongWordCount)
                {
                    string[] colFields  = { "learnedTimes" };
                    string[] values     = { (wholeLearnTime + 1).ToString() };
                    string[] conditions = { "learnedTimes=" + wholeLearnTime.ToString() };

                    mySql.UpdateValues(currentWordsTableName, colFields, values, conditions, true);

                    wholeLearnTime++;
                }

                int index = 0;

                //Debug.Log(wrongWordCount);

                query = string.Format("SELECT * FROM {0} WHERE learnedTimes=ungraspTimes AND learnedTimes>0 LIMIT {1}", currentWordsTableName, wrongWordCount);

                reader = mySql.ExecuteQuery(query);

                for (int i = 0; i < wrongWordCount; i++)
                {
                    reader.Read();

                    HLHWord word = HLHWord.GetWordFromReader(reader);

                    words[index] = word;

                    index++;
                }

                // 边界条件
                string[] condition = { string.Format("learnedTimes={0} ORDER BY RANDOM() LIMIT {1}", wholeLearnTime, count - wrongWordCount) };

                reader = mySql.ReadSpecificRowsOfTable(currentWordsTableName, null, condition, true);

                while (reader.Read())
                {
                    HLHWord word = HLHWord.GetWordFromReader(reader);

                    words[index] = word;

                    index++;
                }
            }

            mySql.CloseConnection(CommonData.dataBaseName);


            return(words);
        }