Beispiel #1
0
        public override string GetEntitySQL(Type type, object key)
        {
            string strsql = "";
            string fields = "";

            string where = "";
            try
            {
                TableAttributeInfo         tableAttribute            = GetTableAttributeInfo(type);
                List <ColumnAttributeInfo> columnAttributeCollection = tableAttribute.ColumnAttributeInfoList;

                for (int i = 0; i < columnAttributeCollection.Count; i++)
                {
                    ColumnAttributeInfo columnAttributeInfo = columnAttributeCollection[i];

                    fields += (fields == "" ? "" : ",") + columnAttributeInfo.FieldName + " as " + columnAttributeInfo.PropertyName;

                    if (columnAttributeInfo.DataKey == true)
                    {
                        object obj = key;
                        where = columnAttributeInfo.FieldName + "=" + ConvertDBValue(obj);
                    }
                }


                strsql = "select {0} from {1} where {2}";

                return(string.Format(strsql, fields, tableAttribute.TableName, where));
            }
            catch (Exception err)
            {
                throw new Exception(err.Message + "SQL:" + strsql);
            }
        }
Beispiel #2
0
        public override string GetDeleteSQL(Type type, object key)
        {
            string strsql = "";

            string where = "";
            try
            {
                TableAttributeInfo         tableAttribute            = GetTableAttributeInfo(type);
                List <ColumnAttributeInfo> columnAttributeCollection = tableAttribute.ColumnAttributeInfoList;

                for (int i = 0; i < columnAttributeCollection.Count; i++)
                {
                    ColumnAttributeInfo columnAttributeInfo = columnAttributeCollection[i];
                    if (columnAttributeInfo.DataKey == true)
                    {
                        object obj = key;
                        where = columnAttributeInfo.FieldName + "=" + ConvertDBValue(obj);
                    }
                }

                strsql = "delete from  {0}  where {1}";

                return(string.Format(strsql, tableAttribute.TableName, where));
            }
            catch (Exception err)
            {
                throw new Exception(err.Message + "SQL:" + strsql);
            }
        }
        public override string GetInsertSQL(object model)
        {
            string strsql = "";

            try
            {
                Dictionary <string, object> dicsql = new Dictionary <string, object>();

                TableAttributeInfo         tableAttribute            = GetTableAttributeInfo(model);
                List <ColumnAttributeInfo> columnAttributeCollection = tableAttribute.ColumnAttributeInfoList;

                for (int i = 0; i < columnAttributeCollection.Count; i++)
                {
                    ColumnAttributeInfo columnAttributeInfo = columnAttributeCollection[i];

                    if (columnAttributeInfo.DataKey == true && columnAttributeInfo.Match == "Custom:Guid")//赋值给自增长ID
                    {
                        object obj = GetEntityValue(columnAttributeInfo.PropertyName, model);
                        obj = obj == null?Guid.NewGuid().ToString() : obj;

                        SetEntityValue(columnAttributeInfo.PropertyName, model, obj);

                        dicsql.Add(columnAttributeInfo.FieldName, obj);
                    }
                    else
                    {
                        if (columnAttributeInfo.IsInsert == true)
                        {
                            object obj = GetEntityValue(columnAttributeInfo.PropertyName, model);
                            obj = obj == null ? "" : obj;
                            dicsql.Add(columnAttributeInfo.FieldName, obj);
                        }
                    }
                }

                string fields = "";
                string values = "";
                strsql = "insert into {0} ({1}) values({2})";

                if (IsJoinWorkId(tableAttribute.IsGB))
                {
                    dicsql.Add("WorkId", Db.WorkId);
                }

                foreach (KeyValuePair <string, object> val in dicsql)
                {
                    fields += (fields == "" ? "" : ",") + val.Key;
                    values += (values == "" ? "" : ",") + ConvertDBValue(val.Value);
                }

                string SQL = string.Format(strsql, tableAttribute.TableName, fields, values);
                //获取自增长ID
                return(SQL + ";" + string.Format("select {0}.currval from dual", "S_" + tableAttribute.TableName));
            }
            catch (Exception err)
            {
                throw new Exception(err.Message + "SQL:" + strsql);
            }
        }
