Ejemplo n.º 1
0
        public void SetDataSource(System.Windows.Forms.BindingSource dataSrc)
        {
            this.myDataSource = dataSrc;
            databases.baseDS.stockCodeDataTable tbl = (databases.baseDS.stockCodeDataTable) this.myDataSource.DataSource;
            this.codeEd.DataBindings.Clear();
            this.codeEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.codeColumn.ColumnName, true));

            this.enNameEd.DataBindings.Clear();
            this.enNameEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.nameColumn.ColumnName, true));

            this.nameEd.DataBindings.Clear();
            this.nameEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.nameEnColumn.ColumnName, true));

            this.addressEd1.DataBindings.Clear();
            this.addressEd1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.address1Column.ColumnName, true));

            this.addressEd2.DataBindings.Clear();
            this.addressEd2.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.address2Column.ColumnName, true));

            this.phoneEd.DataBindings.Clear();
            this.phoneEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.phoneColumn.ColumnName, true));

            this.faxEd.DataBindings.Clear();
            this.faxEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.faxColumn.ColumnName, true));

            this.emailEd.DataBindings.Clear();
            this.emailEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.emailColumn.ColumnName, true));

            this.websiteEd.DataBindings.Clear();
            this.websiteEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.websiteColumn.ColumnName, true));

            this.countryCb.DataBindings.Clear();
            this.countryCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.myDataSource, tbl.countryColumn.ColumnName, true));
        }
Ejemplo n.º 2
0
 public void SetDataSource(System.Windows.Forms.BindingSource dataSrc)
 {
     this.myDataSource = dataSrc;
     databases.baseDS.stockCodeDataTable tbl = (databases.baseDS.stockCodeDataTable) this.myDataSource.DataSource;
     this.bizSectorLb.DataBindings.Clear();
     this.bizSectorLb.DataBindings.Add(new System.Windows.Forms.Binding("myItemString", this.myDataSource, tbl.bizSectorsColumn.ColumnName, true));
 }
Ejemplo n.º 3
0
        public string GetSQL()
        {
            string investorCode = commonClass.SysLibs.sysLoginCode;

            databases.baseDS.transactionsDataTable transactionsTbl = new databases.baseDS.transactionsDataTable();
            databases.baseDS.stockCodeDataTable    stockCodeTbl    = new databases.baseDS.stockCodeDataTable();
            databases.baseDS.portfolioDataTable    portfolioTbl    = new databases.baseDS.portfolioDataTable();
            string sqlCmd = "SELECT * FROM " + transactionsTbl.TableName;
            string filter = "";

            string portfolioCond = "";

            if (investorCode.Trim() != "")
            {
                portfolioCond += (portfolioCond == "" ? "" : " AND ") +
                                 portfolioTbl.investorCodeColumn.ColumnName + "=N'" + investorCode.Trim() + "'";
            }
            if (portfolioCond != "")
            {
                filter += (filter == "" ? "" : " AND ") +
                          transactionsTbl.portfolioColumn.ColumnName + " IN " + common.Consts.constCRLF +
                          "(SELECT " + portfolioTbl.codeColumn.ColumnName + " FROM " + portfolioTbl.TableName +
                          " WHERE " + portfolioCond + ")";
            }

            if (this.stockExchangeChk.Checked && this.stockExchangeCb.myValue != "")
            {
                filter += (filter == "" ? "" : " AND ") +
                          transactionsTbl.stockCodeColumn.ColumnName + " IN (SELECT " + stockCodeTbl.codeColumn.ColumnName +
                          " FROM " + stockCodeTbl.TableName + " WHERE " + stockCodeTbl.stockExchangeColumn.ColumnName + "=N'" + this.stockExchangeCb.myValue.Trim() + "')";
            }
            if (this.dateRangeChk.Checked && this.dateRange.GetDateRange())
            {
                filter += (filter == "" ? "" : " AND ") +
                          "(" + transactionsTbl.onTimeColumn.ColumnName +
                          " BETWEEN '" + common.system.ConvertToSQLDateString(this.dateRange.frDate) + "' AND '" +
                          common.system.ConvertToSQLDateString(this.dateRange.toDate) + "')";
            }
            if (this.stockCodeEd.Enabled && this.stockCodeEd.Text.Trim() != "")
            {
                filter += (filter == "" ? "" : " AND ") +
                          transactionsTbl.stockCodeColumn.ColumnName + " =N'" + this.stockCodeEd.Text.Trim() + "'";
            }

            if (portfolioChk.Checked && portfolioCb.myValue.Trim() != "")
            {
                filter += (filter == "" ? "" : " AND ") +
                          transactionsTbl.portfolioColumn.ColumnName + " =N'" + portfolioCb.myValue.Trim() + "'";
            }
            if (filter != "")
            {
                sqlCmd += " WHERE " + filter;
            }
            return(sqlCmd);
        }
