Esempio n. 1
0
        public static void Delete(string timeStamp)
        {
            TestPosition test = null;

            for (int i = 0, maxi = (null == gTestPositions ? 0 : gTestPositions.Count); i < maxi; i++)
            {
                TestPosition testPosition = gTestPositions[i];
                if (testPosition.time.Equals(timeStamp))
                {
                    test = testPosition;
                    break;
                }
            }
            if (null != test)
            {
                gTestPositions.Remove(test);
            }

            try
            {
                MysqlUtil.Execute(string.Format(MYSQL_DELETE, timeStamp), MysqlConnection);
            }
            catch
            {
                Logger.DebugFormat("Delete failed !");
            }
        }
Esempio n. 2
0
        public static void Add(Vector3 position, float rotation, string timeStamp)
        {
            DataRecord dataRecord = new DataRecord();

            dataRecord.AddField(FIELD_MAP_ID, MapId.ToString());
            dataRecord.AddField(FIELD_POSITION_TYPE, Type);
            dataRecord.AddField(FIELD_X, position.x.ToString());
            dataRecord.AddField(FIELD_Y, position.y.ToString());
            dataRecord.AddField(FIELD_Z, position.z.ToString());
            dataRecord.AddField(FIELD_ROTATION, rotation.ToString());
            dataRecord.AddField(FIELD_TIME, timeStamp);
            MysqlUtil.Add(dataRecord, TABLE, MysqlConnection);

            if (!Exsit(timeStamp))
            {
                TestPosition testPosition = new TestPosition();
                testPosition.mapId    = MapId.ToString();
                testPosition.type     = Type;
                testPosition.x        = position.x;
                testPosition.y        = position.y;
                testPosition.z        = position.z;
                testPosition.rotation = rotation;
                testPosition.time     = timeStamp;
                gTestPositions.Add(testPosition);
            }
        }
Esempio n. 3
0
        private void setCourseById()
        {
            string  sql    = string.Format("select * from t_course where id={0}", commodityID);
            DataRow reader = MysqlUtil.GetDataRow(sql);

            this.c_id.Text    = reader["cid"].ToString();
            this.c_name.Text  = reader["cname"].ToString();
            this.c_marke.Text = reader["remake"].ToString();
        }
Esempio n. 4
0
        public override void DoAction(IEventArgs args)
        {
            DataRecord dr = new DataRecord();

            dr.AddField("time", DateTime.Now.Ticks.ToString());
            dr.AddField("key", key);
            dr.AddField("message", FreeUtil.ReplaceVar(message, args));
            MysqlUtil.Add(dr, "simple_log", FreeRuleConfig.MysqlConnection);
        }
Esempio n. 5
0
        private void SetcombocClass()
        {
            //select * from t_course;
            string sql = string.Format("select * from t_course");

            DataTable reader = MysqlUtil.GetDataTable(sql);

            this.s_course.DataSource    = reader;
            this.s_course.ValueMember   = "cid";   //用于修改
            this.s_course.DisplayMember = "cname"; //显示课程名称
            this.s_course.SelectedIndex = -1;      //便于搜索
        }
Esempio n. 6
0
 private static void IniDesc()
 {
     if (descDic == null)
     {
         descDic = new Dictionary <int, string>();
         List <DataRecord> list = MysqlUtil.SelectRecords("select * from text_lang", FreeRuleConfig.MysqlConnection);
         foreach (DataRecord dr in list)
         {
             descDic.Add(int.Parse(dr.GetValue("id")), dr.GetValue("text"));
         }
     }
 }
Esempio n. 7
0
        private static void Initial()
        {
            if (dic == null)
            {
                dic = new Dictionary <int, string>();

                List <DataRecord> list = MysqlUtil.SelectRecords("select * from rule_replace", FreeRuleConfig.MysqlConnection);
                foreach (DataRecord dr in list)
                {
                    dic.Add(int.Parse(dr.GetValue("race")), dr.GetValue("free"));
                }
            }
        }
