/// <summary>
 /// 将url中提供的id的待报废记录数据写入窗口中的文本框
 /// </summary>
 private void SetWaitScrapRecordToForm()
 {
     //调用过程填写默认值
     fvWaitScrapRecordBackAdd_ItemCreated(null, null);
     //获取传入的url中的id参数
     string strId = Request["waitid"];
     int id;
     if (!string.IsNullOrEmpty(strId) && int.TryParse(strId, out id))
     {
         //获取该条记录的数据写入文本框
         using (var da = new t_proc_lot_card_balanceTableAdapter())
         using (var tab = da.GetDataById(id))
         {
             //检测是否取到数据
             if (tab.Rows.Count > 0)
             {
                 //首行
                 var row = (DataSetProcLotCardMgr.t_proc_lot_card_balanceRow)tab.Rows[0];
                 //填写数据
                 //批量卡号
                 var tb = (TextBox)fvWaitScrapRecordBackAdd.FindControl("txtLotId");
                 if (tb != null)
                 {
                     //设置默认值
                     tb.Text = row.lot_id;
                 }
                 //生产编号
                 tb = (TextBox)fvWaitScrapRecordBackAdd.FindControl("txtProductNum");
                 if (tb != null)
                 {
                     //设置默认值
                     tb.Text = row.product_num;
                 }
                 //pcs数量
                 tb = (TextBox)fvWaitScrapRecordBackAdd.FindControl("txtPcsQty");
                 if (tb != null)
                 {
                     //设置默认值
                     tb.Text = row.pcs_qty.ToString();
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 根据输入的参数在数据库中删除记录
        /// </summary>
        /// <param name="id">待删除的行的序号</param>
        /// <returns></returns>
        private bool DeleteData(Int64 id)
        {
            //数据适配器
            //当前添加语句对象
            //当前数据库连接
            using (var da = new t_proc_lot_card_balanceTableAdapter())
            using (var daChange = new t_proc_lot_card_balance_changeTableAdapter())
            using (var cmd = da.Adapter.InsertCommand)
            using (var conn = cmd.Connection)
            {
                //打开数据库连接
                conn.Open();
                //设置数据库连接
                da.Connection = daChange.Connection = cmd.Connection = conn;
                //开启事务
                using (var tran = conn.BeginTransaction())
                {
                    //设置事务
                    da.Transaction = daChange.Transaction = cmd.Transaction = tran;
                    //试运行
                    try
                    {
                        //提取数据
                        var tab = da.GetDataById(id);
                        //检测数据
                        if (tab.Rows.Count <= 0)
                        {
                            //抛出错误
                            throw new Exception("删除部门批量卡结存发生错误,数据不存在!");
                        }
                        //获取首行数据
                        var row = (DataSetProcLotCardMgr.t_proc_lot_card_balanceRow)tab.Rows[0];
                        //当前用户所在部门
                        string procName = Session["proc_name"].ToString().ToUpper();
                        //当前角色id
                        Int16 roleId = Convert.ToInt16(Session["role_id"]);
                        //检测是否有权限
                        if ((procName != mustProcName && procName != "样板") || roleId < 0 || roleId > 1)
                        {
                            throw new Exception("您没有添加记录权限!");
                        }
                        //当前输入的批量卡序号
                        string lotId = row.lot_id.Trim().ToUpper();
                        //检测是否样板
                        bool isSample = lotId.Contains("S");
                        //检测是否正确批量卡号
                        if (!isSample && !ydOperateLotCard.IsLotCardId(ref lotId))
                        {
                            //非数字返回失败
                            throw new Exception("您输入了一个不合格的批量卡号 " + lotId + " !");
                        }
                        //检测是否正确样板批量卡号
                        if (isSample && !ydOperateSampleLotCard.IsSampleLotCardId(ref lotId))
                        {
                            //非数字返回失败
                            throw new Exception("您输入了一个不合格的样板批量卡号 " + lotId + " !");
                        }
                        //检测lot卡类型
                        if (lotId.Contains("S") && procName != "样板")
                        {
                            throw new Exception("当前只能删除样板批量卡!");
                        }
                        //检测lot卡类型
                        if (!lotId.Contains("S") && procName != "PMC")
                        {
                            throw new Exception("当前只能删除生产板批量卡!");
                        }

                        //执行保存数据
                        if (da.Delete(id) <= 0)
                        {
                            //抛出错误
                            throw new Exception("删除部门批量卡结存发生错误!");
                        }
                        //取得一个相关guid
                        var guid = Guid.NewGuid().ToString();
                        //保存到修改记录表
                        if (daChange.InsertData(
                            row.prev_proc_name,
                            row.proc_name,
                            row.lot_id,
                            row.product_num,
                            row.pnl_qty,
                            row.pcs_qty,
                            row.IsremarkNull() ? null : row.remark,
                            row.add_person,
                            row.Isaccept_personNull() ? null : row.accept_person,
                            row.Isaccept_timeNull() ? null : (DateTime?)row.accept_time,
                            row.is_complete_wenzi,
                            false,
                            guid
                        ) <= 0)
                        {
                            //抛出错误
                            throw new Exception("添加修改批量卡结存旧数据日志记录发生错误!");
                        }
                        //提交事务
                        tran.Commit();
                        //返回成功
                        return true;
                    }
                    catch (Exception ex)
                    {
                        //回滚事务
                        tran.Rollback();
                        //抛出错误
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
Exemplo n.º 3
0
 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();
         }
     }
 }