Ejemplo n.º 1
0
        void generatePassword()
        {
            string Username = textUsername1.Text.Trim();
            string Password = textPassword.Text.Trim();

            User user = new User();

            Cursor.Current = Cursors.WaitCursor;

            if (String.IsNullOrEmpty(Username) || String.IsNullOrEmpty(Password))
            {
                MessageBox.Show("Please fill all given fields!");
            }
            else
            {
                string position = null;
                string pos_id   = null;
                //call function login
                user = User.login(Username, Password, position, pos_id);

                mform pt = null; //not create object
                pt = new mform();

                //if match
                if (Username == user.username && Password == user.password)
                {
                    if (user.position == "cashier")
                    {
                        getid.Text = user.pos_id;

                        string query1 = "SELECT * FROM user_information WHERE  user_id=" + getid.Text + " ";


                        Cmd = new MySqlCommand(query1, connection);

                        connection.Open();

                        //execute reader
                        reader = Cmd.ExecuteReader();

                        if (reader.Read())
                        {
                            getid.Text = reader.GetString("firstname").ToString();

                            POS ca = new POS(getid.Text, atime.Text);
                            ca.Show();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("Wrong Username or Password", "Wrong", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                        }
                        reader.Close();

                        connection.Close();
                    }
                    else if (user.position == "admin")
                    {
                        getid.Text = user.pos_id;

                        string query1 = "SELECT * FROM user_information WHERE  user_id=" + getid.Text + " ";


                        Cmd = new MySqlCommand(query1, connection);

                        connection.Open();

                        //execute reader
                        reader = Cmd.ExecuteReader();

                        if (reader.Read())
                        {
                            getid.Text = reader.GetString("firstname").ToString();

                            InventoryForm form = new InventoryForm(getid.Text, atime.Text);
                            form.Show();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("Wrong Username or Password", "Wrong", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                        }
                        reader.Close();

                        connection.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Wrong Username or Password", "Wrong", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    textPassword.Text = "";
                    if (textPassword.Text == "")
                    {
                        lblhint.Visible = true;
                    }
                    else
                    {
                        lblhint.Visible = false;
                    }
                }
            }
        }