private void Form8_Load(object sender, EventArgs e) { 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.Write_In_Attributes(Filename); for (int i = 0; i < Table.Columns; i++) { comboBox1.Items.Add(Table.Attributes[i]); } }
private void button1_Click(object sender, EventArgs e) { try { int sorted = 0; int writeagin = 0; string swape = ""; 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(); if (comboBox1.Text == "RRN") { DataTable T = new DataTable(); for (int i = 0; i < Table.Columns; i++) { T.Columns.Add(Table.Attributes[i]); } DataRow row; for (int i = 0; i < Table.Rows; i++) { row = T.NewRow(); for (int j = 0; j < Table.Columns; j++) { row[Table.Attributes[j]] = Table.table[i][j]; } T.Rows.Add(row); } dataGridView1.DataSource = T; } else { for (int i = 0; i < Table.Columns; i++) { if (sort[i] == comboBox1.Text) { sorted++; break; } } if (sorted == 0) { sort[size] = comboBox1.Text; size++; try { for (int i = 0; i < Table.Columns; i++) { if (Table.Attributes[i] == comboBox1.Text) { x = i; break; } } for (int i = 0; i < Table.Rows - 1; i++) { for (int j = i + 1; j < Table.Rows; j++) { if (Convert.ToInt32(Table.table[i][x]) > Convert.ToInt32(Table.table[j][x])) { for (int n = 0; n < Table.Columns; n++) { swape = Table.table[i][n]; Table.table[i][n] = Table.table[j][n]; Table.table[j][n] = swape; } } } } } catch { sorted = 0; List <string> myList = new List <string>(); for (int n = 0; n < Table.Rows; n++) { myList.Add(Table.table[n][x]); } myList.Sort(); foreach (string name in myList) { for (int y = 0; y < Table.Rows; y++) { if (name == Table.table[y][x] && y != sorted) { for (int n = 0; n < Table.Columns; n++) { swape = Table.table[y][n]; Table.table[y][n] = Table.table[sorted][n]; Table.table[sorted][n] = swape; } } } sorted++; } } //////////////////////////////////////////// for (int g = 0; g < Table.Rows; g++) { if (writeagin == 0) { XmlWriter Xw = XmlWriter.Create(comboBox1.Text + ".xml"); Xw.WriteStartDocument(); Xw.WriteStartElement("Table"); Xw.WriteAttributeString("Name", comboBox1.Text + ".xml"); Xw.WriteStartElement("Record"); for (int i = 0; i < Table.Columns; i++) { Xw.WriteStartElement(Table.Attributes[i]); Xw.WriteString(Table.table[0][i]); Xw.WriteEndElement(); } Xw.WriteEndElement(); Xw.WriteEndElement(); Xw.WriteEndDocument(); Xw.Close(); writeagin++; } else { XmlDocument Doc = new XmlDocument(); XmlElement Record = Doc.CreateElement("Record"); XmlElement Node; XmlDocument Doc1 = new XmlDocument(); Doc1.Load(comboBox1.Text + ".xml"); XmlNodeList MYList = Doc1.GetElementsByTagName("Record"); for (int i = 0; i < Table.Columns; i++) { Node = Doc.CreateElement(Table.Attributes[i]); Node.InnerText = Table.table[g][i]; Record.AppendChild(Node); } Doc.Load(comboBox1.Text + ".xml"); XmlElement Root = Doc.DocumentElement; Root.AppendChild(Record); Doc.Save(comboBox1.Text + ".xml"); } } } XmlDocument z = new XmlDocument(); z.Load(comboBox1.Text + ".xml"); XmlNodeList MY_List = z.GetElementsByTagName("Record"); XmlNodeList No_de; table = new string[MY_List.Count][]; for (int i = 0; i < MY_List.Count; i++) { table[i] = new string[Table.Columns]; } for (int i = 0; i < Table.Rows; i++) { No_de = MY_List[i].ChildNodes; for (int j = 0; j < Table.Columns; j++) { table[i][j] = No_de[j].InnerText; } } DataTable T = new DataTable(); for (int i = 0; i < Table.Columns; i++) { T.Columns.Add(Table.Attributes[i]); } DataRow row; for (int i = 0; i < Table.Rows; i++) { row = T.NewRow(); for (int j = 0; j < Table.Columns; j++) { row[Table.Attributes[j]] = table[i][j]; } T.Rows.Add(row); } dataGridView1.DataSource = T; } MessageBox.Show("Operation is done", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("File Is Empty !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button3_Click(object sender, EventArgs e) { /* * this button for search by binary search algorithm */ try { flage = true; 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.Write_In_Attributes(Filename); if (string.IsNullOrEmpty(textBox1.Text.ToString())) { flage = false; MessageBox.Show("Invaild !!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { RRN = Convert.ToInt32(textBox1.Text.ToString()); if (Table.BinarySearch(RRN) && Flag == false) { for (int i = 0; i < Table.Columns; i++) { AddNewlabel(i + 1, Table.Attributes[i]); AddNewTextBox(i + 1, Table.Record[0][i]); } Flag = true; } else if (Table.BinarySearch(RRN) && Flag == true) { int i = 0; foreach (Control x in Controls) { if (x.Name.Contains("txt")) { x.Text = Table.Record[0][i]; i++; } } } else { flage = false; MessageBox.Show("Record Is Not Exits !!"); } textBox1.Clear(); } } catch { flage = false; MessageBox.Show("File is Empty !!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); } }
private void button1_Click(object sender, EventArgs e) { bool empty = false; try { string word = comboBox1.SelectedItem.ToString(); string value = textBox1.Text.ToString(); if (string.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("It Is Not Vaild !!"); empty = true; } bool flag = false; int index = 0; //this must be change to file DynamicTable a = new DynamicTable(Convert.ToInt32(num_attributes), FileName); //a.Write_In_Attributes(Filename); a.ReadFromXml(); for (int i = 0; i < a.Columns; i++) { if (word == a.Attributes[i].ToString()) { index = i; break; } } for (int i = 0; i < a.Rows; i++) { if (a.table[i][index] == value) { flag = true; break; } } if (flag) { Data.Rows.Clear(); if (Data.Columns.Count == 0) { for (int i = 0; i < a.Columns; i++) { Data.Columns.Add(a.Attributes[i], a.Attributes[i]); } } for (int i = 0; i < a.Rows; i++) { if (value == a.table[i][index]) { Data.Rows.Add(a.table[i]); } } } else if (flag == false && empty == false) { MessageBox.Show("Record Not Exist !! "); } } catch { MessageBox.Show("It Is Not Vaild !!"); } }