Esempio n. 1
0
        public in_ajusteFisico_Info Get_info()
        {
            try
            {
                Info_AjusteFisico                           = new Info.Inventario.in_ajusteFisico_Info();
                Info_AjusteFisico.IdEmpresa                 = param.IdEmpresa;
                Info_AjusteFisico.IdAjusteFisico            = txtNumAjusteFisico.Text == "" ? 0 : Convert.ToDecimal(txtNumAjusteFisico.Text);
                gridViewAjusteInventario.ActiveFilterString = "";

                Info_Bodega   = Ctrl_SucBod.get_bodega();
                Info_Sucursal = Ctrl_SucBod.get_sucursal();
                Info_AjusteFisico.Observacion           = txtObservacion.Text;
                Info_AjusteFisico.IdBodega              = Info_Bodega.IdBodega;
                Info_AjusteFisico.IdSucursal            = Info_Sucursal.IdSucursal;
                Info_AjusteFisico.IdMovi_inven_tipo_Egr = Ctrl_MoviEgreso.get_TipoMoviInvInfo().IdMovi_inven_tipo;
                Info_AjusteFisico.IdMovi_inven_tipo_Ing = Ctrl_MoviIngreso.get_TipoMoviInvInfo().IdMovi_inven_tipo;
                Info_AjusteFisico.Estado             = (lblAnulado.Visible == true) ? "I" : "A";
                Info_AjusteFisico.Fecha              = dtp_fecha.Value;
                Info_AjusteFisico.IdEstadoAprobacion = ucIn_Catalogos_Cmb1.Get_CatalogosInfo().IdCatalogo;



                decimal En = 0;
                if (decimal.TryParse(txtNumMoviAjustEgreso.Text, out En))
                {
                    Info_AjusteFisico.IdNumMovi_Egr = En;
                }

                decimal Ing = 0;
                if (decimal.TryParse(txtMoviAjustIngreso.Text, out Ing))
                {
                    Info_AjusteFisico.IdNumMovi_Ing = Ing;
                }

                foreach (var item in BindingList_Producto)
                {
                    in_AjusteFisico_Detalle_Info infoAjusteDetalle = new in_AjusteFisico_Detalle_Info();
                    infoAjusteDetalle.IdAjusteFisico   = IdAjusteFisico;
                    infoAjusteDetalle.IdEmpresa        = param.IdEmpresa;
                    infoAjusteDetalle.IdProducto       = item.IdProducto;
                    infoAjusteDetalle.CantidadAjustada = Convert.ToDouble(item.CantidadAjustada);
                    infoAjusteDetalle.StockFisico      = Convert.ToDouble(item.StockFisico);
                    infoAjusteDetalle.StockSistema     = item.pr_stock == null ? 0 : Convert.ToDouble(item.pr_stock);
                    infoAjusteDetalle.IdCentroCosto    = item.IdCentroCosto;
                    Info_AjusteFisico.list_det_AjusteFisico.Add(infoAjusteDetalle);
                }

                return(Info_AjusteFisico);
            }
            catch (Exception ex)
            {
                Log_Error_bus.Log_Error(ex.ToString());
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(new in_ajusteFisico_Info());
            }
        }
        public List <in_AjusteFisico_Detalle_Info> Get_List_AjusteFisico_Detalle(int IdEmpresa, decimal IdAjusteFisico)
        {
            try
            {
                List <in_AjusteFisico_Detalle_Info> List = new List <in_AjusteFisico_Detalle_Info>();

                EntitiesInventario oEntities = new EntitiesInventario();

                var select = from q in oEntities.in_AjusteFisico_Detalle
                             where q.IdEmpresa == IdEmpresa &&
                             q.IdAjusteFisico == IdAjusteFisico
                             select q;



                foreach (var item in select)
                {
                    in_AjusteFisico_Detalle_Info _Info = new in_AjusteFisico_Detalle_Info();
                    _Info.IdEmpresa        = item.IdEmpresa;
                    _Info.IdAjusteFisico   = item.IdAjusteFisico;
                    _Info.IdProducto       = item.IdProducto;
                    _Info.CantidadAjustada = item.CantidadAjustada;
                    _Info.StockFisico      = item.StockFisico;
                    _Info.StockSistema     = item.StockSistema;
                    _Info.IdCentroCosto    = item.IdCentroCosto;
                    List.Add(_Info);
                }
                return(List);
            }
            catch (Exception ex)
            {
                string arreglo = ToString();
                tb_sis_Log_Error_Vzen_Data oDataLog      = new tb_sis_Log_Error_Vzen_Data();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "", "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje);
                mensaje = ex.ToString() + " " + ex.Message;
                throw new Exception(ex.ToString());
            }
        }
