VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Begin VB.Form frmMain 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Импорт справочника сотрудников"
   ClientHeight    =   6165
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   9960
   BeginProperty Font 
      Name            =   "MS Shell Dlg"
      Size            =   8.25
      Charset         =   204
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "Main.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6165
   ScaleWidth      =   9960
   StartUpPosition =   3  'Windows Default
   Begin MSComDlg.CommonDialog CDLG 
      Left            =   240
      Top             =   5280
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      CancelError     =   -1  'True
      DefaultExt      =   "*.xls"
      Filter          =   "Файлы MS Excel (*.xls)|*.xls"
   End
   Begin VB.CheckBox chkReplaceEntries 
      Caption         =   "Заменять &существующие данные"
      Height          =   195
      Left            =   120
      TabIndex        =   19
      Tag             =   "109"
      Top             =   3120
      Width           =   4692
   End
   Begin VB.CheckBox chkEmployeesOnly 
      Caption         =   "&Загружать только сотрудников"
      Height          =   195
      Left            =   6480
      TabIndex        =   20
      Tag             =   "110"
      Top             =   3120
      Width           =   2895
   End
   Begin RichTextLib.RichTextBox txtResults 
      Height          =   1812
      Left            =   120
      TabIndex        =   22
      Top             =   3780
      Width           =   9732
      _ExtentX        =   17171
      _ExtentY        =   3201
      _Version        =   393217
      BorderStyle     =   0
      ReadOnly        =   -1  'True
      ScrollBars      =   2
      TextRTF         =   $"Main.frx":058A
   End
   Begin VB.CheckBox chkBreakOnError 
      Caption         =   "&Останавливать загрузку при ошибках"
      Height          =   195
      Left            =   120
      TabIndex        =   23
      Tag             =   "112"
      Top             =   5820
      Width           =   3312
   End
   Begin VB.CommandButton cmdChooseAdmin 
      Caption         =   "..."
      Height          =   315
      Left            =   9540
      TabIndex        =   12
      Top             =   1800
      Width           =   315
   End
   Begin VB.TextBox txtAdmin 
      Height          =   315
      Left            =   2640
      TabIndex        =   11
      Top             =   1800
      Width           =   6900
   End
   Begin VB.TextBox txtDepGroup 
      Height          =   315
      Left            =   2640
      TabIndex        =   17
      Top             =   2640
      Width           =   6900
   End
   Begin VB.TextBox txtRouter 
      Height          =   315
      Left            =   2640
      TabIndex        =   14
      Top             =   2220
      Width           =   6900
   End
   Begin VB.TextBox txtFileName 
      Height          =   315
      Left            =   2640
      TabIndex        =   5
      Top             =   960
      Width           =   6900
   End
   Begin VB.ComboBox cmbRoutingType 
      Height          =   315
      Left            =   2640
      Style           =   2  'Dropdown List
      TabIndex        =   8
      Top             =   1380
      Width           =   3420
   End
   Begin VB.CommandButton cmdChooseGroup 
      Caption         =   "..."
      Height          =   315
      Left            =   9540
      TabIndex        =   18
      Top             =   2640
      Width           =   315
   End
   Begin VB.CommandButton cmdChooseRouter 
      Caption         =   "..."
      Height          =   315
      Left            =   9540
      TabIndex        =   15
      Top             =   2220
      Width           =   315
   End
   Begin VB.CheckBox chkNotCheckDupAccounts 
      Caption         =   "Не проверять уникальность учетных записей"
      Height          =   495
      Left            =   6480
      TabIndex        =   9
      Tag             =   "105"
      Top             =   1290
      Width           =   3315
   End
   Begin VB.CommandButton cmdClose 
      Cancel          =   -1  'True
      Caption         =   "Закрыть"
      Height          =   315
      Left            =   8400
      TabIndex        =   25
      Tag             =   "114"
      Top             =   5760
      Width           =   1465
   End
   Begin VB.CommandButton cmdLoad 
      Caption         =   "Загрузить"
      Default         =   -1  'True
      Height          =   315
      Left            =   6840
      TabIndex        =   24
      Tag             =   "113"
      Top             =   5760
      Width           =   1465
   End
   Begin VB.CommandButton cmdOpenFile 
      Caption         =   "..."
      Height          =   315
      Left            =   9540
      TabIndex        =   6
      Top             =   960
      Width           =   315
   End
   Begin VB.TextBox txtBaseName 
      Height          =   315
      Left            =   2640
      TabIndex        =   3
      Top             =   540
      Width           =   7212
   End
   Begin VB.TextBox txtServiceURL 
      Height          =   315
      Left            =   2640
      TabIndex        =   1
      Text            =   "http://localhost/DocsVision/StorageServer/StorageServerService.asmx"
      Top             =   120
      Width           =   7212
   End
   Begin VB.Label Label8 
      Caption         =   "&Администратор:"
      Height          =   195
      Left            =   120
      TabIndex        =   10
      Tag             =   "106"
      Top             =   1860
      Width           =   2175
   End
   Begin VB.Label Label7 
      Caption         =   "&Группа для подразделений:"
      Height          =   192
      Left            =   120
      TabIndex        =   16
      Tag             =   "108"
      Top             =   2700
      Width           =   2352
   End
   Begin VB.Label Label6 
      Caption         =   "&Маршрутизатор:"
      Height          =   195
      Left            =   120
      TabIndex        =   13
      Tag             =   "107"
      Top             =   2280
      Width           =   2175
   End
   Begin VB.Label Label5 
      Caption         =   "&Маршрутизация по умолчанию:"
      Height          =   195
      Left            =   120
      TabIndex        =   7
      Tag             =   "104"
      Top             =   1440
      Width           =   2535
   End
   Begin VB.Label Label4 
      Caption         =   "&Результаты загрузки:"
      Height          =   192
      Left            =   120
      TabIndex        =   21
      Tag             =   "111"
      Top             =   3540
      Width           =   2172
   End
   Begin VB.Label Label3 
      Caption         =   "&Файл MS Excel:"
      Height          =   195
      Left            =   120
      TabIndex        =   4
      Tag             =   "103"
      Top             =   1020
      Width           =   2175
   End
   Begin VB.Label Label2 
      Caption         =   "&Имя БД:"
      Height          =   195
      Left            =   120
      TabIndex        =   2
      Tag             =   "102"
      Top             =   600
      Width           =   2175
   End
   Begin VB.Label Label1 
      Caption         =   "URL &сервиса:"
      Height          =   195
      Left            =   120
      TabIndex        =   0
      Tag             =   "101"
      Top             =   180
      Width           =   2175
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private WithEvents m_oLoader As cStaffLoader
Attribute m_oLoader.VB_VarHelpID = -1

