Exemplo n.º 1
0
        private void btnModificar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int modificado;
                idcliente  = (int)ltsClientes.SelectedValue;
                modificado = ltsClientes.SelectedIndex;
                String    consulta         = "SELECT * FROM clientesme where idclienteme=@valor";
                DataTable cliente          = conexion.ConsultaParametrizada(consulta, ltsClientes.SelectedValue);
                string    direccion        = cliente.Rows[0].ItemArray[1].ToString();
                string    pais             = cliente.Rows[0].ItemArray[2].ToString();
                string    web              = cliente.Rows[0].ItemArray[3].ToString();
                string    nombre           = cliente.Rows[0].ItemArray[4].ToString();
                string    cuitpais         = cliente.Rows[0].ItemArray[7].ToString();
                int       terminocomercial = (int)cliente.Rows[0].ItemArray[5];

                int listadeprecios;
                if (cliente.Rows[0].ItemArray[6].ToString() == "")
                {
                    listadeprecios = 0;
                }
                else
                {
                    listadeprecios = (int)cliente.Rows[0].ItemArray[6];
                }



                var newW = new windowAgregarClienteme(nombre, direccion, pais, terminocomercial, cuitpais, web, listaContacto, idcliente, listadeprecios);

                newW.ShowDialog();



                if (newW.DialogResult == true)
                {
                    int    id          = (int)ltsClientes.SelectedValue;
                    int    termino     = newW.cmbtc.SelectedIndex;
                    String country     = newW.cmbpais.Text;
                    String nombreActu  = newW.txtNombre.Text;
                    String address     = newW.txtDireccion.Text;
                    String webpage     = newW.txtdireccionweb.Text;
                    String cuitcountry = newW.txtcp.Text;

                    this.dgvContacto.ItemsSource = newW.dgvContacto.ItemsSource;



                    if (newW.cmbPrecios.Text == "")
                    {
                        String update;
                        update = "update clientesme set nombre = '" + nombreActu + "', direccion = '" + address + "', pais = '" + country + "', web = '" + webpage + "', terminocomercial = '" + termino + "', cuitpais = '" + cuitcountry + "' where idClienteme ='" + idcliente + "';";
                        conexion.operaciones(update);
                    }
                    else
                    {
                        String update;
                        update = "update clientesme set nombre = '" + nombreActu + "', direccion = '" + address + "', pais = '" + country + "', web = '" + webpage + "', terminocomercial = '" + termino + "', FK_idLista = '" + newW.idlp + "', cuitpais = '" + cuitcountry + "' where idClienteme='" + idcliente + "';";
                        conexion.operaciones(update);
                    }



                    String contact = "delete  from contactocliente where FK_idClienteme= '" + idcliente + "'";
                    conexion.operaciones(contact);



                    foreach (var contacto in newW.lista)
                    {
                        string sql;
                        sql = "INSERT INTO contactocliente (telefono,email,nombrecontacto,FK_idClienteme) values('" + contacto.NumeroTelefono + "', '" + contacto.Email + "', '" + contacto.NombreContacto + "', '" + idcliente + "')";
                        conexion.operaciones(sql);
                    }
                    loadListaClientes();
                }


                ltsClientes.SelectedIndex = modificado;
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Seleccione un cliente a modificar", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
        private void btnAgregar_Click(object sender, RoutedEventArgs e)
        {
            var newW = new windowAgregarClienteme();

            newW.ShowDialog();


            if (newW.DialogResult == true)
            {
                String nombre       = newW.txtNombre.Text;
                String direccionweb = newW.txtdireccionweb.Text;
                String pais         = newW.cmbpais.Text;
                String direccion    = newW.txtDireccion.Text;
                String cuitpais     = newW.txtcp.Text;
                int    tc           = newW.cmbtc.SelectedIndex;



                //INSERTAR DATOS PRINCIPALES

                if (newW.cmbPrecios.Text == "")
                {
                    String sql;
                    sql = "insert into clientesme(nombre, web, pais, direccion, terminocomercial, cuitpais) values('" + nombre + "', '" + direccionweb + "', '" + pais + "', '" + direccion + "', '" + tc + "','" + cuitpais + "')";
                    conexion.operaciones(sql);
                }
                else
                {
                    String sql;
                    sql = "insert into clientesme(nombre, web, pais, direccion, terminocomercial, cuitpais, FK_idLista) values('" + nombre + "', '" + direccionweb + "', '" + pais + "', '" + direccion + "', '" + tc + "','" + cuitpais + "','" + newW.idlp + "' )";
                    conexion.operaciones(sql);
                }

                String sql2 = "Select idClienteme from clientesme order by idClienteme DESC LIMIT 1";
                idclientme = conexion.ValorEnVariable(sql2);

                //Console.WriteLine("ULTIMO ID" + idProv);

                //INSERTAR CONTACTO PROVEEDOR
                String sqlContacto;
                string ultimoId = "Select last_insert_id()";
                String id       = conexion.ValorEnVariable(ultimoId);

                for (int i = 0; i < newW.lista.Count; i++)
                {
                    String nombreL   = newW.lista[i].NombreContacto;
                    String telefonoL = newW.lista[i].NumeroTelefono;
                    String emailL    = newW.lista[i].Email;
                    sqlContacto = "insert into contactocliente(telefono, email, nombreContacto, FK_idClienteme) values('" + telefonoL + "', '" + emailL + "', '" + nombreL + "', '" + idclientme + "')";
                    conexion.operaciones(sqlContacto);
                }
                // loadListaProducto();

                //INSERTAR CATEGORIAS PROVEEDOR


                loadListaClientes();
                this.ltsClientes.Items.Refresh();
                InitializeComponent();
                loadListaClientes();
                MessageBox.Show("Se agregó el cliente correctamente", "Información", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            ltsClientes.SelectedIndex = ltsClientes.Items.Count - 1;
        }