标签:
页面直接通过查询语句取值方法
// DataTable页面查询语句取值方法
DataTable dtTable = DbService.Instance().QueryDataTable("select * from TrainErp_Product_LevelAfter where ProductCode=‘" + DbService.DtV(curMainDataTable, "ProductCode") + "‘ and LevelCode=‘" + mLevelCode + "‘") ?? new DataTable();
主从表
1.列表页保存方法体增加:
$("body").on("click", ".save", function() {
$.asFormSetHidden(gConfig.gridFormId, "mc", gConfig.mc);
$.asFormSetHidden(gConfig.gridFormId, "procName", "TrainErp_spProductTopicExecute");
$.asSetXMLInfo(gConfig.gridFormId,"Xml","TrainErp_Product_ProductTopicAfter");
var param = {};
$.asAppSubmitFormProc(
gConfig.gridFormId, param, function(retData) {
//返回正确的数据
if (retData.RetStatus == 100 || retData.RetStatus == 101) {
//刷新数据
$.asTableReloadData(gConfig.id, queryParams);
$("#" + gConfig.gridId).show();
$("#" + gConfig.detailId + "").hide();
} else {
alert(retData.RetValue);
}
}, function() {
//表单提交前进行验证
//return true 继续进行
//return false 阻止提交
//alert("进行验证字段是否合法");
if ($.asCheckStringEmpty($("#TopicName").val(), true, "课题名称不能为空!")== false) {
$("#TopicName").focus();
return false;
}
return true;
}, function() {
alert("发生错误,请重新提交");
});
return false;
});
2.列表页定义从表选择方法
//增加一行的事件
$.asButtonEvent("btnAddRow", "click", function() {
var tplInfo = $("#tplRowInfo").html();
$("#TrainErp_Product_ProductTopicAfter>tbody").append(tplInfo);
});
//删除行事件
$.asButtonEvent("btnDeleteRow", "click", function() {
$("input[name=‘cblProductTopicAfter‘]").each(function() {
if ($(this).prop("checked") == true) {
$(this).parent().parent().remove();
}
});
});
3.列表页编辑从表显示:
<script id="tplRowInfo" type="textml" style="display: none;">
<tr>
<td class="w30"><input type="checkbox" name="cblProductTopicAfter" /></td>
<td class="w100">@Html.Raw(HtmlControlHelper.GetText("FineArtsPoints", "", 40, false, false))</td>
<td class="w100">@Html.Raw(HtmlControlHelper.GetText("EncyclopediasPoints", "", 40, false, false))</td>
<td class="w100">@Html.Raw(HtmlControlHelper.GetText("CorrespondingA", "", 40, false, false))</td>
<td>@Html.Raw(HtmlControlHelper.GetText("CorrespondingB", "", 40, false, false))</td>
</tr>
</script>
4.详细页编辑从表赋值取值
String mProductTopicCode = DbService.DtV(curMainDataTable, "ProductTopicCode");
<table class="">
<tr>
<td style="width: 40px; padding: 2px;">
<input type="button" name="btnAddRow" id="btnAddRow" class="btnAddRow" value="增加行"/></td>
<td style="width: 40px; padding: 2px;">
<input type="button" name="btnDeleteRow" id="btnDeleteRow" class="btnDeleteRow" value="删除行"/></td>
<td></td>
</tr>
</table>
<table class="asDataGrid" id="TrainErp_Product_ProductTopicAfter">
<tbody>
<tr>
<th class="w30">选择</th>
<th class="w100">美术知识点</th>
<th class="w100">百科知识点</th>
<th class="w100">对应课程A</th>
<th>对应课程B</th>
</tr>
@{
//课题-课题信息管理
DataTable curDtProductTopicAfter = AppService.QueryDataTable("ds-ProductTopicAfterEdit", " where ProductTopicCode=‘" + mProductTopicCode + "‘", "FineArtsPoints,EncyclopediasPoints,CorrespondingA,CorrespondingB", "Order by ProductTopicInfoId desc", false) ?? new DataTable();
foreach (DataRow dataRow in curDtProductTopicAfter.Rows)
{
<tr>
<td class="w30">
<input type="checkbox" name="cblProductTopicAfter"/></td>
<td class="w100">@Html.Raw(HtmlControlHelper.GetText("FineArtsPoints", dataRow["FineArtsPoints"].ToString(), 40, false, false))</td>
<td class="w100">@Html.Raw(HtmlControlHelper.GetText("EncyclopediasPoints", dataRow["EncyclopediasPoints"].ToString(), 40, false, false))</td>
<td class="w100">@Html.Raw(HtmlControlHelper.GetText("CorrespondingA", dataRow["CorrespondingA"].ToString(), 40, false, false))</td>
<td>@Html.Raw(HtmlControlHelper.GetText("CorrespondingB", dataRow["CorrespondingB"].ToString(), 40, false, false))</td>
</tr>
}
}
</tbody>
</table>
5.主从表执行存储过程:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER procedure [dbo].[TrainErp_spProductTopicExecute]
(
--输入参数
@pi_DoCmd varchar(200),
@pi_ProductTopicCode varchar(50),
@pi_ProductLevelInfoCode varchar(50),
@pi_TopicName varchar(50),
@pi_Xml varchar(max),
--输出参数
@po_Status int output,
@po_RetValue varchar(200) output
)
as
/*
@名称:新增产品-等级-水平-课题-课题信息
@作者:howie
@创建时间:2015-3-28
@修改人:
@修改时间:
@修改内容:
*/
--定义临时表,用来存放XML转换过来的数据 TrainErp_Product_ProductTopicAfter
declare @pt_table1 table(FineArtsPoints varchar(50),EncyclopediasPoints varchar(500),CorrespondingA varchar(50),CorrespondingB varchar(50))
--对XML数据进行处理,注意下
DECLARE @pt_idoc1 int --查询下
exec sp_xml_preparedocument @pt_idoc1 output,@pi_Xml
insert into @pt_table1
select * from openxml(@pt_idoc1,‘/ROOT/TrainErp_Product_ProductTopicAfter‘,1)
with(FineArtsPoints varchar(50),EncyclopediasPoints varchar(500),CorrespondingA varchar(50),CorrespondingB varchar(50))
--增加
if @pi_DoCmd=‘add‘
begin
begin tran
insert into TrainErp_Product_ProductTopic
(
ProductTopicCode,
ProductLevelInfoCode,
TopicName
)
values
(
@pi_ProductTopicCode,--生成的编号
@pi_ProductLevelInfoCode,
@pi_TopicName
)
--从表
insert into TrainErp_Product_ProductTopicAfter
select newid(),@pi_ProductTopicCode,FineArtsPoints,EncyclopediasPoints,CorrespondingA,CorrespondingB
from @pt_table1 where FineArtsPoints !=‘‘
if @@error<>0
begin
rollback tran
set @po_status = 400
set @po_RetValue=‘增加失败‘
end
else
begin
commit tran
set @po_status = 100
set @po_RetValue=‘增加成功‘
end
end
--修改
if @pi_DoCmd=‘modify‘
begin
begin tran
update TrainErp_Product_ProductTopic set
ProductLevelInfoCode=@pi_ProductLevelInfoCode,
TopicName=@pi_TopicName
where ProductTopicCode=@pi_ProductTopicCode
delete from TrainErp_Product_ProductTopicAfter where ProductTopicCode=@pi_ProductTopicCode
--从表
insert into TrainErp_Product_ProductTopicAfter
select newid(),@pi_ProductTopicCode,FineArtsPoints,EncyclopediasPoints,CorrespondingA,CorrespondingB
from @pt_table1 where FineArtsPoints !=‘‘
if @@error<>0
begin
rollback tran
set @po_status = 400
set @po_RetValue=‘修改失败‘
end
else
begin
commit tran
set @po_status = 100
set @po_RetValue=‘修改成功‘
end
end
--删除
if @pi_DoCmd=‘delete‘
begin
begin tran
--先删除从表
delete from TrainErp_Product_ProductTopicAfter where ProductTopicCode=@pi_ProductTopicCode
--再删除主表
delete from TrainErp_Product_ProductTopic where ProductTopicCode=@pi_ProductTopicCode
if @@error<>0
begin
rollback tran
set @po_status = 400
set @po_RetValue=‘删除失败‘
end
else
begin
commit tran
set @po_status = 103
set @po_RetValue=‘删除成功‘
end
end
if @@error <> 0
begin
set @po_Status = 900
set @po_RetValue = ‘数据执行失败‘
end
6.其他注意点:
a.主从表查询存储过程,注意新建视图,查询视图
b.修改时,详细页需要取附表的值,必须新增一个附表的Edit数据集,用来循环取值
标签:
原文地址:http://www.cnblogs.com/howie/p/4999674.html