JoinView Test
时间:2011-04-16 来源:leslie116
#region to datatable
public DataTable ToTable()
{
return this.ToTable(null, new string[0]);
}
public DataTable ToTable(string tableName)
{
return this.ToTable(tableName, new string[0]);
}
public DataTable ToTable(string tableName, params string[] columnNames)
{
if (columnNames == null)
{
throw new ArgumentNullException("columnNames");
}
DataTable table = new DataTable();
table.Locale = this.Table.Locale;
table.CaseSensitive = this.Table.CaseSensitive;
table.TableName = (tableName != null) ? tableName : this.Table.TableName;
table.Namespace = this.Table.Namespace;
table.Prefix = this.Table.Prefix;
if (columnNames.Length == 0)
{
columnNames = new string[this.FieldInfo.Count];
for (int j = 0; j < columnNames.Length; j++)
{
columnNames[j] = ((FieldInfo)this.FieldInfo[j]).FieldName;
}
}
int[] numArray = new int[columnNames.Length];
for (int i = 0; i < columnNames.Length; i++)
{
FieldInfo field = null;
for (int j = 0; j < this.FieldInfo.Count; j++)
{
if (((FieldInfo)this.FieldInfo[j]).FieldName.ToUpper() == columnNames[i].ToUpper())
{
field = (FieldInfo)this.FieldInfo[j];
numArray[i] = j;
break;
}
}
if (field != null)
{
DataColumn column = new DataColumn(field.FieldName, field.Type);
table.Columns.Add(column);
}
}
foreach (JoinViewRow view in this)
{
object[] objectArray = new object[columnNames.Length];
for (int k = 0; k < numArray.Length; k++)
{
objectArray[k] = view[numArray[k]];
}
table.Rows.Add(objectArray);
}
return table;
}
#endregion
private void button16_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection(this.connectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand("select * from FND_USER", conn);
OleDbDataAdapter oda = new OleDbDataAdapter(cmd);
DataTable table = new DataTable("FND_USER");
oda.Fill(table);
OleDbCommand cmd1 = new OleDbCommand("select * from FND_LOGINS", conn);
OleDbDataAdapter oda1 = new OleDbDataAdapter(cmd1);
DataTable table1 = new DataTable("FND_LOGINS");
oda.Fill(table1);
DataSet ds = new DataSet();
oda.Fill(ds, "FND_USER");
oda1.Fill(ds, "FND_LOGINS");
//
// Establish relations between tables.
//
ds.Relations.Add("FND_LOGINS_USERS", ds.Tables["FND_USER"].Columns["USER_ID"], ds.Tables["FND_LOGINS"].Columns["USER_ID"], false);
string fieldList = "";
foreach (DataColumn col in ds.Tables["FND_LOGINS"].Columns)
{
//col.ColumnName;
}
Lerado.Framework.Data.JoinView jv = new Lerado.Framework.Data.JoinView(ds.Tables["FND_LOGINS"], "LOGIN_ID,USER_ID,START_TIME,FND_LOGINS_USERS.USER_NAME", "", "");
//this.dataGridView1.AutoGenerateColumns = true;
//this.dataGridView1.DataSource = jv;
//todo:create datarows from joinview
//object properties = ((IList)jv)[0];
SharpErp.Framework.Reports.ReportView view = new SharpErp.Framework.Reports.ReportView();
DataTable data = jv.ToTable();
view.ShowReport(@"E:\vsnet\Sharperp3\src\Library\OleDbHelper\OleDbHelperTest\bin\Debug\a.rpx", data, "", null);
//Lerado.Framework.Common.Globals.ShowReport(null, null, @"E:\vsnet\Sharperp3\src\Library\OleDbHelper\OleDbHelperTest\bin\Debug\a.rpx", jv, null, null);
conn.Close();
}