Пример #1
0
 private void button4_Click(object sender, EventArgs e)
 {
     this.Hide();
     var formadmin = new FormAdminPage();
     formadmin.Closed += (s, args) => this.Close();
     formadmin.Show();
 }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string pass, name;
            int? id;
            try
            {
                //id
                id = int.Parse(textBox1.Text);
                if (id == null)
                {
                    MessageBox.Show("Enter Id !!");
                }
                Console.WriteLine("id {0}", id);
                //password
                pass = textBox3.Text;
                if (pass == null)
                {
                    MessageBox.Show("Enter Password !!");
                }
                Console.WriteLine("password {0}", pass);
                //name
                name = textBox3.Text;
                if (name == null)
                {
                    MessageBox.Show("Enter Name !!");
                }
                Console.WriteLine("name {0}", name);

                if (id != null && pass != null && name != null)
                {
                    string cs = @"server=localhost;userid=root;password=1234;database=dairy_mgmt";
                    Console.WriteLine("inside");
                    MySqlConnection conn = null;

                    try
                    {
                        conn = new MySqlConnection(cs);
                        conn.Open();
                        MySqlCommand cmd = new MySqlCommand();
                        cmd.Connection = conn;
                        cmd.CommandText = "INSERT INTO admin VALUES (?admin_id, ?name, ?pwd) ;";
                        cmd.Parameters.AddWithValue("?admin_id", id);
                        cmd.Parameters.AddWithValue("?name", name);
                        cmd.Parameters.AddWithValue("?pwd", pass);
                        Console.WriteLine("in1");
                        Console.WriteLine("MySQL version : {0}", conn.ServerVersion);
                        try
                        {
                            cmd.ExecuteScalar();
                            MessageBox.Show("New Admin Added!!");
                        }
                        catch (Exception ex) { Console.WriteLine("Exception : {0}", ex); }

                    }
                    catch (MySqlException ex)
                    {
                        MessageBox.Show("Failed!!");
                        Console.WriteLine("Error: {0}", ex.ToString());

                    }
                    finally
                    {
                        if (conn != null)
                        {
                            conn.Close();
                        }
                    }
                    this.Hide();
                    var form = new FormAdminPage();
                    form.Closed += (s, args) => this.Close();
                    form.Show();

                }
            }
            catch
            {
                MessageBox.Show("Enter valid Entries !!");
            }
        }
Пример #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            string pass;
            int? id;

            try
            {
                id = int.Parse(textBox1.Text);
                if (id == null)
                {
                    MessageBox.Show("Enter Id !!");
                }
                Console.WriteLine("id {0}",id);
                pass = textBox2.Text;
                if (pass == null)
                {
                    MessageBox.Show("Enter Password !!");
                }
                Console.WriteLine("password {0}", pass);
                if (id != null && pass != null)
                {
                    string cs = @"server=localhost;userid=root;password=1234;database=dairy_mgmt";
                    Console.WriteLine("inside");
                    MySqlConnection conn = null;

                    try
                    {
                        conn = new MySqlConnection(cs);
                        conn.Open();
                        //to insert data or run commands
                        //string sql = "SELECT admin_id FROM admin WHERE admin_id = id AND pwd = pass ;";
                        //MySqlScript script = new MySqlScript(conn, sql);
                        // Create Command
                        MySqlCommand cmd = new MySqlCommand();
                        cmd.Connection = conn;
                        cmd.CommandText = "SELECT admin_id FROM admin WHERE admin_id = ?id AND pwd = ?pass ;";
                        cmd.Parameters.AddWithValue("?id", id);
                        cmd.Parameters.AddWithValue("?pass", pass);
                        Console.WriteLine("in1");
                        try {
                            admin_id_g = (int)(cmd.ExecuteScalar()); }
                        catch (Exception ex) { Console.WriteLine("Exception : {0}", ex); }

                        Console.WriteLine("MySQL version : {0}", conn.ServerVersion);

                        //to show data
                        //MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM admin;", conn);
                        //DataSet ds = new DataSet();
                        //da.Fill(ds);
                        //dataGridView1.DataSource = ds.Tables[0];

                    }
                    catch (MySqlException ex)
                    {
                        Console.WriteLine("Error: {0}", ex.ToString());

                    }
                    finally
                    {
                        if (conn != null)
                        {
                            conn.Close();
                        }
                    }
                }
                if (admin_id_g == null)
                {
                    MessageBox.Show("INVALID USER!!");
                }
                else {
                    this.Hide();
                    var form = new FormAdminPage();
                    form.Closed += (s, args) => this.Close();
                    form.Show();
                }
            }
            catch {
                MessageBox.Show("Enter valid Id !!");
            }

            //id = int.Parse(textBox1.Text);
        }