Exemple #1
0
        private void btnDelete_Click(object sender, System.EventArgs e)
        {
            DataManagerBase dmb = Utils.GetDefaultDataManager();

            try
            {
                CommonDataProvider cdp = (CommonDataProvider)dmb[tbSymbol.Text];
                lMsg.Text = "Original data count :" + cdp.Count + "<br>";
                cdp.DeleteData(dpStart.Date, dpEnd.Date);
                lMsg.Text += "New data count : " + cdp.Count;
                dmb.SaveData(tbSymbol.Text, cdp, false);
            }
            catch (Exception ex)
            {
                lMsg.Text = ex.Message;
            }
        }
        public ProductModel PopulateProductModelFromIDataReader(IDataReader dr)
        {
            ProductModel productModel = new ProductModel();

            productModel.ModelID     = DataRecordHelper.GetInt32(dr, "ModelID");
            productModel.ProductID   = DataRecordHelper.GetInt32(dr, "ProductID");
            productModel.ModelCode   = DataRecordHelper.GetString(dr, "ModelCode");
            productModel.ModelName   = DataRecordHelper.GetString(dr, "ModelName");
            productModel.ModelDesc   = DataRecordHelper.GetString(dr, "ModelDesc");
            productModel.ModelStatus = (ComponentStatus)DataRecordHelper.GetInt32(dr, "ModelStatus");
            productModel.CreateTime  = DataRecordHelper.GetDateTime(dr, "CreateTime");
            productModel.CreateUser  = DataRecordHelper.GetInt32(dr, "CreateUser");
            productModel.UpdateTime  = DataRecordHelper.GetDateTime(dr, "UpdateTime");
            productModel.UpdateUser  = DataRecordHelper.GetInt32(dr, "UpdateUser");
            productModel.SetSerializerData(CommonDataProvider.PopulateSerializerDataIDataRecord(dr));
            return(productModel);
        }
        public override void SetStrings(CommonDataProvider cdp, string Code)
        {
            cdp.SetStringData("Code", Code);
            switch (Code)
            {
            case "^DJI":
                cdp.SetStringData("Name", "Dow Jones");
                break;

            case "^IXIC":
                cdp.SetStringData("Name", "Nasdaq");
                break;

            case "^SPX":
                cdp.SetStringData("Name", "S & P 500");
                break;
            }
        }
        public static ProductFocus PopulateProductFocusFromIDataReader(IDataReader dr)
        {
            ProductFocus productFocus = new ProductFocus();

            productFocus.FocusID      = DataRecordHelper.GetInt32(dr, "FocusID");
            productFocus.FocusType    = (FocusType)DataRecordHelper.GetInt32(dr, "FocusType");
            productFocus.FocusFrom    = DataRecordHelper.GetDateTime(dr, "FocusFrom");
            productFocus.FocusEnd     = DataRecordHelper.GetDateTime(dr, "FocusEnd");
            productFocus.ProductID    = DataRecordHelper.GetInt32(dr, "ProductID");
            productFocus.ModelID      = DataRecordHelper.GetInt32(dr, "ModelID");
            productFocus.DisplayOrder = DataRecordHelper.GetInt32(dr, "DisplayOrder");
            productFocus.FocusMemo    = DataRecordHelper.GetString(dr, "FocusMemo");
            productFocus.FocusStatus  = (ComponentStatus)DataRecordHelper.GetInt32(dr, "FocusStatus");
            productFocus.CreateTime   = DataRecordHelper.GetDateTime(dr, "CreateTime");
            productFocus.CreateUser   = DataRecordHelper.GetInt32(dr, "CreateUser");
            productFocus.UpdateTime   = DataRecordHelper.GetDateTime(dr, "UpdateTime");
            productFocus.UpdateUser   = DataRecordHelper.GetInt32(dr, "UpdateUser");
            productFocus.SetSerializerData(CommonDataProvider.PopulateSerializerDataIDataRecord(dr));
            return(productFocus);
        }
        public static ProductBrand PopulateBrandFromIDataReader(IDataReader dr)
        {
            ProductBrand brand = new ProductBrand();

            brand.BrandID       = DataRecordHelper.GetInt32(dr, "BrandID");
            brand.BrandName     = DataRecordHelper.GetString(dr, "BrandName");
            brand.BrandLogo     = DataRecordHelper.GetString(dr, "BrandLogo");
            brand.BrandTitle    = DataRecordHelper.GetString(dr, "BrandTitle");
            brand.BrandGroup    = DataRecordHelper.GetString(dr, "BrandGroup");
            brand.BrandAbstract = DataRecordHelper.GetString(dr, "BrandAbstract");
            brand.BrandContent  = DataRecordHelper.GetString(dr, "BrandContent");
            brand.DisplayOrder  = DataRecordHelper.GetInt32(dr, "DisplayOrder");
            brand.BrandStatus   = (ComponentStatus)DataRecordHelper.GetInt32(dr, "BrandStatus");
            brand.CreateTime    = DataRecordHelper.GetDateTime(dr, "CreateTime");
            brand.CreateUser    = DataRecordHelper.GetInt32(dr, "CreateUser");
            brand.UpdateTime    = DataRecordHelper.GetDateTime(dr, "UpdateTime");
            brand.UpdateUser    = DataRecordHelper.GetInt32(dr, "UpdateUser");
            brand.SetSerializerData(CommonDataProvider.PopulateSerializerDataIDataRecord(dr));
            return(brand);
        }
        public ProductIndustry PopulateIndustryFromIDataReader(IDataReader dr)
        {
            ProductIndustry industry = new ProductIndustry();

            industry.IndustryID       = DataRecordHelper.GetInt32(dr, "IndustryID");
            industry.IndustryName     = DataRecordHelper.GetString(dr, "IndustryName");
            industry.IndustryLogo     = DataRecordHelper.GetString(dr, "IndustryLogo");
            industry.IndustryTitle    = DataRecordHelper.GetString(dr, "IndustryTitle");
            industry.IndustryAbstract = DataRecordHelper.GetString(dr, "IndustryAbstract");
            industry.IndustryContent  = DataRecordHelper.GetString(dr, "IndustryContent");
            industry.ParentID         = DataRecordHelper.GetInt32(dr, "ParentID");
            industry.DisplayOrder     = DataRecordHelper.GetInt32(dr, "DisplayOrder");
            industry.IndustryStatus   = (ComponentStatus)DataRecordHelper.GetInt32(dr, "IndustryStatus");
            industry.CreateTime       = DataRecordHelper.GetDateTime(dr, "CreateTime");
            industry.CreateUser       = DataRecordHelper.GetInt32(dr, "CreateUser");
            industry.UpdateTime       = DataRecordHelper.GetDateTime(dr, "UpdateTime");
            industry.UpdateUser       = DataRecordHelper.GetInt32(dr, "UpdateUser");
            industry.SetSerializerData(CommonDataProvider.PopulateSerializerDataIDataRecord(dr));
            return(industry);
        }
Exemple #7
0
        public static void UpdateDateAndOpenChartForm(string code, Form Owner, bool NewWindow)
        {
            YahooDataManager ydm = new YahooDataManager();

            ydm.CacheRoot = FormulaHelper.Root + "Cache";
            CommonDataProvider cdp = new CommonDataProvider(ydm);

            if (mCurrentChartForm == null || NewWindow)
            {
                mCurrentChartForm           = new ChartForm();
                mCurrentChartForm.MdiParent = Owner;
                mCurrentChartForm.Show();
                FormList.Add(mCurrentChartForm);
            }

            mCurrentChartForm.m_code = code;
            mCurrentChartForm.om.SaveObject(mCurrentChartForm.m_code);
            ((ChartWinControl)mCurrentChartForm.om.Canvas).ShowChart(cdp);
            mCurrentChartForm.Activate();
            mCurrentChartForm.om.LoadObject(code);
        }
        public static Product PopulateProductFromIDataReader(IDataReader dr)
        {
            Product product = new Product();

            product.ProductID       = DataRecordHelper.GetInt32(dr, "ProductID");
            product.ProductCode     = DataRecordHelper.GetString(dr, "ProductCode");
            product.ProductName     = DataRecordHelper.GetString(dr, "ProductName");
            product.ProductDesc     = DataRecordHelper.GetString(dr, "ProductDesc");
            product.ProductAbstract = DataRecordHelper.GetString(dr, "ProductAbstract");
            product.ProductContent  = DataRecordHelper.GetString(dr, "ProductContent");
            product.BrandID         = DataRecordHelper.GetInt32(dr, "BrandID");
            product.ProductKeywords = DataRecordHelper.GetString(dr, "ProductKeywords");
            product.ProductStatus   = (ComponentStatus)DataRecordHelper.GetInt32(dr, "ProductStatus");
            product.DisplayOrder    = DataRecordHelper.GetInt32(dr, "DisplayOrder");
            product.CreateTime      = DataRecordHelper.GetDateTime(dr, "CreateTime");
            product.CreateUser      = DataRecordHelper.GetInt32(dr, "CreateUser");
            product.UpdateTime      = DataRecordHelper.GetDateTime(dr, "UpdateTime");
            product.UpdateUser      = DataRecordHelper.GetInt32(dr, "UpdateUser");
            product.SetSerializerData(CommonDataProvider.PopulateSerializerDataIDataRecord(dr));
            return(product);
        }
