Пример #1
0
        public IDBEntity Read(string key)
        {
            IDBEntity entity = null;

            _db.TryGetValue(key, out entity);
            return(entity);
        }
Пример #2
0
 /// <summary>
 /// 复制操作数据
 /// </summary>
 /// <param name="target">复制到的目标对象</param>
 public virtual void CopyOperation(IDBEntity target)
 {
     target.CreatorId      = CreatorId;
     target.CreateTime     = CreateTime;
     target.IsDelete       = IsDelete;
     target.LastOperatorId = LastOperatorId;
     target.LastUpdateTime = LastUpdateTime;
 }
Пример #3
0
        private static DesignerPallet BuildPallet(StackAppContext appContext, IDBEntity entity)
        {
            var pallet = new DesignerPallet();

            pallet.Fields  = PrepareFieldList(entity);
            pallet.Buttons = PrepareButtonNLinks(appContext, entity);

            return(pallet);
        }
Пример #4
0
 private void AttachEntity(IDBEntity entity)
 {
     if (entity.ID > 0)
     {
         this.dbContext.Attach(entity);
         this.dbContext.Entry(entity).State = EntityState.Modified;
     }
     else
     {
         this.dbContext.Add(entity);
     }
 }
Пример #5
0
        public bool CreateOrUpdate(string key, IDBEntity entity)
        {
            if (Read(key) != null)
            {
                Update(key, entity);
            }
            else
            {
                Create(key, entity);
            }

            return(true);
        }
Пример #6
0
        public void Remove(IDBEntity entity)
        {
            City cityIn = (City)entity;

            using (MySqlConnection connection = StaticService.GetConnection())
            {
                StaticService.adapter.DeleteCommand =
                    new MySqlCommand("DELETE FROM mydb.cities WHERE (Id = " + cityIn.Id + ");", connection);
                connection.Open();
                StaticService.adapter.DeleteCommand.ExecuteNonQuery();
            }
            //
            StaticService.cities.Remove(cityIn);
        }
Пример #7
0
        public string PrepareRelatedFieldDataQueries(IEntityRelation relation, IDBEntity childEntity)
        {
            if (relation.Type == EntityRelationType.ManyToMany)
            {
                var relField = relation.ParentRefField.DBName;

                return($@"select {childEntity.IDField} as id, {childEntity.TextField} as name, pId from {childEntity.DBName} as c1 
                    join (
                        SELECT pField[s] as x, pId FROM (SELECT {relField} as pField, {_Entity.IDField} as pId, generate_subscripts({relField}, 1) AS s FROM {_Entity.DBName} where id = ANY(@ItemId) ) AS foo
                    ) as z 
                    on c1.{childEntity.IDField} = z.x;");
            }

            return("");
        }
Пример #8
0
        public void Remove(IDBEntity entity)
        {
            Customer customerIn = (Customer)entity;

            using (MySqlConnection connection = StaticService.GetConnection())
            {
                StaticService.adapter.DeleteCommand =
                    new MySqlCommand("DELETE FROM mydb.customers WHERE (Name = '" + customerIn.Name + "') AND (FirstName = '"
                                     + customerIn.FirstName + "');", connection);
                connection.Open();
                StaticService.adapter.DeleteCommand.ExecuteNonQuery();
            }
            //
            StaticService.customers.Remove(customerIn);
        }
Пример #9
0
        private TList PrepareLayout(DataListDefinition ds, IDBEntity entity)
        {
            var fields = new String[] { ds.ItemIdField, ds.ItemViewField };
            var tList  = new TList();

            tList.Fields = new List <TListField>();
            foreach (var f in fields)
            {
                var tfield = new TListField()
                {
                    FieldId = f
                };
                tList.Fields.Add(tfield);
            }

            return(tList);
        }
Пример #10
0
        public IDBEntity Create(IDBEntity entity)
        {
            City city = (City)entity;

            using (MySqlConnection connection = StaticService.GetConnection())
            {
                StaticService.adapter.InsertCommand = new MySqlCommand(
                    "INSERT INTO mydb.cities " +
                    "VALUES(@Id,@City);",
                    connection);
                StaticService.adapter.InsertCommand.Parameters.Add("@Id", MySqlDbType.Int32).Value     = city.Id;
                StaticService.adapter.InsertCommand.Parameters.Add("@City", MySqlDbType.VarChar).Value = city.Name;


                connection.Open();
                StaticService.adapter.InsertCommand.ExecuteNonQuery();
            }
            StaticService.cities.Add(city);
            return(city);
        }
Пример #11
0
        private static List <DynamicObj> PrepareFieldList(IDBEntity entity)
        {
            var fields = entity.GetLayoutFields(EntityLayoutType.None);

            var coll = new List <DynamicObj>();

            foreach (var f in fields)
            {
                var d = new DynamicObj();
                d.Add("Name", f.Name);
                d.Add("Text", f.Text);
                d.Add("Type", f.Type);
                d.Add("WidgetType", f.ControlType);
                d.Add("Isrequired", f.IsRequired);
                d.Add("ShouldFullRow", EntityLayoutService.IsWidgetOnFullRow(f.ControlType));
                coll.Add(d);
            }

            return(coll);
        }
Пример #12
0
        public IDBEntity Create(IDBEntity entity)
        {
            Place place = (Place)entity;

            using (MySqlConnection connection = StaticService.GetConnection())
            {
                StaticService.adapter.InsertCommand = new MySqlCommand(
                    "INSERT INTO mydb.places " +
                    "VALUES(@Id,@CityId,@Street);",
                    connection);
                StaticService.adapter.InsertCommand.Parameters.Add("@Id", MySqlDbType.Int32).Value       = place.Id;
                StaticService.adapter.InsertCommand.Parameters.Add("@CityId", MySqlDbType.Int32).Value   = place.City.Id;
                StaticService.adapter.InsertCommand.Parameters.Add("@Street", MySqlDbType.VarChar).Value = place.Street;


                connection.Open();
                StaticService.adapter.InsertCommand.ExecuteNonQuery();
            }
            StaticService.places.Add(place);
            return(place);
        }
Пример #13
0
        public void Update(int id, IDBEntity entity)
        {
            Place placeIn = (Place)entity;

            using (MySqlConnection connection = StaticService.GetConnection())
            {
                string query =
                    @"UPDATE places SET Id =" + placeIn.Id + " ,CityId = '" + placeIn.City.Id + "' ,Street = '" + placeIn.Street +
                    @"' WHERE (" +
                    @"Id = " + placeIn.Id + @")";

                MySqlDataAdapter localAadapter = new MySqlDataAdapter();

                localAadapter.UpdateCommand = new MySqlCommand(query, connection);
                connection.Open();
                localAadapter.UpdateCommand.ExecuteNonQuery();
            }
            //
            StaticService.places.Remove(StaticService.places.Find(city => city.Id == id));
            StaticService.places.Add(placeIn);
        }
Пример #14
0
        public void Update(int id, IDBEntity entity)
        {
            CustomerPlace customerPlaceIn = (CustomerPlace)entity;

            using (MySqlConnection connection = StaticService.GetConnection())
            {
                string query =
                    @"UPDATE customersPlaces SET Id =" + customerPlaceIn.Id + " ,UpdateTime = '" + customerPlaceIn.UpdateTime.ToString("yyyy-MM-dd hh:mm:ss") + "' ,CustomerId = " + customerPlaceIn.CustomerId + " ,PlaceId = " + customerPlaceIn.PlaceId +
                    @" WHERE (" +
                    @"Id = " + customerPlaceIn.Id + @")";

                MySqlDataAdapter localAadapter = new MySqlDataAdapter();

                localAadapter.UpdateCommand = new MySqlCommand(query, connection);
                connection.Open();
                localAadapter.UpdateCommand.ExecuteNonQuery();
            }
            //
            StaticService.customersPlaces.Remove(StaticService.customersPlaces.Find(city => city.Id == id));
            StaticService.customersPlaces.Add(customerPlaceIn);
        }
Пример #15
0
        public void Update(int id, IDBEntity entity)
        {
            City cityIn = (City)entity;

            using (MySqlConnection connection = StaticService.GetConnection())
            {
                string query =
                    @"UPDATE cities SET Id =" + cityIn.Id + " ,City = '" + cityIn.Name +
                    @" WHERE (" +
                    @"Id = " + cityIn.Id + @")";

                MySqlDataAdapter localAadapter = new MySqlDataAdapter();

                localAadapter.UpdateCommand = new MySqlCommand(query, connection);
                connection.Open();
                localAadapter.UpdateCommand.ExecuteNonQuery();
            }
            //
            StaticService.cities.Remove(StaticService.cities.Find(city => city.Id == id));
            StaticService.cities.Add(cityIn);
        }
Пример #16
0
        public IDBEntity Create(IDBEntity entity)
        {
            CustomerPlace customerPlace = (CustomerPlace)entity;

            using (MySqlConnection connection = StaticService.GetConnection())
            {
                StaticService.adapter.InsertCommand = new MySqlCommand(
                    "INSERT INTO mydb.customersPlaces " +
                    "VALUES(@Id,@UpdateTime,@CustomerId,@PlaceId);",
                    connection);
                StaticService.adapter.InsertCommand.Parameters.Add("@Id", MySqlDbType.Int32).Value             = customerPlace.Id;
                StaticService.adapter.InsertCommand.Parameters.Add("@UpdateTime", MySqlDbType.Timestamp).Value = customerPlace.UpdateTime; // no ToString("FormatString")
                StaticService.adapter.InsertCommand.Parameters.Add("@CustomerId", MySqlDbType.Int32).Value     = customerPlace.CustomerId;
                StaticService.adapter.InsertCommand.Parameters.Add("@PlaceId", MySqlDbType.Int32).Value        = customerPlace.PlaceId;

                connection.Open();
                StaticService.adapter.InsertCommand.ExecuteNonQuery();
            }
            StaticService.customersPlaces.Add(customerPlace);
            return(customerPlace);
        }
Пример #17
0
        public IDBEntity Create(IDBEntity entity)
        {
            Customer customer = (Customer)entity;

            using (MySqlConnection connection = StaticService.GetConnection())
            {
                StaticService.adapter.InsertCommand = new MySqlCommand(
                    "INSERT INTO mydb.customers " +
                    "VALUES(@Id,@Name,@FirstName,@DateOfBirth);",
                    connection);
                StaticService.adapter.InsertCommand.Parameters.Add("@Id", MySqlDbType.Int32).Value          = customer.Id;
                StaticService.adapter.InsertCommand.Parameters.Add("@Name", MySqlDbType.VarChar).Value      = customer.Name;
                StaticService.adapter.InsertCommand.Parameters.Add("@FirstName", MySqlDbType.VarChar).Value = customer.Name;
                StaticService.adapter.InsertCommand.Parameters.Add("@DateOfBirth", MySqlDbType.Date).Value  = customer.DateOfBirth.ToString("yyyy-MM-dd");



                connection.Open();
                StaticService.adapter.InsertCommand.ExecuteNonQuery();
            }
            StaticService.customers.Add(customer);
            return(customer);
        }
Пример #18
0
        public void Update(int id, IDBEntity entity)
        {
            Customer customerIn = (Customer)entity;

            using (MySqlConnection connection = StaticService.GetConnection())
            {
                string query =
                    @"UPDATE customers SET Id = " + customerIn.Id + " ,Name = '" + customerIn.Name +
                    @"',FirstName = '" + customerIn.FirstName +
                    @"',DateOfBirth = '" + customerIn.DateOfBirth.ToString("yyyy-MM-dd") +
                    @"' WHERE (" +
                    @"Id = " + id + @")";

                MySqlDataAdapter localAadapter = new MySqlDataAdapter();

                localAadapter.UpdateCommand = new MySqlCommand(query, connection);
                connection.Open();
                localAadapter.UpdateCommand.ExecuteNonQuery();
            }
            //
            StaticService.customers.Remove(StaticService.customers.Find(customer => customer.Id == id));
            StaticService.customers.Add(customerIn);
        }
Пример #19
0
 public EntityRecordModel(IDBEntity entity) : base(entity)
 {
 }
Пример #20
0
        private static List <int> FetchDataModel(StackAppContext appContext, int parentId, BaseField parentField, IDBEntity entity)
        {
            var filterExp = new FilterExpression(entity.EntityId);
            var relField  = (OneToManyField)parentField;

            filterExp.Add(new FilterExpField(relField.RefFieldName, FilterOperationType.Equal, parentId));
            var ids = entity.ReadIds(appContext, filterExp);

            return(ids);
        }
Пример #21
0
 public bool Update(string key, IDBEntity entity)
 {
     _db[key] = entity;
     return(true);
 }
Пример #22
0
        public static TView CreateDefault(IDBEntity Entity, EntityLayoutType layoutType)
        {
            var view = new TView();

            view.Fields = new List <TField>();

            var page = new TPage();

            view.Pages.Add(page);
            var group = new TGroup();

            page.Groups.Add(group);

            var         start_new_r = true;
            List <TCol> col_r       = new List <TCol>();
            var         layoutF     = Entity.GetLayoutFields(EntityLayoutType.Edit);
            int         idx         = 0;

            foreach (var f in layoutF)
            {
                var col = new TCol(f.Name);

                view.Fields.Add(new TField()
                {
                    FieldId = f.Name, Text = f.Text
                });

                if (col_r.Count == 1)
                {
                    start_new_r = true;
                }
                else
                {
                    start_new_r = false;
                }

                if (IsWidgetOnFullRow(f.ControlType))
                {
                    start_new_r = true;

                    var row = new TRow();
                    col.Span = 24;
                    row.Cols = new List <TCol>()
                    {
                        col
                    };

                    group.Rows.Add(row);
                }
                else
                {
                    col_r.Add(col);
                }


                if (start_new_r)
                {
                    var row = new TRow();
                    row.Cols = col_r;
                    group.Rows.Add(row);

                    col_r = new List <TCol>();
                }
                else if (layoutF.Count - 1 == idx)
                {
                    var row = new TRow();
                    row.Cols = col_r;

                    group.Rows.Add(row);
                }
                idx++;
            }

            return(view);
        }
Пример #23
0
 public EntityDBSave(IDBEntity entity)
 {
     _entity = entity;
 }
Пример #24
0
        public static AnyStatus SaveEntity(StackAppContext appContext, IDBEntity entity, EntityModelBase model, IDbConnection connection, IDbTransaction transaction)
        {
            AnyStatus sts = AnyStatus.UpdateFailure;

            var eSave = new EntityDBSave(entity);

            if (model.IsNew)
            {
                var eId = GetNextEntityDBId(entity.EntityId.Code);
                model.SetID(eId);
            }

            IDbConnection  conn;
            IDbTransaction trans;
            bool           isLocalConnection = true;

            if (connection == null)
            {
                conn = DBService.Connection;
                conn.Open();
                trans = conn.BeginTransaction();
            }
            else
            {
                conn              = connection;
                trans             = transaction;
                isLocalConnection = false;
            }

            try
            {
                sts = entity.OnBeforeDbSave(appContext, model, conn, trans);
                if (sts == AnyStatus.Success)
                {
                    eSave.Save(model, conn, trans);
                    sts = entity.OnAfterDbSave(appContext, model, conn, trans);
                    if (sts != AnyStatus.Success)
                    {
                        if (isLocalConnection)
                        {
                            trans.Rollback();
                        }
                    }
                    else
                    {
                        if (isLocalConnection)
                        {
                            trans.Commit();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                sts         = AnyStatus.SaveFailure;
                sts.Message = ex.Message;
                if (isLocalConnection)
                {
                    trans.Rollback();
                }
            }
            finally
            {
                if (isLocalConnection)
                {
                    trans.Dispose();
                    conn.Close();
                }
            }

            return(sts);
        }
Пример #25
0
 public EntityModelBase(IDBEntity entity) : base(entity)
 {
     TempInfo = new DynamicObj();
 }
Пример #26
0
 public EntityQueryBuilder(IDBEntity entity)
 {
     _Entity = entity;
 }
Пример #27
0
 public bool Create(string key, IDBEntity entity)
 {
     _db.Add(key, entity);
     return(true);
 }
Пример #28
0
        private static List <DynamicObj> PrepareButtonNLinks(StackAppContext appContext, IDBEntity entity)
        {
            var actions = EntityActionService.GetActions(appContext, entity.EntityId, EntityLayoutType.View);

            var coll = new List <DynamicObj>();

            foreach (var f in actions)
            {
                var d = new DynamicObj();
                d.Add("Id", f.Id);
                d.Add("Text", f.Text);
                coll.Add(d);
            }

            return(coll);
        }