示例#1
0
        private void addButton_Click(object sender, EventArgs e)
        {
            //sets strings to user input
            string name = nameBox.Text, id = idBox.Text, c1 = c1Box.Text, c2 = c2Box.Text,
                   c3 = c3Box.Text, c4 = c4Box.Text, c5 = c5Box.Text;

            try
            {
                Convert.ToInt16(idBox.Text);
                Convert.ToString(idBox.Text);
            }
            catch
            {
                MessageBox.Show("The entry into 'ID#' must be a number.  Please re-enter this as a number and try adding again.", "ID# Error");
                return;
            }

            //adds object to list
            dbObject newObject = new dbObject(name, id, c1, c2, c3, c4, c5, image);

            objectDB.Add(newObject);

            nameLabel.Text    = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].name);
            idLabel.Text      = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].id);
            custom1Label.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].c1);
            custom2Label.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].c2);
            custom3Label.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].c3);
            custom4Label.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].c4);
            custom5Label.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].c5);
            if (image != "")
            {
                imageBox.Image = Image.FromFile(objectDB[objectDB.Count() - 1].img);
                image          = "";
            }

            if (nameSearchLabel.ForeColor == Color.Blue)
            {
                objectDB.Sort();
            }

            nameListBox.Items.Clear();
            IDListBox.Items.Clear();

            for (int i = 0; i <= objectDB.Count() - 1; i++)
            {
                nameListBox.Items.Add(objectDB[i].name);
            }

            for (int i = 0; i <= objectDB.Count() - 1; i++)
            {
                IDListBox.Items.Add(objectDB[i].id);
            }

            nameBox.Text = idBox.Text = c1Box.Text = c2Box.Text = c3Box.Text = c4Box.Text = c5Box.Text = image = "";

            cform.Close();
        }
示例#2
0
        private void loadFileDialog_FileOk(object sender, CancelEventArgs e)
        {
            fileName = loadFileDialog.FileName;

            XmlTextReader reader = new XmlTextReader(fileName);
            int           counter = 0; int elementCounter = 0;
            string        name, id, c1, c2, c3, c4, c5;

            name = id = c1 = c2 = c3 = c4 = c5 = "";

            // Continue to read each element and text until the file is done
            while (reader.Read())
            {
                // If the currently read item is correct info then print it to screen,
                // otherwise the loop repeats getting the next piece of information
                if (reader.NodeType == XmlNodeType.Text)
                {
                    if (counter == 0)
                    {
                        name = reader.Value;
                        counter++;
                    }
                    else if (counter == 1)
                    {
                        id = reader.Value;
                        counter++;
                    }
                    else if (counter == 2)
                    {
                        c1 = reader.Value;
                        counter++;
                    }
                    else if (counter == 3)
                    {
                        c2 = reader.Value;
                        counter++;
                    }
                    else if (counter == 4)
                    {
                        c3 = reader.Value;
                        counter++;
                    }
                    else if (counter == 5)
                    {
                        c4 = reader.Value;
                        counter++;
                    }
                    else if (counter == 6)
                    {
                        c5 = reader.Value;
                        counter++;
                    }
                    else if (counter == 7)
                    {
                        image = reader.Value;

                        dbObject newObject = new dbObject(name, id, c1, c2, c3, c4, c5, image);
                        objectDB.Add(newObject);
                        counter = 0;
                    }
                }

                // If the currently read item is element name then print it to screen,
                // otherwise the loop repeats getting the next piece of information
                if (reader.NodeType == XmlNodeType.Element && elementCounter == 8)
                {
                    custom1BoxLabel.Text = custom1LabelLabel.Text = reader.Name + ":";

                    elementCounter++;
                }

                else if (reader.NodeType == XmlNodeType.Element && elementCounter == 11)
                {
                    custom2BoxLabel.Text = custom2LabelLabel.Text = reader.Name + ":";
                    elementCounter++;
                }

                else if (reader.NodeType == XmlNodeType.Element && elementCounter == 14)
                {
                    custom3BoxLabel.Text = custom3LabelLabel.Text = reader.Name + ":";
                    elementCounter++;
                }

                else if (reader.NodeType == XmlNodeType.Element && elementCounter == 17)
                {
                    custom4BoxLabel.Text = custom4LabelLabel.Text = reader.Name + ":";
                    elementCounter++;
                }

                else if (reader.NodeType == XmlNodeType.Element && elementCounter == 20)
                {
                    custom5BoxLabel.Text = custom5LabelLabel.Text = reader.Name + ":";
                    elementCounter       = 0;
                }
                else
                {
                    elementCounter++;
                }
            }
            // When done reading the file close it
            reader.Close();

            //set to 1st object
            nameLabel.Text    = objectDB[0].name;
            idLabel.Text      = objectDB[0].id;
            custom1Label.Text = objectDB[0].c1;
            custom2Label.Text = objectDB[0].c2;
            custom3Label.Text = objectDB[0].c3;
            custom4Label.Text = objectDB[0].c4;
            custom5Label.Text = objectDB[0].c5;

            if (image != "")
            {
                imageBox.Image = Image.FromFile(objectDB[0].img);
                image          = "";
            }

            nameListBox.Items.Clear();
            IDListBox.Items.Clear();



            //display items on name/ID search list
            for (int i = 0; i <= objectDB.Count() - 1; i++)
            {
                nameListBox.Items.Add(objectDB[i].name);
            }

            for (int i = 0; i <= objectDB.Count() - 1; i++)
            {
                IDListBox.Items.Add(objectDB[i].id);
            }

            nameListBox.SelectedIndex = IDListBox.SelectedIndex = 0;
        }
