-
Notifications
You must be signed in to change notification settings - Fork 10
/
DataViewerForm.cs
90 lines (79 loc) · 3.12 KB
/
DataViewerForm.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SasHarness
{
public partial class DataViewerForm : Form
{
System.Data.OleDb.OleDbConnection connection = null;
public DataViewerForm(SasServer session)
{
InitializeComponent();
// init the OleDbConnection based on the Workspace ID
// Note that this requires that the Workspace handle has
// been added to the ObjectKeeper in SASObjectManager
string wsId = session.Workspace.UniqueIdentifier;
connection = new System.Data.OleDb.OleDbConnection("Provider=sas.iomprovider.1; SAS Workspace ID=" + wsId);
}
private void LoadBtn_Click(object sender, EventArgs e)
{
Cursor old = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
try
{
DataSet ds = new DataSet();
string where = "";
// Apply a filter to the result set if specified
if (!string.IsNullOrEmpty(txtFilter.Text))
{
where = String.Format("WHERE {0}", txtFilter.Text);
}
// Using SAS OLE DB provider to access the data
OleDbCommand command = new OleDbCommand(String.Format("select * from {0} {1}", txtData.Text, where), connection);
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
adapter.Fill(ds);
if (ds.Tables.Count > 0)
dgView.DataSource = ds.Tables[0];
else MessageBox.Show("No table found!");
this.Text = string.Format("{0} ({1})", txtData.Text, txtFilter.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error opening table");
}
finally
{
Cursor.Current = old;
}
}
private void btnOK_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// This adds a ROW number to the grid, so you can see how many records
/// are shown in the data set.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnRowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
var grid = sender as DataGridView;
var rowIdx = (e.RowIndex + 1).ToString();
var centerFormat = new StringFormat()
{
// right alignment might actually make more sense for numbers
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);
e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat);
}
}
}