如何将此代码从 ASP.NET 传输到 ASP.NET MVC 以打印水晶报表 [英] How to transfer this code from ASP.NET to ASP.NET MVC to print crystal reports

查看:16
本文介绍了如何将此代码从 ASP.NET 传输到 ASP.NET MVC 以打印水晶报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ASP.NET 应用程序和一些水晶报表,我需要从 ASP.NET 传输以下代码并在 MVC 中使用相同的功能,我正在使用实体框架.

这是我通过使用超链接和 NavigateUrl 将参数值发送到另一个表单的 form.aspx 代码:

<asp:GridView ID="GridView1";宽度=100%"CssClass="dynamicTable table-striped table-bordered table-condensed"样式=颜色:#000000;背景颜色:#f4eb3c"AutoGenerateColumns=假";runat=服务器"><列><asp:模板字段><HeaderTemplate>打印</HeaderTemplate><项目模板><div 样式=宽度:100%"><asp:HyperLink ID=HyperLink1"NavigateUrl='<%#"/RPT/WebForm1.aspx?order_id="+Eval(订单号")+&部门ID="+Eval(DEPTID")+&测试 ID="+Eval("Test Id")+"&Culture=";+Eval(文化")%>'runat=服务器">打印结果</asp:HyperLink></div></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>患者 MRN#</HeaderTemplate><项目模板><asp:标签 ID =LblTest";runat=服务器";Text='<%# Eval("Patient No") %>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>订单号</HeaderTemplate><项目模板><asp:标签 ID =LblTest";runat=服务器";text='<%#eval(<订单号>)%>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>患者姓名</HeaderTemplate><项目模板><asp:标签 ID =LblTest";runat=服务器";Text='<%# Eval("Patient Name") %>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>年龄</HeaderTemplate><项目模板><asp:标签 ID =LblTest";runat=服务器";Text='<%# Eval("AGE") %>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>请求日期</HeaderTemplate><项目模板><asp:标签 ID =LblTest";runat=服务器";Text='<%# Eval("收集日期") %>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>报告日期</HeaderTemplate><项目模板><asp:标签 ID =LblTest";runat=服务器";Text='<%# Eval("报告日期") %>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>测试名称</HeaderTemplate><项目模板><asp:标签 ID =LblTest";runat=服务器";Text='<%# Eval("Test_Name")%>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>结果</HeaderTemplate><项目模板><asp:标签 ID =LblTest";runat=服务器";Text='<%# Eval("Result") %>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>Ref.Range From</HeaderTemplate><项目模板><asp:Label ID =回流"runat=服务器";Text='<%# Eval("Low Range") %>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>到</HeaderTemplate><项目模板><asp:Label ID =回流"runat=服务器";Text='<%# Eval("High Range") %>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate>文本范围</HeaderTemplate><项目模板><asp:Label ID =回流"runat=服务器";Text='<%# Eval("Text Range") %>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><标头模板>请求.FORM NO.</HeaderTemplate><项目模板><asp:标签 ID =req";runat=服务器";Text='<%# Eval("REQ FORM NUMBER")%>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate></HeaderTemplate><项目模板><asp:标签 ID =LblTest";可见=假"runat=服务器";Text='<%# Eval("DEPTID") %>'></asp:Label></项目模板></asp:模板字段><asp:模板字段><HeaderTemplate></HeaderTemplate><项目模板><asp:标签 ID =LblTest";可见=假"runat=服务器";Text='<%# Eval("文化") %>'></asp:Label></项目模板></asp:模板字段></列><EmptyDataTemplate>未找到数据 - لم يتم العثور على بيانات</EmptyDataTemplate></asp:GridView>

这是 ASP.NET webform.aspx.cs 代码:

