示例#1
0
        private void btnModificar_Copy_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int modificado;
                modificado = ltsClientes.SelectedIndex;
                idcliente  = (int)ltsClientes.SelectedValue;
                String    consulta         = "SELECT * FROM clientesmi where idclientemi=@valor";
                DataTable cliente          = conexion.ConsultaParametrizada(consulta, ltsClientes.SelectedValue);
                string    nombre           = cliente.Rows[0].ItemArray[6].ToString();
                string    cuit             = cliente.Rows[0].ItemArray[1].ToString();
                string    transporte       = cliente.Rows[0].ItemArray[2].ToString();
                string    teltransporte    = cliente.Rows[0].ItemArray[3].ToString();
                string    direccionentrega = cliente.Rows[0].ItemArray[4].ToString();
                string    razonsocial      = cliente.Rows[0].ItemArray[5].ToString();
                string    provincia        = cliente.Rows[0].ItemArray[8].ToString();
                int       listadeprecios;
                if (cliente.Rows[0].ItemArray[7].ToString() == "")
                {
                    listadeprecios = 0;
                }
                else
                {
                    listadeprecios = (int)cliente.Rows[0].ItemArray[7];
                }



                var newW = new windowAgregarClientemi(nombre, cuit, transporte, teltransporte, direccionentrega, razonsocial, listaContacto, idcliente, listadeprecios, provincia);

                newW.ShowDialog();


                if (newW.DialogResult == true)
                {
                    this.txtCuit.Text       = newW.txtCuit.Text;
                    this.txtTransporte.Text = newW.txtTransporte.Text;
                    String nombreActu = newW.txtNombre.Text;
                    this.txtDireccion.Text = newW.txtDireccion.Text;
                    this.txtrs.Text        = newW.cmbRs.Text;
                    this.txtTelt.Text      = newW.txtTelt.Text;
                    String province = newW.cmbP.Text;



                    if (newW.cmbPrecios.Text == "")
                    {
                        String update;
                        update = "update clientesmi set nombre = '" + nombreActu + "', razonsocial = '" + this.txtrs.Text + "', cuit = '" + this.txtCuit.Text + "', direccionentrega = '" + this.txtDireccion.Text + "', teltransporte = '" + this.txtTelt.Text + "', transporte = '" + this.txtTransporte.Text + "', provincia='" + province + "' where idClientemi ='" + idcliente + "';";
                        conexion.operaciones(update);
                    }
                    else
                    {
                        String update;
                        update = "update clientesmi set nombre = '" + nombreActu + "', razonsocial = '" + this.txtrs.Text + "', cuit = '" + this.txtCuit.Text + "', direccionentrega = '" + this.txtDireccion.Text + "', teltransporte = '" + this.txtTelt.Text + "', transporte = '" + this.txtTransporte.Text + "', FK_idLista = '" + newW.idlp + "', provincia='" + province + "' where idClientemi ='" + idcliente + "';";
                        conexion.operaciones(update);
                    }



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



                    foreach (var contacto in newW.lista)
                    {
                        string sql;
                        sql = "INSERT INTO contactocliente (telefono,email,nombrecontacto,FK_idClientemi) 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);
            }
        }
示例#2
0
        private void btnAgregar_Click(object sender, RoutedEventArgs e)
        {
            var newW = new windowAgregarClientemi();

            newW.ShowDialog();

            if (newW.DialogResult == true)
            {
                String nombre     = newW.txtNombre.Text;
                String cuit       = newW.txtCuit.Text;
                String telt       = newW.txtTelt.Text;
                String provincia  = newW.cmbP.Text;
                String direccion  = newW.txtDireccion.Text;
                String transporte = newW.txtTransporte.Text;


                int razons = newW.cmbRs.SelectedIndex;



                //INSERTAR DATOS PRINCIPALES

                if (newW.cmbPrecios.Text == "")
                {
                    String sql;
                    sql = "insert into clientesmi(nombre, razonsocial, cuit, teltransporte, direccionentrega, transporte, provincia) values('" + nombre + "', '" + razons + "', '" + cuit + "', '" + telt + "', '" + direccion + "', '" + transporte + "','" + provincia + "')";
                    conexion.operaciones(sql);
                }
                else
                {
                    String sql;
                    sql = "insert into clientesmi(nombre, razonsocial, cuit, teltransporte, direccionentrega, transporte, FK_idLista,provincia) values('" + nombre + "', '" + razons + "', '" + cuit + "', '" + telt + "', '" + direccion + "', '" + transporte + "','" + newW.idlp + "','" + provincia + "')";
                    conexion.operaciones(sql);
                }



                String sql2 = "Select idClientemi from clientesmi order by idClientemi DESC LIMIT 1";
                idclientmi = 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_idClientemi) values('" + telefonoL + "', '" + emailL + "', '" + nombreL + "', '" + idclientmi + "')";
                    conexion.operaciones(sqlContacto);
                }
                // loadListaProducto();

                //INSERTAR CATEGORIAS PROVEEDOR


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