Esempio n. 3
0
        private void ucGe_Menu_event_btnAprobar_Click(object sender, EventArgs e)
        {
            try
            {
                string mensaje_cbte_cble_ing = "";
                string mensaje_cbte_cble_egr = "";

                Get_info();


                in_AjusteFisico_Detalle_Bus BusAjusDeta = new in_AjusteFisico_Detalle_Bus();
                BusAjusDeta.EliminarDB(param.IdEmpresa, Convert.ToDecimal(txtNumAjusteFisico.Text));
                int s = 1;
                ListaAjuste = new List <in_AjusteFisico_Detalle_Info>();
                foreach (var item in BindingList_Producto)
                {
                    in_AjusteFisico_Detalle_Info infoAjusteDetalle = new in_AjusteFisico_Detalle_Info();
                    infoAjusteDetalle.IdAjusteFisico   = Convert.ToDecimal(txtNumAjusteFisico.Text);
                    infoAjusteDetalle.IdEmpresa        = param.IdEmpresa;
                    infoAjusteDetalle.Secuencia        = s;
                    infoAjusteDetalle.IdProducto       = item.IdProducto;
                    infoAjusteDetalle.CantidadAjustada = Convert.ToDouble(item.CantidadAjustada);
                    infoAjusteDetalle.StockFisico      = Convert.ToDouble(item.StockFisico);
                    infoAjusteDetalle.StockSistema     = item.pr_stock == null ? 0 : Convert.ToDouble(item.pr_stock);
                    s++;
                    ListaAjuste.Add(infoAjusteDetalle);
                }

                BusAjusDeta.GuardarDB(ListaAjuste);

                string mensaje = "";

                var TIngreso = (from q in BindingList_Producto
                                where q.CantidadAjustada > 0
                                select q).Count();

                var TEgresos = (from q in BindingList_Producto
                                where q.CantidadAjustada < 0
                                select q).Count();


                HayIngresos = (Convert.ToDouble(TIngreso) > 0) ? true : false;

                #region HayIngreso

                if (HayIngresos == true)
                {
                    in_movi_inve_Info InfoMOviIngreso = new in_movi_inve_Info();

                    #region InfoMoviIngres
                    InfoMOviIngreso.IdEmpresa         = param.IdEmpresa;
                    InfoMOviIngreso.IdSucursal        = Info_AjusteFisico.IdSucursal;
                    InfoMOviIngreso.IdBodega          = Info_AjusteFisico.IdBodega;
                    InfoMOviIngreso.IdMovi_inven_tipo = Info_AjusteFisico.IdMovi_inven_tipo_Ing;
                    InfoMOviIngreso.cm_tipo           = "+";
                    InfoMOviIngreso.cm_observacion    = Info_AjusteFisico.Observacion;
                    InfoMOviIngreso.IdUsuario         = param.IdUsuario;
                    InfoMOviIngreso.nom_pc            = param.nom_pc;
                    InfoMOviIngreso.ip           = param.ip;
                    InfoMOviIngreso.Estado       = "A";
                    InfoMOviIngreso.cm_fecha     = dtp_fecha.Value;
                    InfoMOviIngreso.CodMoviInven = "AJU";

                    #endregion

                    var SelectDetMoviIng = from q in BindingList_Producto
                                           where q.CantidadAjustada > 0
                                           select q;

                    int c = 1;
                    foreach (var item in SelectDetMoviIng)
                    {
                        in_movi_inve_detalle_Info detMovInfo = new in_movi_inve_detalle_Info();

                        detMovInfo.dm_cantidad       = Convert.ToDouble(item.CantidadAjustada);
                        detMovInfo.IdProducto        = item.IdProducto;
                        detMovInfo.Secuencia         = c;
                        detMovInfo.IdEmpresa         = param.IdEmpresa;
                        detMovInfo.IdBodega          = InfoMOviIngreso.IdBodega;
                        detMovInfo.IdSucursal        = InfoMOviIngreso.IdSucursal;
                        detMovInfo.IdMovi_inven_tipo = InfoMOviIngreso.IdMovi_inven_tipo;
                        detMovInfo.IdNumMovi         = 0;
                        detMovInfo.mv_tipo_movi      = InfoMOviIngreso.cm_tipo;
                        detMovInfo.dm_observacion    = Info_AjusteFisico.Observacion;
                        detMovInfo.mv_costo          = item.pr_costo_promedio;

                        listDetMoviIngreso.Add(detMovInfo);

                        c++;
                    }

                    InfoMOviIngreso.listmovi_inve_detalle_Info = listDetMoviIngreso;

                    Bus_MoviInven.GrabarDB(InfoMOviIngreso, ref IdNumMovi_Ing, ref mensaje_cbte_cble_ing, ref mensaje);
                }

                #endregion
                #region HayEgreso
                HayEgresos = (Convert.ToDouble(TEgresos) > 0) ? true : false;

                if (HayEgresos == true)
                {
                    #region InfoMoviEgreso
                    in_movi_inve_Info InfoMOviEgres = new in_movi_inve_Info();
                    InfoMOviEgres.IdEmpresa         = param.IdEmpresa;
                    InfoMOviEgres.IdSucursal        = Info_AjusteFisico.IdSucursal;
                    InfoMOviEgres.IdBodega          = Info_AjusteFisico.IdBodega;
                    InfoMOviEgres.IdMovi_inven_tipo = Info_AjusteFisico.IdMovi_inven_tipo_Egr;
                    InfoMOviEgres.cm_tipo           = "-";
                    InfoMOviEgres.cm_observacion    = Info_AjusteFisico.Observacion;
                    InfoMOviEgres.IdUsuario         = param.IdUsuario;
                    InfoMOviEgres.nom_pc            = param.nom_pc;
                    InfoMOviEgres.ip           = param.ip;
                    InfoMOviEgres.Estado       = "A";
                    InfoMOviEgres.cm_fecha     = dtp_fecha.Value;
                    InfoMOviEgres.CodMoviInven = "AJU";
                    #endregion

                    var SelectDetMoviEgre = from q in BindingList_Producto
                                            where q.CantidadAjustada < 0
                                            select q;

                    int c = 1;

                    foreach (var item in SelectDetMoviEgre)
                    {
                        in_movi_inve_detalle_Info detMovInfo = new in_movi_inve_detalle_Info();
                        detMovInfo.IdEmpresa         = param.IdEmpresa;
                        detMovInfo.IdBodega          = InfoMOviEgres.IdBodega;
                        detMovInfo.IdSucursal        = InfoMOviEgres.IdSucursal;
                        detMovInfo.IdMovi_inven_tipo = InfoMOviEgres.IdMovi_inven_tipo;
                        detMovInfo.IdNumMovi         = IdNumMovi_Egr;
                        detMovInfo.Secuencia         = c;
                        c++;
                        detMovInfo.mv_tipo_movi   = InfoMOviEgres.cm_tipo;
                        detMovInfo.IdProducto     = item.IdProducto;
                        detMovInfo.dm_cantidad    = Convert.ToDouble(item.CantidadAjustada);
                        detMovInfo.dm_observacion = Info_AjusteFisico.Observacion;
                        detMovInfo.mv_costo       = item.pr_costo_promedio;
                        listDetMoviEgreso.Add(detMovInfo);
                    }


                    InfoMOviEgres.listmovi_inve_detalle_Info = listDetMoviEgreso;
                    Bus_MoviInven.GrabarDB(InfoMOviEgres, ref IdNumMovi_Egr, ref mensaje_cbte_cble_egr, ref mensaje);

                    //}
                }
                #endregion

                if (Bus_AjustFisico.ModificarDB(param.IdEmpresa, Convert.ToDecimal(txtNumAjusteFisico.Text), "APRO", IdNumMovi_Egr, IdNumMovi_Ing))
                {
                    MessageBox.Show("Ajuste Fisico Aprobado Con exito.. Ajuste#:" + Convert.ToDecimal(txtNumAjusteFisico.Text) + " Ingreso Inventario#:" + IdNumMovi_Ing
                                    + " Egreso Inventario#:" + IdNumMovi_Egr + " Diarios Contables" + mensaje_cbte_cble_ing + " " + mensaje_cbte_cble_egr);
                    ucGe_Menu.Enabled_btnGuardar         = false;
                    ucGe_Menu.Enabled_bntGuardar_y_Salir = false;
                }
                else
                {
                    MessageBox.Show("Error Al Aprobar");
                }
            }
            catch (Exception ex)
            {
                Log_Error_bus.Log_Error(ex.ToString());
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void toolStripButton2_Click_1(object sender, EventArgs e)
        {
            try
            {
                Get_info();

                BusAjusDeta.Eliminar(param.IdEmpresa, Convert.ToDecimal(txtNumAjusteFisico.Text));
                int s = 1;
                ListaAjuste = new List <Info.Inventario.in_AjusteFisico_Detalle_Info>();
                foreach (var item in ListaPorductos)
                {
                    in_AjusteFisico_Detalle_Info infoAjusteDetalle = new in_AjusteFisico_Detalle_Info();
                    infoAjusteDetalle.IdAjusteFisico   = Convert.ToDecimal(txtNumAjusteFisico.Text);
                    infoAjusteDetalle.IdEmpresa        = param.IdEmpresa;
                    infoAjusteDetalle.Secuencia        = s;
                    infoAjusteDetalle.IdProducto       = item.IdProducto;
                    infoAjusteDetalle.CantidadAjustada = Convert.ToDouble(item.CantidadAjustada);
                    infoAjusteDetalle.StockFisico      = Convert.ToDouble(item.StockFisico);
                    infoAjusteDetalle.StockSistema     = item.pr_stock;
                    s++;
                    ListaAjuste.Add(infoAjusteDetalle);
                }
                // ListaAjuste.ForEach(v=>v.IdAjusteFisico = );

                BusAjusDeta.GuardarBase(ListaAjuste);
                //string MenMovi ="";
                //in_movi_inve_Info movi_I = new in_movi_inve_Info();
                //movi_I.IdEmpresa = param.IdEmpresa;
                //movi_I.IdSucursal = _Info.IdSucursal;
                //movi_I.IdBodega = _Info.IdBodega;

                //BusMoviInven.AnularCabeceraYDetalleyActualizaStock(movi_I, ref MenMovi);

                string mensaje = "";

                var TIngreso = (from q in ListaPorductos
                                where q.CantidadAjustada > 0
                                select q).Count();

                var TEgresos = (from q in ListaPorductos
                                where q.CantidadAjustada < 0
                                select q).Count();


                HayIngresos = (Convert.ToDouble(TIngreso) > 0) ? true : false;

                #region HayIngreso

                if (HayIngresos == true)
                {
                    in_movi_inve_Info InfoMOviIngreso = new in_movi_inve_Info();

                    #region InfoMoviIngres
                    InfoMOviIngreso.IdEmpresa         = param.IdEmpresa;
                    InfoMOviIngreso.IdSucursal        = _Info.IdSucursal;
                    InfoMOviIngreso.IdBodega          = _Info.IdBodega;
                    InfoMOviIngreso.IdMovi_inven_tipo = _Info.IdMovi_inven_tipo_Ing;
                    InfoMOviIngreso.cm_tipo           = "+";
                    InfoMOviIngreso.cm_observacion    = _Info.Observacion;
                    InfoMOviIngreso.IdUsuario         = param.IdUsuario;
                    InfoMOviIngreso.nom_pc            = param.nom_pc;
                    InfoMOviIngreso.ip           = param.ip;
                    InfoMOviIngreso.Estado       = "A";
                    InfoMOviIngreso.cm_fecha     = dtp_fecha.Value;
                    InfoMOviIngreso.CodMoviInven = "AJU";

                    #endregion
                    if (BusMoviInven.GrabarDB(InfoMOviIngreso, ref IdNumMovi_Ing, ref mensaje))
                    {
                        var SelectDetMoviIng = from q in ListaPorductos
                                               where q.CantidadAjustada > 0
                                               select q;

                        int c = 1;
                        foreach (var item in SelectDetMoviIng)
                        {
                            in_movi_inve_detalle_Info detMovInfo = new in_movi_inve_detalle_Info();



                            detMovInfo.dm_stock_ante     = item.pr_stock;
                            detMovInfo.dm_stock_actu     = Convert.ToDouble(item.StockFisico);
                            detMovInfo.dm_cantidad       = Convert.ToDouble(item.CantidadAjustada);
                            detMovInfo.IdProducto        = item.IdProducto;
                            detMovInfo.Secuencia         = c;
                            detMovInfo.IdEmpresa         = param.IdEmpresa;
                            detMovInfo.IdBodega          = InfoMOviIngreso.IdBodega;
                            detMovInfo.IdSucursal        = InfoMOviIngreso.IdSucursal;
                            detMovInfo.IdMovi_inven_tipo = InfoMOviIngreso.IdMovi_inven_tipo;
                            detMovInfo.IdNumMovi         = IdNumMovi_Ing;
                            detMovInfo.mv_tipo_movi      = InfoMOviIngreso.cm_tipo;
                            detMovInfo.dm_observacion    = _Info.Observacion;
                            detMovInfo.dm_precio         = item.pr_precio_publico;
                            detMovInfo.mv_costo          = item.pr_costo_promedio;


                            listDetMoviIngreso.Add(detMovInfo);



                            c++;
                        }
                        //guarda los ingresos
                        BusDetMOvi.GrabarDB(listDetMoviIngreso, ref mensaje);

                        // actualizo el stokc x bodega


                        PrxBoBUS.ActualizarStock_x_Bodega_con_moviInven(listDetMoviIngreso, ref mensaje);
                    }
                }

                #endregion
                #region HayEgreso
                HayEgresos = (Convert.ToDouble(TEgresos) > 0) ? true : false;

                if (HayEgresos == true)
                {
                    #region InfoMoviEgreso
                    in_movi_inve_Info InfoMOviEgres = new in_movi_inve_Info();
                    InfoMOviEgres.IdEmpresa         = param.IdEmpresa;
                    InfoMOviEgres.IdSucursal        = _Info.IdSucursal;
                    InfoMOviEgres.IdBodega          = _Info.IdBodega;
                    InfoMOviEgres.IdMovi_inven_tipo = _Info.IdMovi_inven_tipo_Egr;
                    InfoMOviEgres.cm_tipo           = "-";
                    InfoMOviEgres.cm_observacion    = _Info.Observacion;
                    InfoMOviEgres.IdUsuario         = param.IdUsuario;
                    InfoMOviEgres.nom_pc            = param.nom_pc;
                    InfoMOviEgres.ip           = param.ip;
                    InfoMOviEgres.Estado       = "A";
                    InfoMOviEgres.cm_fecha     = dtp_fecha.Value;
                    InfoMOviEgres.CodMoviInven = "AJU";
                    #endregion
                    if (BusMoviInven.GrabarDB(InfoMOviEgres, ref IdNumMovi_Egr, ref mensaje))
                    {
                        var SelectDetMoviEgre = from q in ListaPorductos
                                                where q.CantidadAjustada < 0
                                                select q;



                        int c = 1;

                        foreach (var item in SelectDetMoviEgre)
                        {
                            in_movi_inve_detalle_Info detMovInfo = new in_movi_inve_detalle_Info();
                            detMovInfo.IdEmpresa         = param.IdEmpresa;
                            detMovInfo.IdBodega          = InfoMOviEgres.IdBodega;
                            detMovInfo.IdSucursal        = InfoMOviEgres.IdSucursal;
                            detMovInfo.IdMovi_inven_tipo = InfoMOviEgres.IdMovi_inven_tipo;
                            detMovInfo.IdNumMovi         = IdNumMovi_Egr;
                            detMovInfo.Secuencia         = c;
                            c++;
                            detMovInfo.mv_tipo_movi   = InfoMOviEgres.cm_tipo;
                            detMovInfo.IdProducto     = item.IdProducto;
                            detMovInfo.dm_cantidad    = Convert.ToDouble(item.CantidadAjustada);
                            detMovInfo.dm_stock_actu  = Convert.ToDouble(item.StockFisico);
                            detMovInfo.dm_stock_ante  = item.pr_stock;
                            detMovInfo.dm_observacion = _Info.Observacion;
                            detMovInfo.dm_precio      = item.pr_precio_publico;
                            detMovInfo.mv_costo       = item.pr_costo_promedio;

                            listDetMoviEgreso.Add(detMovInfo);
                        }

                        BusDetMOvi.GrabarDB(listDetMoviEgreso, ref mensaje);
                        PrxBoBUS.ActualizarStock_x_Bodega_con_moviInven(listDetMoviEgreso, ref mensaje);
                    }
                }
                #endregion

                if (BusAjusteFisico.Modificar(param.IdEmpresa, Convert.ToDecimal(txtNumAjusteFisico.Text), "APRO", IdNumMovi_Egr, IdNumMovi_Ing))
                {
                    MessageBox.Show("Aprobado Con exito..");
                }
                else
                {
                    MessageBox.Show("Error Al Aprobar");
                }
            }
            catch (Exception ex)
            {
                Log_Error_bus.Log_Error(ex.ToString());
            }
        }
        private void guardar()
        {
            try
            {
                //    Get_info();



                string mensaje = "";
                if (cmbEstadoAprob.SelectedValue.ToString() == "APRO")
                {
                    var TIngreso = (from q in ListaPorductos
                                    where q.CantidadAjustada > 0
                                    select q).Count();

                    var TEgresos = (from q in ListaPorductos
                                    where q.CantidadAjustada < 0
                                    select q).Count();


                    HayIngresos = (Convert.ToDouble(TIngreso) > 0) ? true : false;

                    #region HayIngreso

                    if (HayIngresos == true)
                    {
                        in_movi_inve_Info InfoMOviIngreso = new in_movi_inve_Info();

                        #region InfoMoviIngres
                        InfoMOviIngreso.IdEmpresa         = param.IdEmpresa;
                        InfoMOviIngreso.IdSucursal        = _Info.IdSucursal;
                        InfoMOviIngreso.IdBodega          = _Info.IdBodega;
                        InfoMOviIngreso.IdMovi_inven_tipo = _Info.IdMovi_inven_tipo_Ing;
                        InfoMOviIngreso.cm_tipo           = "+";
                        InfoMOviIngreso.cm_observacion    = _Info.Observacion;
                        InfoMOviIngreso.IdUsuario         = param.IdUsuario;
                        InfoMOviIngreso.nom_pc            = param.nom_pc;
                        InfoMOviIngreso.ip           = param.ip;
                        InfoMOviIngreso.Estado       = "A";
                        InfoMOviIngreso.cm_fecha     = dtp_fecha.Value;
                        InfoMOviIngreso.CodMoviInven = "AJU";

                        #endregion



                        /// opteniendo el detalle del movimiento de invetario
                        var SelectDetMoviIng = from q in ListaPorductos
                                               where q.CantidadAjustada > 0
                                               select q;

                        int c = 1;
                        foreach (var item in SelectDetMoviIng)
                        {
                            in_movi_inve_detalle_Info detMovInfo = new in_movi_inve_detalle_Info();


                            detMovInfo.peso              = item.pr_peso;
                            detMovInfo.dm_stock_ante     = item.pr_stock;
                            detMovInfo.dm_stock_actu     = Convert.ToDouble(item.StockFisico);
                            detMovInfo.dm_cantidad       = Convert.ToDouble(item.CantidadAjustada);
                            detMovInfo.IdProducto        = item.IdProducto;
                            detMovInfo.Secuencia         = c;
                            detMovInfo.IdEmpresa         = param.IdEmpresa;
                            detMovInfo.IdBodega          = InfoMOviIngreso.IdBodega;
                            detMovInfo.IdSucursal        = InfoMOviIngreso.IdSucursal;
                            detMovInfo.IdMovi_inven_tipo = InfoMOviIngreso.IdMovi_inven_tipo;
                            detMovInfo.IdNumMovi         = IdNumMovi_Ing;
                            detMovInfo.mv_tipo_movi      = InfoMOviIngreso.cm_tipo;
                            detMovInfo.dm_observacion    = _Info.Observacion;
                            detMovInfo.dm_precio         = item.pr_precio_publico;
                            detMovInfo.mv_costo          = item.pr_costo_promedio;
                            listDetMoviIngreso.Add(detMovInfo);
                            c++;
                        }


                        InfoMOviIngreso.listmovi_inve_detalle_Info = listDetMoviIngreso;
                        BusMoviInven.GrabarDB(InfoMOviIngreso, ref IdNumMovi_Ing, ref mensaje);
                    }

                    #endregion
                    #region HayEgreso
                    HayEgresos = (Convert.ToDouble(TEgresos) > 0) ? true : false;

                    if (HayEgresos == true)
                    {
                        #region InfoMoviEgreso
                        in_movi_inve_Info InfoMOviEgres = new in_movi_inve_Info();
                        InfoMOviEgres.IdEmpresa         = param.IdEmpresa;
                        InfoMOviEgres.IdSucursal        = _Info.IdSucursal;
                        InfoMOviEgres.IdBodega          = _Info.IdBodega;
                        InfoMOviEgres.IdMovi_inven_tipo = _Info.IdMovi_inven_tipo_Egr;
                        InfoMOviEgres.cm_tipo           = "-";
                        InfoMOviEgres.cm_observacion    = _Info.Observacion;
                        InfoMOviEgres.IdUsuario         = param.IdUsuario;
                        InfoMOviEgres.nom_pc            = param.nom_pc;
                        InfoMOviEgres.ip           = param.ip;
                        InfoMOviEgres.Estado       = "A";
                        InfoMOviEgres.cm_fecha     = dtp_fecha.Value;
                        InfoMOviEgres.CodMoviInven = "AJU";
                        #endregion


                        /// encontrando el detalle de inventario
                        ///
                        var SelectDetMoviEgre = from q in ListaPorductos
                                                where q.CantidadAjustada < 0
                                                select q;



                        int c = 1;

                        foreach (var item in SelectDetMoviEgre)
                        {
                            in_movi_inve_detalle_Info detMovInfo = new in_movi_inve_detalle_Info();
                            detMovInfo.IdEmpresa         = param.IdEmpresa;
                            detMovInfo.IdBodega          = InfoMOviEgres.IdBodega;
                            detMovInfo.IdSucursal        = InfoMOviEgres.IdSucursal;
                            detMovInfo.IdMovi_inven_tipo = InfoMOviEgres.IdMovi_inven_tipo;
                            detMovInfo.IdNumMovi         = IdNumMovi_Egr;
                            detMovInfo.peso      = item.pr_peso;
                            detMovInfo.Secuencia = c;
                            c++;
                            detMovInfo.mv_tipo_movi   = InfoMOviEgres.cm_tipo;
                            detMovInfo.IdProducto     = item.IdProducto;
                            detMovInfo.dm_cantidad    = Convert.ToDouble(item.CantidadAjustada) * -1;
                            detMovInfo.dm_stock_actu  = Convert.ToDouble(item.StockFisico);
                            detMovInfo.dm_stock_ante  = item.pr_stock;
                            detMovInfo.dm_observacion = _Info.Observacion;
                            detMovInfo.dm_precio      = item.pr_precio_publico;
                            detMovInfo.mv_costo       = item.pr_costo_promedio;

                            listDetMoviEgreso.Add(detMovInfo);
                        }

                        InfoMOviEgres.listmovi_inve_detalle_Info = listDetMoviEgreso;
                        BusMoviInven.GrabarDB(InfoMOviEgres, ref IdNumMovi_Egr, ref mensaje);
                    }
                    #endregion
                }



                if (BusAjusteFisico.GuardarAjusteFisico(_Info, ref IdAjusteFisico, ref IdNumMovi_Egr, ref IdNumMovi_Ing))
                {
                    txtNumAjusteFisico.Text    = IdAjusteFisico.ToString();
                    _Info.IdAjusteFisico       = IdAjusteFisico;
                    txtMoviAjustIngreso.Text   = IdNumMovi_Ing.ToString();
                    txtNumMoviAjustEgreso.Text = IdNumMovi_Egr.ToString();
                    int c = 1;


                    foreach (var item in ListaPorductos)
                    {
                        in_AjusteFisico_Detalle_Info infoAjusteDetalle = new in_AjusteFisico_Detalle_Info();
                        infoAjusteDetalle.IdAjusteFisico   = IdAjusteFisico;
                        infoAjusteDetalle.IdEmpresa        = param.IdEmpresa;
                        infoAjusteDetalle.Secuencia        = c;
                        infoAjusteDetalle.IdProducto       = item.IdProducto;
                        infoAjusteDetalle.CantidadAjustada = Convert.ToDouble(item.CantidadAjustada);
                        infoAjusteDetalle.StockFisico      = Convert.ToDouble(item.StockFisico);
                        infoAjusteDetalle.StockSistema     = item.pr_stock;
                        c++;
                        ListaAjuste.Add(infoAjusteDetalle);
                    }


                    BusAjusDeta.GuardarBase(ListaAjuste);


                    MessageBox.Show("Guardado OK");
                    btn_ok.Enabled          = false;
                    btnGrabarySalir.Enabled = false;
                }

                //in_producto_x_tb_bodega_Bus _BusProdXBode = new in_producto_x_tb_bodega_Bus();

                //string Mensaje = "";



                ListaPorductos = new List <Info.Inventario.in_Producto_Info>();;
            }
            catch (Exception ex)
            {
                Log_Error_bus.Log_Error(ex.ToString());
            }
        }