customer.cs
public partial class Customer : Form
{
public Customer()
{
InitializeComponent();
}
Dbconn1 obj = new Dbconn1();
private void btnins_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string Name = txtname.Text;
string CellNum = txtcell.Text;
string Address = txtadd.Text;
string query = "INSERT INTO Customer VALUES('" + ID + "','" + Name + "','" + CellNum + "','" + Address + "')";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Inserted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Inserted");
}
}
private void btnupdae_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string Name = txtname.Text;
string CellNum = txtcell.Text;
string Address = txtadd.Text;
string query = "Update Customer set Name='" + Name + "',Cell='" + CellNum + "',Address='" + Address + "' where ID='" + ID + "';";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Updated Successfully");
}
else
{
MessageBox.Show(this, "Record Not Updated ");
}
}
private void btndlt_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string query = "Delete from Customer where ID='" + ID + "'";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Deleted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Deleted ");
}
}
private void btnsearch_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string query = "Select * from Customer where ID='" + ID + "'";
SqlDataReader b = obj.Search(query);
{
if (b.Read())
{
txtname.Text = (b["Name"].ToString());
txtcell.Text = (b["Cell"].ToString());
txtadd.Text = (b["Address"].ToString());
MessageBox.Show(this, "Record found ");
}
else
{
MessageBox.Show(this, "Record Not found ");
}
}
}
Form.cs
private void btnlogin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("Select Count(*) From LoginDetails where Name='"+txtname.Text+"' and Password='"+txtpass.Text+"'",conn);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
Mainwindow s = new Mainwindow();
s.Show();
}
else
{
MessageBox.Show("Alret! Username or password incorrect");
}
}
private void btnexit_Click(object sender, EventArgs e)
{
this.Close();
}
}
Main.cs
private void Main_Load(object sender, EventArgs e)
{
}
Dbconn1 obj = new Dbconn1();
private void btninsert_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string CellNum = txtcell.Text;
string Address = txtadd.Text;
string query = "INSERT INTO Emp VALUES('" + Code + "','" + Name + "','" + CellNum + "','" + Address + "')";
bool b = obj.UDI(query);
if(b=true)
{
MessageBox.Show(this, "Record Inserted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Inserted");
}
}
private void btndlt_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string query = "Delete from Emp where Code='" + Code + "'";
bool b = obj.UDI(query);
if(b=true)
{
MessageBox.Show(this, "Record Deleted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Deleted ");
}
}
private void btnudate_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string CellNum = txtcell.Text;
string Address = txtadd.Text;
string query = "Update Emp set Name='" + Name + "',Cell='" + CellNum + "',Address='" + Address + "' where Code='" + Code + "';";
bool b = obj.UDI(query);
if(b=true)
{
MessageBox.Show(this, "Record Updated Successfully");
}
else
{
MessageBox.Show(this, "Record Not Updated ");
}
}
private void btnsearch_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string query = "Select * from Emp where Code='" + Code + "'";
SqlDataReader b = obj.Search(query);
if(b.Read())
{
txtname.Text = (b["Name"].ToString());
txtcell.Text = (b["Cell"].ToString());
txtadd.Text = (b["Address"].ToString());
}
else
{
MessageBox.Show("Record Not found");
}
}
private void btnviewall_Click(object sender, EventArgs e)
{
dataGridView1.Visible = true;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Select * from Emp";
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Emprec");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Emprec";
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void INS_Sp_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.SP_empInsert", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Code", txtcode.Text));
cmd.Parameters.Add(new SqlParameter("@Name", txtname.Text));
cmd.Parameters.Add(new SqlParameter("@Cell", txtcell.Text));
cmd.Parameters.Add(new SqlParameter("@Address", txtadd.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Inserted");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
}
Mainwindow.cs
private void button1_Click(object sender, EventArgs e)
{
Main obj = new Main();
obj.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Customer obj = new Customer();
obj.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Product obj = new Product();
obj.Show();
}
}
Product.cs
private void label4_Click(object sender, EventArgs e)
{
}
Dbconn1 obj = new Dbconn1();
private void btnins_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string Name = txtname.Text;
string Price = txtprice.Text;
string date = txtdate.Text;
string query = "INSERT INTO Product VALUES('" + ID + "','" + Name + "','" + Price + "','" + date + "')";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Inserted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Inserted");
}
}
private void btndlt_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Do you really delete?", "Delete",
MessageBoxButtons.OKCancel);
if (result == 0)
{
string ID = txtid.Text;
string query = "Delete from Product where Pid='" + ID + "'";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Deleted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Deleted ");
}
}
}
private void btnupdate_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string Name = txtname.Text;
string Price = txtprice.Text;
string date = txtdate.Text;
string query = "Update Product set Pname='" + Name + "',Pprice='" + Price + "',Pdate='" + date + "' where Pid='" + ID + "';";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Updated Successfully");
}
else
{
MessageBox.Show(this, "Record Not Updated ");
}
}
private void btnsearch_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string query = "Select * from Product where Pid='" + ID + "'";
try
{
SqlDataReader read = obj.Search(query);
while (read.Read())
{
txtname.Text = (read["Pname"].ToString());
txtprice.Text = (read["Pprice"].ToString());
txtdate.Text = (read["Pdate"].ToString());
}
}
catch (SqlException ex)
{
MessageBox.Show(this, "Exception:" + ex.Message);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Product_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Select Pid from Product ";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader read = cmd.ExecuteReader();
while (read.Read())
{
comboBox1.Items.Add(read["Pid"].ToString());
}
}
catch (SqlException ex)
{
MessageBox.Show(this, "Exception:" + ex.Message);
}
finally
{
conn.Close();
}
} }
Program.cs
namespace officemgs
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
public partial class Customer : Form
{
public Customer()
{
InitializeComponent();
}
Dbconn1 obj = new Dbconn1();
private void btnins_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string Name = txtname.Text;
string CellNum = txtcell.Text;
string Address = txtadd.Text;
string query = "INSERT INTO Customer VALUES('" + ID + "','" + Name + "','" + CellNum + "','" + Address + "')";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Inserted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Inserted");
}
}
private void btnupdae_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string Name = txtname.Text;
string CellNum = txtcell.Text;
string Address = txtadd.Text;
string query = "Update Customer set Name='" + Name + "',Cell='" + CellNum + "',Address='" + Address + "' where ID='" + ID + "';";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Updated Successfully");
}
else
{
MessageBox.Show(this, "Record Not Updated ");
}
}
private void btndlt_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string query = "Delete from Customer where ID='" + ID + "'";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Deleted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Deleted ");
}
}
private void btnsearch_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string query = "Select * from Customer where ID='" + ID + "'";
SqlDataReader b = obj.Search(query);
{
if (b.Read())
{
txtname.Text = (b["Name"].ToString());
txtcell.Text = (b["Cell"].ToString());
txtadd.Text = (b["Address"].ToString());
MessageBox.Show(this, "Record found ");
}
else
{
MessageBox.Show(this, "Record Not found ");
}
}
}
Form.cs
private void btnlogin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("Select Count(*) From LoginDetails where Name='"+txtname.Text+"' and Password='"+txtpass.Text+"'",conn);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
Mainwindow s = new Mainwindow();
s.Show();
}
else
{
MessageBox.Show("Alret! Username or password incorrect");
}
}
private void btnexit_Click(object sender, EventArgs e)
{
this.Close();
}
}
Main.cs
private void Main_Load(object sender, EventArgs e)
{
}
Dbconn1 obj = new Dbconn1();
private void btninsert_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string CellNum = txtcell.Text;
string Address = txtadd.Text;
string query = "INSERT INTO Emp VALUES('" + Code + "','" + Name + "','" + CellNum + "','" + Address + "')";
bool b = obj.UDI(query);
if(b=true)
{
MessageBox.Show(this, "Record Inserted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Inserted");
}
}
private void btndlt_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string query = "Delete from Emp where Code='" + Code + "'";
bool b = obj.UDI(query);
if(b=true)
{
MessageBox.Show(this, "Record Deleted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Deleted ");
}
}
private void btnudate_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string Name = txtname.Text;
string CellNum = txtcell.Text;
string Address = txtadd.Text;
string query = "Update Emp set Name='" + Name + "',Cell='" + CellNum + "',Address='" + Address + "' where Code='" + Code + "';";
bool b = obj.UDI(query);
if(b=true)
{
MessageBox.Show(this, "Record Updated Successfully");
}
else
{
MessageBox.Show(this, "Record Not Updated ");
}
}
private void btnsearch_Click(object sender, EventArgs e)
{
string Code = txtcode.Text;
string query = "Select * from Emp where Code='" + Code + "'";
SqlDataReader b = obj.Search(query);
if(b.Read())
{
txtname.Text = (b["Name"].ToString());
txtcell.Text = (b["Cell"].ToString());
txtadd.Text = (b["Address"].ToString());
}
else
{
MessageBox.Show("Record Not found");
}
}
private void btnviewall_Click(object sender, EventArgs e)
{
dataGridView1.Visible = true;
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Select * from Emp";
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Emprec");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Emprec";
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
private void INS_Sp_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("dbo.SP_empInsert", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Code", txtcode.Text));
cmd.Parameters.Add(new SqlParameter("@Name", txtname.Text));
cmd.Parameters.Add(new SqlParameter("@Cell", txtcell.Text));
cmd.Parameters.Add(new SqlParameter("@Address", txtadd.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Inserted");
}
catch (SqlException ex)
{
MessageBox.Show("Exception:" + ex.Message);
}
finally
{
conn.Close();
}
}
}
Mainwindow.cs
private void button1_Click(object sender, EventArgs e)
{
Main obj = new Main();
obj.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Customer obj = new Customer();
obj.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Product obj = new Product();
obj.Show();
}
}
Product.cs
private void label4_Click(object sender, EventArgs e)
{
}
Dbconn1 obj = new Dbconn1();
private void btnins_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string Name = txtname.Text;
string Price = txtprice.Text;
string date = txtdate.Text;
string query = "INSERT INTO Product VALUES('" + ID + "','" + Name + "','" + Price + "','" + date + "')";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Inserted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Inserted");
}
}
private void btndlt_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Do you really delete?", "Delete",
MessageBoxButtons.OKCancel);
if (result == 0)
{
string ID = txtid.Text;
string query = "Delete from Product where Pid='" + ID + "'";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Deleted Successfully");
}
else
{
MessageBox.Show(this, "Record Not Deleted ");
}
}
}
private void btnupdate_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string Name = txtname.Text;
string Price = txtprice.Text;
string date = txtdate.Text;
string query = "Update Product set Pname='" + Name + "',Pprice='" + Price + "',Pdate='" + date + "' where Pid='" + ID + "';";
bool b = obj.UDI(query);
if (b = true)
{
MessageBox.Show(this, "Record Updated Successfully");
}
else
{
MessageBox.Show(this, "Record Not Updated ");
}
}
private void btnsearch_Click(object sender, EventArgs e)
{
string ID = txtid.Text;
string query = "Select * from Product where Pid='" + ID + "'";
try
{
SqlDataReader read = obj.Search(query);
while (read.Read())
{
txtname.Text = (read["Pname"].ToString());
txtprice.Text = (read["Pprice"].ToString());
txtdate.Text = (read["Pdate"].ToString());
}
}
catch (SqlException ex)
{
MessageBox.Show(this, "Exception:" + ex.Message);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Product_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=GUL\AHMAD;Initial Catalog=ahmad;Integrated Security=True");
string query = "Select Pid from Product ";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader read = cmd.ExecuteReader();
while (read.Read())
{
comboBox1.Items.Add(read["Pid"].ToString());
}
}
catch (SqlException ex)
{
MessageBox.Show(this, "Exception:" + ex.Message);
}
finally
{
conn.Close();
}
} }
Program.cs
namespace officemgs
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
0 comments:
Post a Comment