예제 #1
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Update(CompanyNewsInfo model)
        {
            string strSQL = "UPDATE CompanyNews SET Title = @Title ,Content = @Content,PublishDateTime =@PublishDateTime,ModifyDateTime = GETDATE(),Remark = @Remark,ImageUrl = @ImageUrl,Tags = @Tags WHERE Id = @Id AND CompanyId = @CompanyId";

            SqlParameter[] parms =
            {
                new SqlParameter("Id",              SqlDbType.Int),
                new SqlParameter("CompanyId",       SqlDbType.Int),
                new SqlParameter("Title",           SqlDbType.NVarChar),
                new SqlParameter("Content",         SqlDbType.NVarChar),
                new SqlParameter("PublishDateTime", SqlDbType.DateTime),
                new SqlParameter("Remark",          SqlDbType.NVarChar),
                new SqlParameter("ImageUrl",        SqlDbType.NVarChar),
                new SqlParameter("Tags",            SqlDbType.NVarChar),
            };
            parms[0].Value = model.Id;
            parms[1].Value = model.CompanyId;
            parms[2].Value = model.Title;
            parms[3].Value = model.Content;
            parms[4].Value = model.PublishDateTime;
            parms[5].Value = string.IsNullOrEmpty(model.Remark) ? string.Empty : model.Remark;
            parms[6].Value = string.IsNullOrEmpty(model.ImageUrl) ? string.Empty : model.ImageUrl;
            parms[7].Value = string.IsNullOrEmpty(model.Tags) ? string.Empty : model.Tags;

            //插入News2Tech表
            InsertNews2Tech(model.Id, model.TechIds);

            return(SQLPlus.ExecuteNonQuery(CommandType.Text, strSQL, parms));
        }
예제 #2
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Insert(CompanyNewsInfo model)
        {
            string strSQL = "DECLARE @MyId AS INT;INSERT INTO CompanyNews(CompanyId,Title,Content,PublishDateTime,ModifyDateTime,CreateDateTime,IsDeleted,Remark,ImageUrl,Tags,[Type]) VALUES(@CompanyId,@Title,@Content,@PublishDateTime,GETDATE(),GETDATE(),0,@Remark,@ImageUrl,@Tags,@Type);SELECT @MyId = @@IDENTITY;UPDATE CompanyNews SET Url = '/company/'+CAST(@CompanyId AS NVARCHAR(255))+'/newsdetail.html?id='+CAST(@MyId AS NVARCHAR(255)) WHERE Id = @MyId; SELECT @MyId;";

            SqlParameter[] parms =
            {
                new SqlParameter("Id",              SqlDbType.Int),
                new SqlParameter("CompanyId",       SqlDbType.Int),
                new SqlParameter("Title",           SqlDbType.NVarChar),
                new SqlParameter("Content",         SqlDbType.NVarChar),
                new SqlParameter("PublishDateTime", SqlDbType.DateTime),
                new SqlParameter("Remark",          SqlDbType.NVarChar),
                new SqlParameter("ImageUrl",        SqlDbType.NVarChar),
                new SqlParameter("Tags",            SqlDbType.NVarChar),
                new SqlParameter("Type",            SqlDbType.NVarChar),
            };
            parms[0].Value = model.Id;
            parms[1].Value = model.CompanyId;
            parms[2].Value = model.Title;
            parms[3].Value = model.Content;
            parms[4].Value = model.PublishDateTime <= DateTime.MinValue ? DateTime.Now : model.PublishDateTime;
            parms[5].Value = string.IsNullOrEmpty(model.Remark) ? string.Empty : model.Remark;
            parms[6].Value = string.IsNullOrEmpty(model.ImageUrl) ? string.Empty : model.ImageUrl;
            parms[7].Value = string.IsNullOrEmpty(model.Tags) ? string.Empty : model.Tags;
            parms[8].Value = string.IsNullOrEmpty(model.Type) ? "news" : model.Type;
            int id = Convert.ToInt32(SQLPlus.ExecuteScalar(CommandType.Text, strSQL, parms));

            //插入News2Tech表
            InsertNews2Tech(id, model.TechIds);

            return(id);
        }