Exemple #9
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = (CommonDataProvider)htHistorical[Code];

            if (cdp == null)
            {
                YahooDataManager ydm = new YahooDataManager();
                ydm.StartTime      = this.StartTime;
                ydm.EndTime        = this.EndTime;
                ydm.CacheRoot      = FormulaHelper.Root + "Cache";
                cdp                = (CommonDataProvider)ydm[Code, Count];
                htHistorical[Code] = cdp;
            }
            DataPacket dp = (DataPacket)htPacket[Code];

            if (dp != null)
            {
                cdp.Merge(dp);
            }
            return(cdp);
        }
Exemple #10
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = (CommonDataProvider)ddm[Code, Count];

            if (!cdp.HasData)
            {
                EasyStockChartDataFeed df = new EasyStockChartDataFeed();
                try
                {
                    byte[] bs = df.BinaryHistory(Code, true);
                    if (bs != null)
                    {
                        cdp.LoadBinary(bs);
                        DBDataManager.UpdateForNewSymbol(Code, cdp, Config.SaveInServerDataManager);
                    }
                }
                catch
                {
                }
            }
            return(cdp);
        }
Exemple #11
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = new CommonDataProvider(this);
            DataRow            dr  = DB.GetFirstRow("select * from CompanyInfo where TickerSymbolID='" + Code + "'");

            if (dr != null)
            {
                cdp.SetStringData("Code", dr["Symbol"].ToString());
                cdp.SetStringData("Name", dr["CompanyName"].ToString());
                cdp.SetStringData("Exchange", dr["Exchange"].ToString());

                DataTable dt = DB.GetDataTable(
                    "SELECT S.SessionNUM, S.SessionDate, Q.StockOpen, Q.StockHigh, Q.StockLow, Q.StockClose, Q.StockVolume" +
                    "	FROM StockQuotes Q "+
                    "			INNER JOIN Sessions S ON Q.SessionNUM = S.SessionNUM "+
                    "	WHERE Q.TickerSymbolId='"+ Code + "' ORDER BY Q.SessionNUM");
                double[] OPEN   = new double[dt.Rows.Count];
                double[] HIGH   = new double[dt.Rows.Count];
                double[] LOW    = new double[dt.Rows.Count];
                double[] CLOSE  = new double[dt.Rows.Count];
                double[] VOLUME = new double[dt.Rows.Count];
                double[] AMOUNT = new double[dt.Rows.Count];
                double[] DATE   = new double[dt.Rows.Count];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    OPEN[i]   = (double)dt.Rows[i]["StockClose"];
                    HIGH[i]   = (double)dt.Rows[i]["StockHigh"];
                    LOW[i]    = (double)dt.Rows[i]["StockLow"];
                    CLOSE[i]  = (double)dt.Rows[i]["StockClose"];
                    VOLUME[i] = (double)(int)dt.Rows[i]["StockVolume"];
                    DATE[i]   = ((DateTime)dt.Rows[i]["SessionDate"]).ToOADate();
                }
                cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
                return(cdp);
            }
            return(base.GetData(Code, Count));
        }
Exemple #12
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = new CommonDataProvider(this);

            cdp.SetStringData("Code", Code);
            string s = FormulaHelper.Root + "Data\\" + Code + ".xml";

            if (File.Exists(s))
            {
                DataSet ds = new DataSet();
                ds.ReadXml(s);
                if (ds.Tables.Count > 0)
                {
                    DataTable dt     = ds.Tables[0];
                    int       N      = dt.Rows.Count;
                    double[]  OPEN   = new double[N];
                    double[]  HIGH   = new double[N];
                    double[]  LOW    = new double[N];
                    double[]  CLOSE  = new double[N];
                    double[]  VOLUME = new double[N];
                    double[]  AMOUNT = new double[N];
                    double[]  DATE   = new double[N];

                    for (int i = 0; i < N; i++)
                    {
                        OPEN[i]   = double.Parse(dt.Rows[i]["Open"].ToString());
                        HIGH[i]   = double.Parse(dt.Rows[i]["High"].ToString());
                        LOW[i]    = double.Parse(dt.Rows[i]["Low"].ToString());
                        CLOSE[i]  = double.Parse(dt.Rows[i]["Close"].ToString());
                        VOLUME[i] = double.Parse(dt.Rows[i]["Volume"].ToString());
                        DATE[i]   = DateTime.Parse(dt.Rows[i]["Date"].ToString(), DateTimeFormatInfo.InvariantInfo).ToOADate();
                    }
                    cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
                    return(cdp);
                }
            }
            return(base.GetData(Code, Count));
        }
        private void btnDelete_Click(object sender, System.EventArgs e)
        {
            DBDataManager ddm = new DBDataManager();

            try
            {
                CommonDataProvider cdp = (CommonDataProvider)ddm[tbSymbol.Text];
                lMsg.Text = "Original data count :" + cdp.Count + "<br>";
                cdp.DeleteData(dpStart.Date, dpEnd.Date);
                lMsg.Text += "New data count : " + cdp.Count;
                string Filename = DBDataManager.GetHisDataFile(tbSymbol.Text);
                if (File.Exists(Filename))
                {
                    File.Delete(Filename);
                }
                Utils.UpdateRealtime(tbSymbol.Text, cdp);
                cdp.SaveBinary(Filename);
            }
            catch (Exception ex)
            {
                lMsg.Text = ex.Message;
            }
        }
Exemple #14
0
        public override IDataProvider GetData(string Code, int Count)
        {
            try
            {
                CommonDataProvider cdp = new CommonDataProvider(this);
                cdp.SetStringData("Code", Code);
                //	cdp.SetStringData("Name",dr["CompanyName"].ToString());
                //	cdp.SetStringData("Exchange",dr["Exchange"].ToString());

                DataTable dt        = DB.GetDataTable("SELECT top " + Count + " * from " + Code + "_1da order by tstamp desc");
                double[]  OPEN      = new double[dt.Rows.Count];
                double[]  HIGH      = new double[dt.Rows.Count];
                double[]  LOW       = new double[dt.Rows.Count];
                double[]  CLOSE     = new double[dt.Rows.Count];
                double[]  VOLUME    = new double[dt.Rows.Count];
                double[]  AMOUNT    = new double[dt.Rows.Count];
                double[]  DATE      = new double[dt.Rows.Count];
                double    LastClose = 0;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[dt.Rows.Count - 1 - i];
                    HIGH[i]   = ToSingle(dr["priceh"]);
                    LOW[i]    = ToSingle(dr["pricel"]);
                    CLOSE[i]  = ToSingle(dr["pricec"]);
                    OPEN[i]   = Math.Min(Math.Max(LOW[i], LastClose), HIGH[i]);
                    VOLUME[i] = 0;
                    DATE[i]   = ((DateTime)dr["tstamp"]).ToOADate();
                    LastClose = CLOSE[i];
                }
                cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
                return(cdp);
            }
            catch
            {
            }
            return(base.GetData(Code, Count));
        }
