コード例 #1
0
        /// <summary>
        /// Handles the Click event of the finishButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void finishButton_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "")
            {
                MessageBox.Show("Заповніть обов'язкові поля, що позначені знаком *");
            }
            else
            {
                if (isLoginDuplicated())
                {
                    MessageBox.Show("Такий логін вже існує!");
                }
                else
                {
                    try
                    {
                        connection1.Open();
                        OleDbCommand command = new OleDbCommand("INSERT INTO [Employees](LastName,FirstName,Patronymic,Profession,DateOfBirth,Salary,PreviousEmployment,Login,Passwordd)"
                                                                + "Values(@lname,@fname,@patr,@prof,@dateBir,@salary,@prevEmploy,@log,@passw)", connection1);

                        command.Parameters.AddWithValue("@lname", textBox3.Text);
                        command.Parameters.AddWithValue("@fname", textBox4.Text);
                        command.Parameters.AddWithValue("@patr", textBox5.Text);
                        command.Parameters.AddWithValue("@prof", textBox6.Text);
                        command.Parameters.AddWithValue("@dateBir", dateTimePicker1.Value.Date.ToString());
                        command.Parameters.AddWithValue("@salary", trackBar1.Value);
                        command.Parameters.AddWithValue("@prevEmploy", textBox7.Text);
                        command.Parameters.AddWithValue("@log", textBox1.Text);
                        command.Parameters.AddWithValue("@passw", textBox2.Text);
                        int result = command.ExecuteNonQuery();

                        if (result > 0)
                        {
                            Debug.WriteLine("Ok");
                        }
                        else
                        {
                            MessageBox.Show("Ви не можете змінювати значення стовбців таблиць в Employees.mdb\nЯкщо ви змінили іх, поверніть попереднє значення.");
                        }

                        connection1.Close();

                        command = new OleDbCommand("SELECT EmpNumber,Login FROM Employees WHERE Login = '******'", connection1);//
                        connection1.Open();
                        OleDbDataReader reader = command.ExecuteReader();
                        reader.Read();
                        PersonalAccount acc = new PersonalAccount(Convert.ToInt32(reader[0]));
                        connection1.Close();
                        acc.Show();
                        this.Close();
                    }
                    catch (Exception r)
                    {
                        MessageBox.Show(r.ToString());
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Handles the Click event of the button1 control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         OleDbCommand command = new OleDbCommand("SELECT EmpNumber,Login,Passwordd FROM Employees WHERE Login = '******'", connection); //WHERE Login = "******"Невірний логін або пароль");
     }
     connection.Close();
 }