示例#1
0
        private string InsertQuery(ClassProxy _proxy)
        {
            List <FieldValue> _fieldsValues = FieldsValues(_proxy.Properties(), _proxy);
            string            _query        = "INSERT INTO " + _proxy.TypeName.ToLower() +
                                              "(objectrepresentation," + Fields(_fieldsValues) + ") " +
                                              "VALUES (" + "'" + SqlCSharp.ObjectRepresentaition(_proxy.Entity) + "'" + "," + Values(_fieldsValues) + ");";

            return(_query);
        }
示例#2
0
        private string UpdateQuery(IEnumerable <PropertyProxy> _changes, ClassProxy _classAndProxy)
        {
            List <FieldValue> _fieldsValues = FieldsValues(_changes, _classAndProxy);

            return("UPDATE " + _classAndProxy.TypeName.ToLower() +
                   " SET " + FieldsEqualValues(_fieldsValues, _classAndProxy) +
                   " WHERE " + _classAndProxy.TypeName.ToLower() + ".id = " +
                   SqlCSharp.SqlValue(_classAndProxy.Entity, TypeHelper.Property(_classAndProxy.Entity.GetType(), "ID")) +
                   ";");
        }
示例#3
0
        private List <FieldValue> FieldsValues(IEnumerable <PropertyProxy> _changes, ClassProxy _classAndProxy)
        {
            List <FieldValue> _fieldsValues = new List <FieldValue>();

            foreach (PropertyProxy _prProxy in _changes)
            {
                _fieldsValues.Add(new FieldValue(_classAndProxy.Entity, _prProxy.PropertyInfo));
            }
            return(_fieldsValues);
        }
示例#4
0
        private static Dictionary <string, object> ClassProxyRepresentation(ClassProxy _proxy, int level = -1)
        {
            Dictionary <string, object> _dic = new Dictionary <string, object>();

            if (level != -1)
            {
                _dic.Add("Level", level);
            }

            // Properties
            Dictionary <string, object> _properties = new Dictionary <string, object>();

            foreach (PropertyProxy _prProxy in _proxy.PropertiesNoObject())
            {
                Dictionary <string, object> _prRepesentation = PropertyRepresentation(_prProxy);
                _properties.Add(_prProxy.ID.ToString(), _prRepesentation);
            }

            // Objects
            foreach (PropertyObjectProxy _prProxy in _proxy.PropertiesObjects())
            {
                AttributeSelected _attr = _prProxy.PropertyInfo.GetCustomAttribute <AttributeSelected>();
                if (_attr != null)
                {
                    Dictionary <string, object> _property = new Dictionary <string, object>();
                    Dictionary <string, object> _data     = new Dictionary <string, object>();

                    _property.Add("Label", _prProxy.Label);

                    if (_prProxy.Value != null)
                    {
                        _property.Add("Selected", ((ClassProxy)_prProxy.Value).ID.ToString());
                    }

                    foreach (object _o in _attr.DataSource())
                    {
                        Base _base = _o as Base;
                        _data.Add(_base.ID.ToString(), ClassProxyRepresentation(_proxy.Context.GetOrAttach(_base)));
                    }
                    _property.Add("data", _data);
                    _properties.Add(_prProxy.ID.ToString(), _property);
                }
                else
                {
                    _dic.Add(_prProxy.Name, ClassProxyRepresentation((ClassProxy)_prProxy.Value, level + 1));
                }
            }

            if (_properties.Count > 0)
            {
                _dic.Add("Properties", _properties);
            }

            return(_dic);
        }
示例#5
0
        /// <summary>
        /// Retourne une chaine comme : field1=val1,field2=val2,...
        /// </summary>
        private string FieldsEqualValues(List <FieldValue> _changes, ClassProxy _classAndProxy)
        {
            string _fieldsEqualValues = "";

            foreach (FieldValue _fieldValue in _changes)
            {
                if (_fieldsEqualValues != "")
                {
                    _fieldsEqualValues += ",";
                }
                _fieldsEqualValues += _fieldValue.ColumnName +
                                      "=" +
                                      _fieldValue.SqlValue;
            }
            return(_fieldsEqualValues);
        }
