Exemple #1
0
        private void btnSelectFileToImport_Click(object sender, EventArgs e)
        {
            var fileName = string.Empty;

            using (var x = new OpenFileDialog()
            {
                Filter = "*.xlsx|*.xlsx|*.xls|*.xls", CheckFileExists = true
            })
            {
                if (x.ShowDialog() == DialogResult.OK)
                {
                    fileName             = x.FileName;
                    lblSelectedFile.Text = fileName;

                    EnableSaveButtons(false);
                    valuesList    = null;
                    valuesDataset = null;
                }
                else
                {
                    return;
                }
            }

            if (!string.IsNullOrWhiteSpace(fileName))
            {
                _runner = new CodeRunner <List <DataValue> >()
                {
                    ShowSplash   = true,
                    CodeToExcute = new GetValuesFromReport()
                    {
                        fileName = lblSelectedFile.Text, SelectedProject = CurrentProjectName
                    },
                    AsyncCallBack = (q) =>
                    {
                        if (q == null)
                        {
                            return;
                        }

                        EnableSaveButtons(true);

                        valuesList    = q;
                        valuesDataset = q.ToDataset();

                        if (dataGridView1.InvokeRequired)
                        {
                            dataGridView1.Invoke(
                                new refreshDisplay((s) => {
                                ShowGridDisplayPort(s.Tables[0]);
                                //dataGridView1.DataSource = s.Tables[0];
                            }),
                                valuesDataset);
                            return;
                        }
                        ShowGridDisplayPort(q.ToDataset().Tables[0]);
                        //dataGridView1.DataSource = q.ToDataset().Tables[0];
                    }
                };
                _runner.Execute();
            }
        }