Пример #1
0
        public static int Update(CompanyProductInfo model)
        {
            string strSQL = "UPDATE CompanyProducts SET CategoryId = @CategoryId,Title = @Title ,Content = @Content,ImageUrl = @ImageUrl,Remark = @Remark,PublishDateTime = @PublishDatetime,ModifyDateTime = GETDATE(),Tags = @Tags,SystemCategoryId = @SystemCategoryId WHERE Id = @Id";

            SqlParameter[] parms =
            {
                new SqlParameter("Id",               SqlDbType.Int),
                new SqlParameter("CategoryId",       SqlDbType.Int),
                new SqlParameter("CompanyId",        SqlDbType.Int),
                new SqlParameter("Title",            SqlDbType.NVarChar),
                new SqlParameter("Content",          SqlDbType.NVarChar),
                new SqlParameter("ImageUrl",         SqlDbType.NVarChar),
                new SqlParameter("Remark",           SqlDbType.NVarChar),
                new SqlParameter("PublishDateTime",  SqlDbType.DateTime),
                new SqlParameter("Tags",             SqlDbType.NVarChar),
                new SqlParameter("SystemCategoryId", SqlDbType.Int),
            };
            parms[0].Value = model.Id;
            parms[1].Value = model.CategoryId;
            parms[2].Value = model.CompanyId;
            parms[3].Value = string.IsNullOrEmpty(model.Title) ? string.Empty : model.Title;
            parms[4].Value = string.IsNullOrEmpty(model.Content) ? string.Empty : model.Content;
            parms[5].Value = string.IsNullOrEmpty(model.ImageUrl) ? string.Empty : model.ImageUrl;
            parms[6].Value = string.IsNullOrEmpty(model.Remark) ? string.Empty : model.Remark;
            parms[7].Value = model.PublishDateTime <= DateTime.MinValue ? DateTime.Now : model.PublishDateTime;
            parms[8].Value = string.IsNullOrEmpty(model.Tags) ? string.Empty : model.Tags;
            parms[9].Value = model.SystemCategoryId;
            return(SQLPlus.ExecuteNonQuery(CommandType.Text, strSQL, parms));
        }
Пример #2
0
        public static int Insert(CompanyProductInfo model)
        {
            string strSQL = "INSERT INTO dbo.CompanyProducts(CategoryId,CompanyId,Title,Content,ImageUrl,Remark,PublishDateTime,CreateDateTime,ModifyDateTime,IsDeleted,Tags,SystemCategoryId) VALUES(@CategoryId,@CompanyId,@Title,@Content,@ImageUrl,@Remark,@PublishDateTime,GETDATE(),GETDATE(),0,@Tags,@SystemCategoryId);SELECT @@IDENTITY;";

            SqlParameter[] parms =
            {
                new SqlParameter("Id",               SqlDbType.Int),
                new SqlParameter("CategoryId",       SqlDbType.Int),
                new SqlParameter("CompanyId",        SqlDbType.Int),
                new SqlParameter("Title",            SqlDbType.NVarChar),
                new SqlParameter("Content",          SqlDbType.NVarChar),
                new SqlParameter("ImageUrl",         SqlDbType.NVarChar),
                new SqlParameter("Remark",           SqlDbType.NVarChar),
                new SqlParameter("PublishDateTime",  SqlDbType.DateTime),
                new SqlParameter("Tags",             SqlDbType.NVarChar),
                new SqlParameter("SystemCategoryId", SqlDbType.Int),
            };
            parms[0].Value = model.Id;
            parms[1].Value = model.CategoryId;
            parms[2].Value = model.CompanyId;
            parms[3].Value = string.IsNullOrEmpty(model.Title) ? string.Empty : model.Title;
            parms[4].Value = string.IsNullOrEmpty(model.Content) ? string.Empty : model.Content;
            parms[5].Value = string.IsNullOrEmpty(model.ImageUrl) ? string.Empty : model.ImageUrl;
            parms[6].Value = string.IsNullOrEmpty(model.Remark) ? string.Empty : model.Remark;
            parms[7].Value = model.PublishDateTime <= DateTime.MinValue ? DateTime.Now : model.PublishDateTime;
            parms[8].Value = string.IsNullOrEmpty(model.Tags) ? string.Empty : model.Tags;
            parms[9].Value = model.SystemCategoryId;
            return(Convert.ToInt32(SQLPlus.ExecuteScalar(CommandType.Text, strSQL, parms)));
        }
Пример #3
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static CompanyProductInfo Update(CompanyProductInfo model)
 {
     if (model.Id == 0)
     {
         int id = CompanyProductManage.Insert(model);
         model.Id = id;
     }
     else
     {
         CompanyProductManage.Update(model);
     }
     return(model);
 }
