-
Notifications
You must be signed in to change notification settings - Fork 0
/
Default.aspx.cs
137 lines (112 loc) · 3.5 KB
/
Default.aspx.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
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// Only for initial insert of the names in the database
/// </summary>
protected void InsertNamesIntoDatabase()
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
string line;
string name = "";
int number = 0;
StreamReader file = new StreamReader("C:\\Users\\Pesanski\\Documents\\Visual Studio 2010\\Projects\\RecordsCollectorApp\\RecordsCollectorApp\\data\\names_num.txt");
while ((line = file.ReadLine()) != null)
{
string[] pom = line.Split(' ');
name = pom[0];
number = Convert.ToInt32(pom[1]);
conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.InitialNamesInsert");
cmd.Parameters.AddWithValue("@Name", name.ToUpper());
cmd.Parameters.AddWithValue("@NumOfItems", number);
cmd.Parameters.AddWithValue("@Male", 0);
cmd.Parameters.AddWithValue("@Female", 0);
try
{
conn.Open();
int k = cmd.ExecuteNonQuery();
}
catch (Exception err)
{
string error = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
}
file.Close();
}
/// <summary>
/// Only for initial insert of the numbers in the database
/// </summary>
protected void InsertNumbersIntoDatabase()
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
string line;
string number = "";
StreamReader file = new StreamReader("C:\\Users\\Pesanski\\Documents\\Visual Studio 2010\\Projects\\RecordsCollectorApp\\RecordsCollectorApp\\data\\numbers.txt");
while ((line = file.ReadLine()) != null)
{
string[] pom = line.Split(' ');
number = pom[0];
conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.InitialNumbersInsert");
cmd.Parameters.AddWithValue("@Number", number);
cmd.Parameters.AddWithValue("@Male", 0);
cmd.Parameters.AddWithValue("@Female", 0);
try
{
conn.Open();
int k = cmd.ExecuteNonQuery();
}
catch (Exception err)
{
string error = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
}
file.Close();
}
protected DataSet GetAllNames()
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.SelectAllNames");
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
try
{
conn.Open();
da.Fill(ds, "NamesOrdered");
}
catch (Exception err)
{
string error = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
return ds;
}
}