Friday, February 3, 2012

Deploying a .Net crystal report website on a shared server

Hi Guys,

Deploying a crystal report website on a shared server has really been a very difficult task. I have been using rdlc reports upto now for my web applications, but due to the limitations they have I had to use crystal report to one of my web applications, that's when I had to learn this thing, and also realised that many of the guys are struggling with this issue and some of them are not able to sort this thing out for months/years. Though there so many deployment issues which is not possible for me to list out, but here I am writting steps to deploy a crystal report site, which you can use as a primary guideline for deploying a crystal report website.

1. Put the following DLLs to your BIN directory at your shared server.

CrystalDecisions.CrystalReports.Engine
CrystalDecisions.Shared
CrystalDecisions.ReportSource

2. Install the appropriate crystal report redistributable(the redistributable applicable for the version you are using) at server.

3. Give the IIS user account and asp.net worker process account full control for the reports folder.

4. Make sure to give 'everyone' full control to the temp directory of windows.

5. for more information and support log on to http://forums.sdn.sap.com/index.jspa.

wish you all the best for your deployment.

Monday, January 30, 2012

tsql function to convert a column value to csv

Option 1:

alter function udf_get_csv_faults (@unit varchar(4),@jobno int)
returns varchar(500)
as
begin
declare @csv varchar(2048)
SELECT @csv= SUBSTRING(
(SELECT ',' + s.detail
FROM vw_job_sheet_fault s
where s.js_unitcode=@unit and s.js_jobno=@jobno
FOR XML PATH('')),2,500)
return @csv
end
GO


Option 2:

create FUNCTION udf_get_csv(@unit varchar(4),@jobno int)
RETURNS varchar(500)
AS
BEGIN
declare @csv varchar(500)
Select @csv = null
SELECT @csv = Coalesce(@csv + ', ', '') +
s.detail
FROM vw_job_sheet_fault s
where s.js_unitcode=@unit and s.js_jobno=@jobno
RETURN @csv

END

Friday, January 20, 2012

code for crystal report

Visual Studio 2005 and Crystal Report XI.

1. Create a Crystal Report as usual in Visual studio 2005 .net
using ODBC connection. In this example "CrystalReport.rpt"

2. Create a aspx web form to display the report. This form will
be a place holder for crystal report.

3. In design mode, drag and drop Crystal Report viewer control and
don't configure anything.

4. Open code behind .aspx.vb

'Declare public variable

Private myReportDocument As ReportDocument

'Note: This is Page Init event not Page Load event

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()

' Note: This is your local ODBC Name NOT SQL SERVER NAME

myConnectionInfo.ServerName = "PUBSODBCNAME"

' If your ODBC connection defaulted to your application database,
' you can remove the following line.

myConnectionInfo.DatabaseName = "Pubs"
myConnectionInfo.UserID = "userid"
myConnectionInfo.Password = "password"

myReportDocument = New ReportDocument()
'If your crystal report is in some other folder, give proper path
' In this example, .rpt file in the same folder as .aspx file
Dim reportPath As String = Server.MapPath("CrystalReport.rpt")
myReportDocument.Load(reportPath)
SetDBLogonForReport(myConnectionInfo, myReportDocument)
CrystalReportViewer1.ReportSource = myReportDocument
' You can customize the Crystal Reports toolbar.
' like the following. I have disabled the business object logo
' in the tool bar.

CrystalReportViewer1.HasCrystalLogo = False

End Sub

'This Sub is necessary for Crystal report database connection

Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument)
Dim myTables As Tables = myReportDocument.Database.Tables
For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
myTableLogonInfo.ConnectionInfo = myConnectionInfo
myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
5. Now run the .aspx page. You will see the report or the crystal report parameter
form. It will not ask you DB login information.

6. dont forget to Imports dll

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.ReportSource

Friday, October 7, 2011

Using Stored Procedures in the Entity Framework with Scalar Return Values

