//// private void TagNameTextBox_LostFocus(object sender, EventArgs e)
        // {
        //     connection = new DatabaseConnector("localhost", "root", "Keepdfaith7!", "instrumentinformation");
        //     connection.connect();
        //     int itemcount = connection.ReturnMachineColumnCount(TagNameTextBox.Text);
        //     //String query = "select count(" + tableName + ") from " + database;

        //     if (itemcount == 0)
        //     {
        //         done.Cursor = Cursors.Hand;
        //         done.Click += Done_Click;

        //     }

        //     else
        //     {
        //         MessageBox.Show("This machine already exists");
        //     }

        // }

        private void Done_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(MachineNameTextbox.Text + "--" + (SelectUnitComboBox.SelectedIndex + 1) + (SelectVoltageRating.SelectedIndex + 1));
            string UniqueIdHash = MainForm.GetHashedPassword(MachineNameTextbox.Text + (SelectUnitComboBox.SelectedIndex + 1) + TagNameTextBox.Text);

            if (MachineNameTextbox.Text.Length <= 5 || MachineBriefDescription.Text.Length <= 5 || TagNameTextBox.Text.Length <= 5)
            {
                MessageBox.Show("There is an invalid text somewhere");
            }

            else
            {
                connection.update("update machine_details set unique_id='" + UniqueIdHash + "',machine_name='" + MachineNameTextbox.Text + "',tag_name='" + TagNameTextBox.Text + "',description='" + MachineBriefDescription.Text + "',unit='" + (SelectUnitComboBox.SelectedIndex + 1) + "',voltage_rating='" + (SelectVoltageRating.SelectedIndex + 1) + "' where unique_id='" + machineUniqueId + "'");

                MessageBox.Show("Machine Added!");
                connection.disconnect();
            }


            //connection.insert()
        }
Пример #2
0
        public void doneHandler(object sender, EventArgs e)
        {
            if (result == DialogResult.OK)
            {
                //insert into database
                connection = new DatabaseConnector("localhost", "root", "Keepdfaith7!", "instrumentinformation");
                string UniqueIdHash = c.GetHashedPassword(tb.Text + tb2.Text);
                //MessageBox.Show(UniqueIdHash);

                connection.connect();
                int tableSize = connection.ReturnTableSize("departments");
                connection.insert("INSERT INTO departments (unique_id,department_name,index_number,brief_description) VALUES('" + UniqueIdHash + "', '" + tb.Text + "','" + (tableSize + 1) + "', '" + briefDescription.Text + "')");

                connection.insertImage(tb2.Text, UniqueIdHash);
                MessageBox.Show("New Department Added!");

                deptName  = tb.Text;
                deptImage = tb2.Text;
                //c.addDepartment(deptName, deptImage);
                c.emptyDepartmentsFlow();
                c.GetDeparmentsFromDatabase();
                f.Dispose();

                connection.disconnect();
            }
            //deptName = tb.Text;
            //deptImage = tb2.Text;
            //c.addDepartment(deptName, deptImage);
            //f.Dispose();

            //to upload the data int the departments database table
            //connection = new DatabaseConnector("localhost", "root", "Keepdfaith7!", "instrumentinformation");
            // connection.connect();
            // if (result==DialogResult.OK)
            // {
            //     MySqlCommand cmd = new MySqlCommand("insert into departments(id,url,image) values(@id, @url," + "@photo" + ")", conn);
            //     MemoryStream ms = new MemoryStream();
            //     //tb2.Text = op.FileName; has been assigned in the showChooser method so I don't know if it is necessary
            // }
        }
        private void Done_Click(object sender, EventArgs e)
        {
            MessageBox.Show(MachineNameTextbox.Text + "--" + (SelectUnitComboBox.SelectedIndex + 1) + (SelectVoltageRating.SelectedIndex + 1));
            string UniqueIdHash = MainForm.GetHashedPassword(MachineNameTextbox.Text + (SelectUnitComboBox.SelectedIndex + 1) + TagNameTextBox.Text);

            if (MachineNameTextbox.Text.Length <= 5 || MachineBriefDescription.Text.Length <= 5 || TagNameTextBox.Text.Length <= 5)
            {
                MessageBox.Show("There is an invalid text somewhere");
            }

            else
            {
                connection = new DatabaseConnector("localhost", "root", "Keepdfaith7!", "instrumentinformation");
                connection.connect();
                connection.insert("INSERT INTO machine_details (unique_id,machine_name,description,unit,voltage_rating,department,tag_name) VALUES('" + UniqueIdHash + "', '" + MachineNameTextbox.Text + "','" + MachineBriefDescription.Text + "', '" + (SelectUnitComboBox.SelectedIndex + 1) + "', '" + (SelectVoltageRating.SelectedIndex + 1) + "', '" + currentDepartmentIndex + "','" + TagNameTextBox.Text + "')");
                MessageBox.Show("Machine Added!");
                connection.disconnect();
            }


            //connection.insert()
        }