Beispiel #4
0
        /* Hard coded to a certain extent, however modularizes the way we create tables */
        /* This method is necessary because to send to a column in a database you must know the attribute name */
        public void BuildTable(string inputName)
        {
            if (inputName == "Items")
            {
                /* Assign name */
                items = new TableAttributeInfo(inputName);

                items.tableAttributes.Add(new Attribute("ItemName", typeof(string)));
            }

            else if (inputName == "AttackBonuses")
            {
                AttackBonuses = new TableAttributeInfo(inputName);

                AttackBonuses.tableAttributes.Add(new Attribute("ItemName", typeof(string)));
                AttackBonuses.tableAttributes.Add(new Attribute("ATT_Stab_Bonus", typeof(int)));
                AttackBonuses.tableAttributes.Add(new Attribute("ATT_Slash_Bonus", typeof(int)));
                AttackBonuses.tableAttributes.Add(new Attribute("ATT_Crush_Bonus", typeof(int)));
                AttackBonuses.tableAttributes.Add(new Attribute("ATT_Magic_Bonus", typeof(int)));
                AttackBonuses.tableAttributes.Add(new Attribute("ATT_Ranged_Bonus", typeof(int)));
            }

            else if (inputName == "DefenseBonuses")
            {
                DefenseBonuses = new TableAttributeInfo(inputName);

                DefenseBonuses.tableAttributes.Add(new Attribute("ItemName", typeof(string)));
                DefenseBonuses.tableAttributes.Add(new Attribute("DEF_Stab_Bonus", typeof(int)));
                DefenseBonuses.tableAttributes.Add(new Attribute("DEF_Slash_Bonus", typeof(int)));
                DefenseBonuses.tableAttributes.Add(new Attribute("DEF_Crush_Bonus", typeof(int)));
                DefenseBonuses.tableAttributes.Add(new Attribute("DEF_Magic_Bonus", typeof(int)));
                DefenseBonuses.tableAttributes.Add(new Attribute("DEF_Ranged_Bonus", typeof(int)));
            }

            else if (inputName == "CombatBonuses")
            {
                CombatBonuses = new TableAttributeInfo(inputName);

                CombatBonuses.tableAttributes.Add(new Attribute("ItemName", typeof(string)));
                CombatBonuses.tableAttributes.Add(new Attribute("STR_Bonus", typeof(int)));
                CombatBonuses.tableAttributes.Add(new Attribute("STR_Ranged_Bonus", typeof(int)));
                CombatBonuses.tableAttributes.Add(new Attribute("STR_Magic_Bonus", typeof(int)));
                CombatBonuses.tableAttributes.Add(new Attribute("Prayer_Bonus", typeof(int)));
            }
            else if (inputName == "ItemInfo")
            {
                ItemInfo = new TableAttributeInfo(inputName);

                ItemInfo.tableAttributes.Add(new Attribute("ItemName", typeof(string)));
                ItemInfo.tableAttributes.Add(new Attribute("ItemValue", typeof(int)));
                ItemInfo.tableAttributes.Add(new Attribute("Tradeable", typeof(bool)));
                ItemInfo.tableAttributes.Add(new Attribute("Equipable", typeof(bool)));
                ItemInfo.tableAttributes.Add(new Attribute("Stackable", typeof(bool)));
                ItemInfo.tableAttributes.Add(new Attribute("Noteable", typeof(bool)));
                ItemInfo.tableAttributes.Add(new Attribute("Examine", typeof(bool)));
            }
        }
Beispiel #5
0
        protected TableAttributeInfo GetTableAttributeInfo(Type type)
        {
            EntityAttributeInfo EAttr = entityAttrList.Find(x => x.ObjType.Equals(type));

            if (EAttr == null)
            {
                throw new Exception("此对象没有配置实体自定义属性");
            }
            TableAttributeInfo tableAttrInfo = EAttr.TableAttributeInfoList.Find(x => x.Alias == Alias);

            //if (tableAttrInfo) throw new Exception("找不到相同别名的表自定义属性");
            return(tableAttrInfo);
        }
Beispiel #6
0
        public override string GetUpdateSQL(object model)
        {
            string strsql = "";

            string where = "";
            try
            {
                Dictionary <string, object> dicsql = new Dictionary <string, object>();


                TableAttributeInfo         tableAttribute            = GetTableAttributeInfo(model);
                List <ColumnAttributeInfo> columnAttributeCollection = tableAttribute.ColumnAttributeInfoList;

                for (int i = 0; i < columnAttributeCollection.Count; i++)
                {
                    ColumnAttributeInfo columnAttributeInfo = columnAttributeCollection[i];

                    if (columnAttributeInfo.DataKey == false && columnAttributeInfo.IsInsert == true)
                    {
                        object obj = GetEntityValue(columnAttributeInfo.PropertyName, model);
                        dicsql.Add(columnAttributeInfo.FieldName, obj);
                    }

                    if (columnAttributeInfo.DataKey == true)
                    {
                        object obj = GetEntityValue(columnAttributeInfo.PropertyName, model);
                        obj   = obj == null ? "" : obj;
                        where = columnAttributeInfo.FieldName + "=" + ConvertDBValue(obj);
                    }
                }

                string field_values = "";

                strsql = "update  {0} set {1} where {2}";

                foreach (KeyValuePair <string, object> val in dicsql)
                {
                    field_values += (field_values == "" ? "" : ",") + val.Key + "=" + ConvertDBValue(val.Value);
                }

                return(string.Format(strsql, tableAttribute.TableName, field_values, where));
            }
            catch (Exception err)
            {
                throw new Exception(err.Message + "SQL:" + strsql);
            }
        }
