Пример #1
0
        /// <summary>
        /// 获取所有排序后的符合条件的数据表行。
        /// </summary>
        /// <param name="condition" > 要检查的条件。</param>
        /// <param name="comparison" > 要排序的条件。</param>
        /// <returns>所有排序后的符合条件的数据表行。</returns>
        public DTMySQL_MyTest[] GetAllDataRows(System.Predicate <DTMySQL_MyTest> condition, System.Comparison <DTMySQL_MyTest> comparison)
        {
            if (condition == null)
            {
                throw new System.Exception("Condition is invalid.");
            }

            if (comparison == null)
            {
                throw new System.Exception("Comparison is invalid.");
            }

            List <DTMySQL_MyTest> results = new List <DTMySQL_MyTest>();

            foreach (var dataRow in _dict)
            {
                DTMySQL_MyTest dr = dataRow.Value;
                if (condition(dr))
                {
                    results.Add(dr);
                }
            }

            results.Sort(comparison);
            return(results.ToArray());
        }
Пример #2
0
 public void CloneButId(DTMySQL_MyTest c)
 {
     Name      = c.Name;
     ClassName = c.ClassName;
     Info      = c.Info;
     Score     = c.Score;
 }
Пример #3
0
        public void CloneAll(DTMySQL_MyTest c)
        {
            Id = c.Id;

            Name = c.Name;

            ClassName = c.ClassName;

            Info = c.Info;

            Score = c.Score;
        }
Пример #4
0
        /// <summary>
        /// 获取所有数据表行。
        /// </summary>
        /// <returns>所有数据表行。</returns>
        public DTMySQL_MyTest[] GetAllDataRows()
        {
            int index = 0;

            DTMySQL_MyTest[] allDataRows = new DTMySQL_MyTest[Count];
            foreach (var dataRow in _dict)
            {
                allDataRows[index++] = dataRow.Value;
            }

            return(allDataRows);
        }
Пример #5
0
        public static List <DTMySQL_MyTest> LoadBy_MySQLComText(string commandText)
        {
            List <DTMySQL_MyTest> testTempList = new List <DTMySQL_MyTest>();

            UnityEngine.Debug.Log("Load: " + commandText);
            System.Data.DataTable dt = DatabaseManager.GetInstance().GetSQLSelectDataTable(commandText);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (System.Data.DataRow dr in dt.Rows)
                {
                    DTMySQL_MyTest temp = new DTMySQL_MyTest(dr);
                    testTempList.Add(temp);
                }
            }

            return(testTempList);
        }
Пример #6
0
        /// <summary>
        /// 获取符合条件的数据表行。
        /// </summary>
        /// <param name="condition" > 要检查的条件。</param>
        /// <returns>符合条件的数据表行。</returns>
        /// <remarks>当存在多个符合条件的数据表行时,仅返回第一个符合条件的数据表行。</remarks>
        public DTMySQL_MyTest GetDataRow(System.Predicate <DTMySQL_MyTest> condition)
        {
            if (condition == null)
            {
                throw new System.Exception("Condition is invalid.");
            }

            foreach (var dataRow in _dict)
            {
                DTMySQL_MyTest dr = dataRow.Value;
                if (condition(dr))
                {
                    return(dr);
                }
            }

            return(null);
        }
Пример #7
0
        /// <summary>
        /// Do reload the dataTable file: MyTest
        /// </summary>
        internal void ReloadAll(bool throwWhenDuplicatePrimaryKey, string customContent = null)
        {
            for (var j = 0; j < TabFilePaths.Length; j++)
            {
                var       tabFilePath = TabFilePaths[j];
                TableFile tableFile;
                if (customContent == null)
                {
                    tableFile = DTMySqlModule.Get(tabFilePath, false);
                }
                else
                {
                    tableFile = TableFile.LoadFromString(customContent);
                }

                using (tableFile)
                {
                    foreach (var row in tableFile)
                    {
                        DTMySQL_MyTest dataTable;
                        dataTable = new DTMySQL_MyTest(row);
                        if (!_dict.ContainsKey(dataTable.Id))
                        {
                            dataTable.UpdateToMySQL();
                            _dict[dataTable.Id] = dataTable;
                        }
                        else
                        {
                            if (throwWhenDuplicatePrimaryKey)
                            {
                                throw new System.Exception(string.Format("DuplicateKey, Class: {0}, File: {1}, Key: {2}", this.GetType().Name, tabFilePath, "Id"));
                            }
                            else
                            {
                                dataTable.Reload(row);
                            }
                        }
                    }
                }
            }
            //UnityEngine.Debug.LogFormat("Reload dataTables: {0}, Row Count: {1}, Reload Count: {2}", GetType(), Count);
        }