FineUI 官方论坛
标题:
(FineUI+动软)在实现多表关联新增时如何获取外键?
[打印本页]
作者:
alfly008
时间:
2014-4-11 20:18
标题:
(FineUI+动软)在实现多表关联新增时如何获取外键?
本帖最后由 alfly008 于 2014-4-11 20:51 编辑
FineUI界面的图,在最下面。说明:每个gird对应一个数据库表,两张表AllocIn为配送表,AllocInDet为配送详情表,以AllocIn的AllocInID做为外键。
每一个新增/编辑都对应一个文件,分别为xxx_new xxx_edit。
第二个明细表的窗体的前台:
<body>
<form id="form1" runat="server">
<x:PageManager ID="PageManager1" AutoSizePanelID="Panel1" runat="server" />
<x:Panel ID="Panel1" runat="server" BodyPadding="5px" EnableLargeHeader="false"
EnableBackgroundColor="true" ShowBorder="false" Layout="VBox" BoxConfigAlign="Stretch"
BoxConfigPosition="Start" ShowHeader="false" Title="配送接收明细">
<Toolbars>
<x:Toolbar ID="Toolbar1" runat="server">
<Items>
<x:Button ID="btnClose" Icon="SystemClose" EnablePostBack="false" runat="server"
Text="关闭">
</x:Button>
<x:ToolbarSeparator ID="ToolbarSeparator1" runat="server">
</x:ToolbarSeparator>
<x:Button ID="btnSaveClose" ValidateForms="SimpleForm1" Icon="SystemSaveClose"
OnClick="btnSaveClose_Click" runat="server" Text="保存后关闭">
</x:Button>
</Items>
</x:Toolbar>
</Toolbars>
<Items>
<x:Grid ID="Grid2" runat="server" BoxFlex="1" ShowBorder="true" ShowHeader="false"
EnableCheckBoxSelect="true" EnableRowNumber="true" DataKeyNames="CK_AllocInDetID" AllowSorting="true"
OnSort="Grid2_Sort" SortColumnIndex="0" SortDirection="DESC" AllowPaging="true"
IsDatabasePaging="true" OnPreDataBound="Grid2_PreDataBound" OnRowCommand="Grid2_RowCommand"
OnPageIndexChange="Grid2_PageIndexChange">
<Toolbars>
<x:Toolbar ID="Toolbar2" runat="server">
<Items>
<%--<x:Button ID="btnDeleteSelected" Icon="Delete" runat="server" Text="删除选中记录" OnClick="btnDeleteSelected_Click">
</x:Button>--%>
<x:ToolbarFill ID="ToolbarFill1" runat="server">
</x:ToolbarFill>
<x:Button ID="btnNew2" runat="server" Icon="Add" EnablePostBack="false" Text="新增配送货品">
</x:Button>
</Items>
</x:Toolbar>
</Toolbars>
<Columns>
<x:BoundField DataField="CK_ProductNo" SortField="CK_ProductNo" Width="100px" HeaderText="货品编号" />
<x:BoundField DataField="CK_ProductTypeName" SortField="CK_ProductTypeName" Width="100px" HeaderText="货品类型" />
<x:BoundField DataField="CK_ProductName" SortField="CK_ProductName" Width="100px" HeaderText="品名" />
<x:BoundField DataField="CK_ProductSizeNo" SortField="CK_ProductSizeNo" Width="50px" HeaderText="尺码" />
<x:BoundField DataField="CK_ProductNum" SortField="CK_ProductNum" ExpandUnusedSpace="true" HeaderText="数量" />
<x:WindowField ColumnID="editField" TextAlign="Center" Icon="Pencil" ToolTip="编辑" WindowID="Window2"
Title="编辑" DataIFrameUrlFields="CK_AllocInDetID" DataIFrameUrlFormatString="~/CK_AllocInDet_edit.aspx?id={0}"
Width="50px" />
<x:LinkButtonField ColumnID="deleteField" TextAlign="Center" Icon="Delete" ToolTip="删除" ConfirmText="确定删除此记录?"
ConfirmTarget="Top" CommandName="Delete" Width="50px" />
</Columns>
</x:Grid>
</Items>
</x:Panel>
<x:Window ID="Window2" CloseAction="Hide" runat="server" IsModal="true" Hidden="true" Target="Top"
EnableResize="true" EnableMaximize="true" EnableIFrame="true" IFrameUrl="about:blank"
Width="400px" Height="250px" OnClose="Window1_Close">
</x:Window>
</form>
</body>
复制代码
后台部分代码:
private void BindGrid()
{
DataSet ds;
int id = GetQueryIntValue("id");
TSM.Model.CK_AllocIn modelCK_AllocIn = m_bllCK_AllocIn.GetModel(id);
string searchText = modelCK_AllocIn.CK_AllocInID.ToString();
string strWhere = "CK_AllocInID = '" + searchText + "'";
ds = m_bllCK_AllocInDet.GetList(strWhere);
复制代码
最后一个新增窗体的后面代码:
private void LoadData()
{
btnClose.OnClientClick = ActiveWindow.GetHideReference();
DataSet ds = m_bllCK_Product.GetList("");
ddlPNo.DataTextField = "CK_ProductNo";
ddlPNo.DataValueField = "CK_ProductID";
ddlPNo.DataSource = ds.Tables[0];
ddlPNo.DataBind();
ddlPNo.SelectedIndex = 0;
int id = GetQueryIntValue("id");
TSM.Model.CK_AllocInDet modelCK_AllocInDet = m_bllCK_AllocInDet.GetModel(id);
if (modelCK_AllocInDet == null)
{
// 参数错误,首先弹出Alert对话框然后关闭弹出窗口
Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference());
return;
}
tbxSize.Text = modelCK_AllocInDet.CK_ProductSizeNo;
tbxPNum.Text = modelCK_AllocInDet.CK_ProductNum.ToString();
ddlPNo.SelectedValue = modelCK_AllocInDet.CK_ProductID.ToString();
}
#endregion
#region Events
protected void btnSaveClose_Click(object sender, EventArgs e)
{
int id = GetQueryIntValue("id");
TSM.Model.CK_AllocInDet modelCK_AllocInDet = m_bllCK_AllocInDet.GetModel(id);
modelCK_AllocInDet.CK_ProductSizeNo = tbxSize.Text.Trim();
modelCK_AllocInDet.CK_ProductNum = int.Parse(tbxPNum.Text.Trim());
modelCK_AllocInDet.CK_ProductID = int.Parse(ddlPNo.SelectedValue);
<font color="#ff0000"> m_bllCK_AllocInDet.Add(modelCK_AllocInDet);</font>
//FineUI.Alert.Show("保存成功!", String.Empty, FineUI.Alert.DefaultIcon, FineUI.ActiveWindow.GetHidePostBackReference());
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
复制代码
上面添加时,总是报错,说是AllocInID冲突,调试时modelCK_AllocInDet.AllocInID=0 看来是要关联上值,可是不知道如何去取。又不是同一个文件
求大佬们指教,拜谢。
作者:
alfly008
时间:
2014-4-11 20:26
补充一下,代码结构图:
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4