private void dgProd_SelectionChanged(object sender, SelectionChangedEventArgs e) { ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client(); if (dgProd.SelectedItem != null) { cbRubro.ItemsSource = null; Producto p = (Producto)dgProd.SelectedItem; txtCod.Text = p.CodigoInterno; txtDescripcion.Text = p.Descripcion; txtNombre.Text = p.Nombre; txtPrecio.Text = p.Precio.ToString(); string json = proxy.ReadAllRubros(); RubroCollections ruCol = new RubroCollections(json); cbRubro.DisplayMemberPath = "TipoRubro"; cbRubro.SelectedValuePath = "IdRubro"; cbRubro.ItemsSource = ruCol.ToList(); for (int i = 0; i < cbRubro.Items.Count; i++) { Rubro rubro = (Rubro)cbRubro.Items[i]; if (rubro.IdRubro == p.IdRubro) { cbRubro.SelectedIndex = i; } } } }
private void CargarCombobox() { ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client(); string json = proxy.ReadAllRubros(); RubroCollections reCol = new RubroCollections(json); cbRubro.DisplayMemberPath = "TipoRubro"; cbRubro.SelectedValuePath = "IdRubro"; cbRubro.ItemsSource = reCol.ToList(); }
private async void btnAgregarPA_Click(object sender, RoutedEventArgs e) { Producto p = new Producto(); ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client(); string json; json = proxy.ReadAllRubros(); RubroCollections reCol = new RubroCollections(json); string aux = string.Empty; p.IdRubro = (int)cbRubroPA.SelectedValue; foreach (var item in reCol) { if (p.IdRubro == item.IdRubro) { aux = item.TipoRubro; } } int precio; int.TryParse(txtPrecioPA.Text, out precio); p.Precio = precio; p.CodigoInterno = txtCodigoPA.Text; p.Nombre = txtNombrePA.Text; p.Sku = txtNombrePA.Text.Substring(0, 4) + aux.Substring(0, 4); p.Descripcion = txtDescripcionPA.Text; string jsons = p.Serializar(); if (proxy.CrearProducto(jsons)) { await this.ShowMessageAsync("Exito", "Producto agregado!"); LimpiarControles(); } else { await this.ShowMessageAsync("Error", "No se pudo agregar el producto"); }; }
private async void btnEjecutar_Click(object sender, RoutedEventArgs e) { lblNombre.Content = validador.validarNombre(txtNombre.Text); lblPrecio.Content = validador.validarPrecio(txtPrecio.Text); lblCodigo.Content = validador.validarCodigoInterno(txtCod.Text); Producto p = new Producto(); ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client(); if (lblNombre.Content.Equals("OK") && lblPrecio.Content.Equals("OK") && lblCodigo.Content.Equals("OK")) { if (cbRubro.SelectedIndex == -1) { lblRubro.Content = "Seleccione una opcion"; lblRubro.Visibility = Visibility.Visible; } else { string json; switch (btnEjecutar.Content.ToString()) { case "Agregar": json = proxy.ReadAllRubros(); RubroCollections reCol = new RubroCollections(json); string aux = string.Empty; p.IdRubro = (int)cbRubro.SelectedValue; foreach (var item in reCol) { if (p.IdRubro == item.IdRubro) { aux = item.TipoRubro; } } int precio; int.TryParse(txtPrecio.Text, out precio); p.Precio = precio; p.CodigoInterno = txtCod.Text; p.Nombre = txtNombre.Text; p.Sku = txtNombre.Text.Substring(0, 4) + aux.Substring(0, 4); p.Descripcion = txtDescripcion.Text; string jsons = p.Serializar(); if (proxy.CrearProducto(jsons)) { await this.ShowMessageAsync("Exito", "Producto agregado!"); LimpiarControles(); } else { await this.ShowMessageAsync("Error", "No se pudo agregar el producto"); }; break; case "Modificar": json = proxy.ReadAllRubros(); RubroCollections ruCol = new RubroCollections(json); string au = string.Empty; p.IdRubro = (int)cbRubro.SelectedValue; foreach (var item in ruCol) { if (p.IdRubro == item.IdRubro) { au = item.TipoRubro; } } int preci; int.TryParse(txtPrecio.Text, out preci); p.Precio = preci; p.CodigoInterno = txtCod.Text; p.Nombre = txtNombre.Text; p.Sku = txtNombre.Text.Substring(0, 4) + au.Substring(0, 4); p.Descripcion = txtDescripcion.Text; Producto pr = (Producto)dgProd.SelectedValue; p.IdProducto = pr.IdProducto; jsons = p.Serializar(); if (proxy.ActualizarProducto(jsons)) { await this.ShowMessageAsync("Exito", "Producto Modificado!"); LimpiarControles(); } else { await this.ShowMessageAsync("Error", "No se pudo agregar el producto"); }; break; case "Eliminar": Producto pro = (Producto)dgProd.SelectedValue; json = pro.Serializar(); if (proxy.EliminarProducto(json)) { await this.ShowMessageAsync("Exito", "Producto eliminado"); LimpiarControles(); } else { await this.ShowMessageAsync("Error", "No se a podido eliminar"); LimpiarControles(); } break; default: break; } } } else { if (lblPrecio.Content.Equals("OK")) { lblPrecio.Visibility = Visibility.Hidden; } else { lblPrecio.Visibility = Visibility.Visible; } if (lblNombre.Content.Equals("OK")) { lblNombre.Visibility = Visibility.Hidden; } else { lblNombre.Visibility = Visibility.Visible; } if (lblCodigo.Content.Equals("OK")) { lblCodigo.Visibility = Visibility.Hidden; } else { lblCodigo.Visibility = Visibility.Visible; } } }
private void CargarCombobox() { // Productos ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client(); string json = proxy.ReadAllRubros(); RubroCollections reCol = new RubroCollections(json); cbRubroPA.DisplayMemberPath = "TipoRubro"; cbRubroPA.SelectedValuePath = "IdRubro"; cbRubroPA.ItemsSource = reCol.ToList(); cbRubroPE.DisplayMemberPath = "TipoRubro"; cbRubroPE.SelectedValuePath = "IdRubro"; cbRubroPE.ItemsSource = reCol.ToList(); cbRubroPEL.DisplayMemberPath = "TipoRubro"; cbRubroPEL.SelectedValuePath = "IdRubro"; cbRubroPEL.ItemsSource = reCol.ToList(); cbRubroPM.DisplayMemberPath = "TipoRubro"; cbRubroPM.SelectedValuePath = "IdRubro"; cbRubroPM.ItemsSource = reCol.ToList(); cbRubroPMO.DisplayMemberPath = "TipoRubro"; cbRubroPMO.SelectedValuePath = "IdRubro"; cbRubroPMO.ItemsSource = reCol.ToList(); //usuarios //Perfiles string jsonP = proxy.ReadAllPerfil(); PerfilCollections perCol = new PerfilCollections(jsonP); cbPerfilUA.DisplayMemberPath = "Tipo"; cbPerfilUA.SelectedValuePath = "IdPerfil"; cbPerfilUA.ItemsSource = perCol.ToList(); cbPerfilUE.DisplayMemberPath = "Tipo"; cbPerfilUE.SelectedValuePath = "IdPerfil"; cbPerfilUE.ItemsSource = perCol.ToList(); cbPerfilUEB.DisplayMemberPath = "Tipo"; cbPerfilUEB.SelectedValuePath = "IdPerfil"; cbPerfilUEB.ItemsSource = perCol.ToList(); cbPerfilUM.DisplayMemberPath = "Tipo"; cbPerfilUM.SelectedValuePath = "IdPerfil"; cbPerfilUM.ItemsSource = perCol.ToList(); cbPerfilUMB.DisplayMemberPath = "Tipo"; cbPerfilUMB.SelectedValuePath = "IdPerfil"; cbPerfilUMB.ItemsSource = perCol.ToList(); //Sucursales string jsonS = proxy.ReadAllSucursal(mainwindow.RetailActual.IdRetail); SucursalCollections suCol = new SucursalCollections(jsonS); Sucursal s = new Sucursal(); cbSucursalUA.DisplayMemberPath = "Nombre"; cbSucursalUA.SelectedValuePath = "IdSucursal"; cbSucursalUA.ItemsSource = suCol.ToList(); cbSucursalUE.DisplayMemberPath = "Nombre"; cbSucursalUE.SelectedValuePath = "IdSucursal"; cbSucursalUE.ItemsSource = suCol.ToList(); cbSucursalUM.DisplayMemberPath = "Nombre"; cbSucursalUM.SelectedValuePath = "IdSucursal"; cbSucursalUM.ItemsSource = suCol.ToList(); cbRetailUEB.DisplayMemberPath = "Nombre"; cbRetailUEB.SelectedValuePath = "IdSucursal"; cbRetailUEB.ItemsSource = suCol.ToList(); cbRetailUMB.DisplayMemberPath = "Nombre"; cbRetailUMB.SelectedValuePath = "IdSucursal"; cbRetailUMB.ItemsSource = suCol.ToList(); }