Exemplo n.º 1
0
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(CriticalMass.TagNode.Model.tattribute_name model, IDbTransaction trn)
        {
            IDbConnection conn           = trn.Connection;
            string        sqlCommandText = @"insert into tattribute_name(`name`,`code`,`createBy`,`createTime`,`status`,`is_custom`,`modifyBy`,`modifyTime`,`canMultiSelect`,`canNull`,`canCustom`,`ctype`)values(@name,@code,@createBy,@createTime,@status,@is_custom,@modifyBy,@modifyTime,@canMultiSelect,@canNull,@canCustom,@ctype);SELECT ifnull(@@IDENTITY,0)";

            return(conn.Query <int>(sqlCommandText, model, trn).First());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns></returns>
        public bool Update(CriticalMass.TagNode.Model.tattribute_name model)
        {
            IDbConnection conn           = base.GetConnection();
            string        sqlCommandText = @"update tattribute_name set `name`=@name,`code`=@code,`createBy`=@createBy,`createTime`=@createTime,`status`=@status,`is_custom`=@is_custom,`modifyBy`=@modifyBy,`modifyTime`=@modifyTime,`canMultiSelect`=@canMultiSelect,`canNull`=@canNull,`canCustom`=@canCustom,`ctype`=@ctype where id=@id";

            return(conn.Execute(sqlCommandText, model) > 0 ? true : false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="where">条件</param>
        ///<param name="parameter">参数</param>
        /// <returns></returns>
        public bool Exists(string where, CriticalMass.TagNode.Model.tattribute_name parameter)
        {
            IDbConnection conn = base.GetConnection();
            string        sql  = @"SELECT count(0) FROM tattribute_name WHERE {0} ";
            int           res  = conn.Query <int>(string.Format(sql, where), parameter).First();

            return(res > 0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 添加属性
        /// </summary>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public string AddOrModifyAttribute([FromBody] dynamic parameModel)
        {
            AjaxResult result = new AjaxResult();

            try{
                TransactionOptions options = new TransactionOptions();
                options.IsolationLevel = System.Transactions.IsolationLevel.RepeatableRead;
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) {
                    dynamic model           = parameModel;
                    var     AttrNameService = HttpContext.RequestServices.GetService <ItAttribute_NameRepository>();
                    int     AttrId          = model.attrId;
                    CriticalMass.TagNode.Model.tattribute_name AttrName = AttrId == 0 ? new CriticalMass.TagNode.Model.tattribute_name() : AttrNameService.GetModel(AttrId);
                    if (AttrName.id > 0 && AttrNameService.Exists(string.Format("name='{0}' and id<>'{1}'", model.attrName.ToString(), AttrName.id)))
                    {
                        throw new Exception("属性名已存在,请使用其他名称!");
                    }
                    else if (AttrName.id == 0 && AttrNameService.Exists(string.Format("name='{0}'", model.attrName.ToString())))
                    {
                        throw new Exception("属性名已存在,请使用其他名称!");
                    }
                    AttrName.canMultiSelect = model.canMultiSelect;
                    AttrName.canNull        = model.canNull;
                    AttrName.canCustom      = model.canCustom;
                    AttrName.name           = model.attrName;
                    AttrName.ctype          = model.ctype;
                    if (AttrId == 0)
                    {
                        AttrName.createBy   = model.createBy;
                        AttrName.createTime = DateTime.Now;
                        AttrName.status     = 1;
                        AttrName.id         = AttrNameService.Insert(AttrName);
                        AttrName.code       = AttrName.id.IntToHex();
                    }
                    else
                    {
                        AttrName.modifyBy   = model.modifyBy;
                        AttrName.modifyTime = DateTime.Now;
                    }
                    AttrNameService.Update(AttrName);
                    if (model.subValues == null || model.subValues.ToString() == "[]")
                    {
                        throw new Exception("值不能为空.");
                    }
                    CriticalMass.TagNode.Repository.Common.ExecSql(string.Format("update tattribute_value t set t.status=0 where t.attrId='{0}'", AttrName.id));
                    string subValues = model.subValues.ToString();
                    AddSubValues(AttrName.id, 0, AttrName.createBy, AttrName.modifyBy, subValues);
                    CriticalMass.TagNode.Repository.Common.ExecSql(string.Format("delete from tattribute_value t where t.status=0 and t.attrId='{0}'", AttrName.id));
                    result.Msg = "ok";
                    scope.Complete();
                }
            }
            catch (Exception ex) {
                result.Msg = ex.Message;
            }
            return(result.ToJson());
        }
Exemplo n.º 5
0
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="id">id</param>
        /// <returns></returns>
        public bool Del(string where, CriticalMass.TagNode.Model.tattribute_name parameter, IDbTransaction trn)
        {
            if (string.IsNullOrWhiteSpace(where))
            {
                return(false);
            }
            IDbConnection conn           = trn.Connection;
            string        sqlCommandText = @"delete from tattribute_name where " + where;

            return(conn.Execute(sqlCommandText, parameter, trn) > 0 ? true : false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model">模型</param>
        /// <returns></returns>
        public bool Update(string field, CriticalMass.TagNode.Model.tattribute_name model, IDbTransaction trn)
        {
            IDbConnection conn = trn.Connection;

            if (model.id <= 0)
            {
                return(false);
            }
            string sqlCommandText = @"update tattribute_name set " + field + " where id=@id";

            return(conn.Execute(sqlCommandText, model, trn) > 0 ? true : false);
        }