//根据传入的参数处理事情
 public void ProcessRequest(HttpContext context)
 {
     //清空之前数据
     context.Response.Clear();
     //检测是否含有session
     if (context.Session.Count < 5)
     {
         //跳转
         context.Response.Redirect("/Account/Login", true);
         //停止加载后续内容
         context.Response.End();
         //直接返回
         return;
     }
     //执行基类的方法
     if (!base.CheckIsLogin(context))
     {
         return;
     }
     //用户传入的生产编号
     string procNum = context.Request["pnum"];
     //检测生产编号
     if (procNum == null || procNum.Length == 0)
     {
         context.Response.Write("未提供生产编号参数!");
         return;
     }
     //用户传入的送货单编号
     string billNum = context.Request["bnum"];
     //检测送货单编号
     if (billNum == null || billNum.Length == 0)
     {
         billNum = string.Empty;
     }
     //用户传入的已经存在的批量卡和数量
     string lotCardList = context.Request["lotlist"];
     //检测批量卡和数量
     if (lotCardList == null || lotCardList.Length == 0)
     {
         lotCardList = string.Empty;
     }
     //转换字符串
     lotCardList = lotCardList.Replace("|l|", "<").Replace("|g|", ">");
     //将查询到的结果保存到字典变量中
     var dic = new Dictionary<string, LiItem>();
     //数据适配器
     using (var da = new t_complete_lot_card_waitTableAdapter())
     {
         //获取数据
         var tab = da.GetDataByProductNum(procNum);
         //获取当前送货单中的批量卡清单
         var tabDeliveryLotCard = new DataSetDeliveryBillMgr.t_delivery_bill_lot_cardDataTable();
         //传入的送货单号大于0才获取之前该送货单的交货批量卡清单
         if (billNum.Length > 0)
         {
             //数据适配器获取之前的清单
             using (var daDeliveryLotCard = new t_delivery_bill_lot_cardTableAdapter())
             {
                 daDeliveryLotCard.FillByBillNum(tabDeliveryLotCard, billNum);
             }
         }
         //获取单据数据
         AddLotListWaitItem(tab, ref dic, lotCardList, tabDeliveryLotCard);
     }
     //待输出到浏览器的数据
     //表格的行
     string strResult = string.Empty;
     //将数据遍历写入页面
     if (dic.Count <= 0)
     {
         //显示未找到数据
         strResult = "在待入仓清单中未找到该生产编号的批量卡数据!";
     }
     else
     {
         //实例化stringbuild类
         var sb = new StringBuilder();
         //加入全选按钮
         sb.Append("<input class='yd-btn-select-all-lot-card yd-lot-card-cmd-btn' type='button' value='全选/全不选' />");
         //加入自动识别扣数按钮
         sb.Append("<input class='yd-btn-auto-lot-card yd-lot-card-cmd-btn' type='button' value='智能识别' title='根据该生产编号输入的总数量自动填写' />");
         //加入筛选按钮
         sb.Append("<input class='yd-tb-filter-lot-id' type='text' />");
         sb.Append("<input class='yd-btn-filter-lot-card yd-lot-card-cmd-btn' type='button' value='着色筛选' />");
         //加入确认按钮
         sb.Append("<input class='yd-accept-lot-card-btn yd-lot-card-cmd-btn' type='button' value='确认(A)' accesskey='A' title='也可按Alt+A执行' />");
         sb.Append("<hr />\n");
         //加入外层div开头
         sb.Append("<div class='yd-div-lot-card-list'>\n");
         //循环设置取得的批量卡清单
         foreach (var itm in dic)
         {
             //将实例加入项目
             sb.Append(itm.Value.ToString());
         }
         //加入外层div尾
         sb.Append("</div>\n");
         //取得最终结果
         strResult = sb.ToString();
     }
     //写入数据
     context.Response.Write(strResult);
 }
        public void ProcessRequest(HttpContext context)
        {
            //清空之前数据
            context.Response.Clear();
            //检测是否含有session
            if (context.Session.Count < 5)
            {
                //跳转
                context.Response.Redirect("/Account/Login", true);
                //停止加载后续内容
                context.Response.End();
                //直接返回
                return;
            }
            //执行基类的方法
            if (!base.CheckIsLogin(context))
            {
                return;
            }
            //用户传入的参数
            string prevDeptName = context.Request["pdept"];
            //检测参数
            if (prevDeptName == null || prevDeptName.Trim().Length <= 0)
            {
                prevDeptName = "%";
            }
            //当前使用的查询表的类型
            var parTable = ParameterTable.None;
            //用户传入的参数
            string tabType = context.Request["ttype"];
            //转换后的结果
            int iType;
            //检测参数
            if (tabType == null || tabType.Trim().Length <= 0
                || !int.TryParse(tabType, out iType) || iType < 1 || iType > 4
            )
            {
                return;
            }
            //设置tab的值得
            parTable = (ParameterTable)iType;

            //当前使用的查询参数类型
            var parField = ParameterField.None;
            //用户传入的参数
            string lotId = context.Request["lid"];
            string productNum = string.Empty;
            //检测lot卡号
            if (lotId != null && lotId.Length > 0)
            {
                //查询字段类型为生产编号
                parField = ParameterField.LotId;
                //去掉空格
                lotId = lotId.Trim();
                //检测lot卡号重新设置参数值
                if (!lotId.Contains("-"))
                {
                    //添加减号
                    lotId = "-" + lotId;
                }
                //使用模糊查询
                lotId = "%" + lotId + "%";
            }
            else
            {
                //用户传入的生产编号
                productNum = context.Request["pnum"];
                if (productNum != null && productNum.Length > 0)
                {
                    //查询字段类型为生产编号
                    parField = ParameterField.ProductNum;
                    //设置参数值
                    productNum = "%" + productNum.Trim() + "%";
                }
            }
            //当前未使用特定的三种字段类型之一进行查询则不输出值直接退出
            if (parField == ParameterField.None)
            {
                return;
            }

            //待输出到浏览器的数据
            string strResult = string.Empty;
            //将查询到的结果保存到泛型变量中
            var l = new List<LotCardLiItem>();
            //检测查询表的类型
            switch (parTable)
            {
                //在待入库记录中查询
                case ParameterTable.Wait:
                    //数据适配器
                    using (var da = new t_complete_lot_card_waitTableAdapter())
                    {
                        //获取数据使用的表
                        DataSetCompleteWait.t_complete_lot_card_waitDataTable tab;
                        //通过lot卡号查询
                        if (parField == ParameterField.LotId)
                        {
                            //取得数据
                            tab = da.GetDataLikePrevDeptAndLotId(prevDeptName, lotId);
                        }
                        //通过生产编号查询
                        else
                        {
                            //取得数据
                            tab = da.GetDataLikePrevDeptAndProductNum(prevDeptName, productNum);
                        }
                        //获取单据数据
                        AddLotCardListItem(tab, ref l);
                    }
                    //退出switch
                    break;
                case ParameterTable.Balance:
                    //数据适配器
                    using (var da = new t_complete_lot_card_balanceTableAdapter())
                    {
                        //获取数据使用的表
                        DataSetCompleteBalance.t_complete_lot_card_balanceDataTable tab;
                        //通过lot卡号查询
                        if (parField == ParameterField.LotId)
                        {
                            //取得数据
                            tab = da.GetDataLikePrevDeptAndLotId(prevDeptName, lotId);
                        }
                        //通过生产编号查询
                        else
                        {
                            //取得数据
                            tab = da.GetDataLikePrevDeptAndProductNum(prevDeptName, productNum);
                        }
                        //获取单据数据
                        AddLotCardListItem(tab, ref l);
                    }
                    //退出switch
                    break;
                case ParameterTable.Lose:
                    //数据适配器
                    using (var da = new v_complete_lot_card_loseTableAdapter())
                    {
                        //获取数据使用的表
                        DataSetCompleteLose.v_complete_lot_card_loseDataTable tab;
                        //通过lot卡号查询
                        if (parField == ParameterField.LotId)
                        {
                            //取得数据
                            tab = da.GetDataLikePrevDeptAndLotId(prevDeptName, lotId);
                        }
                        //通过生产编号查询
                        else
                        {
                            //取得数据
                            tab = da.GetDataLikePrevDeptAndProductNum(prevDeptName, productNum);
                        }
                        //获取单据数据
                        AddLotCardListItem(tab, ref l);
                    }
                    //退出switch
                    break;
            }
            //如果在清单中查询到数据
            if (l.Count > 0)
            {
                //将泛型变量各项目放入数组
                var itms = new LotCardLiItem[l.Count];
                //复制泛型变量的内容到数组
                l.CopyTo(itms);
                //循环重新设置单只数
                foreach (var itm in itms)
                {
                    //将实例加入li
                    strResult += itm.ToString();
                }
            }
            //加入ul头尾
            strResult = "<ul>\n" + strResult + "</ul>\n";
            //写入数据
            context.Response.Write(strResult);
        }
 //根据传入的参数处理事情
 public void ProcessRequest(HttpContext context)
 {
     //清空之前数据
     context.Response.Clear();
     //检测是否含有session
     if (context.Session.Count < 5)
     {
         //跳转
         context.Response.Redirect("/Account/Login", true);
         //停止加载后续内容
         context.Response.End();
         //直接返回
         return;
     }
     //执行基类的方法
     if (!base.CheckIsLogin(context))
     {
         return;
     }
     //用户传入的样板编号
     string proNum = context.Request["pnum"];
     //检测样板编号
     if (proNum == null || proNum.Length == 0)
     {
         context.Response.Write("未提供样板编号参数!");
         return;
     }
     //用户传入的送货单编号
     string billNum = context.Request["bnum"];
     //检测送货单编号
     if (billNum == null || billNum.Length == 0)
     {
         billNum = string.Empty;
     }
     //用户传入的已经存在的lot卡和数量
     string lotCardList = context.Request["lotlist"];
     //检测lot卡和数量
     if (lotCardList == null || lotCardList.Length == 0)
     {
         lotCardList = string.Empty;
     }
     //转换字符串
     lotCardList = lotCardList.Replace("|l|", "<").Replace("|g|", ">");
     //将查询到的结果保存到字典变量中
     var dic = new Dictionary<string, LiItem>();
     //数据适配器
     using (var da = new t_complete_lot_card_waitTableAdapter())
     {
         //获取数据
         var tab = da.GetDataByProductNum(proNum);
         //获取当前送货单中的lot卡清单
         var tabDeliveryLotCard = new DataSetSampleDeliveryBillMgr.t_delivery_bill_lot_card_sampleDataTable();
         //传入的送货单号大于0才获取之前该送货单的交货lot卡清单
         if (billNum.Length > 0)
         {
             //数据适配器获取之前的清单
             using (var daDeliveryLotCard = new t_delivery_bill_lot_card_sampleTableAdapter())
             {
                 daDeliveryLotCard.FillByBillNum(tabDeliveryLotCard, billNum);
             }
         }
         //获取单据数据
         AddBalanceLotListItem(tab, ref dic, lotCardList, tabDeliveryLotCard);
     }
     //待输出到浏览器的数据
     //表格的行
     string strResult = string.Empty;
     //将数据遍历写入页面
     if (dic.Count <= 0)
     {
         //显示未找到数据
         strResult = "在待入仓清单中未找到该样板编号的lot卡数据!";
     }
     else
     {
         //实例化stringbuild类
         var sb = new StringBuilder();
         //加入全选按钮
         sb.Append("<input class='selectalllotcardbtn lotcardcmdbtn' type='button' value='全选/全不选' />");
         //加入自动识别扣数按钮
         sb.Append("<input class='autolotcardbtn lotcardcmdbtn' type='button' value='智能识别' title='根据该样板编号输入的总数量自动填写' />");
         //加入筛选按钮
         sb.Append("<input class='filterlotcardtb' type='text' />");
         sb.Append("<input class='filterlotcardbtn lotcardcmdbtn' type='button' value='着色筛选' />");
         //加入确认按钮
         sb.Append("<input class='acceptlotcardbtn lotcardcmdbtn' type='button' value='确认(A)' accesskey='A' title='也可按Alt+A执行' />");
         sb.Append("<hr />\n");
         //加入表格table头
         sb.Append("<table class='lotcardlisttab'>\n");
         sb.Append("<tbody>\n");
         //当前行第几张lot卡
         int iCountLot = 0;
         //循环设置取得的lot卡清单
         foreach (var itm in dic)
         {
             //记录当前行第几张lot卡
             iCountLot++;
             //第一张lot卡则加入表格tr头
             if (iCountLot == 1)
             {
                 sb.Append("<tr>\n");
             }
             //将实例加入项目
             sb.Append(itm.Value.ToString());
             //如果是第3张lot卡则换行
             if (iCountLot == 4)
             {
                 sb.Append("</tr>\n");
                 //初始为第一张lot卡
                 iCountLot = 0;
             }
         }
         //如果不是第3张lot卡则加入tr结尾符
         if (!sb.ToString().EndsWith("</tr>\n"))
         {
             sb.Append("</tr>\n");
         }
         //加入表格table尾
         sb.Append("</tbody>\n");
         sb.Append("</table>\n");
         //取得最终结果
         strResult = sb.ToString();
     }
     //写入数据
     context.Response.Write(strResult);
 }