Esempio n. 8
0
        protected static void RecordMultiResult(CaseKey key, TestValue[] tvs, string table)
        {
            DataRecord dr = new DataRecord();

            dr.AddField("rule", key.rule);
            dr.AddField("suit", key.suit);
            dr.AddField("case", key.caseName);
            dr.AddField("field", tvs[0].Name);
            dr.AddField("value", TestValue.ToRecords(tvs));

            Debug.LogFormat("table:{0}, dr:{1}", table, dr);

            MysqlUtil.Add(dr, table, FreeRuleConfig.MysqlConnection);
        }
Esempio n. 9
0
        /// <summary>
        /// 获取选中数据库的数据表列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DatabaseListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            _tableList = null;

            if (DatabaseListBox.SelectedItem == null)
            {
                return;
            }

            string selectedDatabase = DatabaseListBox.SelectedItem.ToString();

            if (string.IsNullOrWhiteSpace(selectedDatabase))
            {
                return;
            }

            _databaseNameStr = selectedDatabase;


            try
            {
                var useDatabaseCmd = MysqlUtil.GetSqlCommand($"use {_databaseNameStr};", _mySqlConnection);

                useDatabaseCmd.ExecuteNonQuery();

                var sqlCmd = MysqlUtil.GetSqlCommand("show tables;", _mySqlConnection);

                _tableList = new List <string>();
                using (MySqlDataReader mySqlDataReader = sqlCmd.ExecuteReader())
                {
                    while (mySqlDataReader.Read())
                    {
                        if (mySqlDataReader.HasRows)
                        {
                            string tableName = mySqlDataReader.GetString(0);
                            _tableList.Add(tableName);
                        }
                    }
                }

                TableListBox.ItemsSource = _tableList;
            }
            catch (Exception exception)
            {
                MessageBox.Show("获取数据表信息失败," + exception.Message);
            }
        }
Esempio n. 10
0
        public static string GetRuleXml(string name, bool mysql)
        {
            if (mysql)
            {
                List <DataRecord> list = MysqlUtil.SelectRecords("select * from rule where `key` = '" + name + "'", MysqlConnection);
                if (list.Count > 0)
                {
                    return(RemoveComment(list[0].GetValue("config")));
                }
            }
            else
            {
                return(RemoveComment(GetFileContent(Application.dataPath + "/Config/Server/Rule/" + name + ".xml", Encoding.UTF8)));
            }

            return("");
        }
Esempio n. 11
0
        private string GetBeanClassReturnString(TableModel tableModel)
        {
            List <ColumnModel> columnModels = tableModel.ColumnModels;
            StringBuilder      sb           = new StringBuilder();

            string tableName = MysqlUtil.GetModelColumnName(tableModel.TableName);
            char   firstChar = tableName[0];

            if (firstChar >= 'a' && firstChar <= 'z')
            {
                firstChar = (char)(firstChar - 32);
                tableName = firstChar + tableName.Substring(1);
            }

            sb.AppendLine("@Data");
            sb.AppendLine("@AllArgsConstructor");
            sb.AppendLine("@NoArgsConstructor");
            sb.AppendLine($"@Table(name = \"{tableModel.TableName}\")");


            sb.Append($"public class {tableName}");
            sb.AppendLine("{");
            foreach (var columnModel in columnModels)
            {
                if (string.IsNullOrWhiteSpace(columnModel.DataType))
                {
                    continue;
                }

                string dataType      = MysqlUtil.GetMappedType(columnModel.DataType);
                string attributeLine = $"\t@Column(name = \"{columnModel.OriginalColumnName}\")";
                string fieldLine     = $"\tprivate {dataType} {columnModel.NewColumnName};";
                if (columnModel.IsPrimaryKey)
                {
                    sb.AppendLine("\t@Id");
                }
                sb.AppendLine(attributeLine);
                sb.AppendLine(fieldLine);
                sb.AppendLine();
            }

            sb.AppendLine("}");

            return(sb.ToString());
        }
