-
Notifications
You must be signed in to change notification settings - Fork 0
/
deskTool.cs
155 lines (137 loc) · 5.83 KB
/
deskTool.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data;
namespace AutodeskAccess
{
class deskTool
{
private string DBFileName="";//write
string connectionString;
private OleDbConnection connection = new OleDbConnection();
private List<string> products = new List<string>();//product names
private SortedList<string, string> abreviations = new SortedList<string, string>();//product names
private string[] resultFiles = null;//read from
private string[] HTMLfile = null;
private string[] licFiles = null;
internal string selectDB()
{
try
{
OpenFileDialog choofdlog = new OpenFileDialog();
choofdlog.Filter = "All Files (*.*)|*.*";
choofdlog.FilterIndex = 1;
if (choofdlog.ShowDialog() == DialogResult.OK)
{
DBFileName = choofdlog.FileName;
connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;" +
@"Data Source=" + DBFileName + ";" +
@"Persist Security Info=False;";
Saveproducts();
}
return connectionString;
MessageBox.Show(connectionString);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return connectionString;
}
}//select db ends
internal void Saveproducts()
{
try
{
string PID = "SELECT PID FROM products";//
string ABR = "SELECT Abreviation, ProductName FROM Abr";//
connection = new OleDbConnection(connectionString);//db object
using (OleDbCommand command = new OleDbCommand(PID, connection))//array of products
{
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
products.Add(reader[0].ToString());
}
reader.Close();
connection.Close();
}//end using
using (OleDbCommand command = new OleDbCommand(ABR, connection))//array of abreviations
{
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
abreviations.Add(reader[0].ToString(), reader[1].ToString());
}
reader.Close();
connection.Close();
}//end using
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}//ends connection to DB and writes the list of search items.
internal string[] selectScript()
{
try
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.RootFolder = Environment.SpecialFolder.MyComputer;//This causes the folder to begin at the root folder or your documents
if (fbd.ShowDialog() == DialogResult.OK)
{
HTMLfile = Directory.GetFiles(fbd.SelectedPath, "*.html", SearchOption.AllDirectories);
resultFiles = Directory.GetFiles(fbd.SelectedPath, "*.txt", SearchOption.AllDirectories);//change this to specify file type
licFiles = Directory.GetFiles(fbd.SelectedPath, "*.LIC", SearchOption.AllDirectories);
MessageBox.Show("Files Found: " + resultFiles.Count<string>().ToString() + "\n" + "HTML Files Found: " + HTMLfile.Count<string>().ToString() + "\n" + "Lic Files Found: " + licFiles.Count<string>().ToString());
}
return resultFiles;
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
return null;
}
}//selection of script ends
internal void writeContents()// read all the text files to the Data base
{
try
{
MessageBox.Show(connectionString);
OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
connection.Open();
foreach (string x in resultFiles)//file path
{
string CPname = Path.GetFileNameWithoutExtension(x);//computer name
int c = 0;//line count
using (StreamReader sr = new StreamReader(x))
{
string s;//text line
while ((s = sr.ReadLine()) != null)
{
//this breaks the program
command.CommandText = "insert into Script (FileName, LineNumber, Contents) Values ('" + CPname + "','" + c.ToString() + "','" + s + "')";
command.ExecuteNonQuery();
s = sr.ReadLine();
c++;
}
}
}//ends loop over each file
connection.Close();
}//ends try
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}//ends method
}
}