Exemple #15
0
        private void btnScan_Click(object sender, EventArgs e)
        {
            TreeNode node1 = this.tvFormula.SelectedNode;

            if (node1 != null)
            {
                string text1 = (string)node1.Tag;
                int    num1  = 0;
                if (text1 != null)
                {
                    text1 = text1 + this.GetParam();
                    FormulaBase     base1      = FormulaBase.GetFormulaByName(text1);
                    int             num2       = base1.DataCountAtLeast();
                    FileDataManager manager1   = new FileDataManager(null);
                    string[]        textArray1 = ListForm.Current.GetSymbolList();
                    ArrayList       list1      = new ArrayList();
                    this.pbScan.Maximum = textArray1.Length;
                    this.pbScan.Visible = true;
                    if (textArray1.Length > 0)
                    {
                        string[] textArray2 = textArray1;
                        for (int num4 = 0; num4 < textArray2.Length; num4++)
                        {
                            string             text2     = textArray2[num4];
                            CommonDataProvider provider1 = (CommonDataProvider)manager1[text2, num2];
                            FormulaPackage     package1  = base1.Run(provider1);
                            FormulaData        data1     = package1[package1.Count - 1];
                            if ((data1.Length > 0) && (data1.LASTDATA > 0))
                            {
                                list1.Add(text2);
                            }
                            num1++;
                            if (((num1 % 10) == 0) || (num1 == textArray1.Length))
                            {
                                this.pbScan.Value = num1;
                                double num5 = ((double)num1) / ((double)textArray1.Length);
                                this.lMsg.Text = num1.ToString() + "(" + num5.ToString("p2") + ")";
                                Application.DoEvents();
                                if ((num1 % 100) == 0)
                                {
                                    GC.Collect();
                                }
                            }
                        }
                    }
                    StockDB.LoadFolderRow(1, text1);
                    int num3 = StockDB.GetMaxFolderId();
                    if (list1.Count > 0)
                    {
                        this.pbScan.Maximum = list1.Count;
                        num1 = 0;
                        IEnumerator enumerator1 = list1.GetEnumerator();
                        try
                        {
                            while (enumerator1.MoveNext())
                            {
                                StockDB.LoadFolderRelRow(enumerator1.Current, num3);
                                num1++;
                                if ((num1 % 100) == 0)
                                {
                                    this.pbScan.Value = num1;
                                    Application.DoEvents();
                                }
                            }
                        }
                        finally
                        {
                            IDisposable disposable1 = enumerator1 as IDisposable;
                            if (disposable1 != null)
                            {
                                disposable1.Dispose();
                            }
                        }
                    }
                    StockDB.ResetFolderDatabase();
                    ListForm.Current.FolderId = num3;
                    return;
                }
            }
            MessageBox.Show("Please select a condition!");
        }
        private void btnMerge_Click(object sender, System.EventArgs e)
        {
            string[] Keys = { "OPEN", "HIGH", "LOW", "CLOSE", "VOLUME", "DATE", "ADJCLOSE" };
            string[] ss   = tbCSVData.Text.Trim().Split('\n');

            int DateIndex   = 0;
            int TickerIndex = -1;

            string[] ssHeader;
            string   DateFormat;

            GetFormatInfo(ref DateIndex, ref TickerIndex, out ssHeader, out DateFormat);

            SortedList slAllSymbol = new SortedList(Comparer.Default);
            SortedList slOneSymbol;

            char r = GetSeperator();

            for (int i = cbHasHeader.Checked?1:0; i < ss.Length; i++)
            {
                string[] sss = ss[i].Trim().Split(r);
                try
                {
                    string Ticker = tbSymbol.Text;
                    if (TickerIndex >= 0)
                    {
                        Ticker = sss[TickerIndex];
                    }
                    slOneSymbol = (SortedList)slAllSymbol[Ticker];
                    if (Ticker == "")
                    {
                        throw new Exception("Symbol can't be empty!");
                    }
                    if (slOneSymbol == null)
                    {
                        slOneSymbol         = new SortedList(Comparer.Default);
                        slAllSymbol[Ticker] = slOneSymbol;
                    }

                    slOneSymbol[DateTime.ParseExact(sss[DateIndex].Trim(),
                                                    DateFormat,
                                                    DateTimeFormatInfo.InvariantInfo)
                    ] = sss;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message + ";" + sss[DateIndex] + ";" + DateFormat);
                }
            }

            lMsg.Text = "";
            DBDataManager ddm = new DBDataManager();

            try
            {
                foreach (string s in slAllSymbol.Keys)
                {
                    slOneSymbol = (SortedList)slAllSymbol[s];
                    double[][] ds = new double[7][];
                    for (int i = 0; i < ds.Length; i++)
                    {
                        ds[i] = new double[slOneSymbol.Count];
                        for (int j = 0; j < ds[i].Length; j++)
                        {
                            ds[i][j] = double.NaN;
                        }
                    }

                    for (int i = 0; i < slOneSymbol.Count; i++)
                    {
                        ds[5][i] = ((DateTime)slOneSymbol.GetKey(i)).ToOADate();
                        for (int j = 0; j < ssHeader.Length; j++)
                        {
                            if (j != DateIndex && j != TickerIndex)
                            {
                                int k = Array.IndexOf(Keys, ssHeader[j].ToUpper());
                                if (k >= 0)
                                {
                                    string[] sss = (string[])slOneSymbol.GetByIndex(i);
                                    ds[k][i] = double.Parse(sss[j]);
                                }
                            }
                        }
                        for (int j = 0; j < ds.Length; j++)
                        {
                            if (double.IsNaN(ds[j][i]))
                            {
                                ds[j][i] = ds[3][i];
                            }
                        }
                    }

                    CommonDataProvider cdp      = (CommonDataProvider)ddm[s];
                    CommonDataProvider cdpDelta = new CommonDataProvider(null);
                    cdpDelta.LoadBinary(ds);

                    lMsg.Text += "Symbol:" + s + "; Original data count :" + cdp.Count + "; Merge data count : " + cdpDelta.Count + "; ";
                    cdp.Merge(cdpDelta);
                    lMsg.Text += "New data count : " + cdp.Count + "<br>";
                    Impersonate.ChangeToAdmin();
                    Utils.UpdateRealtime(s, cdp);
                    cdp.SaveBinary(DBDataManager.GetHisDataFile(s));
                }
            }
            catch (Exception ex)
            {
                lMsg.Text = ex.Message;
            }
        }
        public CommonDataProvider GetDataFromString(string s)
        {
            string[]  ss = s.Trim().Split('\n');
            ArrayList al = new ArrayList();

            for (int i = 0; i < ss.Length; i++)
            {
                ss[i] = ss[i].Trim();
                if (!ss[i].StartsWith("<!--") && ss[i] != "")
                {
                    al.Add(ss[i]);
                }
            }

            int N = al.Count;

            double[] CLOSE  = new double[N];
            double[] OPEN   = new double[N];
            double[] HIGH   = new double[N];
            double[] LOW    = new double[N];
            double[] VOLUME = new double[N];
            double[] DATE   = new double[N];

            string Code     = null;
            string Name     = null;
            string Exchange = null;

            DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
            NumberFormatInfo   nfi  = NumberFormatInfo.InvariantInfo;

            for (int i = 0; i < N; i++)
            {
                string[] sss = ((string)al[i]).Split(',');
                int      j   = i;         //N-i-1;
                DATE[j]   = DateTime.ParseExact(sss[1], "yyyyMMdd", dtfi).ToOADate();
                OPEN[j]   = ToDoubleDef(sss[2], 0, nfi);
                HIGH[j]   = ToDoubleDef(sss[3], 0, nfi);
                LOW[j]    = ToDoubleDef(sss[4], 0, nfi);
                CLOSE[j]  = ToDoubleDef(sss[5], 0, nfi);
                VOLUME[j] = ToDoubleDef(sss[6], 0, nfi);
                Code      = sss[0];
                if (string.Compare(Code, "PRN", true) == 0)
                {
                    Code = "PRNN";
                }
                if (sss.Length > 7)
                {
                    Name = sss[7];
                }
                if (sss.Length > 8)
                {
                    Exchange = sss[8];
                }
            }

            CommonDataProvider cdp = new CommonDataProvider(this);

            if (Code != null)
            {
                cdp.SetStringData("Code", Code);
            }
            if (Name != null)
            {
                cdp.SetStringData("Name", Name);
            }
            if (Exchange != null)
            {
                cdp.SetStringData("Exchange", Exchange);
            }
            cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
            return(cdp);
        }
        public override IDataProvider GetData(string Code, int Count)
        {
            Code = Code.Trim();
            Hashtable          htList = GetSymbolListHashtable();
            string             s      = (string)htList[Code];
            CommonDataProvider cdpn   = new CommonDataProvider(this);


            byte[]   bs = new byte[] {};
            string[] ss = null;

            if (s != null)
            {
                ss = s.Split(',');
                if (ss[3] != "")
                {
                    string r = (string)htList[ss[3]];
                    if (r != null)
                    {
                        ss = r.Split(',');
                    }
                }
                if (Count > 0)
                {
                    // Load data from file
                    bs = LoadHisDataFromFile(Code, Count * DataPacket.PacketByteSize);
                    if (DownloadRealTimeQuote)
                    {
                        try
                        {
                            DataPacket dp = DataPacket.DownloadFromYahoo(Code);

                            if (dp != null && !dp.IsZeroValue)
                            {
                                bs = CommonDataProvider.MergeOneQuote(bs, dp);
                            }
                        }
                        catch
                        {
                        }
                    }

                    cdpn.LoadByteBinary(bs);

                    // Update data from yahoo
                    if (AutoYahooToDB)
                    {
                        string   FileName = GetHisDataFile(Code);
                        DateTime d        = new DateTime(1900, 1, 1);
                        try
                        {
                            d = File.GetLastWriteTime(FileName);                            // GetLastAccessTime(FileName);
                        }
                        catch
                        {
                        }
                        DateTime d1 = DateTime.Now.Date;
                        DateTime d2 = d.Date;
                        TimeSpan ts = d1 - d2;
                        if (ts.TotalDays > 0)
                        {
                            YahooDataManager   ydm      = new YahooDataManager();
                            CommonDataProvider cdpDelta = (CommonDataProvider)ydm[Code, ts.Days + 5];
                            cdpDelta.Adjusted = false;
                            if (cdpDelta.Count > 0)
                            {
                                double[] dd1 = cdpDelta["DATE"];
                                double[] dd2 = cdpn["DATE"];
                                if (cdpn.Count == 0 || (int)dd2[dd2.Length - 1] < (int)dd1[dd1.Length - 1])
                                {
                                    cdpn.Merge(cdpDelta);
                                    Impersonate.ChangeToAdmin();
                                    Utils.UpdateRealtime(Code, cdpn);
                                }
                            }
                            cdpn.SaveBinary(FileName);
                        }
                    }
                }
            }
            else
            {
                try
                {
                    // Download data from yahoo
                    if (AutoYahooToDB)
                    {
                        YahooDataManager ydm = new YahooDataManager();
                        cdpn = (CommonDataProvider)ydm[Code];
                        if (cdpn.Count > 0)
                        {
                            UpdateForNewSymbol(Code, cdpn, true);
                        }
                        else
                        {
                            throw new Exception("Invalid Quote : " + Code);
                        }
                    }
                    else
                    {
                        cdpn.LoadByteBinary(bs);
                    }
                }
                catch (Exception e)
                {
                    Tools.Log(e.Message);
                    cdpn.LoadByteBinary(bs);
                }
            }
            //cdpn = TrimToEndTime(cdpn);

            cdpn.SetStringData("Code", Code);
            if (ss != null && ss.Length > 2)
            {
                cdpn.SetStringData("Code", ss[0]);
                cdpn.SetStringData("Name", ss[1]);
                cdpn.SetStringData("Exchange", ss[2]);
            }
            return(cdpn);
        }
