public virtual void Updatestock_New(stock_New stock_New)
 {
     try
     {
         //Database database = DatabaseFactory.CreateDatabase();
         Database database = DatabaseFactory.CreateDatabase("DestinationConnection");
         DbCommand dbCommand = database.GetStoredProcCommand("spstock_NewsUpdate");            
         
         database.AddInParameter(dbCommand, "@NewsID", DbType.Int32, stock_New.NewsID);
         database.AddInParameter(dbCommand, "@NewsTitle", DbType.String, stock_New.NewsTitle);
         database.AddInParameter(dbCommand, "@NewsDescription", DbType.String, stock_New.NewsDescription);
         database.AddInParameter(dbCommand, "@NewsContent", DbType.String, stock_New.NewsContent);
         database.AddInParameter(dbCommand, "@NewsDate", DbType.DateTime, stock_New.NewsDate);
         database.AddInParameter(dbCommand, "@NewsSource", DbType.String, stock_New.NewsSource);
         database.AddInParameter(dbCommand, "@SymbolID", DbType.Int32, stock_New.SymbolID);
         database.AddInParameter(dbCommand, "@UseUrl", DbType.Boolean, stock_New.UseUrl);
         database.AddInParameter(dbCommand, "@NewsUrl", DbType.String, stock_New.NewsUrl);
         database.AddInParameter(dbCommand, "@LanguageID", DbType.Int32, stock_New.LanguageID);
         database.AddInParameter(dbCommand, "@IsApproved", DbType.Boolean, stock_New.IsApproved);
         database.AddInParameter(dbCommand, "@ImageUrl", DbType.String, stock_New.ImageUrl);
         
         database.ExecuteNonQuery(dbCommand);
     }
     catch (Exception ex)
     {
         // log this exception
         log4net.Util.LogLog.Error(ex.Message, ex);
         // wrap it and rethrow
         throw new ApplicationException(SR.DataAccessUpdatestock_NewException, ex);
     }
 }
 public virtual stock_New Createstock_NewFromReader(IDataReader reader)
 {
     stock_New item = new stock_New();
     try
     {
         if (!reader.IsDBNull(reader.GetOrdinal("NewsID"))) item.NewsID = (int)reader["NewsID"];
         if (!reader.IsDBNull(reader.GetOrdinal("NewsTitle"))) item.NewsTitle = (string)reader["NewsTitle"];
         if (!reader.IsDBNull(reader.GetOrdinal("NewsDescription"))) item.NewsDescription = (string)reader["NewsDescription"];
         if (!reader.IsDBNull(reader.GetOrdinal("NewsContent"))) item.NewsContent = (string)reader["NewsContent"];
         if (!reader.IsDBNull(reader.GetOrdinal("NewsDate"))) item.NewsDate = (DateTime)reader["NewsDate"];
         if (!reader.IsDBNull(reader.GetOrdinal("NewsSource"))) item.NewsSource = (string)reader["NewsSource"];
         if (!reader.IsDBNull(reader.GetOrdinal("SymbolID"))) item.SymbolID = (int)reader["SymbolID"];
         if (!reader.IsDBNull(reader.GetOrdinal("UseUrl"))) item.UseUrl = (bool)reader["UseUrl"];
         if (!reader.IsDBNull(reader.GetOrdinal("NewsUrl"))) item.NewsUrl = (string)reader["NewsUrl"];
         if (!reader.IsDBNull(reader.GetOrdinal("LanguageID"))) item.LanguageID = (int)reader["LanguageID"];
         if (!reader.IsDBNull(reader.GetOrdinal("IsApproved"))) item.IsApproved = (bool)reader["IsApproved"];
         if (!reader.IsDBNull(reader.GetOrdinal("ImageUrl"))) item.ImageUrl = (string)reader["ImageUrl"];
     }
     catch (Exception ex)
     {
         // log this exception
         log4net.Util.LogLog.Error(ex.Message, ex);
         // wrap it and rethrow
         throw new ApplicationException(SR.DataAccessCreatestock_NewFromReaderException, ex);
     }
     return item;
 }
 public static void Updatestock_New(stock_New stock_New)
 {            
     try
     {
         stock_NewDAO stock_NewDAO = new stock_NewDAO();
         stock_NewDAO.Updatestock_New(stock_New);
     }
     catch (ApplicationException)
     {
         throw;
     }
     catch (Exception ex)
     {
         // log this exception
         log4net.Util.LogLog.Error(ex.Message, ex);
         // wrap it and rethrow
         throw new ApplicationException(SR.BusinessUpdatestock_NewException, ex);
     }
 }        
        public bool FeedItemIntoWebSite(Int16 sourceId)
        {
            bool returnVal = true;            
            StockNewCollection stockNewCollection;
            DestinationEntities.stock_New stockNewDestination = new DestinationEntities.stock_New();
            DestinationEntities.stock_NewsGroup stock_NewsGroupDestination = new DestinationEntities.stock_NewsGroup();
            DestinationEntities.stock_NewsGroup stock_NewsGroupHome = new DestinationEntities.stock_NewsGroup();

            Int32 totalRows = 0;
            int pos, symbolId;            
            Int32 newGroupId;
            newGroupId = 2; //nhom tin cong bo thong tin
            try
            {
                stockNewCollection = StockNewService.GetStockNewListBySource(sourceId, StockNewColumns.NewsId, "ASC", 1, 10, out totalRows);
                foreach (StockNew stockNew in stockNewCollection)
                {
                    stockNewDestination.NewsTitle = stockNew.NewsTitle;
                    stockNewDestination.NewsDescription = stockNew.NewsDescription;
                    stockNewDestination.NewsContent = stockNew.NewsContent;
                    stockNewDestination.NewsDate = DateTime.Now.AddHours(-7);
                    stockNewDestination.IsApproved = true;
                    stockNewDestination.LanguageID = 2;// should be dymamic 
                    stockNewDestination.NewsSource = stockNew.NewsSource;
                    pos = stockNewDestination.NewsTitle.Trim().IndexOf(':');
                    symbolId = 0;

                    if (pos > 0) symbolId = GetStockSymbolId(stockNewDestination.NewsTitle.Substring(0, pos));

                    if (symbolId > 0)
                    {
                        stockNew.ShareSymbol = stockNewDestination.NewsTitle.Substring(0, pos);
                    }

                    stockNewDestination.SymbolID = (symbolId > 0 ? symbolId : new int());
                    DestinationBusiness.stock_NewService.Createstock_New(stockNewDestination);

                    stock_NewsGroupDestination.NewsID = stockNewDestination.NewsID;
                    stock_NewsGroupDestination.NewsGroup = newGroupId;
                    DestinationBusiness.stock_NewsGroupService.Createstock_NewsGroup(stock_NewsGroupDestination);

                    stock_NewsGroupHome.NewsID = stockNewDestination.NewsID;
                    stock_NewsGroupHome.NewsGroup = 5;
                    DestinationBusiness.stock_NewsGroupService.Createstock_NewsGroup(stock_NewsGroupHome);
                    Ultility.Error("stock id: " + stockNew.NewsId.ToString());
                    StoredToApprovedNews(stockNew);
                    StockNewService.DeleteStockNew((int)stockNew.NewsId);
                }
            }
            catch (Exception ex)
            {
                Ultility.Error(ex.InnerException);
                returnVal = false;
            }
            return returnVal;
        }
    private void ApprovedNewStockList()
    {
        Int32 totalRows;
        string stockNewItemStringId;
        stockNewCollection = StockNewService.GetStockNewList(linkId, StockNewColumns.NewsId, "DESC", this.topPaging.CurrentIndex, ApplicationHelper.PageSize, out totalRows);
        foreach (StockNew stockNewItem in stockNewCollection)
        {
            stockNewItemStringId = Request.Form["selectedItem_" + Convert.ToString(stockNewItem.NewsId)];
            if (stockNewItemStringId != null)
            {
                selectedItems = selectedItems + "," + stockNewItemStringId;
            }          
        }
        selectedItems = selectedItems.Substring(1,(selectedItems.Length)-1);
        string selectedItemsGroupNews = Request.Form["selectedGroupNewsItem"];
        int pos, symbolId;
        Int32 stockId;
        Int32 newGroupId;

        if (selectedItems == string.Empty || selectedItems == null) return;

        foreach (string selectedItemId in selectedItems.Split(','))
        {
            stockId = Convert.ToInt32(selectedItemId);
            newGroupId = Convert.ToInt32(Request.Form["newsCategorySelect_" + stockId.ToString()]);
            StockNew stockNew = StockNewService.GetStockNew(stockId);
            stock_New stockNewDestination = new stock_New();
            stock_NewsGroup stock_NewsGroupDestination = new stock_NewsGroup();
            stock_NewsGroup stock_NewsGroupHome = new stock_NewsGroup();

            stockNewDestination.NewsTitle = stockNew.NewsTitle;
            stockNewDestination.NewsDescription = stockNew.NewsDescription;
            stockNewDestination.NewsContent = stockNew.NewsContent;
            stockNewDestination.NewsDate = DateTime.Now.AddHours(-7);
            stockNewDestination.IsApproved = true;
            stockNewDestination.LanguageID = 2;// should be dymamic 
            stockNewDestination.NewsSource = stockNew.NewsSource;
            pos = stockNewDestination.NewsTitle.Trim().IndexOf(':');
            symbolId = 0;

            if (pos > 0) symbolId = GetStockSymbolId(stockNewDestination.NewsTitle.Substring(0, pos));

            if (symbolId > 0)
            {
                stockNew.ShareSymbol = stockNewDestination.NewsTitle.Substring(0, pos);
            }

            stockNewDestination.SymbolID = (symbolId > 0 ? symbolId : new int());
            stock_NewService.Createstock_New(stockNewDestination);
            stock_NewsGroupDestination.NewsID = stockNewDestination.NewsID;
            stock_NewsGroupDestination.NewsGroup = newGroupId;
            stock_NewsGroupService.Createstock_NewsGroup(stock_NewsGroupDestination);
            if (selectedItemsGroupNews != null)
            {
                if (selectedItemsGroupNews.IndexOf(selectedItemId) >= 0)
                {
                    stock_NewsGroupHome.NewsID = stockNewDestination.NewsID;
                    stock_NewsGroupHome.NewsGroup = 5;
                    stock_NewsGroupService.Createstock_NewsGroup(stock_NewsGroupHome);
                }
            }

            StoredToApprovedNews(stockNew);
            StockNewService.DeleteStockNew(stockId);      
        }
    }
    private void ApprovedNewStockList()
    {
        string selectedItems = Request.Form["selectedItem"];
        int pos, symbolId;
        Int32 stockId;
        Int32 newGroupId;

        if (selectedItems == string.Empty || selectedItems == null) return;

        foreach (string selectedItemId in selectedItems.Split(','))
        {
            stockId = Convert.ToInt32(selectedItemId);
            newGroupId = Convert.ToInt32(Request.Form["newsCategorySelect_" + stockId.ToString()]);
            StockNew stockNew = StockNewService.GetStockNew(stockId);
            stock_New stockNewDestination = new stock_New();
            stock_NewsGroup stock_NewsGroupDestination = new stock_NewsGroup();

            stockNewDestination.NewsTitle = stockNew.NewsTitle;
            stockNewDestination.NewsDescription = stockNew.NewsDescription;
            stockNewDestination.NewsContent = stockNew.NewsContent;
            stockNewDestination.NewsDate = stockNew.NewsDate;
            stockNewDestination.IsApproved = false;
            stockNewDestination.LanguageID = 2;// should be dymamic 
            stockNewDestination.NewsSource = stockNew.NewsSource;
            pos = stockNewDestination.NewsTitle.IndexOf(':');
            symbolId = 0;
            if (linkId == 2)
            {
                if (pos > 0) symbolId = GetStockSymbolId(stockNewDestination.NewsTitle.Substring(0, pos));

                if (symbolId > 0)
                {
                    stockNew.ShareSymbol = stockNewDestination.NewsTitle.Substring(0, pos);
                }
            }

            stockNewDestination.SymbolID = (symbolId > 0 ? symbolId : new int());            
            stock_NewService.Createstock_New(stockNewDestination);
            stock_NewsGroupDestination.NewsID = stockNewDestination.NewsID;
            stock_NewsGroupDestination.NewsGroup = newGroupId;
            stock_NewsGroupService.Createstock_NewsGroup(stock_NewsGroupDestination);
            StoredToApprovedNews(stockNew);
            StockNewService.DeleteStockNew(stockId);
        }
    }