frmStatistic1.frm
上传用户:lizhip88
上传日期:2007-06-21
资源大小:42k
文件大小:11k
源码类别:

交通/航空行业

开发平台:

Visual Basic

  1. VERSION 5.00
  2. Begin VB.Form frmStatistic1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "运营统计"
  5.    ClientHeight    =   3456
  6.    ClientLeft      =   48
  7.    ClientTop       =   336
  8.    ClientWidth     =   3852
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   3456
  13.    ScaleWidth      =   3852
  14.    ShowInTaskbar   =   0   'False
  15.    StartUpPosition =   1  'CenterOwner
  16.    Begin VB.Frame Frame1 
  17.       Caption         =   "运营信息"
  18.       Height          =   2655
  19.       Left            =   240
  20.       TabIndex        =   8
  21.       Top             =   240
  22.       Width           =   3375
  23.       Begin VB.TextBox txtItem 
  24.          Height          =   270
  25.          Index           =   3
  26.          Left            =   1200
  27.          MaxLength       =   10
  28.          TabIndex        =   5
  29.          Top             =   2160
  30.          Width           =   1935
  31.       End
  32.       Begin VB.TextBox txtItem 
  33.          Height          =   270
  34.          Index           =   2
  35.          Left            =   1200
  36.          MaxLength       =   10
  37.          TabIndex        =   4
  38.          Top             =   1800
  39.          Width           =   1935
  40.       End
  41.       Begin VB.TextBox txtItem 
  42.          Height          =   270
  43.          Index           =   1
  44.          Left            =   1200
  45.          MaxLength       =   10
  46.          TabIndex        =   3
  47.          Top             =   1440
  48.          Width           =   1935
  49.       End
  50.       Begin VB.TextBox txtItem 
  51.          Height          =   270
  52.          Index           =   0
  53.          Left            =   1200
  54.          MaxLength       =   10
  55.          TabIndex        =   2
  56.          Top             =   1080
  57.          Width           =   1935
  58.       End
  59.       Begin VB.ComboBox cboItem 
  60.          Height          =   300
  61.          Index           =   1
  62.          Left            =   1200
  63.          Style           =   2  'Dropdown List
  64.          TabIndex        =   1
  65.          Top             =   720
  66.          Width           =   1935
  67.       End
  68.       Begin VB.ComboBox cboItem 
  69.          Height          =   300
  70.          Index           =   0
  71.          Left            =   1200
  72.          Style           =   2  'Dropdown List
  73.          TabIndex        =   0
  74.          Top             =   360
  75.          Width           =   1935
  76.       End
  77.       Begin VB.Label Label2 
  78.          Caption         =   "耗    油:"
  79.          Height          =   255
  80.          Index           =   3
  81.          Left            =   240
  82.          TabIndex        =   14
  83.          Top             =   2160
  84.          Width           =   975
  85.       End
  86.       Begin VB.Label Label2 
  87.          Caption         =   "运行公里:"
  88.          Height          =   255
  89.          Index           =   2
  90.          Left            =   240
  91.          TabIndex        =   13
  92.          Top             =   1800
  93.          Width           =   975
  94.       End
  95.       Begin VB.Label Label2 
  96.          Caption         =   "开始时间:"
  97.          Height          =   255
  98.          Index           =   6
  99.          Left            =   240
  100.          TabIndex        =   12
  101.          Top             =   1080
  102.          Width           =   975
  103.       End
  104.       Begin VB.Label Label2 
  105.          Caption         =   "姓    名:"
  106.          Height          =   255
  107.          Index           =   0
  108.          Left            =   240
  109.          TabIndex        =   11
  110.          Top             =   720
  111.          Width           =   975
  112.       End
  113.       Begin VB.Label Label2 
  114.          Caption         =   "车    号:"
  115.          Height          =   255
  116.          Index           =   1
  117.          Left            =   240
  118.          TabIndex        =   10
  119.          Top             =   360
  120.          Width           =   975
  121.       End
  122.       Begin VB.Label Label2 
  123.          Caption         =   "结束时间:"
  124.          Height          =   255
  125.          Index           =   16
  126.          Left            =   240
  127.          TabIndex        =   9
  128.          Top             =   1440
  129.          Width           =   975
  130.       End
  131.    End
  132.    Begin VB.CommandButton cmdExit 
  133.       Caption         =   "返回 (&X)"
  134.       Height          =   375
  135.       Left            =   2280
  136.       TabIndex        =   7
  137.       Top             =   3000
  138.       Width           =   1215
  139.    End
  140.    Begin VB.CommandButton cmdSave 
  141.       Caption         =   "保存 (&S)"
  142.       Height          =   375
  143.       Left            =   840
  144.       TabIndex        =   6
  145.       Top             =   3000
  146.       Width           =   1215
  147.    End
  148. End
  149. Attribute VB_Name = "frmStatistic1"
  150. Attribute VB_GlobalNameSpace = False
  151. Attribute VB_Creatable = False
  152. Attribute VB_PredeclaredId = True
  153. Attribute VB_Exposed = False
  154. Option Explicit
  155. '是否改动过记录,ture为改过
  156. Dim mblChange As Boolean
  157. Dim mrc As ADODB.Recordset
  158. Public txtSQL As String
  159. Private Sub cboItem_Change(Index As Integer)
  160.     '有变化设置gblchange
  161.     mblChange = True
  162. End Sub
  163. Private Sub cboItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
  164.     EnterToTab KeyCode
  165. End Sub
  166. Private Sub cmdExit_Click()
  167.     If mblChange And cmdSave.Enabled Then
  168.         If MsgBox("保存当前记录的变化吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
  169.             '保存
  170.             Call cmdSave_Click
  171.         End If
  172.     End If
  173.     Unload Me
  174. End Sub
  175. Private Sub cmdSave_Click()
  176.     Dim intCount As Integer
  177.     Dim sMeg As String
  178.     Dim MsgText As String
  179.     
  180.   
  181.     For intCount = 0 To 1
  182.         If Trim(txtItem(intCount) & " ") = "" Then
  183.             Select Case intCount
  184.                 Case 0
  185.                     sMeg = "开始时间"
  186.                 Case 1
  187.                     sMeg = "结束时间"
  188.             End Select
  189.             sMeg = sMeg & "不能为空!"
  190.             MsgBox sMeg, vbOKOnly + vbExclamation, "警告"
  191.             txtItem(intCount).SetFocus
  192.         
  193.             Exit Sub
  194.         End If
  195.     Next intCount
  196.    
  197.    
  198.         If Not IsDate(txtItem(0)) Then
  199.             MsgBox "开始时间应输入日期(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
  200.             txtItem(0).SetFocus
  201.             
  202.             Exit Sub
  203.         Else
  204.             txtItem(0) = Format(txtItem(0), "yyyy-mm-dd")
  205.         End If
  206.     
  207.     
  208.         If Not IsDate(txtItem(1)) Then
  209.             MsgBox "结束时间应输入日期(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
  210.             txtItem(1).SetFocus
  211.             
  212.             Exit Sub
  213.         Else
  214.             txtItem(1) = Format(txtItem(1), "yyyy-mm-dd")
  215.         End If
  216.     
  217.     
  218.     '添加判断是否有相同的ID记录
  219.     If gintsMode = 1 Then
  220.         txtSQL = "select * from statistic where yyid='" & Trim(cboItem(0)) & "' and yydriver='" & Trim(cboItem(1)) & "' and yybegin_date='" & Format(Trim(txtItem(0)), "yyyy-mm-dd") & "'"
  221.         Set mrc = ExecuteSQL(txtSQL, MsgText)
  222.         If mrc.EOF = False Then
  223.             MsgBox "已经存在相同的记录!", vbOKOnly + vbExclamation, "警告"
  224.             txtItem(0).SetFocus
  225.             Exit Sub
  226.         End If
  227.         mrc.Close
  228.     End If
  229.      
  230.     
  231.     '先删除已有记录
  232.     txtSQL = "delete from statistic where yyid='" & Trim(cboItem(0)) & "' and yydriver='" & Trim(cboItem(1)) & "' and yybegin_date='" & Format(Trim(txtItem(0)), "yyyy-mm-dd") & "'"
  233.     Set mrc = ExecuteSQL(txtSQL, MsgText)
  234.     
  235.    
  236.     
  237.     '再加入新记录
  238.     txtSQL = "select * from statistic"
  239.     Set mrc = ExecuteSQL(txtSQL, MsgText)
  240.     mrc.AddNew
  241.     
  242.     mrc.Fields(0) = Trim(cboItem(0))
  243.     mrc.Fields(1) = Trim(cboItem(1))
  244.     For intCount = 0 To 3
  245.         mrc.Fields(intCount + 2) = Trim(txtItem(intCount))
  246.     Next intCount
  247.     
  248.     mrc.Update
  249.     mrc.Close
  250.     
  251.     If gintsMode = 1 Then
  252.         For intCount = 0 To 3
  253.         txtItem(intCount) = ""
  254.         Next intCount
  255.         mblChange = False
  256.     ElseIf gintsMode = 2 Then
  257.         Unload Me
  258.         If flagsEdit Then
  259.             Unload frmStatistic
  260.         End If
  261.         frmStatistic.txtSQL = "select * from statistic"
  262.         frmStatistic.Show
  263.     End If
  264.     
  265. End Sub
  266. Private Sub Form_Load()
  267.     
  268.     Dim intCount As Integer
  269.     Dim MsgText As String
  270.    
  271.     If gintsMode = 1 Then
  272.         Me.Caption = Me.Caption & "添加"
  273.         
  274.         
  275.         txtSQL = "select DISTINCT clid from vehicle"
  276.         Set mrc = ExecuteSQL(txtSQL, MsgText)
  277.         
  278.         If Not mrc.EOF Then
  279.             
  280.                 Do While Not mrc.EOF
  281.                     cboItem(0).AddItem Trim(mrc!clid)
  282.                     mrc.MoveNext
  283.                 Loop
  284.                 cboItem(0).ListIndex = 0
  285.             
  286.         Else
  287.             MsgBox "请先建立车辆档案!", vbOKOnly + vbExclamation, "警告"
  288.             cmdSave.Enabled = False
  289.             Exit Sub
  290.         End If
  291.         
  292.         mrc.Close
  293.         
  294.         '初始化部门
  295.         txtSQL = "select DISTINCT sjname from driver"
  296.         Set mrc = ExecuteSQL(txtSQL, MsgText)
  297.         
  298.         If Not mrc.EOF Then
  299.             
  300.                 Do While Not mrc.EOF
  301.                     cboItem(1).AddItem Trim(mrc!sjname)
  302.                     mrc.MoveNext
  303.                 Loop
  304.                 cboItem(1).ListIndex = 0
  305.             
  306.         Else
  307.             MsgBox "请先建立司机档案!", vbOKOnly + vbExclamation, "警告"
  308.             cmdSave.Enabled = False
  309.             Exit Sub
  310.         End If
  311.         
  312.     ElseIf gintsMode = 2 Then
  313.     
  314.         Set mrc = ExecuteSQL(txtSQL, MsgText)
  315.         
  316.         If mrc.EOF = False Then
  317.             With mrc
  318.                 For intCount = 0 To 1
  319.                     cboItem(intCount).AddItem .Fields(intCount)
  320.                     cboItem(intCount).ListIndex = 0
  321.                 Next intCount
  322.                 
  323.                 For intCount = 0 To 3
  324.                     If Trim(.Fields(intCount + 2) & " ") <> "" Then
  325.                         txtItem(intCount) = .Fields(intCount + 2)
  326.                     End If
  327.                 Next intCount
  328.                
  329.             End With
  330.             
  331.             txtItem(0).Enabled = False
  332.         End If
  333.         
  334.         Me.Caption = Me.Caption & "修改"
  335.             
  336.         
  337.     End If
  338.     
  339.     mblChange = False
  340.     
  341. End Sub
  342. Private Sub Form_Unload(Cancel As Integer)
  343.     gintsMode = 0
  344. End Sub
  345. Private Sub txtItem_Change(Index As Integer)
  346.     '有变化设置gblchange
  347.     mblChange = True
  348. End Sub
  349. Private Sub txtItem_GotFocus(Index As Integer)
  350.     txtItem(Index).SelStart = 0
  351.     txtItem(Index).SelLength = Len(txtItem(Index))
  352. End Sub
  353. Private Sub txtItem_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
  354.     EnterToTab KeyCode
  355. End Sub
  356. Private Sub txtItem_KeyPress(Index As Integer, KeyAscii As Integer)
  357.     If Index = 2 Or Index = 3 Then
  358.         'MsgBox KeyCode
  359.         '对键入字符进行控制
  360.         'txtQuantity(Index).Locked = False
  361.         '小数点只允许输入一次
  362.         If KeyAscii = 190 Then
  363.             If InStr(Trim(txtItem(Index)), ".") = 0 Then
  364.                 If Len(Trim(txtItem(Index))) > 0 Then
  365.                     txtItem(Index).Locked = False
  366.                 Else
  367.                     txtItem(Index).Locked = True
  368.                 End If
  369.             Else
  370.                 txtItem(Index).Locked = True
  371.             End If
  372.             Exit Sub
  373.         End If
  374.         '非数字不能输入
  375.         If KeyAscii > 57 Or KeyAscii < 48 Then
  376.             txtItem(Index).Locked = True
  377.         Else
  378.             txtItem(Index).Locked = False
  379.         End If
  380.         '允许Backspace
  381.         If KeyAscii = 8 Then
  382.             txtItem(Index).Locked = False
  383.         End If
  384.         'Delete键
  385.         If KeyAscii = 46 Then
  386.             txtItem(Index).Locked = False
  387.         End If
  388.     End If
  389. End Sub