Example #1
0
        protected void btn_Buscar_Click(object sender, EventArgs e)
        {
            DTOInventario inven      = new DTOInventario();
            CADInventario inventario = new CADInventario();
            int           refe       = 0;

            try
            {
                inven.Referencia_Producto = buscar.Text;
                refe = inventario.ConsultarProductoPorRef(inven);
            }
            catch
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "nopermitecamp", "campos();", true);
            }
            if (refe > 0)
            {
                inventario.BuscarProductoYCargarloAlGV(inven, GVProductos);
            }
            else
            {
                inventario.CargarProductos(GVProductos);
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "noregist", "noregistrado();", true);
            }
            opciontabla.SelectedIndex = opciontabla.Items.IndexOf(opciontabla.Items.FindByText("Mostrar"));
            buscar.Text = "";
        }
Example #2
0
        protected void fin_pedido_Click(object sender, EventArgs e)
        {
            DTOInventario datos    = new DTOInventario();
            CADInventario procesos = new CADInventario();

            if (procesos.InsertarPedido())
            {
                datos.Id_Pedido = procesos.consultarMaximoPedido();
                List <DTOInventario> hilos = new List <DTOInventario>();
                hilos = procesos.consultarPasoParaFinalizarPedido();
                foreach (var item in hilos)
                {
                    datos.Id_Hilo         = item.Id_Hilo;
                    datos.Metros_Hilo     = item.Metros_Hilo;
                    datos.ValorTotal_Hilo = item.ValorTotal_Hilo;
                    datos.ValorTotal      = item.ValorTotal;
                    try
                    {
                        procesos.InsertarPedidoH(datos);
                        procesos.EliminarPaso();
                    }
                    catch
                    {
                        ScriptManager.RegisterClientScriptBlock(this, GetType(), "error", "problema();", true);
                        break;
                    }
                }
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "mensaje", "registro();", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "error", "problema();", true);
            }
        }
Example #3
0
        protected void btn_Buscar_Click(object sender, EventArgs e)
        {
            DTOInventario inven      = new DTOInventario();
            CADInventario inventario = new CADInventario();
            int           refe       = 0;

            try
            {
                inven.Referencia_Hilo = buscar.Text;
                refe = inventario.ConsultarHiloPorRef(inven);
            }
            catch
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "nopermitecamp", "campos();", true);
            }
            if (refe > 0)
            {
                inventario.BuscarHiloYCargarloAlGV(inven, GVHilos);
            }
            else
            {
                inventario.CargarHilos(GVHilos);
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "noregist", "noregistrado();", true);
            }
            buscar.Text = "";
        }
Example #4
0
        public List <DTOInventario> hilo_por_id(int id)
        {
            List <DTOInventario> hilo    = new List <DTOInventario>();
            DTOInventario        datos   = new DTOInventario();
            CADInventario        proceso = new CADInventario();

            datos.Id_Hilo = id;
            hilo          = proceso.consultarHiloIdConsumo(datos);
            return(hilo);
        }
Example #5
0
        public List <DTOInventario> GetProduct(string referencia)
        {
            DTOInventario Referproducto = new DTOInventario();
            CADInventario Process       = new CADInventario();

            Referproducto.Referencia_Producto = referencia;
            List <DTOInventario> Product = Process.ConsultarProductoPorRefQR(Referproducto);

            return(Product);
        }
Example #6
0
        public List <DTOInventario> hilo(string referencia)
        {
            List <DTOInventario> hilo    = new List <DTOInventario>();
            DTOInventario        datos   = new DTOInventario();
            CADInventario        proceso = new CADInventario();

            datos.Referencia_Hilo = referencia;
            hilo = proceso.consultarHiloReferenciaConsumo(datos);
            return(hilo);
        }
Example #7
0
        public List <string> regisingre(int referenciap)
        {
            List <string> respuesta = new List <string>();
            DTOInventario datos     = new DTOInventario();
            CADInventario proceso   = new CADInventario();

            datos.Id_Pedido = referenciap;
            respuesta       = proceso.registeringreso(datos);
            return(respuesta);
        }
Example #8
0
        public List <DTOInventario> tablapedidoh(int referencia)
        {
            List <DTOInventario> tabla   = new List <DTOInventario>();
            DTOInventario        datos   = new DTOInventario();
            CADInventario        proceso = new CADInventario();

            datos.Id_Pedido = referencia;
            tabla           = proceso.tablapedidoshilos(datos);
            return(tabla);
        }
Example #9
0
        public List <DTOInventario> GetHilo(string code)
        {
            DTOInventario GuidHilo = new DTOInventario();
            CADInventario Process  = new CADInventario();

            GuidHilo.Code_Hilo = code;
            List <DTOInventario> Hilo = Process.ConsultarHiloPorGuidQR(GuidHilo);

            return(Hilo);
        }
Example #10
0
        public List <DTOInventario> buscarHiloPedido(string referencia)
        {
            List <DTOInventario> hilo  = new List <DTOInventario>();
            DTOInventario        datos = new DTOInventario();

            datos.Referencia_Hilo = referencia;
            CADInventario proceso = new CADInventario();

            hilo = proceso.buscarHiloPedidoRef(datos);
            return(hilo);
        }
Example #11
0
        public List <DTOInventario> buscarHiloPedidoId(int id)
        {
            List <DTOInventario> hilo  = new List <DTOInventario>();
            DTOInventario        datos = new DTOInventario();

            datos.Id_Hilo = id;
            CADInventario proceso = new CADInventario();

            hilo = proceso.buscarHiloPedidoId(datos);
            return(hilo);
        }
Example #12
0
        public List <DTOInventario> olvidarHilo(int id)
        {
            List <DTOInventario> hilos   = new List <DTOInventario>();
            DTOInventario        datos   = new DTOInventario();
            CADInventario        proceso = new CADInventario();

            datos.Id_Hilo = id;
            hilos         = proceso.olvidarHilo(datos);

            return(hilos);
        }
Example #13
0
        public List <DTOInventario> buscarProducto(string referencia)
        {
            List <DTOInventario> producto = new List <DTOInventario>();
            DTOInventario        datos    = new DTOInventario();
            CADInventario        procesos = new CADInventario();

            datos.Referencia_Producto = referencia;

            producto = procesos.buscarProductoConsumo(datos);

            return(producto);
        }
Example #14
0
        public List <DTOInventario> buscarProductoId(int id)
        {
            List <DTOInventario> producto = new List <DTOInventario>();
            DTOInventario        datos    = new DTOInventario();
            CADInventario        procesos = new CADInventario();

            datos.Id_Producto = id;

            producto = procesos.buscarProductoConsumoId(datos);

            return(producto);
        }
Example #15
0
        public List <DTOInventario> registrarHiloP(int id, float metros, float valor)
        {
            List <DTOInventario> hilos   = new List <DTOInventario>();
            DTOInventario        datos   = new DTOInventario();
            CADInventario        proceso = new CADInventario();

            datos.Id_Pedido       = proceso.consultarMaximoPedido();
            datos.Id_Hilo         = id;
            datos.Metros_Hilo     = metros;
            datos.ValorTotal_Hilo = metros * valor;
            hilos = proceso.registrarHiloP(datos);
            return(hilos);
        }
Example #16
0
        public List <DTOInventario> registrarHilo(int id, string referencia, float metros, float consumo)
        {
            List <DTOInventario> hilos   = new List <DTOInventario>();
            DTOInventario        datos   = new DTOInventario();
            CADInventario        proceso = new CADInventario();

            datos.Id_Hilo         = id;
            datos.Referencia_Hilo = referencia;
            datos.Metros_Hilo     = metros;
            datos.Consumo         = consumo;
            datos.Resta           = metros - consumo;
            hilos = proceso.registrarHilosPaso(datos);
            return(hilos);
        }
Example #17
0
        public List <DTOInventario> registrarProducto(int id, string referencia, float cantidad, float consumo)
        {
            List <DTOInventario> producto = new List <DTOInventario>();
            DTOInventario        datos    = new DTOInventario();
            CADInventario        proceso  = new CADInventario();

            datos.Id_Producto         = id;
            datos.Referencia_Producto = referencia;
            datos.Cantidad_Producto   = cantidad;
            datos.Consumo             = consumo;
            datos.Resta = cantidad - consumo;
            producto    = proceso.registrarProductoPaso(datos);
            return(producto);
        }
