Пример #1
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!");
        }
Пример #2
0
        public static void Scanning(object o)
        {
            ScanId          si  = (ScanId)o;
            FormulaBase     fb  = FormulaBase.GetFormulaByName("Scan." + si.Condition);
            DataManagerBase dmb = (DataManagerBase)Utils.GetDataManager(Config.DefaultDataManager);

            if (fb != null)
            {
                int N = fb.DataCountAtLeast();
                int M = N;
                if (Config.PrescanLoadToMemory)
                {
                    N = FormulaBase.MaxForAllScan;
                }

                string Where = "";
                if (si.Exchange != "")
                {
                    Where = " where Exchange = '" + si.Exchange + "'";
                }
                //DataTable dt = DB.GetDataTable("select QuoteCode from StockData"+Where);
                string[] ss = dmb.GetSymbolStrings(si.Exchange, null, null);
                if (ss != null)
                {
                    DB.DoCommand("update condition set Total=?,Scaned=0,StartTime=? where conditionId=?",
                                 new DbParam[] {
                        new DbParam("@Total", DbType.Int32, ss.Length),
                        new DbParam("@StartTime", DbType.DateTime, DateTime.Now),
                        new DbParam("@ConditionId", DbType.Int32, si.ConditionId)
                    });

                    int       i  = 0;
                    ArrayList al = new ArrayList();
                    try
                    {
                        foreach (string s in ss)
                        {
                            try
                            {
                                //ddm.AutoYahooToDB = false;
                                //ddm.DownloadRealTimeQuote = false;
                                IDataProvider idp = Admin.UpdatePreScan.GetDataProvider(dmb, s, N);
                                idp.MaxCount = M;
                                //IDataProvider idp = ddm[s,N];
                                if (Utils.VerifyVolumeAndDate(idp))
                                {
                                    FormulaPackage fp = fb.Run(idp);
                                    FormulaData    fd = fp[fp.Count - 1];
                                    if (fd.Length > 0)
                                    {
                                        if (fd.LASTDATA > 0)
                                        {
                                            al.Add(si.ConditionId + "," + s);
                                        }
                                    }
                                }
                                i++;
                                if ((i % 10) == 0)
                                {
                                    HttpRuntime.Cache[si.ConditionId] = i;
                                    if ((i % 100) == 0)
                                    {
                                        Thread.Sleep(1);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Tools.Log("Scanning:" + ex.Message);
                            }
                        }
                    }
                    finally
                    {
                        Utils.BulkInsert(al);
                    }

                    HttpRuntime.Cache[si.ConditionId] = ss.Length;
                    DB.DoCommand("update condition set Scaned=?,ResultCount=?,EndTime=? where ConditionId=" + si.ConditionId,
                                 new DbParam[] {
                        new DbParam("@Total", DbType.Int32, ss.Length),
                        new DbParam("@ResultCount", DbType.Int32, al.Count),
                        new DbParam("@EndDate", DbType.DateTime, DateTime.Now)
                    });
                }
            }
        }