Esempio n. 1
0
 private void ProceduresList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (ProceduresList.SelectedItem != null)
     {
         string tableName = ProceduresList.SelectedItem.ToString();
         try
         {
             string routineName = ProceduresList.SelectedItem.ToString().Substring(2);
             string query       = "select p.parameter_name " +
                                  "from information_schema.routines r left join information_schema.parameters p on r.specific_schema = p.specific_schema and r.specific_name = p.specific_name " +
                                  "where r.routine_schema not in ('pg_catalog', 'information_schema') AND p.parameter_mode = 'IN' AND r.routine_name = \'" + routineName + "\' order by p.ordinal_position;";
             dt = conn.execute(query);
             if (dt.Rows.Count == 0)
             {
                 string prefix = ProceduresList.SelectedItem.ToString().Substring(0, 2);
                 query = (prefix == "F_" ? "SELECT * FROM " : "CALL ") + routineName + "();";
                 Console.WriteLine(query);
                 dt = conn.execute(query);
                 DbGrid.ItemsSource = dt.DefaultView;
                 selTableName       = tableName;
             }
             else
             {
                 List <string> headers = new List <string>();
                 for (int i = 0; i < dt.Rows.Count; ++i)
                 {
                     headers.Add(dt.Rows[i].Field <string>(0));
                 }
                 ParametersWindow insert = new ParametersWindow(conn, dt, DbGrid, headers, ProceduresList.SelectedItem.ToString(), "ROUTINE");
                 insert.ShowDialog();
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex);
         }
     }
 }
Esempio n. 2
0
 private void AddRecordBtn_Click(object sender, RoutedEventArgs e)
 {
     if (selTableName != null)
     {
         try
         {
             List <string> headers = new List <string>();
             foreach (var column in DbGrid.Columns)
             {
                 headers.Add(column.Header.ToString());
             }
             ParametersWindow insert = new ParametersWindow(conn, dt, DbGrid, headers, selTableName, "INSERT");
             insert.ShowDialog();
             string query = "SELECT * FROM \"" + selTableName + "\"";
             dt = conn.execute(query);
             DbGrid.ItemsSource = dt.DefaultView;
         }
         catch (Exception ex)
         {
             MessageBox.Show("Ошибка при вставке!\n" + ex.Message, "Ошибка");
         }
     }
 }