Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            try
            {
                string filename = txt_path.Text;
                openFileDialog1.FileName = filename;
                string[]  filelines = File.ReadAllLines(filename);
                ArrayList chartData = new ArrayList();
                string[]  fileName  = openFileDialog1.SafeFileName.Split('.');

                ArrayList usersCharts = DataBase.getUsersChartList(User.curUsername);
                if (usersCharts.Contains(fileName[0]))
                {
                    MessageBox.Show("You allready have " + fileName[0] + " in your chart list!");
                    return;
                }

                foreach (String line in filelines)
                {
                    string[] words = line.Split(',');
                    try
                    {
                        DateTime myDate = DateTime.ParseExact(words[0], "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);
                        DateTime myTime = DateTime.ParseExact(words[1], "HHmmss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);

                        myDate = myDate.Add(myTime.TimeOfDay);

                        Double open  = Convert.ToDouble(words[2]);
                        Double high  = Convert.ToDouble(words[3]);
                        Double low   = Convert.ToDouble(words[4]);
                        Double close = Convert.ToDouble(words[5]);
                        chartData.Add(new Candle(myDate, high, low, open, close));
                    }
                    catch
                    {
                        MessageBox.Show("File format is invalid. Error in line: \n" + line);
                        return;
                    }
                }

                progressBar1.Show();
                if (DataBase.addNewChart(chartData, fileName[0], User.curUsername))
                {
                    cmbbx_importedCharts.Items.Add(fileName[0]);
                    frm_mainForm frm = ((frm_mainForm)Application.OpenForms["frm_mainForm"]);
                    frm.BuildMenuItems();
                }

                progressBar1.Hide();;
            }
            catch (Exception ex)
            {
                MessageBox.Show("File error: " + ex.Message);
                progressBar1.Hide();
            }
        }
Ejemplo n.º 2
0
        private void btn_delete_Click(object sender, EventArgs e)
        {
            if (cmbbx_importedCharts.SelectedIndex == -1)
            {
                return;
            }
            if (DataBase.deleteChartData(cmbbx_importedCharts.SelectedItem.ToString(), User.curUsername))
            {
                MessageBox.Show(cmbbx_importedCharts.SelectedItem.ToString() + " deleted from the chart list");
                cmbbx_importedCharts.Items.Clear();
                ArrayList ImportedCharts = DataBase.getUsersImportedChartList(User.curUsername);
                foreach (String symbolName in ImportedCharts)
                {
                    cmbbx_importedCharts.Items.Add(symbolName);
                    frm_mainForm frm = ((frm_mainForm)Application.OpenForms["frm_mainForm"]);
                    frm.BuildMenuItems();
                }
            }

            cmbbx_importedCharts.SelectedIndex = -1;
        }