Example #18
0
        public int regisingreproduct(int idiped, int idi, int idpro, int cantid_ingreso, int cantidad_defectuosa, string detalles)
        {
            int           result  = 0;
            DTOInventario datos   = new DTOInventario();
            CADInventario proceso = new CADInventario();

            datos.Id_Pedido           = idiped;
            datos.Id_Ingreso          = idi;
            datos.Id_Producto         = idpro;
            datos.Cantidad_Ingreso    = cantid_ingreso;
            datos.Cantidad_Defectuoso = cantidad_defectuosa;
            datos.Detalles_Ingreso    = detalles;
            result = proceso.registeringresoproducto(datos);
            return(result);
        }
Example #19
0
        public List <DTOInventario> buscarProductoPId(int id)
        {
            //Instanciar objetos
            List <DTOInventario> producto = new List <DTOInventario>();
            DTOInventario        datos    = new DTOInventario();
            CADInventario        procesos = new CADInventario();

            //Dar valores al DTO
            datos.Id_Producto = id;

            //Asignar valores al List
            producto = procesos.buscarProductoPId(datos);

            //Retornar List
            return(producto);
        }
Example #20
0
        public List <DTOInventario> buscarProductoP(string referencia)
        {
            //Instanciar objetos
            List <DTOInventario> producto = new List <DTOInventario>();
            DTOInventario        datos    = new DTOInventario();
            CADInventario        procesos = new CADInventario();

            //Llenar valores al DTO
            datos.Referencia_Producto = referencia;

            //Llenar List invocando función del CAD
            producto = procesos.buscarProductoPRef(datos);

            //Retornar List
            return(producto);
        }
Example #21
0
        public List <DTOInventario> registrarProductoPaso(int id, float cantidad, float valor)
        {
            //Instanciar objetos
            List <DTOInventario> productos = new List <DTOInventario>();
            DTOInventario        datos     = new DTOInventario();
            CADInventario        procesos  = new CADInventario();

            //Asignar valores al DTO
            datos.Id_Producto         = id;
            datos.Cantidad_Producto   = cantidad;
            datos.ValorTotal_Producto = cantidad * valor;

            //Llenar lista
            productos = procesos.registrarProductoPasoPed(datos);

            //Retornar lista
            return(productos);
        }
Example #22
0
        public int regisingrehilo(int idiped, int idi, int idh, float cantid_ingreso, float cantidad_defectuosa, string detalles)
        {
            int result  = 0;
            var culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();

            culture.NumberFormat.NumberDecimalSeparator = ".";
            DTOInventario datos   = new DTOInventario();
            CADInventario proceso = new CADInventario();

            datos.Id_Pedido                = idiped;
            datos.Id_Ingreso               = idi;
            datos.Id_Hilo                  = idh;
            datos.Cantidad_Ingreso_Hilo    = cantid_ingreso;
            datos.Cantidad_Defectuoso_Hilo = cantidad_defectuosa;
            datos.Detalles_Ingreso         = detalles;
            result = proceso.registeringresohilo(datos);
            return(result);
        }
Example #23
0
        protected void fin_consumo_Click(object sender, EventArgs e)
        {
            //Instanciar objetos
            DTOInventario        datos     = new DTOInventario();
            CADInventario        procesos  = new CADInventario();
            List <DTOInventario> productos = new List <DTOInventario>();

            //Si crear un nuevo pedido es exitoso entonces...
            if (procesos.InsertarPedido())
            {
                //Consultar el id del pedido recien creado
                datos.Id_Pedido = procesos.consultarMaximoPedido();

                //Consultar los productos registrados en la tabla paso
                productos = procesos.consultarPasoParaFinalizarPedido();

                //Recorrer list
                foreach (var item in productos)
                {
                    //Dar valores al DTO
                    datos.Id_Producto         = item.Id_Producto;
                    datos.Cantidad_Producto   = item.Cantidad_Producto;
                    datos.ValorTotal_Producto = item.ValorTotal_Producto;
                    datos.ValorTotal          = item.ValorTotal;

                    //Intentar ejecutar la inserción de los productos y la elimináción de tabla Paso
                    try
                    {
                        procesos.InsertarPedidoP(datos);
                        procesos.EliminarPaso();
                    }
                    catch
                    {
                        ScriptManager.RegisterClientScriptBlock(this, GetType(), "error", "problema();", true);
                        break;
                    }
                }
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "mensaje", "registro();", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "error", "problema();", true);
            }
        }