protected void Page_Load(object sender, EventArgs e){如果(!IsPostBack){TXTORDERID.Text = Request.QueryString[order_number"].ToString();TXTDEPTID.Text = Request.QueryString[DEPTID"].ToString();TXTTESTID.Text = Request.QueryString[Test_Id"].ToString();TXTCULTURE.Text = Request.QueryString[文化"].ToString();ReportDocument reportDocument = new ReportDocument();ParameterFields paramFields = new ParameterFields();ParameterField paramField = new ParameterField();ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();ParameterField parameterField1 = new ParameterField();ParameterDiscreteValue parameterDiscreteValue1 = new ParameterDiscreteValue();ParameterFields parameterFields = new ParameterFields();if (Convert.ToInt32(TXTDEPTID.Text) == 7 && Convert.ToInt32(TXTCULTURE.Text) == 1){TXTPOSITIVE.Text = Request.QueryString[正"].ToString();}if (Session["UserCustid"] != null && Convert.ToInt32(Session["UserCustid"]) > 0){if (Convert.ToInt32(TXTDEPTID.Text) == 1 || Convert.ToInt32(TXTDEPTID.Text) == 2 || Convert.ToInt32(TXTDEPTID.Text) == 3 || Convert.ToInt32(TXTDEPTID.Text) == 4){paramField.Name = "@ORDER_ID";paramDiscreteValue.Value = TXTORDERID.Text.ToString();paramField.CurrentValues.Add(paramDiscreteValue);参数字段.添加(参数字段);paramField = new ParameterField();//<-- 这行被添加参数离散值 = 新的参数离散值();//<-- 这行被添加paramField.Name = "@deptid";paramDiscreteValue1.Value = TXTDEPTID.Text.ToString();paramField.CurrentValues.Add(paramDiscreteValue1);参数字段.添加(参数字段);CrystalReportViewer1.ParameterFieldInfo = paramFields;CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;reportDocument.Load(Server.MapPath(~/RPT/RPT_RESULTS.rpt"));CrystalReportViewer1.ReportSource = 报告文档;reportDocument.SetDatabaseLogon(DBadmin", 1111");var connectionInfo = new ConnectionInfo();connectionInfo.ServerName = "DB";connectionInfo.DatabaseName = "DB";connectionInfo.Password = "1111";connectionInfo.UserID = "DBadmin";连接信息类型=连接信息类型.SQL;connectionInfo.IntegratedSecurity = false;for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++){CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;}}否则如果 (Convert.ToInt32(TXTDEPTID.Text) == 5){paramField.Name = "@Criteria";paramDiscreteValue.Value = TXTORDERID.Text.ToString();paramField.CurrentValues.Add(paramDiscreteValue);参数字段.添加(参数字段);paramField = new ParameterField();//<-- 这行被添加参数离散值 = 新的参数离散值();//<-- 这行被添加paramField.Name = "@TESTID";paramDiscreteValue1.Value = TXTDEPTID.Text.ToString();paramField.CurrentValues.Add(paramDiscreteValue1);参数字段.添加(参数字段);CrystalReportViewer1.ParameterFieldInfo = paramFields;CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;reportDocument.Load(Server.MapPath(~/RPT/RPT_HISTO_RESULT.rpt"));CrystalReportViewer1.ReportSource = 报告文档;reportDocument.SetDatabaseLogon(DBadmin", 1111");var connectionInfo = new ConnectionInfo();connectionInfo.ServerName = "DB";connectionInfo.DatabaseName = "DB";connectionInfo.Password = "1111";connectionInfo.UserID = "DBadmin";连接信息类型=连接信息类型.SQL;connectionInfo.IntegratedSecurity = false;for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++){CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;}}否则 if (Convert.ToInt32(TXTDEPTID.Text) == 6 && Convert.ToInt32(TXTTESTID.Text) == 1106){paramField.Name = "@Criteria";paramDiscreteValue.Value = TXTORDERID.Text.ToString();paramField.CurrentValues.Add(paramDiscreteValue);参数字段.添加(参数字段);CrystalReportViewer1.ParameterFieldInfo = paramFields;CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;reportDocument.Load(Server.MapPath("~/RPT/RPT_SEMEN_RESULT.rpt"));CrystalReportViewer1.ReportSource = 报告文档;reportDocument.SetDatabaseLogon(DBadmin", 1111");var connectionInfo = new ConnectionInfo();connectionInfo.ServerName = "DB";connectionInfo.DatabaseName = "DB";connectionInfo.Password = "1111";connectionInfo.UserID = "DBadmin";连接信息类型=连接信息类型.SQL;connectionInfo.IntegratedSecurity = false;for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++){CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;}}

在 ASP.NET MVC 中:

1- 我创建了一个 webform.aspx.cs 并在 MVC 项目中使用了上面相同的代码

2- 我创建了控制器代码和视图这是视图代码:

<div id=hemadiv">@if (labhema1 != null && labhema1.Report_Date.HasValue){<img 宽度=700";高度=200"src=~/Contents/images/aljawdahlogo.png"/><a href="/RPT/WebForm1.aspx/@LABCASHVIEW.FirstOrDefault().order_number">打印结果</a><table class=table table-bordered"><tr><td 样式=文本对齐:居中"><输入类型=提交"value=血液学结果"onclick=PrintElemhema('#hemadiv')";类=btn btn-primary";/></td></tr></表>

<dl 类=水平"样式=填充:10px"><dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Patient_Name)</dt><dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Patient_Name)</dd><dt style="width: 22%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Customer_Name)</dt><dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Customer_Name)</dd><dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Patient_No)</dt><dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Patient_No)</dd><dt style="width: 22%;display: inline-block;margin-left:0px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Collection_Date)</dt><dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Collection_Date)</dd><dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().SEX)</dt><dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().SEX)</dd><dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Receiving_Date)</dt><dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Receiving_Date)</dd><dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().AGE)</dt><dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().AGE)</dd><dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Report_Date)</dt><dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Report_Date)</dd><dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().order_number)</dt><dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().order_number)</dd></dl></div><div class=选项卡窗格容器活动";id=hemadiv">@*
血液科
*@<table class="table-table-bordered";单元格填充=5";单元格间距=5";><头><tr>@*<th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Patient_No)</th><th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Patient_Name)</th>*@<th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Test_Name)</th><th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Result)</th><th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Low_Range)</th><th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().High_Range)</th><th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Text_Range)</th>@*<th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Report_Date)</th>*@</tr></头>@foreach(Model.labCashView.Where(x => hema.Contains(x.DEPTID.GetValueOrDefault())) 中的 var 员工){<tr>@*<td>@employee.Patient_No</td><td>@employee.Patient_Name</td>*@<td>@employee.Test_Name</td><td>@employee.Result</td><td>@employee.Low_Range</td><td>@employee.High_Range</td><td>@employee.Text_Range</td>@*<td>@employee.Report_Date</td>*@</tr>}</表></div>}