示例#6
0
        public static string ProduceJSon(ClassProxy proxy)
        {
            if (proxy == null)
            {
                throw new ArgumentNullException("_proxy");
            }

            Dictionary <string, object> _properties = ClassProxyRepresentation(proxy, 0);
            Dictionary <string, object> _object     = new Dictionary <string, object>()
            {
                { proxy.TypeName, _properties }
            };

            string _json = JsonConvert.SerializeObject(_object, Formatting.Indented);

            return(_json);
        }
示例#7
0
文件: DBLoader.cs 项目: CFLShine/CFL
        /// <summary>
        /// Les données sont extraites de la ligne en cours du reader.
        /// </summary>
        public void SetValuesToClassProxy(ClassProxy _proxy, DBRow _row)
        {
            _proxy.ID = _row.GetId();

            for (int _i = 0; _i < _row.Count; _i++)
            {
                DBField _field        = _row.GetField(_i);
                string  _propertyName = _field.PropertyName;

                PropertyProxy _prProxy = _proxy.GetPropertyProxy(_propertyName);

                if (_prProxy != null)
                {
                    SetValueToProperty(_prProxy, _field.Value);
                }
            }
        }
示例#8
0
文件: DBLoader.cs 项目: CFLShine/CFL
        private string IncludeQuery(ClassProxy _classProxy, string _memberName)
        {
            PropertyProxy _prProxy = _classProxy.GetPropertyProxy(_memberName);

            if (_prProxy is PropertyObjectProxy _prObjectProxy)
            {
                return(IncludeClassQuery(_prObjectProxy));
            }
            else
            if (_prProxy is PropertyListProxy _prListProxy)
            {
                return(IncludeListQuery(_prListProxy));
            }
            else
            {
                throw new Exception("Le type " + _prProxy.GetType().Name + " n'est pas prévu pour Include.");
            }
        }
示例#9
0
文件: DBLoader.cs 项目: CFLShine/CFL
        private List <ClassProxy> Load(string _query)
        {
            List <ClassProxy> _proxies = new List <ClassProxy>();

            DBReader _reader = new DBReader(Connection, _query);

            while (_reader.Read())
            {
                ClassProxy _classProxy = Context.GetOrAttach(_reader.CurrentRow.GetObjectType(), _reader.CurrentRow.GetId());

                if (_classProxy.Entity == null)
                {
                    _classProxy.CreateNewEntity();
                }

                _classProxy.IsNew = false;
                SetValuesToClassProxy(_classProxy, _reader.CurrentRow);
                _proxies.Add(_classProxy);
                Context.Process(_classProxy);
            }
            return(_proxies);
        }
示例#10
0
文件: DBLoader.cs 项目: CFLShine/CFL
        private string IncludeAllQuery(ClassProxy _classProxy)
        {
            string _query = "";

            foreach (PropertyProxy _memberProxy in _classProxy.Properties())
            {
                if (_memberProxy.IsObject)
                {
                    _query += IncludeClassQuery((PropertyObjectProxy)_memberProxy);
                }
                else
                if (_memberProxy.IsList)
                {
                    Type _itemsType = ((PropertyListProxy)_memberProxy).ItemsType;
                    if (_itemsType == typeof(Base) || _itemsType.IsSubclassOf(typeof(Base)))
                    {
                        _query += IncludeListQuery((PropertyListProxy)_memberProxy);
                    }
                }
            }
            return(_query);
        }
示例#11
0
 public PropertyPrimitiveProxy(ShContext context, PropertyInfo prInfo, ClassProxy parent)
     : base(context, prInfo, parent)
 {
 }