private void btnUpdateAddress_Click(object sender, EventArgs e)
        {
            try
            {
                string query = $"SELECT user_id FROM appuser WHERE username = '******';";

                var dt      = Connection_DB.ExecuteQuery(query);
                var dr      = dt.Rows[0];
                var user_id = Convert.ToInt32(dr[0].ToString());


                string updateAddress = $"UPDATE address " +
                                       $"SET address = '{txtAddress_Update.Text}' " +
                                       $"WHERE address = '{cmbAddress_Update.SelectedItem}' " +
                                       $"AND user_id = '{user_id}';";

                Connection_DB.ExecuteNonQuery(updateAddress);

                MessageBox.Show("¡Direccion agregada exitosamente!",
                                "Hugo App", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("Ha ocurrido un error...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnDeleteAddress_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("¿Seguro que desea eliminar la direccion selecionada?",
                                    "Hugo App", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    string query = $"SELECT user_id FROM appuser WHERE username = '******';";

                    var dt      = Connection_DB.ExecuteQuery(query);
                    var dr      = dt.Rows[0];
                    var user_id = Convert.ToInt32(dr[0].ToString());

                    string deleteAddress = $"DELETE FROM address " +
                                           $"WHERE user_id = '{user_id}';";

                    Connection_DB.ExecuteNonQuery(deleteAddress);

                    MessageBox.Show("¡Direccion eliminada exitosamente!",
                                    "Hugo App", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Ha ocurrido un error...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void AddressForm_Load(object sender, EventArgs e)
        {
            // Obteniendo los usuarios
            var users      = Connection_DB.ExecuteQuery("SELECT username FROM appuser");
            var usersCombo = new List <string>();

            foreach (DataRow dr in users.Rows)
            {
                usersCombo.Add(dr[0].ToString());
            }

            cmbUser_Add.DataSource          = usersCombo;
            cmbUser_Update.DataSource       = usersCombo;
            cmbChooseUser_Delete.DataSource = usersCombo;

            // Obteniendo ID del usuario
            string query = $"SELECT user_id FROM appuser WHERE username = '******';";

            var dT      = Connection_DB.ExecuteQuery(query);
            var dR      = dT.Rows[0];
            var user_id = Convert.ToInt32(dR[0].ToString());

            // Obteniendo los address dependiendo del user_id
            var address      = Connection_DB.ExecuteQuery($"SELECT address FROM address WHERE user_id = '{user_id}';");
            var addressCombo = new List <string>();

            foreach (DataRow dr in address.Rows)
            {
                addressCombo.Add(dr[0].ToString());
            }

            cmbAddress_Update.DataSource = addressCombo;
            cmbAddress_Delete.DataSource = addressCombo;
        }
Example #4
0
        private void btnViewOrders_Click(object sender, EventArgs e)
        {
            try
            {
                string queryUserId = $"SELECT user_id FROM appuser WHERE username = '******';";

                var dt      = Connection_DB.ExecuteQuery(queryUserId);
                var dr      = dt.Rows[0];
                var user_id = Convert.ToInt32(dr[0].ToString());

                string query = $"SELECT ao.order_id AS id_orden, ao.create_date AS fecha, pro.name AS producto, au.fullname AS usuario, " +
                               $"ad.address AS direccion " +
                               $"FROM apporder AS ao, address AS ad, product AS pro, appuser AS au " +
                               $"WHERE ao.address_id = ad.address_id " +
                               $"AND ad.user_id = au.user_id " +
                               $"AND au.user_id = '{user_id}';";

                var viewOrders = Connection_DB.ExecuteQuery(query);

                dataGridView1.DataSource = viewOrders;

                MessageBox.Show("¡Datos obtenidos exitosamente!",
                                "Hugo App", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("Ha ocurrido un error...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #5
0
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            if (txtFullname.Text.Equals("") ||
                txtUsername.Text.Equals(""))
            {
                MessageBox.Show("No se pueden dejar campo(s) en vacio...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                try
                {
                    Connection_DB.ExecuteNonQuery($"INSERT INTO appuser(fullname, username, password, user_type) VALUES(" +
                                                  $"'{txtFullname.Text}', " +
                                                  $"'{txtUsername.Text}', " +
                                                  $"'{txtUsername.Text}', " +
                                                  $"'{SetAdmin()}');");

                    MessageBox.Show("Usuario agregado exitosamente!", "Hugo App", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #6
0
        private void OrderForm_Load(object sender, EventArgs e)
        {
            try
            {
                string addressQuery = "SELECT address FROM address";
                var    address      = Connection_DB.ExecuteQuery(addressQuery);
                var    addressCombo = new List <string>();

                foreach (DataRow dr in address.Rows)
                {
                    addressCombo.Add(dr[0].ToString());
                }

                cmbAddress.DataSource = addressCombo;

                string productQuery = "SELECT name FROM product";
                var    product      = Connection_DB.ExecuteQuery(productQuery);
                var    productCombo = new List <string>();

                foreach (DataRow dr in product.Rows)
                {
                    productCombo.Add(dr[0].ToString());
                }

                cmbChooseProduct.DataSource = productCombo;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #7
0
        private void btnAddOrder_Click_1(object sender, EventArgs e)
        {
            try
            {
                // Obtenuiendo ID del producto
                string queryProductId = $"SELECT product_id FROM product WHERE name = '{cmbChooseProduct.SelectedItem}';";
                var    DT             = Connection_DB.ExecuteQuery(queryProductId);
                var    DR             = DT.Rows[0];
                var    product_id     = Convert.ToInt32(DR[0].ToString());

                // Obteniendo el ID del address
                string queryAddressId = $"SELECT address_id FROM address WHERE address = '{cmbAddress.SelectedItem}'";
                var    dt             = Connection_DB.ExecuteQuery(queryAddressId);
                var    dr             = dt.Rows[0];
                var    address_id     = Convert.ToInt32(dr[0].ToString());

                //Insertando los datos
                string addOrder = $"INSERT INTO apporder (create_date, product_id, address_id) " +
                                  $"VALUES ('{dtpDate.Value}', '{product_id}', '{address_id}');";

                Connection_DB.ExecuteNonQuery(addOrder);

                MessageBox.Show("¡Orden agregada exitosamente!",
                                "Hugo App", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("Ha ocurrido un error...", "Mensaje de Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void BussinessMaintenanceForm_Load(object sender, EventArgs e)
        {
            var bussiness      = Connection_DB.ExecuteQuery("SELECT name FROM bussiness");
            var bussinessCombo = new List <string>();

            foreach (DataRow dr in bussiness.Rows)
            {
                bussinessCombo.Add(dr[0].ToString());
            }

            cmbBussiness.DataSource = bussinessCombo;
        }
Example #9
0
        private void ChangePassword_Load(object sender, EventArgs e)
        {
            var users      = Connection_DB.ExecuteQuery("SELECT username FROM appuser");
            var usersCombo = new List <string>();

            foreach (DataRow dr in users.Rows)
            {
                usersCombo.Add(dr[0].ToString());
            }

            cmbUser.DataSource = usersCombo;
        }
Example #10
0
        private bool IsAdmin()
        {
            string checkAdmin = $"SELECT count(*) FROM appuser WHERE username = '******' and user_type = true";

            var dt    = Connection_DB.ExecuteQuery(checkAdmin);
            var dr    = dt.Rows[0];
            var admin = Convert.ToString(dr[0]);

            if (admin == "1")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #11
0
        private void btnUpdatePassword_Click(object sender, EventArgs e)
        {
            if (txtCurrentPassword.Text.Equals("") ||
                txtNewPassword.Text.Equals("") ||
                txtConfirmPassword.Text.Equals(""))
            {
                throw new BlankSpaceException("No se pueden dejar espacios en blanco.");
            }
            else
            {
                string checkPassword = $"SELECT password FROM appuser WHERE username = '******'";

                var dt       = Connection_DB.ExecuteQuery(checkPassword);
                var dr       = dt.Rows[0];
                var password = Convert.ToString(dr[0]);

                string updatePassword = $"UPDATE appuser SET password = '******' " +
                                        $"WHERE username = '******';";

                if (txtCurrentPassword.Text == password)
                {
                    if (txtNewPassword.Text == txtConfirmPassword.Text)
                    {
                        Connection_DB.ExecuteNonQuery(updatePassword);

                        MessageBox.Show("¡Contrasena actualizada exitosamente!",
                                        "Segundo Pre Examen Parcial", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        Form1 window = new Form1();
                        window.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("La nueva contrasena y su confirmacion, no coinciden.",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Contrasena Incorrecta.\nLa contrasena actual no coincide con el usuario.",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void btnViewOrders_Click(object sender, EventArgs e)
        {
            try
            {
                string query = "SELECT * FROM appuser;";

                var viewOrders = Connection_DB.ExecuteQuery(query);

                dataGridView1.DataSource = viewOrders;

                MessageBox.Show("¡Datos obtenidos exitosamente!",
                                "Hugo App", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("Ha ocurrido un error...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("¿Seguro que desea eliminar el negocio " + cmbDeleteProduct.Text + "?",
                                "Pre Segundo Examen Parcial 2", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                string queryProductId = $"SELECT product_id FROM product WHERE name = '{cmbDeleteProduct.SelectedItem}';";
                var    DT             = Connection_DB.ExecuteQuery(queryProductId);
                var    DR             = DT.Rows[0];
                var    product_id     = Convert.ToInt32(DR[0].ToString());

                string deleteProduct = $"DELETE FROM product WHERE product_id = '{product_id}';";

                Connection_DB.ExecuteNonQuery(deleteProduct);

                MessageBox.Show("¡Producto eliminado exitosamente!",
                                "Pre Segundo Examen Parcial 2", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #14
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            if (txtPassword.Text.Equals(""))
            {
                throw new BlankSpaceException("No se puede dejar espacios en blanco");
            }
            else
            {
                string checkPassword = $"SELECT password FROM appuser WHERE username = '******'";

                var dt       = Connection_DB.ExecuteQuery(checkPassword);
                var dr       = dt.Rows[0];
                var password = Convert.ToString(dr[0]);


                if (txtPassword.Text == password)
                {
                    if (IsAdmin())
                    {
                        MessageBox.Show("¡Bienvenido administrador, " + cmbUser.SelectedItem + "!",
                                        "Segundo Pre Examen Parcial", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        AdminForm ventana = new AdminForm();
                        ventana.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("¡Bienvenido usuario, " + cmbUser.SelectedItem + "!",
                                        "Segundo Pre Examen Parcial", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        UserForm ventana = new UserForm();
                        ventana.Show();
                        this.Hide();
                    }
                }
                else
                {
                    MessageBox.Show("Contrasena Incorrecta", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #15
0
        private void btnDeleteUser_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("¿Seguro que desea eliminar al usuario " + cmbDeleteUser.SelectedItem + "?",
                                    "Pre Segundo Examen Parcial 2", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    string NonQuery = $"DELETE FROM appuser WHERE username = '******'";

                    Connection_DB.ExecuteNonQuery(NonQuery);

                    MessageBox.Show("¡Usuario eliminado exitosamente!",
                                    "Hugo App", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Ha ocurrido un error...", "Mensaje de Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnDeleteBussiness_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("¿Seguro que desea eliminar el negocio " + cmbBussiness.Text + "?",
                                    "Hugo App", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    string NonQuery = $"DELETE FROM bussiness WHERE name = '{cmbBussiness.SelectedItem}';";

                    Connection_DB.ExecuteNonQuery(NonQuery);

                    MessageBox.Show("¡Negocio eliminado exitosamente!",
                                    "Hugo App", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Ha ocurrido un error...", "Mensaje de Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #17
0
        private void btnAddOrder_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Equals(""))
            {
                throw new BlankSpaceException("No se pueden dejar espacios en blanco.");
            }
            else
            {
                if (MessageBox.Show("¿Seguro que desea eliminar el pedido?",
                                    "Hugo App", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    string NonQuery = $"DELETE FROM apporder WHERE order_id = '{textBox1.Text}'";

                    Connection_DB.ExecuteNonQuery(NonQuery);

                    MessageBox.Show("¡Orden eliminada exitosamente!",
                                    "Hugo App", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            try
            {
                string queryBussinessId = $"SELECT bussiness_id FROM bussiness WHERE name = '{cmbBussiness.SelectedItem}';";
                var    DT           = Connection_DB.ExecuteQuery(queryBussinessId);
                var    DR           = DT.Rows[0];
                var    bussiness_id = Convert.ToInt32(DR[0].ToString());

                string addProduct = $"INSERT INTO product (bussiness_id, name) " +
                                    $"VALUES ('{bussiness_id}', '{txtProduct.Text}');";

                Connection_DB.ExecuteNonQuery(addProduct);

                MessageBox.Show("¡Producto agregado exitosamente!",
                                "Hugo App", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("Ha ocurrido un error...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void ProductMaintenanceForm_Load(object sender, EventArgs e)
        {
            var bussiness      = Connection_DB.ExecuteQuery("SELECT name FROM bussiness");
            var bussinessCombo = new List <string>();

            foreach (DataRow dr in bussiness.Rows)
            {
                bussinessCombo.Add(dr[0].ToString());
            }

            cmbBussiness.DataSource = bussinessCombo;
            cmbDeleteProduct_Bussiness.DataSource = bussinessCombo;

            string queryBussinessId = $"SELECT bussiness_id FROM bussiness WHERE name = '{cmbBussiness.SelectedItem}';";
            var    DT           = Connection_DB.ExecuteQuery(queryBussinessId);
            var    DR           = DT.Rows[0];
            var    bussiness_id = Convert.ToInt32(DR[0].ToString());

            var product       = Connection_DB.ExecuteQuery($"SELECT name FROM product WHERE bussiness_id = '{bussiness_id}';");
            var productsCombo = new List <string>();

            foreach (DataRow dr in product.Rows)
            {
                productsCombo.Add(dr[0].ToString());
            }

            cmbBussiness.DataSource = bussinessCombo;

            var productDelete       = Connection_DB.ExecuteQuery($"SELECT name FROM product WHERE bussiness_id = '{bussiness_id}';");
            var productsComboDelete = new List <string>();

            foreach (DataRow dr in productDelete.Rows)
            {
                productsComboDelete.Add(dr[0].ToString());
            }
            cmbDeleteProduct.DataSource = productsComboDelete;
        }
        private void btnAddBussiness_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Equals("") ||
                txtDescription.Text.Equals(""))
            {
                MessageBox.Show("No se pueden dejar campo(s) en vacio...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                try
                {
                    Connection_DB.ExecuteNonQuery($"INSERT INTO bussiness (name, description) VALUES(" +
                                                  $"'{txtName.Text}', " +
                                                  $"'{txtDescription.Text}');");

                    MessageBox.Show("Datos obtenidos exitosamente!");
                }
                catch (Exception)
                {
                    MessageBox.Show("Ha ocurrido un error...", "Mensaje de Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }