Dim e As RequestEventArgs = args(0)
Dim wb As New weui
Dim cmd As New SQLCommand
cmd.C
Dim dt,dtt As DataTable
cmd.CommandText = "sele * from {材料入库} Where [_Identify] Is Null"
dt = cmd.ExecuteReader(True)
cmd.CommandText = "sele * from {材料入库明细} Where [_Identify] Is Null"
dtt = cmd.ExecuteReader(True)
'删除订单明细
If e.GetValues.ContainsKey("deldid") Then
dtt.SQLDeleteFor("[_Identify] = " & e.GetValues("deldid"))
End If
'订单编辑
Dim pr As DataRow '订单
Dim srs As List(of DataRow) '订单明细集合
Dim Page As Integer '页码变量
If e.GetValues.ContainsKey("page") Then '如果地址中有page参数
Integer.TryParse(e.GetValues("page"), page) '提取page参数
End If
If e.GetValues.ContainsKey("oid") = False Then '如果没有传递订单编号,则新增一个订单
pr = dt.SQLAddNew() '
pr("入库流水") = Functions.Execute("GetOrderID") '利用自定义函数GetOrderID为新增订单生成编号.
pr("日期") = Date.Now()
Else '如果传递了订单编号,则找出此订单进行编辑
pr = dt.SQLFind("入库流水='" & e.GetValues("oid") & "'")
If pr Is Nothing Then '多用户情况下,必须考虑其他用户删除订单的可能.
wb.InSertHtml("此入库单已被其他用户删除!")
e.WriteString(wb.Build)
Return "" '必须返回
End If
srs = dtt.SQLSelect("入库流水='" & pr("入库流水") & "'") '获取订单明细
End If
Dim url As String = "edit.htm?page=" & page & "&oid=" & pr("入库流水") '传递页码和订单编号
wb.AddForm("","form1",url)
With wb.AddInputGroup("form1","ipg1",iif(e.GetValues.ContainsKey("oid"),"编辑入库","新增入库"))
With .AddInput("入库流水","流水号","text")
.Value = pr("入库流水")
.Readonly = True
End With
.AddHiddenValue("日期",pr("日期"))
' .AddInput("日期","日期","text").Value = pr("日期")
.AddInput("供应商","供应商","text").Value = pr("供应商")
.AddInput("材质","材质","text").Value = pr("材质")
If e.GetValues.ContainsKey("oid") Then '如果是旧订单,则汇总显示数量和金额
Dim qty As Integer
Dim amt0 As Integer
Dim amt As Integer
For Each sr As DataRow In srs
qty = qty + sr("数量")
amt0 = amt0 + sr("毛重")
amt = amt + sr("净重")
Next
.AddInput("总数量","总数量","number").value = qty
.AddInput("总毛重","总毛重","number").value = amt0
.AddInput("总净重","总净重","number").value = amt
End If
End With
'订单明细编辑
Dim mr As DataRow '要编辑的订单明细
Dim IsNew As Boolean '此变量用于标记是否要新增明细
If e.GetValues.ContainsKey("oid") = False OrElse e.GetValues.ContainsKey("addnext") '如果是新增订单,或这包括addnext参数
IsNew = True '将IsNew参数设置为True,表明需要新增订单明细
ElseIf e.GetValues.ContainsKey("did") Then '如果传递了订单明细主键
mr = dtt.SQLFind("[_Identify]=" & e.GetValues("did")) '找出此订单明细进行编辑
End If
If IsNew OrElse mr IsNot Nothing Then
With wb.AddInputGroup("form1","ipg2",iif(IsNew,"新增明细","编辑明细"))
If IsNew Then '如果是新增订单明细
.AddInput("l","长","number")
.AddInput("d","宽","number")
With .AddInputCell("ic4") '通过InputCell增加输入框
.AddLabel("hou","厚",0) '增加标签,0显示在左边
.AddInput("h","number",1).Attribute = ""
.AddVcodeButton("hym","刷新",2) .Attribute = ""
End With
.AddInput("规格","规格","text")
.AddInput("数量","数量","number")
.AddInput("毛重","毛重","number")
.AddInput("净重","净重","number")
Else
.AddHiddenValue("DetailID",mr("_Identify")) '插入一个隐藏的订单明细主键,此值将随表单数据一并提交到服务器.
.AddInput("规格","规格","text").Value = mr("规格")
.AddInput("数量","数量","number").value = mr("数量")
.AddInput("毛重","毛重","number").value = mr("毛重")
.AddInput("毛重","毛重","number").value = mr("毛重")
End If
End With
End If
'生成明细表格
If e.GetValues.ContainsKey("oid") AndAlso srs.count > 0 Then '如果不是新增订单,且订单明细行数大于0,则生成订单明细表格.
With wb.AddTable("form1","detailTable") '为了区分,明细表的名字设为detailTable
.head.AddRow("规格","数量","毛重","净重")
.ActiveSheet = "menu" '指定菜单
For Each sr As DataRow In srs
With .Body.AddRow(sr("规格"),sr("数量"),sr("毛重"),sr("净重"))
.Primarykey = sr("_Identify") '为此行指定主键值
End With
Next
End With
'设计菜单
With wb.AddActionSheet("","menu")
.Add("mnudAdd", "增加明细").Attribute="" '调用js函数
.Add("mnuEdit", "编辑明细").Attribute =""
.Add("mnuDelete", "删除明细").Attribute ="""
.Add("mnuCancel","取消","",True)
End With
End If
With wb.AddDialog("","dlg1", "删除确认","您确定要删除当前明细吗?")
.AddButton("btnCancel","取消").Kind = 1
.AddButton("btnOK","确定").Attribute = ""
End With
With wb.AddButtonGroup("form1","btg1",False)
.Add("btn1", "增加明细", "submit").FormAction = url & "&addnext=true" '加上addnext参数,表示保存后进入增加明细状态
.Add("btn2", "保存", "submit") '正常提交,保存后进入编辑状态
If e.GetValues.ContainsKey("oid") = False Then '如过是新增订单
.Add("btn3", "取消", "button","list.htm?page=" & page & "&deloid=" & pr("入库流水")) '删除新增订单后返回列表
ElseIf IsNew OrElse mr IsNot Nothing Then '如果在给旧订单新增或修改明细,则直接返回编辑状态
.Add("btn3", "取消", "button",url) '返回编辑状态
Else
.Add("btn3", "返回", "button","list.htm?page=" & page) '返回列表
End If
End With
With wb.AddButtonGroup("form1","btg2",False)
.Add("btn4", "生成Excel格式订单", "button","order.xls?oid=" & pr("入库流水"))
End With
pr.Save() '必须保存,而且必须在最后保存,因为SQLAddNew增加的行,保存之后就会销毁,无法再调用
If e.PostValues.Count > 0 Then '如果是通过提交按钮访问,则给一个已经保存的提示给用户,时长500毫秒
wb.AddToast("","t1", "已经保存",0).Msec= 500
End If
wb.AppendHTML("<script src='./lib/order.js'></script>") '引入脚本文件
wb.AppendHTML("<script src='./lib/ajaxform.js'></script>") '引入脚本文件
e.WriteString(wb.Build) '生成网页