-
Notifications
You must be signed in to change notification settings - Fork 2
/
SifarnikU.aspx.cs
144 lines (137 loc) · 5.2 KB
/
SifarnikU.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
138
139
140
141
142
143
144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace ProbaSifarnika
{
public partial class SifarnikU : System.Web.UI.Page
{
DataTable podaci;
string tabela;
void osvezi()
{
tabela = Request.QueryString["tabela"];
SqlConnection conn = konekcija.Connect();
string naredba = "SELECT * FROM " + tabela;
SqlDataAdapter da = new SqlDataAdapter(naredba, konekcija.Connect());
podaci = new DataTable();
da.Fill(podaci);
Table1.Rows.Clear();
TableRow TR = new TableRow();
TableCell TD = new TableCell();
TD.Text = "== Rb ==";
TR.Cells.Add(TD);
TD = new TableCell();
TD.Text = "== Naziv ==";
TR.Cells.Add(TD);
Table1.Rows.Add(TR);
for (int red = 0; red < podaci.Rows.Count; red++)
{
TR = new TableRow();
for (int i = 0; i <= 1; i++)
{
TD = new TableCell();
TD.Text = podaci.Rows[red][i].ToString();
TR.Cells.Add(TD);
}
Table1.Rows.Add(TR);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["korisnik"].ToString() == "")
{
Response.Redirect("Login.aspx");
}
tabela = Request.QueryString["tabela"];
Label1.Text = tabela;
osvezi();
int tekuci = int.Parse(Session["tekuci"].ToString());
if (TextBox1.Text == "")
{
TextBox1.Text = podaci.Rows[tekuci][0].ToString();
TextBox2.Text = podaci.Rows[tekuci][1].ToString();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
int tekuci = int.Parse(Session["tekuci"].ToString());
if (tekuci<podaci.Rows.Count-1) tekuci++;
TextBox1.Text = podaci.Rows[tekuci][0].ToString();
TextBox2.Text = podaci.Rows[tekuci][1].ToString();
Session["tekuci"] = tekuci;
}
protected void Button1_Click(object sender, EventArgs e)
{
int tekuci = int.Parse(Session["tekuci"].ToString());
if (tekuci>0) tekuci--;
TextBox1.Text = podaci.Rows[tekuci][0].ToString();
TextBox2.Text = podaci.Rows[tekuci][1].ToString();
Session["tekuci"] = tekuci;
}
protected void Button2_Click(object sender, EventArgs e)
{
string ID_new = TextBox1.Text;
string naziv1 = TextBox2.Text;
// ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + naziv1 + "');", true);
SqlConnection conn = konekcija.Connect();
string naredba = "UPDATE " + tabela + " SET NAZIV='" + naziv1 + "' WHERE ID=" + ID_new;
SqlCommand comm = new SqlCommand(naredba, conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
osvezi();
}
protected void Button4_Click(object sender, EventArgs e)
{
if (TextBox2.Text.Equals(""))
{
Response.Write("Ne moze prazno!");
}
else
{
SqlConnection conn = konekcija.Connect();
SqlCommand komanda = new SqlCommand("SELECT * FROM " + tabela + " WHERE naziv='" + TextBox2.Text + "'", conn);
conn.Open();
SqlDataReader citac = komanda.ExecuteReader();
if (citac.Read())
{
Response.Write("Takav postoji!");
}
else
{
conn.Close();
SqlCommand komanda2 = new SqlCommand("INSERT INTO " + tabela + "(naziv) VALUES ('" + TextBox2.Text + "')", conn);
conn.Open();
int ubacio = komanda2.ExecuteNonQuery();
// Response.Write("Ubacio " + ubacio + " novih redova");
}
conn.Close();
}
osvezi();
int tekuci = podaci.Rows.Count - 1;
TextBox1.Text = podaci.Rows[tekuci][0].ToString();
TextBox2.Text = podaci.Rows[tekuci][1].ToString();
Session["tekuci"] = tekuci;
}
protected void Button5_Click(object sender, EventArgs e)
{
// Button BRISI
SqlConnection conn = konekcija.Connect();
SqlCommand komanda = new SqlCommand("DELETE FROM " + tabela + " WHERE ID='" + TextBox1.Text + "'", conn);
conn.Open();
komanda.ExecuteNonQuery();
conn.Close();
osvezi();
int tekuci = int.Parse(Session["tekuci"].ToString());
if (tekuci > podaci.Rows.Count-1) tekuci--;
TextBox1.Text = podaci.Rows[tekuci][0].ToString();
TextBox2.Text = podaci.Rows[tekuci][1].ToString();
Session["tekuci"] = tekuci;
}
}
}