//******************************************************************************* //******************************************************************************* private void buttonEliminar_Click(object sender, EventArgs e) { try { if (this.dataGridViewProductos.Rows.Count > 0) { DialogResult confirmacion = MessageBox.Show("¿Seguro deseas eliminar este producto?", "Eliminar Producto", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (confirmacion == DialogResult.OK) { String mensaje = NProductos.Eliminar(Convert.ToInt32(ObtenerSeleccion().Cells["ID"].Value)); if (mensaje == "Y") { Mensaje(String.Format("El Producto {0} ha sido ELIMINADO", Convert.ToString(ObtenerSeleccion().Cells["NOMBRE"].Value))); Refrescar(); } else { MensajeError(mensaje); Refrescar(); } } } else { MensajeError("Debes seleccionar una fila para eliminar"); } } catch (Exception ex) { MensajeError(ex.Message); } }
private void comboBoxProductos_SelectedValueChanged(object sender, EventArgs e) { if (this.comboBoxProductos.SelectedValue.ToString() != "System.Data.DataRowView") { this.textBoxPrecio.Text = (NProductos.PrecioProducto(Convert.ToInt32(this.comboBoxProductos.SelectedValue.ToString()))).ToString("0.00##"); } }
private void buttonGuardar_Click(object sender, EventArgs e) { try { if (String.IsNullOrWhiteSpace(this.textBoxNombreProducto.Text) || String.IsNullOrWhiteSpace(this.comboBoxCategoria.Text)) { MensajeError("Los campos Nombre de Producto y Categoría son obligatorios"); } else { if (String.IsNullOrWhiteSpace(this.textBoxPrecioUnitario.Text)) { this.textBoxPrecioUnitario.Text = "0"; } String mensaje = NProductos.Insertar(this.textBoxNombreProducto.Text, this.comboBoxCategoria.Text, Convert.ToDecimal(this.textBoxPrecioUnitario.Text), this.textBoxDetalles.Text); if (mensaje == "Y") { this._owner.Mensaje(String.Format("El Producto {0} ha sido AGREGADO", this.textBoxNombreProducto.Text)); this._owner.Refrescar(); this.Close(); } else { MensajeError(mensaje); } } } catch (Exception ex) { MensajeError("Los valores ingresados son incorrectos. " + ex.Message); } }
public FormBuscarProducto() { InitializeComponent(); nproducto = new NProductos(dataGridViewBuscarProducto); nproducto.cargarProductos(); }
//Constructor public FrmProductos(Productos _ctrlProductos, string Procedimiento) { InitializeComponent(); this.ctrlProductos = _ctrlProductos; //Carga las categorias en el combobox "cbxCategoria" this.cbxCategoria.DataSource = NProductos.CargarCategorias(); this.cbxCategoria.DisplayMember = "NOMBRE"; this.cbxCategoria.ValueMember = "ID_CATEGORIA"; //Carga los impuestos en el combobox "cbxImpuesto" this.cbxImpuesto.DataSource = NProductos.CargarImpuestos(); this.cbxImpuesto.DisplayMember = "IMPUESTO"; this.cbxImpuesto.ValueMember = "ID_IMPUESTO"; //Verifica para cual procedimiento fue llamado. if (Procedimiento == "Nuevo") { this.cbxImpuesto.SelectedIndex = 0; this.cbxCategoria.SelectedIndex = 0; this.Text = String.Format(Configuracion.Titulo, "Nuevo Producto"); } else if (Procedimiento == "Editar") { //Establece diseño. this.Icon = Recursos.EditarProductoIcono; this.panelImagen.BackgroundImage = Recursos.EditarProductoImagen; this.btnAgregarActualizar.BackgroundImage = Recursos.btnActualizar; this.btnAgregarActualizar.Text = "Actualizar"; this.Text = String.Format(Configuracion.Titulo, "Editar Producto"); this.lblTitulo.Text = "Editar Cliente"; //Introduce en el los datos seleccionados en el dgvProductos. this.IdProducto = Convert.ToInt32(ctrlProductos.ObtenerFila().Cells["CÓDIGO"].Value); this.txtDescripcion.Text = Convert.ToString(ctrlProductos.ObtenerFila().Cells["DESCRIPCIÓN"].Value). Replace(" (E.)", ""); this.txtCosto.Text = Convert.ToString(ctrlProductos.ObtenerFila().Cells["COSTO"].Value); this.txtCosto.Text = this.txtCosto.Text.Replace(",", "a").Replace(".", "b"); this.txtCosto.Text = this.txtCosto.Text.Replace("a", ".").Replace("b", ","); this.txtCosto.Text = String.Format("{0:#,##0.00}", Double.Parse(this.txtCosto.Text)); this.txtUtilidad.Text = Convert.ToString(ctrlProductos.ObtenerFila().Cells["UTILIDAD"].Value); this.txtUtilidad.Text = this.txtUtilidad.Text.Replace(",", "a").Replace(".", "b"); this.txtUtilidad.Text = this.txtUtilidad.Text.Replace("a", ".").Replace("b", ","); this.txtUtilidad.Text = String.Format("{0:#,##0.00}", Double.Parse(this.txtUtilidad.Text. Replace(" %", ""))) + " %"; this.txtPrecioBase.Text = Convert.ToString(ctrlProductos.ObtenerFila().Cells["PRECIO BASE"].Value); this.txtPrecioBase.Text = this.txtPrecioBase.Text.Replace(",", "a").Replace(".", "b"); this.txtPrecioBase.Text = this.txtPrecioBase.Text.Replace("a", ".").Replace("b", ","); this.txtPrecioBase.Text = String.Format("{0:#,##0.00}", Double.Parse(this.txtPrecioBase.Text)); this.cbxImpuesto.Text = Convert.ToString(ctrlProductos.ObtenerFila().Cells["IMPUESTO"].Value); this.txtPrecioVenta.Text = Convert.ToString(ctrlProductos.ObtenerFila().Cells["PRECIO VENTA"].Value); this.txtPrecioVenta.Text = this.txtPrecioVenta.Text.Replace(",", "a").Replace(".", "b"); this.txtPrecioVenta.Text = this.txtPrecioVenta.Text.Replace("a", ".").Replace("b", ","); this.txtExistencia.Text = Convert.ToString(ctrlProductos.ObtenerFila().Cells["EXISTENCIA"].Value); this.txtExistencia.Text = this.txtExistencia.Text.Replace(".00", ""); this.txtPrecioVenta.Text = String.Format("{0:#,##0.00}", Double.Parse(this.txtPrecioVenta.Text)); this.cbxCategoria.Text = Convert.ToString(ctrlProductos.ObtenerFila().Cells["CATEGORÍA"].Value); } }
//Constructor. public FrmBuscarProducto(FrmIngresoProductos _FormIngresoProductos) { InitializeComponent(); FormIngresoProductos = _FormIngresoProductos; //Estable la búqueda por defecto (Código) cbxTipoBusqueda.SelectedIndex = 0; //Rellena los resultados con las coincidencias que encuentre. this.dgvProductos.DataSource = NProductos.Buscar("", "Código"); }
public void Buscar() { try { this.dataGridViewProductos.DataSource = NProductos.Buscar(this.textBoxBuscarNombre.Text); } catch (Exception ex) { MensajeError(ex.Message); } }
//******************************************************************************* //******************************************************************************* public void Buscar() { try { this.dataGridViewProductos.DataSource = NProductos.Buscar(this.textboxNombreBuscar.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//txtBuscar - Evento TextChanged - Carga los resultados de la búsqueda. private void txtBuscar_TextChanged(object sender, EventArgs e) { try { //Busca las coincidencias. this.dgvProductos.DataSource = NProductos.Buscar(this.txtBuscar.Text, this.cbxTipoBusqueda.Text); } catch (Exception ex) { //En caso de error muestra mensaje al usuario. new Configuracion().Mensaje(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//******************************************************************************* //******************************************************************************* public void Mostrar() { try { this.Dock = DockStyle.Fill; this.dataGridViewProductos.DataSource = NProductos.Mostrar(registroporpagina, numeropagina); this.dataGridViewProductos.Columns[0].Visible = false; this.dataGridViewProductos.Columns[4].DefaultCellStyle.Format = "0.00## $"; this.dataGridViewProductos.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; cantidadpaginas = NProductos.Tamaño(registroporpagina); this.labelPaginacion.Text = String.Format("Página {0} de {1}", numeropagina, cantidadpaginas); } catch (Exception ex) { MensajeError(ex.Message); } }
private void comboBoxProductos_SelectedValueChanged(object sender, EventArgs e) { try { if (this.comboBoxProductos.SelectedIndex != -1) { if (this.comboBoxProductos.SelectedValue.ToString() != "System.Data.DataRowView") { this.textBoxPrecio.Text = (NProductos.PrecioProducto(Convert.ToInt32(this.comboBoxProductos.SelectedValue.ToString()))).ToString("0.00##"); } } } catch (Exception ex) { MensajeError(ex.Message); } }
public void CargarComboBox() { if (esCliente == 1) { this.comboBox.DataSource = NClientes.ListaClientes(); } else if (esEmpleado == 1) { this.comboBox.DataSource = NEmpleados.ListaEmpleados(); } else if (esProducto == 1) { this.comboBox.DataSource = NProductos.ListaProductos(); } this.comboBox.ValueMember = "ID"; this.comboBox.DisplayMember = "NOMBRE"; }
//btnEliminar - Evento Click - Elimina el producto selecionado en el dgvProductos. private void btnEliminar_Click(object sender, EventArgs e) { //Verificacion de fila seleccionada. if (this.dgvProductos.Rows.Count > 0) { //Mensaje de confirmación. DialogResult MensajeConfirmacion = MessageBox.Show(String.Format("¿Seguro deseas eliminar el producto {0}?", Convert.ToString(ObtenerFila().Cells["DESCRIPCIÓN"].Value)), String.Format(Configuracion.Titulo, "Eliminar Producto"), MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (MensajeConfirmacion == DialogResult.Yes) { String Respuesta = NProductos.Eliminar(Convert.ToInt32(ObtenerFila().Cells["CÓDIGO"].Value)); if (Respuesta == "OK") { //Establece mensaje de eliminación el el "lblMensajes". Mensaje(String.Format("El producto {0} ha sido ELIMINADO", Convert.ToString(ObtenerFila().Cells["DESCRIPCIÓN"].Value))); //Muestra mensaje de eliminación al usuario mediante un MessageBox MessageBox.Show(String.Format("El producto {0} ha sido ELIMINADO", Convert.ToString(ObtenerFila().Cells["DESCRIPCIÓN"].Value)), String.Format(Configuracion.Titulo, "Producto Eliminado"), MessageBoxButtons.OK, MessageBoxIcon.Information); Refrescar(); } else { //Si ocurre un error muestra mensaje al usuario con la respuesta recibida. MessageBox.Show(Respuesta, String.Format(Configuracion.Titulo, "Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); Refrescar(); } } } else { MessageBox.Show("Debes seleccionar una fila para eliminar.", String.Format(Configuracion.Titulo, "Error"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
//txtBuscar - Evento TextChanged - Muestra los datos que coincidan con la búsqueda en el "dvgProductos". private void txtBuscar_TextChanged(object sender, EventArgs e) { if (this.txtBuscar.Text == String.Empty || this.cbxTipoBusqueda.Text == "") { Configuracion.NumeroPagina = 1; this.Mostrar(); this.panelPaginacion.Show(); } else { try { this.dgvProductos.DataSource = NProductos.Buscar(this.txtBuscar.Text, this.cbxTipoBusqueda.Text); } catch (Exception ex) { MessageBox.Show(ex.Message, String.Format(Configuracion.Titulo, "Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } this.panelPaginacion.Hide(); } }
//Método Mostrar - Muestra los registros actuales en el "dgvProveedores" y establece la cantidad de páginas. public void Mostrar() { this.dgvProductos.DataSource = NProductos.Mostrar(Configuracion.RegistrosPorPagina, Configuracion.NumeroPagina); Configuracion.CantidadPaginas = NProductos.Tamaño(Configuracion.RegistrosPorPagina); this.lblPaginacion.Text = String.Format("Página {0} de {1}.", Configuracion.NumeroPagina, Configuracion.CantidadPaginas); }
//btnAgregarActualizar - Evento Click - Inserta o edita un usuario de la base de datos. private void btnAgregarActualizar_Click(object sender, EventArgs e) { string Respuesta; decimal Costo; decimal Utilidad; decimal Existencia; if (this.lblTitulo.Text == "Nuevo Producto") { //Revisión de datos obligatorios if (String.IsNullOrWhiteSpace(txtDescripcion.Text)) { MessageBox.Show("Debe ingresar la descripción del producto.", String.Format(Configuracion.Titulo, "Dato Inválido"), MessageBoxButtons.OK, MessageBoxIcon.Warning); this.errorProvider.SetError(txtDescripcion, "Ingrese una descripción."); } else if (String.IsNullOrWhiteSpace(txtPrecioBase.Text)) { MessageBox.Show("Debe ingresar un precio libre de impuestos.", String.Format(Configuracion.Titulo, "Dato Inválido"), MessageBoxButtons.OK, MessageBoxIcon.Warning); this.errorProvider.SetError(txtPrecioBase, "Ingrese un precio libre de impuestos."); } else if (String.IsNullOrWhiteSpace(txtPrecioVenta.Text)) { MessageBox.Show("Debe ingresar un precio de venta.", String.Format(Configuracion.Titulo, "Dato Inválido"), MessageBoxButtons.OK, MessageBoxIcon.Warning); this.errorProvider.SetError(txtPrecioBase, "Ingrese un precio de venta."); } else { //Verifica si el producto es exento y extablece la normativa "(E.)" if (cbxImpuesto.Text == "EXENTO 00.00 %") { txtDescripcion.Text += " (E.)"; } //Verifica que los campos de Utilidad y costo hayan sido rellendados if (!String.IsNullOrEmpty(txtCosto.Text)) { Costo = Convert.ToDecimal(txtCosto.Text); } else { Costo = 0; } if (!String.IsNullOrEmpty(txtUtilidad.Text)) { Utilidad = Convert.ToDecimal(txtUtilidad.Text.Replace("%", "")); } else { Utilidad = 0; } if (!String.IsNullOrEmpty(txtExistencia.Text)) { Existencia = Convert.ToDecimal(txtExistencia.Text); } else { Existencia = 0; } //Ingresa los datos en la base de datos. Respuesta = NProductos.Insertar(txtDescripcion.Text, Costo, Convert.ToInt32(cbxImpuesto.SelectedValue), Utilidad, Convert.ToDecimal(txtPrecioBase.Text), Convert.ToDecimal(txtPrecioVenta.Text), Existencia, Convert.ToInt32(cbxCategoria.SelectedValue), this.ctrlProductos.IdUsuario); if (Respuesta == "OK") { //Muestra confirmación al usuario via MessageBox. MessageBox.Show("El producto fue ingresado en el sistema satisfactoriamente.", String.Format(Configuracion.Titulo, "Registro Exitoso"), MessageBoxButtons.OK, MessageBoxIcon.Information); ctrlProductos.Mostrar(); ctrlProductos.Mensaje(String.Format("El producto {0} ha sido AGREGADO satisfactoriamente. ", txtDescripcion.Text)); this.Close(); } else { //Muestra Respuesta error al usuario mediante MessageBox MessageBox.Show(Respuesta, String.Format(Configuracion.Titulo, "Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else if (this.lblTitulo.Text == "Editar Cliente") { //Verifica si el producto es exento y extablece la normativa "(E.)" if (cbxImpuesto.Text == "EXENTO 00.00 %") { txtDescripcion.Text += " (E.)"; } //Revisión de datos obligatorios. if (String.IsNullOrWhiteSpace(txtDescripcion.Text)) { MessageBox.Show("Debe ingresar la descripción del producto.", String.Format(Configuracion.Titulo, "Dato Inválido"), MessageBoxButtons.OK, MessageBoxIcon.Warning); this.errorProvider.SetError(txtDescripcion, "Ingrese una descripción."); } else if (String.IsNullOrWhiteSpace(txtPrecioBase.Text)) { MessageBox.Show("Debe ingresar un precio libre de impuestos.", String.Format(Configuracion.Titulo, "Dato Inválido"), MessageBoxButtons.OK, MessageBoxIcon.Warning); this.errorProvider.SetError(txtPrecioBase, "Ingrese un precio libre de impuestos."); } else if (String.IsNullOrWhiteSpace(txtPrecioVenta.Text)) { MessageBox.Show("Debe ingresar un precio de venta.", String.Format(Configuracion.Titulo, "Dato Inválido"), MessageBoxButtons.OK, MessageBoxIcon.Warning); this.errorProvider.SetError(txtPrecioBase, "Ingrese un precio de venta."); } else { //Verifica si el producto es exento y extable la normativa "(E.)" if (cbxImpuesto.Text == "EXENTO") { txtDescripcion.Text = txtDescripcion.Text.Replace(" (E.)", "") + " (E.)"; } //Verifica que los campos de Utilidad y costo hayan sido rellendados if (!String.IsNullOrEmpty(txtCosto.Text)) { Costo = Convert.ToDecimal(txtCosto.Text); } else { Costo = 0; } if (!String.IsNullOrEmpty(txtUtilidad.Text)) { Utilidad = Convert.ToDecimal(txtUtilidad.Text.Replace("%", "")); } else { Utilidad = 0; } if (!String.IsNullOrEmpty(txtExistencia.Text)) { Existencia = Convert.ToDecimal(txtExistencia.Text); } else { Existencia = 0; } Respuesta = NProductos.Editar(this.IdProducto, txtDescripcion.Text, Costo, Convert.ToInt32(cbxImpuesto.SelectedValue), Utilidad, Convert.ToDecimal(txtPrecioBase.Text), Convert.ToDecimal(txtPrecioVenta.Text), Existencia, Convert.ToInt32(cbxCategoria.SelectedValue), this.ctrlProductos.IdUsuario); if (Respuesta == "OK") { //Muestra confirmación al usuario via MessageBox. MessageBox.Show(String.Format("Los datos del producto {0} fueron modificados satisfactoriamente.", txtDescripcion.Text), String.Format(Configuracion.Titulo, "Actualización de Datos Exitosa"), MessageBoxButtons.OK, MessageBoxIcon.Information); ctrlProductos.Mostrar(); ctrlProductos.Mensaje(String.Format("Los Datos del producto {0} fueron modificados satisfactoriamente.", txtDescripcion.Text)); this.Close(); } else { //Muestra Respuesta error al usuario mediante MessageBox. MessageBox.Show(Respuesta, String.Format(Configuracion.Titulo, "Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public void CargarProductos() { this.comboBoxProductos.DataSource = NProductos.ListaProductos(); this.comboBoxProductos.ValueMember = "ID"; this.comboBoxProductos.DisplayMember = "NOMBRE"; }
public void Mostrar() { this.dataGridViewProductos.DataSource = NProductos.Mostrar(registrosPorPagina, numeroPagina); cantidadPaginas = NProductos.Tamaño(registrosPorPagina); this.labelPaginacion.Text = String.Format("Página {0} de {1}", numeroPagina, cantidadPaginas); }