Exemple #19
0
        static public bool ImportEod(DataClientBase dcb, string Username, string Password, DateTime StartTime, DateTime EndTime, string Exchanges)
        {
            if (FuncMsg == null)
            {
                FuncMsg = "Importing end of day data, Data Feed = " + dcb +
                          ";StartTime=" + StartTime.ToString("yyyy-MM-dd") + ";EndTime=" + EndTime.ToString("yyyy-MM-dd") +
                          ";Exchanges=" + Exchanges;
                FuncStartTime = DateTime.Now;
                try
                {
                    int             Days    = 0;
                    int             Records = 0;
                    DataManagerBase dmb     = Utils.GetDataManager(Config.DefaultDataManager);

                    Hashtable ht = new Hashtable();
                    if (DataFeedAvailable(dcb, Username, Password))
                    {
                        int LocalMergeMax = 100000;
                        int LocalMerge    = 0;
                        for (DateTime D = StartTime; D <= EndTime; D = D.AddDays(1))
                        {
                            Msg = "Downloading end of day data " + D.ToString("yyyy-MM-dd");
                            DataPacket[] dps = dcb.GetEodData(Exchanges, null, D);
                            Days++;
                            if (dps != null)
                            {
                                foreach (DataPacket dp in dps)
                                {
                                    CommonDataProvider cdp = (CommonDataProvider)ht[dp.Symbol];
                                    if (cdp == null)
                                    {
                                        cdp           = CommonDataProvider.Empty;
                                        ht[dp.Symbol] = cdp;
                                    }
                                    LocalMerge++;
                                    Records++;
                                    cdp.Merge(dp);
                                }
                            }
                            if (LocalMerge < LocalMergeMax && D != EndTime)
                            {
                                continue;
                            }

                            if (ht.Count != 0)
                            {
                                int i = 0;
                                foreach (string s in ht.Keys)
                                {
                                    try
                                    {
                                        Msg = "Importing end of day data " + (++i) + "/" + ht.Count;
                                        CommonDataProvider cdp = (CommonDataProvider)ht[s];
                                        dmb.UpdateEod(s, cdp);
                                        if ((i % 10) == 0)
                                        {
                                            GC.Collect();                                             //avoid hosting recolloect the web application
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Msg = e.ToString();
                                        Tools.Log("ImportEod:" + s + ":" + e.Message);
                                    }
                                }

                                ht.Clear();
                                LocalMerge = 0;
                            }
                        }
                        Msg = "Update success , total " + Days + " days , and " + Records + " records";
                        return(Records != 0);
                    }
                }
                finally
                {
                    FuncMsg = null;
                }
            }
            return(false);
        }
Exemple #20
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = new CommonDataProvider(this);

            string FileName = FormulaHelper.Root + "Data\\" + Code + ".csv";

            if (File.Exists(FileName))
            {
                try
                {
                    string s = "";
                    using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        using (StreamReader sr = new StreamReader(fs))
                            s = sr.ReadToEnd();
                    }


                    string[]  ss = s.Trim().Split('\n');
                    ArrayList al = new ArrayList();
                    for (int i = 0; i < ss.Length; i++)
                    {
                        string r = ss[i].Trim();
                        if (r != "")
                        {
                            al.Add(r);
                        }
                    }

                    int      N      = al.Count;
                    double[] CLOSE  = new double[N];
                    double[] OPEN   = new double[N];
                    double[] HIGH   = new double[N];
                    double[] LOW    = new double[N];
                    double[] VOLUME = new double[N];
                    double[] DATE   = new double[N];

                    DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
                    NumberFormatInfo   nfi  = NumberFormatInfo.InvariantInfo;
                    for (int i = 0; i < N; i++)
                    {
                        string[] sss = ((string)al[i]).Split(',');
                        int      j   = N - 1 - i;
                        DATE[j]   = DateTime.ParseExact(sss[0], "yyyy-MM-dd H:mm", dtfi).ToOADate();
                        OPEN[j]   = double.Parse(sss[2]);
                        HIGH[j]   = double.Parse(sss[3]);
                        LOW[j]    = double.Parse(sss[4]);
                        CLOSE[j]  = double.Parse(sss[5]);
                        VOLUME[j] = double.Parse(sss[6]);;
                    }

                    cdp.SetStringData("Code", Code);
                    cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
                    return(cdp);
                }
                catch
                {
                }
            }
            return(CommonDataProvider.Empty);
        }
