Beispiel #1
0
        public void ProcessRequest(HttpContext context)
        {
            try {
                long NewsID = 0;
                Int64.TryParse(context.Request.Form["news_id"].ToString(), out NewsID);
                int CatID = 0;
                Int32.TryParse(context.Request.Form["cat_id"].ToString(), out CatID);

                //NewsEditHelper.AutoSave_Insert(NewsID, CatID, context.Request.Form["news_title"].ToString(), context.Request.Form["image"].ToString(), context.Request.Form["sapo"].ToString(), context.Request.Form["news_content"].ToString(), DateTime.Now);

                NewsRow objNewsRow = NewsEditHelper.GetNewsInfo_News(NewsID, false);
                if (objNewsRow == null)
                {
                    NewsEditHelper.CreateNews(NewsID, CatID, string.Empty, context.Request.Form["news_title"].ToString(), context.Request.Form["image"].ToString(), context.Request.Form["news_title"].ToString(), context.Request.Form["sapo"].ToString(), context.Request.Form["news_content"].ToString(), string.Empty, false, 0 /*lưu tạm*/, 0, string.Empty, string.Empty, string.Empty, DateTime.Now, false, false, 0, string.Empty, string.Empty, string.Empty, false, string.Empty, string.Empty, string.Empty, 0, string.Empty, string.Empty);
                }
                else
                if (objNewsRow.News_Status == 0)
                {
                    NewsEditHelper.UpdateNews(NewsID, CatID, string.Empty, context.Request.Form["news_title"].ToString(), context.Request.Form["image"].ToString(), string.Empty, context.Request.Form["sapo"].ToString(), context.Request.Form["news_content"].ToString(), false, 0, 0, string.Empty, string.Empty, DateTime.Now, false, false, false, 0, string.Empty, string.Empty, string.Empty, string.Empty, false, string.Empty, string.Empty, string.Empty, 0, string.Empty, string.Empty);
                }

                context.Response.Write("Lưu tự động lúc : " + DateTime.Now);
            }
            catch (Exception ex) {
                context.Response.Write(ex.Message);
            }
        }
