예제 #1
0
        public ChemistryElement findByTableName(string tableName)
        {
            command.CommandText = "Select * from ChemistryElement where tableName = ?tb";
            command.Prepare();
            command.Parameters.AddWithValue("?tb", tableName);
            reader = command.ExecuteReader();
            reader.Read();
            ChemistryElement chemistryElement;

            try
            {
                string str = reader[8].ToString();
                char   c   = str[0];
                chemistryElement = new ChemistryElement(int.Parse(reader[0].ToString()), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), int.Parse(reader[4].ToString()), reader[5].ToString(),
                                                        int.Parse(reader[6].ToString()), double.Parse(reader[7].ToString()), c, reader[9].ToString(), reader[10].ToString(), reader[11].ToString());
                //Console.Write(chemistryElement);
                reader.Close();
            }
            catch (Exception ex)
            {
                //reader.Close();
                return(null);
            }


            return(chemistryElement);
        }
예제 #2
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();
        }
예제 #3
0
 public CheckedElement(MainWindow mainWind, ChemistryElement chemElem)
 {
     InitializeComponent();
     parent         = mainWind;
     viewController = new ViewController(parent);
     addImage(chemElem.GraphicModel);
     addRichTextBox(chemElem);
 }
예제 #4
0
        private void addRichTextBox(ChemistryElement element)
        {
            RichTextBox richBox = new RichTextBox();

            Thickness margin = richBox.Margin;

            richBox.Width      = 500; richBox.Height = 500;
            margin.Left        = 170;
            margin.Top         = -420;
            richBox.FontSize   = 24;
            richBox.Margin     = margin;
            richBox.IsReadOnly = true;
            stPnel.Children.Add(richBox);
            richBox.Document.Blocks.Add(new Paragraph(new Run(element.ToString())));
        }
예제 #5
0
        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);
        }
예제 #6
0
        private void addRichTextBox(ChemistryElement element, int index)
        {
            RichTextBox richBox = new RichTextBox();

            Thickness margin = richBox.Margin;

            richBox.Width      = 160; richBox.Height = 256;
            richBox.IsReadOnly = true;
            //margin.Left = -300;
            //margin.Top = 0;
            richBox.Margin = margin;
            //stPnel.Children.Add(richBox);
            richBox.Document.Blocks.Add(new Paragraph(new Run(element.ToString())));
            Grid.SetRow(richBox, index / 4 + 1);
            Grid.SetColumn(richBox, (index % 4) * 2 + 1);


            allElements.Children.Add(richBox);
        }
예제 #7
0
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////MAIN QUERIES////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public void add(ChemistryElement chElem)
 {
     command.CommandText = "INSERT INTO ChemistryElement " +
                           "(FullName,TableName,Description,Groupp,Valence,Period,AtomicWeight,Orbital,GraphicModel,Formula,NaturalName)" +
                           "Values (?ful,?tbl,?dscr,?grp,?vlns,?per,?aw,?orbt,?grphic,?frml,?ntral)";
     command.Prepare();
     command.Parameters.AddWithValue("?ful", chElem.FullName);
     command.Parameters.AddWithValue("?tbl", chElem.TableTame);
     command.Parameters.AddWithValue("?dscr", chElem.Description);
     command.Parameters.AddWithValue("?grp", chElem.Group);
     command.Parameters.AddWithValue("?vlns", chElem.Valence);
     command.Parameters.AddWithValue("?per", chElem.Period);
     command.Parameters.AddWithValue("?aw", chElem.AtomicWeight);
     command.Parameters.AddWithValue("?orbt", chElem.Orbital);
     command.Parameters.AddWithValue("?grphic", chElem.GraphicModel);
     command.Parameters.AddWithValue("?frml", chElem.Formula);
     command.Parameters.AddWithValue("?ntral", chElem.NaturalName);
     command.ExecuteNonQuery();
 }
예제 #8
0
 //коли вибиваєм елемент з таблички
 public void checkedChemistryElementPage(ChemistryElement chemistryElement)
 {
     mainWind.MainThis.Children.Clear();
     mainWind.MainThis.Children.Add(new CheckedElement(mainWind, chemistryElement));
 }
 public void add(ChemistryElement chemistryElement)
 {
     chemistryService.add(chemistryElement);
 }
예제 #10
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;
            }
        }
예제 #11
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], "/MyImages/Графічні моделі/" + tBoxes[0].Text + ".png", 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();
     }
 }