Exemple #1
0
        // Return common.extSortedList that store the mapping [Column in web page] -> [importPrice column]
        private common.extSortedList CreateMapping(metaStock meta, databases.importDS.importPriceDataTable dataTbl)
        {
            common.extSortedList list = new common.extSortedList();

            list.Add(meta.closePriceColId.ToString(), dataTbl.closePriceColumn.ColumnName);
            list.Add(meta.volumeColId.ToString(), dataTbl.volumeColumn.ColumnName);
            return(list);
        }
Exemple #2
0
        protected override metaStock GetMeta()
        {
            metaStock meta = new metaStock();

            meta.noRowIgnore     = 0;
            meta.startAtColId    = 0;      meta.endAtColId = 25;
            meta.openPriceColId  = -1;   meta.highPriceColId = 21;   meta.lowPriceColId = 22;
            meta.closePriceColId = 12;  meta.volumeColId = 13;      meta.volumeColId = 13;
            return(meta);
        }
Exemple #3
0
        public override databases.baseDS.priceDataDataTable GetImportFromWeb(DateTime updateTime, databases.baseDS.exchangeDetailRow exchangeDetailRow)
        {
            metaStock meta = GetMeta();

            if (meta == null)
            {
                return(null);
            }

            databases.importDS.importPriceDataTable importPriceTbl = GetPriceFromWeb(updateTime, meta, exchangeDetailRow);
            Imports.Libs.AddNewCode(exchangeDetailRow.marketCode, importPriceTbl, null);
            databases.DbAccess.UpdateData(importPriceTbl);

            databases.baseDS.priceDataDataTable priceTbl = new databases.baseDS.priceDataDataTable();
            Imports.Libs.AddImportPrice(importPriceTbl, priceTbl);
            databases.DbAccess.UpdateData(priceTbl);
            return(priceTbl);
        }
Exemple #4
0
        public override databases.baseDS.priceDataDataTable GetImportFromWeb(DateTime updateTime, databases.baseDS.exchangeDetailRow exchangeDetailRow)
        {
            try
            {
                databases.importDS.importPriceDataTable importPriceTbl;
                metaStock meta = GetMeta();
                if (meta == null)
                {
                    return(null);
                }

                //try
                //{
                importPriceTbl = GetPriceFromWeb(updateTime, meta, exchangeDetailRow);
                Imports.Libs.AddNewCode(exchangeDetailRow.marketCode, importPriceTbl, null);
                databases.DbAccess.UpdateData(importPriceTbl);
                ////}
                //catch (Exception er)
                //{
                //    commonClass.SysLibs.WriteSysLog(common.SysSeverityLevel.Error, "SRV004 - Import price error", er);
                //    throw er;
                //}

                //try
                //{
                databases.baseDS.priceDataDataTable priceTbl = new databases.baseDS.priceDataDataTable();
                Imports.Libs.AddImportPrice(importPriceTbl, priceTbl);
                databases.DbAccess.UpdateData(priceTbl);
                return(priceTbl);
                //}
                //catch (Exception er)
                //{
                //    commonClass.SysLibs.WriteSysLog(common.SysSeverityLevel.Error, "SRV004 - Price Data table", er);
                //    throw er;
                //}
            }

            catch (Exception er)
            {
                commonClass.SysLibs.WriteSysLog(common.SysSeverityLevel.Error, "SRV004 - GetImport From Web error", er);
                return(null);
            }
        }
Exemple #5
0
        /// <summary>
        /// Import data from URL to tables : importPrice
        /// The function also detect and add new companies to the database
        /// </summary>
        /// <param name="url">URL to get data</param>
        /// <param name="priceMeta">meta describe the webpage structure</param>
        /// <param name="stockExchangeCode">stock exchange code of imported data </param>
        /// <param name="importPriceTbl"> where to store imported data </param>
        public databases.importDS.importPriceDataTable GetPriceFromWeb(DateTime updateTime, metaStock priceMeta, databases.baseDS.exchangeDetailRow exchangeDetailRow)
        {
            bool bHaveData = false; //Kiem tra xem bang co du lieu hay ko
            //Data in
            CultureInfo CultureInfoUS = common.language.GetCulture("en-US");

            databases.importDS.importPriceDataTable importPriceTbl = new databases.importDS.importPriceDataTable();
            this.mappingList = CreateMapping(priceMeta, importPriceTbl);

            // Get the URL specified
            var webGet   = new HtmlWeb();
            var document = webGet.Load(exchangeDetailRow.address);

            // Get <a> tags that have a href attribute and non-whitespace inner text
            var linksOnPage = from item in document.DocumentNode.Descendants()
                              where item.Name == "td" && item.Attributes["id"] == null
                              select new
            {
                Text = item.InnerText
            };

            bool    fError = false;
            int     igmoreRowCount = 0, columnCount = 0;
            decimal val = 0;

            databases.importDS.importPriceRow importRow = null;
            databases.importDS.importPriceRow oldImportRow;
            string stockCode;

            foreach (var item in linksOnPage)
            {
                //Check whether to ignore some items at the first
                if (++igmoreRowCount <= priceMeta.noRowIgnore)
                {
                    continue;
                }
                if (fError)
                {
                    break;
                }

                if (columnCount == priceMeta.startAtColId)
                {
                    stockCode = item.Text.Trim();
                    importRow = importPriceTbl.NewimportPriceRow();
                    databases.AppLibs.InitData(importRow);
                    importRow.onDate        = updateTime;
                    importRow.stockCode     = stockCode;
                    importRow.isTotalVolume = true;
                    columnCount++;
                    continue;
                }
                //Last column
                if (columnCount == priceMeta.endAtColId)
                {
                    if (importRow.closePrice > 0)
                    {
                        //Only add new when there are some changes
                        oldImportRow = lastImportData.Find(importRow);
                        if (!lastImportData.IsSameData(importRow, oldImportRow))
                        {
                            importPriceTbl.AddimportPriceRow(importRow);
                            lastImportData.Update(importRow);
                        }
                        else
                        {
                            importRow.CancelEdit();
                        }
                    }
                    else
                    {
                        importRow.CancelEdit();
                    }
                    columnCount = 0;
                    continue;
                }
                object obj = this.mappingList.GetValue(columnCount.ToString());
                if (obj != null)
                {
                    val = 0; common.system.StrToDecimal(item.Text, CultureInfoUS, out val);

                    //15/07: Kiem tra gia tri co bang 0 hay ko. Neu co thi se co loi doc du lieu
                    if (val != 0)
                    {
                        bHaveData = true;
                    }
                    importRow[(string)obj] = val;
                }
                columnCount++;
            }

            //Neu ko co du lieu
            if (!bHaveData)
            {
                throw new Exception();
            }

            return(importPriceTbl);
        }