Beispiel #2
0
        public static void DeleteNewsRelation(string _news_id, string _news_id_relation_delete)
        {
            NewsRow objNewsRow             = NewsEditHelper.GetNewsInfo(Convert.ToInt64(_news_id.Trim()));
            string  strNew_NewsId_Relation = objNewsRow.News_Relation.Replace("," + _news_id_relation_delete, "");

            strNew_NewsId_Relation = strNew_NewsId_Relation.Replace(_news_id_relation_delete, "");


            // Xoa dau , o dau chuoi string
            if (strNew_NewsId_Relation.Trim() != "")
            {
                if (strNew_NewsId_Relation[0] == ',')
                {
                    strNew_NewsId_Relation = strNew_NewsId_Relation.Remove(0, 1);
                }
            }

            using (MainDB objDb = new MainDB()) {
                // Update vao bang news
                objDb.SelectQuery(" Update  News Set News_Relation = '" + strNew_NewsId_Relation + "'" +
                                  " Where News_Id = " + _news_id
                                  );
                //update vao bang news Published
                objDb.SelectQuery(" Update  NewsPublished Set News_Relation = '" + strNew_NewsId_Relation + "'" +
                                  " Where News_Id = " + _news_id
                                  );
            }
        }
        /// <summary>
        /// Kiểm tra xem bài viết này có đồng thời 2 người can thiệp không [bacth, 12:29 PM 5/31/2008]
        /// </summary>
        /// <param name="message">Thông báo trong trường hợp có sự động độ</param>
        /// <returns></returns>
        private bool isConcurrency(ref string message)
        {
            if (string.IsNullOrEmpty(Request.QueryString["NewsRef"]))
            {
                return(false);                                                      // bài viết mới - không đụng độ
            }
            string cpMode = Request.QueryString["cpmode"].Replace("add,", string.Empty);

            long newsId = 0;

            long.TryParse(Request.QueryString["NewsRef"], out newsId);
            NewsRow news = NewsEditHelper.GetNewsInfo(newsId);

            if (news == null)
            {
                message = "Bài viết không tồn tại hoặc đã bị xóa";
                return(true);
            }

            if (cpMode.Equals("editwaitlist"))
            {
                if (news.News_Status != 1)
                {
                    message = "Bài viết đã có người khác cập nhật";
                    return(true);
                }
                else
                {
                    // kiểm tra xem có ai nhận biên tập không?
                    string otherUser = NewsEditHelper.getReceiver(newsId);
                    if (!string.IsNullOrEmpty(otherUser) && otherUser != Page.User.Identity.Name)
                    {
                        message = otherUser + " đã nhận biên tập bài này trong khi bạn đang xem bài viết";
                        return(true);
                    }
                }
            }
            else if (cpMode.Equals("approvalwaitlist"))
            {
                if (news.News_Status != 2)
                {
                    message = "Bài viết đã có người khác cập nhật";
                    return(true);
                }
                else
                {
                    // kiểm tra xem có ai nhận duyệt không?
                    string otherUser = NewsEditHelper.getReceiver(newsId);
                    if (!string.IsNullOrEmpty(otherUser) && otherUser != Page.User.Identity.Name)
                    {
                        message = otherUser + " đã nhận duyệt bài này trong khi bạn đang xem bài viết";
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #4
0
 private void SetData(List <NewsItem> newsItems)
 {
     foreach (NewsItem newsItem in newsItems)
     {
         GameObject newsRowObject = Instantiate(newsRowPrefab);
         newsRowObject.transform.SetParent(newsGrid.transform, false);
         NewsRow newsRow = newsRowObject.GetComponent <NewsRow>();
         if (newsRow != null)
         {
             newsRow.ScrollContainer     = this.ScrollContainer;
             newsRow.ScrollSnapContainer = this.ScrollSnapContainer;
             newsRow.SetData(newsItem);
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                long news_ID = 0;
                if (!string.IsNullOrEmpty(Request.QueryString["nid"]))
                {
                    news_ID = Convert.ToInt64(Request.QueryString["nid"]);
                }
                if (news_ID > 0)
                {
                    NewsRow objNewsRow    = NewsEditHelper.GetNewsInfo_News(news_ID, false);
                    NewsRow objNewsRow_Ex = NewsEditHelper.GetNewsInfo_NewsExtension(news_ID, false);

                    string title   = LCSFinder.GetEditor(objNewsRow.News_Title, objNewsRow_Ex.News_Title)[0];
                    string Sapo    = LCSFinder.GetEditor(objNewsRow.News_InitialContent, objNewsRow_Ex.News_InitialContent)[0];
                    string Content = LCSFinder.GetEditor(objNewsRow.News_Content, objNewsRow_Ex.News_Content)[0];
                    ltrTitle.Text   = title;
                    ltrInit.Text    = Sapo;
                    ltrContent.Text = Content;
                }
            }
        }
        /// <summary>
        /// Check whether current user can edit the news
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static bool isHasPermission(HttpContext context)
        {
            if (context.Request.QueryString["NewsRef"] == null || context.Request.QueryString["NewsRef"] == string.Empty)
            {
                return(true);
            }
            else
            {
                string cpMode = context.Request.QueryString["cpmode"];
                if (!string.IsNullOrEmpty(cpMode))
                {
                    if (cpMode.Contains(","))
                    {
                        cpMode = cpMode.Substring(cpMode.IndexOf(",") + 1);
                    }
                    cpMode = cpMode.ToLower();

                    long   newsId   = long.Parse(context.Request.QueryString["NewsRef"]);
                    string userName = context.User.Identity.Name;
                    if (!string.IsNullOrEmpty(userName) && newsId != 0)
                    {
                        MainSecurity objsecu = new MainSecurity();
                        //Role objrole = objsecu.GetRole(context.User.Identity.Name);

                        NewsRow newsRow = NewsEditHelper.GetNewsInfo_News(newsId, false);
                        if (newsRow != null)
                        {
                            Permission permission = objsecu.GetPermission(userName);
                            MainDB     db         = new MainDB();
                            bool       toReturn   = false;
                            switch (cpMode)
                            {
                            case "templist":
                                toReturn = newsRow.News_Status == (byte)NewsStatus.LuuTam &&
                                           db.StoredProcedures.News_isLastAccessUser(newsId, userName);
                                break;

                            case "editwaitlist":
                                toReturn = newsRow.News_Status == (byte)NewsStatus.ChoBienTap &&
                                           permission.isBien_Tap_Bai &&
                                           db.StoredProcedures.News_isHasPermissionEdit(newsId, CategoryHelper.GetCatIDByUser());
                                break;

                            case "editinglist":
                                toReturn = newsRow.News_Status == (byte)NewsStatus.NhanBienTap &&
                                           permission.isBien_Tap_Bai &&
                                           db.StoredProcedures.News_isLastAccessUser(newsId, userName);
                                break;

                            case "approvalwaitlist":
                                toReturn = newsRow.News_Status == (byte)NewsStatus.ChoDuyet && permission.isDuyet_Bai &&
                                           db.StoredProcedures.News_isHasPermissionEdit(newsId, CategoryHelper.GetCatIDByUser());
                                break;

                            case "approvalwaitspeciallist":
                                toReturn = newsRow.News_Status == (byte)NewsStatus.ChoDuyet && permission.isDuyet_Bai &&
                                           db.StoredProcedures.News_isHasPermissionEdit(newsId, CategoryHelper.GetCatIDByUser());
                                break;

                            case "approvinglist":
                                toReturn = newsRow.News_Status == (byte)NewsStatus.NhanDuyet && permission.isDuyet_Bai &&
                                           db.StoredProcedures.News_isLastAccessUser(newsId, userName);
                                break;

                            case "publishedlist":
                                toReturn = newsRow.News_Status == (byte)NewsStatus.XuatBan && permission.isXuat_Ban_Bai &&
                                           db.StoredProcedures.News_isHasPermissionEdit(newsId, CategoryHelper.GetCatIDByUser());
                                break;

                            case "removedlist":
                                toReturn = newsRow.News_Status == (byte)NewsStatus.GoBo && permission.isXuat_Ban_Bai &&
                                           db.StoredProcedures.News_isHasPermissionEdit(newsId, CategoryHelper.GetCatIDByUser());
                                break;

                            case "backlist":
                                toReturn = newsRow.News_Status == (byte)NewsStatus.TraLai &&
                                           db.StoredProcedures.News_isLastAccessUser(newsId, userName);
                                break;

                            case "dellist":
                                toReturn = newsRow.News_Status == (byte)NewsStatus.XoaTam &&
                                           db.StoredProcedures.News_isLastAccessUser(newsId, userName);
                                break;
                            }
                            return(toReturn);
                        }
                    }
                }
            }
            return(false);
        }
        private void BindNewsEdit(long _news_id)
        {
            NewsRow      objNewsRow = NewsEditHelper.GetNewsInfo_NewsExtension(_news_id, false);
            MainSecurity objSercu   = new MainSecurity();
            Permission   objPer     = objSercu.GetPermission(Page.User.Identity.Name);

            if (objPer.isXuat_Ban_Bai)
            {
                //Kiểm tra nếu có quyền xuất bản thì sẽ hiện dầy đủ thông tin
                btnPublish.Visible = true;
                // pnControl.Visible = true;
            }
            else
            {
                btnPublish.Visible = false;
            }
            if (objNewsRow != null)
            {
                if (!objPer.isXuat_Ban_Bai && Page.User.Identity.Name.Trim().ToLower() != objNewsRow.News_Author.Trim().ToLower())
                {
                    throw new SecurityException("Bạn không có quyền truy cập vào trang này");
                    return;
                }



                ltrXuatBan.Text      = "Bài viết do \"" + objNewsRow.News_Approver.ToUpper() + "\" xuất bản lúc " + objNewsRow.News_PublishDate.ToString("dd/MM/yyyy hh:mm");
                lstCat.SelectedValue = objNewsRow.Cat_ID.ToString();
                txtTitle.Text        = objNewsRow.News_Title != null ? objNewsRow.News_Title : "";
                txtSubTitle.Text     = objNewsRow.News_Subtitle != null ? objNewsRow.News_Subtitle : "";
                txtSource.Text       = objNewsRow.News_Source != null ? objNewsRow.News_Source : "";
                txtInit.Text         = objNewsRow.News_InitialContent != null?NewsEditHelper.ReplaceImageSrcToEmoticon(objNewsRow.News_InitialContent) : "";

                txtInit.Text = txtInit.Text.Replace("<br/>", System.Environment.NewLine);
                if (Request.QueryString["redirect"] == null)
                {
                    NewsContent.Text       = objNewsRow.News_Content != null ? objNewsRow.News_Content : "";
                    Session["NewsContent"] = NewsContent.Text;
                }
                else
                {
                    NewsContent.Text = Session["NewsContent"].ToString();
                }
                chkIsFocus.Checked     = objNewsRow.IsNews_isFocusNull != true ? objNewsRow.News_isFocus : false;
                cboIsHot.SelectedValue = objNewsRow.IsNews_ModeNull != true?objNewsRow.News_Mode.ToString() : "0";

                hdRelatNews.Value      = objNewsRow.News_Relation != null ? objNewsRow.News_Relation : "";
                chkShowComment.Checked = objNewsRow.IsisCommentNull != true ? objNewsRow.isComment : false; //Cho phép hiện ảnh hay ko?
                chkShowRate.Checked    = objNewsRow.IsisUserRateNull != true ? objNewsRow.isUserRate : false;
                txtSelectedFile.Text   = objNewsRow.News_Image != null ? objNewsRow.News_Image : "";
                txtImageTitle.Text     = objNewsRow.News_ImageNote != null ? objNewsRow.News_ImageNote : "";
                txtIcon.Text           = objNewsRow.Icon != null ? objNewsRow.Icon : "";
                txtMaCP.Text           = objNewsRow.Extension1 != null ? objNewsRow.Extension1 : "";
                txtExtension2.Text     = objNewsRow.Extension2 != null ? objNewsRow.Extension2 : "";
                txtSourceLink.Text     = objNewsRow.Extension3 != null ? objNewsRow.Extension3 : "";


                ddlAuthor.SelectedValue = objNewsRow.IsExtension4Null != true?objNewsRow.Extension4.ToString() : "0";

                if (objNewsRow.Template != 0)
                {
                    ddlProvinces.SelectedValue = objNewsRow.Template.ToString();
                }

                if (objNewsRow.News_OtherCat != null)
                {
                    string[] strOthers = objNewsRow.News_OtherCat.Split(",".ToCharArray());
                    for (int i = 0; i < lstOtherCat.Items.Count; i++)
                    {
                        foreach (string strItem in strOthers)
                        {
                            if (strItem == lstOtherCat.Items[i].Value)
                            {
                                lstOtherCat.Items[i].Selected = true;
                                break;
                            }
                        }
                    }
                }

                if (!objNewsRow.IsNews_PublishDateNull)
                {
                    SetValueForCombo(cboMonth, objNewsRow.News_PublishDate.Month.ToString());
                    SetValueForCombo(cboDay, objNewsRow.News_PublishDate.Day.ToString());
                    SetValueForCombo(cboYear, objNewsRow.News_PublishDate.Year.ToString());
                    SetValueForCombo(cboSercond, objNewsRow.News_PublishDate.Second.ToString());
                    SetValueForCombo(cboMinute, objNewsRow.News_PublishDate.Minute.ToString());
                    SetValueForCombo(cboHour, objNewsRow.News_PublishDate.Hour.ToString());
                }
                else
                {
                    SetValueForCombo(cboMonth, "0");
                    SetValueForCombo(cboDay, "0");
                    SetValueForCombo(cboYear, "2000");
                    SetValueForCombo(cboSercond, "-1");
                    SetValueForCombo(cboMinute, "-1");
                    SetValueForCombo(cboHour, "-1");
                }

                if (!IsPostBack)
                {
                    hdMedia.Value = DFISYS.BO.Editoral.NewsMedia.NewsMediaHelper.Get_ObjectId_By_NewsId(_news_id);
                    DataTable dtThread = ThreadHelper.SelectThreadByNewsID(_news_id);
                    if (dtThread != null && dtThread.Rows.Count > 0)
                    {
                        hidLuongSuKien.Value = dtThread.Rows[0]["Thread_ID"].ToString();
                    }
                }


                //Load data to Combobox Tin lien quan;
                string str;
                if (hdRelatNews.Value.TrimEnd(',') != "")
                {
                    str = NewsEditHelper.Get_Media_By_ListsId("News_ID", "News_Title", "News", hdRelatNews.Value);
                    BindToDropdown(cboNews, str);
                }


                string strThread;
                if (hidLuongSuKien.Value.TrimEnd(',') != "")
                {
                    strThread = NewsEditHelper.Get_Media_By_ListsId("Thread_ID", "Title", "NewsThread", hidLuongSuKien.Value);
                    BindToDropdown(lstThread, strThread);

                    string[] arrThread = hidLuongSuKien.Value.Split(',');
                    if (arrThread != null && arrThread.Length > 0)
                    {
                        for (int i = 0; i < cblTags.Items.Count; i++)
                        {
                            foreach (string strItem in arrThread)
                            {
                                if (strItem == cblTags.Items[i].Value)
                                {
                                    cblTags.Items[i].Selected = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (hdMedia.Value.TrimEnd(',').Length > 0)
                {
                    str = NewsEditHelper.Get_Media_By_ListsId("Object_ID", "Object_Url", "MediaObject", hdMedia.Value);
                    //BindToDropdown(cboMedia, str);
                }

                LoadAttachmentsType(_news_id);
            }
        }
Beispiel #8
0
        public static NewsRow GetNewsInfo_News(long _news_id, bool isUpdateAction)
        {
            NewsRow _newsrow = null;

            using (MainDB objDb = new MainDB()) {
                //_newsrow = objDb.NewsCollection.GetByPrimaryKey(_news_id);
                #region Get thong tin chi tiet cua bang News
                DataTable table = objDb.StoredProcedures.vc_Execute_Sql("SELECT * FROM News WHERE News_ID = " + _news_id);
                if (table.Rows.Count != 0)
                {
                    _newsrow              = new NewsRow();
                    _newsrow.Cat_ID       = table.Rows[0]["Cat_ID"] == System.DBNull.Value ? 0 : Convert.ToInt32(table.Rows[0]["Cat_ID"].ToString());
                    _newsrow.IsCat_IDNull = table.Rows[0]["Cat_ID"] == System.DBNull.Value ? true : false;

                    _newsrow.isComment       = table.Rows[0]["isComment"] == System.DBNull.Value ? false : Convert.ToBoolean(table.Rows[0]["isComment"]);
                    _newsrow.IsisCommentNull = table.Rows[0]["isComment"] == System.DBNull.Value ? true : false;

                    _newsrow.isUserRate       = table.Rows[0]["isUserRate"] == System.DBNull.Value ? true : Convert.ToBoolean(table.Rows[0]["isUserRate"]);
                    _newsrow.IsisUserRateNull = table.Rows[0]["isUserRate"] == System.DBNull.Value ? true : false;

                    _newsrow.News_Approver = table.Rows[0]["News_Approver"] == System.DBNull.Value ? "" : table.Rows[0]["News_Approver"].ToString();
                    _newsrow.News_Author   = table.Rows[0]["News_Author"] == System.DBNull.Value ? "" : table.Rows[0]["News_Author"].ToString();
                    _newsrow.News_Content  = table.Rows[0]["News_Content"] == System.DBNull.Value ? "" : table.Rows[0]["News_Content"].ToString();

                    _newsrow.News_CreateDate       = table.Rows[0]["News_CreateDate"] == System.DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(table.Rows[0]["News_CreateDate"]);
                    _newsrow.IsNews_CreateDateNull = table.Rows[0]["News_CreateDate"] == System.DBNull.Value ? true : false;

                    _newsrow.News_CurrEditor = table.Rows[0]["News_CurrEditor"] == System.DBNull.Value ? "" : table.Rows[0]["News_CurrEditor"].ToString();

                    _newsrow.News_ID             = table.Rows[0]["News_ID"] == System.DBNull.Value ? -1 : Convert.ToInt64(table.Rows[0]["News_ID"]);
                    _newsrow.News_Image          = table.Rows[0]["News_Image"] == System.DBNull.Value ? "" : table.Rows[0]["News_Image"].ToString();
                    _newsrow.News_ImageNote      = table.Rows[0]["News_ImageNote"] == System.DBNull.Value ? "" : table.Rows[0]["News_ImageNote"].ToString();
                    _newsrow.News_InitialContent = table.Rows[0]["News_InitialContent"] == System.DBNull.Value ? "" : table.Rows[0]["News_InitialContent"].ToString();

                    _newsrow.News_isFocus       = table.Rows[0]["News_isFocus"] == System.DBNull.Value ? true : (bool)table.Rows[0]["News_isFocus"];
                    _newsrow.IsNews_isFocusNull = table.Rows[0]["News_isFocus"] == System.DBNull.Value ? true : false;

                    _newsrow.News_Mode       = table.Rows[0]["News_Mode"] == System.DBNull.Value ? -1 : Convert.ToInt32(table.Rows[0]["News_Mode"]);
                    _newsrow.IsNews_ModeNull = table.Rows[0]["News_Mode"] == System.DBNull.Value ? true : false;

                    _newsrow.News_ModifiedDate       = table.Rows[0]["News_ModifiedDate"] == System.DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(table.Rows[0]["News_ModifiedDate"]);
                    _newsrow.IsNews_ModifiedDateNull = table.Rows[0]["News_ModifiedDate"] == System.DBNull.Value ? true : false;

                    _newsrow.News_OtherCat = table.Rows[0]["News_OtherCat"] == System.DBNull.Value ? "" : table.Rows[0]["News_OtherCat"].ToString();

                    _newsrow.News_PublishDate       = table.Rows[0]["News_PublishDate"] == System.DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(table.Rows[0]["News_PublishDate"]);
                    _newsrow.IsNews_PublishDateNull = table.Rows[0]["News_PublishDate"] == System.DBNull.Value ? true : false;

                    _newsrow.News_Rate       = table.Rows[0]["News_Rate"] == System.DBNull.Value ? -1 : Convert.ToDecimal(table.Rows[0]["News_Rate"]);
                    _newsrow.IsNews_RateNull = table.Rows[0]["News_Rate"] == System.DBNull.Value ? true : false;

                    _newsrow.News_Relation = table.Rows[0]["News_Relation"] == System.DBNull.Value ? "" : table.Rows[0]["News_Relation"].ToString();
                    _newsrow.News_Source   = table.Rows[0]["News_Source"] == System.DBNull.Value ? "" : table.Rows[0]["News_Source"].ToString();

                    _newsrow.News_Status       = table.Rows[0]["News_Status"] == System.DBNull.Value ? -1 : Convert.ToInt32(table.Rows[0]["News_Status"]);
                    _newsrow.IsNews_StatusNull = table.Rows[0]["News_Status"] == System.DBNull.Value ? true : false;

                    _newsrow.News_Subtitle = table.Rows[0]["News_Subtitle"] == System.DBNull.Value ? "" : table.Rows[0]["News_Subtitle"].ToString();

                    _newsrow.News_SwitchTime       = table.Rows[0]["News_SwitchTime"] == System.DBNull.Value ? DateTime.MinValue : Convert.ToDateTime(table.Rows[0]["News_SwitchTime"]);
                    _newsrow.IsNews_SwitchTimeNull = table.Rows[0]["News_SwitchTime"] == System.DBNull.Value ? true : false;

                    _newsrow.News_Title = table.Rows[0]["News_Title"] == System.DBNull.Value ? "" : table.Rows[0]["News_Title"].ToString();

                    _newsrow.News_ViewNum       = table.Rows[0]["News_ViewNum"] == System.DBNull.Value ? -1 : Convert.ToInt32(table.Rows[0]["News_ViewNum"]);
                    _newsrow.IsNews_ViewNumNull = table.Rows[0]["News_ViewNum"] == System.DBNull.Value ? true : false;

                    _newsrow.Icon = table.Rows[0]["Icon"] == System.DBNull.Value ? "" : table.Rows[0]["Icon"].ToString();

                    _newsrow.Extension1 = table.Rows[0]["Extension1"] == System.DBNull.Value ? "" : table.Rows[0]["Extension1"].ToString();
                    _newsrow.Extension2 = table.Rows[0]["Extension2"] == System.DBNull.Value ? "" : table.Rows[0]["Extension2"].ToString();
                    _newsrow.Extension3 = table.Rows[0]["Extension3"] == System.DBNull.Value ? "" : table.Rows[0]["Extension3"].ToString();
                    _newsrow.Extension4 = table.Rows[0]["Extension4"] == System.DBNull.Value ? -1 : Convert.ToInt32(table.Rows[0]["Extension4"]);
                }
            }
            #endregion


            #region Cập nhập vào bảng Action
            if (isUpdateAction == true)
            {
                string strcpmode = HttpContext.Current.Request.QueryString["cpmode"].ToString();
                if (strcpmode.ToLower().IndexOf("editwaitlist") >= 0 || strcpmode.ToLower().IndexOf("approvalwaitlis") >= 0)
                {
                    ActionRow objArow       = new ActionRow();
                    ActionRow objcurrAction = getLastestAction(_news_id);
                    objArow.CreateDate = DateTime.Now;
                    objArow.News_ID    = _newsrow.News_ID;
                    //sender chinh la nguoi cu - tot nhat k nen cho null - lay last action de tim sender
                    objArow.Sender_ID = objcurrAction.Sender_ID;
                    //dat lai receiver chinh la nguoi hien tai thuc hien thao tac voi tin
                    objArow.Reciver_ID = HttpContext.Current.User.Identity.Name;
                    //Co nghia news_status =0,1 hoac 2
                    if (_newsrow.News_Status == 0)
                    {
                        objArow.ActionType    = 0;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " Khôi phục từ tin bị xoá";
                    }
                    if (_newsrow.News_Status == 1)
                    {
                        objArow.ActionType    = 1;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " Nhận biên tập";
                    }
                    if (_newsrow.News_Status == 2)
                    {
                        objArow.ActionType    = 2;
                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " Nhận duyệt";
                    }

                    using (MainDB objDb = new MainDB()) {
                        // co the con trang thai tiep theo
                        objDb.ActionCollection.Insert(objArow);
                    }
                }
            }

            #endregion

            return(_newsrow);
        }
Beispiel #9
0
        public static bool CreateNews(long _news_id, int _cat_id, string _news_subtitle, string _news_title, string _news_image, string _news_source, string _news_init, string _news_content, string _poster, bool _news_isfocus, int _news_status, int _news_type, string _related_news, string _obj_media, string _other_cat, DateTime _switchtime, bool _isShowComment, bool _isShowRate, int _template, string _news_title_image, string _news_icon, string _thread_id)
        {
            bool toReturn = false;

            MainDB objDb = new MainDB();

            objDb.BeginTransaction();

            try {
                #region Gán giá trị cho bảng News
                NewsRow objrow = new NewsRow();
                //strResult = _news_id;
                objrow.News_ID             = _news_id;
                objrow.Cat_ID              = _cat_id;
                objrow.News_Subtitle       = _news_subtitle;
                objrow.News_Title          = _news_title;
                objrow.News_Image          = _news_image;
                objrow.News_Source         = _news_source;
                objrow.News_InitialContent = _news_init;
                objrow.News_Content        = _news_content;
                objrow.News_Author         = _poster;
                //objrow.News_Author = _news_author;
                objrow.News_isFocus = _news_isfocus;
                objrow.News_Status  = _news_status;
                objrow.News_Mode    = _news_type;
                //Danh sach nhung tin lien quan den tin nay
                objrow.News_Relation = _related_news;
                //objrow.News_FocusImage = _news_imgfocus;
                objrow.News_CreateDate   = DateTime.Now;
                objrow.News_ModifiedDate = DateTime.Now;
                objrow.isComment         = _isShowComment;
                objrow.isUserRate        = _isShowRate;
                objrow.Template          = _template;
                objrow.News_ImageNote    = _news_title_image;
                objrow.Icon      = _news_icon;
                objrow.WordCount = NewsHelper.WordCount(objrow.News_Content);
                if (_news_status == 3)
                {
                    if (_switchtime.Year != 2000)
                    {
                        objrow.News_PublishDate = _switchtime;
                    }
                    else
                    {
                        objrow.News_PublishDate = DateTime.Now;
                    }

                    objrow.News_Approver = HttpContext.Current.User.Identity.Name;
                }

                //lay other cat neu co
                if (_other_cat != null && _other_cat != "" && _other_cat != "0")
                {
                    objrow.News_OtherCat = _other_cat;
                }

                #endregion

                #region Gán và Insert giá trị cho bảng Action và NewsPublished
                //Thuc hien cap nhat thong tin vao Action
                ActionRow objArow = new ActionRow();
                objArow.News_ID    = objrow.News_ID;
                objArow.Sender_ID  = HttpContext.Current.User.Identity.Name;
                objArow.ActionType = _news_status;
                objArow.CreateDate = DateTime.Now;
                if (_news_status == 0)
                {
                    objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " Tạo bài viết";
                    objArow.Reciver_ID    = HttpContext.Current.User.Identity.Name;
                }
                if (_news_status == 1)
                {
                    objArow.Comment_Title  = HttpContext.Current.User.Identity.Name + " Tạo bài viết và gửi lên chờ biên tập";
                    objrow.News_SwitchTime = DateTime.Now;
                }
                if (_news_status == 2)
                {
                    objArow.Comment_Title  = HttpContext.Current.User.Identity.Name + " Tạo bài viết và gửi lên chờ duyệt";
                    objrow.News_SwitchTime = DateTime.Now;
                }

                NewsPublishedRow objpublishRow = new NewsPublishedRow();
                if (_news_status == 3)
                {
                    // Chỉ có những tin nào xuất bản thì mới Insert vào bảng News Published
                    objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " Tạo bài viết và xuất bản";


                    //thuc hien xuat ban bai viet

                    objpublishRow.News_ID          = _news_id;
                    objpublishRow.Cat_ID           = _cat_id;
                    objpublishRow.News_Subtitle    = _news_subtitle;
                    objpublishRow.News_Title       = _news_title;
                    objpublishRow.News_Image       = _news_image;
                    objpublishRow.News_Source      = _news_source;
                    objpublishRow.News_InitContent = objrow.News_InitialContent;
                    objpublishRow.News_Content     = _news_content;
                    objpublishRow.News_Athor       = _poster;
                    objpublishRow.News_Approver    = HttpContext.Current.User.Identity.Name;
                    objpublishRow.News_Status      = 3;
                    if (_switchtime.Year != 2000)
                    {
                        objpublishRow.News_PublishDate = _switchtime;
                    }
                    else
                    {
                        objpublishRow.News_PublishDate = DateTime.Now;
                    }
                    objpublishRow.News_isFocus   = _news_isfocus;
                    objpublishRow.News_Mode      = _news_type;
                    objpublishRow.News_Relation  = _related_news;
                    objpublishRow.News_OtherCat  = _other_cat;
                    objpublishRow.Template       = _template;
                    objpublishRow.isComment      = _isShowComment;
                    objpublishRow.isUserRate     = _isShowRate;
                    objpublishRow.News_ImageNote = _news_title_image;
                    objpublishRow.Icon           = _news_icon;

                    objpublishRow.WordCount = objrow.WordCount;
                }

                // thu insert 2 lan
                if (!objDb.NewsCollection.Insert(objrow))
                {
                    objrow.News_ID        = long.Parse(NewsHelper.GenNewsID());
                    objpublishRow.News_ID = objrow.News_ID;
                    objArow.News_ID       = objrow.News_ID;
                    if (!objDb.NewsCollection.Insert(objrow))
                    {
                        throw new Exception("Insert khong thanh cong");
                    }
                }

                objDb.ActionCollection.Insert(objArow);
                if (objrow.News_Status == 3)
                {
                    objDb.NewsPublishedCollection.Insert(objpublishRow);
                }

                #endregion

                #region Gan Thread vao bai
                // Gan Thread vao bai

                if (_thread_id != null && _thread_id != "")
                {
                    Threaddetails objThread   = new Threaddetails();
                    string[]      strArThread = _thread_id.Split(',');
                    foreach (string str in strArThread)
                    {
                        objThread.AddnewsThread(objrow.News_ID.ToString(), Convert.ToInt32(str), objDb);
                    }
                }
                #endregion

                #region Insert vào bảng MediaObject
                //truong hop co media object
                if (_obj_media != null && _obj_media != "")
                {
                    News_MediaRow objMrow  = null;
                    string[]      mediaIds = _obj_media.Split(",".ToCharArray());
                    foreach (string strMediaId in mediaIds)
                    {
                        objMrow           = new News_MediaRow();
                        objMrow.News_ID   = objrow.News_ID;
                        objMrow.Object_ID = Convert.ToInt32(strMediaId);
                        objDb.News_MediaCollection.Insert(objMrow);
                    }
                }
                #endregion

                objDb.CommitTransaction();

                toReturn = true;
            }
            catch (Exception ex) {
                objDb.RollbackTransaction();
                toReturn = false;
                // log to system
                try {
                    string mes = "";
                    mes += "NewsId = " + _news_id + Environment.NewLine;
                    mes += "User_Id = " + HttpContext.Current.User.Identity.Name + Environment.NewLine;
                    mes += "_related_news = " + _related_news + Environment.NewLine;
                    mes += "_other_cat = " + _other_cat + Environment.NewLine;
                    mes += "_thread_id = " + _thread_id + Environment.NewLine;
                    mes += ex.ToString();
                    System.Diagnostics.EventLog.WriteEntry("CreateNews_CMS_LOG", mes);
                }
                catch (Exception e) { }
            }
            finally {
                if (HttpContext.Current.Session["newsid"] != null)
                {
                    HttpContext.Current.Session.Remove("newsid");
                }
                objDb.Close();
            }

            return(toReturn);
        }