-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAddition.aspx.cs
More file actions
78 lines (65 loc) · 3.58 KB
/
Copy pathAddition.aspx.cs
File metadata and controls
78 lines (65 loc) · 3.58 KB
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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ConsumablesPortal
{
public partial class Addition : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
SqlCommand cmd;
SqlDataAdapter da;
DataTable dt;
SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
}
// FOR ADDITION
protected void Button1_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into item values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')",con);
cmd.ExecuteNonQuery();
SqlCommand cmd2 = new SqlCommand("INSERT INTO users (EID, item_name, item_make, item_model, process, edit_qty, edit_date, loc, cause, remain_qty) VALUES (@EID, @item_name, @item_make, @item_model, @process, @edit_qty, @edit_date, @loc, @cause, @remain_qty)", con);
cmd2.Parameters.AddWithValue("@EID", DBNull.Value); //NULL value
cmd2.Parameters.AddWithValue("@item_name", TextBox1.Text);
cmd2.Parameters.AddWithValue("@item_make", TextBox2.Text);
cmd2.Parameters.AddWithValue("@item_model", TextBox3.Text);
cmd2.Parameters.AddWithValue("@process", "Add"); // Specific value for process
cmd2.Parameters.AddWithValue("@edit_qty", TextBox4.Text);
cmd2.Parameters.AddWithValue("@edit_date", DateTime.Now); // Current date
cmd2.Parameters.AddWithValue("@loc", DBNull.Value); // NULL value
cmd2.Parameters.AddWithValue("@cause", DBNull.Value); // NULL value
cmd2.Parameters.AddWithValue("@remain_qty", TextBox4.Text);
cmd2.ExecuteNonQuery();
SqlCommand cmd3 = new SqlCommand("INSERT INTO date_qty (item_name, item_make, item_model, today_date, today_qty) VALUES (@item_name, @item_make, @item_model, @today_date, @today_qty)", con);
cmd3.Parameters.AddWithValue("@item_name", TextBox1.Text);
cmd3.Parameters.AddWithValue("@item_make", TextBox2.Text);
cmd3.Parameters.AddWithValue("@item_model", TextBox3.Text);
cmd3.Parameters.AddWithValue("@today_date", DateTime.Now); // Current date
cmd3.Parameters.AddWithValue("@today_qty",TextBox4.Text);
cmd3.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ScriptKey", "alert('Item Added');window.location='home.aspx'; ", true);
}
catch(Exception Ex)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ScriptKey", "alert('Cannot add the same product repeatedly. Please update it');window.location='home.aspx'; ", true);
//Console.WriteLine("An error occurred: " + Ex.Message);
//Console.WriteLine("Cannot add the same product repeatedly. Please update it"); //Not Working or showing message
}
}
// FOR RESET
protected void Button3_Click(object sender, EventArgs e)
{
TextBox1.Text = TextBox2.Text = TextBox3.Text = TextBox4.Text = "";
}
}
}