public Boolean Modificar_Num_Retencion(cp_retencion_Info Info_Retencion, ref string mensajeError)
        {
            try
            {
                Boolean res = false;


                tb_sis_Documento_Tipo_Talonario_Bus  busTalonario  = new tb_sis_Documento_Tipo_Talonario_Bus();
                tb_sis_Documento_Tipo_Talonario_Info infoTalonario = new tb_sis_Documento_Tipo_Talonario_Info();
                tb_Sucursal_Bus Bus_Sucu   = new tb_Sucursal_Bus();
                tb_Bodega_Bus   Bus_bodega = new tb_Bodega_Bus();

                string mensajeDocumentoDupli = "";
                string cod_estable           = "";
                string cod_pto_emision       = "";

                Info_Retencion.CodDocumentoTipo = string.IsNullOrEmpty(Info_Retencion.CodDocumentoTipo) ? "RETEN" : Info_Retencion.CodDocumentoTipo;


                // el objeto viene sin serie o sin # factura tomo el ultimo num de factura del talonario
                if (Info_Retencion.serie1 == "" || Info_Retencion.serie1 == null || Info_Retencion.serie2 == "" || Info_Retencion.serie2 == null ||
                    Info_Retencion.NumRetencion == "" || Info_Retencion.NumRetencion == null)
                {
                    cod_estable     = Bus_Sucu.Get_Cod_Establecimiento_x_Sucursal(Info_Retencion.IdEmpresa, param.IdSucursal);
                    cod_pto_emision = Bus_bodega.Get_cod_pto_emision_x_Bodega(Info_Retencion.IdEmpresa, param.IdSucursal, 1);

                    infoTalonario = busTalonario.Get_Info_Primer_Documento_no_usado(Info_Retencion.IdEmpresa, cod_estable, cod_pto_emision, Info_Retencion.CodDocumentoTipo
                                                                                    , Info_Retencion.EsDocumentoElectronico);


                    if (infoTalonario.NumDocumento == null)
                    {
                        mensajeError = "No hay talonarios para Establecimiento=" + cod_estable + " y punto de emision=" + cod_pto_emision;
                        throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "no hay talonario activos", mensajeError))
                              {
                                  EntityType = typeof(cp_retencion_Bus)
                              };
                    }

                    Info_Retencion.serie1       = infoTalonario.Establecimiento;
                    Info_Retencion.serie2       = infoTalonario.PuntoEmision;
                    Info_Retencion.NumRetencion = infoTalonario.NumDocumento;
                }
                else
                {
                    // se puede dar si mas de un usario estan haciendo la factura y tienen en memoria o en la pantalla el mismo talonario
                    //verifico el numero de factura si esta usado
                    infoTalonario.Establecimiento          = Info_Retencion.serie1;
                    infoTalonario.PuntoEmision             = Info_Retencion.serie2;
                    infoTalonario.NumDocumento             = Info_Retencion.NumRetencion;
                    infoTalonario.IdEmpresa                = Info_Retencion.IdEmpresa;
                    infoTalonario.CodDocumentoTipo         = Info_Retencion.CodDocumentoTipo;
                    infoTalonario.es_Documento_electronico = Info_Retencion.EsDocumentoElectronico;


                    if (busTalonario.Documento_talonario_esta_Usado(infoTalonario, ref mensajeError, ref mensajeDocumentoDupli))
                    {
                        //si esta en usado busco el siguiente
                        cod_estable     = Bus_Sucu.Get_Cod_Establecimiento_x_Sucursal(Info_Retencion.IdEmpresa, param.IdSucursal);
                        cod_pto_emision = Bus_bodega.Get_cod_pto_emision_x_Bodega(Info_Retencion.IdEmpresa, param.IdSucursal, 1);

                        infoTalonario = busTalonario.Get_Info_Primer_Documento_no_usado(Info_Retencion.IdEmpresa, cod_estable,
                                                                                        cod_pto_emision, Info_Retencion.CodDocumentoTipo, Info_Retencion.EsDocumentoElectronico);

                        if (infoTalonario.NumDocumento == null)
                        {
                            throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "no hay talonario activos", mensajeError))
                                  {
                                      EntityType = typeof(cp_retencion_Bus)
                                  };
                        }

                        Info_Retencion.serie1       = infoTalonario.Establecimiento;
                        Info_Retencion.serie2       = infoTalonario.PuntoEmision;
                        Info_Retencion.NumRetencion = infoTalonario.NumDocumento;

                        if (!infoTalonario.es_Documento_electronico)
                        {
                            //si no es documento electronico le actualizo el numero de autorizacion y la fecha de autorizacion
                            Info_Retencion.NAutorizacion      = infoTalonario.NumAutorizacion;
                            Info_Retencion.Fecha_Autorizacion = DateTime.Now.Date;
                        }
                    }
                    else
                    {
                        if (!infoTalonario.es_Documento_electronico)
                        {
                            //Si no esta siendo usado, si no es documento electronico le actualizo el numero de autorizacion y la fecha de autorizacion
                            infoTalonario = busTalonario.Get_Info_Documento_Tipo_Talonario(Info_Retencion.IdEmpresa, Info_Retencion.CodDocumentoTipo, cod_estable, cod_pto_emision, Info_Retencion.NumRetencion);


                            Info_Retencion.NAutorizacion      = infoTalonario.NumAutorizacion;
                            Info_Retencion.Fecha_Autorizacion = DateTime.Now.Date;
                        }
                    }
                }

                res = data_retencion.Modificar_Num_Retencion(Info_Retencion, ref mensajeError);
                busTalonario.Modificar_Estado_Usado(infoTalonario, ref mensajeError);

                return(res);
            }
            catch (Exception ex)
            {
                Core.Erp.Info.Log_Exception.LoggingManager.Logger.Log(Core.Erp.Info.Log_Exception.LoggingCategory.Error, ex.Message);
                throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "ModificarNRetencion", ex.Message), ex)
                      {
                          EntityType = typeof(cp_retencion_Bus)
                      };
            }
        }
        Boolean Validar_y_corregir_objeto(ref in_Guia_x_traspaso_bodega_Info Info_Guia, ref string msg)
        {
            try
            {
                #region 'Validaciones'
                /*--- validaciones */



                if (Info_Guia.IdEmpresa == 0)
                {
                    msg = "La variable estan en cero... IdEmpresa == 0  ";
                    return(false);
                }



                foreach (var item in Info_Guia.list_detalle_Guia)
                {
                    if (item.Cantidad_enviar == 0 || item.Cantidad_enviar == null)
                    {
                        msg = "Ingrese la cantidad de traspaso para el item : " + item.pr_descripcion + "  ";
                        return(false);
                    }
                }



                foreach (var item in Info_Guia.list_detalle_Guia_Sin_OC)
                {
                    if (item.Cantidad_enviar == 0 || item.Cantidad_enviar == null)
                    {
                        msg = "Ingrese la cantidad de traspaso para el item : " + item.nom_producto + "  ";
                        return(false);
                    }
                }


                if (Info_Guia.IdEmpresa <= 0 && Info_Guia.IdSucursal_Partida <= 0 && Info_Guia.IdSucursal_Llegada <= 0)
                {
                    msg = "Error en la cabecera de fact uno de los PK es <=0";
                    throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "Validaciones", msg))
                          {
                              EntityType = typeof(in_Guia_x_traspaso_bodega_Bus)
                          };
                }


                if (Info_Guia.IdTransportista <= 0)
                {
                    msg = "Erro en la cabecera de guia IdTransportista es <=0";
                    throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "Validaciones", msg))
                          {
                              EntityType = typeof(in_Guia_x_traspaso_bodega_Bus)
                          };
                }


                if (Info_Guia.IdMotivo_Traslado == "")
                {
                    msg = "Erro en la cabecera de IdMotivo_Traslado esta en blanco";
                    throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "Validaciones", msg))
                          {
                              EntityType = typeof(in_Guia_x_traspaso_bodega_Bus)
                          };
                }


                if (Info_Guia.list_detalle_Guia.Count == 0 && Info_Guia.list_detalle_Guia_Sin_OC.Count == 0)
                {
                    msg = "la guia  no tiene detalle ";
                    throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "Validaciones", msg))
                          {
                              EntityType = typeof(in_Guia_x_traspaso_bodega_Bus)
                          };
                }



                /*--- Fin validaciones */


                /*--- corrigiendo data */

                Info_Guia.Estado = (string.IsNullOrEmpty(Info_Guia.Estado) == true) ? "A" : Info_Guia.Estado;
                Info_Guia.Fecha  = Convert.ToDateTime(Info_Guia.Fecha).Date;



                tb_sis_Documento_Tipo_Talonario_Bus  busTalonario  = new tb_sis_Documento_Tipo_Talonario_Bus();
                tb_sis_Documento_Tipo_Talonario_Info infoTalonario = new tb_sis_Documento_Tipo_Talonario_Info();
                tb_Sucursal_Bus Bus_Sucu   = new tb_Sucursal_Bus();
                tb_Bodega_Bus   Bus_bodega = new tb_Bodega_Bus();

                string mensajeDocumentoDupli = "";
                string cod_estable           = "";
                string cod_pto_emision       = "";

                Info_Guia.CodDocumentoTipo = Cl_Enumeradores.eTipoDocumento_Talonario.GUIA.ToString();


                // el objeto viene sin serie o sin # factura tomo el ultimo num de factura del talonario
                if (Info_Guia.IdEstablecimiento == "" || Info_Guia.IdEstablecimiento == null || Info_Guia.IdPuntoEmision == "" || Info_Guia.IdPuntoEmision == null ||
                    Info_Guia.NumDocumento_Guia == "" || Info_Guia.NumDocumento_Guia == null)
                {
                    cod_estable     = Bus_Sucu.Get_Cod_Establecimiento_x_Sucursal(Info_Guia.IdEmpresa, Convert.ToInt32(Info_Guia.IdSucursal_Partida));
                    cod_pto_emision = Bus_bodega.Get_cod_pto_emision_x_Bodega(Info_Guia.IdEmpresa, Convert.ToInt32(Info_Guia.IdSucursal_Partida), 1); // la tabla no tiene bodega
                    infoTalonario   = busTalonario.Get_Info_Primer_Documento_no_usado(Info_Guia.IdEmpresa, cod_pto_emision, cod_estable, Info_Guia.CodDocumentoTipo, Info_Guia.Es_electronica);

                    if (infoTalonario.NumDocumento == null)
                    {
                        msg = "No hay talonarios para Establecimiento=" + cod_estable + " y punto de emision=" + cod_pto_emision;
                        throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "no hay talonario activos", msg))
                              {
                                  EntityType = typeof(in_Guia_x_traspaso_bodega_Bus)
                              };
                    }

                    Info_Guia.IdEstablecimiento = infoTalonario.Establecimiento;
                    Info_Guia.IdPuntoEmision    = infoTalonario.PuntoEmision;
                    Info_Guia.NumDocumento_Guia = infoTalonario.NumDocumento;
                }
                else
                {
                    // se puede dar si mas de un usario estan haciendo la factura y tienen en memoria o en la pantalla el mismo talonario
                    //verifico el numero de factura si esta usado
                    infoTalonario.Establecimiento          = Info_Guia.IdEstablecimiento;
                    infoTalonario.PuntoEmision             = Info_Guia.IdPuntoEmision;
                    infoTalonario.NumDocumento             = Info_Guia.NumDocumento_Guia;
                    infoTalonario.IdEmpresa                = Info_Guia.IdEmpresa;
                    infoTalonario.CodDocumentoTipo         = Info_Guia.CodDocumentoTipo;
                    infoTalonario.es_Documento_electronico = Info_Guia.Es_electronica;


                    if (Info_Guia.IdGuia == 0 && busTalonario.Documento_talonario_esta_Usado(infoTalonario, ref msg, ref mensajeDocumentoDupli))
                    {
                        //si esta en usado busco el siguiente
                        cod_estable     = Bus_Sucu.Get_Cod_Establecimiento_x_Sucursal(Info_Guia.IdEmpresa, Convert.ToInt32(Info_Guia.IdSucursal_Partida));
                        cod_pto_emision = Bus_bodega.Get_cod_pto_emision_x_Bodega(Info_Guia.IdEmpresa, Convert.ToInt32(Info_Guia.IdPuntoEmision), 1);

                        infoTalonario = busTalonario.Get_Info_Primer_Documento_no_usado(Info_Guia.IdEmpresa, cod_pto_emision, cod_estable, Info_Guia.CodDocumentoTipo, Info_Guia.Es_electronica);

                        if (infoTalonario.NumDocumento == null)
                        {
                            throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "no hay talonario activos", msg))
                                  {
                                      EntityType = typeof(in_Guia_x_traspaso_bodega_Bus)
                                  };
                        }

                        Info_Guia.IdEstablecimiento = infoTalonario.Establecimiento;
                        Info_Guia.IdPuntoEmision    = infoTalonario.PuntoEmision;
                        Info_Guia.NumDocumento_Guia = infoTalonario.NumDocumento;
                    }
                }


                /*--- corrigiendo data */

                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                Core.Erp.Info.Log_Exception.LoggingManager.Logger.Log(Core.Erp.Info.Log_Exception.LoggingCategory.Error, ex.Message);
                throw new Core.Erp.Info.Log_Exception.DalException(string.Format("", "Validar_y_corregir_objeto", ex.Message), ex)
                      {
                          EntityType = typeof(in_Guia_x_traspaso_bodega_Bus)
                      };
            }
        }