-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddEmployee.cs
142 lines (122 loc) · 4.38 KB
/
addEmployee.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using Oracle.DataAccess.Client;
namespace WindowsFormsApplication3
{
public partial class addEmployee : UserControl
{
OracleConnection con;
public addEmployee()
{
InitializeComponent();
String connection = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) )); User Id=medicalstore; password=medicalstore";
con = new OracleConnection();
con.ConnectionString = connection;
}
private void bunifuButton1_Click(object sender, EventArgs e)
{
try
{
check();
con.Open();
String name = ename.Text.ToString();
String addr = eaddr.Text.ToString();
long contact1 = long.Parse(econtact.Text);
String user = euser.Text.ToString();
String pass = epass.Text.ToString();
//Insert UserInput row in Database
OracleCommand cmd = new OracleCommand();
cmd.CommandText = @"insert into admin values(admin_seq.nextval,'" + name + "','" + addr + "','" + contact1 + "','" + pass + "','" + user + "')";
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
MessageBox.Show("Record Inserted Succesfully");
clear();
// Fetch Row After Add Row button click
cmd.CommandText = "select * from admin";
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(dr);
metroGrid1.DataSource = dataTable;
}
catch (Exception ea)
{
MessageBox.Show(ea.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.Write(ea);
}
finally
{
con.Close();
}
}
public void check()
{
if (ename.Text == "")
{
MessageBox.Show("Employee Name Is Empty");
}
if (eaddr.Text == "")
{
MessageBox.Show("Address Is Empty");
}
if (econtact.Text == "")
{
MessageBox.Show("Contact Is Empty");
}
if (euser.Text == "")
{
MessageBox.Show("Username Is Empty");
}
if (epass.Text == "")
{
MessageBox.Show("Password Is Empty");
}
}
public void clear()
{
ename.Text = "";
eaddr.Text = "";
econtact.Text = "";
euser.Text = "";
epass.Text = "";
}
private void clearTextButton_Click(object sender, EventArgs e)
{
clear();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void addEmployee_Load(object sender, EventArgs e)
{
try
{ // Datagridview with table
String connection = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) )); User Id=medicalstore; password=medicalstore";
OracleConnection con = new OracleConnection();
con.ConnectionString = connection;
con.Open();
OracleCommand cmd = new OracleCommand();
cmd.CommandText = "select * from admin";
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(dr);
metroGrid1.DataSource = dataTable;
}
catch (Exception ae)
{
}
}
}
}