-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryForm.cs
More file actions
93 lines (91 loc) · 2.24 KB
/
QueryForm.cs
File metadata and controls
93 lines (91 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Created by SharpDevelop.
* User: YLIN68
* Date: 1/21/2016
* Time: 10:32 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using Oracle.ManagedDataAccess.Client;
using System.Data;
namespace msql
{
/// <summary>
/// Description of QueryForm.
/// </summary>
public partial class QueryForm : Form
{
string db,user,password;
DataTable dt=new DataTable();
System.Data.OracleClient.OracleDataAdapter da;
System.Data.OracleClient.OracleConnection conn;
public QueryForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
public void Run(string db,string user,string password,string sql)
{
this.db=db;
this.user=user;
this.password=password;
while(sql.Trim().EndsWith(";"))
{
sql=sql.Trim().Substring(0,sql.Trim().Length-1);
}
tbSql.Text=sql;
Text=Text+" - "+db;
conn=new System.Data.OracleClient.OracleConnection(String.Format("Data Source={0};User Id={1};Password={2}",db,user,password));
Show();
btRun.PerformClick();
}
void BtRunClick(object sender, EventArgs e)
{
string sql=tbSql.Text;
while(sql.Trim().EndsWith(";"))
{
sql=sql.Trim().Substring(0,sql.Trim().Length-1);
}
tbSql.Text=sql;
if(sql=="") return;
numPage.Value=1;
try
{
if(conn.State!=ConnectionState.Open) conn.Open();
if(da!=null) da.Dispose();
da=new System.Data.OracleClient.OracleDataAdapter(sql,conn);
dt.Clear();
dt.Columns.Clear();
dt.DefaultView.Sort="";
da.Fill((int)((numPage.Value-1)*numRecords.Value),(int)numRecords.Value,dt);
dataGridView1.DataSource=dt;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message ,"Error");
}
}
void BtCloseClick(object sender, EventArgs e)
{
Close();
}
void NumPageValueChanged(object sender, EventArgs e)
{
dt.Clear();
da.Fill((int)((numPage.Value-1)*numRecords.Value),(int)numRecords.Value,dt);
}
void QueryFormFormClosing(object sender, FormClosingEventArgs e)
{
if(da!=null) da.Dispose();
if(conn!=null) conn.Dispose();
}
}
}