Ejemplo n.º 1
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            SqlCeConnection Connection = DataBaseConnection.Instance.Connection;

            try
            {
                if (NameTextBox.Text == "")
                {
                    MessageBox.Show("Unesite ime!");
                }
                else if (SurNameTextBox.Text == "")
                {
                    MessageBox.Show("Unesite prezime!");
                }


                else
                {
                    bool isUnique = UserRepository.CheckUnique(NameTextBox.Text);

                    if (isUnique != true)
                    {
                        UserRepository.InsertUser(NameTextBox.Text, NameTextBox.Text + SurNameTextBox.Text);
                        int AdminId = UserRepository.GetIdByName(NameTextBox.Text);

                        SqlCeCommand command = new SqlCeCommand("INSERT INTO Administrator (Name, SurName, User_Id) VALUES" + " ('" + NameTextBox.Text + "', '" + SurNameTextBox.Text + "', '" + AdminId + "'); ", Connection);

                        command.ExecuteNonQuery();

                        MessageBox.Show("Unos je uspio!");
                        NameTextBox.Clear();
                        SurNameTextBox.Clear();
                        NameTextBox.Focus();
                    }
                }
            }

            catch (Exception ee)
            {
                MessageBox.Show("Unos nije uspio! \r Greska: " + ee.Message);
                return;
            }
        }
Ejemplo n.º 2
0
        public void SurNameTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            string namePattern = @"[а-я]";

            var surNameIsMatch = Regex.IsMatch(SurNameTextBox.Text, namePattern);

            if (String.IsNullOrEmpty(SurNameTextBox.Text))
            {
                e.Cancel = true;
                SurNameTextBox.Focus();
                ErrorProvider.SetError(SurNameTextBox, "Укажите фамилию");
            }
            else if (surNameIsMatch == false)
            {
                e.Cancel = true;
                SurNameTextBox.Focus();
                ErrorProvider.SetError(SurNameTextBox, "Недопустимый формат");
            }
            else
            {
                e.Cancel = false;
                ErrorProvider.SetError(SurNameTextBox, null);
            }
        }