Un poco de C#,JScript,VB, y CRM, Drupal, SQL , MSDCRM y MSDSL VBTools, developer, project lider, Social Media Activist, BlackBerry developer, telerik tools. (MCITP)
jueves, 24 de mayo de 2012
Crystal report connection
public CrystalDecisions.CrystalReports.Engine.ReportClass GetReport(string stringFromDate, string stringToDate, string stringOfficeID)
{
try {
// Create an instance of the report and set it's datasource.
string sType = "ReportsNameSpace.Report";
Type reportType = Type.GetType(sType, true, true);
if (reportType != null) {
// Create an instance of the report and set it's datasource.
CrystalDecisions.CrystalReports.Engine.ReportClass rpt = (CrystalDecisions.CrystalReports.Engine.ReportClass)Activator.CreateInstance(reportType);
ParameterFieldDefinitions crParameterFieldDefinitions = default(ParameterFieldDefinitions);
crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields;
SCRCollectionEnumerator en = crParameterFieldDefinitions.GetEnumerator();
while ((en.MoveNext())) {
ParameterFieldDefinition param = default(ParameterFieldDefinition);
param = en.Current;
ParameterValues crValue = new ParameterValues();
// you have to check for parameter name
// and pass values
if ((param.Name == "@FromDate")) {
crValue.AddValue(stringFromDate);
param.ApplyCurrentValues(crValue);
} else if ((param.Name == "@ToDate")) {
crValue.AddValue(stringToDate);
param.ApplyCurrentValues(crValue);
}
}
TableLogOnInfo logOnInfo = new TableLogOnInfo();
// I am assuming that you have crystal server database
// connection strings in your web.config
logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings("CrystalServer").ToString();
logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings("CrystalUser").ToString();
logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings("CrystalPassword").ToString();
TableLogOnInfo login = default(TableLogOnInfo);
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in rpt.Database.Tables) {
login = tbl.LogOnInfo;
login.ConnectionInfo.ServerName = ConfigurationManager.AppSettings("CrystalServer").ToString();
login.ConnectionInfo.UserID = ConfigurationManager.AppSettings("CrystalUser").ToString();
login.ConnectionInfo.Password = ConfigurationManager.AppSettings("CrystalPassword").ToString();
tbl.ApplyLogOnInfo(login);
}
return rpt;
} else {
return null;
}
} catch (Exception ex) {
throw ex;
}
}
Fuente: http://forums.asp.net/p/1584368/4000328.aspx
For dynamic Database connection Crystal Reports
Database connection Crystal Reports doesn´t works!!!
crConnectionInfo.ServerName = "YOUR SERVER NAME";
crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
crConnectionInfo.Password = "YOUR DATABASE PASSWORD";
CrTables = cryRpt.Database.Tables ;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
but this Works fine!
foreach (Table crTable in objRpt.Database.Tables)
{
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo = objRpt.Database.Tables[crTable.Name].LogOnInfo;
// Set the connection information for the table in the report.
logOnInfo.ConnectionInfo.ServerName = server.Trim();
logOnInfo.ConnectionInfo.DatabaseName = database.Trim();
logOnInfo.ConnectionInfo.UserID = username;
logOnInfo.ConnectionInfo.Password = password;
objRpt.Database.Tables[crTable.Name].ApplyLogOnInfo(logOnInfo);
}
miércoles, 23 de mayo de 2012
Send email with c#
private void sendEmail()
{
//Declarando Variables
try
{
string From;
string To;
string Message;
string Subject;
System.Net.Mail.MailMessage Email;
//Aplicando los campos a cada variable
From = ;/*correo origen*/
To = ;/*correo destinatario*/
Message = ;/*Mensaje*/;
Subject =;/*Asunto*/
//Establesco El Email
Email = new System.Net.Mail.MailMessage(From, To, Subject, Message);
System.Net.Mail.SmtpClient smtpMail = new System.Net.Mail.SmtpClient("smtp.gmail.com");
Email.IsBodyHtml = false;
System.Net.Mail.Attachment attachment;
txtattach.Text = "";/*File Path*/;
attachment = new System.Net.Mail.Attachment(txtattach.Text.Trim());
Email.Attachments.Add(attachment);
smtpMail.EnableSsl = true;
smtpMail.UseDefaultCredentials = false;
smtpMail.Port = 25;
smtpMail.Credentials = new System.Net.NetworkCredential(/*USER*/,/*PASS*/);
//smtpMail.ClientCertificates.
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpMail.Send(Email);
attachment.Dispose();
MessageBox.Show("enviado con exito");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
sábado, 11 de febrero de 2012
Validación de RFC , CRM
function validaRFC(cual)
{
mensaje = "Debes poner un formato LLLL-999999-XXX"
pat = /[a-z]|[A-Z]/
pat2 = /[a-z]|[A-Z]|[0-9]/
val = cual.split("-")
if (val.length == 3){
if(val[0].length == 4){
if(!comp(val[0],pat)){
alert( mensaje)
return false
}
}
if(val[1].length == 6){
if(isNaN(val[1])){
alert('no es un numero')
return false
}
}
if(val[2].length == 3){
if(!comp(val[2],pat2)){
alert(mensaje)
return false
}
}
else{
alert(mensaje)
return false
}
}
else{
alert(mensaje)
return false
}
return true
}
function comp(cual,pa){
for ( m = 0 ; m < cual.length ; m++ ) {
if(!pa.test(cual.charAt(m))){
return false
break
}
}
return true
}
domingo, 29 de enero de 2012
Read txt file with c#
public ArrayList ReadtxtFile(string txtPath)
{
StreamReader objReader = new StreamReader(txtPath);
string sLine = "";
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
{
if (sLine != "")
arrText.Add(sLine);
}
}
objReader.Close();
return arrText;
}
fill a Data table dynamically with the results of Xml query
Here you can fill a Data table dynamically with the results of Xml query (Prev. Post)
var dtRowsElements = objData.SelectAllfromTable(ElementTable);
IEnumerable
DataTable objDTable = objData.FillDataTable(dtRows);
/*Function to create the Data Table.*/
public DataTable FillDataTable(IEnumerable
{
/*Crea Datatable a partir de lo que Elementos obtenidos de dtRows "Consulta XML que es un IEnumerable
DataTable dtDescrValue = new DataTable();
try
{
foreach (XElement dtColumn in dtRows.First().Elements())
{
//Crea Columnas
dtDescrValue.Columns.Add(dtColumn.Name.ToString(), typeof(string));
}
foreach (XElement dtRow in dtRows)
{
//Crea cada registro "Row"
DataRow dtDescrRow = dtDescrValue.NewRow();
foreach (XElement dtColumn in dtRows.First().Elements())
{ //Asigna valores de cada column de "Row"
dtDescrRow[dtColumn.Name.ToString()] = dtRow.Element(dtColumn.Name.ToString()).Value;
}
dtDescrValue.Rows.Add(dtDescrRow);
}
}
catch (Exception e)
{//En caso de Error regresa un Data table con Id: "Error", Descr: Message de error.
dtDescrValue.Columns.Add("Descr", typeof(string));
dtDescrValue.Columns.Add("Id", typeof(string));
DataRow dtDescrRow = dtDescrValue.NewRow();
dtDescrRow["Descr"] = e.Message;//"No data...";
dtDescrRow["Id"] = "Error";
dtDescrValue.Rows.Add(dtDescrRow);
}
return dtDescrValue;
}
XML Query whit Linq C#
Whit this lines you can get all elements from "Task"
string ElementTable = "Task";
var dtRowsElements = objData.SelectAllfromTable(ElementTable);
IEnumerable
/*Function*/
public IEnumerable SelectAllfromTable(string Table)
{ /*Selecciona Todos los campos de la tabla en el .XML*/
string DBFile = string.Empty;
DBFile = "DB\\TrackTimeDB.xml";
try
{
XElement TracktTimeDB = XElement.Load(DBFile);
var AllData = from c in TracktTimeDB.Descendants(Table)
select c;
return AllData;
}
catch (Exception er)
{
return null;
}
}
Suscribirse a:
Entradas (Atom)