Exemple #1
0
        public new void NewsUpdate(News entity)
        {
            // Check permission: Admin
              PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permAdmin.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // Check required fields:
            if (entity.Title.Length == 0) throw new ArgumentNullException("News.Title", "A hír címe nincs megadva.");
            if (entity.Abstract.Length == 0)
              throw new ArgumentNullException("News.Abstract", "A hír abstract nincs megadva.");
            if (entity.NewsBody.Length == 0)
              throw new ArgumentNullException("News.NewsBody", "A hír szövege nincs megadva.");

            if (entity.PictureUrl.Length > 0 && entity.PictureUrl != DBString.Null)
            {
              string ext = Path.GetExtension(entity.PictureUrl).ToLower();
              if (!(ext.Equals(".gif") || ext.Equals(".jpg") || ext.Equals(".jpeg")))
            throw new ApplicationException("Csak jpeg vagy gif formátumú kép csatolható.");
              if (entity.PictureData == null || entity.PictureData.Length == 0)
            throw new ApplicationException("A fájlnévhez nem tartozik adat.");

              if (entity.PictureData != null && entity.PictureData.Length > 0)
              {
            if (entity.PictureUrl.Length == 0)
              throw new ApplicationException("A kép adathoz nem tartozik fájlnév.");
              }
            }
            // Logical checks
            News selected = NewsSelect(entity.ID);
            if (selected == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik hír.");

            //string oldFileName = selected.PictureUrl;

            // Save data
            selected.Title = entity.Title;
            selected.Abstract = entity.Abstract;
            selected.NewsBody = entity.NewsBody;
            selected.VisibleForVisitor = entity.VisibleForVisitor;
            selected.VisibleForRegistered = entity.VisibleForRegistered;
            selected.IsActive = entity.IsActive;
            selected.PictureUrl = entity.PictureUrl;
            selected.IsActual = entity.IsActual;
            selected.CategoryRef = entity.CategoryRef;

            NewsPictureService newsPictureSrv = new NewsPictureService(m_DataContext);
            FileDataContext fileDataContext = new FileDataContext();
            m_DataContext.BeginNestedTran();
            try
            {
              // Clear old files:
              NewsPictureContainer oldPics = base.SelectChildrenByPictureOfNews(entity.ID);
              foreach (NewsPicture oldPic in oldPics.All)
              {
            newsPictureSrv.NewsPictureDelete(oldPic);
              }

              // NewsPicture - insert:
              foreach (NewsPicture pic in entity.NewsPictures.Current)
              {
            if (/*pic.PicturePath.Length > 0 &&*/  entity.PictureUrl != DBString.Null && entity.PictureData != null && pic.PictureData.Length > 0)
              newsPictureSrv.NewsPictureInsert(pic);
              }

              selected.NewsAttachments = entity.NewsAttachments;

              NewsAttachmentService attSrv = new NewsAttachmentService(m_DataContext);

              // Clear old files:
              NewsAttachmentContainer oldFiles = base.SelectChildrenByAttachmentOfNews(entity.ID);
              foreach (NewsAttachment oldFile in oldFiles.All)
              {
            attSrv.NewsAttachmentDelete(oldFile);
              }
              NewsAttachment newFile;
              // EDocumentAttachments - insert:
              foreach (NewsAttachment file in selected.NewsAttachments.Current)
              {
            if (file.FileData.Length == 0)
            {
              newFile = attSrv.NewsAttachmentSelectFile(file.ID);
            }
            else
            {
              newFile = file;
            }
            newFile.NewsRef = selected.ID;
            newFile.Name = file.Name;
            newFile.Description = file.Description;
            newFile.CreatedDate = DateTime.Now;

            if (attSrv.NewsAttachmentSelect(newFile.ID) != null)
            {
              attSrv.NewsAttachmentUpdate(newFile);
            }
            else
            {
              attSrv.NewsAttachmentInsert(newFile);
            }
              }
              // News
              base.NewsUpdate(selected);

              // News base picture update
              fileDataContext.NewsDelete(selected.ID);
              if (entity.PictureData != null && entity.PictureData.Length > 0)
              {
            fileDataContext.NewsInsert(entity.ID, entity.PictureData);
              }

              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

            BusinessAuditEvent.Success(
              new EventParameter("NewsID", entity.ID.ToString()),
              new EventParameter("NewsTitle", entity.Title)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("NewsID", entity.ID.ToString()),
              new EventParameter("NewsTitle", entity.Title)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Exemple #2
0
        public new void NewsInsert(News entity)
        {
            // check permission: admin
              PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permAdmin.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // check required fields:
            if (entity.Title.Length == 0) throw new ArgumentNullException("News.Title", "A hír címe nincs megadva.");
            if (entity.Abstract.Length == 0)
              throw new ArgumentNullException("News.Abstract", "A hír abstract nincs megadva.");
            if (entity.NewsBody.Length == 0)
              throw new ArgumentNullException("News.NewsBody", "A hír szövege nincs megadva.");

            // logical checks:
            if (entity.PictureUrl.Length > 0 && entity.PictureUrl != DBString.Null)
            {
              string ext = Path.GetExtension(entity.PictureUrl).ToLower();
              if (!(ext.Equals(".gif") || ext.Equals(".jpg") || ext.Equals("jpeg")))
            throw new ApplicationException("Csak jpeg vagy gif formátumú kép csatolható.");
              if (entity.PictureData == null || entity.PictureData.Length == 0)
            throw new ApplicationException("A fájlnévhez nem tartozik adat.");
            }
            if (entity.PictureData != null && entity.PictureData.Length > 0)
            {
              if (entity.PictureUrl.Length == 0)
            throw new ApplicationException("A kép adathoz nem tartozik fájlnév.");
            }

            // save data
            entity.CreatedDate = DBDateTime.Now;

            NewsPictureService newsPictureSrv = new NewsPictureService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              // News
              base.NewsInsert(entity);

              if (entity.PictureData != null && entity.PictureData.Length > 0)
              {

            FileDataContext fileDataContext = new FileDataContext();
            fileDataContext.NewsInsert(entity.ID, entity.PictureData);
              }

              // NewsPictures
              foreach (NewsPicture pic in entity.NewsPictures.Current)
              {
            if (/*pic.PicturePath.Length > 0 &&*/  entity.PictureUrl != DBString.Null && entity.PictureData != null && pic.PictureData.Length > 0)
            newsPictureSrv.NewsPictureInsert(pic);
              }
              NewsAttachmentService attSrv = new NewsAttachmentService(m_DataContext);

              // EDocumentAttachments - insert:
              foreach (NewsAttachment file in entity.NewsAttachments.Current)
              {
            file.NewsRef = entity.ID;
            file.IsActive = true;
            file.CreatedDate = DateTime.Now;
            attSrv.NewsAttachmentInsert(file);
              }
              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

            BusinessAuditEvent.Success(
              new EventParameter("NewsID", entity.ID.ToString()),
              new EventParameter("NewsTitle", entity.Title)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("NewsID", entity.ID.ToString()),
              new EventParameter("NewsTitle", entity.Title)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Exemple #3
0
 public DataSet NewsSelectFiltered(News filter)
 {
     TraceCallEnterEvent.Raise();
       try
       {
     DataSet result = m_DataContext.ndihdNewsSelectFiltered(
       filter.CategoryRef,
       filter.FilterOnVisibleForVisitor,
       filter.FilterOnVisibleForRegistered,
       filter.FilterOnIsactive,
       filter.FilterOnIsActual);
     TraceCallReturnEvent.Raise();
     return result;
       }
       catch (Exception ex)
       {
     ExceptionManager.Publish(ex);
     TraceCallReturnEvent.Raise(false);
     throw;
       }
 }
 public virtual News NewsSelect(DBGuid IDVal)
 {
     TraceCallEnterEvent.Raise();
       try
       {
     News result = null;
     DataSet entitySet = m_DataContext.ndihdNewsSelect(IDVal);
     if (entitySet.Tables[0].Rows.Count != 0)
     {
       result = new News(entitySet);
     }
     TraceCallReturnEvent.Raise();
     return result;
       }
       catch (Exception ex)
       {
     ExceptionManager.Publish(ex);
     TraceCallReturnEvent.Raise(false);
     throw;
       }
 }
 public virtual void NewsUpdate(News entity)
 {
     TraceCallEnterEvent.Raise();
       try
       {
     m_DataContext.BeginNestedTran();
     try
     {
       int count;
       m_DataContext.ndihdNewsUpdate(entity.ID,
                                 entity.Title,
                                 entity.Abstract,
                                 entity.PictureUrl,
                                 entity.NewsBody,
                                 entity.CategoryRef,
                                 entity.VisibleForVisitor,
                                 entity.VisibleForRegistered,
                                 entity.CreatedDate,
                                 entity.IsActive,
                                 entity.IsActual, out count);
       if (count == 0) throw new ServiceUpdateException();
       m_DataContext.CommitNested();
     }
     catch
     {
       m_DataContext.RollbackNested();
       throw;
     }
     TraceCallReturnEvent.Raise();
     return;
       }
       catch (Exception ex)
       {
     ExceptionManager.Publish(ex);
     TraceCallReturnEvent.Raise(false);
     throw;
       }
 }
Exemple #6
0
 // -------------------------------------------------------------------------------------
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="IDVal">Value of 'uID' field</param>
 /// <param name="origInstance">Original document data to copy.</param>
 // -------------------------------------------------------------------------------------
 public News(DBGuid IDVal,
         News origInstance)
     : base(IDVal, origInstance)
 {
 }
 public virtual void NewsDelete(News entity)
 {
     TraceCallEnterEvent.Raise();
       try
       {
     m_DataContext.BeginNestedTran();
     try
     {
       m_DataContext.ndihdNewsDelete(entity.ID);
       m_DataContext.CommitNested();
     }
     catch
     {
       m_DataContext.RollbackNested();
       throw;
     }
     TraceCallReturnEvent.Raise();
     return;
       }
       catch (Exception ex)
       {
     ExceptionManager.Publish(ex);
     TraceCallReturnEvent.Raise(false);
     throw;
       }
 }
        /// <summary>
        /// Fill datagrid with data
        /// </summary>
        private void FillDatagrid(DBGuid ID)
        {
            try
              {
            string sSortColumn = "cTitle";
            int nSelectedRow = -1;

            // Storing the previous sort order
            if (dtgMain.DataSource != null)
            {
              sSortColumn = ((DataTable) dtgMain.DataSource).DefaultView.Sort;
            }

            // Set filter
            News filter = new News(Guid.Empty);
            filter.FilterOnVisibleForRegistered = DBInt.Null;
            if (cmbVisibleForRegistered.SelectedIndex > 0)
            {
              bool bIsVisible = (cmbVisibleForRegistered.SelectedValue.ToString() == "1" ? true : false);
              filter.FilterOnVisibleForRegistered = (DBInt) Convert.ToInt32(bIsVisible);
              filter.VisibleForRegistered = bIsVisible;
            }

            filter.FilterOnVisibleForVisitor = DBInt.Null;
            if (cmbVisibleForVisitor.SelectedIndex > 0)
            {
              bool bIsVisible = (cmbVisibleForVisitor.SelectedValue.ToString() == "1" ? true : false);
              filter.FilterOnVisibleForVisitor = (DBInt) Convert.ToInt32(bIsVisible);
              filter.VisibleForVisitor = bIsVisible;
            }

            filter.FilterOnIsactive = DBInt.Null;
            if (cmbStatus.SelectedIndex > 0)
            {
              bool bIsActive = (cmbStatus.SelectedValue.ToString() == "1" ? true : false);
              filter.FilterOnIsactive = (DBInt) Convert.ToInt32(bIsActive);
              filter.IsActive = bIsActive;
            }

            filter.FilterOnIsActual = DBInt.Null;
            if (cmbActual.SelectedIndex > 0)
            {
              bool bIsActual = (cmbActual.SelectedValue.ToString() == "1" ? true : false);
              filter.FilterOnIsActual = (DBInt) Convert.ToInt32(bIsActual);
              filter.IsActual = bIsActual;
            }
            if (cmbCategoryRef != null && cmbCategoryRef.SelectedIndex > 0)
            {
              filter.CategoryRef = new Guid(cmbCategoryRef.SelectedValue.ToString());
            }

            // Retrieving data from BusinessServices
            INewsService srv = ServiceFactory.GetNewsService();
            DataSet allData = srv.NewsSelectFiltered(filter);
            DataTable dt = allData.Tables[0];
            dt.DefaultView.Sort = sSortColumn;
            dtgMain.DataSource = dt;

            // Locates the row specified by ID param
            if (!ID.IsNull)
            {
              BindingManagerBase bm = dtgMain.BindingContext[dtgMain.DataSource, dtgMain.DataMember];
              DataRow dr;
              for (int i = 0; i < bm.Count; i++)
              {
            dr = ((DataRowView) bm.Current).Row;
            if (ID.Value.Equals(dr["uId"]))
            {
              nSelectedRow = i;
              break;
            }
            bm.Position += 1;
              }
            }

            // Makes the row selected
            if (nSelectedRow <= ((DataTable) dtgMain.DataSource).DefaultView.Count && nSelectedRow > -1)
            {
              dtgMain.Select(nSelectedRow);
              dtgMain.CurrentRowIndex = nSelectedRow;
            }
            else if (((DataTable) dtgMain.DataSource).DefaultView.Count != 0)
            {
              dtgMain.Select(0);
            }

            // Enabling or disabling the buttons according to record count.
            // And is because of previous disable state.
            bool bIsEmptyGrid = (((DataTable) dtgMain.DataSource).DefaultView.Count == 0);
            tbbModify.Enabled = ! bIsEmptyGrid;
            tbbInactivate.Enabled = ! bIsEmptyGrid;
              }
              catch (Exception ex)
              {
            //	---	Log exception
            ExceptionManager.Publish(ex);
            //	---	Display Exception
            ErrorHandler.DisplayError("Nem várt hiba lépett fel a lista frissítése során.", ex);
              }
        }
Exemple #9
0
 // -------------------------------------------------------------------------------------
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="origInstance">Original document data to copy.</param>
 // -------------------------------------------------------------------------------------
 public News(News origInstance)
     : base(origInstance)
 {
 }
Exemple #10
0
        // -------------------------------------------------------------------------------------
        /// <summary>
        /// fill edit window controls
        /// </summary>
        // -------------------------------------------------------------------------------------
        private void RetrieveData()
        {
            try
              {
            // Get data
            INewsService newsSrv = ServiceFactory.GetNewsService();
            INewsPictureService newsPicSrv = ServiceFactory.GetNewsPictureService();
            INewsAttachmentService attSrv = ServiceFactory.GetNewsAttachmentService();
            m_CurrentNews = newsSrv.NewsSelectPicture(CurrentID);
            m_CurrentNews.NewsPictures = newsSrv.SelectChildrenByPictureOfNews(CurrentID);
            m_CurrentNews.NewsAttachments = newsSrv.SelectChildrenByAttachmentOfNews(CurrentID);
            foreach (NewsPicture pic in m_CurrentNews.NewsPictures.All)
            {
              NewsPicture picData = newsPicSrv.NewsPictureSelectPicture(pic.ID);
              pic.PictureData = picData.PictureData;
            }

            // Fill the controls
            txtTitle.Text = m_CurrentNews.Title;
            txtPictureUrl.Text = m_CurrentNews.PictureUrl;
            txtAbstract.Text = m_CurrentNews.Abstract;
            txtNewsBody.Text = m_CurrentNews.NewsBody;
            cbxVisibleForVisitor.Checked = m_CurrentNews.VisibleForVisitor;
            cbxVisibleForRegistered.Checked = m_CurrentNews.VisibleForRegistered;
            cbxActivate.Checked = m_CurrentNews.IsActive;
            cbxActual.Checked = m_CurrentNews.IsActual;
            if (cmbCategory != null && m_CurrentNews.CategoryRef != DBGuid.Null)
            {
              cmbCategory.SelectedValue = m_CurrentNews.CategoryRef.Value.ToString();
            }
            // Show picture
            if (m_CurrentNews.PictureData != null && m_CurrentNews.PictureData.Length > 0)
            {
              MemoryStream imageStream = new MemoryStream(m_CurrentNews.PictureData);
              pbxPictureBase.Image = Image.FromStream(imageStream);
            }

            NewsAttachmentContainer avaiableFiles = new NewsAttachmentContainer();
            foreach (NewsAttachment file in m_CurrentNews.NewsAttachments.All)
            {
              NewsAttachment oldFile = attSrv.NewsAttachmentSelectFile(file.ID);
              if (oldFile.FileData != null && oldFile.FileData.Length > 0)
              {
            file.FileData = oldFile.FileData;
            file.FileSize = oldFile.FileSize;
            if (!avaiableFiles.All.Items.Contains(file))
            {
              avaiableFiles.Add(file);
            }
              }
            }
            m_CurrentNews.NewsAttachments = avaiableFiles;
            // 2nd page
            FillDatagrid(DBGuid.Null);
            //3. lap
            FillFileDatagrid(DBGuid.Null);
              }
              catch (Exception ex)
              {
            //	---	Log exception
            ExceptionManager.Publish(ex);
            //	---	Display Exception
            ErrorHandler.DisplayError("Hiba lépett fel az adatok lekérdezése során", ex);
            //	---	invisible btnOk button
            btnOk.Visible = false;
              }
        }
Exemple #11
0
        /// <summary>
        /// Edit constructor
        /// </summary>
        public frmNewsEdit(DBGuid ID)
        {
            // Required for Windows Form Designer support
              InitializeComponent();

              CurrentID = ID;
              m_bNewEntity = false;
              pHeader.Text2 = "Hírek adatainak módosítása";
              INewsService expSrv = ServiceFactory.GetNewsService();
              m_CurrentNews = expSrv.NewsSelect(CurrentID);
              m_CurrentNews.NewsAttachments = expSrv.SelectChildrenByAttachmentOfNews(m_CurrentNews.ID);
        }
Exemple #12
0
        /// <summary>
        /// Default constructor (new)
        /// </summary>
        public frmNewsEdit()
        {
            // Required for Windows Form Designer support
              InitializeComponent();

              CurrentID = new DBGuid(Guid.NewGuid());
              m_CurrentNews = new News(CurrentID);
              m_CurrentNews.IsActive = true;
              m_bNewEntity = true;
              pHeader.Text2 = "Új hír létrehozása";
        }
Exemple #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Ndi.HelpDesk.BusinessDocuments.News newsSelected = new Ndi.HelpDesk.BusinessDocuments.News(new DBGuid());
              INewsService newsSrv = ServiceFactory.GetNewsService();
              INewsCategoryService newsCatSrv = ServiceFactory.GetNewsCategoryService();
              Guid newsGuid = new Guid();
              try
              {
            string newsId = Request.QueryString["newsid"];
            if (newsId == null)
              throw new ApplicationException("Hiányzó kötelezõ paraméter: hír azonosító.");

            newsGuid = new Guid(newsId);

             newsSelected = newsSrv.NewsSelect(newsGuid);
              }
              catch (Exception ex)
              {
            errorPanel.Exception = ex;
              }
            // check permission: Visitors cannot read news for registered users
            if (!newsSelected.VisibleForVisitor && !Context.User.Identity.IsAuthenticated)
            {
              throw new SecurityException("Nincs joga a hír megtekintéséhez.");
            }
            try
            {
            //if (!newsSelected.VisibleForVisitor)
            //{
            //  PrincipalPermission perm = new PrincipalPermission(Context.User.Identity.Name, "Registered");
            //  perm.Demand();
            //}
            NewsCategory newsCat = newsCatSrv.NewsCategorySelect(newsSelected.CategoryRef);
            if(newsCat != null)
            {
              lblCategory.Text = newsCat.Name;
            }
            lblTitle.Text = newsSelected.Title;
            lblAbstract.Text = newsSelected.Abstract.Replace("\r\n", "<br/>");
            lblNewsBody.Text = newsSelected.NewsBody.Replace("\r\n", "<br/>");
            //lblDate.Text = newsSelected.CreatedDate.ToShortDateString();

            // kép megjelenítése:
            if (newsSelected.PictureUrl.IsNull)
            {
              imgNewsPicture.Visible = false;
              rowImg.Visible = false;
            }
            else
            {
              imgNewsPicture.Visible = true;
              rowImg.Visible = true;
              imgNewsPicture.ImageUrl = "Controls/ShowPicture.aspx?mode=news&newsId=" + newsSelected.ID.Value;
            }

            // hír további képei:
            NewsPictureContainer pics = newsSrv.SelectChildrenByPictureOfNews(newsGuid);
            if (pics.AllCount > 0)
            {
              linkMorePictures.Visible = true;
              pnlMorePics.Visible = true;
              linkMorePictures.NavigateUrl = "NewsMorePictures.aspx?newsId=" + newsGuid;
            }
            else
            {
              pnlMorePics.Visible = false;
              linkMorePictures.Visible = false;
            }
            ShowAttachmentGrid(gridAttachment, 0, null, null, newsGuid);
              }
              catch (Exception ex)
              {
            errorPanel.Exception = ex;
              }
        }
        public void SaveNews(News entity)
        {
            TraceCallEnterEvent.Raise();
              try
              {
            //megnézzük hogy van e már hozzá megadott keresõ szöveg .. mert akkor azt update -eljük
            GlobalSearch search = base.GlobalSearchSelect(entity.ID, "NEWS");

            if (search != null)
            {
              search.SearchText = entity.Title.ToString() + " " + entity.Abstract.ToString() + " " +
                              entity.NewsBody.ToString();
              //ha van ilyen UPDATE
              base.GlobalSearchUpdate(search);
            }
            else //ha még nincs ilyen INSERT
            {
              search = new GlobalSearch(entity.ID, "NEWS");
              search.SearchText = entity.Title.ToString() + " " + entity.Abstract.ToString() + " " +
                              entity.NewsBody.ToString();
              base.GlobalSearchInsert(search);
            }
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("IDRef", entity.ID.ToString()),
              new EventParameter("SearchCategory", "NEWS")
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }