private void button2_Click(object sender, EventArgs e) { /* * This Button For Updata */ if (flage == true) { try { FileStream Data = new FileStream("FilesName.txt", FileMode.Open); StreamReader sr = new StreamReader(Data); while (sr.Peek() != -1) { Filename = sr.ReadLine(); } sr.Close(); FileStream Data1 = new FileStream(Filename, FileMode.Open); StreamReader sr1 = new StreamReader(Data1); FileName = sr1.ReadLine(); num_attributes = sr1.ReadLine(); sr1.Close(); DynamicTable Table = new DynamicTable(Convert.ToInt32(num_attributes), FileName); Table.ReadFromXml(); ///////////////////////////////////////////////////// int n = 0; int n1 = 0; for (int i = 0; i < Table.Rows; i++) { if (Convert.ToInt32(Table.table[i][0]) == RRN) { n = i; break; } } foreach (Control x in Controls) { if (x.Name.Contains("txt")) { Table.Record[0][n1] = x.Text.ToString(); n1++; } } for (int j = 0; j < Table.Columns; j++) { Table.table[n][j] = Table.Record[0][j]; } for (int i = 0; i < Table.Rows; i++) { Table.WriteToXml_Agian(i, 'u'); } MessageBox.Show("Succesfuly updated !! ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("RRN Will Not Be Changed For Ever it is constant ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("File Is Empty !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("You Must Press Button Search to display the record in text box", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void button1_Click(object sender, EventArgs e) { /* * For Delete a record */ if (flage == true) { try { FileStream Data = new FileStream("FilesName.txt", FileMode.Open); StreamReader sr = new StreamReader(Data); while (sr.Peek() != -1) { Filename = sr.ReadLine(); } sr.Close(); FileStream Data1 = new FileStream(Filename, FileMode.Open); StreamReader sr1 = new StreamReader(Data1); FileName = sr1.ReadLine(); num_attributes = sr1.ReadLine(); sr1.Close(); DynamicTable Table = new DynamicTable(Convert.ToInt32(num_attributes), FileName); Table.ReadFromXml(); string[][] T; if (Table.Rows > 1) { T = new String[Table.Rows - 1][]; for (int i = 0; i < Table.Rows - 1; i++) { T[i] = new string[Table.Columns]; } Table.row_is_1 = false; } else { T = new String[1][]; for (int i = 0; i < Table.Rows; i++) { T[i] = new string[Table.Columns]; } Table.row_is_1 = true; } int j = 0; for (int i = 0; i < Table.Rows; i++) { if (Convert.ToInt32(Table.table[i][0]) == RRN) { //delete continue; } else { for (int k = 0; k < Table.Columns; k++) { T[j][k] = Table.table[i][k]; } j++; } } if (Table.Rows > 1) { Table.Rows -= 1; } Table.table = new String[Table.Rows][]; for (int i = 0; i < Table.Rows; i++) { Table.table[i] = new string[Table.Columns]; } for (int i = 0; i < Table.Rows; i++) { for (int o = 0; o < Table.Columns; o++) { Table.table[i][o] = T[i][o]; } } for (int i = 0; i < Table.Rows; i++) { Table.WriteToXml_Agian(i, 'd'); } foreach (Control R in Controls) { if (R.Name.Contains("txt")) { R.ResetText(); } } MessageBox.Show("Deleted Is Done !!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("File Is Empty !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("You Must Press Button Search to display the record in text box", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } }