Ejemplo n.º 1
0
        private void buttonLoad_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = "*.txt";
            openFileDialog1.Filter   = "Text Files|*.txt";
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            int start = openFileDialog1.FileName.LastIndexOf('\\');

            textBoxPath.Text = openFileDialog1.FileName.Substring(0, start + 1);
            string fileName = openFileDialog1.FileName.Substring(start);

            int upIndex = openFileDialog1.FileName.Substring(0, start).LastIndexOf('\\');

            textBoxOutput.Text = openFileDialog1.FileName.Substring(0, upIndex + 1);

            CommodityInfomation commodity = CommodityInfomation.CommodityOf(fileName);

            if (commodity == null)
            {
                textBoxDescription.Text = "Failed to get Commodity Information from " + openFileDialog1.FileName;
                return;
            }
            else
            {
                textBoxDescription.Text = string.Format("{0}\r\n", commodity);
            }

            SortedDictionary <ContractInfomation, QuoteCollection> theSortedQuotes = new SortedDictionary <ContractInfomation, QuoteCollection>();

            foreach (string filename in openFileDialog1.FileNames)
            {
                ContractInfomation theContract = commodity.ContractOf(filename.Substring(start));
                List <Quote>       items       = TextDataImporter.Import(filename);

                if (items == null)
                {
                    continue;
                }

                QuoteCollection quotes = new QuoteCollection(theContract, filename, RecordType.DayRecord, items);

                theSortedQuotes.Add(theContract, quotes);
            }

            quoteGroup = new GroupedQuoteCollection(commodity, theSortedQuotes);

            textBoxDescription.AppendText(String.Format("{0} Contracts: from {1} to {2}", theSortedQuotes.Count, theSortedQuotes.First().Value.Since, theSortedQuotes.Last().Value.Until));

            checkedListBoxMonths.Items.Clear();

            foreach (MonthCodes code in commodity.Months)
            {
                checkedListBoxMonths.Items.Add(code);
                checkedListBoxMonths.SetItemChecked(checkedListBoxMonths.Items.Count - 1, false);
            }
        }
Ejemplo n.º 2
0
        private void buttonLoadPobo_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = "*.da1";
            openFileDialog1.Filter   = "Pobo Day Files|*.da1";
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            int start = openFileDialog1.FileName.LastIndexOf('\\');

            int upIndex = openFileDialog1.FileName.Substring(0, start).LastIndexOf('\\');

            CommodityInfomation commodity = CommodityInfomation.CommodityOf(openFileDialog1.FileName.Substring(start));

            if (quoteGroup == null)
            {
                throw new Exception("Please import records from text files first.");
            }

            if (commodity == null)
            {
                textBoxDescription.Text = "Failed to get Commodity Information from " + openFileDialog1.FileName;
                return;
            }
            else if (commodity != quoteGroup.Commodity)
            {
                textBoxDescription.Text = "Different commodity: " + openFileDialog1.FileName;
                return;
            }
            else
            {
                textBoxDescription.Text = string.Format("{0}\r\n", commodity);
            }

            foreach (string filename in openFileDialog1.FileNames)
            {
                ContractInfomation theContract = commodity.ContractOf(filename.Substring(start));

                if (theContract.Month == 0 && (openFileDialog1.FileNames.Length > 1))
                {
                    continue;
                }

                List <Quote> items = PoboDataImporter.Import(filename, RecordType.DayRecord);

                if (items == null)
                {
                    continue;
                }

                QuoteCollection quotes = new QuoteCollection(theContract, filename, RecordType.DayRecord, items);

                quoteGroup.Group.Add(theContract, quotes);
            }
        }