Ejemplo n.º 1
0
 public FrmVenta()
 {
     InitializeComponent();
     this.TopLevel    = false;
     this.WindowState = FormWindowState.Maximized;
     Titulo           = "Toma de pedidos";
     consumidorFinal  = UtilsData.Get <Cliente>(1);
     ClienteActual    = consumidorFinal;
 }
Ejemplo n.º 2
0
        private void MyCRUDButtonsClientes_ButtonEvent(Actions accion)
        {
            switch (accion)
            {
            case Actions.New:
            {
                txtCedula.Clear();
                txtNombre.Clear();
                txtId.Clear();

                BloquearCampos(false);
                txtCedula.Focus();
                break;
            }

            case Actions.Cancel:
            {
                BloquearCampos(true);
                myBasicControlEntity.Focus();
                MyBasicControlEntity_EventoEntityChanged(null, null);
                break;
            }

            case Actions.Delete:
            {
                var entity = myBasicControlEntity.SelectedEntity;
                entity.Status = Status.Inactivo;
                int count = UtilsData.SaveContext(ref context);
                if (count > 0)
                {
                    LoadData();
                    MessageBox.Show("Registro eliminado correctamente", "Listo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (myBasicControlEntity.Count > 0)
                    {
                        myBasicControlEntity.Focus();
                    }
                    else
                    {
                        myCRUDButtonsClientes.Focus();
                    }
                }
                else
                {
                    context = new Context();
                    LoadData();
                    myBasicControlEntity.ClearFilter();
                }
                break;
            }

            case Actions.Edit:
            {
                BloquearCampos(false);
                txtCedula.Focus();
                break;
            }

            case Actions.Save:
            {
                var entity = new Cliente()
                {
                    Cedula = txtCedula.Text,
                    Nombre = txtNombre.Text,
                    Status = Status.Activo
                };
                if (myCRUDButtonsClientes.Bandera == BanderaGuardar.Edit)
                {
                    var entry = ((Cliente)myBasicControlEntity.SelectedEntity);
                    if (entry.Cedula != entity.Cedula)
                    {
                        bool violation = HaveUniqueViolation(entity.Cedula);
                        if (violation)
                        {
                            myCRUDButtonsClientes.Accion = Actions.Edit;
                            return;
                        }
                    }
                    entry.Cedula = entity.Cedula;
                    entry.Nombre = entity.Nombre;
                }
                else if (myCRUDButtonsClientes.Bandera == BanderaGuardar.New)
                {
                    bool violation = HaveUniqueViolation(entity.Cedula);
                    if (violation)
                    {
                        myCRUDButtonsClientes.Accion = Actions.New;
                        return;
                    }
                    context.Cliente.Add(entity);
                }
                int count = UtilsData.SaveContext(ref context);
                if (count > 0)
                {
                    LoadData();
                    MessageBox.Show("Cliente guardado correctamente", "Listo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (myBasicControlEntity.Count > 0)
                    {
                        myBasicControlEntity.Focus();
                    }
                    else
                    {
                        myCRUDButtonsClientes.Focus();
                    }
                }
                else
                {
                    context = new Context();
                    LoadData();
                    myBasicControlEntity.ClearFilter();
                    MyBasicControlEntity_EventoEntityChanged(null, null);
                    if (!(myBasicControlEntity.Count > 0))
                    {
                        myCRUDButtonsClientes.Accion = Actions.Neutro;
                    }
                }
                BloquearCampos(true);
                myBasicControlEntity.Focus();
                break;
            }

            default:
            {
                break;
            }
            }
        }
Ejemplo n.º 3
0
        private void GetProximaFactura()
        {
            int maxId = UtilsData.MaxId <CabeceraFactura>() + 1;

            labelNumeroFactura.Text = (maxId).ToString().PadLeft(9, '0');
        }
Ejemplo n.º 4
0
        private void MyCRUDButtonsProductos_ButtonEvent(Actions accion)
        {
            switch (accion)
            {
            case Actions.New:
            {
                txtCodigo.Clear();
                txtDescripcion.Clear();
                txtId.Clear();
                txtPrecio.Text                 = string.Empty;
                cmbCategoria.SelectedIndex     = 0;
                cmbMedida.SelectedIndex        = 0;
                pictureBoxImagen.ImageLocation = string.Empty;
                BloquearCampos(false);
                txtCodigo.Focus();
                break;
            }

            case Actions.Cancel:
            {
                BloquearCampos(true);
                myBasicControlEntity.Focus();
                MyBasicControlEntity_EventoEntityChanged(null, null);
                break;
            }

            case Actions.Delete:
            {
                var entity = myBasicControlEntity.SelectedEntity;
                entity.Status = Status.Inactivo;
                int count = UtilsData.SaveContext(ref context);
                if (count > 0)
                {
                    LoadData();
                    MessageBox.Show("Registro eliminado correctamente", "Listo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (myBasicControlEntity.Count > 0)
                    {
                        myBasicControlEntity.Focus();
                    }
                    else
                    {
                        myCRUDButtonsProductos.Focus();
                    }
                }
                else
                {
                    context = new Context();
                    LoadData();
                    myBasicControlEntity.ClearFilter();
                }
                break;
            }

            case Actions.Edit:
            {
                BloquearCampos(false);
                txtCodigo.Focus();
                break;
            }

            case Actions.Save:
            {
                decimal precio     = txtPrecio.DollarValue;
                string  rutaImagen = string.Concat(this.rutaImagenes, DateTime.Now.ToString("yyyyMMdd hhmmss"));
                if (string.IsNullOrEmpty(this.pictureBoxImagen.ImageLocation))
                {
                    rutaImagen = string.Empty;
                }
                var entity = new Producto()
                {
                    Codigo      = txtCodigo.Text,
                    Categoria   = ((Categoria)((CustomAttribute)cmbCategoria.SelectedItem).Id),
                    Descripcion = txtDescripcion.Text,
                    Medida      = ((Medida)((CustomAttribute)cmbMedida.SelectedItem).Id),
                    Precio      = precio,
                    Status      = Status.Activo,
                    RutaImagen  = rutaImagen
                };
                if (myCRUDButtonsProductos.Bandera == BanderaGuardar.Edit)
                {
                    var entry = ((Producto)myBasicControlEntity.SelectedEntity);
                    if (entry.Codigo != entity.Codigo)
                    {
                        bool violation = HaveUniqueViolation(entity.Codigo);
                        if (violation)
                        {
                            myCRUDButtonsProductos.Accion = Actions.Edit;
                            return;
                        }
                    }
                    entry.Categoria   = entity.Categoria;
                    entry.Codigo      = entity.Codigo;
                    entry.Descripcion = entity.Descripcion;
                    entry.Medida      = entity.Medida;
                    entry.Precio      = entity.Precio;
                    entry.RutaImagen  = entity.RutaImagen;
                }
                else if (myCRUDButtonsProductos.Bandera == BanderaGuardar.New)
                {
                    bool violation = HaveUniqueViolation(entity.Codigo);
                    if (violation)
                    {
                        myCRUDButtonsProductos.Accion = Actions.New;
                        return;
                    }
                    context.Producto.Add(entity);
                }
                int count = UtilsData.SaveContext(ref context);
                if (count > 0)
                {
                    LoadData();
                    MessageBox.Show("Producto guardado correctamente", "Listo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (myBasicControlEntity.Count > 0)
                    {
                        myBasicControlEntity.Focus();
                    }
                    else
                    {
                        myCRUDButtonsProductos.Focus();
                    }
                }
                else
                {
                    context = new Context();
                    LoadData();
                    myBasicControlEntity.ClearFilter();
                    MyBasicControlEntity_EventoEntityChanged(null, null);
                    if (!(myBasicControlEntity.Count > 0))
                    {
                        myCRUDButtonsProductos.Accion = Actions.Neutro;
                    }
                }
                BloquearCampos(true);
                myBasicControlEntity.Focus();
                break;
            }

            default:
            {
                break;
            }
            }
        }