Create BMC Entry from Genesis32

VBA Function GetEntryForSCADA create at Class Library MSVS2003 C#

:

using System;
using System.Text;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace ClassLibrary1
{
	[Guid("EA5D24FD-5CC1-42df-9D5B-DF2EB088540D")]
	public interface IMyClass
	{
		[DispId(1)]
		//string GetEntryForSCADA(string ARServerName, string ARUser, string ARPassword, int Port, string FormName, string Qualification,	System.Collections.ArrayList EntryFields, int FirstRetrieve, int maxRetrieve);
		string[,,] GetEntryForSCADA(string ARServerName, string ARUser, string ARPassword, int Port, string FormName, string Qualification, int[] EntryFields, int FirstRetrieve, int maxRetrieve);
		[DispId(2)]
		int i {get;set;}
	}

	//Events
	[Guid("B253E42B-39C4-4108-B7BC-73EE0C3E3336"),
	InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
	public interface IMyEvents
	{

	}

	[Guid("E800190C-4BF4-4d5d-AA5A-E776CE989A43"),
	ClassInterface(ClassInterfaceType.None),
	ComSourceInterfaces(typeof(IMyEvents))]
	public class MyClass:IMyClass
	{
		private int _i;
		public int i
		{
			get {return _i;}
			set {_i = value;}
		}

		public MyClass()
		{
		}

		//public string GetEntryForSCADA(string ARServerName, string ARUser, string ARPassword, int Port, string FormName, string Qualification, System.Collections.ArrayList EntryFields, int FirstRetrieve, int maxRetrieve)
		public string[,,] GetEntryForSCADA(string ARServerName, string ARUser, string ARPassword, int Port, string FormName, string Qualification, int[] EntryFields, int FirstRetrieve, int maxRetrieve)
		{
			BMC.ARSystem.EntryListFieldList FieldIdList = new BMC.ARSystem.EntryListFieldList();
			uint FirstRetrieveUInt;
			uint maxRetrieveUInt;
			string[,,] res = new string[3,3,3];
			res[0,0,0] = EntryFields[0].ToString();
			res[0,0,1] = EntryFields[1].ToString();
			//res[0,0,2] = "2";
			//res[0,1,0] = "10";
			//res[0,1,1] = "11";
			//res[0,1,2] = "12";

			if (EntryFields.Length > 0)
			{
				for (int i = 0; i < EntryFields.Length; i++)
				{
					FieldIdList.AddField(EntryFields[i]);
				}
				FirstRetrieveUInt = Convert.ToUInt32(FirstRetrieve);
				maxRetrieveUInt = Convert.ToUInt32(maxRetrieve);

				BMC.ARSystem.Server BMCServer = new BMC.ARSystem.Server();

				BMCServer.Login(ARServerName, ARUser, ARPassword, "", Port);

				BMC.ARSystem.EntryFieldValueList entryWithFields = BMCServer.GetListEntryWithFields(FormName, Qualification, FieldIdList, FirstRetrieveUInt, maxRetrieveUInt);
                
				int j = 0;

				foreach (BMC.ARSystem.EntryFieldValue entry in entryWithFields)
				{
					for (int i = 0; i < entry.FieldValues.Count; i++)
					{
						if (j == 0 & i == 0)
						{
							res = new string[entryWithFields.Count, entry.FieldValues.Count, 2];
						}
						res[j, i, 0] = entry.FieldValues.Fields[i].ToString();
						res[j, i, 1] = entry.FieldValues[uint.Parse(res[j, i, 0])].ToString();
					}
					j++;
				}
				
			}
			
			return res;
		}
	}
}

VBA code:

' All functions and subroutines related to the subroutine CreateEntry should
' reside in this module or in modules GwxCreateEntry_<CustomName>.

Sub CreateEntry(o As GwxPick)
Set Dat1 = ThisDisplay.GetDynamicObjectFromName("ServiceCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
serv = Dat1Val.Value

If (ThisDisplay.ComboBox1.Text = "" Or serv = "") Then
MsgBox "Поле - 'Назначенное лицо' и 'Сервис' не может быть пустым!"
Else
Dim mas As ArrayList
Set mas = New ArrayList


Dim wq As String
wq = ThisDisplay.ComboBox1.Text




Dim FieldValues As BMC_ARSystem.FieldValueList
Set FieldValues = New BMC_ARSystem.FieldValueList
Dim obj
Set obj = FieldValues

obj(1000000076) = "CREATE"
mas.Add (obj(1000000076))
'sa = ThisDisplay.TextBox1.Value
obj(1000000018) = "Мальцев" 'Last Name
obj(1000000019) = "Юрий" 'First Name
mas.Add (obj(1000000018))
mas.Add (obj(1000000019))
'obj(7) = 1 'Status
'------------------------------------ 'Status
Set Dat1 = ThisDisplay.GetDynamicObjectFromName("StatusCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
Select Case Dat1Val.Value
    Case 1
        obj(7) = "New"
    Case 2
        obj(7) = "Assigned"
    Case 3
        obj(7) = "In Progress"
    Case 4
        obj(7) = "Pending"
    Case 5
        obj(7) = "Resolved"
    Case 6
        obj(7) = "Closed"
    Case 7
        obj(7) = "Cancelled"
    End Select
'obj(7) = Dat1Val.Value
mas.Add (obj(7))
'-------------------------------------
'obj(1000000099) = 1 'Service Type
'------------------------------------ 'Service Type
Set Dat1 = ThisDisplay.GetDynamicObjectFromName("TipCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
Select Case Dat1Val.Value
    Case 1
        obj(1000000099) = "User Service Restoration"
    Case 2
        obj(1000000099) = "User Service Request"
    Case 3
        obj(1000000099) = "Infrastructure Restoration"
    Case 4
        obj(1000000099) = "Infrastructure Event"
    End Select
'obj(1000000099) = Dat1Val.Value
mas.Add (obj(1000000099))
'-------------------------------------
'------------------------------------Impact
   
Set Dat1 = ThisDisplay.GetDynamicObjectFromName("VliyanieCOMBOBOX")
Set Dat1ValImpact = Dat1.GetDataSourcePointObject
Set Dat1 = ThisDisplay.GetDynamicObjectFromName("SrochnostCOMBOBOX")
Set Dat1ValUrgency = Dat1.GetDataSourcePointObject
Set Dat1 = ThisDisplay.GetDynamicObjectFromName("Prioritet")
Set Dat1ValPrioritet = Dat1.GetDataSourcePointObject

'Select Case ThisDisplay.TextBox10.Value
'Case 100
    'Dat1ValImpact.Value = 4
    'Dat1ValUrgency.Value = 4
    'Dat1ValPrioritet.Value = 4
'Case 300
    'Dat1ValImpact.Value = 4
    'Dat1ValUrgency.Value = 4
    'Dat1ValPrioritet.Value = 4
'Case 500
    'Dat1ValImpact.Value = 3
    'Dat1ValUrgency.Value = 3
    'Dat1ValPrioritet.Value = 3
'Case 700
    'Dat1ValImpact.Value = 2
    'Dat1ValUrgency.Value = 2
    'Dat1ValPrioritet.Value = 2
'Case 900
'    Dat1ValImpact.Value = 1
    'Dat1ValUrgency.Value = 1
    'Dat1ValPrioritet.Value = 1
'End Select

Select Case Dat1ValImpact.Value
    Case 1
        obj(1000000163) = 1000
        obj(1000000164) = 0
    Case 2
        obj(1000000163) = 2000
        obj(1000000164) = 1
    Case 3
        obj(1000000163) = 3000
        obj(1000000164) = 2
    Case 4
        obj(1000000163) = 4000
        obj(1000000164) = 3
    End Select
    mas.Add (obj(1000000163))
'-------------------------------------
'obj(1000000162) = 4000 'Urgency
'------------------------------------Urgency
Select Case Dat1ValUrgency.Value
    Case 1
        obj(1000000162) = 1000
    Case 2
        obj(1000000162) = 2000
    Case 3
        obj(1000000162) = 3000
    Case 4
        obj(1000000162) = 4000
    End Select
    mas.Add (obj(1000000162))
'-------------------------------------
'------------------------------------Priority

'-------------------------------------
obj(1000000000) = left(ThisDisplay.TextBox6.Value + " ~ " + ThisDisplay.TextBox9.Value, 99) '"Тема" 'Description
mas.Add (obj(1000000000))
obj(1000000151) = ThisDisplay.TextBox7.Value + " " + ThisDisplay.TextBox9.Value + " " + ThisDisplay.TextBox12.Value 'Detailed Description
mas.Add (obj(1000000151))
obj(1000000215) = 11000 'Reported Source система мониторинга
mas.Add (obj(1000000215))
obj(1000000001) = "ЗАО Company" 'Company
mas.Add (obj(1000000001))
obj(112) = "1000000047;" 'Assignee Groups
mas.Add (obj(1000000112))
obj(230000000) = "AST:BusinessService" '
obj(230000009) = "BMC_BUSINESSSERVICE" '
obj(1000000022) = 2000 'Contact Client Type
obj(1000000026) = 2000 'VIP
obj(1000000169) = 0 'Priority Weight
obj(1000000082) = "ЗАО Company" 'Contact Company
mas.Add (obj(1000000082))
'obj(303519300) = "REGAA5V0G4Q6HAM4HEFP4PGX2AMKFW" 'ServiceCI_ReconID
'obj(303497300) = "АСУТП" 'ServiceCI
'------------------------------------ServiceCIrgency
Set Dat1 = ThisDisplay.GetDynamicObjectFromName("ServiceCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
obj(303497300) = Dat1Val.Value
mas.Add (obj(303497300))
'f = Dat1Val.Text4

Dim d As ClassLibrary1.MyClass
Set d = New ClassLibrary1.MyClass
Dim mi() As Long
ReDim mi(4)
mi(0) = 400129200
mi(1) = 200000020
mi(2) = 200000003
mi(3) = 200000004
mi(4) = 200000005

Dim sql
sql = "('200000020' = """ + Dat1Val.Value + """ and '200000005' != null)"
Dim str2
Dim objsrv As Object
Set objsrv = d
str2 = objsrv.GetEntryForSCADA("10.8.39.78", ThisDisplay.TextBox1, ThisDisplay.TextBox2, 1111, "AST:BusinessService", sql, mi, 0, 1)

obj(303519300) = str2(0, 0, 1) 'Reconciliation Identitity 400129200
ThisDisplay.FoundServiceID = str2(0, 0, 1)
mas.Add (obj(303519300))
obj(200000003) = str2(0, 3, 1) '"Общекорпоративные сервисы" 'Product Categorization Tier 1
mas.Add (obj(200000003))
obj(200000004) = str2(0, 2, 1) '"Обеспечение услугами эксплуатационной поддержки" 'Product Categorization Tier 2
mas.Add (obj(200000004))
obj(200000005) = str2(0, 1, 1) '"Обеспечение услугами поддержки эксплуатации ГМ" 'Product Categorization Tier 3
mas.Add (obj(200000005))
'----------------------------------------
Set Dat1 = ThisDisplay.GetDynamicObjectFromName("GroupCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
obj(1000000217) = Dat1Val.Value '"РГ Аварии в SCADA"  'Assigned Group---------------------------------------------------
mas.Add (obj(1000000217))
ReDim mi(2)
mi(0) = 1000000015
mi(1) = 1
mi(2) = 1000000014

sql = "('1000000015' = """ + Dat1Val.Value + """)"

str2 = objsrv.GetEntryForSCADA("10.8.39.78", ThisDisplay.TextBox1, ThisDisplay.TextBox2, 1111, "CTM:Support Group", sql, mi, 0, 1)
obj(1000000079) = str2(0, 2, 1) '"SGP000000005017" 'Assigned Group ID
mas.Add (obj(1000000079))
selGroup = str2(0, 2, 1)
'----------------------------------------------------
'----------------------------------------
'----------------------------------------------------

obj(1000000218) = ThisDisplay.ComboBox1.Text  ''Assignee--------------------------------------------------------------
mas.Add (obj(1000000218))
obj(1000000251) = "ЗАО Company" 'Assigned Support Company------------------------------?
mas.Add (obj(1000000251))
obj(1000000014) = str2(0, 1, 1) '"Департамент по эксплуатации" 'Assigned Support Organization--------------------------?
mas.Add (obj(1000000014))
obj(1000000560) = DateAdd("h", -4, Now)

selGroup = str2(0, 0, 1)

Dim BMCServer As BMC_ARSystem.Server
Set BMCServer = New BMC_ARSystem.Server
Call BMCServer.Login_3("10.8.39.78", ThisDisplay.TextBox1, ThisDisplay.TextBox2, "", 1111)

Dim str
Dim FormName
FormName = "HPD:IncidentInterface_Create" '"HPD:Help Desk" ' "SRM:Request"
str = BMCServer.CreateEntry(FormName, obj)

Set Reg1 = ThisDisplay.GetDynamicObjectFromName("Acked")
Set Reg1Val = Reg1.GetDataSourcePointObject
Acked = Reg1Val.Value

Dim sad As String
If (Acked) Then

Set Dat3 = ThisDisplay.GetDynamicObjectFromName("AWX")
AWXViewer = Dat3.dataSource
Set parentDisplay = ThisDisplay.GetParentDisplay
Dim awxobj As GwxOleObject
Set awxobj = parentDisplay.GetVisibleObjectFromName(AWXViewer)
Set awx = awxobj.GetOLEObject()
Call awx.AckSelectedRows("ID инцидента: " + str + " " + ThisDisplay.TextBox5.Text + " BMC Login: " + ThisDisplay.TextBox1.Text)
End If
Call InsertInToDB(str, ThisDisplay.FoundOwnerName1, ThisDisplay.FoundOwnerSurname1, ThisDisplay.FullName, 1, ThisDisplay.FoundService)
res = MsgBox("Инцидент успешно создан! ID инцидента: " + str + "   Закрыть окно создания инцидента?", vbYesNoCancel)
If (res = 6) Then
ThisDisplay.HideWindow
'MsgBox res + "ок"
End If
End If
End Sub


Public Function GetEntryStatus(str)

Dim d As ClassLibrary1.MyClass
Set d = New ClassLibrary1.MyClass

Dim mi() As Long

ReDim mi(3)
mi(0) = 1
mi(1) = 301287500
mi(2) = 1000000151
mi(3) = 302830300


Dim sql
sql = "('301287500' = """ + str + """)" 'ThisDisplay.TextBox6.Value + " " + ThisDisplay.TextBox8.Value + """)" ' OR ('1000001021' = ""PPL000000044027"")"
Dim str
Dim obj As Object
Set obj = d

str = obj.GetEntryForSCADA("10.8.39.78", ThisDisplay.TextBox1, ThisDisplay.TextBox2, 1111, "SRM:Request", sql, mi, 0, 50)

EntryCount = UBound(str, 1)
FieldsCount = UBound(str, 2)
LastCount = UBound(str, 3)

If (EntryCount = 2 And FieldsCount = 2 And LastCount = 2) Then
MsgBox "Похожих инцидентов не найдено"
GoTo Label
End If

Dim FinalTable() As String
ReDim FinalTable(EntryCount, FieldsCount)

For i = 0 To EntryCount
    For J = 0 To FieldsCount
        FinalTable(i, J) = str(i, J, 1)
    Next
Next

ThisDisplay.ListBox1.ColumnHeads = False
ThisDisplay.ListBox1.ColumnWidths = "300;200;50"

    With ThisDisplay.ListBox1
        .Clear
        .ColumnCount = FieldsCount
        .List = FinalTable

    End With

Label:

End Function


Public Function GetNameField()
Dim rs1 As ADODB.Recordset

conSTR = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ING_INFO;Data Source=SCADAREPORT\SQLEXPRESS"
sql1 = "SELECT [ING_FIO], [BMC_GROUP] FROM [ING_INFO].[dbo].[Terminator] WHERE [OBJECT] = '" + ThisDisplay.TextBox6.Value + "'"

Set conn = New ADODB.Connection

conn.CursorLocation = adUseClient
conn.ConnectionString = conSTR

conn.Open
conn.CommandTimeout = 0

Set rs1 = conn.Execute(sql1)

Dim Count As Integer
Count = rs1.RecordCount

 ReDim strArray(Count, 1) As Variant
'MsgBox Count

Dim i
i = 0
If (rs1.RecordCount <> 0) Then
   Do While Not rs1.EOF
      'ThisDisplay.ListBox1
      'mylistbox.Items.Add (rs1.Fields(0).Value)
      
      strArray(i, 0) = rs1.Fields(0).Value
      strArray(i, 1) = rs1.Fields(1).Value
      i = i + 1
      rs1.MoveNext
   Loop
    Dim Region As String
    Dim Fio As String
    Dim FirstName As String
    Dim LastName As String
    
        Region = strArray(0, 1)

    Fio = strArray(0, 0)
    If (Fio <> "") Then
    FirstName = left(Fio, InStr(1, Fio, " ") - 1)
    ThisDisplay.FoundOwnerName1 = FirstName
    tes = Right(Fio, Len(Fio) - InStr(1, Fio, " "))
    LastName = left(Right(Fio, Len(Fio) - InStr(1, Fio, " ")), InStr(1, Right(Fio, Len(Fio) - InStr(1, Fio, " ") - 1), " "))
    ThisDisplay.FoundOwnerSurname1 = LastName
    End If
End If

ReDim strArray(3, 1) As Variant

strArray(0, 0) = Region
strArray(1, 0) = FirstName
strArray(2, 0) = LastName

'Dim strArray(2, 1) As Variant


'    With ThisDisplay.ListBox1
'        .Clear
'        .ColumnCount = 2
'        .List = strArray
'    End With

rs1.Close
conn.Close

'ThisDisplay.name1 = "123"



GetNameField = strArray

End Function


Public Sub GetNamesFromRG()
Dim flag As Boolean
flag = True
On Error GoTo Error1
Dim FieldValues As BMC_ARSystem.FieldValueList
Set FieldValues = New BMC_ARSystem.FieldValueList
Dim obj
Set obj = FieldValues
Set Dat1 = ThisDisplay.GetDynamicObjectFromName("GroupCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject

If (Dat1Val.Value <> Group) Then
Dim d As ClassLibrary1.MyClass
Set d = New ClassLibrary1.MyClass
Dim mi() As Long
ReDim mi(1)
mi(0) = 400129200
mi(1) = 200000020


Dim sql
sql = "('200000020' = """ + Dat1Val.Value + """)"
Dim str2
Dim objsrv As Object
Set objsrv = d
str2 = objsrv.GetEntryForSCADA("10.8.39.78", ThisDisplay.TextBox1, ThisDisplay.TextBox2, 1111, "AST:BusinessService", sql, mi, 0, 1)

obj(303519300) = str2(0, 0, 1)
'----------------------------------------
Set Dat1 = ThisDisplay.GetDynamicObjectFromName("GroupCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
ReDim mi(1)
mi(0) = 1000000015
mi(1) = 1

sql = "('1000000015' = """ + Dat1Val.Value + """)"

str2 = objsrv.GetEntryForSCADA("10.8.39.78", ThisDisplay.TextBox1, ThisDisplay.TextBox2, 1111, "CTM:Support Group", sql, mi, 0, 1)
selGroup = str2(0, 1, 1)
ThisDisplay.FoundGroupID = selGroup
'----------------------------------------------------
'----------------------------------------
ReDim mi(3)
mi(0) = 1000000079
mi(1) = 1000000017
mi(2) = 1000000080
mi(3) = 1

fd = Dat1Val.Value
sql = "('1000000079' = """ + selGroup + """)"

str2 = objsrv.GetEntryForSCADA("10.8.39.78", ThisDisplay.TextBox1, ThisDisplay.TextBox2, 1111, "CTM:Support Group Association", sql, mi, 0, 100)

'----------------------------------------------------
'----------------------------------------------------
obj(1000000217) = "РГ Аварии в SCADA" 'Assigned Group---------------------------------------------------
obj(1000000079) = "SGP000000005017" 'Assigned Group ID
    obj(200000003) = "Общекорпоративные сервисы" 'Product Categorization Tier 1
    obj(200000004) = "Обеспечение услугами эксплуатационной поддержки" 'Product Categorization Tier 2
    obj(200000005) = "Обеспечение услугами поддержки эксплуатации ГМ" 'Product Categorization Tier 3
obj(1000000251) = "ЗАО Тандер Головная компания" 'Assigned Support Company------------------------------?
obj(1000000014) = "Департамент по эксплуатации" 'Assigned Support Organization--------------------------?
s = UBound(str2, 1)
ThisDisplay.ComboBox1.Clear
For i = 0 To UBound(str2, 1)
  ThisDisplay.ComboBox1.AddItem str2(i, 0, 1)
Next


'selGroup = str2(0, 0, 100)

'count = ThisDisplay.ComboBox1.ListCount
'thisdisplay.
Group = Dat1Val.Value
End If
flag = False
Error1:
If (flag) Then
MsgBox "Ошибка авторизации BMC или SQL server!"
End If
End Sub


Public Function GetAlarmString(alarm)
Dim str As String
Dim Chr As String
str = Trim(alarm)
Dim flag As Boolean
flag = False

'удаление пробелов и др символов
For i = 0 To Len(str)
  Chr = Right(left(str, i), 1)
  If Chr = "(" Then
  flag = True
  End If

  If (Chr <> " " And Chr <> "0" And Chr <> "1" And Chr <> "2" And Chr <> "3" And Chr <> "4" And Chr <> "5" And Chr <> "6" And Chr <> "7" And Chr <> "8" And Chr <> "9" And flag <> True) Then
  resstr = resstr + Chr
  End If
  
  If Chr = ")" Then
  flag = False
  End If
Next

'преобразование к нижнему регистру
resstr = LCase(resstr)

GetAlarmString = resstr
End Function


'Процедура логирования параметров и ошибок
'EntyID 0: инцидент создать не удалось; в случае успешного создания инцидента - ID
'FoundOwnerName1 Назначенное лицо для инцидента, имя (из внутренней БД)
'FoundOwnerName2 Назначенное лицо для инцидента, имя (из BMC)
'FoundOwnerSurname1 Назначенное лицо для инцидента, фамилия (из внутренней БД)
'FoundOwnerSurname2 Назначенное лицо для инцидента, фамилия (из BMC)
'flgCreated 0: Инцидент не создан; 1: Инцидент создан; 2:Не удалось заполнить поля
'stMsg В БД-1 не найден шаблон, соответствующий текущему сообщению
'stObjName Во внутренней БД-2 не найдено имя объекта
'stOwner 1 — не найдено/некорректны данные владельца в БД-2, 2 — не найдена фамилия в BMC, 3 — фамилия найдена, имя не найдено в BMC.
'flgGrpNotFound Не найдена рабочая группа для текущего объекта в БД-2
Public Sub InsertInToDB(EntryID, FoundOwnerName1, FoundOwnerSurname1, FullName, flgCreated, stMsg)
Set parentDisplay = ThisDisplay.GetParentDisplay
Dim awxobj As GwxOleObject
Set awxobj = parentDisplay.GetVisibleObjectFromName("UserTextBox")
Set awx = awxobj.GetOLEObject()
Dim SCADAUser As String
Dim stObjName
Dim stOwner
Dim flgGrpNotFound
SCADAUser = awx.Users

dt = Format(ThisDisplay.TextBox7.Value, "MM-dd-yyyy hh:mm:ss")
dtNow = Format(Now, "MM-dd-yyyy hh:mm:ss")

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("VliyanieCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim Impact As String
Impact = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("Acked")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim Acked As String
Acked = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("SrochnostCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim Urgency As String
Urgency = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("TipCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim Type2 As String
Type2 = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("ServiceCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim service As String
service = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("GroupCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim Group As String
Group = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("StatusCOMBOBOX")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim Status As String
Status = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("RegionName")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim RegionName As String
RegionName = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("ObjectName")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim ObjectName As String
ObjectName = Dat1Val.Value
If (ObjectName = "") Then
stObjName = 1
Else
stObjName = 0
End If


Set Dat1 = ThisDisplay.GetDynamicObjectFromName("SystemType")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim SystemType As String
SystemType = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("CaseType")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim CaseType As String
CaseType = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("CaseName")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim CaseName As String
CaseName = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("ServedRoom")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim ServedRoom As String
ServedRoom = Dat1Val.Value

Set Dat1 = ThisDisplay.GetDynamicObjectFromName("AREA")
Set Dat1Val = Dat1.GetDataSourcePointObject
Dim AREA As String
AREA = Dat1Val.Value

Set obj = ThisDisplay.GetVisibleObjectFromName("TB5")
Set TB = obj.GetOLEObject()
Severity = TB.Text

stOwner = 0

If (ThisDisplay.FullName = "") Then
stOwner = 1
End If

If (ThisDisplay.FoundOwnerName1 = "") Then
stOwner = 2
End If

If (ThisDisplay.FullName = "" And ThisDisplay.FoundOwnerName1 = "") Then
stOwner = 3
End If

If (Group = "") Then
flgGrpNotFound = 1
Else
flgGrpNotFound = 0

End If
'Set Dat3 = ThisDisplay.GetDynamicObjectFromName("AWX")
'AWXViewer = Dat3.dataSource
'Set parentDisplay = ThisDisplay.GetParentDisplay
'Dim awxobj2 As GwxOleObject
'Set awxobj2 = parentDisplay.GetVisibleObjectFromName(AWXViewer)
'Set awx = awxobj2.GetOLEObject()
'Dim Severity As Integer
'Severity = awx.SelectedColRowInfo(awx.ColumnNametoId("Важность"))


Dim rs1 As ADODB.Recordset

conSTR = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BMC;Data Source=Designer31\SQLEXPRESS"
'sql1 = "INSERT INTO [BMC].[dbo].[Alarms] ([ObjectName],[EventTime],[Source],[Description],[FirstName],[LastName],[Severity],[Impact],[Urgency],[Type],[ServiceCI],[AssignedGroup],[Status],[Assignee],[BMCLogin],[SCADALogin],[SCADAAcknowledge],[AutoService]) VALUES ('" + ThisDisplay.TextBox6.Value + "','" + dt + "','" + ThisDisplay.TextBox8.Value + "','" + ThisDisplay.TextBox9.Value + "','" + "Диспетчер инженерных систем" + "','" + "Гм" + " '," + CStr(Severity) + "," + Impact + "000 ," + Urgency + "000," + Type2 + ",'" + service + "','" + Group + "'," + Status + ",'" + ThisDisplay.ComboBox1.Text + "','" + ThisDisplay.TextBox1.Value + "','" + SCADAUser + "'," + Acked + "," + autoService + ")     "
sql1 = "INSERT INTO [BMC].[dbo].[Alarms] ([EventTime],[TicketTime],[RegionName],[ObjectName],[SystemType],[CaseType],[CaseName],[ServedRoom],[Message],[Severity],[Area],[FoundService],[FoundServiceID],[FoundSeverity],[FoundImpact],[FoundTicketType],[FoundGroup],[FoundGroupID],[EntryID],[FoundOwnerName1],[FoundOwnerSurname1],[FullName],[SCADAUser],[SCADAAcknowledge],[ObjectNameSubscr],[flgCreated],[stMsg],[stObjName],[stOwner],[flgGrpNotFound], [BMCUser])" _
     + " VALUES ('" + dt + "','" + dtNow + "','" + RegionName + "','" + ObjectName + "','" + SystemType + "','" + CaseType + "','" + CaseName + "','" + ServedRoom + "','" + ThisDisplay.TextBox9.Value + "'," + CStr(ThisDisplay.TextBox10.Value) + ",'" + AREA + "','" + service + "','" + ThisDisplay.FoundServiceID + "','" + Urgency + "'," + Impact + ",'" + Type2 + "','" + Group + "','" + ThisDisplay.FoundGroupID + "','" + EntryID + "','" + FoundOwnerName1 + "','" + FoundOwnerSurname1 + "','" + FullName + "','" + SCADAUser + "'," + Acked + ",'" + ThisDisplay.TextBox6.Value + "'," + CStr(flgCreated) + " ," + CStr(stMsg) + " ," + CStr(stObjName) + "," + CStr(stOwner) + "," + CStr(flgGrpNotFound) + ", '" + ThisDisplay.TextBox1.Value + "')      "
sql2 = Right(sql1, 255)
sql3 = Mid(sql1, 355, 255)
Set conn = New ADODB.Connection

conn.CursorLocation = adUseClient
conn.ConnectionString = conSTR

conn.Open
conn.CommandTimeout = 0

Set rs1 = conn.Execute(sql1)
conn.Close
End Sub

Public Function FindeService(str)
Dim rs1 As ADODB.Recordset

conSTR = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ING_INFO;Data Source=scadareport\SQLEXPRESS"
sql1 = "SELECT [ServiceTypeName], [TicketTypeName] FROM [ING_INFO].[dbo].[BMC] where CHARINDEX('" + str + "', AlarmTemplate) > 0"

Set conn = New ADODB.Connection

conn.CursorLocation = adUseClient
conn.ConnectionString = conSTR

conn.Open
conn.CommandTimeout = 0

Set rs1 = conn.Execute(sql1)
Dim Count As Integer
Dim service As String
Dim TypeName As String
Count = rs1.RecordCount

 ReDim strArray(1, 2) As Variant
'MsgBox Count

Dim i
i = 0
If (rs1.RecordCount <> 0) Then
      strArray(1, 1) = rs1.Fields(0).Value
      strArray(1, 2) = rs1.Fields(1).Value
End If

conn.Close

FindeService = strArray
End Function

Categories: VBA

Leave a Comment