private void tablaClientes_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex <= -1)
            {
                return;
            }

            DataGridViewRow row    = TablaRefacciones.CurrentRow;
            int             id     = int.Parse(row.Cells[0].Value.ToString());
            string          code   = row.Cells[1].Value as string;
            string          desc   = row.Cells[2].Value as string;
            decimal         minimo = decimal.Parse(row.Cells[3].Value.ToString());

            txtCodigo.Text = code;
            lblDesc.Text   = desc;
            txtPrecio.Text = minimo.ToString();
            txtCant.Text   = "1";

            CurrentRefaccion = new Refaccion
            {
                Id           = id,
                Codigo       = code,
                Descripcion  = desc,
                PrecioMinimo = minimo,
            };
        }
        private void txtCodigo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string code = txtCodigo.Text;
                //var s = RefaccionesToSelect.Where(el => el.Codigo.Equals(code)).FirstOrDefault();
                //if (s == null)
                //    return;

                //txtCant.Text = "1";
                //txtCodigo.Text = s.Codigo;
                //lblDesc.Text = s.Descripcion;
                //txtPrecio.Text = s.PrecioMinimo.ToString();
                var refaccion = RefaccionController.I.SearchByCode(code);

                if (refaccion == null)
                {
                    return;
                }

                txtCant.Text   = "1";
                lblDesc.Text   = refaccion.Descripcion;
                txtPrecio.Text = refaccion.PrecioMinimo.ToString();

                CurrentRefaccion = refaccion;
            }
        }
Пример #3
0
        public async Task <HttpResponseMessage> PutRefaccion(Refaccion Refaccion)
        {
            try
            {
                _refaccion = await db.Refaccion.FindAsync(Refaccion.IdRefaccion);

                if (_refaccion == null)
                {
                    return(new HttpResponseMessage(HttpStatusCode.NoContent));
                }
                else
                {
                    _refaccion.IdSistemaRefacciones = Refaccion.IdSistemaRefacciones;
                    _refaccion.IdUnidadMedida       = Refaccion.IdUnidadMedida;
                    _refaccion.NumeroParteRefaccion = Refaccion.NumeroParteRefaccion;
                    _refaccion.Nombre          = Refaccion.Nombre;
                    _refaccion.Marca           = Refaccion.Marca;
                    _refaccion.Posicion        = Refaccion.Posicion;
                    _refaccion.CostoUnidad     = Refaccion.CostoUnidad;
                    _refaccion.Cantidad        = Refaccion.Cantidad;
                    _refaccion.Activo_Inactivo = Refaccion.Activo_Inactivo;

                    await db.SaveChangesAsync();

                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(ex.Message)
                });
            }
        }
Пример #4
0
        public async Task <HttpResponseMessage> GetRefaccion(IdModelRefaccion id)
        {
            try
            {
                _refaccion = await db.Refaccion.FindAsync(id.IdReFaccion);

                if (_refaccion == null)
                {
                    return(new HttpResponseMessage(HttpStatusCode.NoContent));
                }
                else
                {
                    return(new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StringContent(JsonConvert.SerializeObject(_refaccion), System.Text.Encoding.UTF8, "application/json")
                    });
                }
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(ex.Message)
                });
            }
        }