Ejemplo n.º 4
0
 //Detect new stockCode and create new one
 public static void AddNewCode(string market, databases.importDS.importPriceDataTable tbl, OnCodeAdded onAddstockCodeFunc)
 {
     databases.baseDS.stockCodeDataTable stockCodeTbl = new databases.baseDS.stockCodeDataTable();
     for (int count = 0; count < tbl.Count; count++)
     {
         if (tbl[count].RowState == DataRowState.Deleted) continue;
         if (AddNewCode(tbl[count].stockCode, market, stockCodeTbl) != null &&
             onAddstockCodeFunc != null) onAddstockCodeFunc(tbl[count].stockCode);
     }
     databases.DbAccess.UpdateData(stockCodeTbl);
 }
Ejemplo n.º 5
0
 private void SetMaxLength()
 {
     databases.baseDS.stockCodeDataTable tbl = new databases.baseDS.stockCodeDataTable();
     codeEd.MaxLength     = tbl.codeColumn.MaxLength;
     enNameEd.MaxLength   = tbl.nameColumn.MaxLength;
     addressEd1.MaxLength = tbl.address1Column.MaxLength;
     addressEd2.MaxLength = tbl.address2Column.MaxLength;
     phoneEd.MaxLength    = tbl.phoneColumn.MaxLength;
     faxEd.MaxLength      = tbl.faxColumn.MaxLength;
     emailEd.MaxLength    = tbl.emailColumn.MaxLength;
     websiteEd.MaxLength  = tbl.websiteColumn.MaxLength;
 }
Ejemplo n.º 6
0
 private void SetMaxLength()
 {
     databases.baseDS.stockCodeDataTable tbl = new databases.baseDS.stockCodeDataTable();
     codeEd.MaxLength = tbl.codeColumn.MaxLength;
     enNameEd.MaxLength = tbl.nameColumn.MaxLength;
     addressEd1.MaxLength = tbl.address1Column.MaxLength;
     addressEd2.MaxLength = tbl.address2Column.MaxLength;
     phoneEd.MaxLength = tbl.phoneColumn.MaxLength;
     faxEd.MaxLength = tbl.faxColumn.MaxLength;
     emailEd.MaxLength = tbl.emailColumn.MaxLength;
     websiteEd.MaxLength = tbl.websiteColumn.MaxLength;
 }
Ejemplo n.º 7
0
        public string GetSQL()
        {
            string investorCode = commonClass.SysLibs.sysLoginCode;

            databases.baseDS.transactionsDataTable transactionsTbl = new databases.baseDS.transactionsDataTable();
            databases.baseDS.stockCodeDataTable stockCodeTbl = new databases.baseDS.stockCodeDataTable();
            databases.baseDS.portfolioDataTable portfolioTbl = new databases.baseDS.portfolioDataTable();
            string sqlCmd = "SELECT * FROM " + transactionsTbl.TableName;
            string filter = "";

            string portfolioCond = "";
            if (investorCode.Trim() != "")
            {
                portfolioCond +=(portfolioCond == "" ? "" : " AND ") +
                                 portfolioTbl.investorCodeColumn.ColumnName + "=N'" + investorCode.Trim() + "'";
            }
            if (portfolioCond != "")
            {
                filter += (filter == "" ? "" : " AND ") +
                          transactionsTbl.portfolioColumn.ColumnName + " IN " + common.Consts.constCRLF +
                          "(SELECT " + portfolioTbl.codeColumn.ColumnName + " FROM " + portfolioTbl.TableName +
                          " WHERE " + portfolioCond + ")";
            }

            if (this.stockExchangeChk.Checked && this.stockExchangeCb.myValue != "")
            {
                filter += (filter == "" ? "" : " AND ") +  
                transactionsTbl.stockCodeColumn.ColumnName + " IN (SELECT " +stockCodeTbl.codeColumn.ColumnName +
                " FROM " + stockCodeTbl.TableName  + " WHERE " + stockCodeTbl.stockExchangeColumn.ColumnName + "=N'" + this.stockExchangeCb.myValue.Trim() + "')";
            }
            if (this.dateRangeChk.Checked && this.dateRange.GetDateRange())
            {
                filter += (filter == "" ? "" : " AND ") +
                           "("+ transactionsTbl.onTimeColumn.ColumnName +
                           " BETWEEN '" + common.system.ConvertToSQLDateString(this.dateRange.frDate) + "' AND '" +
                           common.system.ConvertToSQLDateString(this.dateRange.toDate) + "')";
            }
            if (this.stockCodeEd.Enabled && this.stockCodeEd.Text.Trim()!="")
            {
                filter += (filter == "" ? "" : " AND ") +
                           transactionsTbl.stockCodeColumn.ColumnName + " =N'" + this.stockCodeEd.Text.Trim() + "'";
            }

            if (portfolioChk.Checked && portfolioCb.myValue.Trim() != "")
            {
                filter += (filter == "" ? "" : " AND ") +
                           transactionsTbl.portfolioColumn.ColumnName + " =N'" + portfolioCb.myValue.Trim() + "'";
            }
            if (filter != "") sqlCmd += " WHERE " + filter;
            return sqlCmd;
        }
