protected void lvProcLotCardMgr_ItemCommand(object sender, ListViewCommandEventArgs e) { //当前listview行 var itm = e.Item; //检测命令类型 if (itm.ItemType != ListViewItemType.DataItem) { //直接返回 return; } //检测是否含有session if (Session.Count < 5) { //跳转 Response.Redirect("/Account/Login", true); //停止加载后续内容 Response.End(); //直接返回 return; } //当前是否存在数据 if (e.Item.DataItemIndex < 0) { return; } //当前数据行id号 Int64 id = Convert.ToInt64(e.CommandArgument.ToString().Trim()); //当前数据行 DataSetProcLotCardMgr.t_proc_lot_card_balanceRow row = null; using (var da = new t_proc_lot_card_balanceTableAdapter()) { //取得数据 var tab = da.GetDataById(id); //获取首行 if (tab.Rows.Count > 0) { row = (DataSetProcLotCardMgr.t_proc_lot_card_balanceRow)tab.Rows[0]; } } //检测数据 if (row == null) { throw new Exception(string.Format("未找到序号为 {0} 的结存数据!: ", id)); } //当前行的部门名称 string curProcName = row.proc_name.ToUpper(); //当前用户所在部门 string procName = Session["proc_name"].ToString().ToUpper(); //当前角色id Int16 roleId = Convert.ToInt16(Session["role_id"]); //检测是否有权限 //本部门人员只能确认 if (procName == curProcName) { //检测命令名称 if (e.CommandName == "AcceptQty") { //检测角色 if (roleId < 0 || roleId > 4) { throw new Exception("您没有确认该序号记录的权限!序号: " + id.ToString()); } } else if (e.CommandName == "CancelAcceptQty") { throw new Exception("您没有取消确认该序号记录的权限!序号: " + id.ToString()); } } //计划部,样板组操作员级别以上人员只允许取消确认 else if (procName == mustProcName || procName == "样板") { //检测角色 if (roleId < 0 || roleId > 4) { //检测命令名称 if (e.CommandName == "AcceptQty") { throw new Exception("您没有确认该序号记录的权限!序号: " + id.ToString()); } else if (e.CommandName == "CancelAcceptQty") { throw new Exception("您没有取消确认该序号记录的权限!序号: " + id.ToString()); } } //分清是样板还是生产板 var lotId = row.lot_id; //生产对应生产批量卡,样板对应样板批量卡 if ((!lotId.Contains("S") && procName != mustProcName) || (lotId.Contains("S") && procName != "样板") ) { //检测命令名称 if (e.CommandName == "AcceptQty") { throw new Exception("您没有确认该序号记录的权限!序号: " + id.ToString()); } else if (e.CommandName == "CancelAcceptQty") { throw new Exception("您没有取消确认该序号记录的权限!序号: " + id.ToString()); } } } else { //检测命令名称 if (e.CommandName == "AcceptQty") { throw new Exception("您没有确认该序号记录的权限!序号: " + id.ToString()); } else if (e.CommandName == "CancelAcceptQty") { throw new Exception("您没有取消确认该序号记录的权限!序号: " + id.ToString()); } } //当前用户的名称 string userName = Session["user_name"].ToString(); //检测命令名称 if (e.CommandName == "AcceptQty") { //修改指定的单据 using (var da = new t_proc_lot_card_balanceTableAdapter()) { //执行确认数量 da.AcceptQtyById(userName, id); //重新绑定数据 lvProcLotCardMgr.DataBind(); } } else if (e.CommandName == "CancelAcceptQty") { //修改指定的单据 using (var da = new t_proc_lot_card_balanceTableAdapter()) { //执行取消确认的数量 da.CancelAcceptQtyById(id); //重新绑定数据 lvProcLotCardMgr.DataBind(); } } }