Exemple #21
0
        protected void btnOK_Click(object sender, System.EventArgs e)
        {
            //Create a Formula namespace
            FormulaSpace fms = new FormulaSpace("FML");

            //Create a Formula program , set Formula name and script code on the fly
            FormulaProgram fp = new FormulaProgram();

            fp.Name = tbFormulaName.Text;
            fp.Code = tbProgramScript.Text;

            //Add the script program to the Formula namespace
            fms.Programs.Add(fp);

            //Add parameters to Formula program
            for (int i = 1; i < 5; i++)
            {
                if (Request.Form["tbParamName" + i] != "")
                {
                    fp.Params.Add(new FormulaParam(
                                      Request.Form["tbParamName" + i],
                                      float.Parse(Request.Form["tbDefValue" + i]),
                                      float.Parse(Request.Form["tbMinValue" + i]),
                                      float.Parse(Request.Form["tbMaxValue" + i])));
                }
            }

            try
            {
                //Compile the Formula script on the fly
                Assembly    a  = fms.CompileInMemory(HttpRuntime.BinDirectory);
                FormulaBase fb = FormulaBase.GetFormulaByName(a, fms.Name + "." + fp.Name);

                //Create YahooDataManager , Get stock data from yahoo.
                YahooDataManager ydm = new YahooDataManager();
                ydm.CacheRoot = HttpRuntime.AppDomainAppPath + "Cache\\";
                CommonDataProvider DataProvider = (CommonDataProvider)ydm[tbCode.Text];

                //Create financial chart instance
                FormulaChart fc = new FormulaChart();
                fc.AddArea("MAIN", 3);
                fc.AddArea(fb);
                fc.DataProvider = DataProvider;
                fc.SetSkin(Config.DefaultSkin);


                //Show the temp image just created
                lChart.Text = "<img src=ImageFromCache.aspx?CacheId=" + fc.SaveToImageStream(440, 440, ImageFormat.Png, 0, 0) + ">";
            }
            catch (FormulaErrorException fee)
            {
                //Show the compile result if the script has some errors
                lChart.Text = "<font color=red>";
                foreach (System.CodeDom.Compiler.CompilerError ce in fee.ces)
                {
                    FormulaProgram fpa = fms.GetProgramByLineNum(ce.Line);
                    if (fpa != null)
                    {
                        fpa.AdjustErrors(ce);
                        lChart.Text += string.Format("Name:{0} line:{1} column:{2} error:{3} {4}<br>", fpa.Name, ce.Line, ce.Column, ce.ErrorNumber, ce.ErrorText);
                    }
                }
                lChart.Text += "</font>";
            }
        }
