Option Explicit
Public mode As Integer
Dim photo As Boolean Private Sub cmdEdit_Click()
Dim i As Integer
'如果是新城市,则添加到列表中
For i = 0 To comCity.ListCount - 1
If Trim(comCity.List(i)) = Trim(comCity.Text) Then Exit For
Next
If i > comCity.ListCount - 1 Then
comCity.AddItem comCity.Text
frmMain.comCity.AddItem comCity.Text
ReDim Preserve Cities(UBound(Cities) + 1)
Cities(UBound(Cities)) = comCity.Text
End If
'如果是新职称,则添加到列表中
For i = 0 To comTitle.ListCount - 1
If Trim(comTitle.List(i)) = Trim(comTitle.Text) Then Exit For
Next
If i > comTitle.ListCount - 1 Then
comTitle.AddItem comTitle.Text
frmMain.comTitle.AddItem comTitle.Text
ReDim Preserve Titles(UBound(Titles) + 1)
Titles(UBound(Titles)) = comTitle.Text
End If
Select Case mode
Case 1 '添加
RecNum = RecNum + 1
ReDim Preserve Addrs(RecNum)
With Addrs(RecNum)
.Name = txtName
.Sex = optMale
.Birthday = DateValue(txtbirthday.Text)
.City = comCity.Text
.Company = txtCompany
.Tencent = txtTencent
.Xuehao = txtXuehao
.PostalCode = txtPostalCode
.Email = txtEmail
.Mobile = txtMobile
.Address = txtAddress
.Title = comTitle
.photo = photo
End With
Addrs(i).Modified = True
If Trim(comCity.Text) = Trim(frmMain.comCity) Or Trim(frmMain.comCity) = "全部" Then
If frmMain.comSex.Text = "全部" Or Addrs(RecNum).Sex And frmMain.comSex.Text = "男" Or Not Addrs(RecNum).Sex And frmMain.comSex.Text = "女" Then
frmMain.lstName.AddItem txtName
frmMain.lstName.ItemData(frmMain.lstName.NewIndex) = RecNum
End If
End If
Case 2
i = frmMain.lstName.ItemData(frmMain.lstName.ListIndex) '当前记录号
With Addrs(i)
.Name = txtName
.Sex = optMale
.City = comCity.Text
.Company = txtCompany
.Tencent = txtTencent
.Xuehao = txtXuehao
.PostalCode = txtPostalCode
.Email = txtEmail
.Mobile = txtMobile
.Address = txtAddress
.Title = comTitle
.photo = photo
End With
frmMain.lstName.List(frmMain.lstName.ListIndex) = Addrs(i).Name
Addrs(i).Modified = True
Unload Me
End Select
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdPhoto_Click()
CD.DialogTitle = "指定照片文件"
CD.FileName = ""
CD.ShowOpen
If CD.FileName = "" Then Exit Sub
FileCopy CD.FileName, App.Path & "\photos\" & Trim(txtName) & ".jpg"
imgPhoto.Picture = LoadPicture(App.Path & "\photos\" & Trim(txtName) & ".jpg")
photo = True
End Sub Private Sub cmdPhotoDel_Click()
If Not photo Then Exit Sub
photo = False
imgPhoto.Picture = LoadPicture()
Kill App.Path & "\photos\" & Trim(txtName) & ".jpg"
End Sub Private Sub Form_Load()
Dim i As Integer
Select Case mode
Case 1 '添加
Caption = "添加新记录"
photo = False
Case 2 '修改
i = frmMain.lstName.ItemData(frmMain.lstName.ListIndex)
txtName.Enabled = False
With Addrs(i)
txtName = .Name
If .Sex Then optMale = True Else optFemale = True
txtbirthday = .Birthday
comCity.Text = .City
txtCompany = .Company
txtTencent = .Tencent
txtXuehao = .Xuehao
txtPostalCode = .PostalCode
txtEmail = .Email
txtMobile = .Mobile
txtAddress = .Address
comTitle = .Title
photo = .photo
If .photo = True Then
imgPhoto.Picture = LoadPicture(App.Path & "\photos\" & Trim(Addrs(i).Name) & ".jpg")
End If
End With
Caption = "修改当前记录"
cmdEdit.Caption = "确定"
cmdClose.Caption = "取消"
End Select
For i = 1 To UBound(Cities)
comCity.AddItem Cities(i)
Next
For i = 1 To UBound(Titles)
comTitle.AddItem Titles(i)
Next
End Sub
Public mode As Integer
Dim photo As Boolean Private Sub cmdEdit_Click()
Dim i As Integer
'如果是新城市,则添加到列表中
For i = 0 To comCity.ListCount - 1
If Trim(comCity.List(i)) = Trim(comCity.Text) Then Exit For
Next
If i > comCity.ListCount - 1 Then
comCity.AddItem comCity.Text
frmMain.comCity.AddItem comCity.Text
ReDim Preserve Cities(UBound(Cities) + 1)
Cities(UBound(Cities)) = comCity.Text
End If
'如果是新职称,则添加到列表中
For i = 0 To comTitle.ListCount - 1
If Trim(comTitle.List(i)) = Trim(comTitle.Text) Then Exit For
Next
If i > comTitle.ListCount - 1 Then
comTitle.AddItem comTitle.Text
frmMain.comTitle.AddItem comTitle.Text
ReDim Preserve Titles(UBound(Titles) + 1)
Titles(UBound(Titles)) = comTitle.Text
End If
Select Case mode
Case 1 '添加
RecNum = RecNum + 1
ReDim Preserve Addrs(RecNum)
With Addrs(RecNum)
.Name = txtName
.Sex = optMale
.Birthday = DateValue(txtbirthday.Text)
.City = comCity.Text
.Company = txtCompany
.Tencent = txtTencent
.Xuehao = txtXuehao
.PostalCode = txtPostalCode
.Email = txtEmail
.Mobile = txtMobile
.Address = txtAddress
.Title = comTitle
.photo = photo
End With
Addrs(i).Modified = True
If Trim(comCity.Text) = Trim(frmMain.comCity) Or Trim(frmMain.comCity) = "全部" Then
If frmMain.comSex.Text = "全部" Or Addrs(RecNum).Sex And frmMain.comSex.Text = "男" Or Not Addrs(RecNum).Sex And frmMain.comSex.Text = "女" Then
frmMain.lstName.AddItem txtName
frmMain.lstName.ItemData(frmMain.lstName.NewIndex) = RecNum
End If
End If
Case 2
i = frmMain.lstName.ItemData(frmMain.lstName.ListIndex) '当前记录号
With Addrs(i)
.Name = txtName
.Sex = optMale
.City = comCity.Text
.Company = txtCompany
.Tencent = txtTencent
.Xuehao = txtXuehao
.PostalCode = txtPostalCode
.Email = txtEmail
.Mobile = txtMobile
.Address = txtAddress
.Title = comTitle
.photo = photo
End With
frmMain.lstName.List(frmMain.lstName.ListIndex) = Addrs(i).Name
Addrs(i).Modified = True
Unload Me
End Select
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdPhoto_Click()
CD.DialogTitle = "指定照片文件"
CD.FileName = ""
CD.ShowOpen
If CD.FileName = "" Then Exit Sub
FileCopy CD.FileName, App.Path & "\photos\" & Trim(txtName) & ".jpg"
imgPhoto.Picture = LoadPicture(App.Path & "\photos\" & Trim(txtName) & ".jpg")
photo = True
End Sub Private Sub cmdPhotoDel_Click()
If Not photo Then Exit Sub
photo = False
imgPhoto.Picture = LoadPicture()
Kill App.Path & "\photos\" & Trim(txtName) & ".jpg"
End Sub Private Sub Form_Load()
Dim i As Integer
Select Case mode
Case 1 '添加
Caption = "添加新记录"
photo = False
Case 2 '修改
i = frmMain.lstName.ItemData(frmMain.lstName.ListIndex)
txtName.Enabled = False
With Addrs(i)
txtName = .Name
If .Sex Then optMale = True Else optFemale = True
txtbirthday = .Birthday
comCity.Text = .City
txtCompany = .Company
txtTencent = .Tencent
txtXuehao = .Xuehao
txtPostalCode = .PostalCode
txtEmail = .Email
txtMobile = .Mobile
txtAddress = .Address
comTitle = .Title
photo = .photo
If .photo = True Then
imgPhoto.Picture = LoadPicture(App.Path & "\photos\" & Trim(Addrs(i).Name) & ".jpg")
End If
End With
Caption = "修改当前记录"
cmdEdit.Caption = "确定"
cmdClose.Caption = "取消"
End Select
For i = 1 To UBound(Cities)
comCity.AddItem Cities(i)
Next
For i = 1 To UBound(Titles)
comTitle.AddItem Titles(i)
Next
End Sub