-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoice.aspx.cs
188 lines (147 loc) · 6.65 KB
/
invoice.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
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace authwebpart
{
public partial class invoice : System.Web.UI.Page
{
public static string cons = WebConfigurationManager.ConnectionStrings["v0scon"].ConnectionString;
SqlConnection myConnection = new SqlConnection(cons);
public double gtotal = 0.0;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["suser"] == null)
{
Response.Redirect("login.aspx");
}
if (!IsPostBack)
{
using (myConnection)
{
myConnection.Open();
string que = "SELECT IDENT_CURRENT('invoice_customer')+1; ";
SqlCommand ccmd = new SqlCommand(que, myConnection);
object totals = ccmd.ExecuteScalar();
int ncid = Convert.ToInt32(totals);
TextBox5.Text = ncid + "";
}
}
}
protected void Button1_Click(object sender, EventArgs e)//add to list of bill
{
using (myConnection)
{
string query = "insert into dinvoice(invoice_id,product_name,quantity, rate)";
query += "values(@invoice_id,@product_name,@quantity, @rate)";
myConnection.Open();
SqlCommand cmd = new SqlCommand(query, myConnection);
cmd.Parameters.AddWithValue("@invoice_id", Int32.Parse(TextBox5.Text));
cmd.Parameters.AddWithValue("@product_name", TextBox1.Text);
cmd.Parameters.AddWithValue("@quantity", Int32.Parse(TextBox2.Text));
cmd.Parameters.AddWithValue("@rate", Int32.Parse(TextBox3.Text));
cmd.ExecuteNonQuery();
GridView1.DataBind();
}
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
protected void TextBox6_TextChanged(object sender, EventArgs e)//retrive customer info
{
using (myConnection)
{
myConnection.Open();
string que = "SELECT * from customer where c_id=@c_id ";
SqlCommand ccmd = new SqlCommand(que, myConnection);
if (TextBox6.Text != "" && TextBox6.Text != null)
{
ccmd.Parameters.AddWithValue("@c_id", Int32.Parse(TextBox6.Text));
SqlDataReader rdr = ccmd.ExecuteReader();
if (rdr.HasRows)
{
rdr.Read();
TextBox7.Text = rdr["c_fname"].ToString() + " " + rdr["c_mname"].ToString() + " " + rdr["c_lname"].ToString();
TextBox9.Text = rdr["city"].ToString();
TextBox8.Text = rdr["address"].ToString();
TextBox10.Text = rdr["mobile_no"].ToString();
}
}
else
{
TextBox7.Text = "";
TextBox9.Text = "";
TextBox8.Text = "";
TextBox10.Text = "";
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)//bill item table
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
double dt = Double.Parse((e.Row.DataItem as DataRowView).Row["quantity"].ToString()) * Double.Parse((e.Row.DataItem as DataRowView).Row["rate"].ToString());
e.Row.Cells[6].Text = dt.ToString();
gtotal = gtotal + dt;
TextBox4.Text = "";
Label4.Text = gtotal.ToString();
Label5.Text = "" + 0;
Label6.Text = Label4.Text;
}
}
protected void TextBox4_TextChanged(object sender, EventArgs e)//calculate bill amounts
{
Response.Write(TextBox4.Text);
if (TextBox4.Text == "")
{
Label6.Text = Label4.Text;
}
else
{
double ptot = Double.Parse(Label4.Text) * (Double.Parse(TextBox4.Text) / 100);
Label5.Text = ptot.ToString();
double tp = Double.Parse(Label4.Text) + Double.Parse(Label5.Text);
Label6.Text = tp.ToString();
}
}
protected void TextBox11_TextChanged(object sender, EventArgs e)//calculate bill amounts
{
}
protected void Button3_Click(object sender, EventArgs e)
{
using (myConnection)
{
myConnection.Open();
string que = "insert into invoice_customer (c_id,c_name,address,city,mobile_no,date) ";
que += "values(@c_id,@c_name,@address,@city,@mobile_no,@date)";
SqlCommand ccmd = new SqlCommand(que, myConnection);
if (TextBox6.Text != "" && TextBox6.Text != null)
ccmd.Parameters.AddWithValue("@c_id", Int32.Parse(TextBox6.Text));
//ccmd.Parameters.AddWithValue("@date",);
ccmd.Parameters.AddWithValue("@c_name", TextBox7.Text);
if(TextBox8.Text!="")
ccmd.Parameters.AddWithValue("@address", TextBox8.Text);
else
ccmd.Parameters.AddWithValue("@address", "none");
ccmd.Parameters.AddWithValue("@city", TextBox9.Text);
ccmd.Parameters.AddWithValue("@mobile_no", Decimal.Parse(TextBox10.Text));
ccmd.Parameters.AddWithValue("@date", DateTime.Parse(billDate.Text));
ccmd.ExecuteNonQuery();
Response.Write("updated detail");
string insq = "INSERT INTO invoice (invoice_id,product_name,quantity,rate) SELECT invoice_id,product_name,quantity,rate FROM dinvoice ";
SqlCommand copcmd = new SqlCommand(insq, myConnection);
copcmd.ExecuteNonQuery();
string dropquery = "TRUNCATE TABLE dinvoice ";
SqlCommand drcmd = new SqlCommand(dropquery, myConnection);
drcmd.ExecuteNonQuery();
}
Label7.Text = "data is saved-take your print";
Label7.Visible = true;
}
}
}