private void readFromFileAndAddToDB(string nameFile) { StreamReader filereader = new StreamReader(nameFile); string str = filereader.ReadToEnd(); //MessageBox.Show(str+"\n"+ str.Split('^').Length+str.Split('^')[0].Split('|').Length); string[] elements = str.Split('^'); for (int i = 1; i < elements.Length; i++) { chemistryController = new ChemistryElementController(); string[] fields = elements[i].Split('|'); string str1 = ""; for (int i1 = 0; i1 < fields.Length; i1++) { str1 += fields[i1] + "\n"; } MessageBox.Show(str1); ChemistryElement chemistryElement = new ChemistryElement( fields[0], fields[1], fields[2], int.Parse(fields[3]), fields[4], int.Parse(fields[5]), double.Parse(fields[6]), 'o', fields[8], fields[9], fields[10]); chemistryElement.GraphicModel = "/MyImages/Графічні моделі/" + chemistryElement.FullName + ".png"; chemistryController.add(chemistryElement); chemistryController.close(); } filereader.Close(); }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (comboBox.SelectedIndex == 0) { string forChar = tBoxes[7].Text; char[] c = forChar.ToCharArray(); try { chemistryController = new ChemistryElementController(); ChemistryElement element = new ChemistryElement(tBoxes[0].Text, tBoxes[1].Text, tBoxes[2].Text, int.Parse(tBoxes[3].Text), tBoxes[4].Text, int.Parse(tBoxes[5].Text), double.Parse(tBoxes[6].Text), c[0], tBoxes[8].Text, tBoxes[9].Text, tBoxes[10].Text ); chemistryController.add(element); MessageBox.Show("Successfully added " + element); for (int i = 0; i < tBoxes.Length; i++) { tBoxes[i].Text = ""; } } catch (Exception ex) { MessageBox.Show("Failed, something is wrong"); } chemistryController.close(); } else if (comboBox.SelectedIndex == 1) { try { organicController = new OrganicController(); OrganicElement element = new OrganicElement(tBoxes[0].Text, tBoxes[1].Text, tBoxes[2].Text, tBoxes[3].Text); organicController.add(element); MessageBox.Show("Successfully added " + element); for (int i = 0; i < tBoxes.Length; i++) { tBoxes[i].Text = ""; } } catch (Exception ex) { MessageBox.Show("Failed, something is wrong"); } organicController.close(); } else if (comboBox.SelectedIndex == 2) { try { pageController = new PageController(); PageWithTextAndImage element = new PageWithTextAndImage(int.Parse(tBoxes[0].Text), tBoxes[1].Text); pageController.add(element); MessageBox.Show("Successfully added " + element); for (int i = 0; i < tBoxes.Length; i++) { tBoxes[i].Text = ""; } } catch (Exception ex) { MessageBox.Show("Failed, something is wrong"); } pageController.close(); } else if (comboBox.SelectedIndex == 3) { try { imageController = new ImageController(); Picture picture = new Picture(tBoxes[0].Text); imageController.add(picture); MessageBox.Show("Successfully added " + picture); for (int i = 0; i < tBoxes.Length; i++) { tBoxes[i].Text = ""; } } catch (Exception ex) { MessageBox.Show("Failed, something is wrong"); } imageController.close(); } }