private void Datos_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            // Si el índice es 3, quiere borrar el registro.
            if (e.ColumnIndex == 3) {
                DialogResult ret = MessageBox.Show(null, "Desea borrar el Rol?", "Confirmación", MessageBoxButtons.OKCancel);
                if (ret.Equals(DialogResult.Cancel))
                {
                    return;
                }

                SQLResponse resp = m.executeQuery("select id_estado from GESTION_DE_PATOS.Estados where nombre_estado = 'Eliminado'");

                DataGridViewCellCollection celdas = this.Datos.Rows[e.RowIndex].Cells;
                ParamSet builder = new ParamSet("GESTION_DE_PATOS.EstablecerEstadoDelRol");
                builder.AddParameter("nombre_rol", celdas[0].Value.ToString());
                builder.AddParameter("estado", resp.result.Rows[0][0]);
                builder.executeNoReturn();
                MessageBox.Show("Baja de rol exitosa","Baja rol");
                Datos.DataSource = m.executeQuery("SELECT * from GESTION_DE_PATOS.viewroles").result;

            }
            // Índice 2 es modificar columna.
            else if (e.ColumnIndex == 2)
            {
                new ModificacionRol(this.Datos.Rows[e.RowIndex].Cells[0].Value.ToString()).ShowDialog();
                Datos.DataSource = m.executeQuery("SELECT * from GESTION_DE_PATOS.viewroles").result;

            }
        }
        private void cupones_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            String columna_seleccionada = this.cupones.Columns[e.ColumnIndex].Name;

            if (columna_seleccionada == "Publicar")
            {
                String codigo = this.cupones.Rows[e.RowIndex].Cells[0].Value.ToString();
                if(codigo == ""){
                    MessageBox.Show("No hay promociones para publicar");
                    return;
                }

                ParamSet ps = new ParamSet("GESTION_DE_PATOS.PublicarCupon");
                ps.AddParameter("@codigoPromocion", codigo);
                ps.AddParameter("@fecha", (String)AppContext.getObject(typeof(String)));
                ps.executeNoReturn();

                MessageBox.Show("Promoción publicada");

                setDataGridView();

            }

                return;
        }
        private void Guardar_Click(object sender, EventArgs e)
        {
            if (this.Estado.Text == "1: Habilitado") {
                if (this.ListaFuncionalidades.CheckedItems.Count == 0) {
                    MessageBox.Show("Seleccione al menos una funcionalidad");
                    return;
                }
            }
            ParamSet builder = new ParamSet("GESTION_DE_PATOS.EliminarFuncionalidadesDeRol");
            builder.AddParameter("nombre_rol", this.nombre);
            builder.executeNoReturn();

            builder.NombreSP("GESTION_DE_PATOS.AsignarFuncionalidadAlRol");
            foreach (String item in ListaFuncionalidades.CheckedItems)
            {
                builder.AddParameter("@id", Int32.Parse(item.ToString().Substring(0, item.IndexOf(":"))));
                builder.AddParameter("@rol", this.nombre);
                builder.execSP();
            }

            SqlCommand query;

            String estado = this.Estado.SelectedItem.ToString();

            builder = new ParamSet("GESTION_DE_PATOS.EstablecerEstadoDelRol");
            builder.AddParameter("nombre_rol", this.nombre);
            builder.AddParameter("estado", estado.Substring(0, estado.IndexOf(':')));
            builder.executeNoReturn();

            //("estado", estado.Substring(0, estado.IndexOf(':')))

            if (this.nombre != this.NombreRol.Text)
            {
                query = new SqlCommand("UPDATE GESTION_DE_PATOS.Roles SET nombre=@nombre WHERE nombre=@nombre_original");
                query.Parameters.AddWithValue("nombre", this.NombreRol.Text);
                query.Parameters.AddWithValue("nombre_original", this.nombre);
                manager.executeQuery(query);
            }
            MessageBox.Show("Rol actualizado");

            Main.actualizar();
            this.Hide();
        }
        private void Guardar_Click(object sender, EventArgs e)
        {
            Object elRol = this.Rol.SelectedItem;
            if (elRol == null) {
                MessageBox.Show("Seleccione un rol", "Registro de usuario");
                return;
            }

            ParamSet ps = new ParamSet();
            SqlParameter ret;

            switch (elRol.ToString()) {

                case "Cliente":
                    try
                    {
                        if (!String.Equals(PasswordCliente.Text, ConfirmarPassword.Text))
                        {
                            MessageBox.Show("Los campos passwords no coinciden", "Registro Usuario");
                            return;
                        }

                        if (UsernameCliente.Text == "" || PasswordCliente.Text == "" ||
                            ConfirmarPassword.Text == "" ||
                            NombreCliente.Text == "" || ApellidoCliente.Text == "" ||
                            MailCliente.Text == "" || TelefonoCliente.Text == "" ||
                            FchNacimientoCliente.Text == "" || DNICliente.Text == "" ||
                            DireccionC.Text == "" || ListaZonas.CheckedItems.Count == 0 ||
                            CodigoPostalC.Text == "" ||
                            ciudadCliente.SelectedItem.ToString() == "")
                        {

                            MessageBox.Show("Faltan datos");
                            return;
                        }
                    }
                    catch (NullReferenceException)
                    {
                        MessageBox.Show("Hay campos vacíos", "Registro de Usuario");
                    }

                    ps.NombreSP("GESTION_DE_PATOS.RegistroCliente");
                    ps.AddParameter("@user", UsernameCliente.Text);
                    ps.AddParameter("@pass", PasswordCliente.Text);
                    ps.AddParameter("@nombre", NombreCliente.Text);
                    ps.AddParameter("@apellido", ApellidoCliente.Text);
                    ps.AddParameter("@mail", MailCliente.Text);
                    ps.AddParameter("@tel", Int64.Parse(TelefonoCliente.Text));
                    ps.AddParameter("@fecha", FchNacimientoCliente.Text);
                    ps.AddParameter("@dni", Int64.Parse(DNICliente.Text));
                    ps.AddParameter("@direccion", DireccionC.Text);
                    ps.AddParameter("@ciudad", ciudadCliente.SelectedItem.ToString());
                    ps.AddParameter("@cp", Int64.Parse(CodigoPostalC.Text));

                    try {

                        ret = ps.execSP();
                        switch (ret.Value.ToString()) {
                            case "0":
                                ps.NombreSP("GESTION_DE_PATOS.RegistrarLocalidades");
                                foreach (Object localidad in this.ListaZonas.CheckedItems) {
                                    ps.AddParameter("@localidad", localidad.ToString());
                                    ps.AddParameter("@user", UsernameCliente.Text);
                                    ps.executeNoReturn();
                                }

                                MessageBox.Show("Registro realizado con éxito","Registro de usuario",MessageBoxButtons.OK);
                                this.Hide();
                                return;

                            case "1":
                                MessageBox.Show("El usuario ya existe","Registro de usuario");
                                return;

                            case "2":
                                MessageBox.Show("Los datos ingresados corresponden a un usuario existente", "Registro de usuario");
                                return;

                            }
                    }

                    catch(SqlException){
                        MessageBox.Show("Ingrese un valor correcto para el teléfono, el dni, el código postal o la fecha de nacimiento", "Registro de usuario");
                        return;
                    }
                    catch (OverflowException)
                    {
                        MessageBox.Show("Ha ingresado un codigo postal demasiado grande, ingrese otro", "Alta proveedor", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    return;

                case "Proveedor":

                    try
                    {

                        if (!String.Equals(PassP.Text, ConfirmarPass.Text))
                        {
                            MessageBox.Show("Los campos passwords no coinciden", "Registro Usuario");
                            return;
                        }

                        if (UsernameP.Text == "" || PassP.Text == "" ||
                            ConfirmarPass.Text == "" ||
                            RazonSocial.Text == "" || CUIT.Text == "" ||
                            MailP.Text == "" || TelefonoP.Text == "" ||
                            Direccion.Text == "" || NombreContacto.Text == "" ||
                            ciudadP.SelectedItem.ToString() == "" ||
                            CodigoPostalP.Text == "" ||
                            RubroP.SelectedItem.ToString() == "")
                        {

                            MessageBox.Show("Faltan datos", "Registro de usuario");
                            return;
                        }
                    }
                    catch (NullReferenceException)
                    {
                        MessageBox.Show("Hay campos vacíos", "Registro de Usuario");
                    }

                    try{
                        ps.NombreSP("GESTION_DE_PATOS.RegistrarProveedor");
                        ps.AddParameter("@user", UsernameP.Text);
                        ps.AddParameter("@pass", PassP.Text);
                        ps.AddParameter("@rs", RazonSocial.Text);
                        ps.AddParameter("@cuit", CUIT.Text);
                        ps.AddParameter("@mail", MailP.Text);
                        ps.AddParameter("@telefono", Int64.Parse(TelefonoP.Text));
                        ps.AddParameter("@direccion", Direccion.Text);
                        ps.AddParameter("@ciudad", ciudadP.SelectedItem.ToString());
                        ps.AddParameter("@rubro", RubroP.SelectedItem.ToString());
                        ps.AddParameter("@contacto", NombreContacto.Text);
                        ps.AddParameter("@cp", Int64.Parse(CodigoPostalP.Text));

                        ret = ps.execSP();
                        switch (ret.Value.ToString())
                        {
                            case "0":
                                MessageBox.Show("Registro realizado con éxito", "Registro de usuario",MessageBoxButtons.OK);
                                this.Hide();
                                return;

                            case "1":
                                MessageBox.Show("El usuario ya existe", "Registro de usuario");
                                return;

                            case "2":
                                MessageBox.Show("Los datos ingresados corresponden a un usuario existente", "Registro de usuario");
                                return;

                          }

                        return;

                    }
                     catch(FormatException){
                        MessageBox.Show("Ingrese un valor correcto para el teléfono o el código postal");
                     }
                    catch (OverflowException)
                    {
                        MessageBox.Show("Ha ingresado un codigo postal demasiado grande, ingrese otro", "Alta proveedor", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                return;

            }
        }
        private void Guardar_Click(object sender, EventArgs e)
        {
            if (UsernameCliente.Text == "" || NombreCliente.Text == "" || ApellidoCliente.Text == "" || TelefonoCliente.Text == "" || DNICliente.Text == "")
            {
                MessageBox.Show("Hay campos obligatorios que están vacíos", "Modificar cliente");
                return;
            }

            try
            {
                ParamSet ps = new ParamSet("GESTION_DE_PATOS.ModificarCliente");

                ps.AddParameter("@user", UsernameCliente.Text);
                ps.AddParameter("@nombre", NombreCliente.Text);
                ps.AddParameter("@apellido", ApellidoCliente.Text);
                ps.AddParameter("@mail", MailCliente.Text);
                ps.AddParameter("@tel", TelefonoCliente.Text);
                ps.AddParameter("@fecha", DateTime.Parse(FchNacimientoCliente.Text));
                ps.AddParameter("@dni", DNICliente.Text);
                ps.AddParameter("@direccion", DireccionC.Text);
                ps.AddParameter("@codigo_postal", CodigoPostal.Text);
                ps.AddParameter("@ciudad", ciudadCliente.SelectedItem.ToString());
                ps.AddParameter("@estado", Estado.SelectedItem.ToString());

                SqlParameter retval = ps.execSP();

                switch (retval.Value.ToString())
                {
                    case "0":
                        ps.NombreSP("GESTION_DE_PATOS.EliminarLocalidades");
                        ps.AddParameter("@user", UsernameCliente.Text);
                        ps.executeNoReturn();

                        ps.NombreSP("GESTION_DE_PATOS.RegistrarLocalidades");
                        foreach (Object localidad in this.ListaZonas.CheckedItems)
                        {
                            ps.AddParameter("@localidad", localidad.ToString());
                            ps.AddParameter("@user", UsernameCliente.Text);
                            ps.executeNoReturn();
                        }

                        MessageBox.Show("Registro modificado con éxito", "Modificar cliente");
                        this.listado.actualizar_datagridview();
                        this.Hide();
                        break;
                    case "1": MessageBox.Show("El cliente no existe", "Modificar cliente", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        break;
                    case "2": MessageBox.Show("Los datos ingresados corresponden a un usuario ya registrado", "Modificar cliente", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        break;
                }
            }
            catch (SqlException) {
                MessageBox.Show("Ingrese valores correctos para el dni, teléfono, código postal y fecha de nacimiento");
                return;
            }
            catch (OverflowException)
            {
                MessageBox.Show("Ha ingresado un codigo postal demasiado grande, ingrese otro", "Alta proveedor", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Hay campos vacíos", "Modificación cliente");
            }
        }
        private void Guardar_Click(object sender, EventArgs e)
        {
            try
            {
                if (!String.Equals(PasswordCliente.Text, ConfirmarPassword.Text))
                {
                    MessageBox.Show("Los campos passwords no coinciden", "Alta Cliente");
                    return;
                }

                if ((UsernameCliente.Text == "" && UsernameCliente.Enabled == true) || PasswordCliente.Text == "" ||
                       NombreCliente.Text == "" || ApellidoCliente.Text == "" ||
                       MailCliente.Text == "" || TelefonoCliente.Text == "" ||
                       FchNacimientoCliente.Text == "" || DNICliente.Text == "" ||
                       DireccionC.Text == "" || ListaZonas.CheckedItems.Count == 0 ||
                       CodigoPostal.Text == "" || ConfirmarPassword.Text == "" ||
                       ciudadCliente.SelectedItem.ToString() == "")
                {

                    MessageBox.Show("Faltan datos", "Alta cliente");
                    return;
                }
                ParamSet ps = new ParamSet("GESTION_DE_PATOS.AltaCliente");

                ps.AddParameter("@user", UsernameCliente.Text);
                if (UsernameCliente.Enabled == true)
                {
                    ps.AddParameter("@pass", PasswordCliente.Text);
                }
                else
                {
                    ps.NombreSP("GESTION_DE_PATOS.CambiarRolCliente");
                }

                ps.AddParameter("@nombre", NombreCliente.Text);
                ps.AddParameter("@apellido", ApellidoCliente.Text);
                ps.AddParameter("@dni", Int64.Parse(DNICliente.Text));
                ps.AddParameter("@fecha", DateTime.Parse(FchNacimientoCliente.Text));
                ps.AddParameter("@mail", MailCliente.Text);
                ps.AddParameter("@tel", Int64.Parse(TelefonoCliente.Text));
                ps.AddParameter("@direccion", DireccionC.Text);
                ps.AddParameter("@cp", Int64.Parse(CodigoPostal.Text));
                ps.AddParameter("@ciudad", ciudadCliente.SelectedItem.ToString());
                SqlParameter retval = ps.execSP();

                switch (retval.Value.ToString())
                {
                    case "0":
                        ps.NombreSP("GESTION_DE_PATOS.RegistrarLocalidades");
                        foreach (Object localidad in this.ListaZonas.CheckedItems)
                        {
                            ps.AddParameter("@localidad", localidad.ToString());
                            ps.AddParameter("@user", UsernameCliente.Text);
                            ps.executeNoReturn();
                        }

                        MessageBox.Show("Registro realizado con éxito", "Alta cliente");

                        if (this.listado != null)
                            this.listado.actualizar_datagridview();

                        this.Hide();
                        return;

                    case "1": MessageBox.Show("El cliente ya existe", "Alta cliente", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        break;
                    case "2": MessageBox.Show("Los datos ingresados corresponden a un usuario ya registrado", "Alta cliente", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        break;
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Ingrese un valor correcto para el teléfono, el dni, el código postal o la fecha de nacimiento", "Alta cliente");
                return;
            }
            catch (OverflowException)
            {
                MessageBox.Show("Ha ingresado un codigo postal demasiado grande, ingrese otro", "Alta proveedor", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Hay campos vacíos", "Alta cliente");
            }
        }