Private m_bInLoad As Boolean

Private Function CheckData() As Boolean
   Dim sMsg As String
   If Trim(txtServiceURL.Text) = vbNullString Then sMsg = sMsg & LoadResStringEx(124) & vbCrLf
   If Trim(txtFileName.Text) = vbNullString Then sMsg = sMsg & LoadResStringEx(125) & vbCrLf
   If Trim(txtAdmin.Text) = vbNullString Then sMsg = sMsg & LoadResStringEx(126) & vbCrLf
   If sMsg <> vbNullString Then
      MsgBox sMsg, vbExclamation, LoadResStringEx(100)
   Else
      CheckData = True
   End If
End Function

Private Sub AddMessage(ByVal Message As String)
   txtResults.Text = txtResults.Text & Message & vbCrLf
   txtResults.SelStart = Len(txtResults.Text)
End Sub

Private Sub ChooseAccount(ByVal Control As VB.TextBox, Optional ByVal ChooseUser As Boolean = True)
   On Error GoTo errChoose
   Dim oAccChoose As New HelperAPI.ADItemPicker
   Dim oUser As Object
   Set oUser = oAccChoose.SelectObject(IIf(ChooseUser, AD_USER, AD_GROUP), hWnd)
   If Not oUser Is Nothing Then Control.Text = oUser.Account
   Exit Sub

errChoose:
   ReportError 127
End Sub

Private Sub chkReplaceEntries_Click()
   chkNotCheckDupAccounts.Enabled = (Not chkReplaceEntries.Value = vbChecked)
End Sub

Private Sub cmdChooseAdmin_Click()
   ChooseAccount txtAdmin
End Sub

Private Sub cmdChooseGroup_Click()
   ChooseAccount txtDepGroup, False
End Sub

Private Sub cmdChooseRouter_Click()
   ChooseAccount txtRouter
End Sub

Private Sub cmdClose_Click()
   If m_bInLoad Then Exit Sub
   Unload Me
End Sub

Private Sub cmdLoad_Click()
   If m_bInLoad Then Exit Sub
   If Not CheckData Then Exit Sub
   
   m_bInLoad = True
   txtResults.Text = vbNullString
   Set m_oLoader = New cStaffLoader
   With m_oLoader
      .DefaultRouting = cmbRoutingType.ListIndex
      .CheckDupAccounts = (chkNotCheckDupAccounts.Value = vbUnchecked)
      .AdminAccount = Trim(txtAdmin.Text)
      .RouterAccount = Trim(txtRouter.Text)
      .DepGroup = Trim(txtDepGroup.Text)
      .BreakOnError = (chkBreakOnError.Value = vbChecked)
      .EmployeesOnly = (chkEmployeesOnly.Value = vbChecked)
      .ReplaceEntries = (chkReplaceEntries.Value = vbChecked)
      If Not .LoadStaff(txtServiceURL.Text, txtBaseName.Text, txtFileName.Text) Then
         AddMessage LoadResStringEx(128) & Now
      End If
   End With
   Set m_oLoader = Nothing
   m_bInLoad = False
End Sub

Private Sub cmdOpenFile_Click()
   If m_bInLoad Then Exit Sub

   On Error GoTo errOpen
   CDLG.ShowOpen
   If CDLG.FileName <> vbNullString Then txtFileName.Text = CDLG.FileName
errOpen:
End Sub

Private Sub Form_Load()
   Me.Caption = LoadResStringEx(100)
   LoadResStrings Me.Controls

   With cmbRoutingType
      .Clear
      .AddItem LoadResStringEx(118)
      .AddItem LoadResStringEx(119)
      .AddItem LoadResStringEx(120)
      .AddItem LoadResStringEx(121)
      .AddItem LoadResStringEx(122)
      .AddItem LoadResStringEx(123)
      .ListIndex = 5
   End With
   
   txtServiceURL.Text = cServerURL
   txtBaseName.Text = vbNullString
   
   CDLG.Filter = LoadResStringEx(115)
   
   On Error Resume Next
   Dim oReg As HelperAPI.RegistryKey
   Set oReg = New HelperAPI.RegistryKey
   oReg.Open REG_KEY_LOCAL_MACHINE, "SOFTWARE\DocsVision\TakeOffice\4.3"
   txtServiceURL.Text = oReg.GetValue("SoapServiceURL")
   txtBaseName.Text = oReg.GetValue("BaseName")
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   If UnloadMode = 0 Then
      If m_bInLoad Then
         Cancel = True
         Exit Sub
      End If
   End If
End Sub

Private Sub m_oLoader_ReportProgress(ByVal Message As String)
   AddMessage Message
End Sub
