Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
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);
        }