Exemple #22
0
        static public string MergeData(string Symbol, string TextData, string DataFormat, string DateFormat, char Separator, bool HasHeader)
        {
            string[] Keys = { "OPEN", "HIGH", "LOW", "CLOSE", "VOLUME", "DATE", "ADJCLOSE" };
            string[] ss   = TextData.Trim().Split('\n');

            int DateIndex   = 0;
            int TickerIndex = -1;

            string[] ssHeader;
            //string DateFormat;
            GetFormatInfo(DataFormat, ref DateIndex, ref TickerIndex, out ssHeader, ref DateFormat);

            SortedList slAllSymbol = new SortedList(Comparer.Default);
            SortedList slOneSymbol;

            //char r = GetSeperator();

            for (int i = HasHeader?1:0; i < ss.Length; i++)
            {
                string[] sss = ss[i].Trim().Split(Separator);
                try
                {
                    string Ticker = Symbol;                    //tbSymbol.Text;
                    if (TickerIndex >= 0)
                    {
                        Ticker = sss[TickerIndex];
                    }
                    slOneSymbol = (SortedList)slAllSymbol[Ticker];
                    if (Ticker == "")
                    {
                        throw new Exception("Symbol can't be empty!");
                    }
                    if (slOneSymbol == null)
                    {
                        slOneSymbol         = new SortedList(Comparer.Default);
                        slAllSymbol[Ticker] = slOneSymbol;
                    }

                    slOneSymbol[DateTime.ParseExact(sss[DateIndex].Trim(),
                                                    DateFormat,
                                                    DateTimeFormatInfo.InvariantInfo)
                    ] = sss;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message + ";" + sss[DateIndex] + ";" + DateFormat);
                }
            }

            string          Msg = "";
            DataManagerBase dmb = Utils.GetDefaultDataManager();

            try
            {
                foreach (string s in slAllSymbol.Keys)
                {
                    slOneSymbol = (SortedList)slAllSymbol[s];
                    double[][] ds = new double[7][];
                    for (int i = 0; i < ds.Length; i++)
                    {
                        ds[i] = new double[slOneSymbol.Count];
                        for (int j = 0; j < ds[i].Length; j++)
                        {
                            ds[i][j] = double.NaN;
                        }
                    }

                    for (int i = 0; i < slOneSymbol.Count; i++)
                    {
                        ds[5][i] = ((DateTime)slOneSymbol.GetKey(i)).ToOADate();
                        for (int j = 0; j < ssHeader.Length; j++)
                        {
                            if (j != DateIndex && j != TickerIndex)
                            {
                                int k = Array.IndexOf(Keys, ssHeader[j].ToUpper());
                                if (k >= 0)
                                {
                                    string[] sss = (string[])slOneSymbol.GetByIndex(i);
                                    ds[k][i] = double.Parse(sss[j]);
                                }
                            }
                        }
                        for (int j = 0; j < ds.Length; j++)
                        {
                            if (double.IsNaN(ds[j][i]))
                            {
                                ds[j][i] = ds[3][i];
                            }
                        }
                    }

                    CommonDataProvider cdp      = (CommonDataProvider)dmb[s];
                    CommonDataProvider cdpDelta = new CommonDataProvider(null);
                    cdpDelta.LoadBinary(ds);

                    Msg += "Symbol:" + s + "; Original data count :" + cdp.Count + "; Merge data count : " + cdpDelta.Count + "; ";
                    cdp.Merge(cdpDelta);
                    Msg += "New data count : " + cdp.Count + "<br>";
                    Impersonate.ChangeToAdmin();
                    dmb.SaveData(s, cdp, false);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return(Msg);
        }
Exemple #23
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            int    Height = 800;
            int    Width  = 600;
            Bitmap B;

            try
            {
                long Start = DateTime.Now.Ticks;

                ExchangeIntraday ei        = null;
                DateTime         StartTime = DateTime.Today.AddMonths(-6);
                DateTime         EndTime   = DateTime.Today;

                string Param = Request.QueryString["Span"];
                if (Param != null && Param != "")
                {
                    DataCycle dc;
                    if (Param.Length > 2)
                    {
                        dc = DataCycle.Parse(Param);
                    }
                    else
                    {
                        dc = new DataCycle(DataCycleBase.MONTH, Tools.ToIntDef(Param, 6));
                    }
                    StartTime = EndTime - dc;
                    //StartTime = EndTime.AddMonths(-Tools.ToIntDef(Param,6));
                }

                //Create financial chart instance
                FormulaChart fc = new FormulaChart();

                string Main = Request.QueryString["Main"];
                if (Main == null || Main == "")
                {
                    fc.AddArea("MAIN", 3);
                }
                else
                {
                    fc.AddArea(Main, 3);
                }

                string QuoteCode = Request.QueryString["Code"];
                if (QuoteCode == null)
                {
                    QuoteCode = "";
                }

                DataManagerBase dmb;
                Param = Request.QueryString["Provider"];
                if (Param == null)
                {
                    Param = "";
                }
                if (string.Compare(Param, "DB", true) == 0)
                {
                    //Create DBDataManager , Get stock data from sql server.
                    dmb = new DBDataManager();
                    ((DBDataManager)dmb).AutoYahooToDB =
                        Request.QueryString["His"] != "0" && Config.AutoYahooToDB == 1;
                    if (Request.QueryString["RT"] == "1")
                    {
                        ((DataManagerBase)dmb).DownloadRealTimeQuote = true;
                    }
                }
                else if (Param == "" || string.Compare(Param, "Yahoo", true) == 0)
                {
                    //Create YahooDataManager , Get stock data from yahoo.
                    dmb = new YahooDataManager();
                    ((YahooDataManager)dmb).CacheRoot = HttpRuntime.AppDomainAppPath + "Cache\\";
                    if (Config.IncludeTodayQuote == 1)
                    {
                        ((DataManagerBase)dmb).DownloadRealTimeQuote = true;
                    }
                }
                else
                {
                    string ManagerName = "WebDemos." + Param + "DataManager";
                    Type   t           = Type.GetType(ManagerName);
                    if (t == null)
                    {
                        throw new Exception(ManagerName + " not found!");
                    }
                    dmb = (DataManagerBase)Activator.CreateInstance(t);
                    if (dmb is IntraDataManagerBase)
                    {
                        ei = ExchangeIntraday.GetExchangeIntraday(Utils.GetExchange(QuoteCode));
                        ((CacheDataManagerBase)dmb).CacheTimeSpan = TimeSpan.FromMilliseconds(Config.IntradayCacheTime * 1000);
                        //((CacheDataManagerBase)dmb).EnableFileCache = false;

                        StartTime = ei.GetCurrentTradingDay();
                        EndTime   = StartTime.AddSeconds(3600 * 24 - 1);
                        QuoteCode = Utils.GetPart1(QuoteCode);
                    }
                    dmb.EndTime   = Utils.ToDateDef(Request.QueryString["End"], EndTime);
                    dmb.StartTime = Utils.ToDateDef(Request.QueryString["Start"], StartTime);
                }

                int MainIndex = 0;

                if (Config.SymbolCase == "Upper")
                {
                    QuoteCode = QuoteCode.ToUpper();
                }
                else if (Config.SymbolCase == "Lower")
                {
                    QuoteCode = QuoteCode.ToLower();
                }

                string[] QuoteCodes = QuoteCode.Split(',');
                string   Over       = "";
                QuoteCode = QuoteCodes[0];
                for (int i = 1; i < QuoteCodes.Length; i++)
                {
                    if (Over != "")
                    {
                        Over += ";";
                    }
                    Over += "Compare(" + QuoteCodes[i] + ")";
                }

                Param = Request.QueryString["IND"];
                string[] Inds = null;
                if (Param != null && Param != "")
                {
                    Inds = Param.Split(';');
                }

                //Set stock chart size
                Param = Request.QueryString["Size"];
                try
                {
                    if (Param != null && Param != "")
                    {
                        int i = Param.IndexOf('*');
                        if (i > 0)
                        {
                            Width  = int.Parse(Param.Substring(0, i));
                            Height = int.Parse(Param.Substring(i + 1));
                        }
                        else
                        {
                            Width  = int.Parse(Param);
                            Height = Width * 3 / 4;
                            if (Inds != null && Inds.Length > 1)
                            {
                                Height += Height / 5 * (Inds.Length - 2);
                            }
                            Height += 36;
                        }
                    }
                }
                catch
                {
                }

                CommonDataProvider DataProvider = (CommonDataProvider)dmb[QuoteCode];
                if (DataProvider == null)
                {
                    throw new Exception(QuoteCode + " not found!");
                }
                if (dmb is IntraDataManagerBase)
                {
                    fc.FixedTime = object.Equals(Request.QueryString["Fix"], "1");
                    if (fc.FixedTime)
                    {
                        DataProvider.IntradayInfo = ei;
                    }
                }

                if (DataProvider.Count == 0)
                {
                    throw new Exception("No data found!");
                }
                fc[MainIndex].Formulas[0].Name = QuoteCode;

                //Add MA lines to main stock view
                Param = Request.QueryString["MA"];
                if (Param != null && Param != "")
                {
                    foreach (string s in Param.Split(';'))
                    {
                        if (s != "")
                        {
                            fc[MainIndex].AddFormula("FML.MA(" + s + ")");
                        }
                    }
                }

                //Add EMA lines to main stock view
                Param = Request.QueryString["EMA"];
                if (Param != null && Param != "")
                {
                    foreach (string s in Param.Split(';'))
                    {
                        if (s != "")
                        {
                            fc[MainIndex].AddFormula("FML.EMA(" + s + ")");
                        }
                    }
                }

                //Add override lines to main stock view
                Param = Request.QueryString["OVER"];
                if (Param != null && Param != "")
                {
                    if (Over != "")
                    {
                        Param = Param + ";" + Over;
                    }
                }
                else
                {
                    Param = Over;
                }

                if (dmb is IntraDataManagerBase)
                {
                    string s = DataProvider.GetStringData("LastPrice");
                    if (s != null && s != "")
                    {
                        double d = double.Parse(s);
                        s = "DotLine(" + d.ToString("f2") + ")";
                        if (Param != null && Param != "")
                        {
                            Param += ";" + s;
                        }
                        else
                        {
                            Param = s;
                        }
                    }
                }

                if (Param != null && Param != "")
                {
                    //foreach(string s in Param.Split(';'))
                    string[] ss = Param.Split(';');
                    for (int i = 0; i < ss.Length; i++)
                    {
                        string s = ss[i].ToUpper();
                        if (s != "")
                        {
                            if (s == "AreaBB")
                            {
                                fc[MainIndex].InsertFormula(0, "FML." + s);
                            }
                            else
                            {
                                fc[MainIndex].AddFormula("FML." + s);
                            }
                        }
                    }
                }

                //Add indicators to stock chart
                if (Inds != null)
                {
                    foreach (string s in Inds)
                    {
                        if (s != "")
                        {
                            int k = s.IndexOf("{U}");
                            if (k > 0)
                            {
                                fc.InsertArea(MainIndex, "FML." + s.Substring(0, k));
                                MainIndex++;
                            }
                            else
                            {
                                fc.AddArea("FML." + s);
                            }
                        }
                    }
                }

                //Apply build-in stock chart skin
                Param = Request.QueryString["Skin"];
                if (Param == null || Param == "")
                {
                    Param = Config.DefaultSkin;
                }
                FormulaSkin fs = FormulaSkin.GetSkinByName(Param);
                if (fs != null)
                {
                    if (Config.YAxisFormat != "")
                    {
                        fs.AxisY.Format = Config.YAxisFormat;
                    }

                    if (Config.ShowXAxisInLastArea)
                    {
                        fs.ShowXAxisInLastArea = true;
                    }

                    fc.SetSkin(fs);
                }

                try
                {
                    fc.LatestValueType = (LatestValueType)Enum.Parse(typeof(LatestValueType), Config.LatestValueType, true);
                }
                catch
                {
                }

                //Add compare line to other stocks
                Param = Request.QueryString["COMP"];
                if (Param != null && Param != "")
                {
                    foreach (string s in Param.Split(';', ','))
                    {
                        if (s != "")
                        {
                            fc[MainIndex].AddFormula("COMPARE(" + s + ")");
                        }
                    }
                    fc[MainIndex].AxisY.ShowAsPercent = true;
                    fc[MainIndex].AxisY.Format        = "p1";
                    fc.LatestValueType = LatestValueType.None;
                }

                //Set stock chart time period
                fc.EndTime             = Utils.ToDateDef(Request.QueryString["End"], EndTime);
                fc.StartTime           = Utils.ToDateDef(Request.QueryString["Start"], StartTime);
                DataProvider.DataCycle = DataCycle.Parse(Request.QueryString["Cycle"]);

                //Set X-Axis format
                string XFormat = Request.QueryString["XFormat"];
                if (XFormat != null && XFormat != "")
                {
                    fc.AxisXFormat = XFormat;
                    fc.AllXFormats = null;
                }

                //Set Y-Axis format
                string YFormat = Request.QueryString["YFormat"];
                if (YFormat != null && YFormat != "")
                {
                    fc.AxisYFormat = YFormat;
                }

                //Set X-Axis cycle
                string XCycle = Request.QueryString["XCycle"];
                if (XCycle != null && XCycle != "")
                {
                    fc.DataCycle = DataCycle.Parse(XCycle);
                }

                //Set render type : Bar , Candle or Line
                Param = Request.QueryString["Type"];
                if (Param != null && Param != "")
                {
                    StockRenderType srt;
                    if (Param.Length == 1)
                    {
                        srt = (StockRenderType)int.Parse(Param);
                    }
                    else
                    {
                        srt = (StockRenderType)Enum.Parse(typeof(StockRenderType), Param, true);
                    }
                    fc[MainIndex].StockRenderType = srt;
                }

                //Set Scale type : Normal or Log
                Param = Request.QueryString["Scale"];
                if (Param != null && Param != "")
                {
                    ScaleType st;
                    if (Param.Length == 1)
                    {
                        st = (ScaleType)int.Parse(Param);
                    }
                    else
                    {
                        st = (ScaleType)Enum.Parse(typeof(ScaleType), Param, true);
                    }
                    fc[MainIndex].AxisY.Scale = st;
                }

                //Bottom margin
                Param = Request.QueryString["BMargin"];
                if (Param != null && Param != "")
                {
                    fc[MainIndex].BottomMargin = Tools.ToDoubleDef(Param, 0);
                }

                //Bind stock data
                fc.DataProvider = DataProvider;

                for (int i = 1; i < fc[MainIndex].FormulaDataArray.Count; i++)
                {
                    if (fc[MainIndex][i].ParentFormula.FormulaName.StartsWith("COMPARE"))
                    {
                        FormulaAxisY fay = fc[MainIndex].AddNewAxisY(AxisPos.Left);
                        FormulaData  fd  = fc[MainIndex][i];
                        fd.Transform  = Transform.Normal;
                        fd.AxisYIndex = 1;
                        break;
                    }
                }

                fc[MainIndex].AxisY.MajorTick.ShowLine = Config.ShowMainAreaLineY;
                fc[MainIndex].AxisX.MajorTick.ShowLine = Config.ShowMainAreaLineX;

                //Set indicator line width
                Param = Request.QueryString["Width"];
                if (Param != null && Param != "")
                {
                    float LineWidth = float.Parse(Param);
                    for (int i = 0; i < fc.Areas.Count; i++)
                    {
                        fc[i].LinePen.Width = LineWidth;
                    }
                }
                fc[MainIndex].AxisY.AutoMultiply = false;

                if (Request.QueryString["SV"] == "0")
                {
                    fc.ShowValueLabel = false;
                }
                fc.StickRenderType = Config.StickRenderType;

                Rectangle Rect = new Rectangle(0, 0, Width, Height);
                Param = Request.QueryString["Layout"];
                if (Param == null || Param == "")
                {
                    Param = "Default";
                }
                string[] Layouts = Param.Split(';', ',');
                Layout   L       = Layout.ParseString(Config.Read(Layouts[0] + "Layout", "ChartRect=(0,0,0,0)"), Rect);    //,DataProvider);
                for (int j = 1; j < Layouts.Length; j++)
                {
                    L.Merge(Layout.ParseString(Config.Read(Layouts[j] + "Layout", "ChartRect=(0,0,0,0)"), Rect));                //,DataProvider));
                }
                L.CompanyName = Config.CompanyName;
                L.URL         = Config.URL;
                L.StartTick   = Start;
                fc.Rect       = L.ChartRect;
                B             = fc.GetBitmap(Width, Height, fc.Rect);
                Graphics g = Graphics.FromImage(B);
                L.Render(g, Rect, fc);


                int X = Tools.ToIntDef(Request.QueryString["X"], 0);
                int Y = Tools.ToIntDef(Request.QueryString["Y"], 0);
                if (X > 0 && Y > 0)
                {
                    fc.Rect            = new Rectangle(0, 0, Width, Height);
                    fc.ShowCursorLabel = true;
                    fc.DrawCursor(g, X, Y);
                }
            }
            catch (Exception ex)
            {
                B = new Bitmap(Width, Height);
                Graphics g = Graphics.FromImage(B);

                g.Clear(Color.White);

                StringFormat sf = new StringFormat();
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;
                g.DrawString(ex.Message, new Font("Verdana", 12),
                             new SolidBrush(Color.FromArgb(196, Color.Black)), new Rectangle(0, 0, Width, Height), sf);
            }

            //Create stock image to Bitmap
            Response.ContentType = "Image/" + Config.ImageFormat;

            //Create chart stream
            MemoryStream ms = new MemoryStream();

            if (Config.ImageFormat == "Gif")
            {
                Type tQuantization = (Type)Application["Quantization"];
                if (tQuantization == null)
                {
                    Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies();
                    foreach (Assembly a in ass)
                    {
                        if (a.FullName.StartsWith("ImageQuantization"))
                        {
                            tQuantization = a.GetType("ImageQuantization.OctreeQuantizer");
                        }
                    }
                    Application["Quantization"] = tQuantization;
                }

                if (tQuantization != null)
                {
                    object[] os;
                    if (Config.TransparentColor.IsEmpty)
                    {
                        os = new object[] { B, ms, Config.GifColors }
                    }
                    ;
                    else
                    {
                        os = new object[] { B, ms, Config.GifColors, Config.TransparentColor }
                    };

                    tQuantization.InvokeMember("Save",
                                               BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, os);
                }

                if (ms.Length == 0)
                {
                    B.Save(ms, ImageFormat.Png);
                }
            }
            else if (Config.ImageFormat == "Png")
            {
                B.Save(ms, ImageFormat.Png);
            }
            else if (Config.ImageFormat == "Jpeg")
            {
                B.Save(ms, ImageFormat.Jpeg);
            }

            //Output the chart stream to web browser
            ms.WriteTo(Response.OutputStream);
        }
