Esempio n. 1
0
        public void ExecuteTask()
        {
            try
            {
                //log.WriteEntry("Start Price : " + index, EventLogEntryType.Information);
                bool bfirstTime = true;
                if ((ConfigurationManager.AppSettings["PriceAllowance"] ?? "") != "TRUE")
                {
                    return;
                }
                //log.WriteEntry("Start Price 2 : " + index, EventLogEntryType.Information);
                bool bHo = false, bHa = false, bLastHo = true, bLastHa = true;
                var sql = new SqlDb();
                while (ServiceStarted)
                {
                    var itv = interval;
                    bHo = Utils.InTradingTime(1);
                    bHa = Utils.InTradingTime(2);
                    if (!bHo && !bHa) itv = longInterval;
                    try
                    {
                        try
                        {
                            if (bLastHa && !bHa)
                            {

                                //update index to FC
                                var hnx = sql.GetHnxIndex();
                                if (hnx.Rows.Count > 0)
                                {
                                    sql.UpdateHnxIndex((DateTime)hnx.Rows[0]["TradeDate"], double.Parse(hnx.Rows[0]["PrevIndex"].ToString()), double.Parse(hnx.Rows[0]["CurrentIndex"].ToString()), double.Parse(hnx.Rows[0]["CurrentCount"].ToString()), double.Parse(hnx.Rows[0]["CurrentVolume"].ToString()), double.Parse(hnx.Rows[0]["CurrentValue"].ToString()));
                                }

                            }
                            bLastHa = bHa;
                        }
                        catch (Exception ex)
                        {
                            bLastHa = true;
                            log.WriteEntry("UpdateHNX : " + ex.ToString(), EventLogEntryType.Error);
                        }
                        try
                        {
                            if (bLastHo && !bHo)
                            {
                                //update index to FC
                                var hsx = sql.GetHsxIndex();
                                if (hsx.Rows.Count > 0)
                                {
                                    sql.UpdateHCMIndex((DateTime)hsx.Rows[0]["Date"], double.Parse(hsx.Rows[0]["PrevIndex"].ToString()), double.Parse(hsx.Rows[0]["Index1"].ToString()), double.Parse(hsx.Rows[0]["Quantity1"].ToString()), double.Parse(hsx.Rows[0]["Vol1"].ToString()), double.Parse(hsx.Rows[0]["Value1"].ToString()), double.Parse(hsx.Rows[0]["Index2"].ToString()), double.Parse(hsx.Rows[0]["Quantity2"].ToString()), double.Parse(hsx.Rows[0]["Vol2"].ToString()), double.Parse(hsx.Rows[0]["Value2"].ToString()), double.Parse(hsx.Rows[0]["Index3"].ToString()), double.Parse(hsx.Rows[0]["Quantity3"].ToString()), double.Parse(hsx.Rows[0]["Vol3"].ToString()), double.Parse(hsx.Rows[0]["Value3"].ToString()));
                                }
                            }

                            bLastHo = bHo;
                        }
                        catch (Exception ex)
                        {
                            bLastHa = true;
                            log.WriteEntry("UpdateHNX : " + ex.ToString(), EventLogEntryType.Error);
                        }
                        //log.WriteEntry("Start Price 3 : " + index, EventLogEntryType.Information);

                        UpdatePrice(1, bfirstTime);
                        UpdatePrice(2, bfirstTime);
                        UpdatePrice(9, bfirstTime);
                        UpdateKby();
                        bfirstTime = false;
                        //log.WriteEntry("Start Price 4 : " + index, EventLogEntryType.Information);

                    }
                    catch (Exception ex)
                    {
                        log.WriteEntry(ex.ToString(), EventLogEntryType.Error);
                    }
                    Thread.Sleep(itv);
                }
            }
            catch (Exception ex)
            {
                log.WriteEntry(ex.ToString(), EventLogEntryType.Error);
            }
            finally
            {
                Thread.CurrentThread.Abort();
            }
        }