frmPerson.vb
上传用户:wj57717022
上传日期:2014-12-16
资源大小:4093k
文件大小:19k
源码类别:

医药行业

开发平台:

Visual Basic

  1. Public Class frmPerson
  2.     Inherits System.Windows.Forms.Form
  3. #Region " Windows 窗体设计器生成的代码 "
  4.     Public Sub New()
  5.         MyBase.New()
  6.         '该调用是 Windows 窗体设计器所必需的。
  7.         InitializeComponent()
  8.         '在 InitializeComponent() 调用之后添加任何初始化
  9.     End Sub
  10.     '窗体重写 dispose 以清理组件列表。
  11.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  12.         If disposing Then
  13.             If Not (components Is Nothing) Then
  14.                 components.Dispose()
  15.             End If
  16.         End If
  17.         MyBase.Dispose(disposing)
  18.     End Sub
  19.     'Windows 窗体设计器所必需的
  20.     Private components As System.ComponentModel.IContainer
  21.     '注意: 以下过程是 Windows 窗体设计器所必需的
  22.     '可以使用 Windows 窗体设计器修改此过程。
  23.     '不要使用代码编辑器修改它。
  24.     Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
  25.     Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
  26.     Friend WithEvents Label1 As System.Windows.Forms.Label
  27.     Friend WithEvents txtNumber As System.Windows.Forms.TextBox
  28.     Friend WithEvents Label2 As System.Windows.Forms.Label
  29.     Friend WithEvents txtName As System.Windows.Forms.TextBox
  30.     Friend WithEvents Label3 As System.Windows.Forms.Label
  31.     Friend WithEvents txtPassword As System.Windows.Forms.TextBox
  32.     Friend WithEvents tbrSave As System.Windows.Forms.ToolBarButton
  33.     Friend WithEvents tbrmodify As System.Windows.Forms.ToolBarButton
  34.     Friend WithEvents tbrdelete As System.Windows.Forms.ToolBarButton
  35.     Friend WithEvents tbrSpr As System.Windows.Forms.ToolBarButton
  36.     Friend WithEvents tbrExit As System.Windows.Forms.ToolBarButton
  37.     Friend WithEvents MsdnTextboxValidator1 As MSDNTextboxValidator.MSDNTextboxValidator
  38.     Friend WithEvents ErrorProvider1 As System.Windows.Forms.ErrorProvider
  39.     Friend WithEvents tbrAdd As System.Windows.Forms.ToolBarButton
  40.     Friend WithEvents tbrps As System.Windows.Forms.ToolBar
  41.     Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
  42.     Friend WithEvents dgperson As System.Windows.Forms.DataGrid
  43.     Friend WithEvents ImageList2 As System.Windows.Forms.ImageList
  44.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  45.         Me.components = New System.ComponentModel.Container
  46.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmPerson))
  47.         Me.tbrps = New System.Windows.Forms.ToolBar
  48.         Me.tbrAdd = New System.Windows.Forms.ToolBarButton
  49.         Me.tbrSave = New System.Windows.Forms.ToolBarButton
  50.         Me.tbrmodify = New System.Windows.Forms.ToolBarButton
  51.         Me.tbrdelete = New System.Windows.Forms.ToolBarButton
  52.         Me.tbrSpr = New System.Windows.Forms.ToolBarButton
  53.         Me.tbrExit = New System.Windows.Forms.ToolBarButton
  54.         Me.ImageList2 = New System.Windows.Forms.ImageList(Me.components)
  55.         Me.StatusBar1 = New System.Windows.Forms.StatusBar
  56.         Me.GroupBox1 = New System.Windows.Forms.GroupBox
  57.         Me.txtPassword = New System.Windows.Forms.TextBox
  58.         Me.Label3 = New System.Windows.Forms.Label
  59.         Me.txtName = New System.Windows.Forms.TextBox
  60.         Me.Label2 = New System.Windows.Forms.Label
  61.         Me.txtNumber = New System.Windows.Forms.TextBox
  62.         Me.Label1 = New System.Windows.Forms.Label
  63.         Me.MsdnTextboxValidator1 = New MSDNTextboxValidator.MSDNTextboxValidator(Me.components)
  64.         Me.ErrorProvider1 = New System.Windows.Forms.ErrorProvider
  65.         Me.GroupBox2 = New System.Windows.Forms.GroupBox
  66.         Me.dgperson = New System.Windows.Forms.DataGrid
  67.         Me.GroupBox1.SuspendLayout()
  68.         Me.GroupBox2.SuspendLayout()
  69.         CType(Me.dgperson, System.ComponentModel.ISupportInitialize).BeginInit()
  70.         Me.SuspendLayout()
  71.         '
  72.         'tbrps
  73.         '
  74.         Me.tbrps.Appearance = System.Windows.Forms.ToolBarAppearance.Flat
  75.         Me.tbrps.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.tbrAdd, Me.tbrSave, Me.tbrmodify, Me.tbrdelete, Me.tbrSpr, Me.tbrExit})
  76.         Me.tbrps.DropDownArrows = True
  77.         Me.tbrps.ImageList = Me.ImageList2
  78.         Me.tbrps.Location = New System.Drawing.Point(0, 0)
  79.         Me.tbrps.Name = "tbrps"
  80.         Me.tbrps.ShowToolTips = True
  81.         Me.tbrps.Size = New System.Drawing.Size(748, 44)
  82.         Me.tbrps.TabIndex = 0
  83.         '
  84.         'tbrAdd
  85.         '
  86.         Me.tbrAdd.ImageIndex = 7
  87.         Me.tbrAdd.Text = "添加"
  88.         '
  89.         'tbrSave
  90.         '
  91.         Me.tbrSave.ImageIndex = 4
  92.         Me.tbrSave.Text = "保存"
  93.         '
  94.         'tbrmodify
  95.         '
  96.         Me.tbrmodify.ImageIndex = 5
  97.         Me.tbrmodify.Text = "修改"
  98.         '
  99.         'tbrdelete
  100.         '
  101.         Me.tbrdelete.ImageIndex = 6
  102.         Me.tbrdelete.Text = "删除"
  103.         '
  104.         'tbrSpr
  105.         '
  106.         Me.tbrSpr.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
  107.         '
  108.         'tbrExit
  109.         '
  110.         Me.tbrExit.ImageIndex = 11
  111.         Me.tbrExit.Text = "退出"
  112.         '
  113.         'ImageList2
  114.         '
  115.         Me.ImageList2.ImageSize = New System.Drawing.Size(16, 16)
  116.         Me.ImageList2.ImageStream = CType(resources.GetObject("ImageList2.ImageStream"), System.Windows.Forms.ImageListStreamer)
  117.         Me.ImageList2.TransparentColor = System.Drawing.Color.Transparent
  118.         '
  119.         'StatusBar1
  120.         '
  121.         Me.StatusBar1.Location = New System.Drawing.Point(0, 437)
  122.         Me.StatusBar1.Name = "StatusBar1"
  123.         Me.StatusBar1.Size = New System.Drawing.Size(748, 23)
  124.         Me.StatusBar1.TabIndex = 1
  125.         '
  126.         'GroupBox1
  127.         '
  128.         Me.GroupBox1.Controls.Add(Me.txtPassword)
  129.         Me.GroupBox1.Controls.Add(Me.Label3)
  130.         Me.GroupBox1.Controls.Add(Me.txtName)
  131.         Me.GroupBox1.Controls.Add(Me.Label2)
  132.         Me.GroupBox1.Controls.Add(Me.txtNumber)
  133.         Me.GroupBox1.Controls.Add(Me.Label1)
  134.         Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Left
  135.         Me.GroupBox1.Location = New System.Drawing.Point(0, 44)
  136.         Me.GroupBox1.Name = "GroupBox1"
  137.         Me.GroupBox1.Size = New System.Drawing.Size(256, 393)
  138.         Me.GroupBox1.TabIndex = 2
  139.         Me.GroupBox1.TabStop = False
  140.         Me.GroupBox1.Text = "人员信息"
  141.         '
  142.         'txtPassword
  143.         '
  144.         Me.MsdnTextboxValidator1.SetCustomValidationEnabled(Me.txtPassword, True)
  145.         Me.MsdnTextboxValidator1.SetDataType(Me.txtPassword, MSDNTextboxValidator.DataTypeConstants.StringType)
  146.         Me.MsdnTextboxValidator1.SetDisplayName(Me.txtPassword, "")
  147.         Me.txtPassword.Location = New System.Drawing.Point(72, 112)
  148.         Me.MsdnTextboxValidator1.SetMaxValue(Me.txtPassword, "")
  149.         Me.MsdnTextboxValidator1.SetMinValue(Me.txtPassword, "")
  150.         Me.txtPassword.Name = "txtPassword"
  151.         Me.txtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
  152.         Me.MsdnTextboxValidator1.SetRegularExpression(Me.txtPassword, "")
  153.         Me.MsdnTextboxValidator1.SetRequired(Me.txtPassword, False)
  154.         Me.txtPassword.Size = New System.Drawing.Size(176, 25)
  155.         Me.txtPassword.TabIndex = 5
  156.         Me.txtPassword.Text = ""
  157.         '
  158.         'Label3
  159.         '
  160.         Me.Label3.AutoSize = True
  161.         Me.Label3.Location = New System.Drawing.Point(8, 112)
  162.         Me.Label3.Name = "Label3"
  163.         Me.Label3.Size = New System.Drawing.Size(52, 21)
  164.         Me.Label3.TabIndex = 4
  165.         Me.Label3.Text = "密码:"
  166.         '
  167.         'txtName
  168.         '
  169.         Me.MsdnTextboxValidator1.SetCustomValidationEnabled(Me.txtName, True)
  170.         Me.MsdnTextboxValidator1.SetDataType(Me.txtName, MSDNTextboxValidator.DataTypeConstants.StringType)
  171.         Me.MsdnTextboxValidator1.SetDisplayName(Me.txtName, "")
  172.         Me.txtName.Location = New System.Drawing.Point(72, 72)
  173.         Me.MsdnTextboxValidator1.SetMaxValue(Me.txtName, "")
  174.         Me.MsdnTextboxValidator1.SetMinValue(Me.txtName, "")
  175.         Me.txtName.Name = "txtName"
  176.         Me.MsdnTextboxValidator1.SetRegularExpression(Me.txtName, "")
  177.         Me.MsdnTextboxValidator1.SetRequired(Me.txtName, False)
  178.         Me.txtName.Size = New System.Drawing.Size(176, 25)
  179.         Me.txtName.TabIndex = 3
  180.         Me.txtName.Text = ""
  181.         '
  182.         'Label2
  183.         '
  184.         Me.Label2.AutoSize = True
  185.         Me.Label2.Location = New System.Drawing.Point(8, 72)
  186.         Me.Label2.Name = "Label2"
  187.         Me.Label2.Size = New System.Drawing.Size(52, 21)
  188.         Me.Label2.TabIndex = 2
  189.         Me.Label2.Text = "姓名:"
  190.         '
  191.         'txtNumber
  192.         '
  193.         Me.MsdnTextboxValidator1.SetCustomValidationEnabled(Me.txtNumber, True)
  194.         Me.MsdnTextboxValidator1.SetDataType(Me.txtNumber, MSDNTextboxValidator.DataTypeConstants.Int64Type)
  195.         Me.MsdnTextboxValidator1.SetDisplayName(Me.txtNumber, "")
  196.         Me.txtNumber.Location = New System.Drawing.Point(72, 32)
  197.         Me.MsdnTextboxValidator1.SetMaxValue(Me.txtNumber, "")
  198.         Me.MsdnTextboxValidator1.SetMinValue(Me.txtNumber, "")
  199.         Me.txtNumber.Name = "txtNumber"
  200.         Me.MsdnTextboxValidator1.SetRegularExpression(Me.txtNumber, "")
  201.         Me.MsdnTextboxValidator1.SetRequired(Me.txtNumber, False)
  202.         Me.txtNumber.Size = New System.Drawing.Size(176, 25)
  203.         Me.txtNumber.TabIndex = 1
  204.         Me.txtNumber.Text = ""
  205.         '
  206.         'Label1
  207.         '
  208.         Me.Label1.AutoSize = True
  209.         Me.Label1.Location = New System.Drawing.Point(8, 32)
  210.         Me.Label1.Name = "Label1"
  211.         Me.Label1.Size = New System.Drawing.Size(52, 21)
  212.         Me.Label1.TabIndex = 0
  213.         Me.Label1.Text = "编号:"
  214.         '
  215.         'MsdnTextboxValidator1
  216.         '
  217.         Me.MsdnTextboxValidator1.DisplayControl = Nothing
  218.         Me.MsdnTextboxValidator1.ErrorProvider = Nothing
  219.         Me.MsdnTextboxValidator1.InvalidBackColor = System.Drawing.Color.Empty
  220.         Me.MsdnTextboxValidator1.TooltipProvider = Nothing
  221.         '
  222.         'ErrorProvider1
  223.         '
  224.         Me.ErrorProvider1.ContainerControl = Me
  225.         '
  226.         'GroupBox2
  227.         '
  228.         Me.GroupBox2.Controls.Add(Me.dgperson)
  229.         Me.GroupBox2.Dock = System.Windows.Forms.DockStyle.Fill
  230.         Me.GroupBox2.Location = New System.Drawing.Point(256, 44)
  231.         Me.GroupBox2.Name = "GroupBox2"
  232.         Me.GroupBox2.Size = New System.Drawing.Size(492, 393)
  233.         Me.GroupBox2.TabIndex = 3
  234.         Me.GroupBox2.TabStop = False
  235.         '
  236.         'dgperson
  237.         '
  238.         Me.dgperson.DataMember = ""
  239.         Me.dgperson.Dock = System.Windows.Forms.DockStyle.Fill
  240.         Me.dgperson.HeaderForeColor = System.Drawing.SystemColors.ControlText
  241.         Me.dgperson.Location = New System.Drawing.Point(3, 21)
  242.         Me.dgperson.Name = "dgperson"
  243.         Me.dgperson.Size = New System.Drawing.Size(486, 369)
  244.         Me.dgperson.TabIndex = 0
  245.         '
  246.         'frmPerson
  247.         '
  248.         Me.AutoScaleBaseSize = New System.Drawing.Size(8, 18)
  249.         Me.ClientSize = New System.Drawing.Size(748, 460)
  250.         Me.Controls.Add(Me.GroupBox2)
  251.         Me.Controls.Add(Me.GroupBox1)
  252.         Me.Controls.Add(Me.StatusBar1)
  253.         Me.Controls.Add(Me.tbrps)
  254.         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
  255.         Me.Name = "frmPerson"
  256.         Me.Text = "frmPerson"
  257.         Me.GroupBox1.ResumeLayout(False)
  258.         Me.GroupBox2.ResumeLayout(False)
  259.         CType(Me.dgperson, System.ComponentModel.ISupportInitialize).EndInit()
  260.         Me.ResumeLayout(False)
  261.     End Sub
  262. #End Region
  263.     Public lsweb As New jxcmanage
  264.     Public dslocals As New DataSet
  265.     Private Sub frmPerson_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  266.         dslocals = lsweb.returndataset("select * from wz_mm", "wz_mm")
  267.         ' dslocals.Clear()
  268.         dgperson.DataSource = dslocals.Tables("wz_mm").DefaultView
  269.     End Sub
  270.     Private Sub add()
  271.         txtNumber.Text = "".Trim()
  272.         txtName.Text = "".Trim()
  273.         txtPassword.Text = "".Trim()
  274.     End Sub
  275.     Private Sub save()
  276.         dslocals = lsweb.returndataset("select * from wz_mm", "wz_mm")
  277.         Dim dr As DataRow = dslocals.Tables(0).NewRow()
  278.         dr("人员代码") = txtNumber.Text.Trim
  279.         dr("操作员") = txtName.Text.Trim
  280.         dr("密码") = txtPassword.Text.Trim
  281.         dslocals.Tables(0).Rows.Add(dr)
  282.         If lsweb.updatedataset("select * from wz_mm", "wz_mm", dslocals, DataRowState.Added) = True Then
  283.             Dim strquery As String
  284.             strquery = "insert into dbo.wz_Qxmenu(username,Cname,Ename,Ctype,Cctype,Cbit,DBit) select '" & txtName.Text & "',Cname,Ename,Ctype,Cctype,Cbit,DBit from dbo.wz_Qxmenu where username='admin'"
  285.             lsweb.runSql(strquery)
  286.             MessageBox.Show("信息成功保存!", "提示", MessageBoxButtons.OK)
  287.         Else
  288.             MessageBox.Show("信息保存失败!", "提示", MessageBoxButtons.AbortRetryIgnore)
  289.         End If
  290.         
  291.     End Sub
  292.     Private Sub modify()
  293.         If lsweb.updatedataset("select 人员代码,操作员,密码 from wz_mm", "wz_mm", dslocals, DataRowState.Modified) = True Then
  294.             MessageBox.Show("人员信息修改成功!", "提示", MessageBoxButtons.OK)
  295.         Else
  296.             MessageBox.Show("人员信息修改失败!", "提示", MessageBoxButtons.OK)
  297.         End If
  298.     End Sub
  299.     Private Sub delete()
  300.         Dim drv As DataRowView = BindingContext(Me.dgperson.DataSource).Current
  301.         If drv(0) Is System.DBNull.Value Then
  302.             MessageBox.Show("没有要删除的记录!", "提示", MessageBoxButtons.OK)
  303.         Else
  304.             Dim strquery As String = drv(0)
  305.             Try
  306.                 Dim strsql, strCustomer As String
  307.                 strCustomer = "delete wz_mm where 操作员='" & drv(1) & "'"
  308.                 lsweb.runSql(strCustomer)
  309.                 strsql = "delete wz_Qxmenu where username='" & drv(1) & "'"
  310.                 lsweb.runSql(strsql)
  311.                 MessageBox.Show("已经删除记录啦!", "提示", MessageBoxButtons.OK)
  312.             Catch ex As Exception
  313.                 MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK)
  314.             End Try
  315.             
  316.             
  317.         End If
  318.     End Sub
  319.     Private Sub view()
  320.         Dim drv As DataRowView = BindingContext(Me.dgperson.DataSource).Current
  321.         Dim dr As DataRow
  322.         dr = drv.Row
  323.         txtNumber.Text = IIf(dr("人员代码") Is System.DBNull.Value, "", dr("人员代码"))
  324.         txtName.Text = IIf(dr("操作员") Is System.DBNull.Value, "", dr("操作员"))
  325.         txtPassword.Text = IIf(dr("密码") Is System.DBNull.Value, "", dr("密码"))
  326.     End Sub
  327.     Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tbrps.ButtonClick
  328.         Select Case e.Button.Text
  329.             Case "添加"
  330.                 tbnEnable("tbrAdd.Enabled = False", tbrps)
  331.                 add()
  332.             Case "保存"
  333.                 If txtNumber.Text = "" Or txtName.Text = "" Then
  334.                     MessageBox.Show("信息不完整,保存失败!", "提示", MessageBoxButtons.OK)
  335.                 Else
  336.                     tbnEnable("tbrSave.Enabled = False", tbrps)
  337.                     save()
  338.                     Dim frmmaininst As New frmMain
  339.                     Dim mi As MenuItem
  340.                     For Each mi In frmmaininst.Menu.MenuItems
  341.                         lsweb.menuuser(Me.txtName.Text.Trim, "menuitemid", mi.Text.Trim)
  342.                     Next
  343.                 End If
  344.                
  345.             Case "修改"
  346.                 tbnEnable("tbrModify.Enabled = False", tbrps)
  347.                 modify()
  348.             Case "删除"
  349.                 tbnEnable("tbrDelete.Enabled = False", tbrps)
  350.                 delete()
  351.             Case "退出"
  352.                 Me.Close()
  353.         End Select
  354.     End Sub
  355.     Public Sub tbnEnable(ByVal strboolean As String, ByVal tbr As ToolBar)
  356.         If strboolean = "tbrAdd.Enabled = True" Then
  357.             tbrSave.Enabled = False
  358.             tbrmodify.Enabled = False
  359.             tbrdelete.Enabled = False
  360.             tbrExit.Enabled = True
  361.         ElseIf strboolean = "tbrAdd.Enabled = False" Then
  362.             tbrAdd.Enabled = False
  363.             tbrSave.Enabled = True
  364.             tbrmodify.Enabled = False
  365.             tbrdelete.Enabled = False
  366.             tbrExit.Enabled = True
  367.         ElseIf strboolean = "tbrSave.Enabled = True" Then
  368.             tbrAdd.Enabled = False
  369.             tbrmodify.Enabled = False
  370.             tbrdelete.Enabled = False
  371.             tbrExit.Enabled = True
  372.         ElseIf strboolean = "tbrSave.Enabled = False" Then
  373.             tbrSave.Enabled = False
  374.             tbrAdd.Enabled = True
  375.             tbrmodify.Enabled = True
  376.             tbrdelete.Enabled = True
  377.             tbrExit.Enabled = True
  378.         ElseIf strboolean = "tbrModify.Enabled = True" Then
  379.             tbrAdd.Enabled = False
  380.             tbrSave.Enabled = True
  381.             tbrdelete.Enabled = False
  382.             tbrExit.Enabled = True
  383.         ElseIf strboolean = "tbrModify.Enabled = False" Then
  384.             tbrmodify.Enabled = False
  385.             tbrAdd.Enabled = False
  386.             tbrSave.Enabled = True
  387.             tbrdelete.Enabled = False
  388.             tbrExit.Enabled = True
  389.         ElseIf strboolean = "tbrDelete.Enabled = True" Then
  390.             tbrAdd.Enabled = False
  391.             tbrSave.Enabled = True
  392.             tbrmodify.Enabled = False
  393.             tbrExit.Enabled = True
  394.         ElseIf strboolean = "tbrDelete.Enabled = False" Then
  395.             tbrdelete.Enabled = False
  396.             tbrAdd.Enabled = False
  397.             tbrSave.Enabled = True
  398.             tbrmodify.Enabled = False
  399.             tbrExit.Enabled = True
  400.         End If
  401.     End Sub
  402.     Private Sub txtNumber_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtNumber.Validating
  403.         If txtNumber.Text = String.Empty Then
  404.             ErrorProvider1.SetError(txtNumber, "不能为空,请输入人员代码!")
  405.             e.Cancel = True
  406.         Else
  407.             ErrorProvider1.SetError(txtNumber, "")
  408.         End If
  409.     End Sub
  410.     Private Sub txtName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtName.Validating
  411.         If txtName.Text = String.Empty Then
  412.             ErrorProvider1.SetError(txtName, "不能为空,请输入姓名!")
  413.             e.Cancel = True
  414.         Else
  415.             ErrorProvider1.SetError(txtName, "")
  416.         End If
  417.     End Sub
  418.     Private Sub txtPassword_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtPassword.Validating
  419.         If txtPassword.Text = String.Empty Then
  420.             ErrorProvider1.SetError(txtPassword, "不能为空,请输入密码!")
  421.             e.Cancel = True
  422.         Else
  423.             ErrorProvider1.SetError(txtPassword, "")
  424.         End If
  425.     End Sub
  426.    
  427.     Private Sub dgperson_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgperson.CurrentCellChanged
  428.         view()
  429.         tbrmodify.Enabled = True
  430.         tbrdelete.Enabled = True
  431.         tbrExit.Enabled = True
  432.     End Sub
  433. End Class