Esempio n. 12
0
        private void ChooseTable(string selectedTableName)
        {
            string selectColumnNameSql =
                $"SELECT column_name, data_type, column_key FROM information_schema.columns WHERE table_schema='{_databaseNameStr}' AND table_name='{selectedTableName}';";
            var sqlCmd = MysqlUtil.GetSqlCommand(selectColumnNameSql, _mySqlConnection);

            List <ColumnModel> columnModels = new List <ColumnModel>();

            try
            {
                using (var dataReader = sqlCmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        if (dataReader.HasRows)
                        {
                            string originalName = dataReader.GetString(0);
                            originalName = originalName.ToLower();
                            string dataTypeStr = dataReader.GetString(1);
                            string columnKey   = dataReader.GetString(2);

                            string      newColumnName = MysqlUtil.GetModelColumnName(originalName);
                            ColumnModel columnModel   = new ColumnModel(originalName, newColumnName, dataTypeStr);

                            if (!string.IsNullOrWhiteSpace(columnKey) || "PRI".Equals(columnKey.ToUpper()))
                            {
                                columnModel.IsPrimaryKey = true;
                            }
                            columnModels.Add(columnModel);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("获取表信息失败,错误原因:" + exception.Message);
            }

            TableModel tableModel = new TableModel(selectedTableName, columnModels);

            SetMessageTxtBox(tableModel);
        }
Esempio n. 13
0
        public static void Initial(bool mysql)
        {
            dic.Clear();
            if (mysql)
            {
                List <DataRecord> list = MysqlUtil.SelectRecords("select * from rule_replace", FreeRuleConfig.MysqlConnection);
                foreach (DataRecord dr in list)
                {
                    dic.Add(int.Parse(dr.GetValue("race")), dr.GetValue("free"));
                }
                return;
            }

            string     path = Application.dataPath + "/Config/Server/Rule/rule_replace.xml";
            FileStream fs   = null;

            try
            {
                XmlSerializer xs = new XmlSerializer(typeof(RuleMapConfig));
                fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                RuleMapConfig ruleMapConfig = (RuleMapConfig)xs.Deserialize(fs);

                if (null != ruleMapConfig)
                {
                    foreach (RuleMapConfigItem ruleMapConfigItem in ruleMapConfig.items)
                    {
                        dic[ruleMapConfigItem.race] = ruleMapConfigItem.free;
                    }
                }

                fs.Close();
            }
            catch (Exception e)
            {
                if (fs != null)
                {
                    fs.Close();
                }
                _logger.Error("error : " + e.ToString());
            }
        }
Esempio n. 14
0
        private void AddCourse()
        {
            int result = MysqlUtil.DoInsert("t_course",
                                            new string[] { "cid", "cname", "remake" },
                                            new object[] { c_id.Text.Trim(), c_name.Text.Trim(), c_marke.Text.Trim() }
                                            );

            if (result == 1)
            {
                MessageBox.Show("添加成功", "系统提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                //添加成功后置空表单
                this.setNull();
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败", "系统提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 15
0
        private void EditCourse()
        {
            int result = MysqlUtil.DoUpdate("t_course",
                                            new string[] { "cid", "cname", "remake" },
                                            new object[] { c_id.Text.Trim(), c_name.Text.Trim(), c_marke.Text.Trim() },
                                            new string[] { "id" },
                                            new object[] { this.commodityID }
                                            );

            if (result == 1)
            {
                MessageBox.Show("修改成功", "系统提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                //添加成功后置空表单
                this.Close();
            }
            else
            {
                MessageBox.Show("修改失败", "系统提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 16
0
        private void EditPassword()
        {
            int result = MysqlUtil.DoUpdate(
                "t_user",
                new string[] { "password" },
                new object[] { new_password.Text.Trim() },
                new string[] { "id" },
                new object[] { user.Id }
                );

            if (result == 1)
            {
                MessageBox.Show("修改成功", "系统提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                MessageBox.Show("修改失败。", "系统提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 17
0
        private void AddStudent()
        {
            string sex    = radio_boy.Checked ? "男" : "女";
            int    result = MysqlUtil.DoInsert("t_students",
                                               new string[] { "sid", "sname", "sex", "age", "major", "cid", "class_id" },
                                               new object[] { stu_id.Text.Trim(), stu_name.Text.Trim(), sex, Convert.ToInt32(stu_age.Text.Trim()), stu_major.Text.Trim(), stu_course.SelectedValue, Convert.ToInt32(stu_class.Text.Trim()) }
                                               );

            if (result == 1)
            {
                MessageBox.Show("添加成功", "系统提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                //添加成功后置空表单
                this.SetNull();
                this.Close();
            }
            else
            {
                MessageBox.Show("添加失败", "系统提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 18
0
        private static void Initial()
        {
            if (correct == null)
            {
                correct = new Dictionary <CaseKey, TestValue[]>();
                wrong   = new Dictionary <CaseKey, TestValue[]>();

                List <DataRecord> list = MysqlUtil.SelectRecords("select * from " + TableCorrect, FreeRuleConfig.MysqlConnection);
                foreach (DataRecord dr in list)
                {
                    CaseKey ck = new CaseKey();
                    ck.rule     = dr.GetValue("rule");
                    ck.suit     = dr.GetValue("suit");
                    ck.caseName = dr.GetValue("case");
                    ck.field    = dr.GetValue("field");

                    if (!correct.ContainsKey(ck))
                    {
                        correct.Add(ck, TestValue.RecordsFromString(dr.GetValue("value")));
                    }
                }

                list = MysqlUtil.SelectRecords("select * from " + TableWrong, FreeRuleConfig.MysqlConnection);
                foreach (DataRecord dr in list)
                {
                    CaseKey ck = new CaseKey();
                    ck.rule     = dr.GetValue("rule");
                    ck.suit     = dr.GetValue("suit");
                    ck.caseName = dr.GetValue("case");
                    ck.field    = dr.GetValue("field");

                    if (!correct.ContainsKey(ck))
                    {
                        wrong.Add(ck, TestValue.RecordsFromString(dr.GetValue("value")));
                    }
                }
            }
        }
Esempio n. 19
0
        private void setStuById()
        {
            //初始化课程信息下拉列表
            SetComboCourse();
            string  sql    = string.Format("select * from t_students where sid={0}", commodityID);
            DataRow reader = MysqlUtil.GetDataRow(sql);

            this.stu_id.Text   = reader["sid"].ToString();
            this.stu_name.Text = reader["sname"].ToString();
            //判断性别单选框是否选中
            if (reader["sex"].ToString() == "男")
            {
                this.radio_boy.Checked = true;
            }
            else
            {
                this.radio_girl.Checked = true;
            }
            this.stu_major.Text           = reader["major"].ToString();
            this.stu_age.Value            = Convert.ToDecimal(reader["age"]); //18
            this.stu_course.SelectedValue = reader["cid"].ToString();
            this.stu_class.Value          = Convert.ToDecimal(reader["class_id"]);
        }
Esempio n. 20
0
        public override void DoAction(IEventArgs args)
        {
            List <DataRecord> list = MysqlUtil.SelectRecords("select * from realtime_rule where `rule` = '" + args.Rule.FreeType + "'", FreeRuleConfig.MysqlConnection);

            if (list.Count > 0)
            {
                string config = list[0].GetValue("config");
                if (!string.IsNullOrEmpty(config))
                {
                    object obj = FreeRuleConfig.XmlToObject(config);
                    if (obj is IGameAction)
                    {
                        if (obj is OrderAiAction)
                        {
                            ((IGameAction)obj).Reset(args);
                        }
                        else
                        {
                            ((IGameAction)obj).Act(args);
                        }
                    }
                }
            }
        }
Esempio n. 21
0
        private List <DataRecord> GetRecords()
        {
            List <DataRecord> records = MysqlUtil.SelectRecords(string.Format(SQL, map, type), FreeRuleConfig.MysqlConnection);

            return(records);
        }
Esempio n. 22
0
        public static List <DataRecord> GetAllDataRecord()
        {
            List <DataRecord> list = MysqlUtil.SelectRecords(MYSQL_GET_ALL, MysqlConnection);

            return(list);
        }
Esempio n. 23
0
        private void OpenDbSource(string connectionStr, bool addToList = true)
        {
            ConnectionModel connectionModel = ConnectionUtils.GetConnectionModel(connectionStr);

            if (null == connectionModel)
            {
                MessageBox.Show("打开数据库失败,连接为:" + connectionStr);
                return;
            }

            DatabaseListBox.ItemsSource = null;
            TableListBox.ItemsSource    = null;
            MessageTxtBox.Text          = null;

            try
            {
                string connectIp   = connectionModel.RemoteIp;
                int    connectPort = connectionModel.Port;
                string userName    = connectionModel.UserName;
                string userPass    = connectionModel.UserPass;

                string dbSourceStr =
                    $"Data Source={connectIp};User Id={userName};Password={userPass};pooling=false;CharSet=utf8;port={connectPort}";

                List <string> databaseNames = new List <string>();

                // 打开之前先关闭已经打开的连接
                CloseMysqlConnection();


                _mySqlConnection = MysqlUtil.GetMySqlConnection(dbSourceStr);
                var sqlCmd = MysqlUtil.GetSqlCommand("show databases;", _mySqlConnection);
                _mySqlConnection.Open();

                try
                {
                    using (MySqlDataReader mySqlDataReader = sqlCmd.ExecuteReader())
                    {
                        while (mySqlDataReader.Read())
                        {
                            if (mySqlDataReader.HasRows)
                            {
                                string tableName = mySqlDataReader.GetString(0);
                                databaseNames.Add(tableName);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("打开数据库失败," + e.Message);
                    return;
                }


                _tableList = databaseNames;
                DatabaseListBox.ItemsSource = _tableList; // 显示数据库列表
            }
            catch (Exception e)
            {
                MessageBox.Show("连接数据库失败,错误信息:" + e.Message);
                return;
            }

            // 添加进列表(使用打开功能的话就加,listbox的selectionChanged就不加)
            if (addToList)
            {
                ConnectionUtils.AddConnection(connectionStr);

                LoadConnectionList();
            }
        }
Esempio n. 24
0
        public static int IniTable(int mapId, string type)
        {
            gRecordMap.Clear();
            gTestPositions.Clear();

            Type  = type;
            MapId = mapId;

            int result = -1;

            try {
                result = MysqlUtil.Execute(MYSQL_CREATE_TABLE, MysqlConnection);
            } catch {
                Logger.DebugFormat("CreateTable failed and result is {0} !", result);
            }

            List <DataRecord> list = GetAllDataRecord();

            foreach (DataRecord record in list)
            {
                TestPosition testPosition = new TestPosition();
                if (record.Contains(FIELD_MAP_ID))
                {
                    testPosition.mapId = record.GetValue(FIELD_MAP_ID);
                }
                if (record.Contains(FIELD_POSITION_TYPE))
                {
                    testPosition.type = record.GetValue(FIELD_POSITION_TYPE);
                }
                if (record.Contains(FIELD_X))
                {
                    testPosition.x = float.Parse(record.GetValue(FIELD_X));
                }
                if (record.Contains(FIELD_Y))
                {
                    testPosition.y = float.Parse(record.GetValue(FIELD_Y));
                }
                if (record.Contains(FIELD_Z))
                {
                    testPosition.z = float.Parse(record.GetValue(FIELD_Z));
                }
                if (record.Contains(FIELD_ROTATION))
                {
                    testPosition.rotation = float.Parse(record.GetValue(FIELD_ROTATION));
                }
                if (record.Contains(FIELD_TIME))
                {
                    testPosition.time = record.GetValue(FIELD_TIME);
                }

                Dictionary <string, List <TestPosition> > typeDict = null;
                List <TestPosition> testPositions = null;
                if (!gRecordMap.TryGetValue(testPosition.mapId, out typeDict))
                {
                    typeDict = new Dictionary <string, List <TestPosition> >();
                    gRecordMap[testPosition.mapId] = typeDict;
                }

                if (!typeDict.TryGetValue(testPosition.type, out testPositions))
                {
                    testPositions = new List <TestPosition>();
                    typeDict[testPosition.type] = testPositions;
                }

                if (mapId.ToString().Equals(testPosition.mapId) &&
                    type.Equals(testPosition.type))
                {
                    gTestPositions = testPositions;
                }

                testPositions.Add(testPosition);
            }

            return(result);
        }
Esempio n. 25
0
        public static void Initial()
        {
            if (dropDic == null)
            {
                dropDic   = new MyDictionary <int, CatPriority>();
                catDic    = new MyDictionary <string, ItemPriority>();
                extraDic  = new MyDictionary <int, MyDictionary <int, CatPriority> >();
                rangeDic  = new MyDictionary <int, DropRange>();
                dropCache = new Dictionary <int, List <ItemDrop> >();

                List <DataRecord> dropList = MysqlUtil.SelectRecords("select * from new_item_drop", FreeRuleConfig.MysqlConnection);
                foreach (DataRecord dr in dropList)
                {
                    int    id    = int.Parse(dr.GetValue("id"));
                    string range = dr.GetValue("range");
                    string drop  = dr.GetValue("drop");
                    string count = dr.GetValue("count");

                    rangeDic[id] = new DropRange(range, count);
                    dropDic[id]  = new CatPriority(drop);
                }

                List <DataRecord> catList = MysqlUtil.SelectRecords("select * from new_drop_cat", FreeRuleConfig.MysqlConnection);
                MyDictionary <string, List <DataRecord> > catMap = new MyDictionary <string, List <DataRecord> >();
                foreach (DataRecord dr in catList)
                {
                    string cat = dr.GetValue("cat");
                    if (!catMap.ContainsKey(cat))
                    {
                        catMap[cat] = new List <DataRecord>();
                    }

                    catMap[cat].Add(dr);
                }
                foreach (string key in catMap.Keys)
                {
                    List <DataRecord> list = catMap[key];

                    int[] cats = new int[list.Count];
                    int[] ids  = new int[list.Count];
                    int[] ps   = new int[list.Count];
                    int[] cs   = new int[list.Count];

                    for (int i = 0; i < list.Count; i++)
                    {
                        cats[i] = int.Parse(list[i].GetValue("itemCat"));
                        ids[i]  = int.Parse(list[i].GetValue("itemId"));
                        ps[i]   = int.Parse(list[i].GetValue("priority"));
                        cs[i]   = int.Parse(list[i].GetValue("count"));
                    }

                    catDic[key] = new ItemPriority(cats, ids, ps, cs);
                }

                List <DataRecord> extraList = MysqlUtil.SelectRecords("select * from new_item_extra", FreeRuleConfig.MysqlConnection);
                foreach (DataRecord dr in extraList)
                {
                    int    item = int.Parse(dr.GetValue("item"));
                    int    cat  = int.Parse(dr.GetValue("cat"));
                    string drop = dr.GetValue("extraDrop");
                    if (!extraDic.ContainsKey(cat))
                    {
                        extraDic.Add(cat, new MyDictionary <int, CatPriority>());
                    }
                    extraDic[cat][item] = new CatPriority(drop);
                }

                List <DataRecord> itemList = MysqlUtil.SelectRecords("select * from new_item", FreeRuleConfig.MysqlConnection);
                foreach (DataRecord dr in itemList)
                {
                    string item = dr.GetValue("item");
                    int    id   = int.Parse(dr.GetValue("id"));
                }

                InitialPoints();
            }
        }