예제 #4
0
        /// <summary>
        /// 根据输入的参数值来执行更新数据
        /// </summary>
        /// <param name="e">传入的带有数据的事件参数</param>
        /// <returns></returns>
        private bool UpdateData(FormViewUpdateEventArgs e)
        {
            //数据适配器
            //当前添加语句对象
            //当前数据库连接
            using (var da = new v_complete_lot_card_inTableAdapter())
            using (var conn = da.Connection)
            {
                //打开数据库连接
                conn.Open();
                //开启事务
                using (var tran = conn.BeginTransaction())
                {
                    //设置事务
                    da.Transaction = tran;
                    //试运行
                    try
                    {
                        //部门名称
                        string procName = e.OldValues["proc_name"].ToString();
                        //当前行单号
                        string billNum = Convert.ToString(e.Keys[0]);
                        //获取数据
                        using (var tab = da.GetDataByBillNum(billNum))
                        {
                            //检查是否获取到行
                            if (tab.Rows.Count == 0)
                            {
                                //显示失败
                                throw new Exception("当前记录已经被其他用户删除!");
                            }
                            //数据适配器
                            using (var daHead = new t_complete_lot_card_in_headTableAdapter())
                            using (var daContent = new t_complete_lot_card_in_contentTableAdapter())
                            using (var daBalance = new t_complete_lot_card_balanceTableAdapter())
                            using (var daWait = new t_complete_lot_card_waitTableAdapter())
                            {
                                //设置数据库连接
                                daHead.Connection = daContent.Connection = daBalance.Connection = daWait.Connection = conn;
                                //设置事务
                                daHead.Transaction = daContent.Transaction = daBalance.Transaction = daWait.Transaction = tran;
                                //将之前的单据内容写回
                                foreach (DataSetCompleteIn.v_complete_lot_card_inRow row in tab.Rows)
                                {
                                    //从成品结存清单中扣除
                                    if (!ydOperateCompleteLotCard.DecreaseCompleteBalance(
                                        daBalance,
                                        row.prev_proc_name,
                                        row.lot_id,
                                        row.pnl_qty,
                                        row.pcs_qty
                                    ))
                                    {
                                        return false;
                                    }
                                    //插入到待入库清单
                                    daWait.InsertData(
                                        row.prev_proc_name,
                                        row.proc_name,
                                        row.lot_id,
                                        row.product_num,
                                        row.pnl_qty,
                                        row.pcs_qty,
                                        row.remark,
                                        Session["user_name"].ToString()
                                    );
                                }
                                //从单据内容中删除
                                daContent.DeleteByBillNum(billNum);
                                //从单据表头中删除
                                daHead.Delete(billNum);

                                //日期
                                DateTime billDate = Convert.ToDateTime(e.NewValues["bill_date"]);
                                //上部门
                                string prevProcName = Convert.ToString(e.NewValues["prev_proc_name"]);
                                //单据备注
                                string billRemark = Convert.ToString(e.NewValues["remark"]);
                                //录入员
                                string addPerson = e.NewValues["add_person"].ToString();
                                //录入时间
                                DateTime addTime = Convert.ToDateTime(e.NewValues["add_time"]);
                                //最后修改时间
                                DateTime lastChangeTime = Convert.ToDateTime(e.NewValues["last_change_time"]);
                                //保存表头
                                daHead.Insert(
                                    billDate,
                                    billNum,
                                    prevProcName,
                                    procName,
                                    billRemark,
                                    addPerson,
                                    addTime,
                                    lastChangeTime
                                );
                                //遍历子表执行保存
                                for (int iRow = 0; iRow < 10; iRow++)
                                {
                                    //子表各控件
                                    var tr = tabDataListSon.Rows[iRow + 1];
                                    var litRowId = (Literal)tr.Cells[0].Controls[0];
                                    var txtLotId = (TextBox)tr.Cells[1].Controls[0];
                                    var txtProductNum = (TextBox)tr.Cells[2].Controls[0];
                                    var txtPnlQty = (TextBox)tr.Cells[3].Controls[0];
                                    var txtPcsQty = (TextBox)tr.Cells[4].Controls[0];
                                    var txtRemark = (TextBox)tr.Cells[5].Controls[0];
                                    //取得数据
                                    byte rowId = Convert.ToByte(litRowId.Text);
                                    string lotId = txtLotId.Text;
                                    string productNum = txtProductNum.Text;
                                    int pnlQty = txtPnlQty.Text.Trim().Length <= 0 ? 0 : int.Parse(txtPnlQty.Text.Trim());
                                    int pcsQty = txtPcsQty.Text.Trim().Length <= 0 ? 0 : int.Parse(txtPcsQty.Text.Trim());
                                    string remark = txtRemark.Text;
                                    //存在数据才保存
                                    if (lotId.Length > 0 && productNum.Length > 0 && pnlQty + pcsQty > 0)
                                    {
                                        //保存到单据内容清单
                                        daContent.Insert(
                                            billNum,
                                            rowId,
                                            lotId,
                                            productNum,
                                            pnlQty,
                                            pcsQty,
                                            remark
                                        );
                                        //保存到成品结存清单
                                        daBalance.InsertData(
                                            prevProcName,
                                            procName,
                                            lotId,
                                            productNum,
                                            pnlQty,
                                            pcsQty,
                                            remark,
                                            addPerson
                                        );
                                        //从待入库清单中扣除
                                        if (!ydOperateCompleteLotCard.DecreaseCompleteWait(
                                            daWait,
                                            prevProcName,
                                            lotId,
                                            pnlQty,
                                            pcsQty
                                        ))
                                        {
                                            return false;
                                        }
                                    }
                                }
                            }
                        }
                        //提交事务
                        tran.Commit();
                        //返回成功
                        return true;
                    }
                    catch (Exception ex)
                    {
                        //回滚事务
                        tran.Rollback();
                        //非数字返回失败
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
예제 #5
0
 /// <summary>
 /// 执行递归扣取待入库数据
 /// </summary>
 /// <param name="daWait">操作结存表的数据适配器</param>
 /// <param name="prevProcName">上部门名称</param>
 /// <param name="lotId">批量卡序号</param>
 /// <param name="pnlQty">pnl数量</param>
 /// <param name="pcsQty">pcs数量</param>
 /// <returns></returns>
 internal static bool DecreaseCompleteWait(
     t_complete_lot_card_waitTableAdapter daWait,
     string prevProcName,
     string lotId,
     int pnlQty,
     int pcsQty
 )
 {
     try
     {
         //检测是否数量不正确
         if (pnlQty < 0 || pcsQty < 0)
         {
             throw new Exception("待扣减的pnl数量和pcs数量都不能同时小于0!");
         }
         if (pnlQty > 0 && pcsQty > 0)
         {
             throw new Exception("待扣减的pnl数量和pcs数量不能同时大于0!");
         }
         if (pnlQty + pcsQty <= 0)
         {
             throw new Exception("待扣减的pnl数量和pcs数量不能同时为0!");
         }
         //扣减后剩余数量
         int iQty;
         //执行扣取已入库批量卡余数
         if (pnlQty > 0)
         {
             //扣减后剩余数量
             iQty = UpdateWaitPnlQtyByPrevProcAndLotId(
                 daWait.Transaction,
                 prevProcName,
                 lotId,
                 pnlQty
             );
         }
         else
         {
             //扣减后剩余数量
             iQty = UpdateWaitPcsQtyByPrevProcAndLotId(
                 daWait.Transaction,
                 prevProcName,
                 lotId,
                 pcsQty
             );
         }
         //检测是否需要递归扣数
         if (iQty < 0)
         {
             //重设待扣减数量
             pnlQty = pnlQty > 0 ? -iQty : 0;
             pcsQty = pnlQty > 0 ? 0 : -iQty;
             //执行递归扣减
             if (!DecreaseCompleteWait(
                 daWait,
                 prevProcName,
                 lotId,
                 pnlQty,
                 pcsQty
             ))
             {
                 return false;
             };
         }
         else
         {
             //删除小于或等于0的记录清单
             daWait.DeleteEmptyData();
         }
         //返回成功
         return true;
     }
     catch (Exception ex)
     {
         //抛出错误
         throw new Exception("执行扣减成品待入库记录数时发生错误:\n" + ex.Message);
     }
 }
예제 #6
0
 /// <summary>
 /// 执行删除数据并处理相关数据一致性
 /// </summary>
 /// <param name="e">传入的带有数据的事件参数</param>
 /// <returns></returns>
 private bool DeleteData(FormViewDeleteEventArgs e)
 {
     //当前单号
     string billNum = Convert.ToString(e.Keys[0]);
     //数据适配器
     //当前数据库连接
     //当前更新语句对象
     using (var da = new v_complete_lot_card_inTableAdapter())
     using (var conn = da.Connection)
     {
         //打开数据库连接
         conn.Open();
         //开启事务
         using (var tran = conn.BeginTransaction())
         {
             //试运行
             try
             {
                 //设置事务
                 da.Transaction = tran;
                 //获取数据
                 var tab = da.GetDataByBillNum(billNum);
                 //检查是否获取到行
                 if (tab.Rows.Count == 0)
                 {
                     //显示失败
                     throw new Exception("当前记录已经被其他用户删除!");
                 }
                 //数据适配器
                 using (var daHead = new t_complete_lot_card_in_headTableAdapter())
                 using (var daContent = new t_complete_lot_card_in_contentTableAdapter())
                 using (var daBalance = new t_complete_lot_card_balanceTableAdapter())
                 using (var daWait = new t_complete_lot_card_waitTableAdapter())
                 {
                     //设置数据库连接
                     daHead.Connection = daContent.Connection = daBalance.Connection = daWait.Connection = conn;
                     //设置事务
                     daHead.Transaction = daContent.Transaction = daBalance.Transaction = daWait.Transaction = tran;
                     //将之前的单据内容写回
                     foreach (DataSetCompleteIn.v_complete_lot_card_inRow row in tab.Rows)
                     {
                         //从成品结存清单中扣除
                         if (ydOperateCompleteLotCard.DecreaseCompleteBalance(
                             daBalance,
                             row.prev_proc_name,
                             row.lot_id,
                             row.pnl_qty,
                             row.pcs_qty
                         ))
                         {
                             return false;
                         }
                         //插入到待入库清单
                         daWait.InsertData(
                             row.prev_proc_name,
                             row.proc_name,
                             row.lot_id,
                             row.product_num,
                             row.pnl_qty,
                             row.pcs_qty,
                             row.remark,
                             Session["user_name"].ToString()
                         );
                     }
                     //从单据内容中删除
                     daContent.DeleteByBillNum(billNum);
                     //从单据表头中删除
                     daHead.Delete(billNum);
                 }
                 //提交事务
                 tran.Commit();
                 //返回成功
                 return true;
             }
             catch (Exception ex)
             {
                 //回滚事务
                 tran.Rollback();
                 //非数字返回失败
                 throw new Exception(ex.Message);
             }
         }
     }
 }
예제 #7
0
 /// <summary>
 /// 根据输入的LOT格式来保存多条数据到数据库
 /// </summary>
 /// <param name="e">传入的带有数据的事件参数</param>
 /// <param name="procName">当前部门名称</param>
 /// <returns></returns>
 private bool InsertData(FormViewInsertEventArgs e, string procName)
 {
     //日期
     DateTime billDate = Convert.ToDateTime(e.Values["bill_date"]);
     //单号
     string billNum = Convert.ToString(e.Values["bill_num"]);
     //上部门
     string prevProcName = Convert.ToString(e.Values["prev_proc_name"]);
     //单据备注
     string billRemark = Convert.ToString(e.Values["remark"]);
     //录入员
     string addPerson = e.Values["add_person"].ToString();
     //录入时间
     DateTime addTime = Convert.ToDateTime(e.Values["add_time"]);
     //最后修改时间
     DateTime lastChangeTime = Convert.ToDateTime(e.Values["last_change_time"]);
     //数据适配器
     //当前添加语句对象
     //当前数据库连接
     using (var daHead = new t_complete_lot_card_in_headTableAdapter())
     using (var daContent = new t_complete_lot_card_in_contentTableAdapter())
     using (var daBalance = new t_complete_lot_card_balanceTableAdapter())
     using (var daWait = new t_complete_lot_card_waitTableAdapter())
     using (var conn = daHead.Connection)
     {
         //打开数据库连接
         conn.Open();
         //开启事务
         using (var tran = conn.BeginTransaction())
         {
             //设置数据库连接对象
             daContent.Connection = daBalance.Connection = daWait.Connection = conn;
             //设置事务
             daHead.Transaction = daContent.Transaction = daBalance.Transaction = daWait.Transaction = tran;
             //试运行
             try
             {
                 //保存表头
                 daHead.Insert(
                     billDate,
                     billNum,
                     prevProcName,
                     procName,
                     billRemark,
                     addPerson,
                     addTime,
                     lastChangeTime
                 );
                 //遍历子表执行保存
                 for (int iRow = 0; iRow < 10; iRow++)
                 {
                     //子表各控件
                     var tr = tabDataListSon.Rows[iRow + 1];
                     var litRowId = (Literal)tr.Cells[0].Controls[0];
                     var txtLotId = (TextBox)tr.Cells[1].Controls[0];
                     var txtProductNum = (TextBox)tr.Cells[2].Controls[0];
                     var txtPnlQty = (TextBox)tr.Cells[3].Controls[0];
                     var txtPcsQty = (TextBox)tr.Cells[4].Controls[0];
                     var txtRemark = (TextBox)tr.Cells[5].Controls[0];
                     //取得数据
                     byte rowId = Convert.ToByte(litRowId.Text);
                     string lotId = txtLotId.Text;
                     string productNum = txtProductNum.Text;
                     int pnlQty = txtPnlQty.Text.Trim().Length <= 0 ? 0 : int.Parse(txtPnlQty.Text.Trim());
                     int pcsQty = txtPcsQty.Text.Trim().Length <= 0 ? 0 : int.Parse(txtPcsQty.Text.Trim());
                     string remark = txtRemark.Text;
                     //存在数据才保存
                     if (lotId.Length > 0 && productNum.Length > 0 && pnlQty + pcsQty > 0)
                     {
                         //保存到单据内容清单
                         daContent.Insert(
                             billNum,
                             rowId,
                             lotId,
                             productNum,
                             pnlQty,
                             pcsQty,
                             remark
                         );
                         //保存到成品结存清单
                         daBalance.InsertData(
                             prevProcName,
                             procName,
                             lotId,
                             productNum,
                             pnlQty,
                             pcsQty,
                             remark,
                             addPerson
                         );
                         //从待入库清单中扣除
                         if (!ydOperateCompleteLotCard.DecreaseCompleteWait(
                             daWait,
                             prevProcName,
                             lotId,
                             pnlQty,
                             pcsQty
                         ))
                         {
                             return false;
                         }
                     }
                 }
                 //提交事务
                 tran.Commit();
                 //返回成功
                 return true;
             }
             catch (Exception ex)
             {
                 //回滚事务
                 tran.Rollback();
                 //非数字返回失败
                 throw new Exception(ex.Message);
             }
         }
     }
 }
예제 #8
0
 protected void fvCompleteInAdd_DataBound(object sender, EventArgs e)
 {
     //设置单据清单可见
     tabDataListSon.Visible = true;
     //清空入库单内容清单
     for (int i = 0; i < 10; i++)
     {
         //清空清单数据到控件
         ClearBillContent(i);
     }
     //新增状态
     switch (fvCompleteInAdd.CurrentMode)
     {
         //新增状态
         case FormViewMode.Insert:
             //当前单号文本框
             var tb = (TextBox)fvCompleteInAdd.FindControl("txtBillDate");
             if (tb != null)
             {
                 //检查用户提供的单据日期参数标识
                 string strBillDate = Request["bdate"];
                 DateTime billDate;
                 if (strBillDate != null && strBillDate.Length > 0 &&
                     DateTime.TryParse(strBillDate, out billDate))
                 {
                     //设置默认单据日期为传入的日期
                     tb.Text = billDate.ToString("yyyy-MM-dd");
                 }
                 else
                 {
                     //设置默认单据日期为当前日期
                     tb.Text = DateTime.Now.ToString("yyyy-MM-dd");
                 }
             }
             //当前单号文本框
             tb = (TextBox)fvCompleteInAdd.FindControl("txtBillNum");
             if (tb != null)
             {
                 //户提供的单号参数标识
                 string strBillNum = Request["bnum"];
                 Int64 billNum;
                 if (strBillNum != null && strBillNum.Trim().Length >= 12 &&
                     Int64.TryParse(strBillNum, out billNum))
                 {
                     //设置默认单号为传入的单号加1
                     tb.Text = (billNum + 1).ToString();
                 }
                 else
                 {
                     //当前单号前缀字符串
                     string billNumPrefix = DateTime.Now.ToString("yyyyMMdd");
                     //数据适配器
                     using (var da = new t_complete_lot_card_in_headTableAdapter())
                     {
                         //获取已经使用的最大单号
                         string maxBillNum = da.GetMaxBillNumLikeBillNum(billNumPrefix + "%").ToString();
                         //检测取得的值
                         if (maxBillNum.Trim().Length < 12)
                         {
                             //执行转换
                             billNum = Int64.Parse(billNumPrefix + "0001");
                             //设置默认单号为传入的单号加1
                             tb.Text = billNum.ToString();
                         }
                         else
                         {
                             //执行转换
                             billNum = Int64.Parse(maxBillNum);
                             //设置默认单号为传入的单号加1
                             tb.Text = (billNum + 1).ToString();
                         }
                     }
                 }
             }
             //上部门名称文本框
             tb = (TextBox)fvCompleteInAdd.FindControl("txtPrevProcName");
             if (tb != null)
             {
                 //检查用户提供的部门名称参数标识
                 string prevProc = Request["pproc"];
                 if (prevProc != null && prevProc.Length > 0)
                 {
                     //设置默认部门名称
                     tb.Text = prevProc;
                 }
                 else
                 {
                     //设置默认部门名称
                     tb.Text = "包装";
                 }
             }
             //当前部门名称
             var lit = (Literal)fvCompleteInAdd.FindControl("litProcName");
             if (lit != null)
             {
                 //session中保存的当前部门
                 string procName = Session["proc_name"].ToString();
                 //写入到客户端
                 lit.Text = procName;
             }
             //获取是否传入了多个待入库表的id值
             string strIdAll = Request["ids"];
             if (strIdAll != null && strIdAll.Trim().Length > 0)
             {
                 //分解出id号
                 string[] strIds = strIdAll.Split(new char[] { '|' }, 10, StringSplitOptions.RemoveEmptyEntries);
                 //检测id号数量
                 if (strIds.Length > 0)
                 {
                     //待入库表数据适配器
                     using (var da = new t_complete_lot_card_waitTableAdapter())
                     {
                         //当前子表行索引
                         int iRow = 0;
                         //逐行获取数据
                         foreach (var strId in strIds)
                         {
                             //检测id
                             Int64 id;
                             if (Int64.TryParse(strId, out id))
                             {
                                 //取得数据
                                 var tab = da.GetDataById(id);
                                 //检测有无数据
                                 if (tab.Rows.Count > 0)
                                 {
                                     //首行数据
                                     var row = (DataSetCompleteWait.t_complete_lot_card_waitRow)tab.Rows[0];
                                     //写入清单数据到控件
                                     SetBillContent(row, iRow);
                                     //行号加1
                                     iRow++;
                                 }
                             }
                         }
                     }
                 }
             }
             break;
         case FormViewMode.Edit:
         case FormViewMode.ReadOnly:
             //设置单据清单不可见
             tabDataListSon.Visible = false;
             //通过入库单号获取数据清单
             //取得传入的入库单号
             string billNum2 = Request["bnum"];
             if (billNum2 != null && billNum2.Length > 0)
             {
                 //获取清单
                 using (var daContent = new t_complete_lot_card_in_contentTableAdapter())
                 {
                     //获取数据
                     var tabContent = daContent.GetDataByBillNum(billNum2);
                     //检测是否找到数据
                     if (tabContent.Rows.Count > 0)
                     {
                         //设置单据清单可见
                         tabDataListSon.Visible = true;
                         //把内容写入页面
                         foreach (DataSetCompleteIn.t_complete_lot_card_in_contentRow row in tabContent.Rows)
                         {
                             //当前行号
                             int i = row.row_id - 1;
                             //写入清单数据到控件
                             SetBillContent(row, i);
                         }
                     }
                 }
             }
             break;
     }
     //当前批量卡号文本框获取焦点
     var tb2 = (TextBox)fvCompleteInAdd.FindControl("txtLotId0");
     if (tb2 != null)
     {
         //设置焦点
         tb2.Focus();
     }
 }
예제 #9
0
 /// <summary>
 /// 根据单号从数据库中删除单据的表头和内容
 /// </summary>
 /// <param name="billNum">单据号</param>
 private bool DeleteBillByBillNum(string billNum)
 {
     //实例化数据适配器
     using (var da = new v_complete_lot_card_inTableAdapter())
     //取得数据库连接
     using (var conn = da.Connection)
     {
         //打开数据库连接
         conn.Open();
         //事务
         using (var tran = conn.BeginTransaction())
         {
             //设置事务
             da.Transaction = tran;
             try
             {
                 //取得之前入库单清单记录
                 var tab = da.GetDataByBillNum(billNum);
                 //检测是否存在数据
                 if (tab.Rows.Count > 0)
                 {
                     //单据表头行、内容行、成品结存和待入库数据适配器
                     using (var daHead = new t_complete_lot_card_in_headTableAdapter())
                     using (var daContent = new t_complete_lot_card_in_contentTableAdapter())
                     using (var daBalance = new t_complete_lot_card_balanceTableAdapter())
                     using (var daWait = new t_complete_lot_card_waitTableAdapter())
                     {
                         //设置连接对象
                         daHead.Connection = daContent.Connection = daBalance.Connection = daWait.Connection = tran.Connection;
                         //设置事务
                         daHead.Transaction = daContent.Transaction = daBalance.Transaction = daWait.Transaction = tran;
                         //遍历行执行删除各行的结存记录和写回待入库记录
                         foreach (DataSetCompleteIn.v_complete_lot_card_inRow row in tab.Rows)
                         {
                             //执行扣减结存
                             ydOperateCompleteLotCard.DecreaseCompleteBalance(
                                 daBalance,
                                 row.prev_proc_name,
                                 row.lot_id,
                                 row.pnl_qty,
                                 row.pcs_qty
                             );
                             //执行插入待入库记录
                             daWait.InsertData(
                                 row.prev_proc_name,
                                 row.proc_name,
                                 row.lot_id,
                                 row.product_num,
                                 row.pnl_qty,
                                 row.pcs_qty,
                                 row.remark,
                                 row.add_person
                             );
                         }
                         //根据入库单号删除全部入库内容记录
                         daContent.DeleteByBillNum(billNum);
                         //根据入库单号删除全部入库表头记录
                         daHead.Delete(billNum);
                     }
                 }
                 //提交事务
                 tran.Commit();
                 //返回成功
                 return true;
             }
             catch (Exception ex)
             {
                 //回滚事务
                 tran.Rollback();
                 //抛出错误
                 throw new Exception("删除入库单记录出现错误:\n" + ex.Message);
             }
         }
     }
 }
예제 #10
0
 /// <summary>
 /// 执行删除数据并处理相关数据一致性
 /// </summary>
 /// <param name="e">传入的带有数据的事件参数</param>
 /// <returns></returns>
 private bool DeleteData(ListViewDeleteEventArgs e)
 {
     //实例化数据适配器
     using (var da = new v_complete_lot_card_inTableAdapter())
     //取得数据库连接
     using (var conn = da.Connection)
     {
         //打开数据库连接
         conn.Open();
         //事务
         using (var tran = conn.BeginTransaction())
         {
             //设置事务
             da.Transaction = tran;
             try
             {
                 //当前入库单号
                 string billNum = e.Keys[0].ToString();
                 //当前行号
                 byte rowId = Convert.ToByte(e.Keys[1]);
                 //取得该条入库单清单记录
                 var tab = da.GetDataByBillNumAndRowId(billNum, rowId);
                 //检测是否存在数据
                 if (tab.Rows.Count <= 0)
                 {
                     throw new Exception(string.Format("当前单据:\n单号:{0}\n行号:{1}\n已经被其他用户删除!", billNum, rowId));
                 }
                 //单据内容、成品结存和待入库数据适配器
                 using (var daContent = new t_complete_lot_card_in_contentTableAdapter())
                 using (var daBalance = new t_complete_lot_card_balanceTableAdapter())
                 using (var daWait = new t_complete_lot_card_waitTableAdapter())
                 {
                     //设置连接对象
                     daContent.Connection = daBalance.Connection = daWait.Connection = tran.Connection;
                     //设置事务
                     daContent.Transaction = daBalance.Transaction = daWait.Transaction = tran;
                     //遍历行执行删除各行的结存记录和写回待入库记录
                     foreach (DataSetCompleteIn.v_complete_lot_card_inRow row in tab.Rows)
                     {
                         //执行扣减结存
                         ydOperateCompleteLotCard.DecreaseCompleteBalance(
                             daBalance,
                             row.prev_proc_name,
                             row.lot_id,
                             row.pnl_qty,
                             row.pcs_qty
                         );
                         //执行插入待入库记录
                         daWait.InsertData(
                             row.prev_proc_name,
                             row.proc_name,
                             row.lot_id,
                             row.product_num,
                             row.pnl_qty,
                             row.pcs_qty,
                             row.remark,
                             row.add_person
                         );
                     }
                     //根据入库单号和行号删除入库记录
                     daContent.Delete(billNum, rowId);
                     //检测当前入库记录内容行数
                     int? iCount = daContent.CountByBillNum(billNum);
                     if (iCount.HasValue && iCount.Value <= 0)
                     {
                         //表头适配器
                         using (var daHead = new t_complete_lot_card_in_headTableAdapter())
                         {
                             //删除表头
                             daHead.Delete(billNum);
                         }
                     }
                 }
                 //提交事务
                 tran.Commit();
                 //返回成功
                 return true;
             }
             catch (Exception ex)
             {
                 //回滚事务
                 tran.Rollback();
                 //抛出错误
                 throw new Exception("删除入库单记录出现错误:\n" + ex.Message);
             }
         }
     }
 }
예제 #11
0
 /// <summary>
 /// 添加一条部门未完成lot卡或者到成品仓
 /// </summary>
 /// <param name="tran">当前事务</param>
 /// <param name="e">包含有数据列表值的事件参数</param>
 /// <param name="isUpdatedBalance">是否扣过部门结存</param>
 /// <returns></returns>
 internal static bool InsertOneRecordToLotCardBalance(
     SqlTransaction tran,
     FormViewUpdateEventArgs e,
     bool isUpdatedBalance
 )
 {
     //当前数据库连接对象
     var conn = tran.Connection;
     try
     {
         //要插入到的部门名称
         string nextDeptName = e.NewValues["next_dept_name"].ToString();
         //检测当前部门
         if (nextDeptName == "成品仓")
         {
             //实例化数据适配器
             using (var da = new t_complete_lot_card_waitTableAdapter())
             using (var cmd = da.Adapter.InsertCommand)
             {
                 //设置数据库连接
                 da.Connection = conn;
                 //设置事务
                 da.Transaction = tran;
                 //设置超时
                 cmd.CommandTimeout = 50;
                 //设置参数值
                 cmd.Parameters.Clear();
                 cmd.Parameters.AddWithValue("@prev_dept_name", e.NewValues["dept_name"]);
                 cmd.Parameters.AddWithValue("@dept_name", nextDeptName);
                 cmd.Parameters.AddWithValue("@lot_id", e.NewValues["lot_id"]);
                 cmd.Parameters.AddWithValue("@product_num", e.NewValues["product_num"]);
                 cmd.Parameters.AddWithValue("@pnl_qty", e.NewValues["pnl_qty"]);
                 cmd.Parameters.AddWithValue("@pcs_qty", e.NewValues["pcs_qty"]);
                 cmd.Parameters.AddWithValue("@remark", DBNull.Value);
                 cmd.Parameters.AddWithValue("@add_person", e.NewValues["add_person"]);
                 cmd.Parameters.AddWithValue("@add_time", e.NewValues["add_time"]);
                 cmd.Parameters.AddWithValue("@last_change_time", e.NewValues["last_change_time"]);
                 //执行查询
                 if (cmd.ExecuteNonQuery() == 0)
                 {
                     //抛出错误
                     throw new Exception("添加数据到下部门结存lot卡失败!");
                 }
             }
         }
         else
         {
             //实例化数据适配器
             using (var da = new t_dept_lot_card_balanceTableAdapter())
             using (var cmd = da.Adapter.InsertCommand)
             {
                 //设置数据库连接
                 da.Connection = conn;
                 //设置事务
                 da.Transaction = tran;
                 //设置超时
                 cmd.CommandTimeout = 50;
                 //设置参数值
                 cmd.Parameters.Clear();
                 //当前部门
                 string deptName = HttpContext.Current.Session["dept_name"].ToString();
                 if (deptName == "MRB")
                 {
                     cmd.Parameters.AddWithValue("@prev_dept_name", "MRB");
                     cmd.Parameters.AddWithValue("@dept_name", e.NewValues["dept_name"]);
                 }
                 else
                 {
                     cmd.Parameters.AddWithValue("@prev_dept_name", e.NewValues["dept_name"]);
                     cmd.Parameters.AddWithValue("@dept_name", nextDeptName);
                 }
                 cmd.Parameters.AddWithValue("@lot_id", e.NewValues["lot_id"]);
                 cmd.Parameters.AddWithValue("@product_num", e.NewValues["product_num"]);
                 cmd.Parameters.AddWithValue("@pnl_qty", e.NewValues["pnl_qty"]);
                 cmd.Parameters.AddWithValue("@pcs_qty", e.NewValues["pcs_qty"]);
                 cmd.Parameters.AddWithValue("@remark", DBNull.Value);
                 cmd.Parameters.AddWithValue("@is_updated_balance", isUpdatedBalance);
                 cmd.Parameters.AddWithValue("@add_person", e.NewValues["add_person"]);
                 cmd.Parameters.AddWithValue("@add_time", e.NewValues["add_time"]);
                 cmd.Parameters.AddWithValue("@last_change_time", e.NewValues["last_change_time"]);
                 //执行查询
                 if (cmd.ExecuteNonQuery() == 0)
                 {
                     //抛出错误
                     throw new Exception("添加数据到下部门结存lot卡失败!");
                 }
             }
         }
         //返回成功
         return true;
     }
     catch (Exception ex)
     {
         //抛出错误
         throw ex;
     }
 }
예제 #12
0
 /// <summary>
 /// 添加一条下部门未完成lot卡或者到成品仓记录
 /// </summary>
 /// <param name="tran">当前事务</param>
 /// <param name="nextDeptName">部门名称</param>
 /// <param name="lotId">要保存的记录中保存的lot卡号</param>
 /// <param name="e">包含有数据列表值的事件参数</param>
 /// <param name="isUpdatedBalance">是否有扣部门结存</param>
 /// <returns></returns>
 private static bool InsertOneRecordToLotCardBalance(
     SqlTransaction tran,
     string nextDeptName,
     string lotId,
     FormViewInsertEventArgs e,
     bool isUpdatedBalance
 )
 {
     //当前数据库连接对象
     var conn = tran.Connection;
     try
     {
         //查询对象
         SqlCommand cmd;
         //检测部门名称
         if (nextDeptName == "成品仓")
         {
             //实例化数据适配器
             var da = new t_complete_lot_card_waitTableAdapter();
             //设置事务
             da.Transaction = tran;
             //查询对象
             cmd = da.Adapter.InsertCommand;
         }
         else
         {
             //实例化数据适配器
             var da = new t_dept_lot_card_balanceTableAdapter();
             //设置事务
             da.Transaction = tran;
             //查询对象
             cmd = da.Adapter.InsertCommand;
         }
         //设置数据库连接
         cmd.Connection = conn;
         //设置参数和属性后保存
         using (cmd)
         {
             //设置超时
             cmd.CommandTimeout = 50;
             //设置参数值
             cmd.Parameters.Clear();
             cmd.Parameters.AddWithValue("@prev_dept_name", e.Values["dept_name"]);
             cmd.Parameters.AddWithValue("@dept_name", nextDeptName);
             cmd.Parameters.AddWithValue("@lot_id", lotId);
             cmd.Parameters.AddWithValue("@product_num", e.Values["product_num"]);
             cmd.Parameters.AddWithValue("@pnl_qty", e.Values["pnl_qty"]);
             cmd.Parameters.AddWithValue("@pcs_qty", e.Values["pcs_qty"]);
             cmd.Parameters.AddWithValue("@remark", DBNull.Value);
             cmd.Parameters.AddWithValue("@is_updated_balance", isUpdatedBalance);
             cmd.Parameters.AddWithValue("@add_person", e.Values["add_person"]);
             cmd.Parameters.AddWithValue("@add_time", e.Values["add_time"]);
             cmd.Parameters.AddWithValue("@last_change_time", e.Values["last_change_time"]);
             //执行查询
             if (cmd.ExecuteNonQuery() == 0)
             {
                 //抛出错误
                 throw new Exception("添加数据到下部门结存lot卡失败!");
             }
             //返回成功
             return true;
         }
     }
     catch (Exception ex)
     {
         //抛出错误
         throw ex;
     }
 }