private void addButton_Click(object sender, System.EventArgs e)
        {
            DatabaseWorker.AddEmployee(nameTextBox.Text, jobTextBox.Text, addressTextBox.Text, phoneTextBox.Text);

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
        private void addButton_Click(object sender, EventArgs e)
        {
            if (ValidInput())
            {
                string[] scheduleValues = new string[7];

                for (int i = 0; i < 7; i++)
                {
                    scheduleValues[i] = scheduleComboBoxes[i].Text;
                }

                int  id     = random.Next(int.MaxValue);
                bool exists = true;

                while (exists)
                {
                    exists = DatabaseWorker.IdExists(id);
                    if (!exists)
                    {
                        DatabaseWorker.tempId = id;
                        DatabaseWorker.AddEmployee(id, nameTextBox.Text, jobTextBox.Text, addressTextBox.Text, phoneTextBox.Text, scheduleValues);
                    }
                    id = random.Next(int.MaxValue);
                }

                DialogResult = DialogResult.OK;
                Close();
            }
            else
            {
                PrintErrorMessage();
            }
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 40000; i++)
            {
                DatabaseWorker.AddEmployee(RandomString(5), RandomString(5), RandomString(5), RandomString(5), true);
            }

            fec_Main.xmlDoc.Save("fec.xmldb");
            UpdateEmployeeGrid();
        }
        /// <summary>
        /// Add a new employee in the database.
        /// </summary>
        private void AddButton_Click(object sender, EventArgs e)
        {
            if (ValidInput())
            {
                string[] scheduleValues = new string[7];

                // Get combo box schedule values.
                for (int i = 0; i < 7; i++)
                {
                    scheduleValues[i] = scheduleComboBoxes[i].Text;
                }

                string name    = BuildName();
                string address = BuildAddress();

                // Generate a random id.
                int id = random.Next(int.MaxValue);

                // Used to check whether the id alredy exists in the database.
                bool exists = true;

                // Loop until a non-existent id is generated.
                while (exists)
                {
                    exists = DatabaseWorker.IdExists(id);
                    if (!exists)
                    {
                        DatabaseWorker.tempId = id;
                        DatabaseWorker.AddEmployee(id, name, jobTextBox.Text.Trim(' '), address, phoneTextBox.Text, scheduleValues);
                    }
                    id = random.Next(int.MaxValue);
                }

                DialogResult = DialogResult.OK;
                Close();
            }
            else
            {
                PrintErrorMessage();
            }
        }