Beispiel #7
0
        public override string GetListSQL(Type type, string strWhere, EFWCoreLib.CoreFrame.DbProvider.SqlPagination.PageInfo pageInfo)
        {
            string strsql = "";
            string fields = "";

            string where = "";
            try
            {
                TableAttributeInfo         tableAttribute            = GetTableAttributeInfo(type);
                List <ColumnAttributeInfo> columnAttributeCollection = tableAttribute.ColumnAttributeInfoList;

                for (int i = 0; i < columnAttributeCollection.Count; i++)
                {
                    ColumnAttributeInfo columnAttributeInfo = columnAttributeCollection[i];
                    fields += (fields == "" ? "" : ",") + columnAttributeInfo.FieldName + " as " + columnAttributeInfo.PropertyName;
                }

                where  = JoinWhere(tableAttribute.IsGB, strWhere);
                strsql = "select {0} from {1} {2}";
                strsql = string.Format(strsql, fields, tableAttribute.TableName + " as T1", where);

                if (pageInfo != null)
                {
                    if (pageInfo.KeyName == null)
                    {
                        pageInfo.KeyName = tableAttribute.DataKeyFieldName;
                    }
                    strsql = EFWCoreLib.CoreFrame.DbProvider.SqlPagination.SqlPage.FormatSql(strsql, pageInfo, Db);
                }
                return(strsql);
            }
            catch (Exception err)
            {
                throw new Exception(err.Message + "SQL:" + strsql);
            }
        }
Beispiel #8
0
        public string GetEntityDataKeyPropertyName(object model)
        {
            TableAttributeInfo tableAttribute = GetTableAttributeInfo(model);

            return(tableAttribute.DataKeyPropertyName);
        }
Beispiel #9
0
        public object GetEntityDataKeyValue(object model)
        {
            TableAttributeInfo tableAttribute = GetTableAttributeInfo(model);

            return(GetEntityValue(tableAttribute.DataKeyPropertyName, model));
        }
Beispiel #10
0
        /* Is meant to create proper insert statements given only a table */
        public void NewSqlInsert(TableAttributeInfo table, DBConnection dbCon, List <string> inputList)
        {
            /* We construct the insert statement as a string */
            string tableAttributeNames = "INSERT INTO " + table.tableName + "(";
            string tableValueNames     = "VALUES(";

            int check = 0;

            foreach (Attribute attr in table.tableAttributes)
            {
                /* We dont want to add comma to last one */
                if (check == table.tableAttributes.Count - 1)
                {
                    tableAttributeNames = String.Concat(tableAttributeNames, attr.attributeName + ")");
                    tableValueNames     = String.Concat(tableValueNames, attr.varValueName + ")");
                }
                else /* Normal concat */
                {
                    tableAttributeNames = String.Concat(tableAttributeNames, attr.attributeName + ",");
                    tableValueNames     = String.Concat(tableValueNames, attr.varValueName + ",");
                    check++;
                }
            }

            /* Finish insert statement by putting together all pieces*/
            string newQuery = string.Concat(tableAttributeNames, tableValueNames);

            Console.WriteLine(newQuery);

            MySqlCommand newCommand = new MySqlCommand();

            newCommand.Connection  = dbCon.Connection;
            newCommand.CommandText = newQuery;

            /* Here is where we construct our commands */
            for (int i = 0; i < table.tableAttributes.Count; i++)
            {
                MySqlDbType attributeType; /* Need to instantiate DB type, since sql cannot accept c# types */

                /* Adds a value to a string type attribute */
                if (table.tableAttributes[i].myType == typeof(string))
                {
                    attributeType = MySqlDbType.VarChar;
                    newCommand.Parameters.Add(table.tableAttributes[i].varValueName, attributeType).Value = inputList[i];
                }
                /* Adds a value to a int type attribute */
                else if (table.tableAttributes[i].myType == typeof(int))
                {
                    attributeType = MySqlDbType.Int32;
                    newCommand.Parameters.Add(table.tableAttributes[i].varValueName, attributeType).Value = int.Parse(inputList[i]);
                }
                /* Adds a value to a bool type attribute */
                else if (table.tableAttributes[i].myType == typeof(bool))
                {
                    attributeType = MySqlDbType.VarChar;

                    if (bool.Parse(inputList[i]) == false)
                    {
                        newCommand.Parameters.Add(table.tableAttributes[i].varValueName, attributeType).Value = "NO";
                    }

                    if (bool.Parse(inputList[i]) == true)
                    {
                        newCommand.Parameters.Add(table.tableAttributes[i].varValueName, attributeType).Value = "YES";
                    }
                }
            }

            /* Official send to the db */
            newCommand.ExecuteNonQuery();
        }