Mostrando entradas con la etiqueta Winforms. Mostrar todas las entradas
Mostrando entradas con la etiqueta Winforms. Mostrar todas las entradas

lunes, 5 de mayo de 2008

Prevenir Resize y Minimización de Ventana -

La propiedad que permite prohibir la opción de minimizar y modificar el tamaño de la pantalla es FormBorderStyle.
Las opciones posibles están en este post de msdn:
http://msdn.microsoft.com/es-es/library/hw8kes41(VS.80).aspx

viernes, 29 de febrero de 2008

Crystal Reports en WinForms - Exportar a pdf un reporte con C#.NET

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace ClockManager
{
public partial class Reports : Form
{
#region Propiedades

public string filePath = "";
SaveFileDialog saveFileDialog1 = new SaveFileDialog();

#endregion

#region Metodos

public Reports()
{
InitializeComponent();
}
public void SaveFile()
{


if (filePath.Trim() == "")
return;
//
TuNameSpace.RPT_FECHA_HORA_X_ID rpt = new TuNameSpace.RPT_FECHA_HORA_X_ID();
ReportDocument myReport = new ReportDocument();

//Le paso un parametro al reporte [esto es opcional]
rpt.SetParameterValue("@ID", "25832556");

//Defino los parametros de conexion
string UserID = "usuario1";
string Password = "123456";
string ServerName = "MiPc\\SQLEXPRESS";
string DatabaseName = "MIBASE";

//Seteo los parametros de conexion
rpt.SetDatabaseLogon(UserID, Password, ServerName, DatabaseName);


try
{
//Exporto el archivo
rpt.ExportToDisk(ExportFormatType.PortableDocFormat, this.filePath);
MessageBox.Show("OK!");
}
catch (Exception ex)
{
string a = ex.Message;
}

}

#endregion

private void Reports_Load(object sender, EventArgs e)
{
//Seteo algunas propiedades del SaveFileDialog
this.saveFileDialog1.AddExtension = true;
this.saveFileDialog1.AutoUpgradeEnabled = true;
this.saveFileDialog1.CheckFileExists = false;
this.saveFileDialog1.CheckPathExists = false;
this.saveFileDialog1.DefaultExt = ".pdf";

this.saveFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.saveFileDialog1_FileOk);
saveFileDialog1.ShowDialog();
}

#region Eventos

private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
this.filePath = saveFileDialog1.FileName;
SaveFile();
}


#endregion
}

}

martes, 26 de febrero de 2008

SqlServerCe - SQL Server Compact Edition (Winforms)

/*
Clase tipo capa de datos para Sql Server Compact Edition.
*/


using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlServerCe;

class DBPortable
{
private static string dbName = "MyDB";
private static string pass = "123456";
private static string connString = "Data Source =\"|DataDirectory|\\" + dbName + ".sdf\"; Password =\"" + pass + "\";";
private SqlCeConnection conn = new SqlCeConnection(connString);

public DBPortable()
{
if (!HaveDB())
{
CreateDB();
CreateSchema();
}
}

private bool HaveDB()
{
if (System.IO.File.Exists(conn.Database))
{
return true;
}
else
{
return false;
}
}

private void CreateDB()
{
using (SqlCeEngine sqlCeEngine = new SqlCeEngine(connString))
{
sqlCeEngine.CreateDatabase();
}
}

public string BuildQueryFromString(string sp, string[] param)
{
string query = sp + " '";
int i = 0;
foreach (string p in param)
{
if (i < param.Length - 1)
query += p + "', '";
else
query += p + "'";
i++;
}
return query;
}
public DataSet ExecQuery(string iQuery)
{
DataSet ds = new DataSet();
SqlCeDataAdapter adapter = new SqlCeDataAdapter();

try
{
SqlCeCommand command = new SqlCeCommand(iQuery, this.conn);
adapter.SelectCommand = command;
this.conn.Open();
command.Connection = this.conn;
adapter.Fill(ds);
}
catch (SqlCeException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
this.conn.Close();
}

return ds;

}
public DataSet ExecSP(string sp, string[] param)
{
string iQuery = BuildQueryFromString(sp, param);
DataSet ds = new DataSet();
SqlCeDataAdapter adapter = new SqlCeDataAdapter();

try
{
SqlCeCommand command = new SqlCeCommand(iQuery, this.conn);
adapter.SelectCommand = command;
this.conn.Open();
command.Connection = this.conn;
adapter.Fill(ds);
}
catch(SqlCeException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
this.conn.Close();
}

return ds;
}
private void CreateSchema()
{
string q = "CREATE TABLE TablaDePrueba(ID int NULL, FechaHora DATETIME NULL, ESTADO NCHAR(1))";
this.ExecuteNonQuery(q);
}
private int ExecuteNonQuery(string query)
{
int RowsAffected = 0;

SqlCeCommand objCom = new SqlCeCommand();
objCom.CommandText = query;

try
{
this.conn.Open();
objCom.Connection = this.conn;
RowsAffected = objCom.ExecuteNonQuery();
}
catch (SqlCeException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
this.conn.Close();
}

return RowsAffected;
}