/// <summary>
        /// When Ok button is pressed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonOkClick(object sender, EventArgs e)
        {
            // Get badge ID and password from textbox
            string idBadge  = textBoxUsername.Text;
            string password = textBoxPassword.Text;

            if (idBadge.Contains("700"))
            {
                user = new User()
                {
                    IdBadge = idBadge,
                    Rank    = Rank.Operator
                };
            }
            else
            {
                // Check if user is in database
                user = SqlCommunication.CheckUser(idBadge, password);
            }

            // Check if user has been found
            if (user.IdBadge == null)
            {
                userValid = false;
            }
            else
            {
                userValid = true;
            }

            userChecked = true;

            // Close form
            Close();
        }
        private void ComboBoxProgramsSelectedIndexChanged(object sender, EventArgs e)
        {
            ProgramEntry programToCheck;

            if (comboBoxPrograms.SelectedIndex != -1)
            {
                programToCheck = SqlCommunication.CheckProgram(comboBoxPrograms.SelectedItem.ToString());
            }
            else
            {
                MessageBox.Show("No program selected", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (programToCheck.Name != null)
            {
                triggerOffset      = programToCheck.TriggerOffset;
                startWastingOffset = programToCheck.StartWastingOffset;
                wasteOffset        = programToCheck.WasteOffset;

                logo1Tolerance = 1 - programToCheck.Logo1Camera1Confidence;
                logo2Tolerance = 1 - programToCheck.Logo1Camera2Confidence;

                machine = programToCheck.Machine;
            }
        }
Exemplo n.º 3
0
        private void LoadPrograms()
        {
            programs = SqlCommunication.GetPrograms();

            comboBoxPrograms.Items.Clear();
            comboBoxPrograms.DataSource    = programs;
            comboBoxPrograms.DisplayMember = "name";
            comboBoxPrograms.SelectedIndex = -1;
        }
Exemplo n.º 4
0
        public void LoadPrograms()
        {
            programs = SqlCommunication.GetPrograms();

            comboBoxPrograms.Items.Clear();
            comboBoxPrograms.DataSource    = programs;
            comboBoxPrograms.DisplayMember = "name";
            comboBoxPrograms.SelectedIndex = -1;

            labelDescription.Text = string.Empty;
        }
        private void LoadPrograms()
        {
            listOfPrograms = SqlCommunication.GetPrograms();

            comboBoxPrograms.Items.Clear();

            foreach (var item in listOfPrograms)
            {
                comboBoxPrograms.Items.Add(item.Name);
            }

            comboBoxPrograms.SelectedIndex = -1;
        }
        private void ButtonDeleteSelectedProgramClick(object sender, EventArgs e)
        {
            if (comboBoxPrograms.SelectedIndex != -1)
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete selected program?", "Delete user request", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dialogResult == DialogResult.Yes)
                {
                    SqlCommunication.DeleteProgram(comboBoxPrograms.SelectedItem.ToString());

                    LoadPrograms();
                }
            }
        }
        private void ButtonOkClick(object sender, EventArgs e)
        {
            string idBadge        = textBoxUsername.Text;
            string password       = textBoxPassword.Text;
            string repeatPassword = textBoxRepeatPassword.Text;

            Rank rank = (Rank)comboBoxRank.SelectedItem;

            if (idBadge == string.Empty)
            {
                MessageBox.Show("Username has not been entered", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (rank != Rank.Operator)
            {
                if (password == string.Empty)
                {
                    MessageBox.Show("Password has not been entered", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }

                if (repeatPassword == string.Empty)
                {
                    MessageBox.Show("Repeat password has not been entered", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }

                if (password != repeatPassword)
                {
                    MessageBox.Show("Passwords do not match", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }
            }

            SqlCommunication.InsertUser(idBadge, password, rank.ToString());

            AddLog($"User Configuration: User {idBadge} added");

            UserConfigurationForm parent = (UserConfigurationForm)Owner;

            parent.LoadUsers();

            Close();
        }
Exemplo n.º 8
0
        private void ButtonDeleteSelectedUserClick(object sender, EventArgs e)
        {
            if (dataGridViewUsers.CurrentRow != null)
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete selected user?", "Delete user request", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dialogResult == DialogResult.Yes)
                {
                    SqlCommunication.DeleteUser(dataGridViewUsers.CurrentRow.Cells[0].Value.ToString());

                    AddLog($"User Configuration: User {dataGridViewUsers.CurrentRow.Cells[0].Value.ToString()} deleted");

                    LoadUsers();
                }
            }
        }
        /// <summary>
        /// Loads programs for DB and adds to combo box
        /// </summary>
        private void LoadPrograms()
        {
            // Gets list of programs from DB
            programs = SqlCommunication.GetPrograms();

            // Clear combo box
            comboBoxPrograms.Items.Clear();

            // Set data source of combo box
            comboBoxPrograms.DataSource = programs;

            // What it should display
            comboBoxPrograms.DisplayMember = "name";

            // Deselect everything
            comboBoxPrograms.SelectedIndex = -1;
        }
        private void ButtonOkClick(object sender, EventArgs e)
        {
            string programName = textBoxProgramName.Text.Replace(' ', '_');

            if (programName == string.Empty)
            {
                MessageBox.Show("Program name has not been entered", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ProgramEntry programToCheck = SqlCommunication.CheckProgram(programName);

            if (programToCheck.Name == null)
            {
                manageProgramsForm.AddProgramToComboBox(programName);

                Close();
            }
            else
            {
                MessageBox.Show("Program already exists", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
        public User CheckUser()
        {
            User user = SqlCommunication.CheckUserProgram(scanValue);

            return(user);
        }
        public ProgramEntry CheckProgram()
        {
            ProgramEntry programEntry = SqlCommunication.CheckProgram(scanValue);

            return(programEntry);
        }
 /// <summary>
 /// Adds new log entry to DB
 /// </summary>
 /// <param name="action"></param>
 private void AddLog(string action)
 {
     // Adds log to DB
     SqlCommunication.InsertLog(currentUser.IdBadge, action, string.Empty, string.Empty);
 }
Exemplo n.º 14
0
        private void LoadLogs()
        {
            logEntries = SqlCommunication.GetLogs();

            ShowLogs();
        }
        private void ButtonOkClick(object sender, EventArgs e)
        {
            ProgramEntry programToCheck;

            string shapeTypeCamera1 = string.Empty;
            string shapeTypeCamera2 = string.Empty;

            if (comboBoxPrograms.SelectedIndex != -1)
            {
                programToCheck = SqlCommunication.CheckProgram(comboBoxPrograms.SelectedItem.ToString());
            }
            else
            {
                MessageBox.Show("No program selected", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (startWastingOffset == 0 || startWastingOffset == 0 || wasteOffset == 0 || logo1Tolerance == 0 || logo2Tolerance == 0 || machine == string.Empty)
            {
                MessageBox.Show("Product configuration values not set", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!Directory.Exists(Directory.GetCurrentDirectory() + $"\\Programs\\{comboBoxPrograms.SelectedItem}"))
            {
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + $"\\Programs\\{comboBoxPrograms.SelectedItem}");
            }

            if (!checkBoxCamera1.Checked && !checkBoxCamera2.Checked)
            {
                MessageBox.Show("At least one camera must be activated", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (checkBoxCamera1.Checked)
            {
                if (comboBoxColorsCamera1.SelectedIndex == -1)
                {
                    MessageBox.Show("No color selected for camera 1", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (checkBoxLogoCamera1.Checked)
                {
                    if (numericUpDownLogosCamera1.Value == 0)
                    {
                        MessageBox.Show("Camera 1 logos activated but no logo set", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (numericUpDownLogosCamera1.Value == 1)
                    {
                        if (logo1Camera1RegionCoords[0] == 0 && logo1Camera1RegionCoords[1] == 0 && logo1Camera1RegionCoords[2] == 0 && logo1Camera1RegionCoords[3] == 0)
                        {
                            MessageBox.Show("Logo 1 region not set for camera 1", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else if (numericUpDownLogosCamera1.Value == 2)
                    {
                        if (logo1Camera1RegionCoords[0] == 0 && logo1Camera1RegionCoords[1] == 0 && logo1Camera1RegionCoords[2] == 0 && logo1Camera1RegionCoords[3] == 0)
                        {
                            MessageBox.Show("Logo 1 region not set for camera 1", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        if (logo2Camera1RegionCoords[0] == 0 && logo2Camera1RegionCoords[1] == 0 && logo2Camera1RegionCoords[2] == 0 && logo2Camera1RegionCoords[3] == 0)
                        {
                            MessageBox.Show("Logo 2 region not set for camera 1", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    if (!Directory.Exists(Directory.GetCurrentDirectory() + $@"\Programs\{comboBoxPrograms.SelectedItem}\Camera1"))
                    {
                        Directory.CreateDirectory(Directory.GetCurrentDirectory() + $@"\Programs\{comboBoxPrograms.SelectedItem}\Camera1");
                    }
                    HOperatorSet.RotateImage(hoImageCamera1Rotated, out HObject hImageRotatedCamera1, -90, "constant");

                    HalconProcedures.CreateLogos(hImageRotatedCamera1,
                                                 Directory.GetCurrentDirectory() + $@"\Programs\{comboBoxPrograms.SelectedItem}\Camera1\Logo1.shm",
                                                 Directory.GetCurrentDirectory() + $@"\Programs\{comboBoxPrograms.SelectedItem}\Camera1\Logo2.shm",
                                                 comboBoxColorsCamera1.SelectedItem.ToString().ToLower(),
                                                 Convert.ToInt32(numericUpDownLogosCamera1.Value),
                                                 logo1Camera1RegionCoords[0],
                                                 logo1Camera1RegionCoords[1],
                                                 logo1Camera1RegionCoords[2],
                                                 logo1Camera1RegionCoords[3],
                                                 logo2Camera1RegionCoords[0],
                                                 logo2Camera1RegionCoords[1],
                                                 logo2Camera1RegionCoords[2],
                                                 logo2Camera1RegionCoords[3]);
                }

                if (checkBoxShapeCamera1.Checked)
                {
                    if (comboBoxShapeTypeCamera1.SelectedIndex == -1)
                    {
                        MessageBox.Show("No shape type selected for camera 1", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        shapeTypeCamera1 = comboBoxShapeTypeCamera1.SelectedItem.ToString();
                    }
                }

                if (textBoxOcrCamera1.Text == string.Empty)
                {
                    MessageBox.Show("No OCR text for camera 1", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (checkBoxCamera2.Checked)
            {
                if (comboBoxColorsCamera2.SelectedIndex == -1)
                {
                    MessageBox.Show("No color selected for camera 2", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (checkBoxLogoCamera2.Checked)
                {
                    if (numericUpDownLogosCamera2.Value == 0)
                    {
                        MessageBox.Show("Camera 2 logos activated but no logo set", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else if (numericUpDownLogosCamera2.Value == 1)
                    {
                        if (logo1Camera2RegionCoords[0] == 0 && logo1Camera2RegionCoords[1] == 0 && logo1Camera2RegionCoords[2] == 0 && logo1Camera2RegionCoords[3] == 0)
                        {
                            MessageBox.Show("Logo 1 region not set for camera 2", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else if (numericUpDownLogosCamera2.Value == 2)
                    {
                        if (logo1Camera2RegionCoords[0] == 0 && logo1Camera2RegionCoords[1] == 0 && logo1Camera2RegionCoords[2] == 0 && logo1Camera2RegionCoords[3] == 0)
                        {
                            MessageBox.Show("Logo 1 region not set for camera 2", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        if (logo2Camera2RegionCoords[0] == 0 && logo2Camera2RegionCoords[1] == 0 && logo2Camera2RegionCoords[2] == 0 && logo2Camera2RegionCoords[3] == 0)
                        {
                            MessageBox.Show("Logo 2 region not set for camera 2", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    if (!Directory.Exists(Directory.GetCurrentDirectory() + $@"\Programs\{comboBoxPrograms.SelectedItem}\Camera2"))
                    {
                        Directory.CreateDirectory(Directory.GetCurrentDirectory() + $@"\Programs\{comboBoxPrograms.SelectedItem}\Camera2");
                    }

                    HOperatorSet.RotateImage(hoImageCamera2Rotated, out HObject hImageRotatedCamera2, -90, "constant");

                    HalconProcedures.CreateLogos(hImageRotatedCamera2,
                                                 Directory.GetCurrentDirectory() + $@"\Programs\{comboBoxPrograms.SelectedItem}\Camera2\Logo1.shm",
                                                 Directory.GetCurrentDirectory() + $@"\Programs\{comboBoxPrograms.SelectedItem}\Camera2\Logo2.shm",
                                                 comboBoxColorsCamera2.SelectedItem.ToString().ToLower(),
                                                 Convert.ToInt32(numericUpDownLogosCamera2.Value),
                                                 logo1Camera2RegionCoords[0],
                                                 logo1Camera2RegionCoords[1],
                                                 logo1Camera2RegionCoords[2],
                                                 logo1Camera2RegionCoords[3],
                                                 logo2Camera2RegionCoords[0],
                                                 logo2Camera2RegionCoords[1],
                                                 logo2Camera2RegionCoords[2],
                                                 logo2Camera2RegionCoords[3]);
                }

                if (checkBoxShapeCamera2.Checked)
                {
                    if (comboBoxShapeTypeCamera2.SelectedIndex == -1)
                    {
                        MessageBox.Show("No shape type selected for camera 2", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        shapeTypeCamera2 = comboBoxShapeTypeCamera2.SelectedItem.ToString();
                    }
                }

                if (textBoxOcrCamera2.Text == string.Empty)
                {
                    MessageBox.Show("No OCR text for camera 2", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (programToCheck.Name == null)
            {
                string colorCamera1 = string.Empty;
                string colorCamera2 = string.Empty;

                if (comboBoxColorsCamera1.SelectedIndex != -1)
                {
                    colorCamera1 = comboBoxColorsCamera1.SelectedItem.ToString().ToLower();
                }

                if (comboBoxColorsCamera2.SelectedIndex != -1)
                {
                    colorCamera2 = comboBoxColorsCamera2.SelectedItem.ToString().ToLower();
                }

                SqlCommunication.InsertProgram(comboBoxPrograms.SelectedItem.ToString(),
                                               triggerOffset,
                                               startWastingOffset,
                                               wasteOffset,
                                               colorCamera1,
                                               colorCamera2,
                                               checkBoxCamera1.Checked,
                                               checkBoxCamera2.Checked,
                                               checkBoxLogoCamera1.Checked,
                                               checkBoxLogoCamera2.Checked,
                                               Convert.ToInt32(numericUpDownLogosCamera1.Value),
                                               Convert.ToInt32(numericUpDownLogosCamera2.Value),
                                               $"C:\\Hirschmann\\Hirschmann\\bin\\Debug\\Programs\\{comboBoxPrograms.SelectedItem}\\Camera1\\Logo1.shm".Replace('\\', ' '),
                                               $"C:\\Hirschmann\\Hirschmann\\bin\\Debug\\Programs\\{comboBoxPrograms.SelectedItem}\\Camera1\\Logo2.shm".Replace('\\', ' '),
                                               $"C:\\Hirschmann\\Hirschmann\\bin\\Debug\\Programs\\{comboBoxPrograms.SelectedItem}\\Camera2\\Logo1.shm".Replace('\\', ' '),
                                               $"C:\\Hirschmann\\Hirschmann\\bin\\Debug\\Programs\\{comboBoxPrograms.SelectedItem}\\Camera2\\Logo2.shm".Replace('\\', ' '),
                                               checkBoxShapeCamera1.Checked,
                                               checkBoxShapeCamera2.Checked,
                                               shapeTypeCamera1.ToLower(),
                                               shapeTypeCamera2.ToLower(),
                                               textBoxOcrCamera1.Text.Replace(" ", string.Empty),
                                               textBoxOcrCamera2.Text.Replace(" ", string.Empty)
                                               );

                AddLog($"Manage Programs: Program {comboBoxPrograms.SelectedItem.ToString()} created");
            }
            else
            {
                string colorCamera1 = string.Empty;
                string colorCamera2 = string.Empty;

                if (comboBoxColorsCamera1.SelectedIndex != -1)
                {
                    colorCamera1 = comboBoxColorsCamera1.SelectedItem.ToString().ToLower();
                }

                if (comboBoxColorsCamera2.SelectedIndex != -1)
                {
                    colorCamera2 = comboBoxColorsCamera2.SelectedItem.ToString().ToLower();
                }

                SqlCommunication.UpdateProgramManageProgramsForm(comboBoxPrograms.SelectedItem.ToString(),
                                                                 triggerOffset,
                                                                 startWastingOffset,
                                                                 wasteOffset,
                                                                 colorCamera1,
                                                                 colorCamera2,
                                                                 checkBoxCamera1.Checked,
                                                                 checkBoxCamera2.Checked,
                                                                 checkBoxLogoCamera1.Checked,
                                                                 checkBoxLogoCamera2.Checked,
                                                                 Convert.ToInt32(numericUpDownLogosCamera1.Value),
                                                                 Convert.ToInt32(numericUpDownLogosCamera2.Value),
                                                                 checkBoxShapeCamera1.Checked,
                                                                 checkBoxShapeCamera2.Checked,
                                                                 shapeTypeCamera1.ToLower(),
                                                                 shapeTypeCamera2.ToLower(),
                                                                 textBoxOcrCamera1.Text.Replace(" ", string.Empty),
                                                                 textBoxOcrCamera2.Text.Replace(" ", string.Empty)
                                                                 );

                AddLog($"Manage Programs: Program {comboBoxPrograms.SelectedItem.ToString()} updated");
            }

            Close();
        }
Exemplo n.º 16
0
        public void LoadUsers()
        {
            users = SqlCommunication.GetUsers();

            ShowUsers(users);
        }