Пример #5
0
        public async Task <HttpResponseMessage> DeleteRefaccion(IdModelRefaccion id)
        {
            try
            {
                _refaccion = await db.Refaccion.FindAsync(id.IdReFaccion);

                if (_refaccion == null)
                {
                    return(new HttpResponseMessage(HttpStatusCode.NoContent));
                }
                else
                {
                    _refaccion.Activo_Inactivo = false;
                    db.Entry(_refaccion).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(ex.Message)
                });
            }
        }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            bool isEmpty = !Helper.Llenos(txtCodigo, txtDescripcion, txtPrecioMinimo);

            if (isEmpty)
            {
                MessageBox.Show("Llene todos los campos, por favor", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
            }

            decimal minimo;

            string code           = txtCodigo.Text;
            string descripcion    = txtDescripcion.Text;
            bool   parseIncorrect = !decimal.TryParse(txtPrecioMinimo.Text, out minimo);

            if (parseIncorrect)
            {
                MessageBox.Show("El precio no es valido", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
            }
            minimo = Math.Round(minimo, 2);

            if (CurrentRefaccion == null)
            {
                var toAdd = new Refaccion()
                {
                    Codigo       = code,
                    Descripcion  = descripcion,
                    PrecioMinimo = minimo,
                };

                var res = Validator.Validate(toAdd);
                if (ShowErrorValidation.Valid(res))
                {
                    CurrentRefaccion = RefaccionController.I.Add(toAdd);
                }
            }
            else
            {
                CurrentRefaccion.Codigo       = code;
                CurrentRefaccion.Descripcion  = descripcion;
                CurrentRefaccion.PrecioMinimo = minimo;

                var res = Validator.Validate(CurrentRefaccion);
                if (ShowErrorValidation.Valid(res))
                {
                    CurrentRefaccion = RefaccionController.I.Edit(CurrentRefaccion);
                }
            }

            if (CurrentRefaccion == null)
            {
                MessageBox.Show("Error agregar o editar refaccion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            CurrentRefaccion = null;
            Helper.VaciarTexto(txtCodigo, txtDescripcion, txtPrecioMinimo);
        }
Пример #7
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _refacciones = null;
         _refaccion   = null;
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Пример #8
0
        public async Task <HttpResponseMessage> PostRefaccion(Refaccion Refaccion)
        {
            try
            {
                Refaccion.Activo_Inactivo = true;
                db.Refaccion.Add(Refaccion);
                await db.SaveChangesAsync();

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(ex.Message)
                });
            }
        }
Пример #9
0
        private void InitRefaccion(Entities db)
        {
            var refacciones = new Refaccion[]
            {
                new Refaccion
                {
                    Codigo       = "1",
                    Descripcion  = "Tijeras",
                    IsDeleted    = false,
                    PrecioMinimo = 12.00M,
                },
                new Refaccion
                {
                    Codigo       = "12",
                    Descripcion  = "Rodillo",
                    IsDeleted    = false,
                    PrecioMinimo = 12.00M,
                },
                new Refaccion
                {
                    Codigo       = "123",
                    Descripcion  = "Desarmadores",
                    IsDeleted    = false,
                    PrecioMinimo = 12.00M,
                },
                new Refaccion
                {
                    Codigo       = "1234",
                    Descripcion  = "Eliminado",
                    IsDeleted    = true,
                    PrecioMinimo = 12.00M,
                },
            };

            foreach (var item in refacciones)
            {
                db.Refaccion.Add(item);
                db.SaveChanges();
            }
        }
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            bool isValid = Helper.Llenos(txtCant, txtCodigo, txtPrecio) && CurrentRefaccion != null;

            if (!isValid)
            {
                return;
            }

            int     cantidad = int.Parse(txtCant.Text);
            decimal precio   = decimal.Parse(txtPrecio.Text);

            if (precio < CurrentRefaccion.PrecioMinimo)
            {
                MessageBox.Show("El precio es menor que el costo minimo", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
            }

            var newRef = new RefaccionDTO()
            {
                Id            = CurrentRefaccion.Id,
                Codigo        = CurrentRefaccion.Codigo,
                Descripcion   = CurrentRefaccion.Descripcion,
                Cantidad      = cantidad,
                PrecioUnitrio = precio,
            };

            var resp = RefaccionValidator.Validate(newRef);

            if (ShowErrorValidation.Valid(resp))
            {
                Refacciones.Add(newRef);
            }

            MessageDialog.ShowMessageDialog("", $"Se ha agregado la refaccion {CurrentRefaccion.Codigo} a la orden ", true);
            Helper.VaciarTexto(txtCant, txtCodigo, txtPrecio);
            CurrentRefaccion = null;
        }
 public invNuevo_Mod(Refaccion refaccion)
 {
     InitializeComponent();
     this.CurrentRefaccion = refaccion;
     Validator             = new RefaccionValidator();
 }