Example #24
0
        protected void GVHilos_RowEditing(object sender, GridViewEditEventArgs e)
        {
            CADInventario inventario = new CADInventario();
            DTOInventario inven      = new DTOInventario();

            inven.Id_Hilo = int.Parse(GVHilos.DataKeys[e.NewEditIndex].Values[0].ToString());
            if (inventario.CompletarRegistroHilosParaModificar(inven, codigo, referencia, tipoh, titulo, color, tmetros, valor) == 0)
            {
                btn_Registrar.CssClass  = "btn btn-default";
                btn_Registrar.Enabled   = false;
                btn_Actualizar.CssClass = "btn btn-default";
                btn_Actualizar.Enabled  = true;
                btn_Cancelar.CssClass   = "btn btn-default";
                btn_Cancelar.Enabled    = true;
                tmetros.ReadOnly        = true;
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "error", "problema();", true);
            }
            inventario.CargarHilos(GVHilos);
        }
Example #25
0
        protected void GVProductos_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int           id         = Convert.ToInt32(GVProductos.DataKeys[e.NewEditIndex].Values[0]);
            CADInventario inventario = new CADInventario();
            DTOInventario inven      = new DTOInventario();

            inven.Id_Producto = id;
            if (inventario.CompletarRegistroProductoParaModificar(inven, codigo, referencia, nombre, descripcion, novedad, placa, serial, marca, modelo, cantidad, valorUnitario, consumible) == 0)
            {
                btn_Registrar.CssClass  = "btn btn-default";
                btn_Registrar.Enabled   = false;
                btn_Actualizar.CssClass = "btn btn-default";
                btn_Actualizar.Enabled  = true;
                btn_Cancelar.CssClass   = "btn btn-default";
                btn_Cancelar.Enabled    = true;
                cantidad.ReadOnly       = true;
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "error", "problema();", true);
            }
            inventario.CargarProductos(GVProductos);
        }
Example #26
0
        protected void fin_consumo_Click(object sender, EventArgs e)
        {
            int           id_u    = Convert.ToInt32(Session["id_usuario"]);
            DTOInventario datos   = new DTOInventario();
            CADInventario proceso = new CADInventario();

            datos.Id_Usuario = id_u;

            if (proceso.InsertarConsumo(datos) == 0)
            {
                datos.Id_Consumo    = proceso.consultarMaximoConsumo();
                datos.Id_Inventario = proceso.consultarMaximoInventarioHilo();
                List <DTOInventario> hilos = new List <DTOInventario>();
                hilos = proceso.consultarPasoParaFinalizarConsumo();
                foreach (var item in hilos)
                {
                    datos.Id_Hilo = item.Id_Hilo;
                    datos.Consumo = item.Consumo;
                    try
                    {
                        proceso.InsertarConsumoHilo(datos);
                        proceso.EliminarPaso();
                    }
                    catch
                    {
                        ScriptManager.RegisterClientScriptBlock(this, GetType(), "error", "problema();", true);
                        break;
                    }
                }
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "mensaje", "registro();", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "error", "problema();", true);
            }
        }