示例#3
0
        private void addButton_Click(object sender, EventArgs e)
        {
            //sets strings to user input
            string name = nameBox.Text, id = idBox.Text, c1 = c1Box.Text, c2 = c2Box.Text,
                c3 = c3Box.Text, c4 = c4Box.Text, c5 = c5Box.Text;

            try
            {
                Convert.ToInt16(idBox.Text);
                Convert.ToString(idBox.Text);
            }
            catch
            {
                MessageBox.Show("The entry into 'ID#' must be a number.  Please re-enter this as a number and try adding again.", "ID# Error");
                return;

            }

            //adds object to list
            dbObject newObject = new dbObject(name, id, c1, c2, c3, c4, c5, image);
            objectDB.Add(newObject);

            nameLabel.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].name);
            idLabel.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].id);
            custom1Label.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].c1);
            custom2Label.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].c2);
            custom3Label.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].c3);
            custom4Label.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].c4);
            custom5Label.Text = Convert.ToString(objectDB[Convert.ToInt16(objectDB.Count()) - 1].c5);
            if (image != "")
            {
                imageBox.Image = Image.FromFile(objectDB[objectDB.Count() - 1].img);
                image = "";
            }

            if (nameSearchLabel.ForeColor == Color.Blue)
            {
                objectDB.Sort();
            }

            nameListBox.Items.Clear();
            IDListBox.Items.Clear();

            for (int i = 0; i <= objectDB.Count() - 1; i++)
            {
                nameListBox.Items.Add(objectDB[i].name);
            }

            for (int i = 0; i <= objectDB.Count() - 1; i++)
            {
                IDListBox.Items.Add(objectDB[i].id);
            }

            nameBox.Text = idBox.Text = c1Box.Text = c2Box.Text = c3Box.Text = c4Box.Text = c5Box.Text = image = "";

            cform.Close();
        }
示例#4
0
        private void loadFileDialog_FileOk(object sender, CancelEventArgs e)
        {
            fileName = loadFileDialog.FileName;

            XmlTextReader reader = new XmlTextReader(fileName);
            int counter = 0; int elementCounter = 0;
            string name, id, c1, c2, c3, c4, c5;
            name = id = c1 = c2 = c3 = c4 = c5 = "";

            // Continue to read each element and text until the file is done
            while (reader.Read())
            {
                // If the currently read item is correct info then print it to screen,
                // otherwise the loop repeats getting the next piece of information
                if (reader.NodeType == XmlNodeType.Text)
                {
                    if (counter == 0)
                    {
                        name = reader.Value;
                        counter++;
                    }
                    else if (counter == 1)
                    {
                        id = reader.Value;
                        counter++;
                    }
                    else if (counter == 2)
                    {
                        c1 = reader.Value;
                        counter++;
                    }
                    else if (counter == 3)
                    {
                        c2 = reader.Value;
                        counter++;
                    }
                    else if (counter == 4)
                    {
                        c3 = reader.Value;
                        counter++;
                    }
                    else if (counter == 5)
                    {
                        c4 = reader.Value;
                        counter++;
                    }
                    else if (counter == 6)
                    {
                        c5 = reader.Value;
                        counter++;
                    }
                    else if (counter == 7)
                    {
                        image = reader.Value;

                        dbObject newObject = new dbObject(name, id, c1, c2, c3, c4, c5, image);
                        objectDB.Add(newObject);
                        counter = 0;
                    }
                }

                // If the currently read item is element name then print it to screen,
                // otherwise the loop repeats getting the next piece of information
                if (reader.NodeType == XmlNodeType.Element && elementCounter == 8)
                {
                    custom1BoxLabel.Text = custom1LabelLabel.Text = reader.Name + ":";

                    elementCounter++;
                }

                else if (reader.NodeType == XmlNodeType.Element && elementCounter == 11)
                {
                    custom2BoxLabel.Text = custom2LabelLabel.Text = reader.Name + ":";
                    elementCounter++;
                }

                else if (reader.NodeType == XmlNodeType.Element && elementCounter == 14)
                {
                    custom3BoxLabel.Text = custom3LabelLabel.Text = reader.Name + ":";
                    elementCounter++;
                }

                else if (reader.NodeType == XmlNodeType.Element && elementCounter == 17)
                {
                    custom4BoxLabel.Text = custom4LabelLabel.Text = reader.Name + ":";
                    elementCounter++;
                }

                else if (reader.NodeType == XmlNodeType.Element && elementCounter == 20)
                {
                    custom5BoxLabel.Text = custom5LabelLabel.Text = reader.Name + ":";
                    elementCounter = 0;
                }
                else
                {
                    elementCounter++;
                }
            }
            // When done reading the file close it
            reader.Close();

            //set to 1st object
            nameLabel.Text = objectDB[0].name;
            idLabel.Text = objectDB[0].id;
            custom1Label.Text = objectDB[0].c1;
            custom2Label.Text = objectDB[0].c2;
            custom3Label.Text = objectDB[0].c3;
            custom4Label.Text = objectDB[0].c4;
            custom5Label.Text = objectDB[0].c5;

            if (image != "")
            {
                imageBox.Image = Image.FromFile(objectDB[0].img);
                image = "";
            }

            nameListBox.Items.Clear();
            IDListBox.Items.Clear();

            //display items on name/ID search list
            for (int i = 0; i <= objectDB.Count() - 1; i++)
            {
                nameListBox.Items.Add(objectDB[i].name);
            }

            for (int i = 0; i <= objectDB.Count() - 1; i++)
            {
                IDListBox.Items.Add(objectDB[i].id);
            }

            nameListBox.SelectedIndex = IDListBox.SelectedIndex = 0;
        }