コード例 #1
0
        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();
        }
コード例 #2
0
        private void OnDeleteButton_Click(object sender, RoutedEventArgs e)
        {
            int id;

            try
            {
                id = int.Parse(comboBox3.Text);
            } catch (Exception ex)
            {
                MessageBox.Show("Firstry select id of element");
                return;
            }
            try
            {
                switch (comboBox1.SelectedIndex)
                {
                case 0:
                {
                    chemistryController = new ChemistryElementController();
                    chemistryController.delete(id);
                    chemistryController.close();
                } break;

                case 1:
                {
                    organicController = new OrganicController();
                    organicController.delete(id);
                    organicController.close();
                }
                break;

                case 2:
                {
                    pageController = new PageController();
                    pageController.delete(id);
                    pageController.close();
                }
                break;

                case 3:
                {
                    imageController = new ImageController();
                    imageController.delete(id);
                    imageController.close();
                }
                break;
                }
                updateCombobox3(id.ToString());
            }
            finally
            {
                richTextBox.Document.Blocks.Clear();
                MessageBox.Show("Successfully deleted from " + comboBox1.SelectedValue.ToString());
            }
        }
コード例 #3
0
ファイル: BookPage1.xaml.cs プロジェクト: RosSGaiduk/Cursova
        public BookPage1(MainWindow wind)
        {
            InitializeComponent();
            parent = wind;
            chemistryController = new ChemistryElementController();
            List <ChemistryElement> elements = chemistryController.findAll();

            chemistryController.close();
            generateMendeleev(elements);
            viewController = new ViewController(parent);
            //formTable(elements);
        }
コード例 #4
0
ファイル: BookPage1.xaml.cs プロジェクト: RosSGaiduk/Cursova
        private void Button_Clickk(object sender, EventArgs e)
        {
            //string buttonText = ((Button)sender).Text;
            Button b = (Button)sender;
            //MessageBox.Show("" + b.Content);
            string cont = (string)b.Content;

            string[] lines     = cont.Split('\n');
            string[] tableName = lines[0].Split(' ');

            //MessageBox.Show(tableName[0].Length+" "+tableName[0]);
            chemistryController = new ChemistryElementController();
            ChemistryElement element = chemistryController.findByTableName(tableName[0]);

            chemistryController.close();

            viewController.checkedChemistryElementPage(element);
        }
コード例 #5
0
 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();
     }
 }
コード例 #6
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            switch (comboBox.SelectedIndex)
            {
            case 0:
            {
                chemistryController = new ChemistryElementController();
                ChemistryElement chemistryElement = chemistryController.findByTableName(textBox1.Text);
                chemistryController.close();

                clearScreen();

                try
                {
                    addImage(chemistryElement.GraphicModel, 0);
                    addRichTextBox(chemistryElement, 0);
                }
                catch (NullReferenceException ex)
                {
                }
                break;
            }

            case 1:
                try
                {
                    int group = int.Parse(textBox1.Text);
                } catch (Exception ex) {
                    MessageBox.Show("Only integer value can be read from this text box!!!");
                    return;
                }
                {
                    clearScreen();
                    chemistryController = new ChemistryElementController();
                    List <ChemistryElement> chemistryElements = chemistryController.findAllByGroup(textBox1.Text);


                    for (int i = 0; i < chemistryElements.Count; i++)
                    {
                        addImage(chemistryElements[i].GraphicModel, i);
                        addRichTextBox(chemistryElements[i], i);
                    }
                    chemistryController.close();
                } break;

            case 2:
            {
                if (textBox1.Text != "p" && textBox1.Text != "s" && textBox1.Text != "d")
                {
                    MessageBox.Show("Orbitals can be only like 'p' or 's' or 'd'!!!");
                    return;
                }
                clearScreen();
                chemistryController = new ChemistryElementController();
                List <ChemistryElement> chemistryElements = chemistryController.findAllByOrbital(textBox1.Text);


                for (int i = 0; i < chemistryElements.Count; i++)
                {
                    addImage(chemistryElements[i].GraphicModel, i);
                    addRichTextBox(chemistryElements[i], i);
                }
                chemistryController.close();
            } break;

            case 3:
            {
                clearScreen();
                chemistryController = new ChemistryElementController();
                List <ChemistryElement> elements = chemistryController.findAll();
                for (int i = 0; i < elements.Count; i++)
                {
                    string str = "/MyImages/Графічні моделі/Гідроген.png";
                    addImage(elements[i].GraphicModel, i);
                    addRichTextBox(elements[i], i);
                }
                chemistryController.close();
            } break;
            }
        }
コード例 #7
0
        private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = comboBox1.SelectedIndex;

            comboBox3.Items.Clear();
            richTextBox.Document.Blocks.Clear();
            comboBox2.SelectedIndex = 0;

            //В залежності від того, яку сутність з бд що ми обрали, такими id-шками має наповнитись combobox3
            switch (index)
            {
            case 0:
            {
                chemistryController = new ChemistryElementController();
                List <ChemistryElement> elements = chemistryController.findAll();

                for (int i = 0; i < elements.Count; i++)
                {
                    if (comboBox2.SelectedIndex == 0)
                    {
                        richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + elements[i].ToString() + "\n" + block)));
                    }
                    comboBox3.Items.Add(elements[i].Id);
                }
                chemistryController.close();
            } break;

            case 1:
            {
                organicController = new OrganicController();
                List <OrganicElement> elements = organicController.findAll();
                for (int i = 0; i < elements.Count; i++)
                {
                    richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + elements[i].ToString() + "\n" + block)));
                    comboBox3.Items.Add(elements[i].Id);
                }
                organicController.close();
            } break;

            case 2:
            {
                pageController = new PageController();
                List <PageWithTextAndImage> elements = pageController.findAll();
                for (int i = 0; i < elements.Count; i++)
                {
                    richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + elements[i].ToString() + "\n" + block)));
                    comboBox3.Items.Add(elements[i].Id);
                }
                pageController.close();
            }
            break;


            case 3:
            {
                imageController = new ImageController();
                List <Picture> elements = imageController.findAll();
                for (int i = 0; i < elements.Count; i++)
                {
                    richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + elements[i].ToString() + "\n" + block)));
                    comboBox3.Items.Add(elements[i].Id);
                }
                imageController.close();
            }
            break;
            }
        }
コード例 #8
0
        private void comboBox3_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = comboBox1.SelectedIndex;

            switch (index)
            {
            case 0:
            {
                if (comboBox2.SelectedValue.ToString() == "One")
                {
                    try {
                        richTextBox.Document.Blocks.Clear();
                        chemistryController = new ChemistryElementController();
                        int    id    = int.Parse(comboBox3.SelectedValue.ToString());
                        string block = "---------------------------------------------\n";
                        richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + chemistryController.findOne(id).ToString() + "\n" + block)));
                        chemistryController.close();
                    } catch (Exception ex)
                    {
                        MessageBox.Show("Firstly select id of element!!!");
                    }
                }
            } break;

            case 1:
            {
                if (comboBox2.SelectedValue.ToString() == "One")
                {
                    try
                    {
                        richTextBox.Document.Blocks.Clear();
                        organicController = new OrganicController();
                        int    id    = int.Parse(comboBox3.SelectedValue.ToString());
                        string block = "---------------------------------------------\n";
                        richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + organicController.finOne(id).ToString() + "\n" + block)));
                        organicController.close();
                    } catch (Exception ex)
                    {
                        MessageBox.Show("Firstly select id of element!!!");
                    }
                }
            } break;

            case 2:
            {
                if (comboBox2.SelectedValue.ToString() == "One")
                {
                    try
                    {
                        richTextBox.Document.Blocks.Clear();
                        pageController = new PageController();
                        int    id    = int.Parse(comboBox3.SelectedValue.ToString());
                        string block = "---------------------------------------------\n";
                        richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + pageController.findOne(id).ToString() + "\n" + block)));
                        pageController.close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Firstly select id of element!!!");
                    }
                }
            }
            break;

            case 3:
            {
                if (comboBox2.SelectedValue.ToString() == "One")
                {
                    try
                    {
                        richTextBox.Document.Blocks.Clear();
                        imageController = new ImageController();
                        int    id    = int.Parse(comboBox3.SelectedValue.ToString());
                        string block = "---------------------------------------------\n";
                        richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + imageController.findOne(id).ToString() + "\n" + block)));
                        imageController.close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Firstly select id of element!!!");
                    }
                }
            }
            break;
            }
        }
