예제 #1
0
        private void btnDerechaç_Click(object sender, EventArgs e)
        {
            try
            {
                in_Producto_Info Item = (in_Producto_Info)gridViewProducto_no_asigandos.GetFocusedRow();

                if (Item != null)
                {
                    if (Productos_Asignados_x_Bodega.Count(v => v.IdProducto == Item.IdProducto) == 0)
                    {
                        Productos_Asignados_x_Bodega.Add(Item);
                        in_producto_x_tb_bodega_Info obj = new in_producto_x_tb_bodega_Info();


                        CambioproductoAproductoXBodega(Item, ref obj);

                        Bus_Prod_X_Bod.GrabaDB(obj, param.IdEmpresa, ref Mensaje);

                        Productos_no_asignados.Remove(Item);
                        gridControlProducto.RefreshDataSource();
                        gridControlProdXBodega.RefreshDataSource();
                    }
                }
            }
            catch (Exception ex)
            {
                Log_Error_bus.Log_Error(ex.ToString());
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private Boolean Proceso_Grabacion()
        {
            Boolean respuesta    = false;
            int     c            = 1;
            int     Total_Reg    = 0;
            string  SIdProducto  = "";
            string  nom_producto = "";

            BindingList <cl_estado_grabacion> ListEstadoGrabacion = new BindingList <cl_estado_grabacion>();

            try
            {
                string MensajeLog     = "Ingreso Exitoso.";
                string MensajeWarning = "";
                string listaLog       = "";
                this.rtbLog.Text = "";
                bool B_Proceso_anulacion = true;
                lblMensaje.Text    = "";
                lblMensaje.Visible = false;
                decimal IdProducto = 0;
                int     IdLinea    = 0;
                int     IdGrupo    = 0;
                int     IdSubGrupo = 0;
                int     idMotivo   = 0;

                gridControlProceGrabado.DataSource = ListEstadoGrabacion;

                if (gridControlProductos.DataSource != null)
                {
                    if (rgImportar.SelectedIndex == 0)
                    {
                        MensajeWarning = "Atención esta a punto de eliminar toda la información actual, y reemplazarla con la nueva. Está seguro de continuar?";
                    }
                    else
                    {
                        MensajeWarning = "Atención esta a punto de proceder. Está seguro de continuar?";
                    }
                    lblmsg3.Visible = true;

                    if (MessageBox.Show(MensajeWarning, "SISTEMAS", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                    {
                        if (rgImportar.SelectedIndex == 0)
                        {
                            //splashScreenManager.ShowWaitForm();
                            B_Proceso_anulacion = _Bus_producto_x_bodega.Delete_Todos_Producto_x_bodega(param.IdEmpresa, ref MensajeError);

                            B_Proceso_anulacion = _ProductoBus.Delete_Todos_Producto(param.IdEmpresa, ref MensajeError);

                            if (B_Proceso_anulacion)
                            {
                                ListEstadoGrabacion.Add(new cl_estado_grabacion(0, "", "Eliminado productos", "", "OK", "Eliminado Ok"));
                                gridControlProceGrabado.Refresh();
                            }
                            //splashScreenManager.CloseWaitForm();
                        }

                        if (B_Proceso_anulacion == true)
                        {
                            //splashScreenManager.ShowWaitForm();

                            Total_Reg            = _ListProductoInfo.Count();
                            progressBar.Maximum  = Total_Reg;
                            progressBar.Minimum  = 1;
                            progressBar.Step     = 1;
                            lblNumRegistros.Text = "0 registros de " + Total_Reg;
                            c = 1;

                            #region Listas
                            foreach (var item in list_Categoria)
                            {
                                respuesta = Categoria_Bus.GrabarDB(param.IdEmpresa, item, ref MensajeError);
                            }
                            if (!respuesta)
                            {
                                MessageBox.Show("La Hoja de Categoria no cumple con el formato de la plantilla", "Sistemas", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return(false);
                            }

                            foreach (var item in list_Linea)
                            {
                                respuesta = Linea_bus.GrabarDB(item, ref IdLinea, ref MensajeError);
                            }
                            if (!respuesta)
                            {
                                MessageBox.Show("La Hoja de Línea no cumple con el formato de la plantilla", "Sistemas", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return(false);
                            }

                            foreach (var item in list_Grupo)
                            {
                                respuesta = Grupo_bus.GrabarDB(item, ref IdGrupo, ref MensajeError);
                            }
                            if (!respuesta)
                            {
                                MessageBox.Show("La Hoja de Grupo no cumple con el formato de la plantilla", "Sistemas", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return(false);
                            }

                            foreach (var item in list_SubGrupo)
                            {
                                respuesta = SubGrupo_bus.GrabarDB(item, ref IdSubGrupo, ref MensajeError);
                            }
                            if (!respuesta)
                            {
                                MessageBox.Show("La Hoja de SubGrupo no cumple con el formato de la plantilla", "Sistemas", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return(false);
                            }

                            foreach (var item in list_Marca)
                            {
                                respuesta = Marca_bus.GrabarDB(item, ref MensajeError);
                            }
                            if (!respuesta)
                            {
                                MessageBox.Show("La Hoja de Marca no cumple con el formato de la plantilla", "Sistemas", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return(false);
                            }

                            _Motivo_venta_Info                        = new fa_motivo_venta_Info();
                            _Motivo_venta_Info.IdEmpresa              = param.IdEmpresa;
                            _Motivo_venta_Info.IdMotivo_Vta           = 1;
                            _Motivo_venta_Info.codMotivo_Vta          = "1";
                            _Motivo_venta_Info.descripcion_motivo_vta = "no definido";
                            _Motivo_venta_Info.Estado                 = "A";
                            _Motivo_venta_Info.FechaCreacion          = param.Fecha_Transac;
                            _Motivo_venta_Info.UsuarioCreacion        = param.IdUsuario;

                            respuesta = Motivo_venta_bus.Grabar(_Motivo_venta_Info, ref idMotivo, ref MensajeError);

                            if (!respuesta)
                            {
                                MessageBox.Show("La Hoja de Motivo de venta no cumple con el formato de la plantilla", "Sistemas", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return(false);
                            }

                            foreach (var item in list_Presentacion)
                            {
                                respuesta = Presentacion_bus.GuardarDB(item, ref MensajeError);
                            }
                            if (!respuesta)
                            {
                                MessageBox.Show("La Hoja de Presentación no cumple con el formato de la plantilla", "Sistemas", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return(false);
                            }

                            foreach (in_Producto_Info item in _ListProductoInfo)
                            {
                                SIdProducto                 = item.IdProducto.ToString();
                                nom_producto                = item.pr_descripcion;
                                item.IdProducto             = 0;//en caso de que sea conservar
                                item.IdCategoria            = "1";
                                item.IdLinea                = 1;
                                item.IdGrupo                = 1;
                                item.IdSubGrupo             = 1;
                                item.IdMarca                = 1;
                                item.IdProductoTipo         = 2;
                                item.IdPresentacion         = "1";
                                item.IdUnidadMedida         = "UNID";
                                item.IdUnidadMedida_Consumo = "UNID";
                                item.IdCod_Impuesto_Iva     = "IVA12";;
                                item.IdMotivo_Vta           = 1;
                                item.Estado                 = "A";

                                respuesta = _ProductoBus.GrabarDB(item, ref IdProducto, ref MensajeError);
                                if (respuesta)
                                {
                                    #region Producto por bodega
                                    foreach (var Sucursal in lst_Sucursal)
                                    {
                                        foreach (var Bodega in lst_Bodega)
                                        {
                                            if (Bodega.IdSucursal == Sucursal.IdSucursal)
                                            {
                                                info_producto_x_bodega                   = new in_producto_x_tb_bodega_Info();
                                                info_producto_x_bodega.IdEmpresa         = item.IdEmpresa;
                                                info_producto_x_bodega.IdSucursal        = Sucursal.IdSucursal;
                                                info_producto_x_bodega.IdBodega          = Bodega.IdBodega;
                                                info_producto_x_bodega.IdProducto        = item.IdProducto;
                                                info_producto_x_bodega.pr_precio_publico = item.pr_precio_publico;
                                                info_producto_x_bodega.pr_precio_minimo  = item.pr_precio_minimo;
                                                //info_producto_x_bodega.pr_stock = item.pr_stock;
                                                info_producto_x_bodega.pr_stock_minimo   = item.pr_stock_minimo;
                                                info_producto_x_bodega.pr_costo_promedio = item.pr_costo_promedio;
                                                //Cuentas contables
                                                info_producto_x_bodega.IdCtaCble_Inven       = cmb_IdCtaCble_Inven.get_PlanCtaInfo().IdCtaCble;       //1
                                                info_producto_x_bodega.IdCtaCble_VenIva      = cmb_IdCtaCble_VenIva.get_PlanCtaInfo().IdCtaCble;      //2
                                                info_producto_x_bodega.IdCtaCble_Ven0        = cmb_IdCtaCble_Ven0.get_PlanCtaInfo().IdCtaCble;        //3
                                                info_producto_x_bodega.IdCtaCble_DevIva      = cmb_IdCtaCble_DesIva.get_PlanCtaInfo().IdCtaCble;      //4
                                                info_producto_x_bodega.IdCtaCble_Des0        = cmb_IdCtaCble_Des0.get_PlanCtaInfo().IdCtaCble;        //5
                                                info_producto_x_bodega.IdCtaCble_DevIva      = cmb_IdCtaCble_DevIva.get_PlanCtaInfo().IdCtaCble;      //6
                                                info_producto_x_bodega.IdCtaCble_Dev0        = cmb_IdCtaCble_Dev0.get_PlanCtaInfo().IdCtaCble;        //7
                                                info_producto_x_bodega.IdCtaCble_Costo       = cmb_IdCtaCble_Costo.get_PlanCtaInfo().IdCtaCble;       //8
                                                info_producto_x_bodega.IdCtaCble_Gasto_x_cxp = cmb_IdCtaCble_Gasto_x_cxp.get_PlanCtaInfo().IdCtaCble; //9
                                                info_producto_x_bodega.IdCtaCble_Vta         = cmb_IdCtaCble_Vta.get_PlanCtaInfo().IdCtaCble;         //10
                                                //Fin cuentas contables
                                                info_producto_x_bodega.Estado = "A";
                                                respuesta = bus_producto_x_bodega.GrabaDB(info_producto_x_bodega, param.IdEmpresa, ref MensajeError);
                                            }
                                        }
                                    }
                                    #endregion

                                    ListEstadoGrabacion.Add(new cl_estado_grabacion(c, item.IdProducto.ToString(), item.pr_codigo, item.pr_descripcion, "OK", "Migrado Ok"));
                                    progressBar.Value    = c;
                                    lblNumRegistros.Text = c + " registros de " + Total_Reg;
                                    progressBar.Refresh();
                                    Application.DoEvents();
                                }
                                c++;
                            }
                            #endregion

                            if (listaLog != "")
                            {
                                MensajeLog += " pero con errores:" + "\n" + listaLog + MensajeError;
                            }
                        }
                    }
                    else
                    {
                        MensajeLog = "No se efectuó la operación. Operación cancelada por el usuario.";
                    }
                    lblmsg3.Visible = false;
                }
                else
                {
                    MensajeLog = "No existen Datos para importación.";
                }
                this.rtbLog.Text = MensajeLog;
                //splashScreenManager.CloseWaitForm();
                return(respuesta);
            }
            catch (Exception ex)
            {
                //splashScreenManager.CloseWaitForm();
                ListEstadoGrabacion.Add(new cl_estado_grabacion(c++, SIdProducto, SIdProducto, nom_producto, "ERROR", "No Migrado:" + ex.ToString()));
                gridControlProceGrabado.Refresh();
                lblMensaje.Text    = "Error al cargar " + ex.ToString();
                lblMensaje.Visible = true;
                return(respuesta);
            }
        }