private void srchdgview_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
try
{
string constring = "Data Source=ASHOK-PC\\SQLEXPRESS;Initial Catalog=hotel_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string cmdstring = "select Registration_Id,Name,Address,City,Mobile_no,email,Passport,reference,birth_date,arrival_date,checkout_date,booking_datetime,room_category,room_terrife,room_no,ad_payment,payment_date,remarks,recipt_no,reminder from booking where Registration_Id = '" + (srchdgview.CurrentRow.Cells[0].Value.ToString()) + " ' ";
SqlCommand cmd = new SqlCommand(cmdstring, con);
SqlDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
Booking bk = new Booking();
bk.Show();
bk.datetimedob.Format = DateTimePickerFormat.Custom;
bk.txtreg.Text = Convert.ToString(dr["Registration_Id"]);
bk.txtname.Text = Convert.ToString(dr["Name"]);
bk.txtcity.Text = dr["City"].ToString();
bk.txtadd.Text = dr["Address"].ToString();
bk.txtmobile.Text = dr["Mobile_no"].ToString();
bk.txtemail.Text = dr["email"].ToString();
bk.txtpassport.Text = dr["Passport"].ToString();
bk.txtbirth.Text = dr["birth_date"].ToString();
bk.arrivaldatetime.Text = dr["arrival_date"].ToString();
if (dr["Category"].ToString() == "Gen")
frm.radbtngen.Checked = true;
else
frm.radbtnobc.Checked = true;
frm .button1 .Text ="Update";
bk.paymentdatetime.Text = dr["payment_date"].ToString();
bk.savebutton.Text = "Update";
bk.deletebutton.Enabled = true;
bk.txtname.Enabled = false;
if (srchdgview.RowsDefaultCellStyle.BackColor == Color.Red)
{
bk.BackColor = Color.Red;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void srchreg_TextChanged(object sender, EventArgs e)
{
validation valids = new validation();
valids.numwithdecitxtBox_TxtChng(srchreg, sender, e);
}
---------------------------------------------------------
Cell Formet
private void srchdgview_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
for (int i = 0; i <= srchdgview.Rows.Count - 1; i++)
{
DataGridViewRow dvr = srchdgview.Rows[e.RowIndex];
string strStatus = dvr.Cells["STATUS"].Value.ToString();
DateTime dt1 = new DateTime();
dt1 =Convert.ToDateTime( dvr.Cells["ARRIVAL DATE"].Value.ToString());
DateTime dt3 = new DateTime();
dt3 = Convert.ToDateTime(DateTime.Now.ToShortDateString());
if (strStatus == " Checked " || strStatus == "Checked " || strStatus == " Checked" || strStatus == "Checked")
{
dvr.DefaultCellStyle.BackColor = Color.Red;
}
else if ((strStatus == " Unchecked " || strStatus == "Unchecked ") && dt1 > dt3)
{
dvr.DefaultCellStyle.BackColor = Color.Orange;
}
else
{
dvr.DefaultCellStyle.BackColor = Color.Green;
}
}
}
--------------------------------------------------------------------------------------------------------
Page Ref.
frm = new Form1();
frm.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form3_Load);
frm.Show();
----------------------------------------------------------------------------------------------------
C# Save, Update ,Deleted
public partial class Item_Master : Form
{
Dbclass db = new Dbclass();
string common;
public Item_Master()
{
InitializeComponent();
}
private void btnrecord_Click(object sender, EventArgs e)
{
RecordItemMaster rtm = new RecordItemMaster();
rtm.Show();
}
private void btnfind_Click(object sender, EventArgs e)
{
}
private void btnsave_Click(object sender, EventArgs e)
{
if (txtitem_name.Text == "")
{
MessageBox.Show("Error 9001303991 : Fill Up The Item Name", "Blank.............", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
if (btnsave.Text == "Save")
{
string str = "Itemmaster_sp'S','','" +cmbf_category.SelectedValue + "','" + txtitem_name.Text + "','" + txtitem_rs.Text + "','" +cmbunit_type.SelectedValue + "'";
db.inserfun(str);
MessageBox.Show("Successfully Saved", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
cmbf_category.Text = "";
txtitem_name.Text = "";
txtitem_rs.Text = "";
cmbunit_type.Text = "";
cmbf_category.Focus();
}
else if (btnsave.Text == "Update")
{
string upt = "ItemMaster_sp'U','" +txtunq_id.ToString () + "','" + cmbf_category.Text + "','" + txtitem_name.Text + "','" + txtitem_rs.Text + "','" + cmbunit_type.Text + "'";
db.Updatefun(upt);
MessageBox.Show("Successfully Update ", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
btnfind.Text = "Find";
btnsave.Text = "Save";
cmbf_category.Text = "";
txtitem_name.Text = "";
txtitem_rs.Text = "";
cmbunit_type.Text = "";
cmbf_category.Focus();
}
}
private void Item_Master_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F5)
{
btnsave_Click(sender, e);
}
else if (e.KeyCode == Keys.F2)
{
btnfind_Click(sender, e);
}
else if (e.KeyCode == Keys.F10)
{
btnrecord_Click(sender, e);
}
}
private void Item_Master_Load(object sender, EventArgs e)
{
string str = "Select * from category_master";
string str1 = "select * from unit";
db.Fillcombo(cmbf_category, "category_name", "unq_id", str);
db.Fillcombo(cmbunit_type, "unitname", "unqid", str1);
DataTable dtt = new DataTable();
string grd = "select unq_id, category_name[CATEGORY NAME],item_name [ITEM NAME],item_rs[ITEM RS],unit_type[UNIT TYPE] from item_master";
dtt = db.FindFun(grd);
Grditem_name.DataSource = dtt;
//cmbf_category.Text = ComboBox.v
//txtitem_name.Text = ComboBox;
//txtitem_rs.Text = textBox1;
//cmbunit_type.Text = textBox1;
}
int GridEvent;
private void FillTextBox()
{
if (GridEvent < 0)
{
return;
}
else if (GridEvent > Grditem_name.Rows.Count - 1)
{
return;
}
else
{
txtunq_id.Text = Grditem_name.Rows[GridEvent].Cells[0].Value.ToString();
cmbf_category.Text = Grditem_name.Rows[GridEvent].Cells[1].Value.ToString();
txtitem_name.Text = Grditem_name.Rows[GridEvent].Cells[2].Value.ToString();
txtitem_rs.Text = Grditem_name.Rows[GridEvent].Cells[3].Value.ToString();
cmbunit_type.Text = Grditem_name.Rows[GridEvent].Cells[4].Value.ToString();
cmbf_category.Focus();
btnfind.Text = "Delete";
btnsave.Text = "Update";
}
}
private void btnfind_Click_1(object sender, EventArgs e)
{
if (txtitem_name.Text == "")
{
MessageBox.Show("Error 9001303991 :Fill Up The Item Name", "Blank.............", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
if (btnfind.Text == "Find")
{
tabControl1.SelectedTab = tabPage2;
}
else if (btnfind.Text == "Delete")
{
string del = "ItemMaster_sp 'D','" + txtunq_id.Text.ToString() + "'";
db.Deletefun(del);
MessageBox.Show("Successfull Delete", "Delete............", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
cmbf_category.Text = "";
txtitem_name.Text = "";
txtitem_rs.Text = "";
cmbunit_type.Text = "";
cmbf_category.Focus();
btnfind.Text = "Find";
btnsave.Text = "Save";
}
}
private void Grditem_name_CellDoubleClick_1(object sender, DataGridViewCellEventArgs e)
{
GridEvent = e.RowIndex;
FillTextBox();
}
private void Grditem_name_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
FillTextBox();
}
}
private void Grditem_name_CellEnter(object sender, DataGridViewCellEventArgs e)
{
GridEvent = e.RowIndex;
}
private void btnsave_Click_1(object sender, EventArgs e)
{
}
private void Grditem_name_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
{
try
{
string constring = "Data Source=ASHOK-PC\\SQLEXPRESS;Initial Catalog=hotel_db;Integrated Security=True";
SqlConnection con = new SqlConnection(constring);
string cmdstring = "select Registration_Id,Name,Address,City,Mobile_no,email,Passport,reference,birth_date,arrival_date,checkout_date,booking_datetime,room_category,room_terrife,room_no,ad_payment,payment_date,remarks,recipt_no,reminder from booking where Registration_Id = '" + (srchdgview.CurrentRow.Cells[0].Value.ToString()) + " ' ";
SqlCommand cmd = new SqlCommand(cmdstring, con);
SqlDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
Booking bk = new Booking();
bk.Show();
bk.datetimedob.Format = DateTimePickerFormat.Custom;
bk.txtreg.Text = Convert.ToString(dr["Registration_Id"]);
bk.txtname.Text = Convert.ToString(dr["Name"]);
bk.txtcity.Text = dr["City"].ToString();
bk.txtadd.Text = dr["Address"].ToString();
bk.txtmobile.Text = dr["Mobile_no"].ToString();
bk.txtemail.Text = dr["email"].ToString();
bk.txtpassport.Text = dr["Passport"].ToString();
bk.txtbirth.Text = dr["birth_date"].ToString();
bk.arrivaldatetime.Text = dr["arrival_date"].ToString();
if (dr["Category"].ToString() == "Gen")
frm.radbtngen.Checked = true;
else
frm.radbtnobc.Checked = true;
frm .button1 .Text ="Update";
bk.paymentdatetime.Text = dr["payment_date"].ToString();
bk.savebutton.Text = "Update";
bk.deletebutton.Enabled = true;
bk.txtname.Enabled = false;
if (srchdgview.RowsDefaultCellStyle.BackColor == Color.Red)
{
bk.BackColor = Color.Red;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void srchreg_TextChanged(object sender, EventArgs e)
{
validation valids = new validation();
valids.numwithdecitxtBox_TxtChng(srchreg, sender, e);
}
---------------------------------------------------------
Cell Formet
private void srchdgview_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
for (int i = 0; i <= srchdgview.Rows.Count - 1; i++)
{
DataGridViewRow dvr = srchdgview.Rows[e.RowIndex];
string strStatus = dvr.Cells["STATUS"].Value.ToString();
DateTime dt1 = new DateTime();
dt1 =Convert.ToDateTime( dvr.Cells["ARRIVAL DATE"].Value.ToString());
DateTime dt3 = new DateTime();
dt3 = Convert.ToDateTime(DateTime.Now.ToShortDateString());
if (strStatus == " Checked " || strStatus == "Checked " || strStatus == " Checked" || strStatus == "Checked")
{
dvr.DefaultCellStyle.BackColor = Color.Red;
}
else if ((strStatus == " Unchecked " || strStatus == "Unchecked ") && dt1 > dt3)
{
dvr.DefaultCellStyle.BackColor = Color.Orange;
}
else
{
dvr.DefaultCellStyle.BackColor = Color.Green;
}
}
}
--------------------------------------------------------------------------------------------------------
Page Ref.
frm = new Form1();
frm.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form3_Load);
frm.Show();
----------------------------------------------------------------------------------------------------
C# Save, Update ,Deleted
public partial class Item_Master : Form
{
Dbclass db = new Dbclass();
string common;
public Item_Master()
{
InitializeComponent();
}
private void btnrecord_Click(object sender, EventArgs e)
{
RecordItemMaster rtm = new RecordItemMaster();
rtm.Show();
}
private void btnfind_Click(object sender, EventArgs e)
{
}
private void btnsave_Click(object sender, EventArgs e)
{
if (txtitem_name.Text == "")
{
MessageBox.Show("Error 9001303991 : Fill Up The Item Name", "Blank.............", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
if (btnsave.Text == "Save")
{
string str = "Itemmaster_sp'S','','" +cmbf_category.SelectedValue + "','" + txtitem_name.Text + "','" + txtitem_rs.Text + "','" +cmbunit_type.SelectedValue + "'";
db.inserfun(str);
MessageBox.Show("Successfully Saved", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
cmbf_category.Text = "";
txtitem_name.Text = "";
txtitem_rs.Text = "";
cmbunit_type.Text = "";
cmbf_category.Focus();
}
else if (btnsave.Text == "Update")
{
string upt = "ItemMaster_sp'U','" +txtunq_id.ToString () + "','" + cmbf_category.Text + "','" + txtitem_name.Text + "','" + txtitem_rs.Text + "','" + cmbunit_type.Text + "'";
db.Updatefun(upt);
MessageBox.Show("Successfully Update ", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
btnfind.Text = "Find";
btnsave.Text = "Save";
cmbf_category.Text = "";
txtitem_name.Text = "";
txtitem_rs.Text = "";
cmbunit_type.Text = "";
cmbf_category.Focus();
}
}
private void Item_Master_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F5)
{
btnsave_Click(sender, e);
}
else if (e.KeyCode == Keys.F2)
{
btnfind_Click(sender, e);
}
else if (e.KeyCode == Keys.F10)
{
btnrecord_Click(sender, e);
}
}
private void Item_Master_Load(object sender, EventArgs e)
{
string str = "Select * from category_master";
string str1 = "select * from unit";
db.Fillcombo(cmbf_category, "category_name", "unq_id", str);
db.Fillcombo(cmbunit_type, "unitname", "unqid", str1);
DataTable dtt = new DataTable();
string grd = "select unq_id, category_name[CATEGORY NAME],item_name [ITEM NAME],item_rs[ITEM RS],unit_type[UNIT TYPE] from item_master";
dtt = db.FindFun(grd);
Grditem_name.DataSource = dtt;
//cmbf_category.Text = ComboBox.v
//txtitem_name.Text = ComboBox;
//txtitem_rs.Text = textBox1;
//cmbunit_type.Text = textBox1;
}
int GridEvent;
private void FillTextBox()
{
if (GridEvent < 0)
{
return;
}
else if (GridEvent > Grditem_name.Rows.Count - 1)
{
return;
}
else
{
txtunq_id.Text = Grditem_name.Rows[GridEvent].Cells[0].Value.ToString();
cmbf_category.Text = Grditem_name.Rows[GridEvent].Cells[1].Value.ToString();
txtitem_name.Text = Grditem_name.Rows[GridEvent].Cells[2].Value.ToString();
txtitem_rs.Text = Grditem_name.Rows[GridEvent].Cells[3].Value.ToString();
cmbunit_type.Text = Grditem_name.Rows[GridEvent].Cells[4].Value.ToString();
cmbf_category.Focus();
btnfind.Text = "Delete";
btnsave.Text = "Update";
}
}
private void btnfind_Click_1(object sender, EventArgs e)
{
if (txtitem_name.Text == "")
{
MessageBox.Show("Error 9001303991 :Fill Up The Item Name", "Blank.............", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
if (btnfind.Text == "Find")
{
tabControl1.SelectedTab = tabPage2;
}
else if (btnfind.Text == "Delete")
{
string del = "ItemMaster_sp 'D','" + txtunq_id.Text.ToString() + "'";
db.Deletefun(del);
MessageBox.Show("Successfull Delete", "Delete............", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
cmbf_category.Text = "";
txtitem_name.Text = "";
txtitem_rs.Text = "";
cmbunit_type.Text = "";
cmbf_category.Focus();
btnfind.Text = "Find";
btnsave.Text = "Save";
}
}
private void Grditem_name_CellDoubleClick_1(object sender, DataGridViewCellEventArgs e)
{
GridEvent = e.RowIndex;
FillTextBox();
}
private void Grditem_name_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
FillTextBox();
}
}
private void Grditem_name_CellEnter(object sender, DataGridViewCellEventArgs e)
{
GridEvent = e.RowIndex;
}
private void btnsave_Click_1(object sender, EventArgs e)
{
}
private void Grditem_name_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
No comments:
Post a Comment