Exemple #6
0
        /// <summary>
        /// Import data from URL to tables : importPrice 
        /// The function also detect and add new companies to the database
        /// </summary>
        /// <param name="url">URL to get data</param>
        /// <param name="priceMeta">meta describe the webpage structure</param>
        /// <param name="stockExchangeCode">stock exchange code of imported data </param>
        /// <param name="importPriceTbl"> where to store imported data </param>
        public databases.importDS.importPriceDataTable GetPriceFromWeb(DateTime updateTime, metaStock priceMeta,databases.baseDS.exchangeDetailRow exchangeDetailRow)
        {
            bool bHaveData = false; //Kiem tra xem bang co du lieu hay ko
            //Data in
            CultureInfo CultureInfoUS = common.language.GetCulture("en-US");
            databases.importDS.importPriceDataTable importPriceTbl = new databases.importDS.importPriceDataTable();
            this.mappingList = CreateMapping(priceMeta, importPriceTbl);

            // Get the URL specified
            var webGet = new HtmlWeb();
            var document = webGet.Load(exchangeDetailRow.address);

            // Get <a> tags that have a href attribute and non-whitespace inner text
            var linksOnPage = from item in document.DocumentNode.Descendants()
                              where item.Name == "td" && item.Attributes["id"] == null
                              select new
                              {
                                  Text = item.InnerText
                              };

            bool fError = false;
            int igmoreRowCount = 0, columnCount = 0;
            decimal val = 0;
            databases.importDS.importPriceRow importRow = null;
            databases.importDS.importPriceRow oldImportRow;
            string stockCode;
            foreach (var item in linksOnPage)
            {
                //Check whether to ignore some items at the first
                if (++igmoreRowCount <= priceMeta.noRowIgnore) continue;
                if (fError) break;

                if (columnCount == priceMeta.startAtColId)
                {
                    stockCode = item.Text.Trim();
                    importRow = importPriceTbl.NewimportPriceRow();
                    databases.AppLibs.InitData(importRow);
                    importRow.onDate = updateTime;
                    importRow.stockCode = stockCode;
                    importRow.isTotalVolume = true;
                    columnCount++;
                    continue;
                }
                //Last column
                if (columnCount == priceMeta.endAtColId)
                {
                    if (importRow.closePrice > 0)
                    {
                        //Only add new when there are some changes 
                        oldImportRow = lastImportData.Find(importRow);
                        if (!lastImportData.IsSameData(importRow, oldImportRow))
                        {
                            importPriceTbl.AddimportPriceRow(importRow);
                            lastImportData.Update(importRow);
                        }
                        else importRow.CancelEdit();
                    }
                    else importRow.CancelEdit();
                    columnCount = 0;
                    continue;
                }
                object obj = this.mappingList.GetValue(columnCount.ToString());
                if (obj != null)
                {
                    val = 0; common.system.StrToDecimal(item.Text, CultureInfoUS, out val);

                    //15/07: Kiem tra gia tri co bang 0 hay ko. Neu co thi se co loi doc du lieu
                    if (val != 0)
                        bHaveData = true;                    
                    importRow[(string)obj] = val;
                }
                columnCount++;
            }

            //Neu ko co du lieu
            if (!bHaveData) 
                throw new Exception();
            
            return importPriceTbl;
            
        }
Exemple #7
0
 protected override metaStock GetMeta()
 {
     metaStock meta = new metaStock();
     meta.noRowIgnore = 0;
     meta.startAtColId = 0;      meta.endAtColId = 25;
     meta.openPriceColId = -1;   meta.highPriceColId = 21;   meta.lowPriceColId = 22;
     meta.closePriceColId = 12;  meta.volumeColId = 13;      meta.volumeColId = 13;
     return meta;
 }
Exemple #8
0
        // Return common.extSortedList that store the mapping [Column in web page] -> [importPrice column]
        private common.extSortedList CreateMapping(metaStock meta, databases.importDS.importPriceDataTable dataTbl)
        {
            common.extSortedList list = new common.extSortedList();

            list.Add(meta.closePriceColId.ToString(), dataTbl.closePriceColumn.ColumnName);
            list.Add(meta.volumeColId.ToString(), dataTbl.volumeColumn.ColumnName);
            return list;
        }