protected void fvDeliveryBillMgrAddM2_ItemCreated(object sender, EventArgs e) { //设置单据清单可见 tabDataListSon.Visible = true; //清空送货单内容清单 for (int i = 0; i < 6; i++) { //写入清单数据到控件 SetBillContent(null, i); } //新增状态 switch (fvDeliveryBillMgrAddM2.CurrentMode) { case FormViewMode.Insert: //当前订单落单日期文本框 var tb = (TextBox)fvDeliveryBillMgrAddM2.FindControl("txtBillDate"); //单据日期 var dtBillDate = DateTime.Now.Date; if (tb != null) { //检查用户提供的日期参数标识 string strBillDate = Request["bdate"]; DateTime dt; if (strBillDate != null && strBillDate.Length > 0 && DateTime.TryParse(strBillDate, out dt)) { //设置日期 dtBillDate = dt; } //设置日期为当前日期 tb.Text = dtBillDate.ToString("yyyy-MM-dd"); } //最大单据号+1 tb = (TextBox)fvDeliveryBillMgrAddM2.FindControl("txtBillNum"); if (tb != null) { //获取已经使用的最大单据号 using (var da = new t_delivery_bill_headTableAdapter()) { //单据号 var strBillNum = da.GetMaxBillNumByTypeAndYear(dtBillDate.ToString(@"\P2yy\%")).ToString(); //单据编号 Int64 iBillNum; //检测有无数据 if (!string.IsNullOrWhiteSpace(strBillNum) && Int64.TryParse(strBillNum.Substring(1), out iBillNum) && iBillNum > 2160000000 ) { //设置单据号+1 iBillNum += 1; } else { //设置默认单据号 iBillNum = Int64.Parse(dtBillDate.ToString("2yy0000001")); } //设置单据号到文本框 tb.Text = string.Format("P{0}", iBillNum); } } //退出switch break; //修改或查看状态 case FormViewMode.Edit: case FormViewMode.ReadOnly: //设置单据清单不可见 tabDataListSon.Visible = false; //通过送货单号获取数据清单 //取得传入的送货单号 var strBillNum2 = Request["bnum"]; //单据编号 Int64 iBillNum2; if (!string.IsNullOrWhiteSpace(strBillNum2) && Int64.TryParse(strBillNum2.Substring(1), out iBillNum2) && iBillNum2 > 2160000000 ) { //检测是否含有该表头数据 using (var daHead = new t_delivery_bill_headTableAdapter()) { //获取数据 var tabHead = daHead.GetDataByBillNum(strBillNum2); //检测是否找到数据 if (tabHead.Rows.Count > 0) { //设置单据清单可见 tabDataListSon.Visible = true; //获取清单 using (var daContent = new t_delivery_bill_contentTableAdapter()) { //获取数据 var tabContent = daContent.GetDataByBillNum(strBillNum2); //把内容写入页面 foreach (DataSetDeliveryBillMgr.t_delivery_bill_contentRow row in tabContent.Rows) { //当前行号 int i = row.row_id - 1; //写入清单数据到控件 SetBillContent(row, i); } } } } } //退出switch break; } }
/// <summary> /// 更新保存单据的表头和内容 /// </summary> /// <param name="e">待更新的数据内容</param> private bool UpdateBill(FormViewUpdateEventArgs e) { //当前单据号 string billNum = e.Keys["bill_num"].ToString(); //实例化数据适配器 using (var daHead = new t_delivery_bill_headTableAdapter()) using (var daContent = new t_delivery_bill_contentTableAdapter()) using (var daLotCard = new t_delivery_bill_lot_cardTableAdapter()) //取得数据库连接 using (var conn = daHead.Connection) { //打开数据库连接 conn.Open(); //事务 using (var tran = conn.BeginTransaction()) { //设置数据库连接 daHead.Connection = daContent.Connection = daLotCard.Connection = conn; //设置事务 daHead.Transaction = daContent.Transaction = daLotCard.Transaction = tran; try { //记录需要检测更新首次送货记录工具费的订单序号清单 var lOrderId = new List<string>(); //取得之前单据清单记录 var tabContent = daContent.GetDataByBillNum(billNum); //遍历各行 foreach (DataSetDeliveryBillMgr.t_delivery_bill_contentRow row in tabContent.Rows) { //执行更新订单已交货数和未交货数 daContent.UpdateOrderBalanceQty(-row.pcs_qty, row.order_id); //之前是否有设置为需要记录工具费 if (!row.Isneed_tool_amountNull() && row.need_tool_amount) { //记录到清单 if (!lOrderId.Contains(row.order_id)) { lOrderId.Add(row.order_id); } } } //先执行删除原来单据 daHead.Delete(billNum); daContent.DeleteByBillNum(billNum); daLotCard.DeleteByBillNum(billNum); //保存表头内容 daHead.Insert( Convert.ToDateTime(e.NewValues["bill_date"]), Convert.ToString(e.NewValues["cust_name"]), billNum, Convert.ToString(e.NewValues["remark"]), Convert.ToString(e.NewValues["add_person"]), Convert.ToDateTime(e.NewValues["add_time"]), Convert.ToDateTime(e.NewValues["last_change_time"]) ); //循环保存表身内容 for (int i = 0; i < 6; i++) { //当前行号 byte rowId = Convert.ToByte(i + 1); //取得之前送货单当前行内容 var tab = daContent.GetDataByBillNumAndRowId(billNum, rowId); //检测是否存在数据 if (tab.Rows.Count > 0) { var row = (DataSetDeliveryBillMgr.t_delivery_bill_contentRow)tab.Rows[0]; //取得之前写入的批量卡清单 string strLotCardListOld = row.lot_id_list.Trim(); if (strLotCardListOld.Length > 0) { //取得之前写入的批量卡清单 string productNumOld = row.product_num.Trim(); //之前的批量卡清单写回 LotCardListToWaitInStoreBalance(tran, billNum, rowId, strLotCardListOld, productNumOld); //删除该条单据清单行数据 daContent.DeleteByBillNumAndRowId(billNum, rowId); } } //当前数据所在的行 var trContentRow = (TableRow)tabDataListSon.FindControl("trContentRow" + i); //获取该行生产编号 var txtProductNum = (TextBox)trContentRow.FindControl("txtProductNum" + i); //检测生产编号存在就保存该行 if (txtProductNum == null) { throw new Exception("在第 " + rowId.ToString() + " 行未找到生产编号文本框!"); } //交货数量文本框 var txtPcsQty = (TextBox)trContentRow.FindControl("txtPcsQty" + i); int iPcsQty; if (!int.TryParse(txtPcsQty.Text, out iPcsQty)) { iPcsQty = 0; } var txtFocPcsQty = (TextBox)trContentRow.FindControl("txtFocPcsQty" + i); int iFocPcsQty; if (!int.TryParse(txtFocPcsQty.Text.Trim(), out iFocPcsQty)) { iFocPcsQty = 0; } if (iPcsQty + iFocPcsQty <= 0) { continue; } //保存生产编号到变量 string productNum = txtProductNum.Text; //输入的生产编号 if (productNum.Length <= 0) { throw new Exception("第 " + rowId.ToString() + " 行的生产编号文本框未输入内容!"); } //其他各参数 var txtOrderId = (TextBox)trContentRow.FindControl("txtOrderId" + i); var txtCustNum = (TextBox)trContentRow.FindControl("txtCustNum" + i); var txtOrderNum = (TextBox)trContentRow.FindControl("txtOrderNum" + i); //当前批量卡清单内容保存到的隐藏对象 var hdLotCardList = (HtmlInputHidden)tabDataListSon.FindControl("hdLotCardList" + i); string strLotCardList = hdLotCardList.Value.Replace("|l|", "<").Replace("|g|", ">"); var txtRemark = (TextBox)trContentRow.FindControl("txtRemark" + i); //订单序号 var orderId = txtOrderId.Text.Trim(); //执行扣减待入仓结存并将记录写入批量卡清单 DeductionWaitInStoreBalance( tran, strLotCardList, billNum, rowId, productNum ); //执行插入行 daContent.Insert( billNum, rowId, orderId, null, productNum, Convert.ToString(txtCustNum.Text), txtOrderNum.Text, null, null, iPcsQty, iFocPcsQty == 0 ? null : (int?)iFocPcsQty, null, Convert.ToString(txtRemark.Text), strLotCardList, false ); //执行更新订单已交货数和未交货数 daContent.UpdateOrderBalanceQty(iPcsQty, orderId); //记录到清单 if (!lOrderId.Contains(orderId)) { lOrderId.Add(orderId); } } //更新需要显示工具费的行 UpdateNeedToolAmount(daContent, lOrderId); //提交事务 tran.Commit(); //返回成功 return true; } catch (Exception ex) { //回滚事务 tran.Rollback(); //抛出错误 throw ex; } } } }
protected new void Page_Load(object sender, EventArgs e) { //调用基类方法检测session是否存在 base.Page_Load(sender, e); //删除全部数据 Response.Clear(); //检测是否含有session if (Session.Count < 5) { //跳转 Response.Redirect("/Account/Login", true); //停止加载后续内容 Response.End(); //直接返回 return; } //当前用户所在部门 string procName = Session["proc_name"].ToString(); //当前角色id Int16 roleId = Convert.ToInt16(Session["role_id"]); //检测是否有权限 if (procName != mustProcName || roleId < 0 || roleId > 6) { //设置页面不可用 throw new Exception("您没有打印该单据的权限!"); } //用户传入的送货单号 var bnum = Request["bnum"]; if (bnum == null || bnum.Length == 0) { Response.Write("未检测到传入的送货单号!"); return; } var billNums = bnum.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (billNums.Length <= 0) { Response.Write("传入的送货单号不正确!"); return; } //去重 var lBillNum = new List<string>(); foreach (var billNum in billNums) { if (!lBillNum.Contains(billNum)) { lBillNum.Add(billNum); } } //排序 lBillNum.Sort(); //修改标题 this.Title = "送货单预览 - " + bnum; //表头表身数据表 tabHead = new DataSetDeliveryBillMgr.v_delivery_bill_head_join_custDataTable(); tabContent = new DataSetDeliveryBillMgr.t_delivery_bill_contentDataTable(); //数据适配器 using (var da = new v_delivery_bill_head_join_custTableAdapter()) { //获取表头数据 foreach (var billNum in lBillNum) { tabHead.Merge(da.GetDataByBillNum(billNum)); } if (tabHead.Rows.Count <= 0) { Response.Write("未找到送货单!"); return; } } //数据适配器 using (var da = new t_delivery_bill_contentTableAdapter()) { //获取内容数据 foreach (var billNum in lBillNum) { tabContent.Merge(da.GetDataByBillNum(billNum)); } } }
/// <summary> /// 根据单号从数据库中删除单据的表头和内容 /// </summary> /// <param name="billNum">单据号</param> private bool DeleteBillByBillNum(string billNum) { //实例化数据适配器 using (var daHead = new t_delivery_bill_headTableAdapter()) using (var daContent = new t_delivery_bill_contentTableAdapter()) using (var daLotCard = new t_delivery_bill_lot_cardTableAdapter()) //取得数据库连接 using (var conn = daHead.Connection) { //打开数据库连接 conn.Open(); //事务 using (var tran = conn.BeginTransaction()) { //设置数据库连接 daHead.Connection = daContent.Connection = daLotCard.Connection = conn; //设置事务 daHead.Transaction = daContent.Transaction = daLotCard.Transaction = tran; try { //记录需要检测更新首次送货记录工具费的订单序号清单 var lOrderId = new List<string>(); //取得之前单据清单记录 var tabContent = daContent.GetDataByBillNum(billNum); //遍历各行 foreach (DataSetDeliveryBillMgr.t_delivery_bill_contentRow row in tabContent.Rows) { //之前是否有设置为需要记录工具费 if (!row.Isneed_tool_amountNull() && row.need_tool_amount) { //记录到清单 if (!lOrderId.Contains(row.order_id)) { lOrderId.Add(row.order_id); } } //取得之前写入的批量卡清单 string strLotCardListOld = row.lot_id_list.Trim(); //是否存在批量卡清单 if (strLotCardListOld.Length > 0) { //当前生产编号 string productNum = row.product_num; //之前的清单写回 LotCardListToWaitInStoreBalance(tran, billNum, null, strLotCardListOld, productNum); } //当前交货的数量 var pcsQty = row.pcs_qty; if (!row.Isfoc_pcs_qtyNull()) { pcsQty += row.foc_pcs_qty; } //执行更新订单已交货数和未交货数 daContent.UpdateOrderBalanceQty(-pcsQty, row.order_id); } //执行删除 daHead.Delete(billNum); daContent.DeleteByBillNum(billNum); daLotCard.DeleteByBillNum(billNum); //更新需要显示工具费的行 UpdateNeedToolAmount(daContent, lOrderId); //提交事务 tran.Commit(); //返回成功 return true; } catch (Exception ex) { //回滚事务 tran.Rollback(); //抛出错误 throw ex; } } } }
/// <summary> /// 根据单号从数据库中删除单据的表头和内容 /// </summary> /// <param name="billNum">单据号</param> private bool DeleteBillByBillNum(string billNum) { //实例化数据适配器 using (var daHead = new t_delivery_bill_headTableAdapter()) using (var daContent = new t_delivery_bill_contentTableAdapter()) //取得数据库连接 using (var conn = daHead.Connection) { //打开数据库连接 conn.Open(); //事务 using (var tran = conn.BeginTransaction()) { //设置数据库连接 daContent.Connection = conn; //设置事务 daHead.Transaction = tran; daContent.Transaction = tran; try { //取得之前送货单清单记录 var tab = daContent.GetDataByBillNum(billNum); //遍历各行 foreach (DataSetDeliveryBillMgr.t_delivery_bill_contentRow row in tab.Rows) { //取得之前写入的lot卡清单 string strLotCardListOld = row.lot_id_list.Trim(); //是否存在lot卡清单 if (strLotCardListOld.Length > 0) { //当前生产编号 string productNum = row.product_num; //之前的清单写回 LotCardListToWaitInStoreBalance(tran, strLotCardListOld, productNum); } //当前交货的数量 var pcsQty = row.pcs_qty; if (!row.Isfoc_pcs_qtyNull()) { pcsQty += row.foc_pcs_qty; } //执行更新订单已交货数和未交货数 daContent.UpdateOrderBalanceQty(-pcsQty, row.order_id); } //执行删除 daHead.Delete(billNum); daContent.DeleteByBillNum(billNum); //提交事务 tran.Commit(); //返回成功 return true; } catch (Exception ex) { //回滚事务 tran.Rollback(); //抛出错误 throw ex; } } } }
/// <summary> /// 执行删除数据并处理相关数据一致性 /// </summary> /// <param name="e">传入的带有数据的事件参数</param> /// <returns></returns> private bool DeleteData(ListViewDeleteEventArgs e) { //实例化数据适配器 using (var daContent = new t_delivery_bill_contentTableAdapter()) //取得数据库连接 using (var conn = daContent.Connection) { //打开数据库连接 conn.Open(); //事务 using (var tran = conn.BeginTransaction()) { //设置事务 daContent.Transaction = tran; try { //当前送货单号 string billNum = e.Keys[0].ToString(); //取得之前送货单清单记录 var tab = daContent.GetDataByBillNum(billNum); //检测总共含有的清单行数 if (tab.Rows.Count <= 1) { //执行删除表头数据 using (var daHead = new t_delivery_bill_headTableAdapter()) { //设置数据库连接 daHead.Connection = conn; //设置事务 daHead.Transaction = tran; //执行删除 daHead.Delete(billNum); } } //当前行号 byte rowId = Convert.ToByte(e.Keys[1]); //获取当前行的数据内容 tab = daContent.GetDataByBillNumAndRowId(billNum, rowId); //检测是否存在数据 if (tab.Rows.Count >= 0) { //首行数据 var row = (DataSetDeliveryBillMgr.t_delivery_bill_contentRow)tab.Rows[0]; //取得之前写入的lot卡清单 string strLotCardListOld = row.lot_id_list.Trim(); //是否存在lot卡清单 if (strLotCardListOld.Length > 0) { //当前生产编号 string productNum = row.product_num; //之前的清单写回 LotCardListToWaitInStoreBalance(tran, strLotCardListOld, productNum); } //当前交货的数量 var pcsQty = row.pcs_qty; if (!row.Isfoc_pcs_qtyNull()) { pcsQty += row.foc_pcs_qty; } //执行更新订单已交货数和未交货数 daContent.UpdateOrderBalanceQty(-pcsQty, row.order_id); //执行删除 daContent.DeleteByBillNumAndRowId(billNum, rowId); } //提交事务 tran.Commit(); //返回成功 return true; } catch (Exception ex) { //回滚事务 tran.Rollback(); //抛出错误 throw ex; } } } }
protected new void Page_Load(object sender, EventArgs e) { //调用基类方法检测session是否存在 base.Page_Load(sender, e); //删除全部数据 Response.Clear(); //检测是否含有session if (Session.Count < 5) { //跳转 Response.Redirect("/Account/Login", true); //停止加载后续内容 Response.End(); //直接返回 return; } //当前用户所在部门 string deptName = Session["dept_name"].ToString(); //当前角色id Int16 roleId = Convert.ToInt16(Session["role_id"]); //检测是否有权限 if (deptName != mustDeptName || roleId < 0 || roleId > 6) { //设置页面不可用 throw new Exception("您没有打印该单据的权限!"); } //用户传入的送货单号 string billNum = Request["bnum"]; if (billNum == null || billNum.Length == 0) { Response.Write("未检测到传入的送货单号!"); return; } //修改标题 this.Title = "送货单预览 - " + billNum; //数据适配器 using (var da = new t_delivery_bill_headTableAdapter()) { //获取表头数据 var tab = da.GetDataByBillNum(billNum); if (tab.Rows.Count <= 0) { return; } //首行数据 var row = (DataSetDeliveryBillMgr.t_delivery_bill_headRow)tab.Rows[0]; //设置值到控件 litBillNum.Text = billNum; litCustName.Text = row.cust_name; litBillDate.Text = row.bill_date.ToString("yyyy年MM月dd日"); litConsignor.Text = row.add_person; } //数据适配器 using (var da = new t_delivery_bill_contentTableAdapter()) { //获取内容数据 var tab = da.GetDataByBillNum(billNum); //遍历行 foreach (DataSetDeliveryBillMgr.t_delivery_bill_contentRow row in tab.Rows) { //取得当前行序号 Int16 i = row.row_id; //各显示数据的控件 var litOrderNum = (Literal)this.FindControl("litOrderNum" + i.ToString()); var litProductNum = (Literal)this.FindControl("litProductNum" + i.ToString()); var litCustNum = (Literal)this.FindControl("litCustNum" + i.ToString()); var litQty = (Literal)this.FindControl("litQty" + i.ToString()); var litRemark = (Literal)this.FindControl("litRemark" + i.ToString()); //设置数据到控件 litOrderNum.Text = row.order_num; litProductNum.Text = row.product_num; litCustNum.Text = row.cust_num; litQty.Text = row.pcs_qty.ToString(); litRemark.Text = row.IsremarkNull() ? string.Empty : row.remark; } } }
/// <summary> /// 获取模版1的单据 /// </summary> /// <param name="bnums">传递的单据编号的key名称</param> /// <param name="tabHead">返回的表头数据</param> /// <param name="tabContent">返回的表身数据</param> private void GetBillData( string bnums, DataSetDeliveryBillMgr.v_delivery_bill_head_join_custDataTable tabHead, DataSetDeliveryBillMgr.t_delivery_bill_contentDataTable tabContent ) { //用户传入的送货单号 var bnum = Request[bnums]; if (bnum == null || bnum.Length == 0) { //Response.Write("未检测到传入的送货单号!"); return; } var billNums = bnum.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (billNums.Length <= 0) { //Response.Write("传入的送货单号不正确!"); return; } //去重 var lBillNum = new List<string>(); foreach (var billNum in billNums) { if (!lBillNum.Contains(billNum)) { lBillNum.Add(billNum); } } //排序 lBillNum.Sort(); //修改标题 this.Title = "送货单预览"; //数据适配器 using (var da = new v_delivery_bill_head_join_custTableAdapter()) { //获取表头数据 foreach (var billNum in lBillNum) { tabHead.Merge(da.GetDataByBillNum(billNum)); } if (tabHead.Rows.Count <= 0) { //Response.Write("未找到送货单!"); return; } } //数据适配器 using (var da = new t_delivery_bill_contentTableAdapter()) { //获取内容数据 foreach (var billNum in lBillNum) { tabContent.Merge(da.GetDataByBillNum(billNum)); } } }
protected void fvDeliveryBillMgrAdd_ItemCreated(object sender, EventArgs e) { //设置单据清单可见 tabDataListSon.Visible = true; //清空送货单内容清单 for (int i = 0; i < 6; i++) { //写入清单数据到控件 SetBillContent(null, i); } //送货单号 string billNum; //送货单号里面的数字序号 Int64 iBillNum; //新增状态 switch (fvDeliveryBillMgrAdd.CurrentMode) { case FormViewMode.Insert: //当前订单下单日期文本框 var tb = (TextBox)fvDeliveryBillMgrAdd.FindControl("txtBillDate"); if (tb != null) { //检查用户提供的日期参数标识 string strBillDate = Request["bdate"]; DateTime dtBillDate; if (strBillDate != null && strBillDate.Length > 0 && DateTime.TryParse(strBillDate, out dtBillDate)) { //设置默认日期 tb.Text = dtBillDate.ToString("yyyy-MM-dd"); } else { //设置日期为当前日期 tb.Text = DateTime.Now.ToString("yyyy-MM-dd"); } } //最大单据号+1 tb = (TextBox)fvDeliveryBillMgrAdd.FindControl("txtBillNum"); if (tb != null) { //获取已经使用的最大单据号 using (var da = new t_delivery_bill_headTableAdapter()) { //单据号 billNum = da.GetMaxBillNumByYear(DateTime.Now.ToString("yy") + "%").ToString(); //检测有无数据 if (billNum.Length > 0 && Int64.TryParse(billNum, out iBillNum) && iBillNum > 1300000000) { //设置单据号+1 tb.Text = (iBillNum + 1).ToString(); } else { //设置默认单据号 tb.Text = DateTime.Now.ToString("yy00000001"); } } } //退出switch break; //修改或查看状态 case FormViewMode.Edit: case FormViewMode.ReadOnly: //设置单据清单不可见 tabDataListSon.Visible = false; //通过送货单号获取数据清单 //取得传入的送货单号 billNum = Request["bnum"]; if (billNum != null && billNum.Length > 0 && Int64.TryParse(billNum, out iBillNum)) { //检测是否含有该表头数据 using (var daHead = new t_delivery_bill_headTableAdapter()) { //获取数据 var tabHead = daHead.GetDataByBillNum(billNum); //检测是否找到数据 if (tabHead.Rows.Count > 0) { //设置单据清单可见 tabDataListSon.Visible = true; //获取清单 using (var daContent = new t_delivery_bill_contentTableAdapter()) { //获取数据 var tabContent = daContent.GetDataByBillNum(billNum); //把内容写入页面 foreach (DataSetDeliveryBillMgr.t_delivery_bill_contentRow row in tabContent.Rows) { //当前行号 int i = row.row_id - 1; //写入清单数据到控件 SetBillContent(row, i); } } } } } //退出switch break; } }