Exemplo n.º 1
0
        private async void updateUsersList()
        {
            try
            {
                FirebaseResponse resp = await client.GetTaskAsync("posUsers/");

                Dictionary <string, Pos_Users> dict = resp.ResultAs <Dictionary <string, Pos_Users> >();



                //Adding product keys to Array Keys
                foreach (KeyValuePair <string, Pos_Users> ele1 in dict)
                {
                    keys.Add(ele1.Key);
                }

                //traversing list keys to fetch product details
                for (int i = 0; i < keys.Count; i++)
                {
                    FirebaseResponse resp2 = await client.GetTaskAsync("posUsers/" + keys[i]);

                    Pos_Users user = resp2.ResultAs <Pos_Users>();
                    usersList.Add(user);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("No Users Exist Already.");
            }
        }
Exemplo n.º 2
0
        private async void button1_Click(object sender, EventArgs e)

        {
            bool check = false;

            for (int i = 0; i < usersList.Count; i++)
            {
                if (name_editText.Text == usersList[i].name && pw_editText.Text == usersList[i].password)
                {
                    check = true;

                    loggedInUser = new Pos_Users()
                    {
                        name     = usersList[i].name,
                        password = usersList[i].password,
                        role     = usersList[i].role
                    };

                    MessageBox.Show("Logged in Successfully");

                    Home Home = new Home(); //this is the change, code for redirect
                    Home.Show();
                    Hide();

                    break;
                }
            }
            if (!check)
            {
                MessageBox.Show("Wrong username or password.");
            }
        }
Exemplo n.º 3
0
        private async void update_btn_Click(object sender, EventArgs e)
        {
            if (name_editText.Text != "" && password_editText.Text != "")
            {
                string role;
                if (role_list.SelectedIndex == 0)
                {
                    role = "Cashier";
                }
                else
                {
                    role = "Admin";
                }
                try
                {
                    Pos_Users user = new Pos_Users
                    {
                        name     = name_editText.Text,
                        password = password_editText.Text,
                        role     = role
                    };

                    FirebaseResponse response = await client.UpdateTaskAsync("posUsers/" + keys[selectedRow], user);

                    //setting values to default
                    name_editText.Text     = "";
                    password_editText.Text = "";


                    MessageBox.Show("Updated Successfully!");
                }

                catch (Exception)
                {
                    MessageBox.Show("Update Failed");
                }
            }
        }
Exemplo n.º 4
0
        private async void add_btn_Click(object sender, EventArgs e)
        {
            if (name_editText.Text != "" && password_editText.Text != "")
            {
                int    temp = role_list.SelectedIndex;
                string role;
                //cashier is selected
                if (temp == 0)
                {
                    role = "Cashier";
                }
                else
                {
                    role = "Admin";
                }

                Pos_Users user = new Pos_Users()
                {
                    name     = name_editText.Text,
                    password = password_editText.Text,
                    role     = role
                };
                try
                {
                    PushResponse response = await client.PushTaskAsync("posUsers", user);

                    Pos_Users result = response.ResultAs <Pos_Users>();

                    usersList.Add(user);

                    FirebaseResponse resp = await client.GetTaskAsync("posUsers/");

                    Dictionary <string, Pos_Users> dict = resp.ResultAs <Dictionary <string, Pos_Users> >();

                    //Adding new key to keys array
                    foreach (KeyValuePair <string, Pos_Users> ele1 in dict)
                    {
                        if (!keys.Contains(ele1.Key))
                        {
                            keys.Add(ele1.Key);
                            break;
                        }
                    }

                    //adding new row to DT
                    DataRow row = dt.NewRow();
                    row["Name"]     = user.name;
                    row["Password"] = user.password;
                    row["Role"]     = user.role;

                    dt.Rows.Add(row);
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed to connect to database. Check your internet connection and try again.");
                }
            }
            else
            {
                MessageBox.Show("Please fill the fields first.");
            }
        }