using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using System.Data;
using System.Web.UI.WebControls;
namespace SistemaCreditos.Clases
{
public class Utilidades
{
Conexion con = new Conexion();
string error = "",sql="",a="";
SqlDataReader r;
public void llenaCombosId(string cadena, string item,string id, ref DropDownList ddl)
{
//try
//{
ddl.Items.Clear();
r = con.Reg(cadena);
while (r.Read())
{
ddl.Items.Add(new ListItem(r[item].ToString(),r[id].ToString().Trim()));
}
r.Close();
//}
//catch (Exception ex)
//{
// return;
//}
}
//Para llenar Reportes
public void GetDate(ref string hora, ref string fecha)
{
r = con.Reg("select GETDATE();");
if (r.Read())
{
DateTime x = Convert.ToDateTime(r[0]);
hora = x.ToShortTimeString();
fecha = x.ToShortDateString();
}
}
public DateTime GetDate()
{
DateTime x = DateTime.Today;
r = con.Reg("select GETDATE();");
if (r.Read()) x=Convert.ToDateTime(r[0]);
return x;
}
public string DateTime_A_BD(string fecha){
return "'" + Convert.ToDateTime(fecha).ToShortDateString() + " " + Convert.ToDateTime(fecha).TimeOfDay + "'";
}
public bool Exists(string cad)
{
r=con.Reg(cad);
if (r.Read()) return true;
else return false;
}
public string ObtenNombreCliente(int idCliente)
{
sql = "Select RTRIM(Nombre)+SPACE(1)+RTRIM(ApellidoPaterno)+SPACE(1)+RTRIM(ApellidoMaterno) from Clientes where idCliente=" + idCliente;
r = con.Reg(sql);
if (r.Read()) return r[0].ToString();
else return "";
}
public string Age(DateTime birthday)
{
DateTime now = DateTime.Today;
int age = now.Year - birthday.Year;
if (now < birthday.AddYears(age)) age--;
return age.ToString();
}
public string ObtenValor(string cadena)
{
r = con.Reg(cadena);
if (r.Read()) return r[0].ToString();
else return "";
}
}
}