Пример #1
0
        public override UpdateResult_I <T> OnUpdate(T objectToUpdate)
        {
            using (SqlConnection connection = (SqlConnection)XDataBase.GetDataConnection <T>())
            {
                connection.Open();

                return(OnSqlUpdate(connection, objectToUpdate));
            }
        }
Пример #2
0
        public override RemoveResult_I <T> OnRemoveAll()
        {
            using (SqlConnection connection = (SqlConnection)XDataBase.GetDataConnection <T>())
            {
                connection.Open();

                return(OnSqlDeleteAll(connection));
            }
        }
Пример #3
0
        public override RemoveResult_I <T> OnRemoveById(long id)
        {
            using (SqlConnection connection = (SqlConnection)XDataBase.GetDataConnection <T>())
            {
                connection.Open();

                return(OnSqlDeleteById(connection, id));
            }
        }
Пример #4
0
        public override RemoveResult_I <T> OnRemove(T objectToRemove)
        {
            using (SqlConnection connection = (SqlConnection)XDataBase.GetDataConnection <T>())
            {
                connection.Open();

                return(OnSqlDelete(connection, objectToRemove));
            }
        }
Пример #5
0
        public override GetResult_I <T> OnGetById(long id)
        {
            using (SqlConnection connection = (SqlConnection)XDataBase.GetDataConnection <T>())
            {
                connection.Open();

                return(OnSqlSelectById(connection, id));
            }
        }
Пример #6
0
        public override GetCollectionResult_I <T> OnGetAll()
        {
            using (SqlConnection connection = (SqlConnection)XDataBase.GetDataConnection <T>())
            {
                connection.Open();

                return(OnSqlSelectAll(connection));
            }
        }
Пример #7
0
        public override AddResult_I <T> OnAdd(T objectToAdd)
        {
            using (SqlConnection connection = (SqlConnection)XDataBase.GetDataConnection <T>())
            {
                connection.Open();

                return(OnSqlInsert(connection, objectToAdd));
            }
        }
Пример #8
0
        public override void OnStore(T poco)
        {
            using (SqlConnection connection = (SqlConnection)XDataBase.GetDataConnection <T>())
            {
                connection.Open();

                var getResult = OnSqlSelectById(connection, poco.Id.Value);

                if (getResult.Data != null)
                {
                    OnSqlUpdate(connection, poco);
                }
                else
                {
                    OnSqlInsert(connection, poco);
                }
            }
        }
Пример #9
0
        private static void BuildFields(XTableSchema schema)
        {
            string connectionName = schema.ConnectionName;
            string selectSql      = schema.SelectCommand;

            XDataBase xdb = XDatabaseFactory.Instance.GetDataBase(connectionName);


            XSql xSql = new XSql(selectSql);

            string tableName = xSql.GetFrom();
            //  schema.Fields.Clear();

            SchemaList <FieldSchema> tmpfs = new SchemaList <FieldSchema>();

            DbConnection con      = xdb.GetConnection();
            DataTable    netTable = new DataTable();

            DbDataAdapter da = xdb.GetAdapter();

            DbCommand cmd = con.CreateCommand();

            cmd.CommandText = selectSql;

            string[] paramNames = xSql.GetParamNames();
            for (int i = 0; i < paramNames.Count(); i++)
            {
                string pName = paramNames[i];
                if (!string.IsNullOrEmpty(pName))
                {
                    pName = pName.Trim();
                }
                SqlParameter p = new SqlParameter();
                p.ParameterName = "@" + pName;
                //p.SourceColumn = pName;
                p.Value = "";
                cmd.Parameters.Add(p);
            }
            da.SelectCommand = cmd;

            da.Fill(netTable);
            //da.FillSchema(netTable, SchemaType.Source);

            foreach (DataColumn col in netTable.Columns)
            {
                FieldSchema field = new FieldSchema();
                field.Id          = col.ColumnName;
                field.DisplayName = col.Caption;
                //                    schema.Fields.Add(field);
                if (schema.Fields.FindItem(field.Id) == null)
                {
                    schema.Fields.Add(field);
                }

                if (tmpfs.FindItem(field.Id) == null)
                {
                    tmpfs.Add(field);
                }
            }


            //从原是表中获取,字段标题等信息;

            if (xSql.IsFromSourceTable(tableName))
            {
                string keyfield = xdb.GetPrimaryKey(tableName);
                if (!string.IsNullOrEmpty(keyfield))
                {
                    schema.KeyField = keyfield;
                }

                List <FieldDef> fieldDefs = xdb.GetFieldInfos(tableName);

                for (int i = 0; i < fieldDefs.Count; i++)
                {
                    FieldDef    fieldDef = fieldDefs[i];
                    FieldSchema field    = schema.Fields.FindItem(fieldDef.Name);

                    //                    field.Id =;
                    if (field != null)
                    {
                        field.DisplayName = fieldDef.Alias;//未用
                        if (string.IsNullOrEmpty(field.Title))
                        {
                            field.Title = fieldDef.Alias;
                        }
                        if (fieldDef.IsIdentity)
                        {
                            field.IsAutoInc = true;
                        }
                    }
                    //                    if (field == null)
                    //                        schema.Fields.Add(field);
                    //    if (tmpfs.FindItem(field.Id) == null)
                    //        tmpfs.Add(field);
                }
            }

            //删除不存在的字段
            for (int i = schema.Fields.Count - 1; i >= 0; i--)
            {
                FieldSchema fld    = schema.Fields[i];
                FieldSchema newFld = tmpfs.FindItem(fld.Id);
                if (newFld == null)
                {
                    schema.Fields.Remove(fld);
                }
            }

            xdb.Close();
        }
Пример #10
0
 public DataLayerApi_I GetApiForModel <T>()
 {
     return(XDataBase.GetApiForModel <T>());
 }
Пример #11
0
 public object GetApi <T>()
 {
     return(XDataBase.GetApi <T>());
 }
Пример #12
0
 public void LoadApis()
 {
     XDataBase.LoadApis();
 }