private void gridControlUserTable_DoubleClick(object sender, EventArgs e)
{
try
{
//gridView datatable GridLevelNode都用同一个名字
//ViewCaption中放类别, 1, 用户相关表. 0, 用户无关表
GridView curView = (DevExpress.XtraGrid.Views.Grid.GridView)gridControlUserTable.FocusedView; //当前的GridView
curView.MasterRowExpanding += new MasterRowCanExpandEventHandler(curView_MasterRowExpanding);
curView.MasterRowExpanded += new CustomMasterRowEventHandler(curView_MasterRowExpanded);
string viewName = curView.Name;
string id = "view" + icount.ToString();
int ihandle = curView.FocusedRowHandle; //当前的行号
DataRow dr = curView.GetDataRow(ihandle); //当前的行
GridView newGridView = null;
DataTable newDataTable = null;
DevExpress.XtraGrid.GridLevelNode gridLevel = null;
icount++;
#region 顶层的gridView
if (curView.Name == "gridViewParent")//顶层的gridView
{
string tableEName = dr["tableEName"].ToString();
string supplierRelated = dr["supplierRelated"].ToString();
#region 顶层
newGridView = new GridView();
newGridView.Name = id;
newGridView.OptionsView.ShowGroupPanel = false;
newGridView.OptionsBehavior.Editable = false;
newGridView.OptionsDetail.ShowDetailTabs = false;
newGridView.OptionsCustomization.AllowColumnMoving = false;
newGridView.OptionsBehavior.AutoExpandAllGroups = true;
this.gridControlUserTable.ViewCollection.Add(newGridView);
RelatedTableRecord[] relatedTableInfoArray = null;
UnrelatedTableRecord[] unRelatedTableInfoArray = null;
if (supplierRelated == "1")//厂商相关
{
relatedTableInfoArray = PublicFunction.GetRelatedTableInfos(tableEName, btime, etime);
if (relatedTableInfoArray == null || relatedTableInfoArray.Length == 0)
{
return;
}
CollectCommon.SetGridViewColumn(newGridView, "Config\\CollectMonitor\\supplierRelatedColumn.xml", "/Head");
newGridView.ViewCaption = "1";
}
else if (supplierRelated == "0")//厂商无关
{
unRelatedTableInfoArray = PublicFunction.GetUnRelatedTableInfos(tableEName, "", btime, etime);
if (unRelatedTableInfoArray == null || unRelatedTableInfoArray.Length == 0)
{
return;
}
CollectCommon.SetGridViewColumn(newGridView, "Config\\CollectMonitor\\supplierUnRelatedColumn.xml", "/Head");
newGridView.ViewCaption = "0";
}
newDataTable = new DataTable(id);
CollectCommon.SetDataTableColumn(newGridView, newDataTable);
if (supplierRelated == "1")//厂商相关
{
CollectCommon.FillTableData(newDataTable, relatedTableInfoArray);
}
else//厂商无关
{
CollectCommon.FillTableData(newDataTable, unRelatedTableInfoArray);
}
ds.Tables.Add(newDataTable);
gridLevel = new DevExpress.XtraGrid.GridLevelNode();
gridLevel.LevelTemplate = newGridView;
gridLevel.RelationName = id;
gridControlUserTable.LevelTree.Nodes.Add(gridLevel);
DataRelation dataRelation = new DataRelation(id, ds.Tables["parent"].Columns["tableEName"], ds.Tables[id].Columns["tableEName"], false);
ds.Relations.Add(dataRelation);
newGridView.RefreshData();
gridViewParent.RefreshData();
#endregion
}
#endregion
#region 非顶层表
else//非顶层表
{
if (curView.ViewCaption == "1")//厂商相关表,再钻取最后一层,厂商无关的信息表,就钻取到头了.
{
#region
string tableEName = dr["tableEName"].ToString();
string supplier = dr["supplier"].ToString();
UnrelatedTableRecord[] unRelatedTableInfoArray = null;
unRelatedTableInfoArray = PublicFunction.GetUnRelatedTableInfos(tableEName, supplier, btime, etime);
if (unRelatedTableInfoArray == null || unRelatedTableInfoArray.Length == 0)
{
return;
}
newGridView = new GridView();
newGridView.Name = id;
newGridView.OptionsView.ShowGroupPanel = false;
newGridView.OptionsBehavior.Editable = false;
newGridView.OptionsDetail.ShowDetailTabs = false;
newGridView.OptionsCustomization.AllowColumnMoving = false;
newGridView.OptionsBehavior.AutoExpandAllGroups = true;
newGridView.ViewCaption = "0";
this.gridControlUserTable.ViewCollection.Add(newGridView);
CollectCommon.SetGridViewColumn(newGridView, "Config\\CollectMonitor\\supplierUnRelatedColumn.xml", "/Head");
newDataTable = new DataTable(id);
CollectCommon.SetDataTableColumn(newGridView, newDataTable);
CollectCommon.FillTableData(newDataTable, unRelatedTableInfoArray);
ds.Tables.Add(newDataTable);
gridLevel = new DevExpress.XtraGrid.GridLevelNode();
gridLevel.LevelTemplate = newGridView;
gridLevel.RelationName = id;
string parentTableName = curView.Name;
string parentLevelName = curView.Name;
//AddGridLevelNode(gridControlUserTable, parentLevelName, gridLevel);
gridControlUserTable.LevelTree.Nodes[0].Nodes.Add(gridLevel);
DataColumn[] parentColumns = new DataColumn[2];
DataColumn[] childColumns = new DataColumn[2];
parentColumns[0] = ds.Tables[parentTableName].Columns["tableEName"];
parentColumns[1] = ds.Tables[parentTableName].Columns["supplier"];
childColumns[0] = ds.Tables[id].Columns["tableEName"];
childColumns[1] = ds.Tables[id].Columns["supplier"];
DataRelation dataRelation = new DataRelation(id, parentColumns, childColumns, false);
//DataRelation dataRelation = new DataRelation(id, parentColumns[0], childColumns[0], false);
ds.Relations.Add(dataRelation);
curView.RefreshData();
#endregion
}
else if (curView.ViewCaption == "0")//厂商无关表
{
}
}
#endregion
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
}