DataSet ds = new DataSet();
#region 头
string strSql = @" select distinct top 10 cNo 生产周计划单号,h.ddate 生产周计划日期,cus.cCusName 客户名称,d.cSOCode 客户订单号,cFree1 色号,
convert(nvarchar(10),so.dDate,120) as 下单日期,d.cMemo 表头备注
from jn_moweekplan h
left join dbo.jn_moweekplans d on d.id = h.id
left join dbo.Inventory inv on inv.cInvCode = d.cinvcode
left join dbo.Customer cus on cus.cCusCode = d.ccuscode
left join dbo.SO_SOMain so on so.cSOCode=d.cSOCode
left join dbo.UserDefine usd on usd.cValue=cFree3
where isnull(cAuditor,'')!='' and isnull(d.cinvcode,'')!='' ";
if (StrHeadSql != "") strSql = StrHeadSql;
//父GridView的数据
SqlConnection con = new SqlConnection(strConn);
SqlDataAdapter adapt = new SqlDataAdapter(strSql + this.StrLoadWhere, con);
adapt.Fill(ds, "main");
ds.Tables["main"].Columns.Add("选择", System.Type.GetType("System.Boolean")).SetOrdinal(0);
#endregion
#region 子
//子GridView的数据
strSql = @" select distinct cInvStd 型材规格,cFree2 包装形式,cFree3 工艺要求,cFree1 色号,
cDefine34 支数,cFree4 长度,d.cMemo 表头备注,dPreDate 订单交期,isnull(pftheqty,0) 排放支数,cNo 生产周计划单号,cus.cCusName 客户名称,d.cSOCode 客户订单号
from jn_moweekplan h
left join dbo.jn_moweekplans d on d.id = h.id
left join dbo.Inventory inv on inv.cInvCode = d.cinvcode
left join dbo.Customer cus on cus.cCusCode = d.ccuscode
left join dbo.SO_SOMain so on so.cSOCode=d.cSOCode
left join dbo.UserDefine usd on usd.cValue=cFree3
where isnull(cAuditor,'')!='' and isnull(d.cinvcode,'')!='' ";
if (strHeadOneSql != "") strSql = strHeadOneSql;
adapt = new SqlDataAdapter(strSql + this.StrLoadWhere, con);
adapt.Fill(ds, "son");
ds.Tables["son"].Columns.Add("选择", System.Type.GetType("System.Boolean")).SetOrdinal(0);
#endregion
//这个是显示主从表的关键,一、GridControl通过检查DataSet.Relations的内容来分析数据
//二、关键名必须与设计GridView的层级关系的level name相同,否则,结果在意料之外。
DataColumn[] dr = new DataColumn[] { ds.Tables["main"].Columns["生产周计划单号"], ds.Tables["main"].Columns["客户名称"],
ds.Tables["main"].Columns["客户订单号"], ds.Tables["main"].Columns["色号"] };
DataColumn[] drs = new DataColumn[] { ds.Tables["son"].Columns["生产周计划单号"], ds.Tables["son"].Columns["客户名称"],
ds.Tables["son"].Columns["客户订单号"], ds.Tables["son"].Columns["色号"] };
DataRelation relation = new DataRelation("明细", dr, drs, false);
ds.Relations.Add(relation);
//这也是一个关键,不能直接设为:ds,必须指明到表。
GridView.DataSource = ds.Tables["main"];
这个做一个绑定,第一列会有一个 checkbox ,我选择 父行的时候,同时子表行也选中。选择子表行的时候要触发其他事件,这个不知道怎么获取 ,下面是父的 CellChecked,子表不知道怎么写
private void GridView_CellChecked(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
//MessageBox.Show(GridView.Rows[GridView.RowSel][2].ToString() + GridView.Rows[GridView.RowSel]["色号"].ToString());
C1FlexDataTree child = GridView.Rows[GridView.RowSel].UserData as C1FlexDataTree;
//MessageBox.Show(child.Rows[1]["型材规格"].ToString() + child.Rows[1]["色号"].ToString());
if (child == null)
{
//if (GridView.Rows[GridView.RowSel]["选择"].ToString() == "True")
// GridView.Rows[GridView.RowSel]["选择"] = "True";
//else
// GridView.Rows[GridView.RowSel]["选择"] = "";
return;
}
if (GridView.Rows[GridView.RowSel]["选择"].ToString() == "True")
{
for (int i = 1; i < child.Rows.Count; i++)
{
child.Rows["选择"] = "True";
}
}
else
{
for (int i = 1; i < child.Rows.Count; i++)
{
child.Rows["选择"] = "False";
}
}
} |