Example #27
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            CADInventario process = new CADInventario();
            DTOInventario invent  = new DTOInventario();

            if (referencia.Text != "" && observaciones.Text != "")
            {
                invent.Referencia_Inventario  = referencia.Text;
                invent.Observacion_Inventario = observaciones.Text;
                //validar que el inventario no exista
                if (process.ConsultarInventarioPorReferencia(invent) == 0)
                {
                    //Registrar inventario
                    //Validar proceso exitoso
                    if (process.RegistrarInventario(invent) == 0)
                    {
                        //Obtener id del inventario registrado
                        invent.Id_Inventario = process.ObtenerIdInventarioPorReferencia(invent);

                        int resultp = 0;
                        //Recorrer gridview productos para registrarlos  en el inventario
                        foreach (GridViewRow row in GridView1.Rows)
                        {
                            invent.Id_Producto       = int.Parse((row.FindControl("codigop") as Label).Text);
                            invent.Cantidad_Producto = float.Parse((row.FindControl("cantidadp") as TextBox).Text);
                            invent.Novedad_Producto  = (row.FindControl("novedadp") as TextBox).Text;
                            if (process.RegistrarInventarioProducto(invent) == 0)
                            {
                                resultp++;
                            }
                        }

                        int resulth = 0;
                        //Recorrer gridiview hilos para registralos en el inventario
                        if (resultp > 0)
                        {
                            foreach (GridViewRow row in GridView2.Rows)
                            {
                                invent.Id_Hilo     = int.Parse((row.FindControl("codigoh") as Label).Text);
                                invent.Metros_Hilo = float.Parse((row.FindControl("metrosh") as TextBox).Text);
                                if (process.RegistrarInventarioHilo(invent) == 0)
                                {
                                    resulth++;
                                }
                            }
                        }

                        //Validar que se hayan registrado los hilos y productos en el inventario
                        if (resultp > 0 && resulth > 0)
                        {
                            referencia.Text    = "";
                            observaciones.Text = "";
                            //alerta resultado exitoso
                            ScriptManager.RegisterClientScriptBlock(this, GetType(), "correcto", "registro();", true);
                        }
                        else
                        {
                            //alerta error inesperado
                            ScriptManager.RegisterClientScriptBlock(this, GetType(), "errorinesp", "problema();", true);
                        }
                    }
                    else
                    {
                        //Aletar error inesperado
                        ScriptManager.RegisterClientScriptBlock(this, GetType(), "errorines", "problema();", true);
                    }
                }
                else
                {
                    //ALERTA: Ya existe inventario con esa referencia
                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "ya", "yaexiste();", true);
                }
            }
            else
            {
                //alerta complete los campos
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "nopermitecamp", "campos();", true);
            }
        }
