using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Rice
{
public partial class SupplierInfo : Form
{
OleDbConnection con = new OleDbConnection("Provider=microsoft.jet.oledb.4.0;data source=E:\\Rice\\Rice.mdb");
public SupplierInfo()
{
InitializeComponent();
}
private void TextClear()
{
cbxSupplierid.Text = "Select";
txtAddress.Text = "";
txtBalamount.Text = "";
txtContactno.Text = "";
txtEmail.Text = "";
txtMobile.Text = "";
txtSname.Text = "";
}
private void Idgen()
{
int id = 0;
String str2 = "select MAX(Supid) from Supinfo";
OleDbCommand cmd2 = new OleDbCommand(str2, con);
con.Open();
OleDbDataReader dr2 = cmd2.ExecuteReader();
while (dr2.Read())
{
if (dr2.IsDBNull(0) == false)
{
id = dr2.GetInt32(0) + 1;
}
else
id = 1;
}
cbxSupplierid.Text = id.ToString();
cbxSupplierid.Focus();
dr2.Close();
con.Close();
}
private void Idshow()
{
cbxSupplierid.Items.Clear();
String st1 = "Select * from Supinfo order by Supid";
OleDbCommand cm = new OleDbCommand(st1, con);
con.Open();
OleDbDataReader dr = cm.ExecuteReader();
while (dr.Read())
{
if (dr.IsDBNull(0) == false)
{
cbxSupplierid.Items.Add(dr.GetValue(0).ToString());
}
}
dr.Close();
con.Close();
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
txtBalamount.Enabled = false;
TextClear();
cbxSupplierid.Focus();
Idgen();
}
private void OnlyNumberWithDot(object sender, KeyPressEventArgs e)
{
if (!(char.IsNumber(e.KeyChar)) && (e.KeyChar != 8) && (e.KeyChar != 46))
{
e.Handled = true;
}
}
private void OnlyNumber(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar)) && (e.KeyChar != 8))
{
e.Handled = true;
}
}
private void txtMobile_KeyPress(object sender, KeyPressEventArgs e)
{
OnlyNumber(sender, e);
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
if (cbxSupplierid.Text == "Select")
{
MessageBox.Show("Select The Supplier ID");
cbxSupplierid.Focus();
return;
}
else
{
String str = "Select * from Supinfo where Supid=" + cbxSupplierid.Text + "";
OleDbCommand cmd = new OleDbCommand(str, con);
con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.IsDBNull(0) == false)
{
txtSname.Text = dr.GetValue(1).ToString();
txtAddress.Text = dr.GetValue(2).ToString();
txtContactno.Text = dr.GetValue(3).ToString();
txtMobile.Text = dr.GetValue(4).ToString();
txtEmail.Text = dr.GetValue(5).ToString();
txtBalamount.Text = dr.GetValue(6).ToString();
}
}
dr.Close();
con.Close();
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
txtBalamount.Enabled = false;
String str1 = "Select * from Supinfo";
OleDbCommand cmd1 = new OleDbCommand(str1, con);
con.Open();
OleDbDataReader dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
if (dr1.IsDBNull(0) == false)
{
string sid = dr1.GetValue(0).ToString();
if (cbxSupplierid.Text == sid)
{
MessageBox.Show("This Number Already Exist");
cbxSupplierid.Focus();
con.Close();
goto l2;
}
}
}
con.Close();
if (cbxSupplierid.Text == "Select")
{
MessageBox.Show("Select The Supplier ID");
cbxSupplierid.Focus();
return;
}
if (txtSname.Text == "")
{
MessageBox.Show("Enter The Supplier Name");
txtSname.Focus();
return;
}
if (txtAddress.Text == "")
{
MessageBox.Show("Enter The Address");
txtAddress.Focus();
return;
}
if (txtContactno.Text == "")
{
MessageBox.Show("Enter The Contact Number");
txtContactno.Focus();
return;
}
if (txtMobile.Text == "")
{
MessageBox.Show("Enter The Mobile Number");
txtMobile.Focus();
return;
}
if (txtEmail.Text == "")
{
MessageBox.Show("Enter The Email Id");
txtEmail.Focus();
return;
}
//if (txtBalamount.Text == "")
//{
// MessageBox.Show("Enter The Balance Amount");
// txtBalamount.Focus();
// return;
//}
String str = "Insert into Supinfo(Supid,Supname,Address,Contactno,Mobile,Email)Values(" + cbxSupplierid.Text + ",'" + txtSname.Text + "','" + txtAddress.Text + "','" + txtContactno.Text + "','" + txtMobile.Text + "','" + txtEmail.Text + "')";
OleDbCommand cmd = new OleDbCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Details Saved");
TextClear();
Idshow();
l2:
dr1.Close();
}
private void updateToolStripMenuItem_Click(object sender, EventArgs e)
{
if (cbxSupplierid.Text == "Select")
{
MessageBox.Show("Select The Supplier ID");
cbxSupplierid.Focus();
return;
}
else
{
String str = "Update Supinfo SET Supname='" + txtSname.Text + "',Address='" + txtAddress.Text + "',Contactno='" + txtContactno.Text + "',Mobile='" + txtMobile.Text + "',Email='" + txtEmail.Text + "' where Supid=" + cbxSupplierid.Text + "";
OleDbCommand cmd = new OleDbCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Details Updated");
TextClear();
Idshow();
}
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (cbxSupplierid.Text == "Select")
{
MessageBox.Show("Select The Supplier ID");
cbxSupplierid.Focus();
return;
}
else
{
String str = "Delete * from Supinfo where Supid=" + cbxSupplierid.Text + "";
OleDbCommand cmd = new OleDbCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Details Deleted");
TextClear();
Idshow();
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void SupplierInfo_Load(object sender, EventArgs e)
{
cbxSupplierid.Text = "Select";
String str = "Select * from Supinfo";
OleDbCommand cmd = new OleDbCommand(str, con);
con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (dr.IsDBNull(0) == false)
{
cbxSupplierid.Items.Add(dr.GetValue(0).ToString());
}
}
dr.Close();
con.Close();
cbxSupplierid.Focus();
}
private void cbxSupplierid_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}