コード例 #9
0
        private void comboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = comboBox1.SelectedIndex;

            switch (index)
            {
            case 0:
            {
                richTextBox.Document.Blocks.Clear();
                chemistryController = new ChemistryElementController();
                if (comboBox2.SelectedIndex == 0)
                {
                    List <ChemistryElement> elements = chemistryController.findAll();
                    foreach (ChemistryElement element in elements)
                    {
                        richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + element.ToString() + "\n" + block)));
                    }
                }
                else
                {
                    richTextBox.Document.Blocks.Clear();
                    try
                    {
                        if (comboBox3.SelectedValue.ToString() != "")
                        {
                            int id = int.Parse(comboBox3.SelectedValue.ToString());

                            richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + chemistryController.findOne(id).ToString() + "\n" + block)));
                        }
                    } catch (Exception ex)
                    {
                        MessageBox.Show("Firstly select id of element!!!");
                    }
                }
                chemistryController.close();
            } break;

            case 1:
            {
                richTextBox.Document.Blocks.Clear();
                organicController = new OrganicController();
                if (comboBox2.SelectedIndex == 0)
                {
                    List <OrganicElement> elements = organicController.findAll();
                    foreach (OrganicElement element in elements)
                    {
                        richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + element.ToString() + "\n" + block)));
                    }
                }
                else
                {
                    richTextBox.Document.Blocks.Clear();
                    try
                    {
                        if (comboBox3.SelectedValue.ToString() != "")
                        {
                            int id = int.Parse(comboBox3.SelectedValue.ToString());
                            richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + organicController.finOne(id).ToString() + "\n" + block)));
                        }
                    } catch (Exception ex)
                    {
                        MessageBox.Show("Firstly select id of element!!!");
                    }
                }
                organicController.close();
            } break;

            case 2:
            {
                richTextBox.Document.Blocks.Clear();
                pageController = new PageController();
                if (comboBox2.SelectedIndex == 0)
                {
                    List <PageWithTextAndImage> elements = pageController.findAll();
                    foreach (PageWithTextAndImage element in elements)
                    {
                        richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + element.ToString() + "\n" + block)));
                    }
                }
                else
                {
                    richTextBox.Document.Blocks.Clear();
                    try
                    {
                        if (comboBox3.SelectedValue.ToString() != "")
                        {
                            int id = int.Parse(comboBox3.SelectedValue.ToString());
                            richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + pageController.findOne(id).ToString() + "\n" + block)));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Firstly select id of element!!!");
                    }
                }
                pageController.close();
            }
            break;



            case 3:
            {
                richTextBox.Document.Blocks.Clear();
                imageController = new ImageController();
                if (comboBox2.SelectedIndex == 0)
                {
                    List <Picture> elements = imageController.findAll();
                    foreach (Picture element in elements)
                    {
                        richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + element.ToString() + "\n" + block)));
                    }
                }
                else
                {
                    richTextBox.Document.Blocks.Clear();
                    try
                    {
                        if (comboBox3.SelectedValue.ToString() != "")
                        {
                            int id = int.Parse(comboBox3.SelectedValue.ToString());
                            richTextBox.Document.Blocks.Add(new Paragraph(new Run(block + imageController.findOne(id).ToString() + "\n" + block)));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Firstly select id of element!!!");
                    }
                }
                imageController.close();
            }
            break;
            }
        }