martes, 26 de junio de 2018
Generar Tabla de Calendarios y Calendarios x Empleado
Estimados,
En esta ocasión les dejare este pequeño ejemplo como yo realice un calendario y calendario empleado por temas de rrhh.
Slds
declare @Fecha datetime = '01/12/2018'
declare @ini datetime
declare @fin datetime
--primer dia del mes
SELECT @ini = DATEADD(mm, DATEDIFF(mm,0,@Fecha ), 0)
--ultimo dia del mes
SELECT @fin = dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,@Fecha )+1, 0));
declare @begdate as datetime
declare @enddate as datetime
declare @diff as int
declare @T_Fecha Table
(
Periodo varchar(10),
Annio int ,
Mes int ,
Fecha datetime ,
Feriado bit
)
set @begdate = (select cast( @ini as datetime) )
set @enddate = (select cast(@fin as datetime) )
set @diff = datediff(day, @begdate ,@enddate)
while (@begdate <= @enddate) --insertar el registro hasta que fecha inicio y fin sean iguales
begin
--insert into @T_Fecha values( ( cast( year(@begdate) as varchar)+ '-' + RIGHT( '00' + cast( month(@begdate) AS varchar), 2) ) , year(@begdate), month(@begdate), @begdate , 0)
insert into Calendario values( ( cast( year(@begdate) as varchar)+ '-' + RIGHT( '00' + cast( month(@begdate) AS varchar), 2) ) , year(@begdate), month(@begdate), @begdate , 0)
set @begdate = dateadd(day,1,@begdate) --vamos incrementando los días
end
select distinct Periodo from Calendario
select distinct idpersonal , Periodo from dbo.personal
left join Calendario on Calendario.Periodo=Calendario.Periodo
insert into EmpleadoCalendario
select distinct idpersonal , Periodo from dbo.personal
left join Calendario on Calendario.Periodo=Calendario.Periodo
select * from EmpleadoCalendario where idempleado = 3
martes, 19 de junio de 2018
Limpiar Formulario desde C# ASP.NET - Nuevo
Para limpiar un formulario desde un boton "Nuevo", podemos realizarlos con este pequeño codigo, esto incluye asi tengamos querystrings en nuestros formularios.
Response.Redirect(Request.RawUrl.Replace(Request.Url.Query, ""));
Slds
Response.Redirect(Request.RawUrl.Replace(Request.Url.Query, ""));
Slds
viernes, 24 de noviembre de 2017
Cannot find libSQLDBCHDB.dll:null HANA
Estimado,
En esta ocasión veremos como solucionar este problema.
En esta ocasión veremos como solucionar este problema.
viernes, 9 de junio de 2017
Store procedure SAP Hana
Estimados,
En esta ocasión veremos como generar un store procedure en Hana Studio e invocarlo desde visual Studio .net, asimismo adjuntare las DLL necesarias para la conexion asi como la cadena de conexion, sabemos que no hay mucha información sobre Hana studio hasta el momento, seria bueno sus comentarios,
Saludos,
DROP PROCEDURE "Pa_OrdenCompra_Listar";
CREATE PROCEDURE "Pa_OrdenCompra_Listar" (
IN Id int)
as
BEGIN
select "DocNum" ID, "CardCode" as Codigo,"CardName" as Proveedor, "Address" Direccion, "DocTotal" Total ,cast( "DocDate" as char(10)) Fecha , "DocCur" Moneda
from opor
;
END
En esta ocasión veremos como generar un store procedure en Hana Studio e invocarlo desde visual Studio .net, asimismo adjuntare las DLL necesarias para la conexion asi como la cadena de conexion, sabemos que no hay mucha información sobre Hana studio hasta el momento, seria bueno sus comentarios,
Saludos,
DROP PROCEDURE "Pa_OrdenCompra_Listar";
CREATE PROCEDURE "Pa_OrdenCompra_Listar" (
IN Id int)
as
BEGIN
select "DocNum" ID, "CardCode" as Codigo,"CardName" as Proveedor, "Address" Direccion, "DocTotal" Total ,cast( "DocDate" as char(10)) Fecha , "DocCur" Moneda
from opor
;
END
void DataHana()
{
HanaConnection oHanaConnection = new HanaConnection("Server=192.168.1.XX:TUPUERTO;UserID=TUUSUARIO;Password=TUCLAVE");
oHanaConnection.Open();
String strSQL = "select * from BD.OIGN ";
//Execute the SQL statement
HanaCommand cmd = new HanaCommand(strSQL, oHanaConnection);
String strCommand = @"call ""BD"".""Pa_OrdenCompra_Listar"" (1)";
DataTable oDataTable = new DataTable();
HanaCommand oHanaCommand = new HanaCommand();
oHanaCommand.Connection = oHanaConnection;
// oHanaCommand.CommandType = CommandType.StoredProcedure;
oHanaCommand.CommandText = strCommand;// @"ZZ_DESARROLLO.bpvs_CL_LY_VOUCHER";
// CALL "bpvs_CL_LY_VOUCHER" ({?DocKey@})
//oHanaCommand.Parameters.AddWithValue("Id", 1);
HanaDataAdapter oHanaDataAdapter = new HanaDataAdapter(oHanaCommand);
//Read and store the result set
HanaDataReader reader = cmd.ExecuteReader();
oHanaDataAdapter.Fill(oDataTable);
string Filas = oDataTable.Rows.Count.ToString();
//Bind the result set to a DataGridViewer/
GridFamiliaProductos.DataSource = oDataTable;
GridFamiliaProductos.DataBind();
//Close the reader connection
reader.Close();
//Close the database connection
oHanaConnection.Close();
}
miércoles, 31 de mayo de 2017
Coneccion a PostGress
En esta ocasión subiré un ejemplo como conectarnos a postgress, adjunto proyecto,
Descargar aqui
Slds,
Descargar aqui
Slds,
martes, 16 de mayo de 2017
Obtener columnas del resultado de un store en un DataTable
En algunas ocasiones necesitamos tener el resultado de las columnas en una lista de objeto u arreglo, para ello lo realizamos de la siguiente manera.
foreach (DataColumn oDataColumn in oObj.Columns)
{
string Columna = oDataColumn.ColumnName;
oLista.Add(Columna);
}
Slds
Leer archivos de excel desde un directorio de manera dinamica
Aquí después de un tiempo, en esta ocasión vamos a ver como leer archivos (excel )desde .NET y poder recorrer las hojas de manera dinámica.
Por ejemplo vamos a recorrer todos los archivos que hay en esta ruta y lo guardamos en una colecciòn.
DirectoryInfo di2 = new DirectoryInfo(@"\\192.168.1.111\Carpeta\SubCarpeta");
ObjetoPrint oObjetoPrint = new Migrar.ObjetoPrint();
List<ObjetoPrint> oListaObjetoPrint = new List<Migrar.ObjetoPrint>();
foreach (var fi in di2.GetFiles())
{
// Console.WriteLine(fi.Name);
oObjetoPrint = new Migrar.ObjetoPrint();
oObjetoPrint.FechaCreacion = fi.CreationTime;
oObjetoPrint.NombreArchivo = fi.Name.ToString();
oListaObjetoPrint.Add(oObjetoPrint);
}
string[] Hojas = GetExcelSheetNames(Ruta);
Con este metodo vamos a obtener las hojas del archivo que deseamos.
Aqui leemos el contenido de una hoja en especifico.
oObject = GetDataExcel(Ruta, Hojas[0]);
Este resultado podemos migrarlo a un temporal.
Slds
// Establishing connection
SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder();
cb.DataSource = "192.168.1.111";
cb.InitialCatalog = "TUBD";
cb.IntegratedSecurity = true;
SqlConnection cnn = new SqlConnection(cb.ConnectionString);
// Initializing an SqlBulkCopy object
SqlBulkCopy sbc = new SqlBulkCopy("server=192.168.4.111;database=TUBD;Integrated Security=SSPI");
// Copying data to destination
sbc.DestinationTableName = "TEMP";
sbc.WriteToServer(oObject);
private static String[] GetExcelSheetNames(string excelFile)
{
OleDbConnection objConn = null;
System.Data.DataTable dt = null;
try
{
// Connection String. Change the excel file to the file you
// will search.
String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
// Create connection object by using the preceding connection string.
objConn = new OleDbConnection(connString);
// Open connection with the database.
objConn.Open();
// Get the data table containg the schema guid.
dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dt == null)
{
return null;
}
String[] excelSheets = new String[dt.Rows.Count];
int i = 0;
// Add the sheet name to the string array.
foreach (DataRow row in dt.Rows)
{
excelSheets[i] = row["TABLE_NAME"].ToString();
i++;
}
// Loop through all of the sheets if you want too...
for (int j = 0; j < excelSheets.Length; j++)
{
// Query each excel sheet.
}
return excelSheets;
}
catch (Exception ex)
{
return null;
}
finally
{
// Clean up.
if (objConn != null)
{
objConn.Close();
objConn.Dispose();
}
if (dt != null)
{
dt.Dispose();
}
}
}
static public DataTable GetDataExcel(
string fileName, string sheetName)
{
try
{
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source =" + fileName + ";Extended Properties=Excel 8.0";
using (OleDbConnection cnn = new OleDbConnection(connString))
{
OleDbCommand cmd = cnn.CreateCommand();
// cmd.CommandText = string.Format("SELECT * FROM [{0}]", sheetName);
//cmd.CommandText = "SELECT * FROM [{0}]";
cmd.CommandText = string.Format("SELECT * FROM [{0}]", sheetName);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
catch (Exception)
{
throw;
}
}
Suscribirse a:
Entradas (Atom)