Ejemplo n.º 8
0
        public static void AddNewCode(databases.importDS.importPriceDataTable tbl, OnCodeAdded onAddstockCodeFunc)
        {
            databases.tmpDS.stockCodeRow shortCodeRow;
            databases.baseDS.stockCodeDataTable stockCodeTbl = new databases.baseDS.stockCodeDataTable();
            for (int count = 0; count < tbl.Count; count++)
            {
                if (tbl[count].RowState == DataRowState.Deleted) continue;
                shortCodeRow = databases.AppLibs.FindAndCache_StockCodeShort(tbl[count].stockCode);
                if (shortCodeRow == null) continue;

                if (AddNewCode(tbl[count].stockCode, shortCodeRow.stockExchange, stockCodeTbl) != null &&
                    onAddstockCodeFunc != null) onAddstockCodeFunc(tbl[count].stockCode);
            }
            databases.DbAccess.UpdateData(stockCodeTbl);
        }
Ejemplo n.º 9
0
 public static void AddNewCode(databases.baseDS.priceDataDataTable tbl, string stockEchangeCode, OnCodeAdded onAddstockCodeFunc)
 {
     databases.baseDS.stockCodeDataTable stockCodeTbl = new databases.baseDS.stockCodeDataTable();
     for (int count = 0; count < tbl.Count; count++)
     {
         if (tbl[count].RowState == DataRowState.Deleted)
         {
             continue;
         }
         if (AddNewCode(tbl[count].stockCode, stockEchangeCode, stockCodeTbl) != null &&
             onAddstockCodeFunc != null)
         {
             onAddstockCodeFunc(tbl[count].stockCode);
         }
     }
     databases.DbAccess.UpdateData(stockCodeTbl);
 }
Ejemplo n.º 10
0
 public static databases.baseDS.stockCodeRow FindAndCache(databases.baseDS.stockCodeDataTable tbl, string code)
 {
     databases.baseDS.stockCodeRow row = tbl.FindBycode(code);
     if (row != null)
     {
         return(row);
     }
     databases.baseDSTableAdapters.stockCodeTA dataTA = new databases.baseDSTableAdapters.stockCodeTA();
     dataTA.ClearBeforeFill = false;
     dataTA.FillByCode(tbl, code);
     row = tbl.FindBycode(code);
     if (row != null)
     {
         return(row);
     }
     return(null);
 }
Ejemplo n.º 11
0
 public static databases.baseDS.stockCodeRow AddNewCode(string comCode, string stockEchangeCode,
                                                        databases.baseDS.stockCodeDataTable toStockCodeTbl)
 {
     databases.baseDS.stockCodeRow stockCodeRow;
     stockCodeRow = application.SysLibs.FindAndCache(toStockCodeTbl, comCode);
     if (stockCodeRow == null)
     {
         stockCodeRow = toStockCodeTbl.NewstockCodeRow();
         databases.AppLibs.InitData(stockCodeRow);
         stockCodeRow.code          = comCode;
         stockCodeRow.name          = "<New>";
         stockCodeRow.code          = comCode;
         stockCodeRow.tickerCode    = comCode;
         stockCodeRow.stockExchange = stockEchangeCode;
         stockCodeRow.regDate       = DateTime.Today;
         toStockCodeTbl.AddstockCodeRow(stockCodeRow);
     }
     return(stockCodeRow);
 }
