public ba_Talonario_cheques_x_banco_Info get_info(int IdEmpresa, int IdBanco, string Num_cheque)
 {
     try
     {
         ba_Talonario_cheques_x_banco_Info info = new ba_Talonario_cheques_x_banco_Info();
         using (Entities_banco Context = new Entities_banco())
         {
             ba_Talonario_cheques_x_banco Entity = Context.ba_Talonario_cheques_x_banco.FirstOrDefault(q => q.IdEmpresa == IdEmpresa && q.IdBanco == IdBanco && q.Num_cheque == Num_cheque);
             if (Entity == null)
             {
                 return(null);
             }
             info = new ba_Talonario_cheques_x_banco_Info
             {
                 IdEmpresa = Entity.IdEmpresa,
                 IdBanco   = Entity.IdBanco,
                 IdCbteCble_cbtecble_Usado = Entity.IdCbteCble_cbtecble_Usado,
                 IdEmpresa_cbtecble_Usado  = Entity.IdEmpresa_cbtecble_Usado,
                 IdTipoCbte_cbtecble_Usado = Entity.IdTipoCbte_cbtecble_Usado,
                 Estado_bool = Entity.Estado == "A",
                 Num_cheque  = Entity.Num_cheque,
                 secuencia   = Entity.secuencia,
                 Usado       = Entity.Usado,
                 Fecha_uso   = Entity.Fecha_uso
             };
         }
         return(info);
     }
     catch (Exception)
     {
         throw;
     }
 }
        public bool anularDB(ba_Talonario_cheques_x_banco_Info info)
        {
            try
            {
                using (Entities_banco Context = new Entities_banco())
                {
                    ba_Talonario_cheques_x_banco Entity = Context.ba_Talonario_cheques_x_banco.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa && q.IdBanco == info.IdBanco && q.Num_cheque == info.Num_cheque);
                    if (Entity == null)
                    {
                        return(false);
                    }

                    Entity.Estado = info.Estado = "I";

                    Entity.IdUsuario_Anu  = info.IdUsuario_Anu;
                    Entity.FechaAnulacion = DateTime.Now;
                    Context.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
 public bool guardarDB(ba_Talonario_cheques_x_banco_Info info)
 {
     try
     {
         decimal secuencia = get_secuencia(info.IdEmpresa, info.IdBanco);
         using (Entities_banco Context = new Entities_banco())
         {
             ba_Talonario_cheques_x_banco Entity = new ba_Talonario_cheques_x_banco
             {
                 IdEmpresa  = info.IdEmpresa,
                 IdBanco    = info.IdBanco,
                 Num_cheque = info.Num_cheque,
                 Usado      = info.Usado,
                 secuencia  = info.secuencia = secuencia++,
                 Fecha_uso  = info.Fecha_uso,
                 Estado     = info.Estado = "A"
             };
             Context.ba_Talonario_cheques_x_banco.Add(Entity);
             Context.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
        public Boolean GrabarDB(ba_Talonario_cheques_x_banco_Info info, ref string mensaje)
        {
            try
            {
                using (EntitiesBanco context = new EntitiesBanco())
                {
                    EntitiesBanco EDB = new EntitiesBanco();

                    var Q = from per in EDB.ba_Talonario_cheques_x_banco
                            where (per.Num_cheque == info.Num_cheque &&
                                   per.IdEmpresa == info.IdEmpresa &&
                                   per.IdBanco == info.IdBanco) ||
                            (per.secuencia == info.secuencia &&
                             per.IdEmpresa == info.IdEmpresa &&
                             per.IdBanco == info.IdBanco)
                            select per;

                    if (Q.ToList().Count == 0)
                    {
                        var address = new ba_Talonario_cheques_x_banco();

                        address.IdEmpresa = info.IdEmpresa;
                        address.secuencia = GetSecuencia(info.IdEmpresa);
                        address.IdBanco   = info.IdBanco;
                        address.IdCbteCble_cbtecble_Usado = info.IdCbteCble_cbtecble_Usado;
                        address.IdEmpresa_cbtecble_Usado  = info.IdEmpresa_cbtecble_Usado;
                        address.IdTipoCbte_cbtecble_Usado = info.IdTipoCbte_cbtecble_Usado;
                        address.IdUsuario_Anu             = (info.IdUsuario_Anu == null) ? "" : info.IdUsuario_Anu;
                        //address.MotivoAnulacion = info.MotivoAnulacion;
                        //address.FechaAnulacion = info.FechaAnulacion;
                        address.Fecha_uso  = DateTime.Now;
                        address.Num_cheque = info.Num_cheque;
                        address.Usado      = info.Usado;
                        address.Estado     = info.Estado;

                        context.ba_Talonario_cheques_x_banco.Add(address);
                        context.SaveChanges();

                        mensaje = "Se ha procedido a guardar ..# : " + info.Num_cheque.ToString() + " EXITOSAMENTE";
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(true);
            }
            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.InnerException + " " + ex.Message;
                mensaje = "Error al grabar .." + ex.Message;
                throw new Exception(ex.InnerException.ToString());
            }
        }
        public bool modificarDB(ba_Talonario_cheques_x_banco_Info info)
        {
            try
            {
                using (Entities_banco Context = new Entities_banco())
                {
                    ba_Talonario_cheques_x_banco Entity = Context.ba_Talonario_cheques_x_banco.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa && q.IdBanco == info.IdBanco && q.Num_cheque == info.Num_cheque);
                    if (Entity == null)
                    {
                        return(false);
                    }

                    Entity.Usado  = info.Usado;
                    Entity.Estado = info.Estado_bool == true ? "A" : "I";

                    Context.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }