private void btndelete3_Click(object sender, EventArgs e) { cc = new ReservationDetailController(); dt = new DataTable("SearchRecords"); dt.Columns.Add("Reserve_ID", System.Type.GetType("System.String")); dt.Columns.Add("Customer_ID", System.Type.GetType("System.String")); dt.Columns.Add("Room_Type", System.Type.GetType("System.String")); dt.Columns.Add("Room_Number", System.Type.GetType("System.String")); dt.Columns.Add("Date_in", System.Type.GetType("System.String")); dt.Columns.Add("Date_out", System.Type.GetType("System.String")); dataGridView1.DataSource = dt; btndelete3.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"); btndelete3.Visible = false; } } searchType = 0; bool flag = false; ReservationDetail cd = null; flag = int.TryParse(txtreserveid.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.Reserve_ID, cd.Customer_ID, cd.Room_Type, cd.Room_Number, cd.Date_In, cd.Date_Out }); btndelete3.Visible = true; } else { dt.Rows.Clear(); MessageBox.Show("Record Not Found"); id = -1; btndelete3.Visible = false; } }
private void btnsearch_Click(object sender, EventArgs e) { int id; bool flag = int.TryParse(txtreserveid.Text, out id); if (!flag) { MessageBox.Show("Invalid ID"); return; } ReservationDetailController std = new ReservationDetailController(); ReservationDetail i = std.Searchcustomer(id); if (i != null) { a = true; txtreserveid.Text = i.Reserve_ID.ToString(); } else { a = false; MessageBox.Show("Record Not Found"); } ReservationDetailController sc = new ReservationDetailController(); dt = new DataTable(); if (a == true) { dt.Columns.Add("Reserve_ID", System.Type.GetType("System.String")); dt.Columns.Add("Customer_ID", System.Type.GetType("System.String")); dt.Columns.Add("Room_Type", System.Type.GetType("System.String")); dt.Columns.Add("Room_Number", System.Type.GetType("System.String")); dt.Columns.Add("Date_in", System.Type.GetType("System.String")); dt.Columns.Add("Date_out", System.Type.GetType("System.String")); List <ReservationDetail> d = sc.GetAllitem(); foreach (var s in d) { if (id == s.Reserve_ID) { dt.Rows.Add(new object[] { s.Reserve_ID, s.Customer_ID, s.Room_Type, s.Room_Number, s.Date_In, s.Date_Out }); } } dataGridView1.DataSource = dt; } }
public ReservationDetail Searchcustomer(int Boid) { ReservationDetail cd = null; int pos = GetPosition(Boid); if (pos != -1) { using (FileStream LoginReader = new FileStream("ReservationDetails.txt", FileMode.Open)) { cd = new ReservationDetail(); string line = ""; int chr; LoginReader.Seek(pos, SeekOrigin.Begin); while ((chr = LoginReader.ReadByte()) > 0) { char c; c = Convert.ToChar(chr); if (c == '$') { break; } line += c; } string[] subStr = line.Split('|'); try { cd.Reserve_ID = int.Parse(subStr[0]); cd.Customer_ID = int.Parse(subStr[1]); cd.Room_Type = subStr[2]; cd.Room_Number = int.Parse(subStr[3]); cd.Date_In = subStr[4]; cd.Date_Out = subStr[5]; } catch (Exception e) { Console.Out.WriteLine(e.StackTrace); Console.Out.WriteLine("inside search Reservation error ---------------------"); } } return(cd); } return(cd); }
public ReservationDetail SearchCustomer(string reName) { ReservationDetail cd = null; SortByName(); int pos = GetPosition(reName); if (pos != -1) { using (FileStream LoginReader = new FileStream("ReservationDetails.txt", FileMode.Open)) { cd = new ReservationDetail(); string line = ""; int chr; LoginReader.Seek(pos, SeekOrigin.Begin); while ((chr = LoginReader.ReadByte()) > 0) { char c; c = Convert.ToChar(chr); if (c == '$') { break; } line += c; } string[] subStr = line.Split('|'); cd.Reserve_ID = int.Parse(subStr[0]); cd.Customer_ID = int.Parse(subStr[1]); cd.Room_Type = subStr[2]; cd.Room_Number = int.Parse(subStr[3]); cd.Date_In = subStr[4]; cd.Date_Out = subStr[5]; } return(cd); } return(cd); }