Ejemplo n.º 1
0
        private void Button1_Click(object sender, EventArgs e)
        {
            connection = new SqlConnection();
            command    = new SqlCommand();
            connection.ConnectionString = "server=.;initial catalog=MANAGER;integrated security=true";
            command.Connection          = connection;
            connection.Open();
            SqlCommand cmd = new SqlCommand(" select ad_ID FROM Addmin Where ad_username=@ad_username and ad_password =@ad_password ", connection);

            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("@ad_username", textBox1.Text);
            cmd.Parameters.AddWithValue("@ad_password", textBox2.Text);
            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.Read())
            {
                this.Visible = false;
                Managment obj2 = new Managment();
                obj2.ShowDialog();
            }
            else
            {
                MessageBox.Show("invalid username or password.....try again");
            }
            connection.Close();
        }
Ejemplo n.º 2
0
        private void Button3_Click(object sender, EventArgs e)
        {
            connection = new SqlConnection();
            command    = new SqlCommand();
            connection.ConnectionString = "server=.;initial catalog=MANAGER;integrated security=true";
            command.Connection          = connection;
            connection.Open();

            try
            {
                SqlCommand cmd = new SqlCommand("insert into Employee(em_username , em_password , em_fullname,task )values( @em_username , @em_password , @em_fullname,@task  ) ", connection);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@em_username", textBox2.Text);
                cmd.Parameters.AddWithValue("em_fullname", textBox1.Text);
                cmd.Parameters.AddWithValue("@em_password ", textBox3.Text);
                cmd.Parameters.AddWithValue("@task  ", textBox4.Text);

                int i = cmd.ExecuteNonQuery();
                if (i > 0)
                {
                    MessageBox.Show("account created seccessfuly");
                    SqlCommand    cmd1 = new SqlCommand("select max(em_ID) from Employee", connection);
                    SqlDataReader dr1  = cmd1.ExecuteReader();
                    if (dr1.Read())
                    {
                        MessageBox.Show("dear Employee ,your id is  '" + dr1.GetInt32(0) + "' your registetration seccessfullt");
                        this.Hide();
                        Managment obj2 = new Managment();
                        obj2.ShowDialog();
                    }
                    connection.Close();
                }
                else
                {
                    MessageBox.Show("account not created ");
                }
                connection.Close();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }