- 主题
- 0
- 积分
- 0
- 贝壳
- 0 个
- 来自
- 云南曲靖
- 注册时间
- 2006-11-19
- 最后登录
- 2006-11-19
|
[公告]技术区5.1比赛作品发表专帖
借出单
Private SQL As String
Private startcol As Integer
Private endcol As Integer
Private col, row As Integer
Private rowheight As Integer
Private colwidth(14) As Long
Private order(14) As Boolean
Option Explicit
Private Sub SaveInit()
startcol = DataGrid1.SelStartCol
endcol = DataGrid1.SelEndCol
col = DataGrid1.LeftCol
row = DataGrid1.row
rowheight = DataGrid1.rowheight
Dim i As Integer
For i = 0 To DataGrid1.Columns.count - 1
colwidth(i) = DataGrid1.Columns(i).width
Next
End Sub
Private Sub ResumeInit()
DataGrid1.SelStartCol = startcol
DataGrid1.SelEndCol = endcol
DataGrid1.Scroll col, row
DataGrid1.rowheight = rowheight
Dim i As Integer
For i = 0 To DataGrid1.Columns.count - 1
DataGrid1.Columns(i).width = colwidth(i)
Next
DataGrid1.Columns(0).Locked = True
DataGrid1.Columns(1).Locked = True
DataGrid1.Columns(2).Locked = True
DataGrid1.Columns(3).Locked = True
DataGrid1.Columns(4).Locked = True
DataGrid1.Columns(6).Locked = True
DataGrid1.Columns(7).Locked = True
DataGrid1.Columns(8).Locked = True
DataGrid1.Columns(9).Locked = True
DataGrid1.Columns(10).Locked = True
End Sub
Private Sub initdatagrid1()
DataGrid1.Columns(0).width = 500
DataGrid1.Columns(1).width = 1000
DataGrid1.Columns(2).width = 1000
DataGrid1.Columns(3).width = 1000
DataGrid1.Columns(4).width = 1000
DataGrid1.Columns(5).width = 1000
DataGrid1.Columns(6).width = 800
DataGrid1.Columns(7).width = 800
DataGrid1.Columns(8).width = 800
DataGrid1.Columns(9).width = 800
DataGrid1.Columns(10).width = 800
DataGrid1.Columns(11).width = 800
DataGrid1.Columns(12).width = 800
DataGrid1.Columns(0).Locked = True
DataGrid1.Columns(1).Locked = True
DataGrid1.Columns(2).Locked = True
DataGrid1.Columns(3).Locked = True
DataGrid1.Columns(4).Locked = True
DataGrid1.Columns(6).Locked = True
DataGrid1.Columns(7).Locked = True
DataGrid1.Columns(8).Locked = True
DataGrid1.Columns(9).Locked = True
DataGrid1.Columns(10).Locked = True
DataGrid1.rowheight = 270
End Sub
Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error Resume Next
Adodc1.caption = Adodc1.Recordset.Fields("货物名称").Value
End Sub
Private Sub B新增借出单_Click()
新增借出单.Show vbModal
SaveInit
Adodc1.Refresh
ResumeInit
End Sub
Private Sub DataGrid1_HeadClick(ByVal ColIndex As Integer)
On Error Resume Next
Dim caption As String
caption = DataGrid1.Columns(ColIndex).caption
If caption = "经办人" Then caption = "姓名"
If caption = "金额" Then Exit Sub
If caption = "备注" Then caption = "借出单.备注"
If caption = "编号" Then caption = "借出单.编号"
If caption = "供应商" Then caption = "供应商名称"
If caption = "存放仓库" Then caption = "仓库名称"
Adodc1.RecordSource = SQL + " order by " + caption
order(ColIndex) = True - order(ColIndex)
If order(ColIndex) = True Then
Adodc1.RecordSource = Adodc1.RecordSource + " ASC"
Else
Adodc1.RecordSource = Adodc1.RecordSource + " DESC"
End If
SaveInit
Adodc1.Refresh
ResumeInit
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = DataConnectString
SQL = Adodc1.RecordSource
Set DataGrid1.DataSource = Adodc1
Adodc1.Refresh
initdatagrid1
';通过权限来初始化控件性质
If 权限类别(0) = 0 Then B新增借出单.Enabled = False
If 权限类别(1) = 0 Then DataGrid1.AllowUpdate = False
If 权限类别(2) = 0 Then
退出借出单.Enabled = False
删除借出单.Enabled = False
End If
If 权限类别(8) = 0 Then 打印借出单.Enabled = False
End Sub
Private Sub 打印借出单_Click()
On Error GoTo quit
Dim p As New 新增借出单
p.编号 = DataGrid1.Columns(0).Value
p.Show vbModal
Unload p
quit:
End Sub
Private Sub 删除借出单_Click()
On Error GoTo quit
If DataGrid1.Columns(10).Text = "已还入" Then GoTo con
If MsgBox("建议用[退出借出单],而不要直接删除,以免数据丢失.您确信要删除该借出单吗?", vbYesNo Or vbQuestion) = vbNo Then Exit Sub
con:
On Error Resume Next
Dim code, code1, code2 As Long
code = DataGrid1.Columns(0).Text
fMainForm.m_checkado.RecordSource = "select 货物编号,借出数量,仓库编号 from 借出单 where 编号=" + Str(code)
fMainForm.m_checkado.Refresh
Dim num1, num2 As Long
code1 = fMainForm.m_checkado.Recordset.Fields("货物编号").Value
num1 = fMainForm.m_checkado.Recordset.Fields("借出数量").Value
code2 = fMainForm.m_checkado.Recordset.Fields("仓库编号").Value
';如果是已退出借出单则直接删除
If DataGrid1.Columns(12).Text = "已还入" Then
If MsgBox("您确信要删除该借出退出单吗?", vbYesNo Or vbQuestion) = vbNo Then Exit Sub
fMainForm.m_checkado.RecordSource = "select * from 借出单 where 编号=" + Str(code)
fMainForm.m_checkado.Refresh
fMainForm.m_checkado.Recordset.Delete
fMainForm.m_checkado.Refresh
SaveInit
Adodc1.Refresh
ResumeInit
Exit Sub
End If
fMainForm.m_checkado.RecordSource = "select (货物信息.最高限量-库存数量) as 剩余量 from 库存状况,货物信息 where 货物信息.编号=库存状况.货物编号 and 货物编号=" + Str(code1) + " and 仓库编号=" + Str(code2)
fMainForm.m_checkado.Refresh
';当前库存数量num2
num2 = fMainForm.m_checkado.Recordset.Fields("剩余量").Value
';库存不足
If num2 < num1 Then
If MsgBox("库存超额,库存最大剩余限量为" + Str(num2) + ",入库量为" + Str(num1) + "," + "要忽略它并强制删除吗?", vbQuestion Or vbYesNo) = vbNo Then Exit Sub
End If
';更新库存状况
fMainForm.m_checkado.RecordSource = "select * from 库存状况 where 货物编号=" + Str(code1) + " and 仓库编号=" + Str(code2)
fMainForm.m_checkado.Refresh
';如果已有记录则更新
If fMainForm.m_checkado.Recordset.RecordCount > 0 Then
If num2 - num1 > 0 Then ';剩余限量够
fMainForm.m_checkado.Recordset.Fields("库存数量").Value = fMainForm.m_checkado.Recordset.Fields("库存数量").Value + num1
fMainForm.m_checkado.Recordset.update
Else
fMainForm.m_checkado.Recordset.Fields("库存数量").Value = fMainForm.m_checkado.Recordset.Fields("库存数量").Value + num2
fMainForm.m_checkado.Recordset.update
End If
Else ';没有记录开始创建
fMainForm.m_checkado.RecordSource = "select * from 库存状况"
fMainForm.m_checkado.Refresh
';移到记录最后
Dim ncode As Long
If fMainForm.m_checkado.Recordset.RecordCount > 0 Then
fMainForm.m_checkado.Recordset.MoveLast
ncode = fMainForm.m_checkado.Recordset.Fields("编号").Value + 1
Else
ncode = 1
End If
fMainForm.m_checkado.Recordset.AddNew
fMainForm.m_checkado.Recordset.Fields("编号") = ncode
fMainForm.m_checkado.Recordset.Fields("货物编号") = code1
fMainForm.m_checkado.Recordset.Fields("仓库编号") = code2
If num2 > num1 Then
fMainForm.m_checkado.Recordset.Fields("库存数量") = num1
Else
fMainForm.m_checkado.Recordset.Fields("库存数量") = num2
End If
fMainForm.m_checkado.Recordset.update
End If
fMainForm.m_checkado.Refresh
';更新借出单
fMainForm.m_checkado.RecordSource = "select * from 借出单 where 编号=" + Str(code)
fMainForm.m_checkado.Refresh
fMainForm.m_checkado.Recordset.Delete
fMainForm.m_checkado.Refresh
SaveInit
Adodc1.Refresh
ResumeInit
MsgBox "借出单删除成功!"
';写入系统日志
fMainForm.WriteLog ("删除借出单")
quit:
End Sub
Private Sub 退出借出单_Click()
On Error GoTo quit
Dim code, code1, code2 As Long
code = DataGrid1.Columns(0).Text
If DataGrid1.Columns(10).Text = "已还入" Then
MsgBox "该借出单已还入!"
Exit Sub
End If
On Error Resume Next
fMainForm.m_checkado.RecordSource = "select 货物编号,借出数量,仓库编号 from 借出单 where 编号=" + Str(code)
fMainForm.m_checkado.Refresh
Dim num1, num2 As Long
code1 = fMainForm.m_checkado.Recordset.Fields("货物编号").Value
num1 = fMainForm.m_checkado.Recordset.Fields("借出数量").Value
code2 = fMainForm.m_checkado.Recordset.Fields("仓库编号").Value
fMainForm.m_checkado.RecordSource = "select 最高限量 from 货物信息 where 编号=" + Str(code1)
fMainForm.m_checkado.Refresh
num2 = fMainForm.m_checkado.Recordset.Fields("最高限量").Value
fMainForm.m_checkado.RecordSource = "select 库存数量 from 库存状况 where 货物编号=" + Str(code1) + " and 仓库编号=" + Str(code2)
fMainForm.m_checkado.Refresh
If fMainForm.m_checkado.Recordset.RecordCount > 0 Then
num2 = num2 - fMainForm.m_checkado.Recordset.Fields("库存数量").Value
End If
';库存不足
If num2 < num1 Then
MsgBox "库存超额,库存最大剩余限量为" + Str(num2) + ",入库量为" + Str(num1) + "."
Exit Sub
Else
';更新库存状况
fMainForm.m_checkado.RecordSource = "select * from 库存状况 where 货物编号=" + Str(code1) + " and 仓库编号=" + Str(code2)
fMainForm.m_checkado.Refresh
';如果已有记录则更新
If fMainForm.m_checkado.Recordset.RecordCount > 0 Then
If num2 - num1 > 0 Then ';剩余限量够
fMainForm.m_checkado.Recordset.Fields("库存数量").Value = fMainForm.m_checkado.Recordset.Fields("库存数量").Value + num1
fMainForm.m_checkado.Recordset.update
Else
fMainForm.m_checkado.Recordset.Fields("库存数量").Value = fMainForm.m_checkado.Recordset.Fields("库存数量").Value + num2
fMainForm.m_checkado.Recordset.update
End If
Else ';没有记录开始创建
fMainForm.m_checkado.RecordSource = "select * from 库存状况"
fMainForm.m_checkado.Refresh
';移到记录最后
Dim ncode As Long
If fMainForm.m_checkado.Recordset.RecordCount > 0 Then
fMainForm.m_checkado.Recordset.MoveLast
ncode = fMainForm.m_checkado.Recordset.Fields("编号").Value + 1
Else
ncode = 1
End If
fMainForm.m_checkado.Recordset.AddNew
fMainForm.m_checkado.Recordset.Fields("编号") = ncode
fMainForm.m_checkado.Recordset.Fields("货物编号") = code1
fMainForm.m_checkado.Recordset.Fields("仓库编号") = code2
If num2 > num1 Then
fMainForm.m_checkado.Recordset.Fields("库存数量") = num1
Else
fMainForm.m_checkado.Recordset.Fields("库存数量") = num2
End If
fMainForm.m_checkado.Recordset.update
End If
fMainForm.m_checkado.Refresh
';更新借出单
fMainForm.m_checkado.RecordSource = "select * from 借出单 where 编号=" + Str(code)
fMainForm.m_checkado.Refresh
fMainForm.m_checkado.Recordset.Fields("定单状况") = "已还入"
fMainForm.m_checkado.Recordset.update
fMainForm.m_checkado.Refresh
SaveInit
Adodc1.Refresh
ResumeInit
MsgBox "借出单退出成功!"
';写入系统日志
fMainForm.WriteLog ("退出借出单")
End If
quit:
End Sub |
|