Example #28
0
        protected void btn_Registrar_Click(object sender, EventArgs e)
        {
            int           val        = 0;
            int           consu      = 2;
            int           confirma   = 0;
            int           cantid_p   = 0;
            DTOInventario inven      = new DTOInventario();
            CADInventario inventario = new CADInventario();

            try
            {
                val      = Convert.ToInt32(valorUnitario.Text);
                consu    = Convert.ToInt32(consumible.SelectedValue);
                cantid_p = Convert.ToInt32(cantidad.Text);
            }
            catch
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "nopermitecamp", "campos();", true);
            }
            if (referencia.Text != "" && nombre.Text != "" && descripcion.Text != "" && novedad.Text != "" && placa.Text != "" && serial.Text != "" && marca.Text != "" && modelo.Text != "")
            {
                confirma += 1;
            }
            if (val != 0 && consu >= 0 && consu < 2)
            {
                confirma += 1;
            }
            if (confirma == 2)
            {
                inven.Referencia_Producto    = referencia.Text;
                inven.Nombre_Producto        = nombre.Text;
                inven.Descripcion_Producto   = descripcion.Text;
                inven.Novedad_Producto       = novedad.Text;
                inven.Placa_Producto         = placa.Text;
                inven.Serial_Producto        = serial.Text;
                inven.Marca_Producto         = marca.Text;
                inven.Modelo_Producto        = modelo.Text;
                inven.ValorUnitario_Producto = val;
                inven.Consumible             = consu;
                inven.Cantidad_Producto      = cantid_p;
                if (inventario.ConsultarProductoPorPlaca(inven) == 0)
                {
                    if (inventario.ConsultarProductoPorSerial(inven) == 0)
                    {
                        if (inventario.InsertarProducto(inven) == 0)
                        {
                            //Genernado Codigo QR
                            QrEncoder qrencoder = new QrEncoder();
                            QrCode    qrcode    = new QrCode();
                            //Recolectando referencia producto
                            qrencoder.TryEncode(placa.Text, out qrcode);
                            //Generar dicho datos con cierta estructura y estipular colores
                            GraphicsRenderer renderer = new GraphicsRenderer(new FixedCodeSize(400, QuietZoneModules.Zero), Brushes.Black, Brushes.White);
                            //Memoria de datos
                            MemoryStream ms = new MemoryStream();

                            renderer.WriteToStream(qrcode.Matrix, ImageFormat.Png, ms);
                            var image       = new Bitmap(ms);
                            var imagenfinal = new Bitmap(image, new Size(new Point(200, 200)));
                            //Guardar codigoQR en carpeta servidor
                            imagenfinal.Save(Server.MapPath("~/QR/") + placa.Text + ".png", ImageFormat.Png);
                            DTOUsuario u       = new DTOUsuario();
                            CADUsuario process = new CADUsuario();
                            u.Id_u_logueado       = int.Parse(Convert.ToString(Session["id_usuario"]));
                            u.Descripcion_history = "Registro producto placa: " + placa.Text;
                            process.InsertarHistorial(u);
                            btn_Registrar.CssClass  = "btn btn-default";
                            btn_Registrar.Enabled   = true;
                            btn_Actualizar.CssClass = "btn btn-default";
                            btn_Actualizar.Enabled  = false;
                            btn_Cancelar.CssClass   = "btn btn-default";
                            btn_Cancelar.Enabled    = false;
                            codigo.Text             = "";
                            referencia.Text         = "";
                            nombre.Text             = "";
                            descripcion.Text        = "";
                            novedad.Text            = "";
                            placa.Text         = "";
                            serial.Text        = "";
                            marca.Text         = "";
                            modelo.Text        = "";
                            cantidad.Text      = "";
                            valorUnitario.Text = "";
                            inventario.CargarProductos(GVProductos);
                            ScriptManager.RegisterClientScriptBlock(this, GetType(), "mensaje", "registro();", true);
                        }
                        else
                        {
                            ScriptManager.RegisterClientScriptBlock(this, GetType(), "inconsis", "problema();", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(this, GetType(), "yaexisserial", "yaexisteserial();", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "yaexisplaca", "yaexisteplaca();", true);
                }
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "nopermitecamp", "campos();", true);
            }
            inventario.CargarProductos(GVProductos);
        }
Example #29
0
        private void btRodar_Click(object sender, EventArgs e)
        {
            int          quantInv;
            DialogResult d = MessageBox.Show("Deseja rodar o inventário " + txtNumeroInventario.Text + " e gerar os movimentos relativos a ele?", "Aviso", MessageBoxButtons.YesNo);

            if (d.ToString() == "Yes")
            {
                DALConexao cx = new DALConexao(DadosDaConexao.StringDaConexao);

                DTOInventario inv    = new DTOInventario();
                BLLInventario bllinv = new BLLInventario(cx);
                bllinv.Concluir(Convert.ToInt32(txtNumeroInventario.Text));

                // gerar movimentações de estoque

                DTOMovimento mov    = new DTOMovimento();
                BLLMovimento bllmov = new BLLMovimento(cx);

                for (int i = 0; i < dgvInventario.RowCount; i++)
                {
                    mov.Lancamento     = 0;
                    mov.NfMov          = Convert.ToInt32(txtNumeroInventario.Text);
                    mov.DataNfMov      = Convert.ToDateTime(txtDataInventario.Text);
                    mov.DataCriacaoMov = DateTime.Now;
                    mov.DataMov        = Convert.ToDateTime(txtDataMovimento.Text);
                    mov.IdUnidade      = Convert.ToInt32(cbUnidade.SelectedValue);
                    mov.IdFornecedor   = Convert.ToInt32(cbUnidade.SelectedValue);
                    mov.IdUsuario      = idUsuario;
                    mov.TipoMov        = "Inventario";


                    mov.IdProduto = Convert.ToInt32(dgvInventario.Rows[i].Cells[0].Value);


                    //buscar quantidade de diferença
                    try
                    {
                        quantInv = Convert.ToInt32(dgvInventario.Rows[i].Cells[5].Value);
                    }
                    catch
                    {
                        quantInv = 0;
                    }

                    int      ultimoInv   = 0;
                    int      ultimosMovs = 0;
                    DateTime dataUltimoInv;


                    //Localiza quantidade do último inventario concluído.

                    string buscaUltimoInv = "select inventario, data_mov_inv, id_produto, quant_inv from inventario " +
                                            " where concluido = 'c' and id_produto = " + mov.IdProduto +
                                            " and data_mov_inv < '" + Convert.ToDateTime(txtDataMovimento.Text).ToString("d") + "' order by data_mov_inv asc;";

                    BLLInventario bll    = new BLLInventario(cx);
                    DataTable     tabela = bll.Localizar(buscaUltimoInv);

                    try
                    {
                        ultimoInv = Convert.ToInt32(tabela.Rows[0]["quant_inv"]);
                    }
                    catch
                    {
                        ultimoInv = 0;
                    }

                    try
                    {
                        dataUltimoInv = Convert.ToDateTime(tabela.Rows[0]["data_mov_inv"]);
                    }
                    catch
                    {
                        DateTime data = new DateTime(1900, 1, 1);
                        dataUltimoInv = data;
                    }


                    //Soma movimentos de um período de tempo.
                    //select sum(quant_mov) as quantidade, id_produto from movimentacao where data_mov between '2016-05-10' and '2016-05-24' and id_produto = 38 group by id_produto, quant_mov;

                    string buscaQuantMovimentacoes = "select sum(quant_mov) as quantidade, id_produto from movimentacao " +
                                                     "where data_mov > '" + dataUltimoInv.ToString("d") + "' and data_mov <= '" + Convert.ToDateTime(txtDataMovimento.Text).ToString("d") +
                                                     "' and id_produto = " + mov.IdProduto + " group by id_produto;";


                    BLLMovimento bllquantmov = new BLLMovimento(cx);
                    DataTable    tabelamov   = bllquantmov.LocalizarValor(buscaQuantMovimentacoes);

                    try
                    {
                        ultimosMovs = Convert.ToInt32(tabelamov.Rows[0]["quantidade"]);
                    }
                    catch
                    {
                        ultimosMovs = 0;
                    }

                    mov.QuantMov = quantInv - (ultimoInv + ultimosMovs);


                    //Buscar custo unitario da ultima movimentacao de entrada

                    string buscacusto = "select * from movimentacao " +
                                        "where id_produto = " + mov.IdProduto + " order by data_mov desc;";

                    BLLMovimento bllCustotmov = new BLLMovimento(cx);
                    DataTable    tabelacusto  = bllCustotmov.LocalizarValor(buscacusto);
                    try
                    {
                        mov.CustoUnitMov = Convert.ToDouble(tabelacusto.Rows[0]["custo_unitario_mov"]);
                    }
                    catch
                    {
                        mov.CustoUnitMov = 0.00;
                    }
                    bllmov.Incluir(mov);
                }

                MessageBox.Show("Inventário processado com sucesso.");
                LimpaCampos();

                AlteraBotoes(1);
            }
        }
Example #30
0
        private void Salvar()
        {
            DALConexao cx = new DALConexao(DadosDaConexao.StringDaConexao);

            DTOInventario rodainv = new DTOInventario();
            BLLInventario bllinv  = new BLLInventario(cx);


            if (this.operacao != "Editar")
            {
                try
                {
                    SqlConnection  con = new SqlConnection(DadosDaConexao.StringDaConexao.ToString()); // making connection
                    SqlDataAdapter sda = new SqlDataAdapter("select max(inventario) from inventario", con);

                    DataTable dt = new DataTable(); //this is creating a virtual table
                    sda.Fill(dt);

                    nrInventario             = Convert.ToInt32(dt.Rows[0][0]);
                    nrInventario             = nrInventario + 1;
                    txtNumeroInventario.Text = nrInventario.ToString("00000000");
                }
                catch
                {
                    txtNumeroInventario.Text = "00000001";
                }
            }

            for (int i = 0; i < dgvInventario.RowCount; i++)
            {
                rodainv.Inventario            = Convert.ToInt32(txtNumeroInventario.Text);
                rodainv.DataCriacaoInventario = Convert.ToDateTime(txtDataInventario.Text);
                rodainv.DataMovInventario     = Convert.ToDateTime(txtDataMovimento.Text);
                rodainv.IdUnidade             = Convert.ToInt32(cbUnidade.SelectedValue);
                rodainv.IdProduto             = Convert.ToInt32(dgvInventario.Rows[i].Cells[0].Value);

                try
                {
                    rodainv.QuantInv = Convert.ToInt32(dgvInventario.Rows[i].Cells[5].Value);
                }
                catch
                {
                    rodainv.QuantInv = 0;
                }


                if (cbTipoInv.Text == "Inventário")
                {
                    rodainv.Tipo = "C";
                }
                else
                {
                    rodainv.Tipo = "I";
                }



                rodainv.IdUsuario = Convert.ToInt32(idUsuario);
                rodainv.concluido = "A";

                bllinv.Incluir(rodainv);
            }
        }