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

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

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

            return(res > 0);
        }
Esempio n. 4
0
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="id">id</param>
        /// <returns></returns>
        public bool Del(string where, CriticalMass.TagNode.Model.tattribute_value parameter, IDbTransaction trn)
        {
            if (string.IsNullOrWhiteSpace(where))
            {
                return(false);
            }
            IDbConnection conn           = trn.Connection;
            string        sqlCommandText = @"delete from tattribute_value where " + where;

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

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

            return(conn.Execute(sqlCommandText, model, trn) > 0 ? true : false);
        }
Esempio n. 6
0
        /// <summary>
        /// 递归添加子项
        /// </summary>
        /// <param name="attrId"></param>
        /// <param name="pid"></param>
        private void AddSubValues(int attrId, int pid, int createBy, int modifyBy, string subValues)
        {
            List <dynamic> lt           = ((string)subValues).ToString().Str2List <dynamic>();
            var            ValueService = HttpContext.RequestServices.GetService <Itattribute_valueRepository>();

            if (lt != null && lt.Count != 0)
            {
                lt.Each(a => {
                    int attrValId = a.attrValId;
                    string val    = a.val;
                    CriticalMass.TagNode.Model.tattribute_value model = attrValId == 0 ? new CriticalMass.TagNode.Model.tattribute_value() : ValueService.GetModel(attrValId);
                    if (model.id > 0 && ValueService.Exists(string.Format("val='{0}' and id<>'{1}' and attrid='{2}'", val, model.id, attrId)))
                    {
                        throw new Exception("属性值重复.");
                    }
                    else if (model.id == 0 && ValueService.Exists(string.Format("val='{0}' and attrid='{1}'", val, attrId)))
                    {
                        throw new Exception("属性值重复.");
                    }
                    model.val    = val;
                    model.attrId = attrId;
                    model.Pid    = pid;
                    model.status = 1;
                    if (attrValId == 0)
                    {
                        model.createBy   = createBy;
                        model.createTime = DateTime.Now;
                        int ValId        = ValueService.Insert(model);
                        model.id         = ValId;
                        model.code       = model.id.IntToHex();//生成值Code
                    }
                    else
                    {
                        model.modifyBy   = modifyBy;
                        model.modifyTime = DateTime.Now;
                    }
                    ValueService.Update(model);
                    subValues = a.subValues.ToString();
                    AddSubValues(attrId, model.id, createBy, modifyBy, subValues);
                });
            }
        }