Exemple #24
0
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            BindData();

            Tools.Log("CurrentFullName1:" + CurrentFullName);

            foreach (Assembly a in FormulaBase.SupportedAssemblies.Values)
            {
                Tools.Log("Assembly:" + a.FullName);
            }

            FormulaBase fb = FormulaBase.GetFormulaByName(CurrentFullName);

            Tools.Log("CurrentFullName2:" + CurrentFullName);

            if (fb != null)
            {
                Tools.Log(fb.FullName);
            }
            foreach (string s in Request.Form)
            {
                if (s.StartsWith("__Param"))
                {
                    fb.SetParam(s.Substring(7), Request.Form[s]);
                }
            }

            YahooDataManager ydm = new YahooDataManager();

            ydm.CacheRoot = HttpRuntime.AppDomainAppPath + "Cache\\";
            CommonDataProvider DataProvider = (CommonDataProvider)ydm[tbCode.Text];

            FormulaChart fc = new FormulaChart();

            fc.AddArea("MAIN", 2);
            if (CurrentProgram.IsMainView)
            {
                fc[0].AddFormula(fb);
            }
            else
            {
                fc.AddArea(fb);
            }
            fc.LatestValueType = LatestValueType.StockOnly;

            fc.SetSkin(Config.DefaultSkin);

            try
            {
                fc.DataProvider = DataProvider;
                FormulaData fdDate = DataProvider["DATE"];
                string      s      = tbCode.Text;
                if (fdDate.Length > 0)
                {
                    s += " (" + DateTime.FromOADate(fdDate[fdDate.Length - 1]).ToString("yyyy-MMM-dd", DateTimeFormatInfo.InvariantInfo) + ")";
                }

                fc[0].Formulas[0].Name          = s;
                fc[0].Formulas[0].TextInvisible = false;
                fc.StartTime = DateTime.Now.AddMonths(-8);
                fc.EndTime   = DateTime.Now;
            }
            catch (Exception ee)
            {
                Bitmap   b = new Bitmap(640, 480);
                Graphics g = Graphics.FromImage(b);
                g.FillRectangle(Brushes.WhiteSmoke, 0, 0, 640, 480);
                g.DrawRectangle(Pens.Black, 0, 0, 639, 479);
                g.DrawString(ee.Message, new Font("verdana", 10), Brushes.Red, 1, 1);
            }

            lChart.Text = "<img src=ImageFromCache.aspx?CacheId=" + fc.SaveToImageStream(640, 400, ImageFormat.Png, 0, 0) + ">";
        }
 private CommonDataProvider GetData(string symbol)
 {
     CommonDataProvider result;
     try
     {
         int num = 0;
         string b = "NAV";
         if (symbol == b || symbol == "SET")
         {
             DataTable dataTable = this.tds.Tables["TABLE"];
             num = dataTable.Rows.Count;
             double[] array = new double[num];
             double[] array2 = new double[num];
             double[] array3 = new double[num];
             double[] array4 = new double[num];
             double[] array5 = new double[num];
             double[] array6 = new double[num];
             double[] array7 = new double[num];
             DateTimeFormatInfo invariantInfo = DateTimeFormatInfo.InvariantInfo;
             NumberFormatInfo invariantInfo2 = NumberFormatInfo.InvariantInfo;
             double num2 = 0.0;
             for (int i = 0; i < num; i++)
             {
                 DataRow dataRow = dataTable.Rows[i];
                 string text = dataRow["sDate"].ToString();
                 DateTime dateTime;
                 DateTime.TryParse(string.Concat(new string[]
                 {
                     text.Substring(0, 4),
                     "/",
                     text.Substring(4, 2),
                     "/",
                     text.Substring(6, 2)
                 }), out dateTime);
                 if (symbol == b)
                 {
                     double.TryParse(dataRow["nmrNav"].ToString(), out num2);
                 }
                 else
                 {
                     double.TryParse(dataRow["nmrIndexVal"].ToString(), out num2);
                 }
                 array6[i] = dateTime.ToOADate();
                 array2[i] = double.Parse(num2.ToString(), invariantInfo2);
                 array3[i] = double.Parse(num2.ToString(), invariantInfo2);
                 array4[i] = double.Parse(num2.ToString(), invariantInfo2);
                 array[i] = double.Parse(num2.ToString(), invariantInfo2);
                 array5[i] = 0.0;
                 array7[i] = double.Parse(num2.ToString(), invariantInfo2);
             }
             CommonDataProvider commonDataProvider = new CommonDataProvider(this);
             commonDataProvider.DataCycle.CycleBase = DataCycleBase.TICK;
             commonDataProvider.LoadBinary(new double[][]
             {
                 array2,
                 array3,
                 array4,
                 array,
                 array5,
                 array6
             });
             StockList.StockInformation stockInformation = ApplicationInfo.StockInfo[symbol];
             if (array2.Length > 0)
             {
                 commonDataProvider.Prior = array2[0];
             }
             commonDataProvider.Ceiling = (double)stockInformation.Ceiling;
             commonDataProvider.Floor = (double)stockInformation.Floor;
             result = commonDataProvider;
             return result;
         }
         if (this.tds.Tables.Contains("TABLE"))
         {
             if (this.tds.Tables["TABLE"].Rows.Count > 0)
             {
                 num = this.tds.Tables["TABLE"].Rows.Count;
             }
             string text2 = string.Empty;
             decimal num3 = 0m;
             decimal num4 = 0m;
             decimal num5 = 0m;
             decimal num6 = 0m;
             decimal num7 = 0m;
             int num8 = 0;
             bool flag = false;
             if (num > 0 && this.tds.Tables.Contains("INFO") && this.tds.Tables["INFO"].Rows.Count > 0)
             {
                 text2 = this.tds.Tables["INFO"].Rows[0]["dtLastUpd"].ToString();
                 if (this.tds.Tables["TABLE"].Rows[0]["sDate"].ToString() != text2)
                 {
                     num++;
                     flag = true;
                     decimal.TryParse(this.tds.Tables["INFO"].Rows[0]["open_price1"].ToString(), out num3);
                     decimal.TryParse(this.tds.Tables["INFO"].Rows[0]["last_sale_price"].ToString(), out num4);
                     decimal.TryParse(this.tds.Tables["INFO"].Rows[0]["high_price"].ToString(), out num5);
                     decimal.TryParse(this.tds.Tables["INFO"].Rows[0]["low_price"].ToString(), out num6);
                     decimal.TryParse(this.tds.Tables["INFO"].Rows[0]["accvolume"].ToString(), out num7);
                 }
             }
             double[] array = new double[num];
             double[] array2 = new double[num];
             double[] array3 = new double[num];
             double[] array4 = new double[num];
             double[] array5 = new double[num];
             double[] array6 = new double[num];
             double[] array7 = new double[num];
             DateTimeFormatInfo invariantInfo = DateTimeFormatInfo.InvariantInfo;
             NumberFormatInfo invariantInfo2 = NumberFormatInfo.InvariantInfo;
             if (flag)
             {
                 DateTime dateTime;
                 DateTime.TryParse(string.Concat(new string[]
                 {
                     text2.Substring(0, 4),
                     "/",
                     text2.Substring(4, 2),
                     "/",
                     text2.Substring(6, 2)
                 }), out dateTime);
                 double num9 = double.Parse(num4.ToString(), invariantInfo2);
                 array6[num - 1] = dateTime.ToOADate();
                 array2[num - 1] = double.Parse(num3.ToString(), invariantInfo2);
                 array3[num - 1] = double.Parse(num5.ToString(), invariantInfo2);
                 array4[num - 1] = double.Parse(num6.ToString(), invariantInfo2);
                 array[num - 1] = num9;
                 array5[num - 1] = double.Parse(num7.ToString(), invariantInfo2);
                 array7[num - 1] = num9;
             }
             int count = this.tds.Tables["TABLE"].Rows.Count;
             for (int i = count - 1; i > -1; i--)
             {
                 DataRow dataRow = this.tds.Tables["TABLE"].Rows[i];
                 string text = dataRow["sDate"].ToString();
                 DateTime dateTime;
                 DateTime.TryParse(string.Concat(new string[]
                 {
                     text.Substring(0, 4),
                     "/",
                     text.Substring(4, 2),
                     "/",
                     text.Substring(6, 2)
                 }), out dateTime);
                 double num9 = double.Parse(dataRow["nmrClosingPrice"].ToString(), invariantInfo2);
                 array6[num8] = dateTime.ToOADate();
                 array2[num8] = double.Parse(dataRow["nmrOpenPrice1"].ToString(), invariantInfo2);
                 array3[num8] = double.Parse(dataRow["nmrHighPrice"].ToString(), invariantInfo2);
                 array4[num8] = double.Parse(dataRow["nmrLowPrice"].ToString(), invariantInfo2);
                 array[num8] = num9;
                 array5[num8] = double.Parse(dataRow["nmrDlVol"].ToString(), invariantInfo2);
                 array7[num8] = num9;
                 num8++;
             }
             CommonDataProvider commonDataProvider = new CommonDataProvider(this);
             commonDataProvider.DataCycle.CycleBase = DataCycleBase.TICK;
             commonDataProvider.LoadBinary(new double[][]
             {
                 array2,
                 array3,
                 array4,
                 array,
                 array5,
                 array6
             });
             StockList.StockInformation stockInformation = ApplicationInfo.StockInfo[symbol];
             commonDataProvider.Prior = 0.0;
             commonDataProvider.Ceiling = (double)stockInformation.Ceiling;
             commonDataProvider.Floor = (double)stockInformation.Floor;
             result = commonDataProvider;
             return result;
         }
     }
     catch
     {
     }
     result = CommonDataProvider.Empty;
     return result;
 }
        public override IDataProvider GetData(string Code, int Count)
        {
            try
            {
                CommonDataProvider cdp = new CommonDataProvider(this);
                DbParam[]          dps = new DbParam[] {
                    new DbParam("@Symbol", DbType.String, Code),
                    new DbParam("@Q1", DbType.DateTime, StartTime),
                    new DbParam("@Q2", DbType.DateTime, EndTime),
                };
                BaseDb bd = DB.Open(false);
                try
                {
                    DataTable dt    = bd.GetDataTable("select Price,Volume,QuoteTime from Intraday where Symbol=? and QuoteTime>=? and QuoteTime<=? order by QuoteTime", dps);
                    double    LastV = -1;
                    foreach (DataRow dr in dt.Rows)
                    {
                        double NowV = (double)dr["Volume"];
                        if (LastV >= 0)
                        {
                            if (NowV > LastV)
                            {
                                dr["Volume"] = NowV - LastV;
                            }
                            else
                            {
                                dr["Volume"] = (double)0;
                            }
                        }
                        LastV = NowV;
                    }

                    dps[2].Value = ((DateTime)dps[1].Value).AddSeconds(-1);
                    dps[1].Value = ((DateTime)dps[1].Value).AddDays(-30);
                    DataRow drr = bd.GetFirstRow("select Price from Intraday where Symbol=? and QuoteTime>=? and QuoteTime<=? order by QuoteTime desc", dps);

                    if (dt.Rows.Count > 0)
                    {
                        cdp.SetStringData("LastTradeTime", ((DateTime)dt.Rows[dt.Rows.Count - 1]["QuoteTime"]).ToString());
                    }
                    if (drr != null)
                    {
                        cdp.SetStringData("LastPrice", drr[0].ToString());
                    }
                    SetStrings(cdp, Code);

                    if (dt.Rows.Count == 0)
                    {
                        dt.Rows.Add(new object[] { double.NaN, 0, StartTime });
                    }
                    double[] CLOSE  = new double[dt.Rows.Count];
                    double[] VOLUME = new double[dt.Rows.Count];
                    double[] DATE   = new double[dt.Rows.Count];

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        CLOSE[i]  = ToDouble(dt.Rows[i]["Price"]);
                        VOLUME[i] = ToDouble(dt.Rows[i]["Volume"]);
                        DATE[i]   = ((DateTime)dt.Rows[i]["QuoteTime"]).ToOADate();
                    }
                    cdp.LoadBinary("CLOSE", CLOSE);
                    cdp.LoadBinary("DATE", DATE);
                    cdp.LoadBinary("VOLUME", VOLUME);
                }
                finally
                {
                    bd.Close();
                }
                return(cdp);
            }
            catch
            {
            }
            return(base.GetData(Code, Count));
        }