Exemple #1
0
        private void addButton_Click(object sender, EventArgs e)
        {
            bool passwordStrong = true;

            if (string.IsNullOrWhiteSpace(passwordTextBox.Text) || !FormatChecker.checkPasswdFormat(passwordTextBox.Text))
            {
                passwordHintLabel.ForeColor = Color.Red;
                passwordStrong = false;
            }
            else
            {
                passwordHintLabel.ForeColor = SystemColors.ControlText;
            }

            if (isInputCorrect() && passwordStrong)
            {
                Supplier sup = new Supplier();
                sup.setSupplierID(idTextBox.Text);
                sup.setSupplierName(supplierNameTextBox.Text);
                sup.setContectNo(supplierContactNoTextBox.Text);
                sup.setEmail(emailTextBox.Text);
                sup.setAddress(supplierAddressTextBox.Text);
                sup.setPassword(Security.getHash(passwordTextBox.Text, "SHA512", null));
                if (perfumeRadioButton.Checked)
                {
                    sup.setProductCategory("Perfume");
                }
                else if (packageRadioButton.Checked)
                {
                    sup.setProductCategory("Package");
                }
                else if (bottleRadioButton.Checked)
                {
                    sup.setProductCategory("Bottle");
                }

                int i = sda.insert(sup, conn);
                if (i > 0)
                {
                    supplierListDataGridView.Rows.Add(false, sup.getSupplierID(), sup.getSupplierName(),
                                                      ((sup.getProductCategory().Equals("Perfume")) ? rs.GetString("perfumeText") : ((sup.getProductCategory().Equals("Package")) ? rs.GetString("packageText") : rs.GetString("bottleText"))),
                                                      sup.getContectNo(), sup.getEmail(), sup.getAddress());

                    supplierListDataGridView.ClearSelection();
                    foreach (DataGridViewRow row in supplierListDataGridView.Rows)
                    {
                        if (idTextBox.Text.Equals(row.Cells["supplierIDColumn"].Value.ToString()))
                        {
                            row.Selected = true;
                            supplierListDataGridView.FirstDisplayedScrollingRowIndex = row.Index;
                        }
                    }

                    deleteButton.Enabled      = true;
                    deselectAllButton.Enabled = true;
                    selectAllButton.Enabled   = true;

                    addButton.Enabled        = false;
                    updateButton.Enabled     = true;
                    staffIdHintLabel.Visible = false;

                    MessageBox.Show(rs.GetString("addSuccessMsg"));
                }
                else
                {
                    MessageBox.Show(rs.GetString("failToAddMsg"), rs.GetString("errorText"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }