Tuesday, February 23, 2016
Select All checkbox using Knockout JS
Normal SelectAll CheckBoxes using Knockout
// Select All checkbox
self.SelectedAllPermissions = ko.computed({
read: function () {
var item = ko.utils.arrayFirst(self.SecurityPagesListArray(), function (item) {
return !item.SelectedPage();
});
return item == null;
},
write: function (value) {
ko.utils.arrayForEach(self.SecurityPagesListArray(), function (permission) {
permission.SelectedPage(value);
});
}
});
--------------------------------------------------------------------------------
Select All Checkbox from One Array to Another
// Select All checkbox
self.SelectedAllPermissions= ko.computed({
read: function () {
return self.selectedBooks().length === self.filterBooks().length;
},
write: function (value) {
self.selectedBooks(value ? self.filterBooks().slice(0) : []);
},
owner: self
});
<input style="margin-left:10px;width:20px;height:20px;" class="pull-left" type="checkbox" data-bind="checked: SelectedAllPermissions" />
Thursday, February 18, 2016
jQuery Datatable Reset Search and Filters
jQuery Datatable Reset Search and Filters. This post talks you about the Datatable filters. Here we are going to reset the search operation in the middle of search results. get the whole results. This will work on server side as well. The following code helps you to do that operation. It will work on individual column search’s as well.
Here the following code helps us to create a datatable from html table .
you can add the following code to a button, there before create a rest button and get its click action.
$(document).on('click', '.SaveButton', function (e) {
var table = $closestform.find('table').DataTable();
table.search('').columns().search('').draw();
}
That’s it. It will take care the reset operation. When you want to reset a search operation, just use the above function to get it.
Wednesday, February 17, 2016
Windows visual diff and merge for files and directories
WinMerge
Description
WinMerge is a Windows tool for visual difference display and merging, for both files and directories. It is highly useful for determining what has changed between file versions, and then merging those changes. WinMerge has Unicode support, Flexible syntax coloring editor, Visual SourceSafe integration, and Windows Shell integration. Regexp filtering for filenames and lines. Side-by-side line difference and highlights differences inside lines. A file map shows the overall file differences in a location pane. The user interface is translated into several languages.
Features
- Visual differencing and merging of text files
- Flexible editor with syntax highlighting, line numbers and word-wrap
- Highlights differences inside lines
- Difference pane shows current difference in two vertical panes
- Location pane shows map of files compared
- Moved lines detection
- Compare folders in one level or recursive
- Can show folder compare results flat or in a tree-style view
- Regular Expression based file filters allow excluding and including items
- Compares binary files in folder compare as well as text files
- Shell Integration (supports 64-bit Windows versions)
- Archive file support using 7-Zip
- Fast compare using file sizes and dates
- Creates patch files (Normal-, Context- and Unified formats)
Download URL:
https://sourceforge.net/projects/winmerge/?source=typ_redirect
Tuesday, February 16, 2016
Select2 dropdown with allow new values by user
I used the code below I am using Version: 3.4.5 of select2.
$('.location_select').select2({
ajax: {
url: location_url,
dataType: 'json',
quietMillis: 100,
data: function (term) {
return {
term: term
};
},
results: function (data) {
results = [];
$.each(data, function(index, item){
results.push({
id: item.location_id,
text: item.location_name
});
});
return {
results: results
};
}
},
//Allow manually entered text in drop down.
createSearchChoice:function(term, results) {
if ($(results).filter( function() {
return term.localeCompare(this.text)===0;
}).length===0) {
return {id:term, text:term + ' [New]'};
}
},
});
reference :
http://stackoverflow.com/questions/14577014/select2-dropdown-but-allow-new-values-by-user
Monday, February 15, 2016
How to access session variable in SSRS (SQL Server 2012)?
I want to access the session or viewstate variables in
SSRS 2012 reports just like we access in c#.Session["user"]
I want to access like this in
SSRS report.
I want to include the user who is logged in when the report is generated.
Is there any way to achieve this? Can we access it in custom code in
SSRS?
In the code behind, you could copy the desired data at a report parameter.
// Copy the session username to a report param called "CurrentUser".
ReportParameter userParam = new ReportParameter("CurrentUser", Session["user"]);
// add the parameter to the report
reportViewer.ServerReport.SetParameters(new ReportParameter[] { userParam });
And then add your parameter to the report as you would any other parameter. See example at:http://msdn.microsoft.com/en-us/library/aa337091.aspx
How to display Arabic numbers in RDLC reports?
I want to display Arabic number in my report.
I tried to set the
Language property to ar but it's not working. also tried a lot of things but none of them are working :(
Any idea how to make it?
Try setting the NumeralVariant property of the TextBox to "3". You also need an Arabic language installed on your operating system.
Sunday, February 14, 2016
SSRS: How to Repeat Headers on Each Page
reference :
http://social.technet.microsoft.com/wiki/contents/articles/19398.ssrs-how-to-repeat-headers-on-each-page.aspx
http://social.technet.microsoft.com/wiki/contents/articles/19398.ssrs-how-to-repeat-headers-on-each-page.aspx
SSRS: How to Repeat Headers on Each Page
This article shows an example of how to repeat headers on each page of SSRS report .
Consider this code block is my dataset query from AdventureWorks database:
Drag and drop Table from Toolbox - > ReportItems on to the body of the report under Design pane and assign the columns from Dataset to the Table .

If we click on Preview pane , we will notice report data gets displayed into three pages with no headers on all pages except the first page .

So to repeat headers on all pages :
Under Design Pane - > at the bottom Column Groups - > click on drop down (down arrow) - > Advanced Mode .

Once we selected Advanced Mode, we will be able to notice (static) in Row Groups and Column Groups at the bottom of Design pane .

Under Design Pane - > Row Groups - > click on (static) - > Press F4 - > Properties window will pop-up.
In the Properties window - >Set KeepWithGroup = After and RepeatOnNewPage = True.
If you want header to be frozen while scrolling down the report, set FixedData = True.

Now click on Preview pane and check all the pages for headers and scroll-down to check the fixed header.

Reference - http://technet.microsoft.com/en-us/library/dd207045.aspx
http://technet.microsoft.com/en-us/library/dd220509.aspx
Consider this code block is my dataset query from AdventureWorks database:
SELECT TOP 100 BusinessEntityID,JobTitle,Gender FROM [HumanResources].[Employee]Drag and drop Table from Toolbox - > ReportItems on to the body of the report under Design pane and assign the columns from Dataset to the Table .
If we click on Preview pane , we will notice report data gets displayed into three pages with no headers on all pages except the first page .
So to repeat headers on all pages :
Under Design Pane - > at the bottom Column Groups - > click on drop down (down arrow) - > Advanced Mode .
Once we selected Advanced Mode, we will be able to notice (static) in Row Groups and Column Groups at the bottom of Design pane .
Under Design Pane - > Row Groups - > click on (static) - > Press F4 - > Properties window will pop-up.
In the Properties window - >Set KeepWithGroup = After and RepeatOnNewPage = True.
If you want header to be frozen while scrolling down the report, set FixedData = True.
Now click on Preview pane and check all the pages for headers and scroll-down to check the fixed header.
Reference - http://technet.microsoft.com/en-us/library/dd207045.aspx
http://technet.microsoft.com/en-us/library/dd220509.aspx
Thursday, February 11, 2016
Access web project file path from another project (Service or Business Layer)
Access web project file path from another project (Service or Business Layer)
var appDomain = System.AppDomain.CurrentDomain;
var fullPath = Path.Combine(appDomain.BaseDirectory, Resources.DynamicTabFilePath);
Views\Shared\DynamicTabs\
Wednesday, February 10, 2016
How to call report in MVC Report.aspx with custom print button
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportPage.aspx.cs" Inherits="UI.Report.ReportPage" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<html>
<head id="Head1" runat="server">
<script src="Content/js/bootstrap.js"></script>
<script src="Content/js/jquery.min.js"></script>
<title>View Report</title>
</head>
<style type="text/css">
html, body, form {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
font-family: Verdana, Tahoma, Arial;
font-size: small;
}
.spinner {
position: fixed;
top: 50%;
left: 50%;
margin-left: -50px; /* half width of the spinner gif */
margin-top: -50px; /* half height of the spinner gif */
text-align: center;
z-index: 1234;
overflow: auto;
width: 150px; /* width of the spinner gif */
height: 62px; /*height of the spinner gif +2px to fix IE8 issue */
background-color: #E1E1D7;
border: 1px solid black;
}
.HighlightDiv img {
background-color: transparent;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: transparent;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
cursor: default;
}
.HighlightDiv:hover img {
background-color: #DDEEF7;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #336699;
border-right-color: #336699;
border-bottom-color: #336699;
border-left-color: #336699;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
cursor: pointer;
}
.dirRTL{
direction:rtl;
}
</style>
<body >
<form id="frmReportViewer" runat="server">
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true"
EnablePartialRendering="true" runat="server">
</asp:ScriptManager>
<div id="divMain">
<rsweb:ReportViewer ID="TransportationReportViewer" runat="server" ProcessingMode="Remote" Height="700px" CssClass="dirRTL"
Width="1024px" >
</rsweb:ReportViewer>
<iframe id="frmPrint" name="frmPrint" runat="server" style="display: none"></iframe>
</div>
<div id="spinner" class="spinner" style="display: none;">
<table align="center" valign="middle" style="height: 100%; width: 100%">
<tr>
<td>
<img id="img-spinner" src="../Content/img/InProgess.gif" alt="Printing" /></td>
<td><span style="font-family: Verdana; font-weight: bold; font-size: 10pt; width: 86px;">Printing...</span></td>
</tr>
</table>
</div>
</form>
<script type="text/javascript">
$(document).ready(function () {
$("#spinner").bind("ajaxSend", function () {
$(this).show();
}).bind("ajaxStop", function () {
$(this).hide();
}).bind("ajaxError", function () {
$(this).hide();
});
//$(function () {
// showDatePicker();
//});
$(function () {
showPrintButton();
});
});
//$("#TransportationReportViewer_ctl04_ctl00").click(function () {
// // window.setTimeout("printPDF(this);", 3000);
// alert('riyad');
// window.setTimeout("showPrintButton();", 1000);
//});
$(document).on("click", "#TransportationReportViewer_ctl04_ctl00", function () {
$("#TransportationReportViewer_ctl04_ctl00").attr('value', 'طباعة الطلب');
window.setTimeout("showPrintButton();", 1000);
});
$("#TransportationReportViewer_ctl04_ctl00").attr('value', 'طباعة الطلب');
function showDatePicker() {
var parameterRow = $("#ParametersRowrvREXReport");
var innerTable = $(parameterRow).find("table").find("table");
var span = innerTable.find("span:contains('From Date (dd/mm/yyyy):')");
if (span) {
var innerRow = $(span).parent().parent();
var innerCell = innerRow.find("td").eq(1);
var textFrom = innerCell.find("input[type=text]");
innerCell = innerRow.find("td").eq(4);
var textTo = innerCell.find("input[type=text]");
$(textFrom).datepicker({
defaultDate: "+1w",
dateFormat: 'dd/mm/yy',
changeMonth: true,
numberOfMonths: 1,
onClose: function (selectedDate) {
$(textTo).datepicker("option", "minDate", selectedDate);
}
});
$(textFrom).focus(function (e) {
e.preventDefault();
$(textFrom).datepicker("show");
});
$(textTo).datepicker({
defaultDate: "+1w",
dateFormat: 'dd/mm/yy',
changeMonth: true,
numberOfMonths: 1,
onClose: function (selectedDate) {
$(textFrom).datepicker("option", "maxDate", selectedDate);
}
});
$(textTo).focus(function () {
$(textTo).datepicker("show");
});
}
}
//Function that is called on Successful AJAX method call. These are referenced in the "CallServerMethodBeforePrint" function that is created from code behind and will exist in the final rendering of the page.
function ServerCallSucceeded(result, context) {
var iFrameURL = "<%=iFrameURL%>";
window.frames['frmPrint'].document.location.href = iFrameURL;
window.frames['frmPrint'].focus();
var timeout = window.setTimeout("window.frames[\"frmPrint\"].focus();window.frames[\"frmPrint\"].print();", 500);
window.setTimeout("ServerCallAfterPrint(this)", 2000);
}
function ServerCallSucceededAfterPrint(result, context) {
}
//Function that is called on failure or error in AJAX method call. These are referenced in the "CallServerMethodBeforePrint" function that is created from code behind and will exist in the final rendering of the page.
function ServerCallFailed(result, context) {
}
function ServerCallBeforePrint(btn) {
$('#spinner').show();
var context = new Object();
//example of passing multiple args
context.flag = new Array('1');
//This "CallServerMethodBeforePrint" function is created from code behind and will exist in the final rendering of the page
CallServerMethodBeforePrint(context.flag, context);
}
function ServerCallAfterPrint(btn) {
var context = new Object();
//example of passing multiple args
context.flag = new Array('2');
//This "CallServerAfterPrint" function is created from code behind and will exist in the final rendering of the page
CallServerAfterPrint(context.flag, context);
$('#spinner').hide();
}
function printPDF(btn) {
ServerCallBeforePrint(btn);
}
function showPrintButton() {
var table = $("table[title='Refresh']");
var parentTable = $(table).parents('table');
var parentDiv = $(parentTable).parents('div').parents('div').first();
var btnPrint = $("<input type='button' id='btnPrint' name='btnPrint' value='Print' style=\"font-family:Verdana;font-size:8pt;width:86px\"/>");
var btnClose = $("<input type='button' id='btnClose' name='btnClose'value='Close' style=\"font-family:Verdana;font-size:8pt;width:86px\"/>");
btnPrint.click(function () {
printPDF(this);
});
btnClose.click(function () {
window.close();
});
if (parentDiv.find("input[value='Print']").length == 0) {
parentDiv.append('<table cellpadding="0" cellspacing="0" toolbarspacer="true" style="display:inline-block;width:6px;"><tbody><tr><td></td></tr></tbody></table>');
parentDiv.append('<div id="customDiv" class=" " style="display:inline-block;font-family:Verdana;font-size:8pt;vertical-align:inherit;"><table cellpadding="0" cellspacing="0"><tbody><tr><td><span style="cursor:pointer;" class="HighlightDiv" onclick="javascript:printPDF(this);" ><img src="../Content/img/Print.png" alt="Print Report" title="Print Report" width="18px" height="18px" style="margin-top:4px"/></span></td></tr></tbody></table></div>');
parentDiv.append('<table cellpadding="0" cellspacing="0" toolbarspacer="true" style="display:inline-block;width:10px;"><tbody><tr><td></td></tr></tbody></table>');
parentDiv.append('<div id="customDiv" class=" " style="display:inline-block;font-family:Verdana;font-size:8pt;vertical-align:inherit;"><table cellpadding="0" cellspacing="0" style="display:inline;"><tbody><tr><td><span style="cursor:pointer;" class="HighlightDiv" onclick="javascript:window.close();"></span></td></tr></tbody></table></div>');
}
}
function cfnReportsViewer_ViewReport(selectedTreeKeyGuidValue, ReportName, VenueExamCounter) {
var windowWidth = 1000;
var windowHeight = 800;
var left = (screen.width / 2) - (windowWidth / 2);
var top = (screen.height / 2) - (windowHeight / 2);
var myForm = document.getElementById("frmReportViewer");
if (myForm) {
myForm.target = "PopupReport";
}
$("#hfAccessObjectGuid").val(selectedTreeKeyGuidValue);
$("#hfReportName").val(ReportName);
$("#hfVenueExamCounter").val(VenueExamCounter);
var thePopup = window.open("about:blank", "PopupReport", 'scrollbars=yes,status=yes,toolbar=yes,menubar=no,location=no,resizable=no,fullscreen=yes, width=' + windowWidth + ', height=' + windowHeight + ', top=' + top + ', left=' + left);
window.setTimeout(document.getElementById("frmReportViewer").submit(), 500);
return false;
}
</script>
</body>
</html>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<html>
<head id="Head1" runat="server">
<script src="Content/js/bootstrap.js"></script>
<script src="Content/js/jquery.min.js"></script>
<title>View Report</title>
</head>
<style type="text/css">
html, body, form {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
font-family: Verdana, Tahoma, Arial;
font-size: small;
}
.spinner {
position: fixed;
top: 50%;
left: 50%;
margin-left: -50px; /* half width of the spinner gif */
margin-top: -50px; /* half height of the spinner gif */
text-align: center;
z-index: 1234;
overflow: auto;
width: 150px; /* width of the spinner gif */
height: 62px; /*height of the spinner gif +2px to fix IE8 issue */
background-color: #E1E1D7;
border: 1px solid black;
}
.HighlightDiv img {
background-color: transparent;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: transparent;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
cursor: default;
}
.HighlightDiv:hover img {
background-color: #DDEEF7;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-color: #336699;
border-right-color: #336699;
border-bottom-color: #336699;
border-left-color: #336699;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
cursor: pointer;
}
.dirRTL{
direction:rtl;
}
</style>
<body >
<form id="frmReportViewer" runat="server">
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true"
EnablePartialRendering="true" runat="server">
</asp:ScriptManager>
<div id="divMain">
<rsweb:ReportViewer ID="TransportationReportViewer" runat="server" ProcessingMode="Remote" Height="700px" CssClass="dirRTL"
Width="1024px" >
</rsweb:ReportViewer>
<iframe id="frmPrint" name="frmPrint" runat="server" style="display: none"></iframe>
</div>
<div id="spinner" class="spinner" style="display: none;">
<table align="center" valign="middle" style="height: 100%; width: 100%">
<tr>
<td>
<img id="img-spinner" src="../Content/img/InProgess.gif" alt="Printing" /></td>
<td><span style="font-family: Verdana; font-weight: bold; font-size: 10pt; width: 86px;">Printing...</span></td>
</tr>
</table>
</div>
</form>
<script type="text/javascript">
$(document).ready(function () {
$("#spinner").bind("ajaxSend", function () {
$(this).show();
}).bind("ajaxStop", function () {
$(this).hide();
}).bind("ajaxError", function () {
$(this).hide();
});
//$(function () {
// showDatePicker();
//});
$(function () {
showPrintButton();
});
});
//$("#TransportationReportViewer_ctl04_ctl00").click(function () {
// // window.setTimeout("printPDF(this);", 3000);
// alert('riyad');
// window.setTimeout("showPrintButton();", 1000);
//});
$(document).on("click", "#TransportationReportViewer_ctl04_ctl00", function () {
$("#TransportationReportViewer_ctl04_ctl00").attr('value', 'طباعة الطلب');
window.setTimeout("showPrintButton();", 1000);
});
$("#TransportationReportViewer_ctl04_ctl00").attr('value', 'طباعة الطلب');
function showDatePicker() {
var parameterRow = $("#ParametersRowrvREXReport");
var innerTable = $(parameterRow).find("table").find("table");
var span = innerTable.find("span:contains('From Date (dd/mm/yyyy):')");
if (span) {
var innerRow = $(span).parent().parent();
var innerCell = innerRow.find("td").eq(1);
var textFrom = innerCell.find("input[type=text]");
innerCell = innerRow.find("td").eq(4);
var textTo = innerCell.find("input[type=text]");
$(textFrom).datepicker({
defaultDate: "+1w",
dateFormat: 'dd/mm/yy',
changeMonth: true,
numberOfMonths: 1,
onClose: function (selectedDate) {
$(textTo).datepicker("option", "minDate", selectedDate);
}
});
$(textFrom).focus(function (e) {
e.preventDefault();
$(textFrom).datepicker("show");
});
$(textTo).datepicker({
defaultDate: "+1w",
dateFormat: 'dd/mm/yy',
changeMonth: true,
numberOfMonths: 1,
onClose: function (selectedDate) {
$(textFrom).datepicker("option", "maxDate", selectedDate);
}
});
$(textTo).focus(function () {
$(textTo).datepicker("show");
});
}
}
//Function that is called on Successful AJAX method call. These are referenced in the "CallServerMethodBeforePrint" function that is created from code behind and will exist in the final rendering of the page.
function ServerCallSucceeded(result, context) {
var iFrameURL = "<%=iFrameURL%>";
window.frames['frmPrint'].document.location.href = iFrameURL;
window.frames['frmPrint'].focus();
var timeout = window.setTimeout("window.frames[\"frmPrint\"].focus();window.frames[\"frmPrint\"].print();", 500);
window.setTimeout("ServerCallAfterPrint(this)", 2000);
}
function ServerCallSucceededAfterPrint(result, context) {
}
//Function that is called on failure or error in AJAX method call. These are referenced in the "CallServerMethodBeforePrint" function that is created from code behind and will exist in the final rendering of the page.
function ServerCallFailed(result, context) {
}
function ServerCallBeforePrint(btn) {
$('#spinner').show();
var context = new Object();
//example of passing multiple args
context.flag = new Array('1');
//This "CallServerMethodBeforePrint" function is created from code behind and will exist in the final rendering of the page
CallServerMethodBeforePrint(context.flag, context);
}
function ServerCallAfterPrint(btn) {
var context = new Object();
//example of passing multiple args
context.flag = new Array('2');
//This "CallServerAfterPrint" function is created from code behind and will exist in the final rendering of the page
CallServerAfterPrint(context.flag, context);
$('#spinner').hide();
}
function printPDF(btn) {
ServerCallBeforePrint(btn);
}
function showPrintButton() {
var table = $("table[title='Refresh']");
var parentTable = $(table).parents('table');
var parentDiv = $(parentTable).parents('div').parents('div').first();
var btnPrint = $("<input type='button' id='btnPrint' name='btnPrint' value='Print' style=\"font-family:Verdana;font-size:8pt;width:86px\"/>");
var btnClose = $("<input type='button' id='btnClose' name='btnClose'value='Close' style=\"font-family:Verdana;font-size:8pt;width:86px\"/>");
btnPrint.click(function () {
printPDF(this);
});
btnClose.click(function () {
window.close();
});
if (parentDiv.find("input[value='Print']").length == 0) {
parentDiv.append('<table cellpadding="0" cellspacing="0" toolbarspacer="true" style="display:inline-block;width:6px;"><tbody><tr><td></td></tr></tbody></table>');
parentDiv.append('<div id="customDiv" class=" " style="display:inline-block;font-family:Verdana;font-size:8pt;vertical-align:inherit;"><table cellpadding="0" cellspacing="0"><tbody><tr><td><span style="cursor:pointer;" class="HighlightDiv" onclick="javascript:printPDF(this);" ><img src="../Content/img/Print.png" alt="Print Report" title="Print Report" width="18px" height="18px" style="margin-top:4px"/></span></td></tr></tbody></table></div>');
parentDiv.append('<table cellpadding="0" cellspacing="0" toolbarspacer="true" style="display:inline-block;width:10px;"><tbody><tr><td></td></tr></tbody></table>');
parentDiv.append('<div id="customDiv" class=" " style="display:inline-block;font-family:Verdana;font-size:8pt;vertical-align:inherit;"><table cellpadding="0" cellspacing="0" style="display:inline;"><tbody><tr><td><span style="cursor:pointer;" class="HighlightDiv" onclick="javascript:window.close();"></span></td></tr></tbody></table></div>');
}
}
function cfnReportsViewer_ViewReport(selectedTreeKeyGuidValue, ReportName, VenueExamCounter) {
var windowWidth = 1000;
var windowHeight = 800;
var left = (screen.width / 2) - (windowWidth / 2);
var top = (screen.height / 2) - (windowHeight / 2);
var myForm = document.getElementById("frmReportViewer");
if (myForm) {
myForm.target = "PopupReport";
}
$("#hfAccessObjectGuid").val(selectedTreeKeyGuidValue);
$("#hfReportName").val(ReportName);
$("#hfVenueExamCounter").val(VenueExamCounter);
var thePopup = window.open("about:blank", "PopupReport", 'scrollbars=yes,status=yes,toolbar=yes,menubar=no,location=no,resizable=no,fullscreen=yes, width=' + windowWidth + ', height=' + windowHeight + ', top=' + top + ', left=' + left);
window.setTimeout(document.getElementById("frmReportViewer").submit(), 500);
return false;
}
</script>
</body>
</html>
---------------------------------------------------------------------------------------------------
Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using Microsoft.Reporting.WebForms.Internal;
using System.Drawing.Printing;
using System.IO;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text;
using System.Collections.Specialized;
using System.Drawing;
using System.Configuration;
using System.ComponentModel;
//using System.Drawing.Printing;
namespace UI.Report
{
public partial class ReportPage : System.Web.UI.Page, ICallbackEventHandler
{
private string _reportName;
private string _sessionPDFFileName;
protected string iFrameURL;
protected void Page_Load(object sender, EventArgs e)
{
_reportName = "ReportName";
_sessionPDFFileName = Session.SessionID.ToString() + ".pdf";
//Attach pdf to the iframe
string url = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + _sessionPDFFileName;
iFrameURL = url;
RegisterClientsCallBackReference();
RegisterClientCallBackAfterPrint();
if (!IsPostBack)
{
RenderReport();
}
else
{
this.TransportationReportViewer.ShowReportBody = true;
// RenderReport();
}
}
private ReportParameter[] GetHCResultRepParameters()
{
ReportParameter[] RptParameters = null;
var orderID = "";
if (null != Request.QueryString["orderID"]) orderID = Request.QueryString["orderID"].ToString();
RptParameters = new Microsoft.Reporting.WebForms.ReportParameter[1];
RptParameters[0] = !string.IsNullOrEmpty(orderID) ?
new Microsoft.Reporting.WebForms.ReportParameter("orderID", orderID, false) :
new Microsoft.Reporting.WebForms.ReportParameter("orderID", new string[] { null }, false);
return RptParameters;
}
//--------------------------------------------------------------------------------------
#region PrintButton
protected void ShowPrintButton()
{
string script = "<SCRIPT LANGUAGE='JavaScript'> ";
script += "showPrintButton()";
script += "</SCRIPT>";
ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowStatus", "javascript:showPrintButton();", true);
}
protected void SavePDF()
{
string _reportPath = Request.PhysicalApplicationPath + "\\UPLOADS\\";
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
this.TransportationReportViewer.LocalReport.ReportPath = _reportName;
System.Diagnostics.Trace.WriteLine(_reportName);
byte[] bytes = this.TransportationReportViewer.ServerReport.Render("PDF", "", out mimeType, out encoding, out extension, out streamids, out warnings);
//save the pdf byte to the folder
if (!File.Exists(Server.MapPath(_sessionPDFFileName)))
{
using (StreamWriter sw = new StreamWriter(File.Create(Server.MapPath(_sessionPDFFileName))))
{
sw.Write("");
}
}
FileStream fs = new FileStream(Server.MapPath(_sessionPDFFileName), FileMode.Create);
byte[] data = new byte[fs.Length];
fs.Write(bytes, 0, bytes.Length);
fs.Close();
}
protected void TransportationReportViewer_ReportRefresh(object sender, CancelEventArgs e)
{
ShowPrintButton();
}
public string AjaxCall(string name)
{
System.Diagnostics.Trace.WriteLine(_sessionPDFFileName);
//if (name == "2") //Delete file- After print
//{
if (File.Exists(_sessionPDFFileName))
{
//frmPrint.Attributes["src"] = "";
File.Delete(_sessionPDFFileName);
}
//}
//else
if (name == "1") //Create file- before print
{
SavePDF();
}
return name;
////var ajaxcall = Request.Form["ajaxcall"];
//if (name != null)
//{
// if (File.Exists(Server.MapPath(_sessionPDFFileName)))
// {
// //frmPrint.Attributes["src"] = "";
// File.Delete(Server.MapPath(_sessionPDFFileName));
// }
// else
// {
// SavePDF();
// }
//}
//return name;
}
string returnValue;
string ICallbackEventHandler.GetCallbackResult()
{
return returnValue;
}
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
returnValue = AjaxCall(eventArgument);
}
private void RegisterClientsCallBackReference()
{
String myClientsCallBack = Page.ClientScript.GetCallbackEventReference(this, "arg", "ServerCallSucceeded", "context", "ServerCallFailed", true);
//Could also call this wtihout the callback succeeded or failed methods:
String myCompleteClientFunction = @"function CallServerMethodBeforePrint(arg, context)
{ " +
myClientsCallBack + @";
}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "TheScriptToCallServer", myCompleteClientFunction, true);
}
private void RegisterClientCallBackAfterPrint()
{
String myClientAfterPrintCallBack = Page.ClientScript.GetCallbackEventReference(this, "arg", "ServerCallSucceededAfterPrint", "context", "ServerCallFailed", true);
String myAfterPrintCompleteClientFunction = @"function CallServerAfterPrint(arg, context)
{ " +
myClientAfterPrintCallBack + @";
}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "TheScriptToCallServerAfterPrint", myAfterPrintCompleteClientFunction, true);
}
#endregion
public void RenderReport()
{
var querystring = string.Empty;
if (null != Request.QueryString["reportName"]) querystring = Request.QueryString["reportName"].ToString();
if (!string.IsNullOrEmpty(querystring))
{
this.TransportationReportViewer.Visible = true;
this.TransportationReportViewer.ServerReport.ReportServerUrl = new System.Uri(ConfigurationManager.AppSettings["Report_URL"]);
string strReport = "/Masajed Sector/" + querystring;
this.TransportationReportViewer.ServerReport.ReportPath = strReport;
_reportName = strReport;
if (querystring == "notesDismissal")
{
this.TransportationReportViewer.ServerReport.SetParameters(GetHCResultRepParameters());
this.TransportationReportViewer.ShowParameterPrompts = true;
}
if (querystring == "notesDismissalSpecialOrder")
{
this.TransportationReportViewer.ServerReport.SetParameters(GetHCResultRepParameters());
this.TransportationReportViewer.ShowParameterPrompts = false;
}
this.TransportationReportViewer.ServerReport.Refresh();
this.TransportationReportViewer.PageCountMode = PageCountMode.Actual;
//ShowPrintButton();
if (querystring == "RptListofBooks")
{
this.TransportationReportViewer.ShowParameterPrompts = true;
this.TransportationReportViewer.ShowReportBody = true;
}
if (querystring == "RptRequesterOrderBooks")
{
this.TransportationReportViewer.ShowParameterPrompts = true;
this.TransportationReportViewer.ShowReportBody = true;
}
if (querystring == "OrderStatistics_Departmentwise")
{
this.TransportationReportViewer.ShowParameterPrompts = true;
this.TransportationReportViewer.ShowReportBody = true;
}
if (querystring == "OrderStatistics_Jobwise")
{
this.TransportationReportViewer.ShowParameterPrompts = true;
this.TransportationReportViewer.ShowReportBody = true;
}
if (querystring == "RptOrderStatisticDeptJobwise")
{
this.TransportationReportViewer.ShowParameterPrompts = true;
this.TransportationReportViewer.ShowReportBody = true;
}
if (querystring == "OrderStatistics_Bookwise")
{
this.TransportationReportViewer.ShowParameterPrompts = true;
this.TransportationReportViewer.ShowReportBody = true;
}
if (querystring == "OrderStatistics_Bookwise")
{
this.TransportationReportViewer.ShowParameterPrompts = true;
this.TransportationReportViewer.ShowReportBody = true;
}
if (querystring == "BookStock")
{
this.TransportationReportViewer.ShowParameterPrompts = true;
this.TransportationReportViewer.ShowReportBody = true;
}
}
}
}
}
Subscribe to:
Comments (Atom)