コード例 #1
0
        protected void rgNews_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.Item != null && (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem))
            {
                GridDataItem dataItem = (GridDataItem)e.Item;
                int          id       = Convert.ToInt32(dataItem.GetDataKeyValue("Id"));
                NewsContent  st       = db.NewsContents.SingleOrDefault <NewsContent>(s => s.Id == id);
                if (e.CommandName == "Send" && st != null && st.ApprovementStatus <= (short)EnumNewsApprovementStatus.DaDuyetChuaXuatBan)
                {
                    st.ApprovementStatus = (short)EnumNewsApprovementStatus.DaDuyetChuaXuatBan;
                    db.SubmitChanges();
                    LoadNewsContent();
                }
                else if (e.CommandName == "WithDraw" && st != null && st.ApprovementStatus == (short)EnumNewsApprovementStatus.DaXuatBan)
                {
                    st.ApprovementStatus = (short)EnumNewsApprovementStatus.ThuHoiTinDaXuatBan;

                    NewsApprovementHistory newHis = new NewsApprovementHistory();
                    newHis.ApprovedBy   = UserInfo.UserAccount.AccountName;
                    newHis.CreatedTime  = DateTime.Now;
                    newHis.NewsId       = st.Id;
                    newHis.Comment      = "Thu hồi tin đã xuất bản";
                    newHis.AppStatustId = (short)EnumNewsApprovementStatus.ThuHoiTinDaXuatBan;

                    NewsApprovementHistory nah = db.NewsApprovementHistories.OrderByDescending <NewsApprovementHistory, DateTime>(nn => nn.CreatedTime.Value).FirstOrDefault <NewsApprovementHistory>(nnn => nnn.NewsId == st.Id);
                    //Int16 lastSeq = (from na in db.NewsApprovementHistories where na.NewsId == st.Id orderby na.CreatedTime descending select na.Sequence.Value).Take(1).SingleOrDefault<Int16>();
                    short lastSeq = 0;
                    if (nah != null)
                    {
                        lastSeq = nah.Sequence.Value;
                    }
                    newHis.Sequence = (short)(lastSeq + 1);

                    db.NewsApprovementHistories.InsertOnSubmit(newHis);

                    db.SubmitChanges();
                    LoadNewsContent();
                }
            }
        }
コード例 #2
0
        private void ProcessNewsContent()
        {
            NewsContent st = null;

            if (NewsId > 0)
            {
                st = db.NewsContents.SingleOrDefault <NewsContent>(s => s.Id == NewsId && (s.ApprovementStatus == (short)EnumNewsApprovementStatus.DaDuyetChuaXuatBan ||
                                                                                           s.ApprovementStatus == (short)EnumNewsApprovementStatus.ThuHoiTinDaXuatBan));
            }

            if (st == null)
            {
                return;
            }

            PreventSQLInjection.ClearSQLInjectionInAllControls(this);
            st.NewsTitle   = txtTieuDe.Text;
            st.Description = txtMoTa.Text;
            //st.Content = Editor1.MainEditor.Content;
            st.Content         = Editor1.MainEditor.Text;
            st.LastUpdatedTime = DateTime.Now;
            st.CategoryId      = Convert.ToInt32(rcbCategories.SelectedValue);
            st.Source          = txtSource.Text;
            st.OriginAuthor    = txtAuthor.Text;
            //st.Hidden = !ckbShow.Checked;

            //upload hinh dai dien cua ban tin
            if (fulHinhAnh.HasFile)
            {
                //kiem tra kieu va kich co file
                //if ((NT.Lib.Globals.IsImageFile(fulHinhAnh.FileName)) && (fulHinhAnh.FileContent.Length <= SystemConfig.ApplicationConfig.MaxUserImageSizeUpload))
                if (NT.Lib.Globals.IsImageFile(fulHinhAnh.FileName))
                {
                    //xoa anh cu neu co (truong hop cap nhat)
                    if (!String.IsNullOrEmpty(st.ImagePath))
                    {
                        System.IO.File.Delete(Server.MapPath(st.ImagePath));
                    }

                    string uploadFolder = Server.MapPath(virtualUploadFolder + ThumbFolder);
                    if (!System.IO.Directory.Exists(uploadFolder))
                    {
                        System.IO.Directory.CreateDirectory(uploadFolder);
                    }

                    //tao chuoi ten file ngau nhien
                    string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + Hash.GetRandomHashKey(4) + "." + NT.Lib.Globals.GetFileExtension(fulHinhAnh.FileName);

                    //resize anh
                    System.Drawing.Image img        = System.Drawing.Image.FromStream(fulHinhAnh.PostedFile.InputStream);
                    System.Drawing.Image imgResized = Utilities.ResizeImage(img, SystemConfig.ApplicationConfig.News_MaxImageWidth, SystemConfig.ApplicationConfig.News_MaxImageWidth);
                    imgResized.Save(uploadFolder + fileName);//luu file vao o cung

                    //luu duong dan anh vao db
                    st.ImagePath = virtualUploadFolder + ThumbFolder + fileName;
                }
            }

            NewsApprovementHistory apHis = new NewsApprovementHistory();

            apHis.NewsId = st.Id;

            if (ddlApprove.SelectedValue == "1")
            {
                st.ApprovementStatus = (short)EnumNewsApprovementStatus.DaXuatBan;
                apHis.IsApproved     = true;
            }
            else
            {
                st.ApprovementStatus = (short)EnumNewsApprovementStatus.KhongXuatBan;
                apHis.IsApproved     = false;
            }

            apHis.AppStatustId = st.ApprovementStatus;
            apHis.ApprovedBy   = UserInfo.UserAccount.AccountName;
            apHis.Comment      = txtApprovementDetail.Text;
            apHis.CreatedTime  = DateTime.Now;
            NewsApprovementHistory nah = db.NewsApprovementHistories.OrderByDescending <NewsApprovementHistory, DateTime>(nn => nn.CreatedTime.Value).FirstOrDefault <NewsApprovementHistory>(nnn => nnn.NewsId == st.Id);
            //Int16 lastSeq = (from na in db.NewsApprovementHistories where na.NewsId == st.Id orderby na.CreatedTime descending select na.Sequence.Value).Take(1).SingleOrDefault<Int16>();
            short lastSeq = 0;

            if (nah != null)
            {
                lastSeq = nah.Sequence.Value;
            }
            apHis.Sequence = (short)(lastSeq + 1);

            st.ShowInDropdownMenu = true;
            st.ShowInFeature      = ckbFeature.Checked;
            st.ShowInMostView     = ckbHot.Checked;
            st.ShowInNewest       = ckbNewest.Checked;
            st.Hidden             = false;
            st.PublishFrom        = DateTime.Now;
            st.PublishTo          = DateTime.MaxValue;


            db.NewsApprovementHistories.InsertOnSubmit(apHis);

            db.SubmitChanges();

            Response.Redirect(Common.GenerateAdminUrl("publishnews"));
        }