Ejemplo n.º 1
0
        ///This section includes the code for implementing the data set and its tables.
        ///

        //Creates a DataTable from input method CreateDataTableFromFile
        //Converts From DataTable object to String Array for a 2D array of any size.
        //Outputs
        public void GetTableData(out DataTable dt, out string[,] results)
        {
            DataSet_Processing instance = new DataSet_Processing();                     /////GOT HUNGUP HERE BADLY! READ MORE.

            dt      = instance.CreateDataTableFromFile("somename", _tableFileLocation); //TODO come back and use name field
            results = new string[dt.Rows.Count, dt.Columns.Count];
            for (int index = 0; index < dt.Rows.Count; index++)
            {
                for (int columnIndex = 0; columnIndex < dt.Columns.Count; columnIndex++)
                {
                    results[index, columnIndex] = dt.Rows[index][columnIndex].ToString();
                }
            }
        }
Ejemplo n.º 2
0
        public void ReadTextFile()
        {
            string line;

            try
            {
                this.InputText.Clear();
                //Pass the file path and file name to the StreamReader constructor
                StreamReader sr = new StreamReader("C:\\temp\\Jamaica.txt");

                //Read the first line of text
                line = sr.ReadLine();

                //Continue to read until you reach end of file
                while (line != null)
                {
                    //write the lie to console window
                    //this.InputText.SelectionStart = InputText.Text.Length;

                    this.InputText.AppendText(line);
                    this.InputText.AppendText(Environment.NewLine);

                    //Read the next line
                    line = sr.ReadLine();
                }

                //close the file
                sr.Close();
                String             dt;
                DataSet_Processing instance = new DataSet_Processing();
                instance.CreateDataTableFromFile(testFileLocation, testFileLocation);  ///create the table, this is expecting a table name, too
            }
            catch (Exception e)
            {
                MessageBox.Show("Exception: " + e.Message);
            }
            finally
            {
                MessageBox.Show("Executing finally block.");
            }
        }
Ejemplo n.º 3
0
        private void RunExcelProcess()
        {
            Excel.Application oXL;
            Excel._Workbook   oWB;
            Excel._Worksheet  oSheet;
            Excel.Range       oRng;

            try
            {
                //Start Excel and get Application object.
                oXL         = new Excel.Application();
                oXL.Visible = true;

                //Get a new workbook.
                oWB    = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
                oSheet = (Excel._Worksheet)oWB.ActiveSheet;

                //Add table headers going cell by cell.
                oSheet.Cells[1, 1] = "Test 1";
                oSheet.Cells[1, 2] = "Response 1";
                oSheet.Cells[1, 3] = "Full Name";
                oSheet.Cells[1, 4] = "Salary";

                //Format A1:D1 as bold, vertical alignment = center.
                oSheet.get_Range("A1", "D1").Font.Bold         = true;
                oSheet.get_Range("A1", "D1").VerticalAlignment =
                    Excel.XlVAlign.xlVAlignCenter;

                /*
                 * // Create an array to multiple values at once.
                 * string[,] saNames = new string[5, 2];
                 *
                 * saNames[0, 0] = "John";
                 * saNames[0, 1] = "Smith";
                 * saNames[1, 0] = "Tom";
                 * saNames[1, 1] = "Brown";
                 * saNames[2, 0] = "Sue";
                 * saNames[2, 1] = "Thomas";
                 * saNames[3, 0] = "Jane";
                 * saNames[3, 1] = "Jones";
                 * saNames[4, 0] = "Adam";
                 * saNames[4, 1] = "Johnson";
                 */

                //Fill A2:B6 with an array of values (First and Last Names).
                //oSheet.get_Range("A2", "B6").Value2 = saNames;

                //attempt to fill excel with DT object.
                DataTable dt;
                string[,] results;
                DataSet_Processing dataset1 = new DataSet_Processing();
                dataset1.tableFileLocation = testFileList.ElementAt(0);
                dataset1.GetTableData(out dt, out results);


                oSheet.get_Range("A" + dt.Columns.Count, "B" + dt.Rows.Count).Value2 = results;

                DataSet_Processing dataset2 = new DataSet_Processing();
                dataset2.tableFileLocation = testFileList.ElementAt(1);
                dataset2.GetTableData(out dt, out results);

                oSheet.get_Range("C" + dt.Columns.Count, "D" + dt.Rows.Count).Value2 = results;

                /*
                 * //Fill C2:C6 with a relative formula (=A2 & " " & B2).
                 * oRng = oSheet.get_Range("C2", "C6");
                 * oRng.Formula = "=A2 & \" \" & B2";
                 *
                 * //Fill D2:D6 with a formula(=RAND()*100000) and apply format.
                 * oRng = oSheet.get_Range("D2", "D6");
                 * oRng.Formula = "=RAND()*100000";
                 * oRng.NumberFormat = "$0.00";
                 *
                 * //AutoFit columns A:D.
                 * oRng = oSheet.get_Range("A1", "D1");
                 * oRng.EntireColumn.AutoFit();
                 *
                 * //Manipulate a variable number of columns for Quarterly Sales Data.
                 * DisplayQuarterlySales(oSheet);
                 */
                //Make sure Excel is visible and give the user control
                //of Microsoft Excel's lifetime.
                oXL.Visible     = true;
                oXL.UserControl = true;
            }
            catch (Exception theException)
            {
                String errorMessage;
                errorMessage = "Error: ";
                errorMessage = String.Concat(errorMessage, theException.Message);
                errorMessage = String.Concat(errorMessage, " Line: ");
                errorMessage = String.Concat(errorMessage, theException.Source);

                MessageBox.Show(errorMessage, "Error");
            }
        }