コード例 #1
0
ファイル: SaveForm.cs プロジェクト: SerjChaoz/rad_a4
        private void SaveButton_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    // create writer
                    StreamWriter writer = new StreamWriter("Name2s.txt", true);
                    writer.WriteLine(FirstNameTextBox.Text + " " + LastNameTextBox.Text);

                    // close connections
                    writer.Close();

                    // reset the form fields
                    FirstNameTextBox.Clear();
                    LastNameTextBox.Clear();

                    FirstNameTextBox.Focus();
                }
                else
                {
                    FirstNameTextBox.Focus();
                    FirstNameTextBox.SelectAll();
                }
            } catch
            {
                Console.WriteLine("problems");
            }
        }
コード例 #2
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                // Step 1 - Open a stream
                StreamWriter writer = new StreamWriter("Names.txt", true);

                // Step 2 - Write to the buffer
                writer.WriteLine(FirstNameTextBox.Text + " " + LastNameTextBox.Text);

                // Step 3 - Close the file
                writer.Close();

                //Step 4 - Reset the Form
                FirstNameTextBox.Clear();
                LastNameTextBox.Clear();
                FirstNameTextBox.Focus();
            }
            else
            {
                FirstNameTextBox.Focus();
                FirstNameTextBox.SelectAll();
            }
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: Nilzor/wf4-rule-engine
        private void PerformSalutation()
        {
            _person.Salutation = String.Empty; // Reset
            personBindingSource.ResetBindings(false);
            if (_person.Name == String.Empty || _person.Firstname == String.Empty)
            {
                MessageBox.Show("Enter both the firstname and name of the person.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                FirstNameTextBox.Focus();
                FirstNameTextBox.SelectAll();
                return;
            }

            // Execute rules
            try
            {
                var ruleExecuter = new RuleSetInvoker();
                if (_settings.Source == RuleSource.CodedDynamic)
                {
                    ruleExecuter.PerformDynamicRules(_person, _settings.Rules);
                }
                else if (_settings.Source == RuleSource.CodedStatic)
                {
                    ruleExecuter.PerformCodedRules(_person);
                }
                else
                {
                    ruleExecuter.PerformDesignerRules(_person);
                }
                personBindingSource.ResetBindings(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void FirstNameTextBox_Leave(object sender, EventArgs e)
 {
     if (FirstNameTextBox.TextLength < 2)
     {
         FirstNameTextBox.Focus();
         FirstNameTextBox.SelectAll();
     }
 }
コード例 #5
0
        public bool ValidateEdition()
        {
            String errors      = "";
            String line        = "";
            bool   focusSetted = false;

            if (String.IsNullOrWhiteSpace(NameTextBox.Text) && String.IsNullOrWhiteSpace(FirstNameTextBox.Text))
            {
                errors += line + "Name and first name can't be empty.";
                line    = "\n";
                if (!focusSetted)
                {
                    if (String.IsNullOrWhiteSpace(NameTextBox.Text))
                    {
                        NameTextBox.Focus();
                        NameTextBox.SelectAll();
                    }
                    else
                    {
                        FirstNameTextBox.Focus();
                        FirstNameTextBox.SelectAll();
                    }
                    focusSetted = true;
                }
            }

            if (String.IsNullOrWhiteSpace(EmailTextBox.Text))
            {
                //errors += line + "Email can't be empty.";
                //line = "\n";
                //if (!focusSetted)
                //{
                //    EmailTextBox.Focus();
                //    EmailTextBox.SelectAll();
                //    focusSetted = true;
                //}
            }
            else if (!UserUtil.validateEmail(EmailTextBox.Text))
            {
                errors += line + "Wrong email format.";
                line    = "\n";
                if (!focusSetted)
                {
                    EmailTextBox.Focus();
                    EmailTextBox.SelectAll();
                    focusSetted = true;
                }
            }

            if (String.IsNullOrWhiteSpace(LoginTextBox.Text))
            {
                errors += line + "Login can't be empty.";
                line    = "\n";
                if (!focusSetted)
                {
                    LoginTextBox.Focus();
                    LoginTextBox.SelectAll();
                    focusSetted = true;
                }
            }

            if (String.IsNullOrWhiteSpace(PasswordTextBox.Password))
            {
                errors += line + "Password can't be empty.";
                line    = "\n";
                if (!focusSetted)
                {
                    PasswordTextBox.Focus();
                    PasswordTextBox.SelectAll();
                    focusSetted = true;
                }
            }
            else if (!Util.UserUtil.validatePassword(PasswordTextBox.Password, ConfirmPasswordTextBox.Password))
            {
                errors += line + "Password does not match.";
                line    = "\n";
                if (!focusSetted)
                {
                    ConfirmPasswordTextBox.Focus();
                    ConfirmPasswordTextBox.SelectAll();
                    focusSetted = true;
                }
            }
            bool isValid = String.IsNullOrWhiteSpace(errors);

            this.Console.Text       = errors;
            this.Console.Visibility = isValid ? Visibility.Collapsed : Visibility.Visible;
            return(isValid);
        }