コード例 #1
0
        public void Add(GenericData u)
        {
            u.CreationDate = DateTime.Now;
            u.UpdateDate   = DateTime.Now;
            SqlItemList sqlItems = Get(u);

            SetInsertIntoSql(u.GetType().Name, sqlItems);
            ExecuteSql();
        }
コード例 #2
0
        public void Update(GenericData g)
        {
            g.UpdateDate = DateTime.Now;
            SqlItemList sqlItems = Get(g);

            SetUpdateSql(g.GetType().Name, sqlItems, new SqlItemList {
                new SqlItem {
                    FieldName = "Id", FieldValue = g.Id
                }
            });
            ExecuteSql();
        }
コード例 #3
0
        private static SqlItemList Get(GenericData u)
        {
            var sqlItems = new SqlItemList();

            sqlItems.Add(new SqlItem("Active", u.Active));
            sqlItems.Add(new SqlItem("CreationDate", u.CreationDate));
            sqlItems.Add(new SqlItem("Description", u.Description));
            sqlItems.Add(new SqlItem("UpdateDate", u.UpdateDate));

            var props = u.GetType().GetProperties();

            foreach (var pinfo in props)
            {
                var genericDataField = ((GenericDataFieldAttribute[])pinfo.GetCustomAttributes(typeof(GenericDataFieldAttribute), true)).FirstOrDefault();
                if (genericDataField != null)
                {
                    var val = pinfo.GetValue(u);
                    sqlItems.Add(new SqlItem(genericDataField.FieldName, val ?? string.Empty));
                }
            }

            return(sqlItems);
        }