Ejemplo n.º 12
0
        public void SetDataSource(System.Windows.Forms.BindingSource dataSrc)
        {
            this.myDataSource = dataSrc;
            databases.baseDS.stockCodeDataTable tbl = (databases.baseDS.stockCodeDataTable) this.myDataSource.DataSource;

            this.stockMarketCb.DataBindings.Clear();
            this.stockMarketCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.myDataSource, tbl.stockExchangeColumn.ColumnName, true));

            this.tickerCodeEd.DataBindings.Clear();
            this.tickerCodeEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.tickerCodeColumn.ColumnName, true));

            this.treasuryStockEd.DataBindings.Clear();
            this.treasuryStockEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.noTreasuryStockColumn.ColumnName, true));

            this.listedStockEd.DataBindings.Clear();
            this.listedStockEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.noListedStockColumn.ColumnName, true));

            this.outstandingStockEd.DataBindings.Clear();
            this.outstandingStockEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.noOutstandingStockColumn.ColumnName, true));

            this.foreignOwnStockEd.DataBindings.Clear();
            this.foreignOwnStockEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.noForeignOwnedStockColumn.ColumnName, true));

            this.bookPriceEd.DataBindings.Clear();
            this.bookPriceEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.bookPriceColumn.ColumnName, true));

            this.targetPriceEd.DataBindings.Clear();
            this.targetPriceEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.targetPriceColumn.ColumnName, true));

            this.targetPriceVariantEd.DataBindings.Clear();
            this.targetPriceVariantEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myDataSource, tbl.targetPriceVariantColumn.ColumnName, true));

            this.regDateEd.DataBindings.Clear();
            this.regDateEd.DataBindings.Add(new System.Windows.Forms.Binding("myDateTime", this.myDataSource, tbl.regDateColumn.ColumnName, true));

            this.statusCb.DataBindings.Clear();
            this.statusCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.myDataSource, tbl.statusColumn.ColumnName, true));
        }
Ejemplo n.º 13
0
        public static void AddNewCode(databases.importDS.importPriceDataTable tbl, OnCodeAdded onAddstockCodeFunc)
        {
            databases.tmpDS.stockCodeRow        shortCodeRow;
            databases.baseDS.stockCodeDataTable stockCodeTbl = new databases.baseDS.stockCodeDataTable();
            for (int count = 0; count < tbl.Count; count++)
            {
                if (tbl[count].RowState == DataRowState.Deleted)
                {
                    continue;
                }
                shortCodeRow = databases.AppLibs.FindAndCache_StockCodeShort(tbl[count].stockCode);
                if (shortCodeRow == null)
                {
                    continue;
                }

                if (AddNewCode(tbl[count].stockCode, shortCodeRow.stockExchange, stockCodeTbl) != null &&
                    onAddstockCodeFunc != null)
                {
                    onAddstockCodeFunc(tbl[count].stockCode);
                }
            }
            databases.DbAccess.UpdateData(stockCodeTbl);
        }
Ejemplo n.º 14
0
 public bool UpdateStock(ref databases.baseDS.stockCodeDataTable stockCodeTbl)
 {
     return(base.Channel.UpdateStock(ref stockCodeTbl));
 }
Ejemplo n.º 15
0
 private void SetMaxLength()
 {
     databases.baseDS.stockCodeDataTable tbl = new databases.baseDS.stockCodeDataTable();
     bizSectorLb.maxLen = tbl.bizSectorsColumn.MaxLength;
 }
Ejemplo n.º 16
0
 public static databases.baseDS.stockCodeRow UpdateData(databases.baseDS.stockCodeRow row)
 {
     try
     {
         lock (myClient)
         {
             databases.baseDS.stockCodeDataTable tbl = new databases.baseDS.stockCodeDataTable();
             tbl.ImportRow(row);
             myClient.UpdateStock(ref tbl);
             row.AcceptChanges();
             return tbl[0];
         }
     }
     catch (Exception er)
     {
         if (OnError != null) OnError(er);
     }
     return null;
 }