3- 这是控制器代码:

public ActionResult CashData(int id){var 表 = 新 Orders_Tables{测试范围 = db.TestsRanges.ToList(),LabResults = db.LAB_RESULTS.Where(o => o.ORDER_ID == id).Include(p => p.LabTests).Include(t => t.Patients).ToList(),LabParaResult = db.LAB_PARA_RESULTS.Where(o => o.ORDER_ID == id).Include(t =>t.Patients).Include(t =>t.LabTests).Include(c =>c.客户).ToList(),LabCultureResults = db.LAB_CULTURE_RESULT.Where(o => o.ORDER_ID == id).Include(t => t.Patients).Include(t => t.LabTests).Include(c => c.客户).ToList(),LabMicroResults = db.LAB_MICRO_NEGATIVE_RESULT.Where(o => o.ORDER_ID == id).ToList(),labCashView = db.LAB_RESULT_CASH_VIEW.Where(o => o.order_number == id).ToList(),LabParasitologyView = db.LAB_PARASITOLOGY_VIEW.Where(o => o.order_number == id).ToList(),LabCulturesView = db.LAB_CULTURES_VIEW.Where(o => o.ORDER_ID == id).ToList(),LabMicroView = db.LAB_MICRO_VIEW.Where(o => o.ORDER_ID == id).ToList(),LabHistopathologyView = db.LAB_HISTOPATHOLOGY_VIEW.Where(o => o.ORDER_ID == id).ToList(),LabHistoResult = db.LAB_HISTO_RESULT.Where(o => o.ORDER_ID == id).ToList(),labtests = db.LabTests.ToList(),//患者 = db.Patients.ToList()};

4- 我创建了 LABCASHVIEW 类

我在 stackoverflow 网站上查看了很多文章,他写的一个答案是你可以在 ASP.NET MVC 中使用来自 ASP.NET 的相同设计

  • 在您的 MVC 项目中创建 webform 并将参数从 MVC 传递到 webform,然后它将像 ASP.NET 一样工作并打印水晶报告.所以我照他说的做了,但现在我需要最后一步,如何将以下参数从 MVC 视图传递到 webform 并打印水晶报告:

我需要将选中的 order_number 、 dept_Id 、 Test_Id 和culture 参数从选中的行发送到webform 并打印水晶报告我用了<a> 标签和 href="到

<a href="/RPT/WebForm1.aspx/@LABCASHVIEW.FirstOrDefault().order_number"></a>

但是如何将所有这些参数一次性传递给webform并避免错误引用对象未设置为对象实例并首先检查参数是否不为空?

这是问答,但没有详细说明如何调用水晶报表以及如何将多个参数传递给水晶报表,例如,如果我需要打印选定的 order_id 或选定的发票:

https://stackoverflow.com/questions/348785/crystal-reports-in-asp-net-mvc

更新:

我在 webform.aspx.cs 中为这些文本框提供了静态值
以及现在的印刷:

 TXTORDERID.Text = 2000000054";TXTDEPTID.Text = "1";TXTTESTID.Text = "46";TXTCULTURE.Text = "2";

现在最后一个问题是如何从 MVC 视图中发送 webform 中这些文本框的值,如下所示:

TXTORDERID.Text = Request.QueryString["labCashView.order_number"].ToString();TXTDEPTID.Text = Request.QueryString[labCashView.DEPTID"].ToString();TXTTESTID.Text = Request.QueryString[labCashView.Test_Id"].ToString();TXTCULTURE.Text = Request.QueryString[labCashView.Culture"].ToString();

解决方案

我看到你完成了一切,你需要将参数从视图传递到水晶报表,试试这个解决方案:

<a href="/RPT/WebForm1.aspx/?order_number=@Model.labCashView.FirstOrDefault().order_number&deptid=@Model.labCashView.FirstOrDefault().DEPTID&testid=@Model.labCashView.FirstOrDefault().Test_Id&Culture=@Model.labCashView.FirstOrDefault().Culture">打印结果</a>

然后在 webform.aspx.cs 中编写以下代码并使用从链接传递的值:

TXTORDERID.Text = Request.QueryString["order_number"].ToString();TXTDEPTID.Text = Request.QueryString[deptid"].ToString();TXTTESTID.Text = Request.QueryString[testid"].ToString();TXTCULTURE.Text = Request.QueryString[文化"].ToString();

希望这将帮助您并在您的 MVC 视图中打印水晶报告.

I have ASP.NET application and some crystal reports and I need to transfer the following code from ASP.NET and use same functionality in MVC , I am using entity framework.

this is the form.aspx code which i send the parameters value to the other form by using hyperlink and NavigateUrl:

<asp:GridView ID="GridView1"  Width="100%" CssClass="dynamicTable table  table-striped table-bordered table-condensed"  style="color:#000000;background-color:#f4eb3c  " AutoGenerateColumns="false"  runat="server">
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate>Print</HeaderTemplate>
                    <ItemTemplate>
                        <div style="width:100%"> <asp:HyperLink ID="HyperLink1"  NavigateUrl='<%#"/RPT/WebForm1.aspx?order_id=" +Eval("order number")+"&DEPT ID=" +Eval("DEPTID")+"&Test Id=" +Eval("Test Id")+"&Culture=" +Eval("Culture")%>' runat="server">Print Result</asp:HyperLink></div>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>Patient MRN#</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LblTest" runat="server" Text='<%# Eval("Patient No") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>Order Number</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LblTest" runat="server" Text='<%# Eval("order number") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>Patient Name</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LblTest" runat="server" Text='<%# Eval("Patient Name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>AGE</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LblTest" runat="server" Text='<%# Eval("AGE") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>Request Date</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LblTest" runat="server" Text='<%# Eval("Collection Date") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate>Report Date</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LblTest" runat="server" Text='<%# Eval("Report Date") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                
                 <asp:TemplateField>
                    <HeaderTemplate>Test Name</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LblTest" runat="server" Text='<%# Eval("Test_Name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
               
                <asp:TemplateField>
                    <HeaderTemplate>Result</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LblTest" runat="server" Text='<%# Eval("Result") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField>
                    <HeaderTemplate>Ref.Range From</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Reflow" runat="server" Text='<%# Eval("Low Range") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField>
                    <HeaderTemplate>To</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Reflow" runat="server" Text='<%# Eval("High Range") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField>
                    <HeaderTemplate>Text Range</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Reflow" runat="server" Text='<%# Eval("Text Range") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField>
                    <HeaderTemplate>REQ. FORM NO.</HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="req" runat="server" Text='<%# Eval("REQ FORM NUMBER") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate></HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LblTest" Visible="false" runat="server" Text='<%# Eval("DEPTID") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <HeaderTemplate></HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LblTest" Visible="false" runat="server" Text='<%# Eval("Culture") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                
            </Columns>
            <EmptyDataTemplate>No Data Found   -    لم يتم العثور على بيانات</EmptyDataTemplate>
        </asp:GridView>

This is the ASP.NET webform.aspx.cs code :

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            TXTORDERID.Text = Request.QueryString["order_number"].ToString();
            TXTDEPTID.Text = Request.QueryString["DEPTID"].ToString();
            TXTTESTID.Text = Request.QueryString["Test_Id"].ToString();
            TXTCULTURE.Text = Request.QueryString["Culture"].ToString();
            ReportDocument reportDocument = new ReportDocument();
            ParameterFields paramFields = new ParameterFields();
            ParameterField paramField = new ParameterField();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
            ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
            ParameterField parameterField1 = new ParameterField();
            ParameterDiscreteValue parameterDiscreteValue1 = new ParameterDiscreteValue();
            ParameterFields parameterFields = new ParameterFields();


            if (Convert.ToInt32(TXTDEPTID.Text) == 7 && Convert.ToInt32(TXTCULTURE.Text) == 1)
            {
                TXTPOSITIVE.Text = Request.QueryString["Positive"].ToString();
            }
            if (Session["UserCustid"] != null && Convert.ToInt32(Session["UserCustid"]) > 0)
            {
                if (Convert.ToInt32(TXTDEPTID.Text) == 1 || Convert.ToInt32(TXTDEPTID.Text) == 2 || Convert.ToInt32(TXTDEPTID.Text) == 3 || Convert.ToInt32(TXTDEPTID.Text) == 4)
                {

                    paramField.Name = "@ORDER_ID";
                    paramDiscreteValue.Value = TXTORDERID.Text.ToString();
                    paramField.CurrentValues.Add(paramDiscreteValue);
                    paramFields.Add(paramField);

                    paramField = new ParameterField(); // <-- This line is added
                    paramDiscreteValue = new ParameterDiscreteValue();  // <-- This line is added
                    paramField.Name = "@deptid";
                    paramDiscreteValue1.Value = TXTDEPTID.Text.ToString();
                    paramField.CurrentValues.Add(paramDiscreteValue1);
                    paramFields.Add(paramField);

                    CrystalReportViewer1.ParameterFieldInfo = paramFields;
                    CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
                    CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
                    reportDocument.Load(Server.MapPath("~/RPT/RPT_RESULTS.rpt"));
                    CrystalReportViewer1.ReportSource = reportDocument;
                    reportDocument.SetDatabaseLogon("DBadmin", "1111");
                    var connectionInfo = new ConnectionInfo();
                    connectionInfo.ServerName = "DB";
                    connectionInfo.DatabaseName = "DB";
                    connectionInfo.Password = "1111";
                    connectionInfo.UserID = "DBadmin";
                    connectionInfo.Type = ConnectionInfoType.SQL;
                    connectionInfo.IntegratedSecurity = false;
                    for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
                    {
                        CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
                    }
                }

                else if (Convert.ToInt32(TXTDEPTID.Text) == 5)
                {

                    paramField.Name = "@Criteria";
                    paramDiscreteValue.Value = TXTORDERID.Text.ToString();
                    paramField.CurrentValues.Add(paramDiscreteValue);
                    paramFields.Add(paramField);

                    paramField = new ParameterField(); // <-- This line is added
                    paramDiscreteValue = new ParameterDiscreteValue();  // <-- This line is added
                    paramField.Name = "@TESTID";
                    paramDiscreteValue1.Value = TXTDEPTID.Text.ToString();
                    paramField.CurrentValues.Add(paramDiscreteValue1);
                    paramFields.Add(paramField);

                    CrystalReportViewer1.ParameterFieldInfo = paramFields;
                    CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
                    CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
                    reportDocument.Load(Server.MapPath("~/RPT/RPT_HISTO_RESULT.rpt"));
                    CrystalReportViewer1.ReportSource = reportDocument;
                    reportDocument.SetDatabaseLogon("DBadmin", "1111");
                    var connectionInfo = new ConnectionInfo();
                    connectionInfo.ServerName = "DB";
                    connectionInfo.DatabaseName = "DB";
                    connectionInfo.Password = "1111";
                    connectionInfo.UserID = "DBadmin";
                    connectionInfo.Type = ConnectionInfoType.SQL;
                    connectionInfo.IntegratedSecurity = false;
                    for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
                    {
                        CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
                    }
                }
                else if (Convert.ToInt32(TXTDEPTID.Text) == 6 && Convert.ToInt32(TXTTESTID.Text) == 1106)
                {
                    paramField.Name = "@Criteria";
                    paramDiscreteValue.Value = TXTORDERID.Text.ToString();
                    paramField.CurrentValues.Add(paramDiscreteValue);
                    paramFields.Add(paramField);

                    

                    CrystalReportViewer1.ParameterFieldInfo = paramFields;
                    CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
                    reportDocument.Load(Server.MapPath("~/RPT/RPT_SEMEN_RESULT.rpt"));
                    CrystalReportViewer1.ReportSource = reportDocument;
                    reportDocument.SetDatabaseLogon("DBadmin", "1111");
                    var connectionInfo = new ConnectionInfo();
                    connectionInfo.ServerName = "DB";
                    connectionInfo.DatabaseName = "DB";
                    connectionInfo.Password = "1111";
                    connectionInfo.UserID = "DBadmin";
                    connectionInfo.Type = ConnectionInfoType.SQL;
                    connectionInfo.IntegratedSecurity = false;
                    for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
                    {
                        CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
                    }
                }

IN ASP.NET MVC :

1- I created a webform.aspx.cs and used same code above in MVC project

2- I created the controller code and view this is the view code :

<div id="hemadiv">
        @if (labhema1 != null && labhema1.Report_Date.HasValue)
        {
            <img width="700" height="200" src="~/Contents/images/aljawdahlogo.png" />
            <a href="/RPT/WebForm1.aspx/@LABCASHVIEW.FirstOrDefault().order_number">Print Result</a>
            <table class="table table-bordered">
                <tr>
                    <td style="text-align:center">
                        <input type="submit" value="Heamatology Result " onclick="PrintElemhema('#hemadiv')" class="btn btn-primary" />
                    </td>
                </tr>
            </table>
            <div>
                <dl class="horizontal" style="padding:10px">
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Patient_Name)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Patient_Name)</dd>
                    <dt style="width: 22%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Customer_Name)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Customer_Name)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Patient_No)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Patient_No)</dd>
                    <dt style="width: 22%;display: inline-block;margin-left:0px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Collection_Date)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Collection_Date)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().SEX)</dt>
                    <dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().SEX)</dd>
                    <dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Receiving_Date)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Receiving_Date)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().AGE)</dt>
                    <dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().AGE)</dd>
                    <dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().Report_Date)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().Report_Date)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.FirstOrDefault().order_number)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labCashView.FirstOrDefault().order_number)</dd>
                </dl>
            </div>
            <div class="tab-pane container active" id="hemadiv">


                @*<h5 class="text-uppercase p-2 text-center">Hematology Department</h5>*@
                <table class="table table-bordered" cellpadding="5" cellspacing="5" >
                    <thead>
                        <tr>
                            @*<th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Patient_No)</th>
                                <th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Patient_Name)</th>*@
                            <th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Test_Name)</th>
                            <th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Result)</th>
                            <th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Low_Range)</th>
                            <th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().High_Range)</th>
                            <th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Text_Range)</th>
                            @*<th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Report_Date)</th>*@


                        </tr>
                    </thead>
                    @foreach (var employee in Model.labCashView.Where(x => hema.Contains(x.DEPTID.GetValueOrDefault())))
                    {
                        <tr>
                            @*<td>@employee.Patient_No</td>
                                <td>@employee.Patient_Name</td>*@
                            <td>@employee.Test_Name</td>
                            <td>@employee.Result</td>
                            <td>@employee.Low_Range</td>
                            <td>@employee.High_Range</td>
                            <td>@employee.Text_Range</td>
                            @*<td>@employee.Report_Date</td>*@


                        </tr>
                    }
                </table>
            </div>

        }

