Ejemplo n.º 1
0
        public static bool UpdateNews(long _news_id, int _cat_id, string _news_subtitle, string _news_title, string _news_image, string _news_source, string _news_init, string _news_content, bool _news_isfocus, int _news_status, int _news_type, string _related_news, string _other_cat, DateTime _switchtime, bool _isSend, bool _isShowComment, bool _isShowRate, int _template, string _obj_media, string _news_title_image, string _news_icon, string _thread_id)
        {
            bool   toReturn        = false;
            int    old_news_status = -1;
            MainDB objDb           = new MainDB();

            objDb.BeginTransaction();
            NewsRow objrow;


            if (_news_init != null)
            {
                _news_init = _news_init.Replace(System.Environment.NewLine, "<br/>");
            }

            try {
                #region Gan Thread vao bai
                // Gan Thread vao bai

                Threaddetails objThread = new Threaddetails();
                objDb.SelectScalar("Delete ThreadDetail Where News_ID = '" + _news_id + "'");

                if (_thread_id != null)
                {
                    string[] strArThread = _thread_id.Split(',');
                    foreach (string str in strArThread)
                    {
                        objThread.AddnewsThread(_news_id.ToString(), int.Parse(str), objDb);
                    }
                }
                #endregion

                objrow          = objDb.NewsCollection.GetByPrimaryKey(_news_id);
                old_news_status = objrow.News_Status;

                if (objrow != null)
                {
                    #region Gan cac gia tri cho bang News
                    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.WordCount           = NewsHelper.WordCount(objrow.News_Content);
                    //objrow.User_ID = _poster;
                    //objrow.News_Author = _news_author;
                    objrow.News_isFocus = _news_isfocus;
                    //Trang thai cua tin tuy thuoc vao nguoi bien tap.
                    if (_news_status != -1)
                    {
                        objrow.News_Status = _news_status;
                    }
                    objrow.News_Mode = _news_type;
                    //tin lien quan
                    objrow.News_Relation = _related_news;
                    //if (_news_imgfocus != "" && _news_imgfocus!=null)
                    //objrow.News_FocusImage = _news_imgfocus;
                    if (_other_cat != "")
                    {
                        objrow.News_OtherCat = _other_cat;
                    }

                    DateTime dtPublish = _switchtime;
                    if (objrow.News_Status == 3)
                    {
                        if (dtPublish.Year != 9999)
                        {
                            // Neu khong phai la news da published ma khong chon ngay Xuat ban thi update lai ngay gio
                            if (dtPublish.Year != 2000)
                            {
                                objrow.News_PublishDate = dtPublish;
                            }
                            else
                            {
                                objrow.News_PublishDate = DateTime.Now;
                            }
                        }
                    }

                    objrow.Template       = _template;
                    objrow.News_ImageNote = _news_title_image;

                    objrow.isComment  = _isShowComment;
                    objrow.isUserRate = _isShowRate;
                    objrow.Icon       = _news_icon;


                    objrow.News_ModifiedDate = DateTime.Now;
                    #endregion

                    #region Gan cac gia tri cho bang Action
                    //thuc hien luu thong tin vao action.
                    ActionRow objArow = new ActionRow();
                    objArow.Sender_ID = HttpContext.Current.User.Identity.Name;
                    //Gui len. Neu la xoa tam thi khong luu action - Cho nay can phai xem la gui len hay luu lai?
                    string cpMode = HttpContext.Current.Request.QueryString["cpmode"].Replace("add,", string.Empty);
                    switch (objrow.News_Status)
                    {
                    case 1:
                        if (old_news_status != 1)
                        {
                            objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gửi bài chờ biên tập";
                        }
                        else
                        {
                            objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " nhận biên tập";
                            objArow.Reciver_ID    = HttpContext.Current.User.Identity.Name;
                            ActionRow tem = new ActionRow();
                            tem = getLastestAction(_news_id);
                            objArow.Sender_ID = tem.Sender_ID;
                        }
                        break;

                    case 2:
                        if (old_news_status != 2)
                        {
                            objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " gửi bài chờ duyệt";
                        }
                        else
                        {
                            objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " nhận duyệt";
                            objArow.Reciver_ID    = HttpContext.Current.User.Identity.Name;
                            ActionRow tem = new ActionRow();
                            tem = getLastestAction(_news_id);
                            objArow.Sender_ID = tem.Sender_ID;
                        }
                        break;

                    case 3: objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " xuất bản bài"; break;
                    }
                    objArow.ActionType = objrow.News_Status;
                    objArow.News_ID    = _news_id;

                    objArow.CreateDate = DateTime.Now;
                    // chỉ khi tin đổi trạng thái
                    // hoặc
                    // không phải tin ở trong danh sách nhận duyệt, nhận biên tập
                    // thì mới lưu action
                    // [bacth, 11:00 AM 5/31/2008]
                    if (old_news_status != objrow.News_Status || (cpMode.ToLower().Equals("approvalwaitlist") || cpMode.ToLower().Equals("editwaitlist")))
                    {
                        if (objrow.News_Status == 1 || objrow.News_Status == 2 || objrow.News_Status == 3)
                        {
                            objDb.ActionCollection.Insert(objArow);
                        }
                    }

                    #endregion

                    #region Gan cac gia tri cho bang NewsPublished
                    NewsPublishedRow objpublishRow;

                    // Get lai nhung gia tri cua cua News Published
                    objpublishRow = objDb.NewsPublishedCollection.GetByPrimaryKey(_news_id);

                    // Neu khong ton tai news_id trong NewsPUblished thi khoi tao lai
                    if (objpublishRow == null)
                    {
                        objpublishRow = new NewsPublishedRow();
                    }

                    // Gan cac gia tri cho News Published
                    if (_news_status == 3)
                    {
                        objrow.News_Approver = HttpContext.Current.User.Identity.Name;

                        objArow.Comment_Title = HttpContext.Current.User.Identity.Name + " xuất bản bài";
                        objArow.ActionType    = 3;

                        //thuc hien chuyen du lieu qua bang newspublished
                        objpublishRow.Icon          = _news_icon;
                        objpublishRow.News_ID       = _news_id;
                        objpublishRow.Cat_ID        = _cat_id;
                        objpublishRow.News_Subtitle = _news_subtitle;
                        objpublishRow.News_Title    = _news_title;
                        if (_news_image != "" && _news_image != null)
                        {
                            objpublishRow.News_Image = _news_image;
                        }
                        else
                        {
                            objpublishRow.News_Image = objrow.News_Image;
                        }
                        objpublishRow.News_Source      = _news_source;
                        objpublishRow.News_InitContent = objrow.News_InitialContent;
                        objpublishRow.News_Content     = _news_content;
                        objpublishRow.News_Athor       = objrow.News_Author;
                        objpublishRow.News_Approver    = HttpContext.Current.User.Identity.Name;
                        objpublishRow.News_Status      = 3;

                        if (dtPublish.Year != 9999)
                        {
                            // Neu khong phai la news da published ma khong chon ngay Xuat ban thi update lai ngay gio
                            if (dtPublish.Year != 2000)
                            {
                                objpublishRow.News_PublishDate = dtPublish;
                            }
                            else
                            {
                                objpublishRow.News_PublishDate = DateTime.Now;
                            }
                        }

                        objpublishRow.News_isFocus = _news_isfocus;
                        objpublishRow.News_Mode    = _news_type;
                        if (_related_news != "" && _related_news != null)
                        {
                            objpublishRow.News_Relation = objrow.News_Relation;
                        }
                        else
                        {
                            objpublishRow.News_Relation = _related_news;
                        }
                        if (_other_cat != "" && _other_cat != null)
                        {
                            objpublishRow.News_OtherCat = objrow.News_OtherCat;
                        }
                        else
                        {
                            objpublishRow.News_OtherCat = _other_cat;
                        }

                        objpublishRow.Template       = _template;
                        objpublishRow.isComment      = _isShowComment;
                        objpublishRow.isUserRate     = _isShowRate;
                        objpublishRow.News_ImageNote = _news_title_image;
                    }

                    #endregion

                    if (!objDb.NewsCollection.Update(objrow))
                    {
                        throw new Exception("Không cập nhật được bản tin");
                    }

                    #region Cap nhap vao bang News, Action va  NewsPublished
                    NewsPublishedRow objCurrRow;
                    //neu la send thi moi cap nhat Action



                    if (objrow.News_Status == 3)
                    {
                        //thuc hien xoa neu ton tai tin do va chen moi vao bang xuat ban
                        objCurrRow = objDb.NewsPublishedCollection.GetByPrimaryKey(_news_id);
                        if (objCurrRow != null)
                        {
                            objDb.NewsPublishedCollection.DeleteByPrimaryKey(_news_id);
                        }
                        objDb.NewsPublishedCollection.Insert(objpublishRow);
                    }
                    #endregion

                    #region Cap nhap vao bang MediaObject
                    // Xoa tat ca News_Media cu theo NewsID
                    string strObjectId = NewsMediaHelper.Get_ObjectId_By_NewsId(_news_id);
                    if (strObjectId != null && strObjectId != "")
                    {
                        string[] mediaIds = strObjectId.Split(",".ToCharArray());
                        foreach (string strMediaId in mediaIds)
                        {
                            NewsMediaHelper.Delete_News_Media_ByNewsIdAndObjectId(_news_id, strMediaId, objDb);
                        }
                    }

                    //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   = _news_id;
                            objMrow.Object_ID = int.Parse(strMediaId);
                            objDb.News_MediaCollection.Insert(objMrow);
                        }
                    }

                    #endregion

                    objDb.CommitTransaction();
                    toReturn = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally {
                if (HttpContext.Current.Session["newsid"] != null)
                {
                    HttpContext.Current.Session.Remove("newsid");
                }
                objDb.Close();
            }



            return(toReturn);;
        }
Ejemplo n.º 2
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);
        }