-
Notifications
You must be signed in to change notification settings - Fork 0
/
New Challan.aspx.cs
213 lines (175 loc) · 6.64 KB
/
New Challan.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Data.SqlClient;
public partial class challan_type : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitForNew();
}
}
protected void btnNew_Click(object sender, EventArgs e)
{
InitForNew();
lblMsg.Text = "";
}
void InitForNew()
{
lblHead.Text = "New Challan Type";
btnSave.Text = "Add";
txtID.Text = "";
txtChallan.Text = "";
txtFine.Text = "0.00";
txtDescription.Text = "";
txtRemarks.Text = "";
btnCalcel.Enabled = false;
FillList();
ddlChallan.Items.Insert(0, "----Select----");
txtChallan.Focus();
}
protected void btnSave_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["eChallanConnectionString2"].ToString());
try
{
con.Open();
string sp;
if(btnSave.Text == "Add") sp = "AddChallanType";
else sp = "UpdateChallan";
SqlCommand cmd = new SqlCommand(sp, con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("@Name", System.Data.SqlDbType.VarChar, 250).Value = txtChallan.Text;
cmd.Parameters.Add("@Fine", System.Data.SqlDbType.VarChar, 50).Value = txtFine.Text;
cmd.Parameters.Add("@Description", System.Data.SqlDbType.VarChar, 50).Value = txtDescription.Text;
cmd.Parameters.Add("@Remarks", System.Data.SqlDbType.VarChar, 50).Value = txtRemarks.Text;
if(btnSave.Text == "Update") cmd.Parameters.Add("@ChallanTypeID", System.Data.SqlDbType.Int).Value = txtID.Text;
SqlParameter prm;
prm = cmd.Parameters.Add("@ErrorMsg", System.Data.SqlDbType.VarChar, 250);
prm.Direction = System.Data.ParameterDirection.InputOutput;
cmd.ExecuteNonQuery();
string err;
err = (string)cmd.Parameters["@ErrorMsg"].Value;
if(err.Length == 0)
{
lblMsg.Text = (btnSave.Text == "Add") ? "Added Successfully!" : "Updated Successfully!";
lblMsg.ForeColor = Color.Green;
InitForNew();
}
else
{
lblMsg.Text = err;
lblMsg.ForeColor = Color.Red;
}
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
finally
{
if(con.State == System.Data.ConnectionState.Open) con.Close();
}
}
void FillList()
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["eChallanConnectionString2"].ToString());
try
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT ChallanTypeID, Name, STR(Fine, 10, 2) [Fine], Description, Remarks FROM ChallanTypes ORDER BY Name", con);
cmd.CommandType = System.Data.CommandType.Text;
SqlDataReader dr;
dr = cmd.ExecuteReader();
ddlChallan.DataSource = dr;
ddlChallan.DataBind();
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
finally
{
if (con.State == System.Data.ConnectionState.Open) con.Close();
}
}
protected void ddlChallan_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["eChallanConnectionString2"].ToString());
try
{
con.Open();
string sql;
sql = string.Format("SELECT ChallanTypeID, Name, Fine, Description, Remarks FROM ChallanTypes WHERE ChallanTypeID={0}", ddlChallan.SelectedValue);
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = System.Data.CommandType.Text;
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
txtID.Text = dr["ChallanTypeID"].ToString();
txtChallan.Text = dr["Name"].ToString();
txtFine.Text = string.Format("{0:0.00}", dr["Fine"]);
txtDescription.Text = dr["Description"].ToString();
txtRemarks.Text = dr["Remarks"].ToString();
txtChallan.Focus();
}
dr.Close();
// Form settings
lblHead.Text = "Update Challan Type";
lblMsg.Text = "";
btnSave.Text = "Update";
btnCalcel.Enabled = true;
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
finally
{
if (con.State == System.Data.ConnectionState.Open) con.Close();
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["eChallanConnectionString2"].ToString());
try
{
con.Open();
SqlCommand cmd = new SqlCommand("DeleteChallanType", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("ChallanTypeID", System.Data.SqlDbType.Int).Value = txtID.Text;
SqlParameter prm;
prm = cmd.Parameters.Add("@ErrorMsg", System.Data.SqlDbType.VarChar, 250);
prm.Direction = System.Data.ParameterDirection.InputOutput;
cmd.ExecuteNonQuery();
string err;
err = (string)cmd.Parameters["@ErrorMsg"].Value;
if (err.Length == 0)
{
lblMsg.Text = "Deleted successfully!";
lblMsg.ForeColor = Color.Green;
InitForNew();
}
else
{
lblMsg.Text = err;
lblMsg.ForeColor = Color.Red;
}
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
finally
{
if (con.State == System.Data.ConnectionState.Open) con.Close();
}
}
}