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    =   4320
   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     =   4320
   ScaleWidth      =   9960
   StartUpPosition =   3  'Windows Default
   Begin VB.CheckBox chkReplaceEntries 
      Caption         =   "Заменять &существующие данные"
      Height          =   195
      Left            =   120
      TabIndex        =   9
      Tag             =   "109"
      Top             =   3960
      Width           =   4692
   End
   Begin VB.TextBox txtFileName 
      Height          =   315
      Left            =   2580
      TabIndex        =   5
      Top             =   960
      Width           =   6960
   End
   Begin MSComDlg.CommonDialog CDLG 
      Left            =   180
      Top             =   3300
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      CancelError     =   -1  'True
      DefaultExt      =   "*.xls"
      Filter          =   "Файлы MS Excel (*.xls)|*.xls"
   End
   Begin VB.CommandButton cmdClose 
      Cancel          =   -1  'True
      Caption         =   "Закрыть"
      Height          =   315
      Left            =   8400
      TabIndex        =   11
      Tag             =   "114"
      Top             =   3900
      Width           =   1465
   End
   Begin VB.CommandButton cmdLoad 
      Caption         =   "Загрузить"
      Default         =   -1  'True
      Height          =   315
      Left            =   6840
      TabIndex        =   10
      Tag             =   "113"
      Top             =   3900
      Width           =   1465
   End
   Begin RichTextLib.RichTextBox txtResults 
      Height          =   2055
      Left            =   120
      TabIndex        =   8
      Top             =   1680
      Width           =   9735
      _ExtentX        =   17171
      _ExtentY        =   3625
      _Version        =   393217
      BorderStyle     =   0
      ReadOnly        =   -1  'True
      ScrollBars      =   2
      TextRTF         =   $"Main.frx":0E42
   End
   Begin VB.CommandButton cmdOpenFile 
      Caption         =   "..."
      Height          =   315
      Left            =   9540
      TabIndex        =   6
      Top             =   960
      Width           =   315
   End
   Begin VB.TextBox txtBaseName 
      Height          =   315
      Left            =   2580
      TabIndex        =   3
      Top             =   540
      Width           =   7275
   End
   Begin VB.TextBox txtServiceURL 
      Height          =   315
      Left            =   2580
      TabIndex        =   1
      Text            =   "http://localhost/DocsVision/StorageServer/StorageServerService.asmx"
      Top             =   120
      Width           =   7275
   End
   Begin VB.Label Label4 
      Caption         =   "&Результаты загрузки:"
      Height          =   195
      Left            =   120
      TabIndex        =   7
      Tag             =   "111"
      Top             =   1440
      Width           =   2175
   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 cPartnersLoader
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 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 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 cPartnersLoader
   With m_oLoader
      .ReplaceEntries = (chkReplaceEntries.Value = vbChecked)
      If Not .LoadPartners(txtServiceURL.Text, txtBaseName.Text, txtFileName.Text) Then
         AddMessage LoadResStringEx(128)
      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
   
   CDLG.Filter = LoadResStringEx(115)

   txtServiceURL.Text = cServerURL
   txtBaseName.Text = vbNullString
   
   On Error Resume Next
   Dim oReg As HelperAPI.RegistryKey
   Set oReg = New HelperAPI.RegistryKey
   oReg.Open REG_KEY_LOCAL_MACHINE, "SOFTWARE\DocsVision\TakeOffice\4.1"
   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