Пример #4
0
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="searchSetting"></param>
        /// <returns></returns>
        public static IPageOfList <CompanyProductInfo> List(CompanyProductSearchSetting searchSetting)
        {
            FastPaging fp = new FastPaging();

            fp.OverOrderBy = " CP.PublishDateTime DESC";
            fp.PageIndex   = searchSetting.PageIndex;
            fp.PageSize    = searchSetting.PageSize;
            fp.QueryFields = "*";
            fp.TableName   = "CompanyProducts";
            fp.PrimaryKey  = "Id";
            fp.TableReName = "CP";
            fp.WithOptions = " WITH(NOLOCK)";
            fp.Condition   = " IsDeleted = 0 ";
            if (searchSetting.CompanyId > 0)
            {
                fp.Condition += string.Format(" AND CompanyId = {0}", searchSetting.CompanyId);
            }
            if (searchSetting.CategoryId > 0)
            {
                fp.Condition += string.Format(" AND CategoryId = {0}", searchSetting.CategoryId);
            }
            if (searchSetting.SystemCategoryId > 0)
            {
                fp.Condition += string.Format(" AND SystemCategoryId = {0}", searchSetting.SystemCategoryId);
            }

            IList <CompanyProductInfo> list  = new List <CompanyProductInfo>();
            CompanyProductInfo         model = null;
            DataTable dt = SQLPlus.ExecuteDataTable(CommandType.Text, fp.Build2005());

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    model = GetByDataRow(dr);
                    if (model != null)
                    {
                        list.Add(model);
                    }
                }
            }
            int count = Convert.ToInt32(SQLPlus.ExecuteScalar(CommandType.Text, fp.BuildCountSQL()));

            return(new PageOfList <CompanyProductInfo>(list, searchSetting.PageIndex, searchSetting.PageSize, count));
        }
Пример #5
0
        /// <summary>
        /// 没有分类的列表
        /// </summary>
        /// <param name="topCount"></param>
        /// <returns></returns>
        public static IList <CompanyProductInfo> ListWithoutPage(int topCount, int companyId)
        {
            string strSQL = string.Format("SELECT TOP({0}) * FROM CompanyProducts WITH(NOLOCK) WHERE IsDeleted = 0 {1} ORDER BY PublishDateTime DESC", topCount, companyId > 0 ? string.Format(" AND CompanyId = {0} ", companyId) : string.Empty);
            IList <CompanyProductInfo> list  = new List <CompanyProductInfo>();
            CompanyProductInfo         model = null;
            DataTable dt = SQLPlus.ExecuteDataTable(CommandType.Text, strSQL);

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    model = GetByDataRow(dr);
                    if (model != null)
                    {
                        list.Add(model);
                    }
                }
            }
            return(list);
        }
Пример #6
0
        public ActionResult ProductEdit(CompanyProductInfo oldModel, FormCollection fc)
        {
            bool errors      = false;
            bool isAdd       = oldModel.Id == 0;
            var  companyInfo = MemberService.GetCompanyInfoByUserId(PlantEngContext.Current.UserId);

            if (string.IsNullOrEmpty(oldModel.Title))
            {
                errors = true;
                ModelState.AddModelError("TitleEmpty", "标题不能为空");
            }
            if (string.IsNullOrEmpty(oldModel.Content))
            {
                errors = true;
                ModelState.AddModelError("ContentEmpty", "内容不能为空");
            }
            oldModel.SystemCategoryId = Utils.StrToInt(fc["syscat"], 0);

            if (oldModel.SystemCategoryId == 0)
            {
                errors = true;
                ModelState.AddModelError("SysCatEmpty", "请选择产品系统分类");
            }
            //为了在更新的时候,判断新分类是否还是以前的分类,然后为更新新分类产品数做判断
            int oldCatId = oldModel.CategoryId;

            oldModel.CategoryId = Utils.StrToInt(fc["cat"], 0);
            if (oldModel.CategoryId == 0)
            {
                errors = true;
                ModelState.AddModelError("CatEmpty", "请选择自定义分类");
            }
            if (!errors && ModelState.IsValid)
            {
                oldModel.CompanyId = companyInfo.CompanyId;

                oldModel = CompanyProductService.Update(oldModel);
                if (isAdd)
                {
                    //如果是添加,则更新产品分类表中的产品数 + 1
                    CompanyProductCategoryService.UpdateProductCount(oldModel.CategoryId, companyInfo.CompanyId, true);
                }
                else
                {
                    //如果没有更改分类,则什么都不变
                    //否则则原来的分类的产品数-1,新分类产品数+ 1
                    if (oldCatId == oldModel.CategoryId)
                    {
                        //说明还是在原来的分类上更新
                    }
                    else
                    {
                        //分类改变了
                        //原来的分类产品数 - 1 ,新分类数 + 1
                        CompanyProductCategoryService.UpdateProductCount(oldCatId, companyInfo.CompanyId, false);
                        //新分类 + 1
                        CompanyProductCategoryService.UpdateProductCount(oldModel.CategoryId, companyInfo.CompanyId, true);
                    }
                }


                ViewBag.Msg = "保存成功!";
            }
            //产品分类
            ViewBag.CategoryList = CompanyProductCategoryService.GetCategoryList(companyInfo.CompanyId);
            return(View(oldModel));
        }