
- •Аннотация
- •Содержание
- •Введение
- •1. Описание предметной области
- •2. Постановка задачи
- •3. Анализ задачи
- •3.1. Обзор существующих систем
- •3.1.1. Службы поддержки (Service Desk)
- •3.1.1.1. Naumen Service Desk
- •3.1.1.2. TrackStudio Service Desk
- •3.1.2. Службы помощи (Help Desk)
- •3.1.2.1. HelpdeskAdvanced
- •3.1.2.2. AstroSoft HelpDesk
- •3.1.2.3. Heat Power Desk
- •3.1.3. Системы учета заявок
- •3.1.3.1. Регистрация заявок lan
- •3.1.3.2. Заявки ит
- •3.1.4. Вывод
- •3.2. Выбор инструментальных средств
- •3.2.1. Клиент-серверные субд
- •3.2.1.1. Microsoft sql Server
- •3.2.1.2. Interbase
- •3.2.1.3. Firebird (FirebirdSql)
- •3.2.1.4. MySql
- •3.2.2. Язык программирования и среда разработки
- •3.2.3. Вывод
- •4. Решение задачи
- •4.1. Создание модели ис
- •4.2. Проектирование базы данных
- •4.2.1. Инфологическая модель данных
- •4.2.2. Даталогическая модель данных
- •4.2.3. Физическая модель данных
- •4.2.4. Построение схемы данных
- •4.3. Разработка интерфейса
- •4.3.1. Приложение «Заявки – Пользователь»
- •4.3.1.1. Главное окно
- •4.3.1.2. Окно «Настройки»
- •4.3.2.2. Окно «Заявка»
- •Приложение 1. Диаграмма «Деятельность отдела ит по принятию и обработке заявок»
- •Приложение 2. Примеры отчетов
- •Приложение 3. Коды программ
Приложение 1. Диаграмма «Деятельность отдела ит по принятию и обработке заявок»
Рисунок П1.1. Контекстная диаграмма «Деятельность отдела ИТ по принятию и обработке заявок»
Рисунок П1.2. Диаграмма верхнего уровня «Деятельность отдела ИТ по принятию и обработке заявок»
Рисунок П1.3. Диаграмма декомпозиции «Принять заявку»
Рисунок П1.4. Диаграмма декомпозиции «Рассмотрение заявки»
Рисунок П1.5. Диаграмма декомпозиции «Управление»
Приложение 2. Примеры отчетов
Отчет о невыполненных заявках - 14.06.2012 4:04:24
Номер |
Пользователь |
Инцидент |
Текст заявки |
1 |
1831-00-325 |
Отсутствуют сетевые диски |
Нет диска G |
3 |
1831-00-478 |
Проблема с принтером |
Печатает с полосой |
5 |
1831-00-784 |
Создание нового рабочего места |
Новое место |
6 |
1831-00-045 |
Проблема с принтером |
Не печатает |
7 |
1831-00-657 |
Не открывается файл |
G:\obmen\вася.txt |
8 |
1831-00-465 |
Проблема с электронной почтой |
Много спама |
9 |
1831-00-479 |
Телефония |
Не работает телефон |
11 |
1831-00-478 |
Проблема с компьютером |
Не загружается windows |
13 |
1831-00-657 |
Перемещение техники |
Переключить принтер |
14 |
1831-00-479 |
Другое |
Не могу подписать файл |
15 |
1831-00-112 |
Проблема с электронной почтой |
Проблемная почта |
Всего заявок - 12
Всего типов инцидентов - 9
Всего пользователей - 9
Отчет о выполненных заявках - 14.06.2012 4:08:00
За период - с 07.06.2012 20:06:47 по 14.06.2012 0:00:00
Номер |
Пользователь |
Инцидент |
2 |
1831-00-112 |
Проблема с компьютером |
4 |
1831-00-953 |
Проблема с интернетом |
10 |
user |
Отсутствуют сетевые диски |
12 |
user |
Проблема с сетью |
16 |
1831-00-045 |
Отсутствуют сетевые диски |
Всего заявок - 5
Всего типов инцидентов - 4
Всего пользователей - 4
Отчет о заявках по исполнителям - 14.06.2012 4:10:57
За период - с 07.06.2012 20:06:47 по 14.06.2012 0:00:00
Кычанов В.П.
3 1831-00-478 Проблема с принтером
6 1831-00-045 Проблема с принтером
9 1831-00-479 Телефония
11 1831-00-478 Проблема с компьютером
13 1831-00-657 Перемещение техники
Миронов В.В.
1 1831-00-325 Отсутствуют сетевые диски
5 1831-00-784 Создание нового рабочего места
7 1831-00-657 Не открывается файл
14 1831-00-479 Другое
Тестовый
2 1831-00-112 Проблема с компьютером
4 1831-00-953 Проблема с интернетом
8 1831-00-465 Проблема с электронной почтой
10 user Отсутствуют сетевые диски
12 user Проблема с сетью
15 1831-00-112 Проблема с электронной почтой
16 1831-00-045 Отсутствуют сетевые диски
Отчет об отклоненных заявках - 14.06.2012 4:12:15
За период - с 07.06.2012 20:06:47 по 14.06.2012 0:00:00
Номер |
Пользователь |
Инцидент |
Текст заявки |
17 |
Не назначен |
Проблема с компьютером |
Не включается |
Всего заявок - 1
Всего типов инцидентов - 1
Всего пользователей - 1
Приложение 3. Коды программ
«Заявки – Пользователь»
Public Class Form1
Dim server As String
Dim StartDate As String = "19811121 00:00:00"
Dim time As String = "00:00:00"
Dim PC As String = My.Computer.Name
Dim USR As String = Split(My.User.Name, "\")(1)
Dim img_path As String = My.Computer.FileSystem.SpecialDirectories.Temp
Public srv As String = Split(GetSettings(), "%")(0)
Public it_db As String = Split(GetSettings(), "%")(1)
Public refr_time As String = Split(GetSettings(), "%")(2)
Public ticket_count As String = Split(GetSettings(), "%")(3)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MaximizeBox = False
Timer1.Interval = CInt(refr_time) * 1000
tbox_user.Text = USR
tbox_pc.Text = PC
If srv <> "1" And it_db <> "1" Then
If TestConnect(srv, "master") Then
If TestConnect(srv, it_db) Then
FillForm()
Else
MsgBox("Не найдена база данных. Обратитесь к администратору за именем базы данных", MsgBoxStyle.Information, "Информация")
Dim result As MsgBoxResult = MsgBox("Изменить базу данных?", MsgBoxStyle.OkCancel, "Информация")
If result = MsgBoxResult.Ok Then
Form2.Visible = True
Me.Enabled = False
End If
End If
Else
MsgBox("Не правильные настройки. SQL Server не найден", MsgBoxStyle.Information, "Информация")
Dim result As MsgBoxResult = MsgBox("Выполнить настройку?", MsgBoxStyle.OkCancel, "Сообщение")
If result = MsgBoxResult.Ok Then
Form2.Visible = True
Me.Enabled = False
End If
End If
Else
Dim result As MsgBoxResult = MsgBox("Программа не настроена. Настроить?", MsgBoxStyle.OkCancel, "Сообщение")
If result = MsgBoxResult.Ok Then
Form2.Visible = True
Me.Enabled = False
End If
End If
End Sub
Private Sub picbox_screen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picbox_screen.Click
GetPrintSceen()
End Sub
Private Sub button_create_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_create.Click
If srv <> "1" And it_db <> "1" Then
If TestConnect(srv, it_db) Then
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
If tbox_room.Text = "" Then
tbox_room.BackColor = Color.Red
End If
If tbox_phone.Text = "" Then
tbox_phone.BackColor = Color.Red
End If
If (cbox_priority.SelectedIndex = -1) Or (cbox_priority.Text = "") Or _
(cbox_priority.SelectedItem <> cbox_priority.Text) Then
cbox_priority.BackColor = Color.Red
End If
If (cbox_type.SelectedIndex = -1) Or (cbox_type.Text = "") Or _
(cbox_type.SelectedItem <> cbox_type.Text) Then
cbox_type.BackColor = Color.Red
End If
If tbox_ticket.Text = "" Then
tbox_ticket.BackColor = Color.Red
End If
If (tbox_room.Text <> "") And (tbox_phone.Text <> "") And (tbox_ticket.Text <> "") And _
(cbox_priority.SelectedIndex > -1) And (cbox_priority.SelectedItem = cbox_priority.Text) And _
(cbox_type.SelectedIndex > -1) And (cbox_type.SelectedItem = cbox_type.Text) Then
Dim dn As String = GetDateNowString()
Dim cmd As String = _
"INSERT INTO [ticket] " & _
"([fio],[phone],[id_incident],[id_priority]," & _
"[id_status],[id_users],[open_ticket],[close_ticket]," & _
"[work_time],[tabel],[pc_inv],[room],[deleted],[otklon]) " & _
"VALUES ('" & _
tbox_user.Text & "','" & _
tbox_phone.Text & "'," & _
CStr(cbox_type.SelectedIndex + 1) & "," & _
CStr(cbox_priority.SelectedIndex + 1) & "," & _
"1" & "," & _
"-1" & "," & _
"CONVERT(datetime,'" & dn & "',12)" & "," & _
"CONVERT(datetime,'" & StartDate & "',12)" & "," & _
"CONVERT(time,'" & time & "',12)" & "," & _
"1" & ",'" & tbox_pc.Text & "','" & tbox_room.Text & "','0','0')"
SqlCommand1.CommandText = cmd
SqlAdapter1.InsertCommand = SqlCommand1
SqlAdapter1.InsertCommand.Connection = SqlConnection1
SqlAdapter1.InsertCommand.Connection.Open()
SqlAdapter1.InsertCommand.ExecuteNonQuery()
SqlAdapter1.InsertCommand.Connection.Close()
Dim l_id As Integer = GetLastID()
FillComment(l_id, "----Пользователь----" & vbCrLf & tbox_ticket.Text.ToString, dn)
Dim attach As String = img_path & "\img_zayavka_" & CStr(l_id) & ".jpg"
Try
picbox_screen.Image.Save(attach, System.Drawing.Imaging.ImageFormat.Jpeg)
Catch ex As Exception
picbox_screen.ErrorImage.Save(attach, System.Drawing.Imaging.ImageFormat.Jpeg)
End Try
FillAttach(l_id, attach)
My.Computer.FileSystem.DeleteFile(attach)
clearText()
MsgBox("Заявка создана", MsgBoxStyle.Information, "Сообщение")
If Not CheckBox1.Checked Then
FillDataGridView(srv, it_db)
End If
End If
End If
Try
picbox_screen.Image = picbox_screen.ErrorImage
picbox_screen.Refresh()
Catch ex As Exception
End Try
Else
Dim result As MsgBoxResult = MsgBox("Программа не настроена. Настроить?", MsgBoxStyle.OkCancel, "Сообщение")
If result = MsgBoxResult.Ok Then
Form2.Visible = True
Me.Enabled = False
End If
End If
End Sub
Private Sub tbox_room_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbox_room.Click
tbox_room.BackColor = Color.White
End Sub
Private Sub cbox_priority_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbox_priority.Click
cbox_priority.BackColor = Color.White
End Sub
Private Sub tbox_phone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbox_phone.Click
tbox_phone.BackColor = Color.White
End Sub
Private Sub cbox_type_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbox_type.Click
cbox_type.BackColor = Color.White
End Sub
Private Sub tbox_ticket_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbox_ticket.Click
tbox_ticket.BackColor = Color.White
End Sub
Private Function GetDateNowString() As String
Dim sd, sm, sy, sh, sn, ss As String
Dim dn As Date = DateAndTime.Now
If DateAndTime.Hour(dn) < 10 Then
sh = "0" + DateAndTime.Hour(dn).ToString
Else
sh = DateAndTime.Hour(dn).ToString
End If
If DateAndTime.Minute(dn) < 10 Then
sn = "0" + DateAndTime.Minute(dn).ToString
Else
sn = DateAndTime.Minute(dn).ToString
End If
If DateAndTime.Second(dn) < 10 Then
ss = "0" + DateAndTime.Second(dn).ToString
Else
ss = DateAndTime.Second(dn).ToString
End If
sy = DateAndTime.Year(dn).ToString
If DateAndTime.Month(dn) < 10 Then
sm = "0" + DateAndTime.Month(dn).ToString
Else
sm = DateAndTime.Month(dn).ToString
End If
If DateAndTime.Day(dn) < 10 Then
sd = "0" + DateAndTime.Day(dn).ToString
Else
sd = DateAndTime.Day(dn).ToString
End If
GetDateNowString = sy & sm & sd & " " & sh & ":" & sn & ":" & ss
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If srv <> "1" And it_db <> "1" Then
If TestConnect(srv, it_db) Then
FillDataGridView(srv, it_db)
End If
End If
End Sub
Private Sub FillDataGridView(ByVal server As String, ByVal DBN As String)
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim con_string As String = "Data Source=" & server & ";Initial Catalog=" & DBN & ";Integrated Security=True"
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim c_row, c_col As Integer
Dim cmd As String = "SELECT TOP " & ticket_count & " [id_ticket]" & _
",[id_status]" & _
",[id_users]" & _
",[open_ticket]" & _
",[close_ticket]" & _
",[id_incident]" & _
"FROM [ticket] where fio like '" & USR & "' and PC_inv like '" & _
PC & "' and deleted = 0 and otklon = 0 ORDER BY [ID_ticket] DESC"
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
Try
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
c_row = DataSet2.Tables.Item(0).Rows.Count
c_col = DataSet2.Tables.Item(0).Columns.Count
If c_row > 0 Then
DataGridView1.RowCount = c_row
DataGridView1.ColumnCount = c_col
DataGridView1.Columns.Item(0).HeaderText = "Номер заявки"
DataGridView1.Columns.Item(1).HeaderText = "Статус заявки"
DataGridView1.Columns.Item(2).HeaderText = "Исполнитель"
DataGridView1.Columns.Item(3).HeaderText = "Открыта"
DataGridView1.Columns.Item(4).HeaderText = "Закрыта"
DataGridView1.Columns.Item(5).HeaderText = "Тип инцидента"
For i = 1 To c_row
For j = 1 To c_col
If j = 2 Then
DataGridView1.Item(j - 1, i - 1).Value = GetStatus(DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1))
Else
If j = 3 Then
DataGridView1.Item(j - 1, i - 1).Value = GetAdmin(DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1))
Else
If j = 5 Then
If DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1).ToString = "21.11.1981 0:00:00" Then
DataGridView1.Item(j - 1, i - 1).Value = "Не закрыта"
Else
DataGridView1.Item(j - 1, i - 1).Value = DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1).ToString
End If
Else
If j = 6 Then
DataGridView1.Item(j - 1, i - 1).Value = GetIncident(DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1))
Else
DataGridView1.Item(j - 1, i - 1).Value = DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1).ToString
End If
End If
End If
End If
Next
Next
End If
SqlAdapter2.SelectCommand.Connection.Close()
Catch ex As Exception
End Try
End Sub
Private Sub clearText()
tbox_room.Text = ""
tbox_pc.Text = PC
tbox_pc.ReadOnly = True
tbox_user.Text = USR
tbox_user.ReadOnly = True
CheckBox1.Checked = False
tbox_phone.Text = ""
tbox_ticket.Text = ""
cbox_priority.Text = ""
cbox_type.Text = ""
End Sub
Private Function GetStatus(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [name_status]" & _
"FROM [status] where id_status = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetStatus = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetAdmin(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [admin]" & _
"FROM [admins] where id_users = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetAdmin = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetIncident(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [name_incident]" & _
"FROM [incident] where id_incident = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetIncident = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetComment(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [comments]" & _
"FROM [comments] where id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetComment = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetLastID() As Integer
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "select MAX(id_ticket) as id_ticket from ticket " & _
"where fio like '" & tbox_user.Text & "' and " & _
"pc_inv like '" & tbox_pc.Text & "'"
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetLastID = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Sub FillComment(ByVal id As Integer, ByVal comment As String, ByVal dn As String)
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
Dim cmd As String = _
"INSERT INTO [comments]" & _
"([id_ticket]" & _
",[dt_comments]" & _
",[comments])" & _
"VALUES" & _
"(" & CStr(id) & ",CONVERT(datetime,'" & dn & "'),'" & comment & "')"
tbox_ticket.Text = cmd
SqlCommand1.CommandText = cmd
SqlAdapter1.InsertCommand = SqlCommand1
SqlAdapter1.InsertCommand.Connection = SqlConnection1
SqlAdapter1.InsertCommand.Connection.Open()
SqlAdapter1.InsertCommand.ExecuteNonQuery()
SqlAdapter1.InsertCommand.Connection.Close()
End Sub
Private Sub FillAttach(ByVal id As Integer, ByVal attach As String)
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
Dim cmd As String = _
"INSERT INTO [attach] (" & _
"[id_ticket],[image]) " & _
"VALUES (" & id & ",0x0)"
SqlCommand1.CommandText = cmd
SqlAdapter1.InsertCommand = SqlCommand1
SqlAdapter1.InsertCommand.Connection = SqlConnection1
SqlAdapter1.InsertCommand.Connection.Open()
SqlAdapter1.InsertCommand.ExecuteNonQuery()
SqlAdapter1.InsertCommand.Connection.Close()
File2SqlBlob(attach, id)
End Sub
Private Sub File2SqlBlob(ByVal SourceFilePath As String, ByVal id As Integer)
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim cn As New SqlClient.SqlConnection(con_string)
Dim cmd As New SqlClient.SqlCommand("UPDATE attach SET Image=@Image WHERE id_ticket=" & CStr(id), cn)
Dim fs As New System.IO.FileStream(SourceFilePath, IO.FileMode.Open, IO.FileAccess.Read)
Dim b(fs.Length() - 1) As Byte
fs.Read(b, 0, b.Length)
fs.Close()
Dim P As New SqlClient.SqlParameter("@Image", SqlDbType.Image, b.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, b)
cmd.Parameters.Add(P)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End Sub
Private Sub SqlBlob2File(ByVal DestFilePath As String, ByVal id As Integer)
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim PictureCol As Integer = 0
Dim cn As New SqlClient.SqlConnection(con_string)
Dim cmd As New SqlClient.SqlCommand("SELECT image FROM attach WHERE id_ticket=" & CStr(id), cn)
cn.Open()
Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(PictureCol, 0, b, 0, b.Length)
dr.Close()
cn.Close()
Dim fs As New System.IO.FileStream(DestFilePath, IO.FileMode.Create, IO.FileAccess.Write)
fs.Write(b, 0, b.Length)
fs.Close()
End Sub
Private Sub GetPrintSceen()
Me.Hide()
Threading.Thread.Sleep(1000)
Dim bmpScreenShot As Bitmap
Dim gfxScreenshot As Graphics
bmpScreenShot = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Imaging.PixelFormat.Format32bppArgb)
gfxScreenshot = Graphics.FromImage(bmpScreenShot)
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
picbox_screen.Image = bmpScreenShot
Me.Show()
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Form2.Visible = True
Form2.Activate()
End Sub
Function TestConnect(ByVal server As String, ByVal DBN As String) As Boolean
Dim con_string As String = "Data Source=" & server & ";Initial Catalog=" & DBN & ";Integrated Security=True"
Dim result As String = ""
Try
Dim cn As New SqlClient.SqlConnection(con_string)
cn.Open()
cn.Close()
Catch ex As Exception
result = ex.Message
End Try
If result = "" Then
TestConnect = True
Else
TestConnect = False
End If
End Function
Sub FillForm()
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
FillDataGridView(srv, it_db)
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
SqlCommand1.CommandText = "select * from incident"
SqlAdapter1.SelectCommand = SqlCommand1
SqlAdapter1.SelectCommand.Connection = SqlConnection1
Dim c_row As Integer
Try
SqlAdapter1.SelectCommand.Connection.Open()
SqlAdapter1.Fill(DataSet1)
c_row = DataSet1.Tables.Item(0).Rows.Count
cbox_type.Items.Clear()
For i = 1 To c_row
cbox_type.Items.Add(DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(1))
Next
SqlAdapter1.SelectCommand.Connection.Close()
Catch ex As Exception
End Try
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = "select * from priority"
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
Try
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
c_row = DataSet2.Tables.Item(0).Rows.Count
cbox_priority.Items.Clear()
For i = 1 To c_row
cbox_priority.Items.Add(DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(1))
Next
SqlAdapter2.SelectCommand.Connection.Close()
Catch ex As Exception
End Try
'GetPrintSceen()
End Sub
Function GetSettings() As String
Dim s As String = "1%1%30%10"
Dim r As Object
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\settings.ini") Then
r = My.Computer.FileSystem.OpenTextFileReader(My.Application.Info.DirectoryPath & "\settings.ini")
s = r.ReadLine
r.Close()
If s = "" Then s = "1%1%30%10"
End If
GetSettings = s
End Function
Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Dim wr As Object
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\settings.ini") Then
My.Computer.FileSystem.DeleteFile(My.Application.Info.DirectoryPath & "\settings.ini")
End If
wr = My.Computer.FileSystem.OpenTextFileWriter(My.Application.Info.DirectoryPath & "\settings.ini", False)
wr.WriteLine(srv & "%" & it_db & "%" & refr_time & "%" & ticket_count)
wr.Close()
End Sub
Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
Dim cur_row As Integer = DataGridView1.CurrentRow.Index
Dim cur_id_value As Integer = DataGridView1.Item(0, cur_row).Value
Dim cur_inc_value As String = DataGridView1.Item(5, cur_row).Value
OpenTicket(cur_id_value, cur_inc_value)
End Sub
Sub OpenTicket(ByVal id As Integer, ByVal id_inc As String)
Form3.Visible = True
Form3.Activate()
Form3.l_id.Text = "Заявка №" & CStr(id)
Form3.l_incident.Text = "Тип инцидента - " & id_inc
Form3.tbox_ticket.Text = GetComment(id)
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
tbox_pc.Text = ""
tbox_pc.ReadOnly = False
tbox_user.ReadOnly = False
Else
tbox_pc.Text = PC
tbox_user.Text = USR
tbox_pc.ReadOnly = True
tbox_user.ReadOnly = True
End If
End Sub
End Class
Public Class Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If (tbox_server.Text = "") Then
tbox_server.BackColor = Color.Red
If tbox_DB.Text = "" Then tbox_DB.BackColor = Color.Red
Else
If tbox_DB.Text = "" Then
tbox_DB.BackColor = Color.Red
Else
If Form1.TestConnect(tbox_server.Text, tbox_DB.Text) Then
If tbox_refresh_t.Text = "" Then tbox_refresh_t.Text = "30"
SaveSettings(tbox_server.Text, tbox_DB.Text, tbox_refresh_t.Text, tbox_count_tick.Text)
Me.Close()
Form1.FillForm()
Else
Dim result As MsgBoxResult = MsgBox("Не правильные настройки! Повторить?", MsgBoxStyle.OkCancel, "Информация")
If result = MsgBoxResult.Ok Then
tbox_server.BackColor = Color.Red
tbox_DB.BackColor = Color.Red
End If
End If
End If
End If
End Sub
Private Sub Form2_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form1.Enabled = True
End Sub
Private Sub SaveSettings(ByVal server As String, ByVal DBN As String, ByVal refr_tm As String, ByVal c_tick As String)
Form1.srv = server
Form1.it_db = DBN
Form1.refr_time = refr_tm
Form1.ticket_count = c_tick
End Sub
Private Sub tbox_server_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbox_server.Click
tbox_server.BackColor = Color.White
End Sub
Private Sub tbox_DB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbox_DB.Click
tbox_DB.BackColor = Color.White
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tbox_server.Text = Form1.srv
tbox_DB.Text = Form1.it_db
tbox_refresh_t.Text = Form1.refr_time
tbox_count_tick.Text = Form1.ticket_count
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Form1.TestConnect(tbox_server.Text, tbox_DB.Text) Then
MsgBox("Соединение успешно установлено", MsgBoxStyle.Information, "Сообщение")
Else
MsgBox("Неправильные настройки", MsgBoxStyle.Information, "Сообщение")
End If
End Sub
End Class
Public Class Form3
Private Sub Form3_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form1.Enabled = True
End Sub
End Class
«Заявки – Оператор»
Public Class Form1
Dim server As String
Dim StartDate As String = "19811121 00:00:00"
Dim PC As String = My.Computer.Name
Dim USR As String = Split(My.User.Name, "\")(1)
Dim img_path As String = My.Computer.FileSystem.SpecialDirectories.Temp
Public tmp1 As String
Public srv As String = Split(GetSettings(), "%")(0)
Public it_db As String = Split(GetSettings(), "%")(1)
Public refr_time As String = Split(GetSettings(), "%")(2)
Public ticket_count As String = Split(GetSettings(), "%")(3)
Dim c1, c2 As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.ForeColor = Me.BackColor
Me.MaximizeBox = False
Timer1.Interval = CInt(refr_time) * 1000
If srv <> "1" And it_db <> "1" Then
If TestConnect(srv, "master") Then
If TestConnect(srv, it_db) Then
FillForm()
c1 = DataGridView1.RowCount
c2 = DataGridView2.RowCount
Else
MsgBox("Не найдена база данных. Обратитесь к администратору за именем базы данных", MsgBoxStyle.Information, "Информация")
Dim result As MsgBoxResult = MsgBox("Изменить базу данных?", MsgBoxStyle.OkCancel, "Информация")
If result = MsgBoxResult.Ok Then
Form2.Visible = True
Me.Enabled = False
End If
End If
Else
MsgBox("Не правильные настройки. SQL Server не найден", MsgBoxStyle.Information, "Информация")
Dim result As MsgBoxResult = MsgBox("Выполнить настройку?", MsgBoxStyle.OkCancel, "Сообщение")
If result = MsgBoxResult.Ok Then
Form2.Visible = True
Me.Enabled = False
End If
End If
Else
Dim result As MsgBoxResult = MsgBox("Программа не настроена. Настроить?", MsgBoxStyle.OkCancel, "Сообщение")
If result = MsgBoxResult.Ok Then
Form2.Visible = True
Form2.Activate()
Me.Enabled = False
End If
End If
End Sub
Sub FillForm()
FillDataGridView(srv, it_db, DataGridView1, "1")
TabControl1.TabPages.Item(0).Text = "Поступившие (" & CStr(DataGridView1.RowCount) & ")"
FillDataGridView(srv, it_db, DataGridView2, "5")
TabControl1.TabPages.Item(1).Text = "Закрытые (" & CStr(DataGridView2.RowCount) & ")"
End Sub
Function GetSettings() As String
Dim s As String = "1%1%30%10"
Dim r As Object
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\settings.ini") Then
r = My.Computer.FileSystem.OpenTextFileReader(My.Application.Info.DirectoryPath & "\settings.ini")
s = r.ReadLine
r.Close()
If s = "" Then s = "1%1%30%10"
End If
GetSettings = s
End Function
Function TestConnect(ByVal server As String, ByVal DBN As String) As Boolean
Dim con_string As String = "Data Source=" & server & ";Initial Catalog=" & DBN & ";Integrated Security=True"
Dim result As String = ""
Try
Dim cn As New SqlClient.SqlConnection(con_string)
cn.Open()
cn.Close()
Catch ex As Exception
result = ex.Message
End Try
If result = "" Then
TestConnect = True
Else
TestConnect = False
End If
End Function
Private Sub SqlBlob2File(ByVal DestFilePath As String, ByVal id As Integer)
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim PictureCol As Integer = 0
Dim cn As New SqlClient.SqlConnection(con_string)
Dim cmd As New SqlClient.SqlCommand("SELECT image FROM attach WHERE id_ticket=" & CStr(id), cn)
cn.Open()
Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(PictureCol, 0, b, 0, b.Length)
dr.Close()
cn.Close()
Dim fs As New System.IO.FileStream(DestFilePath, IO.FileMode.Create, IO.FileAccess.Write)
fs.Write(b, 0, b.Length)
fs.Close()
End Sub
Private Function GetComment(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [comments]" & _
"FROM [comments] where id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetComment = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetIncident(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [name_incident]" & _
"FROM [incident] where id_incident = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetIncident = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetStatus(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [name_status]" & _
"FROM [status] where id_status = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetStatus = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetUsersID(ByVal admin As String) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [id_users]" & _
"FROM [admins] where [admin] like '" & CStr(admin) & "'"
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetUsersID = CStr(DataSet2.Tables.Item(0).Rows.Item(0).Item(0))
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Sub FillDataGridView(ByVal server As String, ByVal DBN As String, ByRef DGV As DataGridView, ByVal status As String)
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim con_string As String = "Data Source=" & server & ";Initial Catalog=" & DBN & ";Integrated Security=True"
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim c_row, c_col As Integer
Dim cmd As String = "SELECT [id_ticket]" & _
",[fio]" & _
",[phone]" & _
",[pc_inv]" & _
",[room]" & _
",[open_ticket]" & _
",[id_incident]" & _
"FROM [ticket] WHERE [deleted] = 0 and [otklon] = 0 and [id_status] = " & status
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Close()
Try
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
c_row = DataSet2.Tables.Item(0).Rows.Count
c_col = DataSet2.Tables.Item(0).Columns.Count
If c_row > 0 Then
DGV.RowCount = c_row
DGV.ColumnCount = c_col
DGV.Columns.Item(0).HeaderText = "Номер заявки"
DGV.Columns.Item(1).HeaderText = "ФИО"
DGV.Columns.Item(2).HeaderText = "Телефон"
DGV.Columns.Item(3).HeaderText = "Имя компьютера"
DGV.Columns.Item(4).HeaderText = "Кабинет"
DGV.Columns.Item(5).HeaderText = "Открыта"
DGV.Columns.Item(6).HeaderText = "Тип инцидента"
For i = 1 To c_row
For j = 1 To c_col
If j = 7 Then
DGV.Item(j - 1, i - 1).Value = GetIncident(DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1))
Else
If j = 0 Then DGV.Item(j - 1, i - 1).Value = DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1)
DGV.Item(j - 1, i - 1).Value = DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1).ToString
End If
Next
Next
End If
Catch ex As Exception
End Try
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim m1, m2 As String
Dim rc1, rc2 As Integer
FillForm()
rc1 = DataGridView1.RowCount
rc2 = DataGridView2.RowCount
If c1 < rc1 Or c2 < rc2 Then
If c1 < rc1 Then
m1 = vbTab & "Поступившие - " & CStr(rc1 - c1) & "(" & rc1 & ")" & vbCrLf
c1 = rc1
Else
m1 = ""
End If
If c2 < rc2 Then
m2 = vbTab & "Закрытые - " & CStr(rc2 - c2) & "(" & rc2 & ")"
c2 = rc2
Else
m2 = ""
End If
If Me.WindowState = FormWindowState.Minimized Then
Me.Show()
Me.WindowState = FormWindowState.Normal
End If
NotifyIcon1.ShowBalloonTip(5000, "ticket_operator", "ЗАЯВКИ:" & vbTab & vbTab & vbCrLf & _
m1 & m2, ToolTipIcon.Info)
End If
End Sub
Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick, DataGridView2.CellDoubleClick
Dim cur_row As Integer = sender.CurrentRow.Index
Dim cur_id_value As Integer = sender.Item(0, cur_row).Value
Dim cur_inc_value As String = sender.Item(6, cur_row).Value
Label1.Text = CStr(cur_id_value)
Form3.L_user.Text = "Пользователь - " & sender.Item(1, cur_row).Value & _
" Тел. " & sender.Item(2, cur_row).Value & _
" Каб. " & sender.Item(4, cur_row).Value
OpenTicket(cur_id_value, cur_inc_value)
tmp1 = img_path & "\image_z_" & CStr(cur_id_value) & ".jpg"
SqlBlob2File(tmp1, cur_id_value)
Form3.PictureBox1.ImageLocation = tmp1
Form3.PictureBox1.Load()
End Sub
Sub OpenTicket(ByVal id As Integer, ByVal id_inc As String)
Form3.Visible = True
Form3.Activate()
Form3.l_id.Text = "Заявка №" & CStr(id)
Form3.l_incident.Text = "Тип инцидента - " & id_inc
Form3.tbox_ticket.Text = GetComment(id)
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Form2.Visible = True
Form2.Activate()
End Sub
Private Sub Form1_LocationChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LocationChanged
If Me.WindowState = FormWindowState.Minimized Then
Me.Hide()
End If
End Sub
Private Sub NotifyIcon1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.Show()
Me.WindowState = FormWindowState.Normal
End Sub
Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
NotifyIcon1.Dispose()
End Sub
End Class
Public Class Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If (tbox_server.Text = "") Then
tbox_server.BackColor = Color.Red
If tbox_DB.Text = "" Then tbox_DB.BackColor = Color.Red
Else
If tbox_DB.Text = "" Then
tbox_DB.BackColor = Color.Red
Else
If Form1.TestConnect(tbox_server.Text, tbox_DB.Text) Then
If tbox_refresh_t.Text = "" Then tbox_refresh_t.Text = "30"
SaveSettings(tbox_server.Text, tbox_DB.Text, tbox_refresh_t.Text, tbox_count_tick.Text)
Me.Close()
Form1.FillForm()
Else
Dim result As MsgBoxResult = MsgBox("Не правильные настройки! Повторить?", MsgBoxStyle.OkCancel, "Информация")
If result = MsgBoxResult.Ok Then
tbox_server.BackColor = Color.Red
tbox_DB.BackColor = Color.Red
End If
End If
End If
End If
End Sub
Private Sub Form2_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form1.Enabled = True
End Sub
Private Sub SaveSettings(ByVal server As String, ByVal DBN As String, ByVal refr_tm As String, ByVal c_tick As String)
Form1.srv = server
Form1.it_db = DBN
Form1.refr_time = refr_tm
Form1.ticket_count = c_tick
End Sub
Private Sub tbox_server_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbox_server.Click
tbox_server.BackColor = Color.White
End Sub
Private Sub tbox_DB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbox_DB.Click
tbox_DB.BackColor = Color.White
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tbox_server.Text = Form1.srv
tbox_DB.Text = Form1.it_db
tbox_refresh_t.Text = Form1.refr_time
tbox_count_tick.Text = Form1.ticket_count
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Form1.TestConnect(tbox_server.Text, tbox_DB.Text) Then
MsgBox("Соединение успешно установлено", MsgBoxStyle.Information, "Сообщение")
Else
MsgBox("Неправильные настройки", MsgBoxStyle.Information, "Сообщение")
End If
End Sub
End Class
Public Class Form3
Dim USR As String = Split(My.User.Name, "\")(1)
Dim cur_id As Integer
Private Sub Form3_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form1.Enabled = True
PictureBox1.Image.Dispose()
My.Computer.FileSystem.DeleteFile(Form1.tmp1)
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Form4.PictureBox1.ImageLocation = Form1.tmp1
Form4.PictureBox1.Load()
Form4.Visible = True
Form4.Activate()
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Form4.PictureBox1.ImageLocation = Form1.tmp1
Form4.PictureBox1.Load()
Form4.Visible = True
Form4.Activate()
End Sub
Private Function GetComment(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [comments]" & _
"FROM [comments] where id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetComment = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim selected_isp As Integer = cbox_ispoln.SelectedIndex
If selected_isp > -1 Then
cur_id = CInt(Form1.Label1.Text)
UpdateIspoln(cur_id, selected_isp)
UpdateStatus(cur_id, 2) 'назначено
UpdatePriority(cur_id, cbox_priority.SelectedIndex + 1)
MsgBox("Заявка назначена", MsgBoxStyle.Information, "Сообщение")
Form1.FillForm()
Else
MsgBox("Заявка не назначена. Не выбран исполнитель", MsgBoxStyle.Information, "Сообщение")
End If
Form1.FillDataGridView(Form1.srv, Form1.it_db, Form1.DataGridView1, "1")
Form1.FillDataGridView(Form1.srv, Form1.it_db, Form1.DataGridView2, "5")
Me.Close()
End Sub
Private Sub UpdateIspoln(ByVal id As Integer, ByVal ispoln As Integer)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "UPDATE ticket" & vbCrLf & _
"set id_users = " & CStr(ispoln) & vbCrLf & _
"WHERE id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
SqlAdapter2.SelectCommand.Connection.Close()
End Sub
Private Sub UpdateStatus(ByVal id As Integer, ByVal status As Integer)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "UPDATE ticket" & vbCrLf & _
"set id_status = " & CStr(status) & vbCrLf & _
"WHERE id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
SqlAdapter2.SelectCommand.Connection.Close()
End Sub
Private Sub UpdateDT(ByVal id As Integer, ByVal DT As String)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "UPDATE ticket" & vbCrLf & _
"set close_ticket = convert(datetime,'" & DT & "')" & vbCrLf & _
"WHERE id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
SqlAdapter2.SelectCommand.Connection.Close()
End Sub
Private Function GetDateNowString() As String
Dim sd, sm, sy, sh, sn, ss As String
Dim dn As Date = DateAndTime.Now
If DateAndTime.Hour(dn) < 10 Then
sh = "0" + DateAndTime.Hour(dn).ToString
Else
sh = DateAndTime.Hour(dn).ToString
End If
If DateAndTime.Minute(dn) < 10 Then
sn = "0" + DateAndTime.Minute(dn).ToString
Else
sn = DateAndTime.Minute(dn).ToString
End If
If DateAndTime.Second(dn) < 10 Then
ss = "0" + DateAndTime.Second(dn).ToString
Else
ss = DateAndTime.Second(dn).ToString
End If
sy = DateAndTime.Year(dn).ToString
If DateAndTime.Month(dn) < 10 Then
sm = "0" + DateAndTime.Month(dn).ToString
Else
sm = DateAndTime.Month(dn).ToString
End If
If DateAndTime.Day(dn) < 10 Then
sd = "0" + DateAndTime.Day(dn).ToString
Else
sd = DateAndTime.Day(dn).ToString
End If
GetDateNowString = sy & sm & sd & " " & sh & ":" & sn & ":" & ss
End Function
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form3_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
SqlCommand1.CommandText = "select * from admins"
SqlAdapter1.SelectCommand = SqlCommand1
SqlAdapter1.SelectCommand.Connection = SqlConnection1
SqlAdapter1.SelectCommand.Connection.Open()
SqlAdapter1.Fill(DataSet1)
Dim c_row As Integer = DataSet1.Tables.Item(0).Rows.Count
cbox_ispoln.Items.Clear()
For i = 2 To c_row
cbox_ispoln.Items.Add(DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(1))
Next
SqlAdapter1.SelectCommand.Connection.Close()
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = "select name_priority from priority"
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
c_row = DataSet2.Tables.Item(0).Rows.Count
cbox_priority.Items.Clear()
For i = 1 To c_row
cbox_priority.Items.Add(DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(0))
Next
SqlAdapter2.SelectCommand.Connection.Close()
Dim SqlAdapter3 As New SqlClient.SqlDataAdapter
Dim DataSet3 As New DataSet
Dim SqlConnection3 As New SqlClient.SqlConnection
SqlConnection3.ConnectionString = con_string
Dim SqlCommand3 As New SqlClient.SqlCommand
SqlCommand3.CommandText = "SELECT [id_priority]" & vbCrLf & _
"FROM [ticket] where id_ticket = " & Form1.Label1.Text
SqlAdapter3.SelectCommand = SqlCommand3
SqlAdapter3.SelectCommand.Connection = SqlConnection3
SqlAdapter3.SelectCommand.Connection.Open()
SqlAdapter3.Fill(DataSet3)
Dim npriority As String = DataSet3.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter3.SelectCommand.Connection.Close()
cbox_priority.SelectedIndex = npriority - 1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim selected_pri As Integer = cbox_priority.SelectedIndex
If selected_pri > -1 Then
cur_id = CInt(Form1.Label1.Text)
UpdatePriority(cur_id, selected_pri + 1)
MsgBox("Приоритет изменен", MsgBoxStyle.Information, "Сообщение")
Else
MsgBox("Приоритет не изменен. Не выбран приоритет", MsgBoxStyle.Information, "Сообщение")
End If
End Sub
Private Sub UpdatePriority(ByVal id As Integer, ByVal priority As Integer)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "UPDATE ticket" & vbCrLf & _
"set id_priority = " & CStr(priority) & vbCrLf & _
"WHERE id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
SqlAdapter2.SelectCommand.Connection.Close()
End Sub
Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
SetOtklon(CInt(Form1.Label1.Text))
MsgBox("Заявка отклонена", MsgBoxStyle.Information, "Сообщение")
End Sub
Private Sub SetOtklon(ByVal id As Integer)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "UPDATE ticket" & vbCrLf & _
"set otklon = 1 " & vbCrLf & _
"WHERE id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
SqlAdapter2.SelectCommand.Connection.Close()
Me.Close()
Form1.FillForm()
End Sub
End Class
Public Class Form4
Private Sub Form4_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form3.Enabled = True
PictureBox1.Image.Dispose()
End Sub
End Class
«Заявки – Исполнитель»
Public Class Form1
Dim server As String
Dim StartDate As String = "19811121 00:00:00"
Dim PC As String = My.Computer.Name
Dim USR As String = Split(My.User.Name, "\")(1)
Dim img_path As String = My.Computer.FileSystem.SpecialDirectories.Temp
Public tmp1 As String
Public srv As String = Split(GetSettings(), "%")(0)
Public it_db As String = Split(GetSettings(), "%")(1)
Public refr_time As String = Split(GetSettings(), "%")(2)
Public ticket_count As String = Split(GetSettings(), "%")(3)
Dim c1, c2, c3 As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.MaximizeBox = False
Timer1.Interval = CInt(refr_time) * 1000
If srv <> "1" And it_db <> "1" Then
If TestConnect(srv, "master") Then
If TestConnect(srv, it_db) Then
FillForm()
c1 = DataGridView1.RowCount
c2 = DataGridView2.RowCount
c3 = DataGridView3.RowCount
Else
MsgBox("Не найдена база данных. Обратитесь к администратору за именем базы данных", MsgBoxStyle.Information, "Информация")
Dim result As MsgBoxResult = MsgBox("Изменить базу данных?", MsgBoxStyle.OkCancel, "Информация")
If result = MsgBoxResult.Ok Then
Form2.Visible = True
Me.Enabled = False
End If
End If
Else
MsgBox("Не правильные настройки. SQL Server не найден", MsgBoxStyle.Information, "Информация")
Dim result As MsgBoxResult = MsgBox("Выполнить настройку?", MsgBoxStyle.OkCancel, "Сообщение")
If result = MsgBoxResult.Ok Then
Form2.Visible = True
Me.Enabled = False
End If
End If
Else
Dim result As MsgBoxResult = MsgBox("Программа не настроена. Настроить?", MsgBoxStyle.OkCancel, "Сообщение")
If result = MsgBoxResult.Ok Then
Form2.Visible = True
Me.Enabled = False
End If
End If
End Sub
Sub FillForm()
Dim n1, n2, n3 As Integer
FillDataGridView(srv, it_db, DataGridView1, "3")
n1 = DataGridView1.RowCount
TabControl1.TabPages.Item(0).Text = "Высокий (" & CStr(n1) & ")"
Try
If CStr(DataGridView1.Item(0, 0).Value) = "" Then
TabControl1.TabPages.Item(0).Text = "Высокий (0)"
End If
Catch ex As Exception
End Try
FillDataGridView(srv, it_db, DataGridView2, "2")
n2 = DataGridView2.RowCount
TabControl1.TabPages.Item(1).Text = "Нормальный (" & CStr(n2) & ")"
Try
If CStr(DataGridView2.Item(0, 0).Value) = "" Then
TabControl1.TabPages.Item(1).Text = "Нормальный (0)"
End If
Catch ex As Exception
End Try
FillDataGridView(srv, it_db, DataGridView3, "1")
n3 = DataGridView3.RowCount
TabControl1.TabPages.Item(2).Text = "Низкий (" & CStr(n3) & ")"
Try
If CStr(DataGridView3.Item(0, 0).Value) = "" Then
TabControl1.TabPages.Item(2).Text = "Низкий (0)"
End If
Catch ex As Exception
End Try
End Sub
Function GetSettings() As String
Dim s As String = "1%1%30%10"
Dim r As Object
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\settings.ini") Then
r = My.Computer.FileSystem.OpenTextFileReader(My.Application.Info.DirectoryPath & "\settings.ini")
s = r.ReadLine
r.Close()
If s = "" Then s = "1%1%30%10"
End If
GetSettings = s
End Function
Function TestConnect(ByVal server As String, ByVal DBN As String) As Boolean
Dim con_string As String = "Data Source=" & server & ";Initial Catalog=" & DBN & ";Integrated Security=True"
Dim result As String = ""
Try
Dim cn As New SqlClient.SqlConnection(con_string)
cn.Open()
cn.Close()
Catch ex As Exception
result = ex.Message
End Try
If result = "" Then
TestConnect = True
Else
TestConnect = False
End If
End Function
Private Sub SqlBlob2File(ByVal DestFilePath As String, ByVal id As Integer)
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim PictureCol As Integer = 0
Dim cn As New SqlClient.SqlConnection(con_string)
Dim cmd As New SqlClient.SqlCommand("SELECT image FROM attach WHERE id_ticket=" & CStr(id), cn)
cn.Open()
Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(PictureCol, 0, b, 0, b.Length)
dr.Close()
cn.Close()
Dim fs As New System.IO.FileStream(DestFilePath, IO.FileMode.Create, IO.FileAccess.Write)
fs.Write(b, 0, b.Length)
fs.Close()
End Sub
Private Function GetComment(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [comments]" & _
"FROM [comments] where id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetComment = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetIncident(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [name_incident]" & _
"FROM [incident] where id_incident = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetIncident = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetStatus(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [name_status]" & _
"FROM [status] where id_status = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetStatus = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetUsersID(ByVal admin As String) As String
Dim con_string As String = "Data Source=" & srv & ";Initial Catalog=" & it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [id_users]" & _
"FROM [admins] where [login] like '" & CStr(admin) & "'"
Try
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetUsersID = CStr(DataSet2.Tables.Item(0).Rows.Item(0).Item(0))
SqlAdapter2.SelectCommand.Connection.Close()
Catch ex As Exception
End Try
End Function
Private Sub FillDataGridView(ByVal server As String, ByVal DBN As String, ByRef DGV As DataGridView, ByVal priority As String)
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim con_string As String = "Data Source=" & server & ";Initial Catalog=" & DBN & ";Integrated Security=True"
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim c_row, c_col As Integer
Dim cmd As String = "SELECT [id_ticket]" & _
",[fio]" & _
",[phone]" & _
",[pc_inv]" & _
",[room]" & _
",[open_ticket]" & _
",[id_incident]" & _
"FROM [ticket] WHERE [id_users] = " & GetUsersID(USR) & " and [deleted] = 0 and [otklon] = 0 and [id_status] > 1 and [id_status] < 5 and [id_priority] = " & _
priority
Try
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
c_row = DataSet2.Tables.Item(0).Rows.Count
c_col = DataSet2.Tables.Item(0).Columns.Count
If c_row > 0 Then
DGV.RowCount = c_row
DGV.ColumnCount = c_col
DGV.Columns.Item(0).HeaderText = "Номер заявки"
DGV.Columns.Item(1).HeaderText = "ФИО"
DGV.Columns.Item(2).HeaderText = "Телефон"
DGV.Columns.Item(3).HeaderText = "Имя компьютера"
DGV.Columns.Item(4).HeaderText = "Кабинет"
DGV.Columns.Item(5).HeaderText = "Открыта"
DGV.Columns.Item(6).HeaderText = "Тип инцидента"
For i = 1 To c_row
For j = 1 To c_col
If j = 7 Then
DGV.Item(j - 1, i - 1).Value = GetIncident(DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1))
Else
If j = 0 Then DGV.Item(j - 1, i - 1).Value = DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1)
DGV.Item(j - 1, i - 1).Value = DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1).ToString
End If
Next
Next
Else
DGV.Rows.Clear()
DGV.RowCount = 0
End If
SqlAdapter2.SelectCommand.Connection.Close()
Catch ex As Exception
End Try
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim m1, m2, m3 As String
Dim rc1, rc2, rc3 As Integer
FillForm()
rc1 = DataGridView1.RowCount
rc2 = DataGridView2.RowCount
rc3 = DataGridView3.RowCount
If c1 < rc1 Or c2 < rc2 Or c3 < rc3 Then
If c1 < rc1 Then
m1 = vbTab & "Высокий приоритет - " & CStr(rc1 - c1) & "(" & rc1 & ")" & vbCrLf
c1 = rc1
Else
m1 = ""
End If
If c2 < rc2 Then
m2 = vbTab & "Нормальный приоритет - " & CStr(rc2 - c2) & "(" & rc2 & ")" & vbCrLf
c2 = rc2
Else
m2 = ""
End If
If c3 < rc3 Then
m3 = vbTab & "Низкий приоритет - " & CStr(rc3 - c3) & "(" & rc3 & ")"
c3 = rc3
Else
m3 = ""
End If
If Me.WindowState = FormWindowState.Minimized Then
Me.Show()
Me.WindowState = FormWindowState.Normal
End If
NotifyIcon1.ShowBalloonTip(5000, "ticket_admin", "НОВЫЕ ЗАЯВКИ:" & vbTab & vbTab & vbCrLf & _
m1 & m2 & m3, ToolTipIcon.Info)
End If
End Sub
Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick, DataGridView3.CellDoubleClick, DataGridView2.CellDoubleClick
Dim cur_row As Integer = sender.CurrentRow.Index
If CStr(sender.Item(0, 0).Value) <> "" Then
If cur_row > -1 And sender.RowCount > 0 Then
Dim cur_id_value As Integer = sender.Item(0, cur_row).Value
Dim cur_inc_value As String = sender.Item(6, cur_row).Value
Form3.L_user.Text = "Пользователь - " & sender.Item(1, cur_row).Value & _
" Тел. " & sender.Item(2, cur_row).Value & _
" Каб. " & sender.Item(4, cur_row).Value
OpenTicket(cur_id_value, cur_inc_value)
tmp1 = img_path & "\image_z_" & CStr(cur_id_value) & ".jpg"
SqlBlob2File(tmp1, cur_id_value)
Form3.PictureBox1.ImageLocation = tmp1
Form3.PictureBox1.Load()
End If
End If
End Sub
Sub OpenTicket(ByVal id As Integer, ByVal id_inc As String)
Form3.Visible = True
Form3.Activate()
Form3.l_id.Text = "Заявка №" & CStr(id)
Form3.l_incident.Text = "Тип инцидента - " & id_inc
Form3.tbox_ticket.Text = GetComment(id)
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Form2.Visible = True
Form2.Activate()
End Sub
Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
NotifyIcon1.Dispose()
Dim wr As Object
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\settings.ini") Then
My.Computer.FileSystem.DeleteFile(My.Application.Info.DirectoryPath & "\settings.ini")
End If
wr = My.Computer.FileSystem.OpenTextFileWriter(My.Application.Info.DirectoryPath & "\settings.ini", False)
wr.WriteLine(srv & "%" & it_db & "%" & refr_time & "%" & ticket_count)
wr.Close()
End Sub
Private Sub NotifyIcon1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.Show()
Me.WindowState = FormWindowState.Normal
End Sub
Private Sub Form1_LocationChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LocationChanged
If Me.WindowState = FormWindowState.Minimized Then
Me.Hide()
End If
End Sub
End Class
Public Class Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If (tbox_server.Text = "") Then
tbox_server.BackColor = Color.Red
If tbox_DB.Text = "" Then tbox_DB.BackColor = Color.Red
Else
If tbox_DB.Text = "" Then
tbox_DB.BackColor = Color.Red
Else
If Form1.TestConnect(tbox_server.Text, tbox_DB.Text) Then
If tbox_refresh_t.Text = "" Then tbox_refresh_t.Text = "30"
SaveSettings(tbox_server.Text, tbox_DB.Text, tbox_refresh_t.Text, tbox_count_tick.Text)
Me.Close()
Form1.FillForm()
Else
Dim result As MsgBoxResult = MsgBox("Не правильные настройки! Повторить?", MsgBoxStyle.OkCancel, "Информация")
If result = MsgBoxResult.Ok Then
tbox_server.BackColor = Color.Red
tbox_DB.BackColor = Color.Red
End If
End If
End If
End If
End Sub
Private Sub Form2_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form1.Enabled = True
End Sub
Private Sub SaveSettings(ByVal server As String, ByVal DBN As String, ByVal refr_tm As String, ByVal c_tick As String)
Form1.srv = server
Form1.it_db = DBN
Form1.refr_time = refr_tm
Form1.ticket_count = c_tick
End Sub
Private Sub tbox_server_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbox_server.Click
tbox_server.BackColor = Color.White
End Sub
Private Sub tbox_DB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbox_DB.Click
tbox_DB.BackColor = Color.White
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tbox_server.Text = Form1.srv
tbox_DB.Text = Form1.it_db
tbox_refresh_t.Text = Form1.refr_time
tbox_count_tick.Text = Form1.ticket_count
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Form1.TestConnect(tbox_server.Text, tbox_DB.Text) Then
MsgBox("Соединение успешно установлено", MsgBoxStyle.Information, "Сообщение")
Else
MsgBox("Неправильные настройки", MsgBoxStyle.Information, "Сообщение")
End If
End Sub
End Class
Public Class Form3
Dim USR As String = Split(My.User.Name, "\")(1)
Dim cur_id As Integer
Private Sub Form3_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form1.Enabled = True
PictureBox1.Image.Dispose()
My.Computer.FileSystem.DeleteFile(Form1.tmp1)
Timer1.Enabled = False
UpdateStatus(cur_id, 4) 'отложить
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Form4.PictureBox1.ImageLocation = Form1.tmp1
Form4.PictureBox1.Load()
Form4.Visible = True
Form4.Activate()
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Form4.PictureBox1.ImageLocation = Form1.tmp1
Form4.PictureBox1.Load()
Form4.Visible = True
Form4.Activate()
End Sub
Private Function GetComment(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [comments]" & _
"FROM [comments] where id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetComment = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If tbox_otvet.Text <> "" Then
UpdateComment(cur_id)
tbox_otvet.Text = ""
End If
End Sub
Private Sub UpdateComment(ByVal id As Integer)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "UPDATE comments" & vbCrLf & _
"SET comments = '" & tbox_ticket.Text & vbCrLf & _
"----" & USR & "----" & vbCrLf & _
tbox_otvet.Text & "'" & vbCrLf & _
"WHERE (id_ticket = " & CStr(id) & ")"
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
SqlAdapter2.SelectCommand.Connection.Close()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
tbox_ticket.Text = GetComment(cur_id)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
UpdateStatus(cur_id, 4)
Me.Close()
End Sub
Private Sub UpdateStatus(ByVal id As Integer, ByVal status As Integer)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "UPDATE ticket" & vbCrLf & _
"set id_status = " & CStr(status) & vbCrLf & _
"WHERE id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
SqlAdapter2.SelectCommand.Connection.Close()
End Sub
Private Sub UpdateDT(ByVal id As Integer, ByVal DT As String)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "UPDATE ticket" & vbCrLf & _
"set close_ticket = convert(datetime,'" & DT & "')" & vbCrLf & _
"WHERE id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
SqlAdapter2.SelectCommand.Connection.Close()
End Sub
Private Sub Form3_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Timer1.Enabled = True
cur_id = CInt(Split(l_id.Text, "№")(1))
UpdateStatus(cur_id, 3)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If tbox_otvet.Text <> "" Then
UpdateComment(cur_id)
tbox_otvet.Text = ""
Else
tbox_otvet.Text = "-------"
UpdateComment(cur_id)
tbox_otvet.Text = ""
End If
Me.Close()
UpdateDT(cur_id, GetDateNowString())
UpdateStatus(cur_id, 5)
UpdateWT(cur_id)
End Sub
Private Function GetDateNowString() As String
Dim sd, sm, sy, sh, sn, ss As String
Dim dn As Date = DateAndTime.Now
If DateAndTime.Hour(dn) < 10 Then
sh = "0" + DateAndTime.Hour(dn).ToString
Else
sh = DateAndTime.Hour(dn).ToString
End If
If DateAndTime.Minute(dn) < 10 Then
sn = "0" + DateAndTime.Minute(dn).ToString
Else
sn = DateAndTime.Minute(dn).ToString
End If
If DateAndTime.Second(dn) < 10 Then
ss = "0" + DateAndTime.Second(dn).ToString
Else
ss = DateAndTime.Second(dn).ToString
End If
sy = DateAndTime.Year(dn).ToString
If DateAndTime.Month(dn) < 10 Then
sm = "0" + DateAndTime.Month(dn).ToString
Else
sm = DateAndTime.Month(dn).ToString
End If
If DateAndTime.Day(dn) < 10 Then
sd = "0" + DateAndTime.Day(dn).ToString
Else
sd = DateAndTime.Day(dn).ToString
End If
GetDateNowString = sy & sm & sd & " " & sh & ":" & sn & ":" & ss
End Function
Private Sub UpdateWT(ByVal id As Integer)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = _
"UPDATE [ticket]" & vbCrLf & _
"SET [work_time] = (select [close_ticket]-[open_ticket] from [ticket] where id_ticket = " & CStr(id) & ")" & vbCrLf & _
"where id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
SqlAdapter2.SelectCommand.Connection.Close()
End Sub
End Class
Public Class Form4
Private Sub Form4_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form3.Enabled = True
PictureBox1.Image.Dispose()
End Sub
End Class
«Заявки – Настройка»
Public Class Form1
Dim server As String
Dim StartDate As String = "19811121 00:00:00"
Dim PC As String = My.Computer.Name
Dim USR As String = Split(My.User.Name, "\")(1)
Dim img_path As String = My.Computer.FileSystem.SpecialDirectories.Temp
Public tmp1 As String
Public srv As String = Split(GetSettings(), "%")(0)
Public it_db As String = Split(GetSettings(), "%")(1)
Public refr_time As String = Split(GetSettings(), "%")(2)
Public ticket_count As String = Split(GetSettings(), "%")(3)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Visible = True
Form2.Activate()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form3.Visible = True
Form3.Activate()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Form4.Visible = True
Form4.Activate()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Form5.Visible = True
Form5.Activate()
Form5.TextBox1.Text = srv
Form5.TextBox2.Text = it_db
End Sub
Function GetSettings() As String
Dim s As String = "1%1%30%10"
Dim r As Object
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\settings.ini") Then
r = My.Computer.FileSystem.OpenTextFileReader(My.Application.Info.DirectoryPath & "\settings.ini")
s = r.ReadLine
r.Close()
If s = "" Then s = "1%1%30%10"
End If
GetSettings = s
End Function
Function TestConnect(ByVal server As String, ByVal DBN As String) As Boolean
Dim con_string As String = "Data Source=" & server & ";Initial Catalog=" & DBN & ";Integrated Security=True"
Dim result As String = ""
Try
Dim cn As New SqlClient.SqlConnection(con_string)
cn.Open()
cn.Close()
Catch ex As Exception
result = ex.Message
End Try
If result = "" Then
TestConnect = True
Else
TestConnect = False
End If
End Function
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Dim wr As Object
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\settings.ini") Then
My.Computer.FileSystem.DeleteFile(My.Application.Info.DirectoryPath & "\settings.ini")
End If
wr = My.Computer.FileSystem.OpenTextFileWriter(My.Application.Info.DirectoryPath & "\settings.ini", False)
wr.WriteLine(srv & "%" & it_db & "%" & refr_time & "%" & ticket_count)
wr.Close()
End Sub
End Class
Public Class Form2
Private Sub Form2_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form1.Visible = True
Form1.Activate()
End Sub
Private Sub Form2_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Form1.Visible = False
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FillDGVInc(Form1.srv, Form1.it_db, DataGridView1)
End Sub
Private Sub FillDGVInc(ByVal server As String, ByVal DBN As String, ByRef DGV As DataGridView)
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim con_string As String = "Data Source=" & server & ";Initial Catalog=" & DBN & ";Integrated Security=True"
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim c_row, c_col As Integer
Dim cmd As String = "SELECT [id_incident],[name_incident] FROM [incident]"
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
Try
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
c_row = DataSet2.Tables.Item(0).Rows.Count
c_col = DataSet2.Tables.Item(0).Columns.Count
If c_row > 0 Then
DGV.RowCount = c_row
DGV.ColumnCount = c_col
DGV.Columns.Item(0).HeaderText = "Номер"
DGV.Columns.Item(1).HeaderText = "Инцидент"
For i = 1 To c_row
For j = 1 To c_col
DGV.Item(j - 1, i - 1).Value = DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1).ToString
Next
Next
End If
SqlAdapter2.SelectCommand.Connection.Close()
Catch ex As Exception
MsgBox("Ошибка: " & ex.Message, MsgBoxStyle.Information, "Сообщение")
Me.Close()
End Try
End Sub
Private Sub TextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Click
TextBox1.BackColor = Color.White
TextBox1.Text = ""
TextBox1.ForeColor = Color.Black
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
TextBox1.BackColor = Color.Red
TextBox1.Text = "Введите инцидент"
TextBox1.ForeColor = Color.White
Else
AddIncident(TextBox1.Text)
FillDGVInc(Form1.srv, Form1.it_db, DataGridView1)
MsgBox("Инцидент добавлен", MsgBoxStyle.Information, "Сообщение")
TextBox1.Text = ""
End If
End Sub
Private Sub AddIncident(ByVal incident As String)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
Dim cmd As String = _
"INSERT" & vbCrLf & _
"INTO incident(name_incident)" & vbCrLf & _
"VALUES ('" & incident & "')"
SqlCommand1.CommandText = cmd
SqlAdapter1.InsertCommand = SqlCommand1
SqlAdapter1.InsertCommand.Connection = SqlConnection1
Try
SqlAdapter1.InsertCommand.Connection.Open()
SqlAdapter1.InsertCommand.ExecuteNonQuery()
SqlAdapter1.InsertCommand.Connection.Close()
Catch ex As Exception
MsgBox("Ошибка: " & ex.Message, MsgBoxStyle.Information, "Сообщение")
End Try
End Sub
End Class
Public Class Form3
Private Sub Form3_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form1.Visible = True
Form1.Activate()
End Sub
Private Sub Form3_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Form1.Visible = False
End Sub
Private Sub TextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Click
TextBox1.BackColor = Color.White
TextBox1.Text = ""
TextBox1.ForeColor = Color.Black
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
If TextBox1.Text = "" Then
TextBox1.BackColor = Color.Red
TextBox1.Text = "Введите исполнителя"
TextBox1.ForeColor = Color.White
End If
If TextBox2.Text = "" Then
TextBox2.BackColor = Color.Red
TextBox2.Text = "Введите логин"
TextBox2.ForeColor = Color.White
End If
Else
AddIspoln(TextBox1.Text, TextBox2.Text)
FillDGVIsp(Form1.srv, Form1.it_db, DataGridView1)
MsgBox("Исполнитель добавлен", MsgBoxStyle.Information, "Сообщение")
TextBox1.Text = ""
TextBox2.Text = ""
End If
End Sub
Private Sub AddIspoln(ByVal ispoln As String, ByVal isp_l As String)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
Dim cmd As String = _
"INSERT" & vbCrLf & _
"INTO admins(admin, login)" & vbCrLf & _
"VALUES ('" & ispoln & "','" & isp_l & "')"
SqlCommand1.CommandText = cmd
SqlAdapter1.InsertCommand = SqlCommand1
SqlAdapter1.InsertCommand.Connection = SqlConnection1
SqlAdapter1.InsertCommand.Connection.Open()
SqlAdapter1.InsertCommand.ExecuteNonQuery()
SqlAdapter1.InsertCommand.Connection.Close()
End Sub
Private Sub FillDGVIsp(ByVal server As String, ByVal DBN As String, ByRef DGV As DataGridView)
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim con_string As String = "Data Source=" & server & ";Initial Catalog=" & DBN & ";Integrated Security=True"
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim c_row, c_col As Integer
Dim cmd As String = "SELECT [id_users],[admin],[login] FROM [admins]"
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
Try
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
c_row = DataSet2.Tables.Item(0).Rows.Count
c_col = DataSet2.Tables.Item(0).Columns.Count
If c_row > 0 Then
DGV.RowCount = c_row
DGV.ColumnCount = c_col
DGV.Columns.Item(0).HeaderText = "Номер"
DGV.Columns.Item(1).HeaderText = "Исполнитель"
DGV.Columns.Item(2).HeaderText = "Логин"
For i = 1 To c_row
For j = 1 To c_col
DGV.Item(j - 1, i - 1).Value = DataSet2.Tables.Item(0).Rows.Item(i - 1).Item(j - 1).ToString
Next
Next
End If
SqlAdapter2.SelectCommand.Connection.Close()
Catch ex As Exception
MsgBox("Ошибка: " & ex.Message, MsgBoxStyle.Information, "Сообщение")
Me.Close()
End Try
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FillDGVIsp(Form1.srv, Form1.it_db, DataGridView1)
End Sub
Private Sub TextBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.Click
TextBox2.BackColor = Color.White
TextBox2.Text = ""
TextBox2.ForeColor = Color.Black
End Sub
End Class
Imports Microsoft.Office.Interop
Public Class Form4
Private Sub Form4_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form1.Visible = True
Form1.Activate()
End Sub
Private Sub Form4_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Form1.Visible = False
End Sub
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim d As Date = MinDate()
DateTimePicker1.Value = d
DateTimePicker1.MinDate = d
DateTimePicker2.MinDate = d
DateTimePicker1.MaxDate = Date.Today
DateTimePicker2.MaxDate = Date.Today
End Sub
Private Function MinDate() As Date
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "select open_ticket from ticket where id_ticket = (select MIN(id_ticket) from ticket)"
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
MinDate = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked Then
RadioButton1.ForeColor = Color.Black
DateTimePicker1.Enabled = False
DateTimePicker2.Enabled = False
Label1.ForeColor = Color.DarkGray
Label2.ForeColor = Color.DarkGray
Label3.ForeColor = Color.DarkGray
Dim d As Date = MinDate()
DateTimePicker1.Value = d
DateTimePicker1.MinDate = d
DateTimePicker2.MinDate = d
DateTimePicker1.MaxDate = Date.Today
DateTimePicker2.MaxDate = Date.Today
Else
RadioButton1.ForeColor = Color.DarkGray
End If
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked Then
RadioButton2.ForeColor = Color.Black
DateTimePicker1.Enabled = True
DateTimePicker2.Enabled = True
Label1.ForeColor = Color.Black
Label2.ForeColor = Color.Black
Label3.ForeColor = Color.Black
Dim d As Date = MinDate()
DateTimePicker1.Value = d
DateTimePicker1.MinDate = d
DateTimePicker2.MinDate = d
DateTimePicker1.MaxDate = Date.Today
DateTimePicker2.MaxDate = Date.Today
Else
RadioButton2.ForeColor = Color.DarkGray
End If
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
If RadioButton3.Checked Then
RadioButton3.ForeColor = Color.Black
DateTimePicker1.Enabled = True
DateTimePicker2.Enabled = True
Label1.ForeColor = Color.Black
Label2.ForeColor = Color.Black
Label3.ForeColor = Color.Black
Dim d As Date = MinDate()
DateTimePicker1.Value = d
DateTimePicker1.MinDate = d
DateTimePicker2.MinDate = d
DateTimePicker1.MaxDate = Date.Today
DateTimePicker2.MaxDate = Date.Today
Else
RadioButton3.ForeColor = Color.DarkGray
End If
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
If RadioButton4.Checked Then
RadioButton4.ForeColor = Color.Black
DateTimePicker1.Enabled = True
DateTimePicker2.Enabled = True
Label1.ForeColor = Color.Black
Label2.ForeColor = Color.Black
Label3.ForeColor = Color.Black
Dim d As Date = MinDate()
DateTimePicker1.Value = d
DateTimePicker1.MinDate = d
DateTimePicker2.MinDate = d
DateTimePicker1.MaxDate = Date.Today
DateTimePicker2.MaxDate = Date.Today
Else
RadioButton4.ForeColor = Color.DarkGray
End If
End Sub
Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
If RadioButton5.Checked Then
RadioButton5.ForeColor = Color.Black
DateTimePicker1.Enabled = True
DateTimePicker2.Enabled = True
Label1.ForeColor = Color.Black
Label2.ForeColor = Color.Black
Label3.ForeColor = Color.Black
Dim d As Date = MinDate()
DateTimePicker1.Value = d
DateTimePicker1.MinDate = d
DateTimePicker2.MinDate = d
DateTimePicker1.MaxDate = Date.Today
DateTimePicker2.MaxDate = Date.Today
Else
RadioButton5.ForeColor = Color.DarkGray
End If
End Sub
Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged
If RadioButton6.Checked Then
RadioButton6.ForeColor = Color.Black
DateTimePicker1.Enabled = True
DateTimePicker2.Enabled = True
Label1.ForeColor = Color.Black
Label2.ForeColor = Color.Black
Label3.ForeColor = Color.Black
Dim d As Date = MinDate()
DateTimePicker1.Value = d
DateTimePicker1.MinDate = d
DateTimePicker2.MinDate = d
DateTimePicker1.MaxDate = Date.Today
DateTimePicker2.MaxDate = Date.Today
Else
RadioButton6.ForeColor = Color.DarkGray
End If
End Sub
Private Sub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton7.CheckedChanged
If RadioButton7.Checked Then
RadioButton7.ForeColor = Color.Black
DateTimePicker1.Enabled = True
DateTimePicker2.Enabled = True
Label1.ForeColor = Color.Black
Label2.ForeColor = Color.Black
Label3.ForeColor = Color.Black
Dim d As Date = MinDate()
DateTimePicker1.Value = d
DateTimePicker1.MinDate = d
DateTimePicker2.MinDate = d
DateTimePicker1.MaxDate = Date.Today
DateTimePicker2.MaxDate = Date.Today
Else
RadioButton7.ForeColor = Color.DarkGray
End If
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked Then
Otchet_Nevyp()
End If
If RadioButton2.Checked Then
Otchet_Vyp()
End If
If RadioButton3.Checked Then
Otchet_PoIsp()
End If
If RadioButton4.Checked Then
Otchet_Otkl()
End If
If RadioButton5.Checked Then
Otchet_ProblUsers()
End If
If RadioButton6.Checked Then
Otchet_ProblPC()
End If
If RadioButton7.Checked Then
Otchet_Dynamic()
End If
End Sub
Private Sub Otchet_Nevyp()
Dim StartDate As String = Form6.GetDateString(DateTimePicker1.Value)
Dim EndDate As String = Form6.GetDateString(DateTimePicker2.Value)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
SqlCommand1.CommandText = "select [id_ticket],[fio],[id_incident] from [ticket]" & vbCrLf & _
"where [id_status] < 5 and [otklon] = 0 " & vbCrLf & _
"and [open_ticket] >= convert(datetime,'" & StartDate & "',12) and [open_ticket] <= convert(datetime,'" & EndDate & "',12)"
SqlAdapter1.SelectCommand = SqlCommand1
SqlAdapter1.SelectCommand.Connection = SqlConnection1
Dim c_row, c_col As Integer
Dim id_ticket, fio, incident, comment As String
Try
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oPara1, oPara2, oPara3, oPara4 As Word.Paragraph
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "Отчет о невыполненных заявках - " & DateAndTime.Now.ToString
oPara1.Range.Font.Size = 13
oPara1.Range.Font.Bold = True
oPara1.Range.InsertParagraphAfter()
SqlAdapter1.SelectCommand.Connection.Open()
SqlAdapter1.Fill(DataSet1)
c_row = DataSet1.Tables.Item(0).Rows.Count
c_col = DataSet1.Tables.Item(0).Columns.Count
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, c_row + 1, 4)
oTable.Range.ParagraphFormat.SpaceAfter = 6
oTable.Range.Font.Size = 11
oTable.Range.Font.Bold = False
oTable.Rows.Borders.Enable = True
oTable.Columns.Borders.Enable = True
oTable.Columns(1).SetWidth(43, Word.WdRulerStyle.wdAdjustNone)
oTable.Columns(2).SetWidth(80, Word.WdRulerStyle.wdAdjustNone)
oTable.Columns(3).SetWidth(170, Word.WdRulerStyle.wdAdjustNone)
oTable.Columns(4).SetWidth(179, Word.WdRulerStyle.wdAdjustNone)
oTable.Rows.Item(1).Range.Font.Bold = True
oTable.Rows.Item(1).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray15
oTable.Cell(1, 1).Range.Text = "Номер"
oTable.Cell(1, 2).Range.Text = "Пользователь"
oTable.Cell(1, 3).Range.Text = "Инцидент"
oTable.Cell(1, 4).Range.Text = "Текст заявки"
For i = 1 To c_row
id_ticket = DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(0)
fio = DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(1)
incident = GetIncident(DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(2))
comment = GetComment(id_ticket)
oTable.Cell(i + 1, 1).Range.Text = CStr(id_ticket)
oTable.Cell(i + 1, 2).Range.Text = CStr(fio)
oTable.Cell(i + 1, 3).Range.Text = CStr(incident)
oTable.Cell(i + 1, 4).Range.Text = Replace(CStr(comment), "----Пользователь----" & vbCrLf, "")
Next
SqlAdapter1.SelectCommand.Connection.Close()
oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "select COUNT(*) from ticket where [id_status] < 5 and [otklon] = 0"
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
Dim nz As String = DataSet2.Tables.Item(0).Rows.Item(0).Item(0).ToString
SqlAdapter2.SelectCommand.Connection.Close()
oPara2.Range.ParagraphFormat.SpaceBefore = 0
oPara2.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara2.Range.ParagraphFormat.SpaceAfter = 0
oPara2.Range.ParagraphFormat.SpaceAfterAuto = False
oPara2.Range.Text = "Всего заявок - " & vbTab & vbTab & vbTab & nz
oPara2.Range.Font.Size = 11
oPara2.Range.Font.Bold = True
oPara2.Range.InsertParagraphAfter()
oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
Dim SqlAdapter3 As New SqlClient.SqlDataAdapter
Dim DataSet3 As New DataSet
Dim SqlConnection3 As New SqlClient.SqlConnection
cmd = "select distinct [id_incident] from [ticket] where [id_status] < 5 and [otklon] = 0"
SqlConnection3.ConnectionString = con_string
Dim SqlCommand3 As New SqlClient.SqlCommand
SqlCommand3.CommandText = cmd
SqlAdapter3.SelectCommand = SqlCommand3
SqlAdapter3.SelectCommand.Connection = SqlConnection3
SqlAdapter3.SelectCommand.Connection.Open()
SqlAdapter3.Fill(DataSet3)
Dim ninc As String = DataSet3.Tables.Item(0).Rows.Count.ToString
SqlAdapter3.SelectCommand.Connection.Close()
oPara3.Range.ParagraphFormat.SpaceBefore = 0
oPara3.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara3.Range.ParagraphFormat.SpaceAfter = 0
oPara3.Range.ParagraphFormat.SpaceAfterAuto = False
oPara3.Range.Text = "Всего типов инцидентов - " & vbTab & ninc
oPara3.Range.Font.Size = 11
oPara3.Range.Font.Bold = True
oPara3.Range.InsertParagraphAfter()
oPara4 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
Dim SqlAdapter4 As New SqlClient.SqlDataAdapter
Dim DataSet4 As New DataSet
Dim SqlConnection4 As New SqlClient.SqlConnection
cmd = "select distinct convert(char(11),[fio]) from [ticket] where [id_status] < 5 and [otklon] = 0"
SqlConnection4.ConnectionString = con_string
Dim SqlCommand4 As New SqlClient.SqlCommand
SqlCommand4.CommandText = cmd
SqlAdapter4.SelectCommand = SqlCommand4
SqlAdapter4.SelectCommand.Connection = SqlConnection4
SqlAdapter4.SelectCommand.Connection.Open()
SqlAdapter4.Fill(DataSet4)
Dim nfio As String = DataSet4.Tables.Item(0).Rows.Count.ToString
SqlAdapter4.SelectCommand.Connection.Close()
oPara4.Range.ParagraphFormat.SpaceBefore = 0
oPara4.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara4.Range.ParagraphFormat.SpaceAfter = 0
oPara4.Range.ParagraphFormat.SpaceAfterAuto = False
oPara4.Range.Text = "Всего пользователей - " & vbTab & nfio
oPara4.Range.Font.Size = 11
oPara4.Range.Font.Bold = True
oPara4.Range.InsertParagraphAfter()
Catch ex As Exception
End Try
End Sub
Private Sub Otchet_Vyp()
Dim StartDate As String = Form6.GetDateString(DateTimePicker1.Value)
Dim EndDate As String = Form6.GetDateString(DateTimePicker2.Value)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
SqlCommand1.CommandText = "select [id_ticket],[fio],[id_incident] from [ticket]" & vbCrLf & _
"where [id_status] = 5 and [otklon] = 0 " & vbCrLf & _
"and [open_ticket] >= convert(datetime,'" & StartDate & "',12) and [open_ticket] <= convert(datetime,'" & EndDate & "',12)"
SqlAdapter1.SelectCommand = SqlCommand1
SqlAdapter1.SelectCommand.Connection = SqlConnection1
Dim c_row, c_col As Integer
Dim id_ticket, fio, incident, comment As String
Try
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oPara0, oPara1, oPara2, oPara3, oPara4 As Word.Paragraph
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
oPara0 = oDoc.Content.Paragraphs.Add
oPara0.Range.Text = "Отчет о выполненных заявках - " & DateAndTime.Now.ToString
oPara0.Range.Font.Size = 13
oPara0.Range.Font.Bold = True
oPara0.Range.ParagraphFormat.SpaceBefore = 0
oPara0.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara0.Range.ParagraphFormat.SpaceAfter = 0
oPara0.Range.ParagraphFormat.SpaceAfterAuto = False
oPara0.Range.InsertParagraphAfter()
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "За период - с " & DateTimePicker1.Value.ToString & _
" по " & DateTimePicker2.Value.ToString
oPara1.Range.Font.Size = 12
oPara1.Range.Font.Bold = False
oPara1.Range.ParagraphFormat.SpaceBefore = 0
oPara1.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara1.Range.ParagraphFormat.SpaceAfter = 20
oPara1.Range.ParagraphFormat.SpaceAfterAuto = False
oPara1.Range.InsertParagraphAfter()
SqlAdapter1.SelectCommand.Connection.Open()
SqlAdapter1.Fill(DataSet1)
c_row = DataSet1.Tables.Item(0).Rows.Count
c_col = DataSet1.Tables.Item(0).Columns.Count
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, c_row + 1, 3)
oTable.Range.Font.Size = 11
oTable.Range.Font.Bold = False
oTable.Rows.Borders.Enable = True
oTable.Columns.Borders.Enable = True
oTable.Columns(1).SetWidth(43, Word.WdRulerStyle.wdAdjustNone)
oTable.Columns(2).SetWidth(80, Word.WdRulerStyle.wdAdjustNone)
oTable.Columns(3).SetWidth(349, Word.WdRulerStyle.wdAdjustNone)
oTable.Rows.Item(1).Range.Font.Bold = True
oTable.Rows.Item(1).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray15
oTable.Cell(1, 1).Range.Text = "Номер"
oTable.Cell(1, 2).Range.Text = "Пользователь"
oTable.Cell(1, 3).Range.Text = "Инцидент"
For i = 1 To c_row
id_ticket = DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(0)
fio = DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(1)
incident = GetIncident(DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(2))
comment = GetComment(id_ticket)
oTable.Cell(i + 1, 1).Range.Text = CStr(id_ticket)
oTable.Cell(i + 1, 2).Range.Text = CStr(fio)
oTable.Cell(i + 1, 3).Range.Text = CStr(incident)
Next
SqlAdapter1.SelectCommand.Connection.Close()
oTable.Range.ParagraphFormat.SpaceBefore = 0
oTable.Range.ParagraphFormat.SpaceBeforeAuto = False
oTable.Range.ParagraphFormat.SpaceAfter = 0
oTable.Range.ParagraphFormat.SpaceAfterAuto = False
oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara2.Range.ParagraphFormat.SpaceBefore = 0
oPara2.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara2.Range.ParagraphFormat.SpaceAfter = 0
oPara2.Range.ParagraphFormat.SpaceAfterAuto = False
oPara2.Range.Text = "Всего заявок - " & vbTab & vbTab & vbTab & c_row.ToString
oPara2.Range.Font.Size = 11
oPara2.Range.Font.Bold = True
oPara2.Range.InsertParagraphAfter()
oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
Dim SqlAdapter3 As New SqlClient.SqlDataAdapter
Dim DataSet3 As New DataSet
Dim SqlConnection3 As New SqlClient.SqlConnection
Dim cmd As String = "select distinct [id_incident] from [ticket] where [id_status] = 5 and [otklon] = 0 " & _
"and [open_ticket] >= convert(datetime,'" & StartDate & "',12) and [open_ticket] <= convert(datetime,'" & EndDate & "',12)"
SqlConnection3.ConnectionString = con_string
Dim SqlCommand3 As New SqlClient.SqlCommand
SqlCommand3.CommandText = cmd
SqlAdapter3.SelectCommand = SqlCommand3
SqlAdapter3.SelectCommand.Connection = SqlConnection3
SqlAdapter3.SelectCommand.Connection.Open()
SqlAdapter3.Fill(DataSet3)
Dim ninc As String = DataSet3.Tables.Item(0).Rows.Count.ToString
SqlAdapter3.SelectCommand.Connection.Close()
oPara3.Range.ParagraphFormat.SpaceBefore = 0
oPara3.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara3.Range.ParagraphFormat.SpaceAfter = 0
oPara3.Range.ParagraphFormat.SpaceAfterAuto = False
oPara3.Range.Text = "Всего типов инцидентов - " & vbTab & ninc
oPara3.Range.Font.Size = 11
oPara3.Range.Font.Bold = True
oPara3.Range.InsertParagraphAfter()
oPara4 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
Dim SqlAdapter4 As New SqlClient.SqlDataAdapter
Dim DataSet4 As New DataSet
Dim SqlConnection4 As New SqlClient.SqlConnection
cmd = "select distinct convert(char(11),[fio]) from [ticket] where [id_status] = 5 and [otklon] = 0 " & _
"and [open_ticket] >= convert(datetime,'" & StartDate & "',12) and [open_ticket] <= convert(datetime,'" & EndDate & "',12)"
SqlConnection4.ConnectionString = con_string
Dim SqlCommand4 As New SqlClient.SqlCommand
SqlCommand4.CommandText = cmd
SqlAdapter4.SelectCommand = SqlCommand4
SqlAdapter4.SelectCommand.Connection = SqlConnection4
SqlAdapter4.SelectCommand.Connection.Open()
SqlAdapter4.Fill(DataSet4)
Dim nfio As String = DataSet4.Tables.Item(0).Rows.Count.ToString
SqlAdapter4.SelectCommand.Connection.Close()
oPara4.Range.ParagraphFormat.SpaceBefore = 0
oPara4.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara4.Range.ParagraphFormat.SpaceAfter = 0
oPara4.Range.ParagraphFormat.SpaceAfterAuto = False
oPara4.Range.Text = "Всего пользователей - " & vbTab & nfio
oPara4.Range.Font.Size = 11
oPara4.Range.Font.Bold = True
oPara4.Range.InsertParagraphAfter()
Catch ex As Exception
End Try
End Sub
Private Sub Otchet_PoIsp()
Dim StartDate As String = Form6.GetDateString(DateTimePicker1.Value)
Dim EndDate As String = Form6.GetDateString(DateTimePicker2.Value)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
SqlCommand1.CommandText = "select distinct [id_users] from [ticket]" & vbCrLf & _
"where [otklon] = 0 " & vbCrLf & _
"and [open_ticket] >= convert(datetime,'" & _
StartDate & "',12) and [open_ticket] <= convert(datetime,'" & _
EndDate & "',12)"
SqlAdapter1.SelectCommand = SqlCommand1
SqlAdapter1.SelectCommand.Connection = SqlConnection1
Dim c_row, c1_row As Integer
Dim id_ticket, fio, incident As String
Try
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oPara0, oPara1 As Word.Paragraph
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
oPara0 = oDoc.Content.Paragraphs.Add
oPara0.Range.Text = "Отчет о заявках по исполнителям - " & DateAndTime.Now.ToString
oPara0.Range.Font.Size = 13
oPara0.Range.Font.Bold = True
oPara0.Range.ParagraphFormat.SpaceBefore = 0
oPara0.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara0.Range.ParagraphFormat.SpaceAfter = 0
oPara0.Range.ParagraphFormat.SpaceAfterAuto = False
oPara0.Range.InsertParagraphAfter()
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "За период - с " & DateTimePicker1.Value.ToString & _
" по " & DateTimePicker2.Value.ToString
oPara1.Range.Font.Size = 12
oPara1.Range.Font.Bold = False
oPara1.Range.ParagraphFormat.SpaceBefore = 0
oPara1.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara1.Range.ParagraphFormat.SpaceAfter = 20
oPara1.Range.ParagraphFormat.SpaceAfterAuto = False
oPara1.Range.InsertParagraphAfter()
SqlAdapter1.SelectCommand.Connection.Open()
SqlAdapter1.Fill(DataSet1)
c_row = DataSet1.Tables.Item(0).Rows.Count
Dim id_user As Integer
Dim n_user As String
For i = 1 To c_row
id_user = DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(0)
n_user = GetAdmin(id_user)
oPara1.Range.Font.Bold = True
oPara1.Range.ParagraphFormat.SpaceAfter = 10
oPara1.Range.InsertAfter(n_user & vbCrLf)
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "select [id_ticket],[fio],[id_incident] from [ticket] where [otklon] = 0 " & _
"and [open_ticket] >= convert(datetime,'" & _
StartDate & "',12) and [open_ticket] <= convert(datetime,'" & _
EndDate & "',12) and [id_users] = " & id_user.ToString
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
c1_row = DataSet2.Tables.Item(0).Rows.Count
For j = 1 To c1_row
oPara1.Range.Font.Bold = False
oPara1.Range.ParagraphFormat.SpaceAfter = 0
id_ticket = DataSet2.Tables.Item(0).Rows.Item(j - 1).Item(0)
fio = DataSet2.Tables.Item(0).Rows.Item(j - 1).Item(1)
incident = GetIncident(DataSet2.Tables.Item(0).Rows.Item(j - 1).Item(2))
oPara1.Range.InsertAfter(id_ticket & vbTab & fio & vbTab & incident & vbCrLf)
Next
Next
Catch ex As Exception
End Try
End Sub
Private Sub Otchet_Otkl()
Dim StartDate As String = Form6.GetDateString(DateTimePicker1.Value)
Dim EndDate As String = Form6.GetDateString(DateTimePicker2.Value)
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter1 As New SqlClient.SqlDataAdapter
Dim DataSet1 As New DataSet
Dim SqlConnection1 As New SqlClient.SqlConnection
SqlConnection1.ConnectionString = con_string
Dim SqlCommand1 As New SqlClient.SqlCommand
SqlCommand1.CommandText = "select [id_ticket],[fio],[id_incident] from [ticket]" & vbCrLf & _
"where [otklon] = 1 " & vbCrLf & _
"and [open_ticket] >= convert(datetime,'" & _
StartDate & "',12) and [open_ticket] <= convert(datetime,'" & _
EndDate & "',12)"
SqlAdapter1.SelectCommand = SqlCommand1
SqlAdapter1.SelectCommand.Connection = SqlConnection1
Dim c_row, c_col As Integer
Dim id_ticket, fio, incident, comment As String
Try
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oPara0, oPara1, oPara2, oPara3, oPara4 As Word.Paragraph
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
oPara0 = oDoc.Content.Paragraphs.Add
oPara0.Range.Text = "Отчет об отклоненных заявках - " & DateAndTime.Now.ToString
oPara0.Range.Font.Size = 13
oPara0.Range.Font.Bold = True
oPara0.Range.ParagraphFormat.SpaceBefore = 0
oPara0.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara0.Range.ParagraphFormat.SpaceAfter = 0
oPara0.Range.ParagraphFormat.SpaceAfterAuto = False
oPara0.Range.InsertParagraphAfter()
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "За период - с " & DateTimePicker1.Value.ToString & _
" по " & DateTimePicker2.Value.ToString
oPara1.Range.Font.Size = 12
oPara1.Range.Font.Bold = False
oPara1.Range.ParagraphFormat.SpaceBefore = 0
oPara1.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara1.Range.ParagraphFormat.SpaceAfter = 20
oPara1.Range.ParagraphFormat.SpaceAfterAuto = False
oPara1.Range.InsertParagraphAfter()
SqlAdapter1.SelectCommand.Connection.Open()
SqlAdapter1.Fill(DataSet1)
c_row = DataSet1.Tables.Item(0).Rows.Count
c_col = DataSet1.Tables.Item(0).Columns.Count
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, c_row + 1, 4)
oTable.Range.ParagraphFormat.SpaceAfter = 6
oTable.Range.Font.Size = 11
oTable.Range.Font.Bold = False
oTable.Rows.Borders.Enable = True
oTable.Columns.Borders.Enable = True
oTable.Columns(1).SetWidth(43, Word.WdRulerStyle.wdAdjustNone)
oTable.Columns(2).SetWidth(80, Word.WdRulerStyle.wdAdjustNone)
oTable.Columns(3).SetWidth(170, Word.WdRulerStyle.wdAdjustNone)
oTable.Columns(4).SetWidth(179, Word.WdRulerStyle.wdAdjustNone)
oTable.Rows.Item(1).Range.Font.Bold = True
oTable.Rows.Item(1).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray15
oTable.Cell(1, 1).Range.Text = "Номер"
oTable.Cell(1, 2).Range.Text = "Пользователь"
oTable.Cell(1, 3).Range.Text = "Инцидент"
oTable.Cell(1, 4).Range.Text = "Текст заявки"
For i = 1 To c_row
id_ticket = DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(0)
fio = DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(1)
incident = GetIncident(DataSet1.Tables.Item(0).Rows.Item(i - 1).Item(2))
comment = GetComment(id_ticket)
oTable.Cell(i + 1, 1).Range.Text = CStr(id_ticket)
oTable.Cell(i + 1, 2).Range.Text = CStr(fio)
oTable.Cell(i + 1, 3).Range.Text = CStr(incident)
oTable.Cell(i + 1, 4).Range.Text = Replace(CStr(comment), "----Пользователь----" & vbCrLf, "")
Next
oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara2.Range.ParagraphFormat.SpaceBefore = 0
oPara2.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara2.Range.ParagraphFormat.SpaceAfter = 0
oPara2.Range.ParagraphFormat.SpaceAfterAuto = False
oPara2.Range.Text = "Всего заявок - " & vbTab & vbTab & vbTab & c_row
oPara2.Range.Font.Size = 11
oPara2.Range.Font.Bold = True
oPara2.Range.InsertParagraphAfter()
oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
Dim SqlAdapter3 As New SqlClient.SqlDataAdapter
Dim DataSet3 As New DataSet
Dim SqlConnection3 As New SqlClient.SqlConnection
Dim cmd As String = "select distinct [id_incident] from [ticket] where [otklon] = 1 " & _
"and [open_ticket] >= convert(datetime,'" & _
StartDate & "',12) and [open_ticket] <= convert(datetime,'" & _
EndDate & "',12)"
SqlConnection3.ConnectionString = con_string
Dim SqlCommand3 As New SqlClient.SqlCommand
SqlCommand3.CommandText = cmd
SqlAdapter3.SelectCommand = SqlCommand3
SqlAdapter3.SelectCommand.Connection = SqlConnection3
SqlAdapter3.SelectCommand.Connection.Open()
SqlAdapter3.Fill(DataSet3)
Dim ninc As String = DataSet3.Tables.Item(0).Rows.Count.ToString
SqlAdapter3.SelectCommand.Connection.Close()
oPara3.Range.ParagraphFormat.SpaceBefore = 0
oPara3.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara3.Range.ParagraphFormat.SpaceAfter = 0
oPara3.Range.ParagraphFormat.SpaceAfterAuto = False
oPara3.Range.Text = "Всего типов инцидентов - " & vbTab & ninc
oPara3.Range.Font.Size = 11
oPara3.Range.Font.Bold = True
oPara3.Range.InsertParagraphAfter()
oPara4 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
Dim SqlAdapter4 As New SqlClient.SqlDataAdapter
Dim DataSet4 As New DataSet
Dim SqlConnection4 As New SqlClient.SqlConnection
cmd = "select distinct convert(char(11),[fio]) from [ticket] where [otklon] = 1 " & _
"and [open_ticket] >= convert(datetime,'" & _
StartDate & "',12) and [open_ticket] <= convert(datetime,'" & _
EndDate & "',12)"
SqlConnection4.ConnectionString = con_string
Dim SqlCommand4 As New SqlClient.SqlCommand
SqlCommand4.CommandText = cmd
SqlAdapter4.SelectCommand = SqlCommand4
SqlAdapter4.SelectCommand.Connection = SqlConnection4
SqlAdapter4.SelectCommand.Connection.Open()
SqlAdapter4.Fill(DataSet4)
Dim nfio As String = DataSet4.Tables.Item(0).Rows.Count.ToString
SqlAdapter4.SelectCommand.Connection.Close()
oPara4.Range.ParagraphFormat.SpaceBefore = 0
oPara4.Range.ParagraphFormat.SpaceBeforeAuto = False
oPara4.Range.ParagraphFormat.SpaceAfter = 0
oPara4.Range.ParagraphFormat.SpaceAfterAuto = False
oPara4.Range.Text = "Всего пользователей - " & vbTab & nfio
oPara4.Range.Font.Size = 11
oPara4.Range.Font.Bold = True
oPara4.Range.InsertParagraphAfter()
Catch ex As Exception
End Try
End Sub
Private Sub Otchet_ProblUsers()
End Sub
Private Sub Otchet_ProblPC()
End Sub
Private Sub Otchet_Dynamic()
End Sub
Private Function GetIncident(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [name_incident]" & _
"FROM [incident] where id_incident = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetIncident = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetComment(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [comments]" & _
"FROM [comments] where id_ticket = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetComment = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
Private Function GetAdmin(ByVal id As Integer) As String
Dim con_string As String = "Data Source=" & Form1.srv & ";Initial Catalog=" & Form1.it_db & ";Integrated Security=True"
Dim SqlAdapter2 As New SqlClient.SqlDataAdapter
Dim DataSet2 As New DataSet
Dim SqlConnection2 As New SqlClient.SqlConnection
Dim cmd As String = "SELECT [admin]" & _
"FROM [admins] where id_users = " & CStr(id)
SqlConnection2.ConnectionString = con_string
Dim SqlCommand2 As New SqlClient.SqlCommand
SqlCommand2.CommandText = cmd
SqlAdapter2.SelectCommand = SqlCommand2
SqlAdapter2.SelectCommand.Connection = SqlConnection2
SqlAdapter2.SelectCommand.Connection.Open()
SqlAdapter2.Fill(DataSet2)
GetAdmin = DataSet2.Tables.Item(0).Rows.Item(0).Item(0)
SqlAdapter2.SelectCommand.Connection.Close()
End Function
End Class
Imports System.Data.Odbc
Public Class Form5
Private Sub Form5_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Form1.Visible = False
End Sub
Private Sub Form5_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form1.Visible = True
Form1.Activate()
End Sub
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label3.Text = "Действие выполнять" & vbCrLf & "один раз"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.srv = TextBox1.Text
Form1.it_db = TextBox2.Text
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DBCreate()
End Sub
Private Sub DBCreate()
Dim cmd1 As String = _
"CREATE DATABASE [" & TextBox2.Text & "] ON PRIMARY " & vbCrLf & _
"( NAME = N'" & TextBox2.Text & "', FILENAME = N'C:\" & TextBox2.Text & ".mdf' , SIZE = 3072KB , FILEGROWTH = 1024KB )" & vbCrLf & _
" LOG ON " & vbCrLf & _
"( NAME = N'" & TextBox2.Text & "_log', FILENAME = N'C:\" & TextBox2.Text & "_log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%)" & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET COMPATIBILITY_LEVEL = 100" & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET ANSI_NULL_DEFAULT OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET ANSI_NULLS OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET ANSI_PADDING OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET ANSI_WARNINGS OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET ARITHABORT OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET AUTO_CLOSE OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET AUTO_CREATE_STATISTICS ON " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET AUTO_SHRINK OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET AUTO_UPDATE_STATISTICS ON " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET CURSOR_CLOSE_ON_COMMIT OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET CURSOR_DEFAULT GLOBAL " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET CONCAT_NULL_YIELDS_NULL OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET NUMERIC_ROUNDABORT OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET QUOTED_IDENTIFIER OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET RECURSIVE_TRIGGERS OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET DISABLE_BROKER " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET AUTO_UPDATE_STATISTICS_ASYNC OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET DATE_CORRELATION_OPTIMIZATION OFF " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET PARAMETERIZATION SIMPLE " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET READ_WRITE " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET RECOVERY SIMPLE " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET MULTI_USER " & vbCrLf & _
"ALTER DATABASE [" & TextBox2.Text & "] SET PAGE_VERIFY CHECKSUM "
Dim cmd2 As String = _
"USE [" & TextBox2.Text & "]" & vbCrLf & _
"IF NOT EXISTS (SELECT name FROM sys.filegroups WHERE is_default=1 AND name = N'PRIMARY') ALTER DATABASE [" & TextBox2.Text & "] MODIFY FILEGROUP [PRIMARY] DEFAULT" & vbCrLf & _
"USE [" & TextBox2.Text & "]" & vbCrLf & _
"SET ANSI_NULLS ON" & vbCrLf & _
"SET QUOTED_IDENTIFIER ON" & vbCrLf & _
"CREATE TABLE [dbo].[status](" & vbCrLf & _
" [id_status] [int] IDENTITY(1,1) NOT NULL," & vbCrLf & _
" [name_status] [text] NOT NULL," & vbCrLf & _
" CONSTRAINT [PK_status] PRIMARY KEY CLUSTERED " & vbCrLf & _
"(" & vbCrLf & _
" [id_status] ASC" & vbCrLf & _
")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]" & vbCrLf & _
") ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]" & vbCrLf & _
"SET ANSI_NULLS ON" & vbCrLf & _
"SET QUOTED_IDENTIFIER ON" & vbCrLf & _
"CREATE TABLE [dbo].[priority](" & vbCrLf & _
" [id_priority] [int] IDENTITY(1,1) NOT NULL," & vbCrLf & _
" [name_priority] [text] NOT NULL," & vbCrLf & _
" CONSTRAINT [PK_priority] PRIMARY KEY CLUSTERED " & vbCrLf & _
"(" & vbCrLf & _
" [id_priority] ASC" & vbCrLf & _
")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]" & vbCrLf & _
") ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]" & vbCrLf & _
"SET ANSI_NULLS ON" & vbCrLf & _
"SET QUOTED_IDENTIFIER ON" & vbCrLf & _
"CREATE TABLE [dbo].[incident](" & vbCrLf & _
" [id_incident] [int] IDENTITY(1,1) NOT NULL," & vbCrLf & _
" [name_incident] [text] NOT NULL," & vbCrLf & _
" CONSTRAINT [PK_incident] PRIMARY KEY CLUSTERED " & vbCrLf & _
"(" & vbCrLf & _
" [id_incident] ASC" & vbCrLf & _
")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]" & vbCrLf & _
") ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]" & vbCrLf & _
"SET ANSI_NULLS ON" & vbCrLf & _
"SET QUOTED_IDENTIFIER ON" & vbCrLf & _
"CREATE TABLE [dbo].[admins](" & vbCrLf & _
" [id_users] [int] IDENTITY(-1,1) NOT NULL," & vbCrLf & _
" [admin] [text] NOT NULL," & vbCrLf & _
" [login] [text] NOT NULL," & vbCrLf & _
" CONSTRAINT [PK_admins] PRIMARY KEY CLUSTERED " & vbCrLf & _
"(" & vbCrLf & _
" [id_users] ASC" & vbCrLf & _
")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]" & vbCrLf & _
") ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]" & vbCrLf & _
"SET ANSI_NULLS ON" & vbCrLf & _
"SET QUOTED_IDENTIFIER ON" & vbCrLf & _
"CREATE TABLE [dbo].[ticket](" & vbCrLf & _
" [id_ticket] [int] IDENTITY(1,1) NOT NULL," & vbCrLf & _
" [fio] [text] NOT NULL," & vbCrLf & _
" [phone] [text] NOT NULL," & vbCrLf & _
" [id_incident] [int] NOT NULL," & vbCrLf & _
" [id_priority] [int] NOT NULL," & vbCrLf & _
" [id_status] [int] NOT NULL," & vbCrLf & _
" [id_users] [int] NULL," & vbCrLf & _
" [open_ticket] [datetime] NOT NULL," & vbCrLf & _
" [close_ticket] [datetime] NULL," & vbCrLf & _
" [work_time] [time] NULL," & vbCrLf & _
" [tabel] [smallint] NOT NULL," & vbCrLf & _
" [pc_inv] [text] NOT NULL," & vbCrLf & _
" [room] [text] NOT NULL," & vbCrLf & _
" [deleted] [bit] NOT NULL," & vbCrLf & _
" [otklon] [bit] NOT NULL," & vbCrLf & _
" CONSTRAINT [PK_ticket] PRIMARY KEY CLUSTERED " & vbCrLf & _
"(" & vbCrLf & _
" [id_ticket] ASC" & vbCrLf & _
")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]" & vbCrLf & _
") ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]" & vbCrLf & _
"SET ANSI_NULLS ON" & vbCrLf & _
"SET QUOTED_IDENTIFIER ON" & vbCrLf & _
"CREATE TABLE [dbo].[comments](" & vbCrLf & _
" [id_ticket] [int] NOT NULL," & vbCrLf & _
" [dt_comments] [datetime] NOT NULL," & vbCrLf & _
" [comments] [text] NOT NULL," & vbCrLf & _
" CONSTRAINT [PK_comments] PRIMARY KEY CLUSTERED " & vbCrLf & _
"(" & vbCrLf & _
" [id_ticket] ASC" & vbCrLf & _
")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]" & vbCrLf & _
") ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]" & vbCrLf & _
"SET ANSI_NULLS ON" & vbCrLf & _
"SET QUOTED_IDENTIFIER ON" & vbCrLf & _
"SET ANSI_PADDING ON" & vbCrLf & _
"CREATE TABLE [dbo].[attach](" & vbCrLf & _
" [id_ticket] [int] NOT NULL," & vbCrLf & _
" [image] [varbinary](max) NOT NULL," & vbCrLf & _
" CONSTRAINT [PK_attach] PRIMARY KEY CLUSTERED " & vbCrLf & _
"(" & vbCrLf & _
" [id_ticket] ASC" & vbCrLf & _
")WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]" & vbCrLf & _
") ON [PRIMARY]" & vbCrLf & _
"SET ANSI_PADDING OFF" & vbCrLf & _
"ALTER TABLE [dbo].[attach] WITH CHECK ADD CONSTRAINT [FK_attach_ticket] FOREIGN KEY([id_ticket])" & vbCrLf & _
"REFERENCES [dbo].[ticket] ([id_ticket])" & vbCrLf & _
"ON UPDATE CASCADE" & vbCrLf & _
"ALTER TABLE [dbo].[attach] CHECK CONSTRAINT [FK_attach_ticket]" & vbCrLf & _
"ALTER TABLE [dbo].[comments] WITH CHECK ADD CONSTRAINT [FK_comments_ticket] FOREIGN KEY([id_ticket])" & vbCrLf & _
"REFERENCES [dbo].[ticket] ([id_ticket])" & vbCrLf & _
"ON UPDATE CASCADE" & vbCrLf & _
"ALTER TABLE [dbo].[comments] CHECK CONSTRAINT [FK_comments_ticket]" & vbCrLf & _
"ALTER TABLE [dbo].[ticket] WITH CHECK ADD CONSTRAINT [FK_ticket_admins] FOREIGN KEY([id_users])" & vbCrLf & _
"REFERENCES [dbo].[admins] ([id_users])" & vbCrLf & _
"ALTER TABLE [dbo].[ticket] CHECK CONSTRAINT [FK_ticket_admins]" & vbCrLf & _
"ALTER TABLE [dbo].[ticket] WITH CHECK ADD CONSTRAINT [FK_ticket_incident] FOREIGN KEY([id_incident])" & vbCrLf & _
"REFERENCES [dbo].[incident] ([id_incident])" & vbCrLf & _
"ALTER TABLE [dbo].[ticket] CHECK CONSTRAINT [FK_ticket_incident]" & vbCrLf & _
"ALTER TABLE [dbo].[ticket] WITH CHECK ADD CONSTRAINT [FK_ticket_priority] FOREIGN KEY([id_priority])" & vbCrLf & _
"REFERENCES [dbo].[priority] ([id_priority])" & vbCrLf & _
"ALTER TABLE [dbo].[ticket] CHECK CONSTRAINT [FK_ticket_priority]" & vbCrLf & _
"ALTER TABLE [dbo].[ticket] WITH CHECK ADD CONSTRAINT [FK_ticket_status] FOREIGN KEY([id_status])" & vbCrLf & _
"REFERENCES [dbo].[status] ([id_status])" & vbCrLf & _
"ALTER TABLE [dbo].[ticket] CHECK CONSTRAINT [FK_ticket_status]"
Dim cmd3 As String = _
"USE [" & TextBox2.Text & "]" & vbCrLf & _
"INSERT" & vbCrLf & _
"INTO admins(admin,login)" & vbCrLf & _
"VALUES ('Не назначен','Нет')" & vbCrLf & _
"INSERT" & vbCrLf & _
"INTO incident(name_incident)" & vbCrLf & _
"VALUES ('Другое'),('Не открывается файл'),('Отсутствуют сетевые диски'),('Перемещение техники')," & vbCrLf & _
" ('Проблема с интернетом'),('Проблема с компьютером'),('Проблема с сетью'),('Проблема с электронной почтой')," & vbCrLf & _
" ('Проблема с принтером'),('Создание нового рабочего места'),('Телефония') " & vbCrLf & _
"INSERT" & vbCrLf & _
"INTO priority(name_priority)" & vbCrLf & _
"VALUES ('Низкий'),('Нормальный'),('Высокий')" & vbCrLf & _
"INSERT" & vbCrLf & _
"INTO status(name_status)" & vbCrLf & _
"VALUES ('Открыта'),('Назначена'),('В работе'),('Отложена'),('Закрыта')"
Dim conn_string As String = "Driver={SQL Server};Server=" & TextBox1.Text & ";Trusted_Connection=Yes;Database=master;"
If Not Form1.TestConnect(TextBox1.Text, TextBox2.Text) Then
ExQuery(conn_string, cmd1)
conn_string = "Driver={SQL Server};Server=" & TextBox1.Text & ";Trusted_Connection=Yes;Database=" & TextBox2.Text & ";"
ExQuery(conn_string, cmd2)
ExQuery(conn_string, cmd3)
MsgBox("База " & Chr(34) & TextBox2.Text & Chr(34) & " создана на сервере " & _
Chr(34) & TextBox1.Text & Chr(34) & ".", _
MsgBoxStyle.Information, "Сообщение")
Else
MsgBox("База " & Chr(34) & TextBox2.Text & Chr(34) & " не создана на сервере " & _
Chr(34) & TextBox1.Text & Chr(34) & ", т.к. существует база с таким же именем.", _
MsgBoxStyle.Information, "Сообщение")
End If
End Sub
Function ExQuery(ByVal connectionString As String, ByVal cmd As String) As Integer
Dim command As New OdbcCommand(cmd)
Using connection As New OdbcConnection(connectionString)
command.Connection = connection
Try
connection.Open()
ExQuery = command.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Ошибка: " & ex.Message, MsgBoxStyle.Information, "Сообщение")
End Try
End Using
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Form6.Visible = True
Form6.Activate()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Form7.Visible = True
Form7.Activate()
End Sub
End Class
Public Class Form6
Private Sub Form6_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Form5.Visible = False
End Sub
Private Sub Form6_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form5.Visible = True
Form5.Activate()
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
DateTimePicker1.Enabled = True
Else
DateTimePicker1.Enabled = False
End If
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked Then
DateTimePicker2.Enabled = True
Else
DateTimePicker2.Enabled = False
End If
End Sub
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DateTimePicker1.MaxDate = Date.Today
DateTimePicker2.MaxDate = Date.Today
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim StartDate, EndDate As String
If CheckBox1.Checked Then
StartDate = GetDateString(DateTimePicker1.Value.Date)
Else
StartDate = "20120101 00:00:00"
End If
If CheckBox2.Checked Then
EndDate = GetDateString(DateTimePicker2.Value.Date)
Else
EndDate = "21001231 00:00:00"
End If
If Not DateTimePicker1.Value.Date = DateTimePicker2.Value.Date Then
Dim cmd As String = ""
Dim cmd1 As String = _
"declare @mint int, @maxt int" & vbCrLf & _
"SELECT @mint=MIN(id_ticket)" & vbCrLf & _
"FROM [ticket] where [open_ticket] > convert(datetime,'" & StartDate & "',12) and [open_ticket] < convert(datetime,'" & EndDate & "',12)" & vbCrLf & _
"select @maxt=MAX(id_ticket)" & vbCrLf & _
"FROM [ticket] where [open_ticket] > convert(datetime,'" & StartDate & "',12) and [open_ticket] < convert(datetime,'" & EndDate & "',12)" & vbCrLf
Dim cmd2 As String = _
"UPDATE ticket" & vbCrLf & _
"SET deleted = 1 where ([id_ticket] >= @mint) and ([id_ticket] <= @maxt) and ([deleted] = 0)"
Dim cmd3 As String = _
"delete from [comments] where ([id_ticket] >= @mint) and ([id_ticket] <= @maxt)" & vbCrLf & _
"delete from [attach] where ([id_ticket] >= @mint) and ([id_ticket] <= @maxt)" & vbCrLf & _
"delete from [ticket] where ([id_ticket] >= @mint) and ([id_ticket] <= @maxt)"
Dim conn_string As String = "Driver={SQL Server};Server=" & Form1.srv & ";Trusted_Connection=Yes;Database=" & Form1.it_db & ";"
If CheckBox3.Checked Then
cmd = cmd1 & cmd3
Else
cmd = cmd1 & cmd2
End If
Dim delt As Integer = Form5.ExQuery(conn_string, cmd)
If delt > 0 Then
If CheckBox3.Checked Then
MsgBox("Удалено записей - " & CStr(delt / 3), MsgBoxStyle.Information, "Сообщение")
Else
MsgBox("Удалено записей - " & CStr(delt), MsgBoxStyle.Information, "Сообщение")
End If
Else
MsgBox("Нет данных для удаления", MsgBoxStyle.Information, "Сообщение")
End If
Else
MsgBox("Нулевой интервал. Измените дату", MsgBoxStyle.Information, "Сообщение")
End If
End Sub
Function GetDateString(ByVal dt As DateTime) As String
Dim sd, sm, sy, sh, sn, ss As String
Dim dn As Date = dt
If DateAndTime.Hour(dn) < 10 Then
sh = "0" + DateAndTime.Hour(dn).ToString
Else
sh = DateAndTime.Hour(dn).ToString
End If
If DateAndTime.Minute(dn) < 10 Then
sn = "0" + DateAndTime.Minute(dn).ToString
Else
sn = DateAndTime.Minute(dn).ToString
End If
If DateAndTime.Second(dn) < 10 Then
ss = "0" + DateAndTime.Second(dn).ToString
Else
ss = DateAndTime.Second(dn).ToString
End If
sy = DateAndTime.Year(dn).ToString
If DateAndTime.Month(dn) < 10 Then
sm = "0" + DateAndTime.Month(dn).ToString
Else
sm = DateAndTime.Month(dn).ToString
End If
If DateAndTime.Day(dn) < 10 Then
sd = "0" + DateAndTime.Day(dn).ToString
Else
sd = DateAndTime.Day(dn).ToString
End If
GetDateString = sy & sm & sd & " " & sh & ":" & sn & ":" & ss
End Function
End Class
Public Class Form7
Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CheckBox3.Text = "Физическое удаление" & vbCrLf & "записей"
End Sub
Private Sub Form7_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
Form5.Visible = True
Form5.Activate()
End Sub
Private Sub Form7_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
Form5.Visible = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cmd As String = ""
Dim cmd1 As String = _
"UPDATE ticket" & vbCrLf & _
"SET deleted = 1 where ([deleted] = 0)"
Dim cmd2 As String = _
"delete from [comments]" & vbCrLf & _
"delete from [attach]" & vbCrLf & _
"delete from [ticket]"
Dim conn_string As String = "Driver={SQL Server};Server=" & Form1.srv & ";Trusted_Connection=Yes;Database=" & Form1.it_db & ";"
If CheckBox3.Checked Then
cmd = cmd2
Else
cmd = cmd1
End If
Dim delt As Integer = Form5.ExQuery(conn_string, cmd)
If delt > 0 Then
If CheckBox3.Checked Then
MsgBox("Удалено записей - " & CStr(delt / 3), MsgBoxStyle.Information, "Сообщение")
Else
MsgBox("Удалено записей - " & CStr(delt), MsgBoxStyle.Information, "Сообщение")
End If
Me.Close()
Else
MsgBox("Нет данных для удаления", MsgBoxStyle.Information, "Сообщение")
End If
End Sub
End Class