Exemplo n.º 1
0
        private void tsbQuerySub_Click(object sender, EventArgs e)
        {
            TcpClient tcpClientQuote = new TcpClient();
            string    respxml        = null;
            Stopwatch stopWatch      = new Stopwatch();

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                tcpClientQuote.Connect(ConfigurationManager.AppSettings["QueryHost"], int.Parse(ConfigurationManager.AppSettings["QueryPort"]));
                if (tcpClientQuote.Connected)
                {
                    //TaiwanCalendar twC = new TaiwanCalendar();
                    //string tdate = twC.GetYear(DateTime.Today) + "/" + twC.GetMonth(DateTime.Today) + "/" + twC.GetDayOfMonth(DateTime.Today);
                    string ldate = PushUtils.GetTALastTradeDate(tcpClientQuote, int.Parse(ConfigurationManager.AppSettings["OneTryTime"]), int.Parse(ConfigurationManager.AppSettings["RetryTimes"]));
                    string param = string.Format(ConfigurationManager.AppSettings["QuerySubParam"], ldate);
                    stopWatch.Start();

                    respxml = PushUtils.QueryTA(tcpClientQuote, ConfigurationManager.AppSettings["QuerySubURL"] + "\x01" + param + "\x02",
                                                int.Parse(ConfigurationManager.AppSettings["OneTryTime"]), int.Parse(ConfigurationManager.AppSettings["RetryTimes"]));
                    stopWatch.Stop();
                    textBox1.Text = stopWatch.ElapsedMilliseconds.ToString();
                }
                tcpClientQuote.Close();
                tcpClientQuote = null;
                if (GD.stocklist == null)
                {
                    GD.stocklist = new SubStockList();
                }
                if (GD.bsSubStockList == null)
                {
                    GD.bsSubStockList = new BindingSource();
                }
                stopWatch.Restart();
                if (!string.IsNullOrEmpty(respxml))
                {
                    GD.stocklist.LoadList(respxml);
                }
                stopWatch.Stop();
                textBox2.Text = stopWatch.ElapsedMilliseconds.ToString();
                stopWatch.Restart();
                if (GD.stocklist.Count > 0)
                {
                    GD.bsSubStockList.DataSource = null;
                    GD.bsSubStockList.DataSource = GD.stocklist.Values;
                    dgvSubStockList.DataSource   = GD.bsSubStockList;

                    GD.stocklist.SaveToDB();
                }
                stopWatch.Stop();
                textBox3.Text = stopWatch.ElapsedMilliseconds.ToString();
            }
            catch (Exception ex)
            {
                GD.aplogger.Error(string.Format("Query Sub Stock exception {0}", ex.Message));
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemplo n.º 2
0
        public void LoadList(string xml)
        {
            string referdumm = "";

            this.Clear();
            TextReader sr = new StringReader(xml);
            XElement   xe = XElement.Load(sr);

            sr.Close();

            //SubStock item = null;

            /*var qitems = from qitem in xe.Descendants("NFSLISTS")
             *           select new
             *           {
             *               Symbol = qitem.Attribute("symb") == null ? "" : qitem.Attribute("symb").Value,
             *               SymbolName = qitem.Attribute("name") == null ? "" : qitem.Attribute("name").Value,
             *               Market = qitem.Attribute("mark") == null ? "" : qitem.Attribute("mark").Value,
             *               StartDate = qitem.Attribute("name") == null ? "" : qitem.Attribute("name").Value
             *               qitem.Element("NFSLIDURS").Element()
             *           };*/
            var qitems = from qitem in xe.Descendants("NFSLISTS")
                         select qitem;
            TcpClient tcpClientQuote = new TcpClient();
            string    ldate          = "";

            try
            {
                tcpClientQuote.Connect(ConfigurationManager.AppSettings["QueryHost"], int.Parse(ConfigurationManager.AppSettings["QueryPort"]));
                ldate = PushUtils.GetTALastTradeDate(tcpClientQuote, int.Parse(ConfigurationManager.AppSettings["OneTryTime"]), int.Parse(ConfigurationManager.AppSettings["RetryTimes"]));
            }
            catch (Exception ex)
            {
                GD.aplogger.Error(string.Format("SubStock loadlist TCP connect exception - {0}", ex.Message));
            }
            foreach (var qitem in qitems)
            {
                SubStock ss     = new SubStock();
                var      nitems = from nitem in qitem.Descendants("NFSLIDUR")
                                  select nitem;
                referdumm = "";
                foreach (var nitem in nitems)
                {
                    if (nitem.Attribute("duno") == null)
                    {
                        continue;
                    }
                    if (int.Parse(nitem.Attribute("duno").Value) == 0)
                    {
                        ss.StartDate = nitem.Attribute("duii").Value;
                        ss.StopDate  = nitem.Attribute("ducl").Value;
                    }
                    else if (int.Parse(nitem.Attribute("duno").Value) == 5)
                    {
                        ss.DebitDate = nitem.Attribute("duii").Value;
                    }
                    else if (int.Parse(nitem.Attribute("duno").Value) == 10)
                    {
                        ss.DrawDate = nitem.Attribute("duii").Value;
                    }
                    else if (int.Parse(nitem.Attribute("duno").Value) == 20)
                    {
                        ss.RefundDate = nitem.Attribute("duii").Value;
                    }
                    else if (int.Parse(nitem.Attribute("duno").Value) == 30)
                    {
                        ss.CouponDate = nitem.Attribute("duii").Value;
                    }
                    else if (int.Parse(nitem.Attribute("duno").Value) == 91)
                    {
                        referdumm = nitem.Attribute("dumm").Value;
                        //if (referdumm == null || int.Parse(referdumm) > 0)
                        //int result= 0;
                        decimal result = 0;
                        //if (!int.TryParse(referdumm, out result) || result == 0)
                        //     referdumm = null;
                        if (!decimal.TryParse(referdumm, out result) || result == 0)
                        {
                            referdumm = null;
                        }
                    }
                }
                ss.Symbol = qitem.Attribute("symb") == null ? "" : qitem.Attribute("symb").Value;
                string memo = qitem.Attribute("memo") == null ? "" : qitem.Attribute("memo").Value;
                ss.SymbolName = qitem.Attribute("name") == null ? "" : qitem.Attribute("name").Value;
                if (memo.IndexOf('(') >= 0)
                {
                    ss.Market     = memo.Substring(memo.IndexOf('(') + 1, memo.IndexOf(')') - memo.IndexOf('(') - 1);
                    ss.SymbolName = memo.Substring(0, memo.IndexOf('('));
                }
                ss.Share     = qitem.Attribute("shar") == null ? "" : qitem.Attribute("shar").Value;
                ss.TempRefer = string.IsNullOrEmpty(referdumm) ? qitem.Attribute("refe").Value : referdumm;
                if (DateTime.Today > DateTime.Parse(PushUtils.RepublicToAD(ss.DebitDate)))
                {
                    ss.Refer = qitem.Attribute("refe") == null ? "" : qitem.Attribute("refe").Value;
                }
                ss.Volumn   = qitem.Attribute("valu") == null ? "" : qitem.Attribute("valu").Value;
                ss.Txun     = qitem.Attribute("txun") == null ? "" : qitem.Attribute("txun").Value;
                ss.TAMarket = qitem.Attribute("mark") == null ? "" : qitem.Attribute("mark").Value;

                /*try{
                 *  tcpClientQuote.Connect(ConfigurationManager.AppSettings["QueryHost"], int.Parse(ConfigurationManager.AppSettings["QueryPort"]));
                 *  if (tcpClientQuote.Connected) {
                 *      ss.LastDeal = PushUtils.QueryTAStockRefer(tcpClientQuote, ss.Symbol, int.Parse(ConfigurationManager.AppSettings["OneTryTime"]), int.Parse(ConfigurationManager.AppSettings["RetryTimes"]));
                 *  }
                 * }catch (Exception ex) {
                 *  GD.aplogger.Error(string.Format("SubStock loadlist exception - {0}", ex.Message));
                 * }finally{
                 *  if (tcpClientQuote != null)
                 *      tcpClientQuote.Close();
                 * }*/

                //Add(ss.Symbol, ss);
                if (DateTime.Today > DateTime.Parse(PushUtils.RepublicToAD(ss.CouponDate)))
                {
                    ss = null;
                }
                else
                {
                    try
                    {
                        if (tcpClientQuote.Connected)
                        {
                            ss.LastDeal = PushUtils.QueryTAStockRefer(tcpClientQuote, ss.Symbol, ldate,
                                                                      int.Parse(ConfigurationManager.AppSettings["OneTryTime"]), int.Parse(ConfigurationManager.AppSettings["RetryTimes"]));
                        }
                    }
                    catch (Exception ex)
                    {
                        GD.aplogger.Error(string.Format("SubStock loadlist LastDeal exception - {0}", ex.Message));
                    }
                    Add(ss.Symbol, ss);
                }
            }//foreach
            if (tcpClientQuote != null)
            {
                tcpClientQuote.Close();
            }
        }