public static IndustryInfo Create(IndustryInfo model)
 {
     if (model.Id == 0)
     {
         //Add
         int id = CategoryManage.AddIndustryInfo(model);
         model.Id = id;
     }
     else
     {
         CategoryManage.UpdateIndustryInfo(model);
     }
     return model;
 }
        public ActionResult List(IndustryInfo model)
        {
            //检查
            //如果添加,判断别名是否存在
            bool isAdd = true;
            var list = IndustryService.List();
            if (model.Id > 0)
            {
                isAdd = false;
            }
            if (isAdd)
            {
                //判断是否别名存在
                if (!string.IsNullOrEmpty(model.Alias))
                {
                    if (list.Where(m => m.Alias == model.Alias).Count() > 0)
                    {
                        ModelState.AddModelError("ALIASEXISTS", "别名存在,请选择其他别名");
                    }
                }
            }
            else
            {
                //编辑,除了自身之外,判断是否存在
                if (!string.IsNullOrEmpty(model.Alias))
                {
                    if (list.Where(m => (m.Alias == model.Alias && m.Id != model.Id)).Count() > 0)
                    {
                        ModelState.AddModelError("ALIASEXISTS", "别名存在,请选择其他别名");
                    }
                }
            }

            if (ModelState.IsValid)
            {
                IndustryService.Create(model);
                ViewBag.Msg = "保存成功";
            }

            list = IndustryService.List();
            ViewBag.List = list;


            return View();
        }
        public static int UpdateIndustryInfo(IndustryInfo model)
        {
            string strSQL = "UPDATE Categories SET Name = @Name,Alias = @Alias,Sort = @Sort,IsDeleted = @IsDeleted WHERE Id = @Id AND [Type] = 'industry'";
            SqlParameter[] parms = { 
                                    new SqlParameter("Id",SqlDbType.Int),
                                    new SqlParameter("Name",SqlDbType.NVarChar),
                                    new SqlParameter("Alias",SqlDbType.NVarChar),
                                    new SqlParameter("Sort",SqlDbType.Int),
                                    new SqlParameter("IsDeleted",SqlDbType.Bit),
                                   };
            parms[0].Value = model.Id;
            parms[1].Value = model.Name;
            parms[2].Value = model.Alias;
            parms[3].Value = model.Sort;
            parms[4].Value = model.IsDeleted;

            return SQLPlus.ExecuteNonQuery(CommandType.Text, strSQL, parms);
        }
 public static IndustryInfo GetIndustryInfoById(int id)
 {
     string strSQL = "SELECT * FROM Categories WITH(NOLOCK) WHERE Id = @Id AND [Type] = 'industry'";
     SqlParameter parm = new SqlParameter("Id", id);
     DataRow dr = SQLPlus.ExecuteDataRow(CommandType.Text, strSQL, parm);
     IndustryInfo model = new IndustryInfo();
     if (dr != null)
     {
         model.Alias = dr.Field<string>("Alias");
         model.Id = dr.Field<int>("Id");
         model.IsDeleted = dr.Field<bool>("IsDeleted");
         model.Name = dr.Field<string>("Name");
         model.Sort = dr.Field<int>("Sort");
     }
     return model;
 }
        /// <summary>
        /// 添加行业分类
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int AddIndustryInfo(IndustryInfo model) {
            string strSQL = "INSERT INTO Categories(ParentId,RootId,ParentIds,Name,Alias,Sort,IsDeleted,[Type],CreateDateTime) VALUES(0,0,'0',@Name,@Alias,@Sort,@IsDeleted,@Type,GETDATE());SELECT @@IDENTITY;";
            SqlParameter[] param = { 
                                    new SqlParameter("Name",SqlDbType.NVarChar),
                                    new SqlParameter("Alias",SqlDbType.VarChar),
                                    new SqlParameter("Sort",SqlDbType.Int),
                                    new SqlParameter("IsDeleted",SqlDbType.Bit),
                                    new SqlParameter("Type",SqlDbType.VarChar)
                                   };
            param[0].Value = model.Name;
            param[1].Value = model.Alias.ToLower();
            param[2].Value = model.Sort;
            param[3].Value = model.IsDeleted;
            param[4].Value = CatType.Industry.ToString().ToLower();

            return Convert.ToInt32(SQLPlus.ExecuteScalar(CommandType.Text,strSQL,param));
        }