예제 #3
0
        public ActionResult ApplicationEdit(CompanyNewsInfo oldModel, FormCollection fc)
        {
            bool errors      = false;
            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", "内容不能为空");
            }
            if (!errors && ModelState.IsValid)
            {
                oldModel.CompanyId = companyInfo.CompanyId;
                oldModel.Type      = "application";

                //添加技术分类
                string   requestTechIds = fc["techcat"] == null ? string.Empty : fc["techcat"];
                string[] strTechIds     = requestTechIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                int[]    techIds        = strTechIds.Select(i => Utils.StrToInt(i, 0)).ToArray <int>();
                oldModel.TechIds = techIds;

                CompanyNewsService.Update(oldModel);
                ViewBag.Msg = "保存成功!";
            }
            return(View(oldModel));
        }
예제 #4
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static CompanyNewsInfo Update(CompanyNewsInfo model)
 {
     if (model.Id == 0)
     {
         int id = CompanyNewsManage.Insert(model);
         model.Id = id;
     }
     else
     {
         CompanyNewsManage.Update(model);
     }
     return(model);
 }
예제 #5
0
        /// <summary>
        /// 前台页面公司新闻列表,也包含编辑发的新闻(包含CompanyNews和Articles两个部分)
        /// </summary>
        /// <param name="topCount"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        public static IList <CompanyNewsInfo> ListWithoutPageForFront(int topCount, int companyId)
        {
            string strSQL = string.Format(@"SELECT TOP({0})* FROM (
	SELECT TOP(100) Id,CompanyId,[Type],Title,Content,Remark,ImageUrl,Tags,PublishDateTime,ModifyDateTime,CreateDateTime,IsDeleted,Url FROM CompanyNews WITH(NOLOCK) WHERE CompanyId = {1} AND IsDeleted = 0 ORDER BY PublishDateTime DESC
	UNION ALL
	SELECT TOP(100) Id,CompanyId,'article',Title,Content,Remark,ImageUrl,Tags,PublishDateTime,LastModifyDateTime,CreateDateTime,IsDeleted,Url FROM Articles WITH(NOLOCK) WHERE CompanyId = {1} AND IsDeleted = 0 ORDER BY PublishDateTime DESC 
) AS A ORDER BY PublishDateTime DESC", topCount, companyId);
            IList <CompanyNewsInfo> list  = new List <CompanyNewsInfo>();
            CompanyNewsInfo         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
        /// <summary>
        /// 分页列表(包含CompanyNews和Articles两个部分)
        /// </summary>
        /// <param name="searchSetting"></param>
        /// <returns></returns>
        public static IPageOfList <CompanyNewsInfo> List(CompanyNewsSearchSetting searchSetting)
        {
            FastPaging fp = new FastPaging();

            fp.OverOrderBy = " CN.PublishDateTime DESC";
            fp.PageIndex   = searchSetting.PageIndex;
            fp.PageSize    = searchSetting.PageSize;
            fp.QueryFields = "*";
            fp.TableName   = string.Format(@"( 
SELECT Id,CompanyId,[Type],Title,Content,Remark,ImageUrl,Tags,PublishDateTime,ModifyDateTime,CreateDateTime,IsDeleted,Url 
FROM CompanyNews WITH(NOLOCK) WHERE CompanyId = {0} AND [Type] = '{1}' AND IsDeleted = 0 
UNION ALL 
SELECT Id,CompanyId,'article',Title,Content,Remark,ImageUrl,Tags,PublishDateTime,LastModifyDateTime,CreateDateTime,IsDeleted,Url 
FROM Articles WITH(NOLOCK) WHERE CompanyId = {0} AND IsDeleted = 0)", searchSetting.CompanyId, searchSetting.Type);
            fp.PrimaryKey  = "Id";
            fp.TableReName = "CN";

            IList <CompanyNewsInfo> list  = new List <CompanyNewsInfo>();
            CompanyNewsInfo         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 <CompanyNewsInfo>(list, searchSetting.PageIndex, searchSetting.PageSize, count));
        }