3- this is the controller code :

public ActionResult CashData(int id)
        {
            
            var tables = new Orders_Tables
            {
                testsRanges = db.TestsRanges.ToList(),

                LabResults = db.LAB_RESULTS.Where(o => o.ORDER_ID == id)
                             .Include(p => p.LabTests)
                             .Include(t => t.Patients).ToList(),
       
                
                LabParaResult = db.LAB_PARA_RESULTS.Where(o => o.ORDER_ID == id).Include(t => t.Patients).Include(t => t.LabTests).Include(c => c.Customers).ToList(),
                LabCultureResults = db.LAB_CULTURE_RESULT.Where(o => o.ORDER_ID == id).Include(t => t.Patients).Include(t => t.LabTests).Include(c => c.Customers).ToList(),
                LabMicroResults = db.LAB_MICRO_NEGATIVE_RESULT.Where(o => o.ORDER_ID == id).ToList(),
                labCashView = db.LAB_RESULT_CASH_VIEW.Where(o => o.order_number == id).ToList(),
                LabParasitologyView = db.LAB_PARASITOLOGY_VIEW.Where(o => o.order_number == id).ToList(),
                LabCulturesView = db.LAB_CULTURES_VIEW.Where(o => o.ORDER_ID == id).ToList(),
                LabMicroView = db.LAB_MICRO_VIEW.Where(o => o.ORDER_ID == id).ToList(),
                LabHistopathologyView = db.LAB_HISTOPATHOLOGY_VIEW.Where(o => o.ORDER_ID == id).ToList(),
                LabHistoResult = db.LAB_HISTO_RESULT.Where(o => o.ORDER_ID == id).ToList(),
                labtests = db.LabTests.ToList(),
               // patients = db.Patients.ToList()
            };

4- i created the class LABCASHVIEW

I checked alot of articles in stackoverflow site and one answer just he wrote you can use same design from ASP.NET in ASP.NET MVC

  • create webform in your MVC project and pass the parameters from MVC to webform then it will work and print crystal reports as same as ASP.NET . So I did what he said but now I need the final step , How to pass the following parameters from MVC view to webform and print crystal reports :

I need to send the selected order_number , dept_Id , Test_Id and culture parameters from selected row to webform and print crystal report I used <a> tag and href="" to

<a href="/RPT/WebForm1.aspx/@LABCASHVIEW.FirstOrDefault().order_number"></a>

but how to pass all this parameter one time to webform and avoid the error reference object not set to an instance of an object and check if parameters not null first ?

this is the question and answer but no details how to call crystal reports and how to pass multiple parameters to crystal report , for example if i need to print selected order_id or selected invoice :

https://stackoverflow.com/questions/348785/crystal-reports-in-asp-net-mvc

UPDATE :

I gave static values for these textboxes in webform.aspx.cs
and its printing now :

            TXTORDERID.Text = "2000000054";
            TXTDEPTID.Text = "1";
            TXTTESTID.Text = "46";
            TXTCULTURE.Text = "2";

now final issue how to send the value for these text boxes in webform from MVC view as the following :

TXTORDERID.Text = Request.QueryString["labCashView.order_number"].ToString();
 TXTDEPTID.Text = Request.QueryString["labCashView.DEPTID"].ToString();
 TXTTESTID.Text = Request.QueryString["labCashView.Test_Id"].ToString();
 TXTCULTURE.Text = Request.QueryString["labCashView.Culture"].ToString();

解决方案

As I see you completed everything and you need to pass parameters from View to crystal reports try this solution :

<a href="/RPT/WebForm1.aspx/?order_number=@Model.labCashView.FirstOrDefault().order_number&deptid=@Model.labCashView.FirstOrDefault().DEPTID&testid=@Model.labCashView.FirstOrDefault().Test_Id&Culture=@Model.labCashView.FirstOrDefault().Culture">Print Result</a>

Then in webform.aspx.cs write the following code and use the value passed from the link :

TXTORDERID.Text = Request.QueryString["order_number"].ToString();
            TXTDEPTID.Text = Request.QueryString["deptid"].ToString();
            TXTTESTID.Text = Request.QueryString["testid"].ToString();
            TXTCULTURE.Text = Request.QueryString["Culture"].ToString(); 

Hope this will help you and print crystal reports in your MVC view.

这篇关于如何将此代码从 ASP.NET 传输到 ASP.NET MVC 以打印水晶报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