private void btndelete_Click(object sender, EventArgs e) { cc = new itemdetailcontroller(); dt = new DataTable("SearchRecords"); dt.Columns.Add("Customer_ID", System.Type.GetType("System.String")); dt.Columns.Add("Fname", System.Type.GetType("System.String")); dt.Columns.Add("Lname", System.Type.GetType("System.String")); dt.Columns.Add("email", System.Type.GetType("System.String")); dt.Columns.Add("phone", System.Type.GetType("System.String")); dataGridView2.DataSource = dt; btndelete.Visible = false; DialogResult dr = MessageBox.Show("You want to delete the record ?", "Confirm", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { if (id != -1) { cc.DeleteRecord(id); dt.Rows.Clear(); MessageBox.Show("Record Deleted"); btndelete.Visible = false; } } searchType = 0; bool flag = false; itemdetail cd = null; flag = int.TryParse(txtcustid.Text, out id); cd = cc.Searchcustomer(id); if (cd == null) { flag = false; } else { id = cd.Customer_ID; searchType = 1; flag = true; } if (flag) { dt.Rows.Clear(); dt.Rows.Add(new object[] { cd.Customer_ID, cd.Fname, cd.Lname, cd.email, cd.phone }); btndelete.Visible = true; } else { dt.Rows.Clear(); MessageBox.Show("Record Not Found"); id = -1; btndelete.Visible = false; } }
private void btnsearch_Click(object sender, EventArgs e) { int id; bool flag = int.TryParse(txtcustid.Text, out id); if (!flag) { MessageBox.Show("Invalid ID"); return; } itemdetailcontroller std = new itemdetailcontroller(); itemdetail i = std.Searchcustomer(id); if (i != null) { a = true; txtcustid.Text = i.Customer_ID.ToString(); } else { a = false; MessageBox.Show("Record Not Found"); } itemdetailcontroller sc = new itemdetailcontroller(); dt = new DataTable(); if (a == true) { dt.Columns.Add("Customer_ID", System.Type.GetType("System.String")); dt.Columns.Add("Fname", System.Type.GetType("System.String")); dt.Columns.Add("Lname", System.Type.GetType("System.String")); dt.Columns.Add("email", System.Type.GetType("System.String")); dt.Columns.Add("phone", System.Type.GetType("System.String")); List <itemdetail> d = sc.GetAllitem(); foreach (var s in d) { if (id == s.Customer_ID) { dt.Rows.Add(new object[] { s.Customer_ID, s.Fname, s.Lname, s.email, s.phone }); } } dataGridView2.DataSource = dt; } }