示例#1
0
        private 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],
                                      Request.Form["tbDefValue" + i],
                                      Request.Form["tbMinValue" + i],
                                      Request.Form["tbMaxValue" + i], FormulaParamType.Double));
                }
            }

            try
            {
                //Compile the Formula script on the fly
                Assembly    a  = fms.CompileInMemory();
                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.PriceLabelFormat = "{CODE}";
                fc.LatestValueType  = LatestValueType.Custom;
                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 = fee.ToHtml();
            }
        }
示例#2
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>";
            }
        }