首页上一页 1 下一页尾页 4 条记录 1/1页
《实战突击:ASP.NET项目开发案例整合》第21章企业级通用进销存软件 入库单确认时出错
发表在ASP.NET图书答疑
2012-02-08
是否精华
是
否
版块置顶:
是
否
PurchaseStockAudit.aspx.cs 中代码
/// <summary>
/// 入库确认
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAudit_Click(object sender, EventArgs e)
{
int cnt = 0;
foreach (GridViewRow row in dgvInfo.Rows) //遍历GridView所有的行
{
bool chk = ((CheckBox)row.Cells[1].FindControl("chkAuditFlag")).Checked;
if (chk) //判断该行是行被选中
{
cnt++;
//取GridView行主键值
string tempId = dgvInfo.DataKeys[row.RowIndex].Value.ToString();
string billCode = row.Cells[2].Text; //取GridView行单据号内容
if (!string.IsNullOrEmpty(tempId))
{
try
{
//调用业务层入库单审核方法
[font color=#FF0000]PurchaseService.Instance.AuditPurchase(Convert.ToInt32(tempId), true, Context.User.Identity.Name);
[/font] ((CheckBox)row.Cells[1].FindControl("chkAuditFlag")).Checked = false;
}
catch
{
throw new Exception("单据号" + billCode + "审核失败");
}
}
}
}
调用 PurchaseService.cs 中
/// <summary>
/// 入库单审核确认
/// </summary>
/// <param name="id"></param>
/// <param name="isAudit"></param>
/// <param name="operatorCode"></param>
/// <returns></returns>
public bool AuditPurchase(int id, bool isAudit, string operatorCode)
{.......
Store storeParam = new Store();
storeParam.Warehouse = tPur.Content.WareHouse;
storeParam.ProductCode = tPurDetail.DetDetail.ProductCode;
Store sto = null;
//根据仓库、货品代码取库存表中该货品信息
[font color=#FF0000]sto = daoStore.GetStore(storeParam);
[/font]
if (sto == null)//库存中没有该货品
{.......
调用 StoreDao.cs 中的
/// <summary>
/// 根据仓库,商品代码获得库存实体
/// </summary>
/// <param name="obj">只需传入仓库代码,商品代码即可</param>
/// <returns>库存实体</returns>
public Store GetStore(Store obj)
{
[font color=#00FF00]return dc.Store.FirstOrDefault(itm => itm.Warehouse == obj.Warehouse && itm.ProductCode == obj.ProductCode);
[/font] }
这里报错:从查询中返回了结果后,将无法修改数据上下文选项。
这个怎么解决??????????
/// <summary>
/// 入库确认
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAudit_Click(object sender, EventArgs e)
{
int cnt = 0;
foreach (GridViewRow row in dgvInfo.Rows) //遍历GridView所有的行
{
bool chk = ((CheckBox)row.Cells[1].FindControl("chkAuditFlag")).Checked;
if (chk) //判断该行是行被选中
{
cnt++;
//取GridView行主键值
string tempId = dgvInfo.DataKeys[row.RowIndex].Value.ToString();
string billCode = row.Cells[2].Text; //取GridView行单据号内容
if (!string.IsNullOrEmpty(tempId))
{
try
{
//调用业务层入库单审核方法
[font color=#FF0000]PurchaseService.Instance.AuditPurchase(Convert.ToInt32(tempId), true, Context.User.Identity.Name);
[/font] ((CheckBox)row.Cells[1].FindControl("chkAuditFlag")).Checked = false;
}
catch
{
throw new Exception("单据号" + billCode + "审核失败");
}
}
}
}
调用 PurchaseService.cs 中
/// <summary>
/// 入库单审核确认
/// </summary>
/// <param name="id"></param>
/// <param name="isAudit"></param>
/// <param name="operatorCode"></param>
/// <returns></returns>
public bool AuditPurchase(int id, bool isAudit, string operatorCode)
{.......
Store storeParam = new Store();
storeParam.Warehouse = tPur.Content.WareHouse;
storeParam.ProductCode = tPurDetail.DetDetail.ProductCode;
Store sto = null;
//根据仓库、货品代码取库存表中该货品信息
[font color=#FF0000]sto = daoStore.GetStore(storeParam);
[/font]
if (sto == null)//库存中没有该货品
{.......
调用 StoreDao.cs 中的
/// <summary>
/// 根据仓库,商品代码获得库存实体
/// </summary>
/// <param name="obj">只需传入仓库代码,商品代码即可</param>
/// <returns>库存实体</returns>
public Store GetStore(Store obj)
{
[font color=#00FF00]return dc.Store.FirstOrDefault(itm => itm.Warehouse == obj.Warehouse && itm.ProductCode == obj.ProductCode);
[/font] }
这里报错:从查询中返回了结果后,将无法修改数据上下文选项。
这个怎么解决??????????