This Link explains well on how to deal with stored procs returning scalar values using EF. Further it also explains how to handle if the proc returns null. If you have any doubt or need more examples, you can discuss with me here.

Friday, September 16, 2011

upload a file in asp.net MVC along with other components in your view

Hi,

I am here going to describe how to upload a file in asp.net MVC along with other components in your view. The view is a content page.

let us take an example of an item object I will write here some portions of viewmodel, view page and controller function.

ViewModel:


[Required(ErrorMessage = "Item Code Required")]
[StringLength(50, ErrorMessage = "Must be less than 51 characters")]
public string i_code
{
get;
set;
}

[Required(ErrorMessage = "Item Name Required")]
[StringLength(50, ErrorMessage = "Must be less than 51 characters")]
public string i_name
{
get;
set;
}

public HttpPostedFileBase Image
{
get;
set;
}





View:

'

<% using (Html.BeginForm("Create","items",FormMethod.Post, new {enctype = "multipart/form-data"}))
{%>

<% =ViewData["Result"] %>
<%: Html.ValidationSummary(true)%>



<%: Html.LabelFor(model => model.i_code) %>
<%: Html.TextBoxFor(model => model.i_code) %>
<%: Html.ValidationMessageFor(model => model.i_code) %>

<%: Html.LabelFor(model => model.i_name) %>
<%: Html.TextBoxFor(model => model.i_name) %>
<%: Html.ValidationMessageFor(model => model.i_name) %>

<%: Html.LabelFor(model => model.FileUpload) %>
input type="file" id="Image" name="Image"

input type="submit" value="Create"


<% } %>'




Controller Function:

[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create( itemviewmodel ToCreate)
{

if (ToCreate.Image.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("../bin/Uploads"),
Path.GetFileName(ToCreate.Image.FileName.Replace(' ','_')));
ToCreate.Image.SaveAs(filePath);
ToCreate.i_imgpath = filePath;
}

_entities.AddToitems(m);
_entities.SaveChanges();

}


The things to be more careful are

1). Using a correct version of Html.BeginForm function(see above) and
2). Input type file should have "id" and "name" same value as the name of your viewmodel property field for file upload.
3). Make sure you have given sufficient permissions to the Network service or IUser Account for the folders where images will be stored, this is a common problem after deployment to many developers.

Further one more thing to be kept in mind is that your master page also has a
tag which will cause the
tag of the content page to be bypassed, to overcome this problem, remove
tag from the master page.


hope you will find this post helpful.
wish you good luck with file uploading.

Friday, March 25, 2011

calling a Stored Procedure using Entity Framework

Any stored procedure can be called through EF. Create a SP and add it to your model. Further go to the model browser, right click the sp, and click add function import, here select your SP, and select what type it returns, if it returns nothing then select 'None'. If it returns a sclar type then select the type, and if its returning a recordset then select complex. Click on get column information, it will show you the colums returning. click on create new complex type. and click ok. If its returning one of you entities then click on option entity and select the entity type from the list box.

now you call call it in your code.

if its returning a complex type use code:

MyEntities _entities = new MyEntities();
var p = from d in _entities.GetOrderInfo() select d;


if its returning nothing then use code:

MyEntities _entities = new MyEntities();
_entities.Cancel_Sale(ucode, oid);

Friday, February 25, 2011

simple application using mvccontrib grid

download the mvccontrib.dll, and add the reference of this dll to your application.


write a controller function:

public ActionResult salesreport()
{
handsetviewmodel vm = new handsetviewmodel();
return View(vm);

}



view code:

include the following namespace:

<%@ Import Namespace="MvcContrib.UI.Grid" %>
<%@ Import Namespace="MvcContrib.UI.Grid.ActionSyntax" %>


write the following code to display the grid

<%: Html.Grid(Model.handsetstock()).Columns(column => {

column.For(c=>c.itemcode);
column.For(c => c.imeicsv);


})%>