Ejemplo n.º 17
0
        private void okBtn_Click(object sender, System.EventArgs e)
        {
            try
            {
                ClearNotifyError();
                codeEd.Text = codeEd.Text.Trim();
                if (codeChk.Checked && codeEd.Text == "")
                {
                    NotifyError(codeChk);
                    return;
                }

                ClearNotifyError();
                this.ShowMessage("");
                this.ShowMessage("");
                okBtn.Enabled   = false;
                codeChk.Enabled = false;
                codeEd.Enabled  = false;

                ShowCurrorWait();
                fCanceled = false;

                System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
                stopWatch.Start();

                CultureInfo stockCulture = application.AppLibs.GetStockCulture(codeEd.Text);
                if (codeChk.Checked)
                {
                    this.ShowMessage(codeEd.Text);
                    databases.AppLibs.ReAggregatePriceData(codeEd.Text, stockCulture, OnAggregateData);
                }
                else
                {
                    databases.baseDS.stockCodeDataTable tbl = new databases.baseDS.stockCodeDataTable();
                    databases.DbAccess.LoadData(tbl);
                    for (int idx = 0; idx < tbl.Count; idx++)
                    {
                        if (fCanceled)
                        {
                            break;
                        }
                        this.ShowMessage(tbl[idx].code);
                        databases.AppLibs.ReAggregatePriceData(tbl[idx].code, stockCulture, OnAggregateData);
                        this.ShowMessage("");
                        Application.DoEvents();
                    }
                }
                stopWatch.Stop();
                this.ShowMessage("Hòan tất " + common.dateTimeLibs.TimeSpan2String(stopWatch.Elapsed));
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
            finally
            {
                progressBar.Visible = false;
                okBtn.Enabled       = true;
                codeChk.Enabled     = true;
                codeChk_CheckedChanged(null, null);

                progressBar.Visible = false;
                ShowCurrorDefault();
            }
        }
Ejemplo n.º 18
0
        //Use the idea from http://www.codeproject.com/KB/database/CsvReader.aspx by Sebastien Lorion
        public static bool CSV_ImportParse(string csvFileName, char delimiter,
                                           common.dateTimeLibs.DateTimeFormats dateDataFormat,
                                           string marketCode, CultureInfo dataCulture,
                                           databases.baseDS.priceDataDataTable priceDataTbl,
                                           ImportRowHandler ImportRowFunc,
                                           OnUpdatePriceData onUpdateDataFunc,
                                           OnEndImportPriceData onEndImportFunc)
        {
            importStat myImportStat = new importStat();

            myImportStat.Reset();
            myImportStat.dateDataFormat = dateDataFormat;
            myImportStat.srcCulture     = dataCulture;
            databases.baseDS.stockCodeDataTable stockCodeTbl = new databases.baseDS.stockCodeDataTable();
            databases.baseDS.priceDataRow       priceDataRow;

            DataRowView[] foundRows;
            databases.DbAccess.LoadData(stockCodeTbl, AppTypes.CommonStatus.Enable);
            DataView stockCodeView = new DataView(stockCodeTbl);

            stockCodeView.Sort = stockCodeTbl.codeColumn.ColumnName;

            bool     fCanceled     = false;
            DateTime lastPriceDate = common.Consts.constNullDate;

            importOHLCV data;

            // open the file "data.csv" which is a CSV file with headers
            using (CsvReader csv = new CsvReader(new StreamReader(csvFileName), true, delimiter))
            {
                // missing fields will not throw an exception,
                // but will instead be treated as if there was a null value
                csv.MissingFieldAction = MissingFieldAction.ReplaceByNull;

                int fieldCount = csv.FieldCount;
                if (fieldCount < 7)
                {
                    return(false);
                }
                while (csv.ReadNextRecord())
                {
                    Application.DoEvents();
                    myImportStat.dataCount++;
                    data = ImportRowFunc(csv, myImportStat);
                    if (myImportStat.cancel)
                    {
                        fCanceled = true; break;
                    }
                    if (data == null)
                    {
                        myImportStat.errorCount++;
                        continue;
                    }
                    //Assume that all price must be valid
                    if (data.Open <= 0 || data.High <= 0 || data.Low <= 0 || data.Close <= 0)
                    {
                        continue;
                    }

                    foundRows = stockCodeView.FindRows(data.code);
                    if (foundRows.Length == 0)
                    {
                        //Try to add new stock code
                        Libs.AddNewCode(data.code, marketCode, stockCodeTbl);
                        databases.DbAccess.UpdateData(stockCodeTbl);
                    }

                    // Ignore all data that was in database
                    //if (!foundLastPriceDate)
                    //{
                    //    lastPriceDate = FindLastPriceDate(data.code);
                    //    foundLastPriceDate = true;
                    //}
                    if (lastPriceDate != common.Consts.constNullDate && data.dateTime <= lastPriceDate)
                    {
                        continue;
                    }
                    if (priceDataTbl.FindBystockCodeonDate(data.code, data.dateTime) != null)
                    {
                        myImportStat.errorCount++;
                        continue;
                    }
                    myImportStat.updateCount++;
                    priceDataRow = priceDataTbl.NewpriceDataRow();
                    databases.AppLibs.InitData(priceDataRow);
                    priceDataRow.stockCode = data.code;
                    priceDataRow.onDate    = data.dateTime;
                    //Try to fix some error in data
                    priceDataRow.openPrice  = (decimal)data.Open;
                    priceDataRow.highPrice  = (decimal)data.High;
                    priceDataRow.lowPrice   = (decimal)data.Low;
                    priceDataRow.closePrice = (decimal)data.Close;
                    priceDataRow.volume     = (decimal)data.Volume;
                    priceDataTbl.AddpriceDataRow(priceDataRow);
                    if (onUpdateDataFunc != null)
                    {
                        onUpdateDataFunc(priceDataRow, myImportStat);
                    }
                }
            }
            if (fCanceled)
            {
                priceDataTbl.Clear();
                return(false);
            }
            if (onEndImportFunc != null)
            {
                onEndImportFunc(priceDataTbl);
            }
            return(true);
        }
Ejemplo n.º 19
0
 private void SetMaxLength()
 {
     databases.baseDS.stockCodeDataTable tbl = new databases.baseDS.stockCodeDataTable();
     tickerCodeEd.MaxLength = tbl.tickerCodeColumn.MaxLength;
 }
Ejemplo n.º 20
0
        private void okBtn_Click(object sender, System.EventArgs e)
        {
            try
            {
                ClearNotifyError();
                codeEd.Text = codeEd.Text.Trim();
                if (codeChk.Checked &&  codeEd.Text == "")
                {
                    NotifyError(codeChk);
                    return; 
                }

                ClearNotifyError();
                this.ShowMessage("");
                this.ShowMessage("");
                okBtn.Enabled = false;
                codeChk.Enabled = false;
                codeEd.Enabled = false;

                ShowCurrorWait();
                fCanceled = false;
                
                System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
                stopWatch.Start();

                CultureInfo stockCulture = application.AppLibs.GetStockCulture(codeEd.Text);
                if (codeChk.Checked)
                {
                    this.ShowMessage(codeEd.Text);
                    databases.AppLibs.ReAggregatePriceData(codeEd.Text, stockCulture, OnAggregateData);
                }
                else
                {
                    databases.baseDS.stockCodeDataTable tbl = new databases.baseDS.stockCodeDataTable();
                    databases.DbAccess.LoadData(tbl);
                    for (int idx = 0; idx < tbl.Count; idx++)
                    {
                        if (fCanceled) break;
                        this.ShowMessage(tbl[idx].code);
                        databases.AppLibs.ReAggregatePriceData(tbl[idx].code, stockCulture, OnAggregateData);
                        this.ShowMessage("");
                        Application.DoEvents();
                    }
                }
                stopWatch.Stop();
                this.ShowMessage("Hòan tất " + common.dateTimeLibs.TimeSpan2String(stopWatch.Elapsed));
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
            finally
            {
                progressBar.Visible = false;
                okBtn.Enabled = true;
                codeChk.Enabled = true;
                codeChk_CheckedChanged(null,null);

                progressBar.Visible = false;
                ShowCurrorDefault();
            }
        }
Ejemplo n.º 21
0
 private void SetMaxLength()
 {
     databases.baseDS.stockCodeDataTable tbl = new databases.baseDS.stockCodeDataTable();
     tickerCodeEd.MaxLength = tbl.tickerCodeColumn.MaxLength;
 }
Ejemplo n.º 22
0
        //Use the idea from http://www.codeproject.com/KB/database/CsvReader.aspx by Sebastien Lorion 
        public static bool CSV_ImportParse(string csvFileName, char delimiter, 
                                           common.dateTimeLibs.DateTimeFormats dateDataFormat,
                                           string marketCode, CultureInfo dataCulture,
                                           databases.baseDS.priceDataDataTable priceDataTbl,
                                           ImportRowHandler ImportRowFunc,
                                           OnUpdatePriceData onUpdateDataFunc,
                                           OnEndImportPriceData onEndImportFunc)
        {
            importStat myImportStat = new importStat();
            myImportStat.Reset();
            myImportStat.dateDataFormat = dateDataFormat;
            myImportStat.srcCulture  = dataCulture;
            databases.baseDS.stockCodeDataTable stockCodeTbl = new databases.baseDS.stockCodeDataTable();
            databases.baseDS.priceDataRow priceDataRow;

            DataRowView[] foundRows;
            databases.DbAccess.LoadData(stockCodeTbl, AppTypes.CommonStatus.Enable);
            DataView stockCodeView = new DataView(stockCodeTbl);
            stockCodeView.Sort = stockCodeTbl.codeColumn.ColumnName;

            bool fCanceled = false;
            DateTime lastPriceDate = common.Consts.constNullDate;

            importOHLCV data;
            // open the file "data.csv" which is a CSV file with headers
            using (CsvReader csv = new CsvReader(new StreamReader(csvFileName), true, delimiter))
            {
                // missing fields will not throw an exception,
                // but will instead be treated as if there was a null value
                csv.MissingFieldAction = MissingFieldAction.ReplaceByNull;

                int fieldCount = csv.FieldCount;
                if (fieldCount < 7) return false;
                while (csv.ReadNextRecord())
                {
                    Application.DoEvents();
                    myImportStat.dataCount++;
                    data = ImportRowFunc(csv, myImportStat);
                    if (myImportStat.cancel)
                    {
                        fCanceled = true; break;
                    }
                    if (data == null)
                    {
                        myImportStat.errorCount++;
                        continue;
                    }
                    //Assume that all price must be valid
                    if (data.Open <= 0 || data.High <= 0 || data.Low <= 0 || data.Close <= 0) continue;

                    foundRows = stockCodeView.FindRows(data.code);
                    if (foundRows.Length == 0)
                    {
                        //Try to add new stock code
                        Libs.AddNewCode(data.code, marketCode, stockCodeTbl);
                        databases.DbAccess.UpdateData(stockCodeTbl);
                    }

                    // Ignore all data that was in database
                    //if (!foundLastPriceDate)
                    //{
                    //    lastPriceDate = FindLastPriceDate(data.code);
                    //    foundLastPriceDate = true;
                    //}
                    if (lastPriceDate != common.Consts.constNullDate && data.dateTime <= lastPriceDate)
                    {
                        continue;
                    }
                    if (priceDataTbl.FindBystockCodeonDate(data.code, data.dateTime) != null)
                    {
                        myImportStat.errorCount++;
                        continue;
                    }
                    myImportStat.updateCount++;
                    priceDataRow = priceDataTbl.NewpriceDataRow();
                    databases.AppLibs.InitData(priceDataRow);
                    priceDataRow.stockCode = data.code;
                    priceDataRow.onDate = data.dateTime;
                    //Try to fix some error in data
                    priceDataRow.openPrice = (decimal)data.Open;
                    priceDataRow.highPrice = (decimal)data.High;
                    priceDataRow.lowPrice = (decimal)data.Low;
                    priceDataRow.closePrice = (decimal)data.Close;
                    priceDataRow.volume = (decimal)data.Volume;
                    priceDataTbl.AddpriceDataRow(priceDataRow);
                    if (onUpdateDataFunc != null) onUpdateDataFunc(priceDataRow, myImportStat);
                }
            }
            if (fCanceled)
            {
                priceDataTbl.Clear();
                return false;
            }
            if (onEndImportFunc != null) onEndImportFunc(priceDataTbl);
            return true;
        }
Ejemplo n.º 23
0
 public databases.baseDS.stockCodeDataTable GetStockFull()
 {
     try
     {
         databases.baseDS.stockCodeDataTable tbl = new databases.baseDS.stockCodeDataTable();
         databases.DbAccess.LoadData(tbl);
         return tbl;
     }
     catch (Exception ex)
     {
         WriteSysLogLocal("WS018", ex);
     }
     return null;
 }
Ejemplo n.º 24
0
 private void SetMaxLength()
 {
     databases.baseDS.stockCodeDataTable tbl = new databases.baseDS.stockCodeDataTable();
     bizSectorLb.maxLen = tbl.bizSectorsColumn.MaxLength;
 }