-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddAuthor.aspx.cs
138 lines (131 loc) · 3.63 KB
/
AddAuthor.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
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class AddAuthor : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USER_TYPE"] == null)
{
Response.Redirect("Logout.aspx");
}
if (Page.IsPostBack == false)
{
ReadAuthor();
if (Session["USER_TYPE"].ToString() == "A")
{
Panel2.Visible = false;
}
else
{
Panel3.Visible = false;
}
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
lblEMsg.Visible = false;
string[] Auth;
try
{
string sql = "SELECT COUNT(*) FROM Author WHERE Author_NAME = '" + txtAName.Text + "' And Status = 'A'";
SqlDataReader sdr;
Profile pro = new Profile();
sdr = pro.ReturnMDetails(sql);
sdr.Read();
int RegNo = (int)sdr[0];
if (RegNo > 0)
{
lblEMsg.Text = "Author Name already exists.";
lblEMsg.Visible = true;
sdr.Close();
return;
}
else
{
Auth = new string[15];
Auth[0] = txtAuthor.Text;
Auth[1] = txtAName.Text;
Auth[2] = txtAdd.Text;
Auth[3] = txtPhone.Text;
Auth[4] = txtFax.Text;
Auth[5] = txtemail.Text;
if (chkStatus.Checked == true)
{
Auth[6] = "A";
}
else
{
Auth[7] = "I";
}
bool status;
status = pro.AddAuthor(Auth);
if (status == false)
{
lblEMsg.Visible = true;
lblEMsg.Text = "Author creation Failed";
}
lblEMsg.Visible = true;
lblEMsg.Text = "Author added.";
ReadAuthor();
txtAName.Text = "";
txtAdd.Text = "";
txtPhone.Text = "";
txtFax.Text = "";
txtemail.Text = "";
}
}
catch (Exception ex)
{
throw ex;
}
}
protected void btnClear_Click(object sender, EventArgs e)
{
txtAName.Text = "";
txtAdd.Text = "";
txtPhone.Text = "";
txtFax.Text = "";
txtemail.Text = "";
chkStatus.Checked = false;
lblEMsg.Visible = false;
}
private void ReadAuthor()
{
try
{
string sql = "SELECT COUNT(*) FROM Author";
SqlDataReader sdr;
Profile pro = new Profile();
sdr = pro.ReturnMDetails(sql);
sdr.Read();
int Auth = (int)sdr[0] + 1;
if (Auth < 10)
{
txtAuthor.Text = string.Format("A000{0}", Auth);
}
else if (Auth >= 10 && Auth < 100)
{
txtAuthor.Text = string.Format("S00{0}", Auth);
}
else
{
txtAuthor.Text = string.Format("S0{0}", Auth);
}
sdr.Close();
return;
}
catch (Exception ex)
{
throw ex;
}
}
}