Пример #1
0
        public static async Task <string> GetNameDB(Conexion conexion, string empresa)
        {
            try
            {
                StringBuilder query = new StringBuilder();
                query.Append("DECLARE @dbname nvarchar(128) ");
                query.Append($"SET @dbname = N'{empresa}' ");
                query.Append("IF (EXISTS (SELECT ");
                query.Append("    name ");
                query.Append("  FROM master.dbo.sysdatabases ");
                query.Append("  WHERE ('[' + name + ']' = @dbname ");
                query.Append("  OR name = @dbname)) ");
                query.Append("  ) ");
                query.Append("BEGIN ");
                query.Append("  SELECT  'TRUE' ");
                query.Append("END ");
                query.Append("ELSE ");
                query.Append("BEGIN ");
                query.Append("  SELECT  'FALSE' ");
                query.Append("END ");

                conexion.Query = query.ToString();
                var res = (string)await Conexion.ExecuteScalarAsync(conexion);

                return(res);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Get 1 F° available of NV.
        /// </summary>
        /// <param name="conexion"></param>
        /// <returns></returns>
        public static async Task <int> GetLastNv(Conexion conexion)
        {
            try
            {
                conexion.Query = "select MAX(NVNumero) + 1  from softland.nw_nventa";
                object result = await Conexion.ExecuteScalarAsync(conexion);

                if (result != null)
                {
                    return(Convert.ToInt32(result));
                }
                else
                {
                    return(1); // FOR NEW COMPANIES.
                }
            }
            catch (Exception)
            {
                throw;
            }
        }