Exemplo n.º 1
0
        //--------------------------------------------------------------------------------------

        public void RunAllyearsDB()
        {
            if (WSDB_Open)
            {
                TablenameDialog tableDialog  = new TablenameDialog();
                string          runtablename = "";
                DataTable       DT           = new DataTable();
                // get the table name
                if (tableDialog.ShowDialog(WSim.DbConnection, false, false) == System.Windows.Forms.DialogResult.OK)
                {
                    runtablename = tableDialog.Tablename;
                    if (tableDialog.isNewTablename)
                    {
                        WSim.CreateNewDataTable(runtablename);
                    }
                }
                if (runtablename != "")
                {
                    StatusLabel1.Text = "Running DB Simulation";

                    // Ok fill the data table with all teh relvant fields

                    // initialize a db simulation, turn control over to WaterSim_DB
                    WSim.Simulation_Initialize(runtablename, ScenarioNameTextBox.Text);
                    // Fetch all the Input fields
                    SetAllModelValues(WS_InputPanel.GetAllValues());

                    // run each year of simulation db
                    foreach (int year in WSim.simulationYears())
                    {
                        WSim.Simulation_NextYear();
                    }
                    // stop the simulation (which adds all data to data table
                    WSim.Simulation_Stop();
                    // OK I now have control, update the database
                    UniDataAdapter NewRawTableAdapter = new UniDataAdapter("Select * from " + dbTool.BracketIt(WSim.DbConnection.SQLServerType, runtablename) + ";", WSim.DbConnection);
                    NewRawTableAdapter.Fill(DT);
                    dbTableGridView.DataSource = DT;
                    StatusLabel1.Text          = "Done";

                    FetchTablenames();
                }
            }
            else
            {
                MessageBox.Show("A Database must first be opened");
                OpenDB();
            }
        }
Exemplo n.º 2
0
 private void testReadTableToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MyUniDbConnection != null)
     {
         TableDlg.dbConnect = MyUniDbConnection;
         if (TableDlg.ShowDialog() == DialogResult.OK)
         {
             string         TableName  = TableDlg.Tablename;
             UniDataAdapter TheAdapter = new UniDataAdapter("SELECT * FROM " + TableName + ";", MyUniDbConnection);
             DataTable      TheTable   = new DataTable();
             TheAdapter.Fill(TheTable);
             dataGridViewTest.DataSource = TheTable;
         }
     }
 }
Exemplo n.º 3
0
 public DataTableCollection RunQueryMultipleResults(string sql)
 {
     try
     {
         UniCommand     sqlCommand     = new UniCommand(sql, uniConnection);
         DataTable      dataTable      = new DataTable();
         DataSet        ds             = new DataSet();
         UniDataAdapter sqlDataAdapter = new UniDataAdapter(sqlCommand);
         sqlDataAdapter.Fill(ds);
         return(ds.Tables);
     }
     catch (Exception e)
     {
         throw new Exception(string.Format("Error running SQL: [{0}]", sql), e);
     }
 }
Exemplo n.º 4
0
 public DataTable RunQueryDataTable(string sql)
 {
     try
     {
         UniCommand     sqlCommand     = new UniCommand(sql, uniConnection);
         DataTable      dataTable      = new DataTable();
         DataSet        ds             = new DataSet();
         UniDataAdapter sqlDataAdapter = new UniDataAdapter(sqlCommand);
         //sqlDataAdapter.Fill(dataTable, null); // Just pass the DataTable into the SqlDataAdapters Fill Method
         sqlDataAdapter.Fill(ds);
         return(ds.Tables[0]);
         //return dataTable;
     }
     catch (Exception e)
     {
         throw new Exception(string.Format("Error running SQL: [{0}]", sql), e);
     }
 }
Exemplo n.º 5
0
 private void ConfigTabControl_Selected(object sender, TabControlEventArgs e)
 {
     SourceComboBox.Text = config.sourceOptions?.FirstOrDefault(p => p.Key == "sourceType").Value;
     if (ConfigTabControl.SelectedIndex == 1) //Preview Tab Selected
     {
         PreviewDataGridView.DataSource = null;
         if (config.sourceOptions?.FirstOrDefault(p => p.Key == "sourceType").Value == "Base de datos")
         {
             var query = queryTextBox.Text;
             if (!String.IsNullOrEmpty(query))
             {
                 try
                 {
                     connection = new UniConnection(config.sourceOptions?.FirstOrDefault(p => p.Key == "connectionString").Value);
                     connection.Open();
                     UniCommand     cmd            = new UniCommand(query, connection);
                     UniDataAdapter uniDataAdapter = new UniDataAdapter(cmd);
                     DataSet        dataSet        = new DataSet("PreviewTable");
                     uniDataAdapter.Fill(dataSet, "PreviewTable");
                     PreviewDataGridView.DataSource = dataSet.Tables["PreviewTable"];
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("Ocurrió un error al ejecutar la consulta. Descripción del error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 finally
                 {
                     connection.Close();
                 }
             }
         }
         if (config.sourceOptions?.FirstOrDefault(p => p.Key == "sourceType").Value == "Ficheros Excel")
         {
             MessageBox.Show("Opción en desarrollo.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
             ConfigTabControl.SelectedTab = QueryTabPage;
         }
     }
 }
 public DataTable RunQueryDataTable(string sql)
 {
     try
     {
         UniCommand sqlCommand = new UniCommand(sql, uniConnection);
         DataTable dataTable = new DataTable();
         DataSet ds = new DataSet();
         UniDataAdapter sqlDataAdapter = new UniDataAdapter(sqlCommand);
         //sqlDataAdapter.Fill(dataTable, null); // Just pass the DataTable into the SqlDataAdapters Fill Method
         sqlDataAdapter.Fill(ds);
         return ds.Tables[0];
         //return dataTable;
     }
     catch (Exception e)
     {
         throw new Exception(string.Format("Error running SQL: [{0}]", sql), e);
     }
 }
 public DataTableCollection RunQueryMultipleResults(string sql)
 {
     try
     {
         UniCommand sqlCommand = new UniCommand(sql, uniConnection);
         DataTable dataTable = new DataTable();
         DataSet ds = new DataSet();
         UniDataAdapter sqlDataAdapter = new UniDataAdapter(sqlCommand);
         sqlDataAdapter.Fill(ds);
         return ds.Tables;
     }
     catch (Exception e)
     {
         throw new Exception(string.Format("Error running SQL: [{0}]", sql), e);
     }
 }