have a problem export grid to excel when more than one grid exports to excel. In the attched "Screen jpeg" the export to excel works fine. in the "export jpeg" the export changes the grid around and does not export to excel. I have listed my aspx page and code behind.
<%@ Page Title="" Language="C#" MasterPageFile="~/Modules/Module.Master" AutoEventWireup="true" CodeBehind="ManageEmployees.aspx.cs" Inherits="HelmOnline.Web.Modules.TimeClock.ManageEmployee" %>
<%@ Register Src="~/Common/Controls/CustomerIdSelect.ascx" TagPrefix="uc1" TagName="CustomerIdSelect" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ModuleContent" runat="server">
<div style="margin: 10px; height: 100%;">
<style type="text/css">
.rightAlign {
float: right;
}
.pad1 {
padding-right: 20px
}
</style>
<telerik:RadScriptBlock runat="server">
<script type="text/javascript">
function OpenWCEntry(sender, punchid, customerid, employeeid, jobsiteid, punchtimein, punchtimeout) {
var dialogWindow = $find("<%=RadWindow1.ClientID%>");
if (punchid == 0)
{ dialogWindow.set_title("Add New Punch Entry"); }
else
{ dialogWindow.set_title("Modify Punch Entry"); }
var baseUrl = "Dialog/AddEditWebTime.aspx";
baseUrl = baseUrl + "?";
baseUrl = baseUrl + "punchid=" + punchid;
baseUrl = baseUrl + "&";
baseUrl = baseUrl + "customerid=" + customerid;
baseUrl = baseUrl + "&";
baseUrl = baseUrl + "employeeid=" + employeeid;
baseUrl = baseUrl + "&";
baseUrl = baseUrl + "jobsiteid=" + jobsiteid;
baseUrl = baseUrl + "&";
baseUrl = baseUrl + "punchtimein=" + punchtimein;
baseUrl = baseUrl + "&";
baseUrl = baseUrl + "punchtimeout=" + punchtimeout;
dialogWindow.set_navigateUrl(baseUrl)
dialogWindow.set_modal(true);
dialogWindow.show();
}
function OnClientCloseHandler(sender, args) {
var btnRefreshGrids = $find("<%=btnRefreshGrids.ClientID%>");
btnRefreshGrids.click();
}
function OpenReport() {
var comboReport = $find("<%=cboReport.ClientID%>");
var comboPeriods = $find("<%=rcCustomerPeriod.ClientID%>");
var comboImportFilter = $find("<%=rcImportFilter.ClientID%>");
var jobsiteid = checkcheckeditems();
var hidCustomerId = document.getElementById('<%=hidCustomerId.ClientID%>');
//var baseUrl = "Dialog/WebClockReport.aspx";
var nbaseUrl = "../Shared/ModuleReport.aspx";
var parms = "";
parms = parms + "customerid:" + hidCustomerId.value;
parms = parms + "|";
parms = parms + "jobsiteid:" + jobsiteid;
parms = parms + "|";
parms = parms + "periodid:" + comboPeriods.get_selectedItem().get_value();
parms = parms + "|";
parms = parms + "importfilterid:" + comboImportFilter.get_selectedItem().get_value();
nbaseUrl = nbaseUrl + "?ReportID=" + comboReport.get_selectedItem().get_value();
nbaseUrl = nbaseUrl + "&ReportParms=" + parms;
//alert(jobsiteid);
//baseUrl = baseUrl + "?";
//baseUrl = baseUrl + "customerid=" + hidCustomerId.value;
//baseUrl = baseUrl + "&";
//baseUrl = baseUrl + "jobsiteid=" + jobsiteid;
//baseUrl = baseUrl + "&";
//baseUrl = baseUrl + "periodid=" + comboPeriods.get_selectedItem().get_value();
//baseUrl = baseUrl + "&";
//baseUrl = baseUrl + "importfilterid=" + comboImportFilter.get_selectedItem().get_value();
document.title = 'Web Clock Report';
//window.open(baseUrl);
window.open(nbaseUrl);
}
function checkcheckeditems() {
var checkeditems = '';
var radvalue;
var combo = $find("<%=rcWCJSList.ClientID%>")
var items = combo.get_checkedItems();
for (i = 0; i < items.length; i++) {
radvalue = items[i].get_value();
if (i == 0) {
checkeditems = checkeditems + radvalue;
}
else {
checkeditems = checkeditems + "," + radvalue;
}
}
//alert(checkeditems);
return (checkeditems);
}
function OpenPunchLogReport() {
var comboPeriods = $find("<%=rcCustomerPeriod.ClientID%>");
var grid = $find("<%=RadGrid1.ClientID %>");
var MasterTable = grid.get_masterTableView();
var Rows = MasterTable.get_dataItems();
//if (Rows.length > 0)
//{
// var cell = MasterTable.getCellByColumnUniqueName(MasterTable.get_dataItems()[0], "EmployeeID").innerHTML;
// var baseUrl = "Dialog/PunchReport.aspx";
// baseUrl = baseUrl + "?";
// baseUrl = baseUrl + "employeeid=" + cell;
// baseUrl = baseUrl + "&";
// baseUrl = baseUrl + "periodid=" + comboPeriods.get_selectedItem().get_value();
// document.title = 'Punch Log Report';
// window.open(baseUrl);
//}
var selectedRows = MasterTable.get_selectedItems();
for (var i = 0; i < selectedRows.length; i++) {
var row = selectedRows[i];
var cell = MasterTable.getCellByColumnUniqueName(row, "EmployeeID")
//alert(cell.innerHTML);
var nbaseUrl = "../Shared/ModuleReport.aspx";
var parms = "";
parms = parms + "employeeid:" + cell.innerHTML;
parms = parms + "|";
parms = parms + "periodid:" + comboPeriods.get_selectedItem().get_value();
nbaseUrl = nbaseUrl + "?ReportID=7"
nbaseUrl = nbaseUrl + "&ReportParms=" + parms;
//var baseUrl = "Dialog/PunchReport.aspx";
//baseUrl = baseUrl + "?";
//baseUrl = baseUrl + "employeeid=" + cell.innerHTML;
//baseUrl = baseUrl + "&";
//baseUrl = baseUrl + "periodid=" + comboPeriods.get_selectedItem().get_value();
document.title = 'Punch Log Report';
window.open(nbaseUrl);
}
}
function OpenWebClockEmployeeReport(sender, customerid, employeeid, startdate, enddate) {
var baseUrl = "Dialog/WebClockEmployeeReport.aspx";
baseUrl = baseUrl + "?";
baseUrl = baseUrl + "customerid=" + customerid;
baseUrl = baseUrl + "&";
baseUrl = baseUrl + "employeeid=" + employeeid;
baseUrl = baseUrl + "&";
baseUrl = baseUrl + "startdate=" + startdate;
baseUrl = baseUrl + "&";
baseUrl = baseUrl + "enddate=" + enddate;
document.title = 'Web Clock Employee Report';
window.open(baseUrl);
}
</script>
</telerik:RadScriptBlock>
<telerik:RadWindowManager RenderMode="Lightweight" ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false" ReloadOnShow="true" runat="server" EnableShadow="true">
<Windows>
<telerik:RadWindow RenderMode="Lightweight" ID="RadWindow1" runat="server" Height="525" Width="850" NavigateUrl="~/Modules/TimeClock/Dialog/AddEditWebTime.aspx" OnClientClose="OnClientCloseHandler" Behaviors="Close" />
</Windows>
</telerik:RadWindowManager>
<telerik:RadAjaxManager ID="RadRadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" UpdatePanelHeight="100%" />
<telerik:AjaxUpdatedControl ControlID="RadGrid2" UpdatePanelHeight="100%" />
<telerik:AjaxUpdatedControl ControlID="btnAdd" />
<telerik:AjaxUpdatedControl ControlID="btnEdit" />
<telerik:AjaxUpdatedControl ControlID="btnPunchLog" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="btnRefreshGrids">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="btnRefreshGrids" />
<telerik:AjaxUpdatedControl ControlID="RadGrid1" UpdatePanelHeight="100%" />
<telerik:AjaxUpdatedControl ControlID="RadGrid2" UpdatePanelHeight="100%" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
<ClientEvents />
</telerik:RadAjaxManager>
<asp:Panel runat="server" ID="pnlcustomerselect">
<uc1:CustomerIdSelect runat="server" ID="CustomerIDField" OnCustomerSelectEvent="CustomerIDField_CustomerSelectEvent" />
</asp:Panel>
<telerik:RadAjaxPanel runat="server" ID="pnlgridcontainer" PostBackControls="btnExportGrid,btnExportGrid2" Height="100%">
<div style="margin: 0px; height: 5%;">
<table>
<tbody>
<tr>
<td width="5%">
<telerik:RadLabel runat="server" ID="radlabel2" Text="Customer"></telerik:RadLabel>
</td>
<td width="30%">
<telerik:RadLabel runat="server" ID="lblCustomerIDName"></telerik:RadLabel>
</td>
<td width="15%">
<telerik:RadComboBox ID="rcCustomerPeriod" runat="server" Height="200" Width="250" DropDownWidth="320" EmptyMessage="Choose a Period" HighlightTemplatedItems="true" DataTextField="DisplyText" DataValueField="PeriodID" OnSelectedIndexChanged="rcbEarningSelection_SelectedIndexChanged" AutoPostBack="true">
<HeaderTemplate>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td style="width: 75px;">Status
</td>
<td style="width: 75px;">Start Date
</td>
<td style="width: 75px;">End Date
</td>
<td style="width: 75px;">WE Date
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td style="width: 75px;">
<%# DataBinder.Eval(Container.DataItem , "StatusDescription")%>
</td>
<td style="width: 75px;">
<%# string.Format("{0:MM/dd/yyyy}", DataBinder.Eval(Container.DataItem , "StartDate"))%>
</td>
<td style="width: 75px;">
<%# string.Format("{0:MM/dd/yyyy}", DataBinder.Eval(Container.DataItem , "EndDate"))%>
</td>
<td style="width: 75px;">
<%# string.Format("{0:MM/dd/yyyy}", DataBinder.Eval(Container.DataItem , "WEDate"))%>
</td>
</tr>
</table>
</ItemTemplate>
</telerik:RadComboBox>
</td>
<td width="40%">
<telerik:RadLabel runat="server" ID="RadLabel" Text="Report" />
<telerik:RadComboBox runat="server" ID="cboReport" DataTextField="WebDisplayName" DataValueField="ReportID" />
<telerik:RadComboBox runat="server" ID="rcWCJSList" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" DataTextField="JobSiteName" DataValueField="JobSiteID" />
<telerik:RadComboBox runat="server" ID="rcImportFilter" Width="120px">
<Items>
<telerik:RadComboBoxItem runat="server" Text="All Time" Value="0" />
<telerik:RadComboBoxItem runat="server" Text="Imported Time" Value="1" />
<telerik:RadComboBoxItem runat="server" Text="Unimported Time" Value="2" />
</Items>
</telerik:RadComboBox>
<asp:LinkButton runat="server" ID="btnReport" Text="Display" OnClientClick="javascript:OpenReport();false;" />
</td>
<td width="15%">
<telerik:RadButton runat="server" ID="btnTimeImport" CssClass="rightAlign" Text="Import Time" OnClick="btnTimeImport_Click" />
</td>
</tbody>
</table>
<telerik:RadButton ID="btnRefreshGrids" Text="Refresh" OnClick="btnRefreshGrids_Click" runat="server" Style="display: none;" />
</div>
<div style="margin: 0px; height: 95%;" id="gridContainer">
<div style="margin: 0px; height: 50%;">
<asp:ImageButton ID="btnExportGrid" runat="server" ImageUrl="/Images/Excel_XLSX.png" Height="24" Width="24" OnClick="btnExportGrid_Click" AlternateText="ExportToExcel" />
<telerik:RadGrid runat="server" ID="RadGrid1" Width="100%" Height="80%" AutoGenerateColumns="false" AllowPaging="False" AllowSorting="true" ShowGroupPanel="false" RenderMode="Classic" AllowFilteringByColumn="true" GroupingSettings-CaseSensitive="false" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged" OnNeedDataSource="RadGrid1_NeedDataSource">
<MasterTableView TableLayout="Fixed">
<Columns>
<telerik:GridBoundColumn HeaderStyle-Width="0" SortExpression="Customer ID" HeaderText="Customerid" HeaderButtonType="TextButton" DataField="Customerid" DataFormatString="{0:d}" />
<telerik:GridBoundColumn SortExpression="EmployeeID" HeaderText="Employee ID" HeaderButtonType="TextButton" DataField="EmployeeID" DataFormatString="{0:d}" />
<telerik:GridBoundColumn SortExpression="FirstName" HeaderText="First Name" HeaderButtonType="TextButton" DataField="FirstName" DataFormatString="{0:d}" />
<telerik:GridBoundColumn SortExpression="LastName" HeaderText="Last Name" HeaderButtonType="TextButton" DataField="LastName" DataFormatString="{0:d}" />
<telerik:GridBoundColumn SortExpression="Imported_Hours" HeaderText="Imported Hours" HeaderButtonType="TextButton" DataField="Imported_Hours" DataFormatString="{0:###,##0.00}" />
<telerik:GridBoundColumn SortExpression="Unimported_Hours" HeaderText="Unimported Hours" HeaderButtonType="TextButton" DataField="Unimported_Hours" DataFormatString="{0:###,##0.00}" />
<telerik:GridBoundColumn SortExpression="Gross_Hours" HeaderText="Gross Hours" HeaderButtonType="TextButton" DataField="Gross_Hours" DataFormatString="{0:###,##0.00}" />
<telerik:GridBoundColumn SortExpression="Net_Hours" HeaderText="Net Hours" HeaderButtonType="TextButton" DataField="Net_Hours" DataFormatString="{0:###,##0.00}" />
</Columns>
</MasterTableView>
<ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True" EnablePostBackOnRowClick="true" Selecting-AllowRowSelect="true">
<Selecting AllowRowSelect="True"></Selecting>
<Resizing AllowRowResize="False" AllowColumnResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="False"></Resizing>
<Scrolling UseStaticHeaders="true" AllowScroll="true" />
<%--<ClientEvents OnGridCreated="GridCreated" />--%>
</ClientSettings>
</telerik:RadGrid>
</div>
<div style="margin: 0px; height: 50%;">
<table>
<tr>
<td>
<asp:ImageButton ID="btnExportGrid2" runat="server" ImageUrl="/Images/Excel_XLSX.png" Height="24" Width="24" OnClick="btnExportGrid2_Click" AlternateText="ExportToExcel" />
</td>
<td class="pad1">
<asp:LinkButton runat="server" ID="btnAdd" Text="Add New Punch" OnClick="btnAdd_Click" Visible="false"></asp:LinkButton></td>
<td>
<asp:LinkButton runat="server" ID="btnPunchLog" Text="Employee Punch Log" Visible="false" OnClientClick="javascript:OpenPunchLogReport();false;"></asp:LinkButton></td>
</tr>
</table>
<telerik:RadGrid Width="100%" Height="80%" ID="RadGrid2" OnNeedDataSource="RadGrid2_NeedDataSource" runat="server" AutoGenerateColumns="false" AllowPaging="False" AllowSorting="true" ShowGroupPanel="false" PageSize="10" RenderMode="Classic" AllowFilteringByColumn="false" GroupingSettings-CaseSensitive="false" OnItemCreated="RadGrid2_ItemCreated" OnItemCommand="RadGrid2_ItemCommand" OnItemDataBound="RadGrid2_ItemDataBound">
<MasterTableView TableLayout="Fixed">
<Columns>
<telerik:GridButtonColumn UniqueName="btnDelete" CommandName="Delete" ButtonType="LinkButton" Text="Delete" HeaderStyle-Width="45" HeaderText="Delete" ConfirmText="Do want to delete punch?" ImageUrl="../../Images/redx-md.png" />
<telerik:GridButtonColumn UniqueName="btnEdit" ButtonType="LinkButton" Text="Modify" HeaderText="Modify" HeaderStyle-Width="55" />
<telerik:GridBoundColumn HeaderStyle-Width="0" SortExpression="Customerid" HeaderText="Customerid" HeaderButtonType="TextButton" DataField="Customerid" DataFormatString="{0:d}" />
<telerik:GridBoundColumn HeaderStyle-Width="0" SortExpression="EmployeeID" HeaderText="EmployeeID" HeaderButtonType="TextButton" DataField="EmployeeID" DataFormatString="{0:d}" />
<telerik:GridBoundColumn HeaderStyle-Width="0" SortExpression="FirstName" HeaderText="FirstName" HeaderButtonType="TextButton" DataField="FirstName" DataFormatString="{0:d}" />
<telerik:GridBoundColumn HeaderStyle-Width="0" SortExpression="LastName" HeaderText="LastName" HeaderButtonType="TextButton" DataField="LastName" DataFormatString="{0:d}" />
<telerik:GridBoundColumn HeaderStyle-Width="0" SortExpression="PunchID" HeaderText="PunchID" HeaderButtonType="TextButton" DataField="PunchID" DataFormatString="{0:d}" />
<telerik:GridBoundColumn HeaderStyle-Width="0" SortExpression="JobSitID" HeaderText="JobSitID" HeaderButtonType="TextButton" DataField="JobSitID" DataFormatString="{0:d}" />
<telerik:GridBoundColumn HeaderStyle-Width="0" SortExpression="IsEdit" HeaderText="IsEdit" HeaderButtonType="TextButton" DataField="IsEdit" DataFormatString="{0:d}" />
<telerik:GridBoundColumn HeaderStyle-Width="60" SortExpression="Imported_BatchID" HeaderText="BatchID" HeaderButtonType="TextButton" DataField="Imported_BatchID" DataFormatString="{0:d}" />
<telerik:GridDateTimeColumn SortExpression="dt" HeaderText="Date" HeaderStyle-Width="70" HeaderButtonType="TextButton" DataField="dt" DataType="System.DateTime" DataFormatString="{0:M/d/yyyy}" />
<telerik:GridBoundColumn SortExpression="DayOfWeek" HeaderText="Day Of Week" HeaderStyle-Width="85" HeaderButtonType="TextButton" DataField="DayOfWeek" DataFormatString="{0:d}" />
<telerik:GridBoundColumn SortExpression="JobSiteName" HeaderText="Job Site Name" HeaderButtonType="TextButton" DataField="JobSiteName" DataFormatString="{0:d}" />
<telerik:GridDateTimeColumn SortExpression="PunchInDate" HeaderText="Punch In Date" HeaderStyle-Width="95" HeaderButtonType="TextButton" DataField="PunchInDate" DataType="System.DateTime" DataFormatString="{0:M/d/yyyy}" />
<telerik:GridDateTimeColumn SortExpression="PunchInTime" HeaderText="Punch In Time" HeaderStyle-Width="95" HeaderButtonType="TextButton" DataField="PunchInTime" DataType="System.DateTime" />
<telerik:GridDateTimeColumn SortExpression="PunchOutDate" HeaderText="Punch Out Date" HeaderStyle-Width="100" HeaderButtonType="TextButton" DataField="PunchOutDate" DataType="System.DateTime" DataFormatString="{0:M/d/yyyy}" />
<telerik:GridDateTimeColumn SortExpression="PunchOutTime" HeaderText="Punch Out Time" HeaderStyle-Width="100" HeaderButtonType="TextButton" DataField="PunchOutTime" DataType="System.DateTime" />
<telerik:GridBoundColumn SortExpression="Hours_Worked" HeaderText="Gross Hours" HeaderStyle-Width="95" HeaderButtonType="TextButton" DataField="Hours_Worked" DataFormatString="{0:###,##0.00}" />
</Columns>
</MasterTableView>
<ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True" EnablePostBackOnRowClick="true">
<Selecting AllowRowSelect="True"></Selecting>
<Resizing AllowRowResize="False" AllowColumnResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="False"></Resizing>
<Scrolling UseStaticHeaders="true" AllowScroll="true" />
</ClientSettings>
</telerik:RadGrid>
</div>
</div>
</telerik:RadAjaxPanel>
</div>
<asp:HiddenField runat="server" ID="hidCustomerId" />
<asp:HiddenField runat="server" ID="hidEmmployeeId" />
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using xi = Telerik.Web.UI.ExportInfrastructure;
using Telerik.Web.UI.GridExcelBuilder;
using HelmOnline.Web.Common.Context;
namespace HelmOnline.Web.Modules.TimeClock
{
public partial class ManageEmployee : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack){
int customerid = 0;
if (customerid == 0){
customerid = Common.Context.SecurityContext.CustomerId;
}
if (customerid > 0){
this.CustomerIDField.CustomerId = customerid;
CustomerIDField_CustomerSelectEvent(customerid);
}
else{
this.pnlcustomerselect.Visible = true;
this.pnlgridcontainer.Visible = false;
}
}
}
protected void RadGrid2_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
DateTime punchdatein;
DateTime punchdateout;
if (e.Item is GridDataItem) {
var gridItem = (GridDataItem)e.Item;
var scItem = (svcHelm.WC_EmployeeDetailItem)gridItem.DataItem;
if (scItem != null) {
if (this.rcCustomerPeriod.SelectedItem.Text.Contains("Closed")) {
((LinkButton)gridItem["btnDelete"].Controls[0]).Visible = false;
((LinkButton)gridItem["btnEdit"].Controls[0]).Visible = false;
}
else {
if (scItem.Imported_BatchID > 0){
((LinkButton)gridItem["btnDelete"].Controls[0]).Visible = false;
((LinkButton)gridItem["btnEdit"].Controls[0]).Visible = false;
}
else {
((LinkButton)gridItem["btnDelete"].Controls[0]).Visible = true;
((LinkButton)gridItem["btnEdit"].Controls[0]).Visible = true;
}
punchdatein = DateTime.Parse(DateTime.Parse(scItem.PunchInDate.ToString()).ToString("M/dd/yyyy") + " " + scItem.PunchInTime.ToString());
if (scItem.PunchOutDate == null) {
punchdateout = DateTime.Parse(DateTime.Parse(scItem.PunchInDate.ToString()).ToString("M/dd/yyyy") + " " + scItem.PunchInTime.ToString());
}
else{
punchdateout = DateTime.Parse(DateTime.Parse(scItem.PunchOutDate.ToString()).ToString("M/dd/yyyy") + " " + scItem.PunchOutTime.ToString());
}
((LinkButton)gridItem["btnEdit"].Controls[0]).Attributes.Add("onclick", "OpenWCEntry(this, '" + scItem.PunchID.ToString() + "',"
+ scItem.Customerid.ToString() + ","
+ scItem.Employeeid.ToString() + ","
+ scItem.JobSiteID.ToString() + ","
+ punchdatein.ToString("yyyyMMddHHmmss") + ","
+ punchdateout.ToString("yyyyMMddHHmmss")
+ "); return false;");
}
}
}
}
protected void RadGrid2_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
using (var client = new svcHelm.HelmClient())
{
var gridItem = (GridDataItem)e.Item;
client.WC_DeleteEmployeePunch(int.Parse(gridItem["PunchID"].Text));
}
RadGrid2.Rebind();
}
}
protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
int employeeid = 0;
int customerid = 0;
int periodid = 0;
if (this.RadGrid1.SelectedItems != null)
{
if (this.RadGrid1.SelectedItems.Count > 0)
{
var selectGridItem = (Telerik.Web.UI.GridDataItem)this.RadGrid1.SelectedItems[0];
employeeid = int.Parse(selectGridItem["EmployeeID"].Text);
customerid = int.Parse(selectGridItem["CustomerID"].Text);
periodid = int.Parse(this.rcCustomerPeriod.SelectedValue);
}
}
using (var client = new svcHelm.HelmClient())
{
var grid = sender as RadGrid;
grid.DataSource = client.WC_GetEmployeeDetails(customerid, employeeid, periodid);
}
}
protected void CustomerIDField_CustomerSelectEvent(int customerid)
{
if (customerid > 0){
using (var client = new svcHelm.HelmClient()){
this.hidCustomerId.Value = customerid.ToString();
var tsperiods = client.TS_GetCustomerPeriods(customerid);
var WCRJCList = client.WebClockJobSiteList(customerid, SecurityContext.UserId);
var reports = client.HelmOnlineWebReports("WebClock");
if (tsperiods.Count == 0){
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('Customer Periods not set up!');", true);
return;
}
this.rcCustomerPeriod.DataSource = tsperiods;
this.rcCustomerPeriod.DataBind();
this.rcWCJSList.DataSource = WCRJCList;
this.rcWCJSList.DataBind();
this.cboReport.DataSource = reports;
this.cboReport.DataBind();
this.pnlgridcontainer.Visible = true;
this.pnlcustomerselect.Visible = false;
var cinfo = client.GetHelmCustomer(customerid);
this.lblCustomerIDName.Text = cinfo.CustomerID.ToString() + " " + cinfo.CustomerName;
//Set to first open period
int counter = 0;
foreach (svcHelm.TS_CustomerPeriod period in tsperiods){
if (period.StatusID == 1){
this.rcCustomerPeriod.SelectedIndex = counter;
break;
}
counter += 1;
}
foreach (RadComboBoxItem itm in rcWCJSList.Items){
itm.Checked = true;
}
this.btnTimeImport.Visible = client.CustomerVaildateImport(int.Parse(this.hidCustomerId.Value)).isTimeImport;
this.RadGrid1.Rebind();
}
}
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
int customerid = (int)this.CustomerIDField.CustomerId;
if (customerid > 0){
using (var client = new svcHelm.HelmClient()){
var grid = sender as RadGrid;
grid.DataSource = client.WC_GetCustomerEmployeesSummary(customerid, int.Parse(this.rcCustomerPeriod.SelectedValue), SecurityContext.UserId);
}
}
}
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
GridDataItem selectedItem = (GridDataItem)RadGrid1.SelectedItems[0];
Session["RowIndex"] = selectedItem.ItemIndex;// Gets the index of currently selected row
//this.hidEmmployeeId.Value = selectedItem.Cells[3].Text;
this.RadGrid2.Rebind();
RadGrid2.Visible = true;
if (this.rcCustomerPeriod.SelectedItem.Text.Contains("Closed"))
{ btnAdd.Visible = false; }
else { btnAdd.Visible = true; }
this.btnPunchLog.Visible = true;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
int employeeid = 0;
int customerid = (int)this.CustomerIDField.CustomerId;
int periodid = int.Parse(this.rcCustomerPeriod.SelectedValue);
DateTime startdate = DateTime.Now;
DateTime enddate = DateTime.Now;
if (customerid > 0){
if (this.RadGrid1.SelectedItems.Count > 0){
var selectGridItem = (Telerik.Web.UI.GridDataItem)this.RadGrid1.SelectedItems[0];
employeeid = int.Parse(selectGridItem["EmployeeID"].Text);
svcHelm.TS_CustomerPeriod period;
using (var client = new svcHelm.HelmClient()){
period = client.TS_GetCustomerPeriod(periodid);
startdate = period.StartDate;
enddate = period.EndDate;
}
}
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "btnadd", "OpenWCEntry(this,0," + customerid.ToString() + "," + employeeid.ToString() + ", 0 ," + startdate.ToString("yyyyMMddHHmmss") + "," + enddate.ToString("yyyyMMddHHmmss") + "); ", true);
}
else{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('Customerid is blank');", true);
}
}
protected void btnRefreshGrids_Click(object sender, EventArgs e)
{
string selectedEmployeeId = string.Empty;
for (int i = 0; i < RadGrid1.Items.Count; i++){
if (RadGrid1.Items[i].Selected) {
selectedEmployeeId = RadGrid1.Items[i]["EmployeeID"].Text;
}
}
this.RadGrid1.Rebind();
if(selectedEmployeeId.Length > 0){
for (int i = 0; i < RadGrid1.Items.Count; i++){
if(selectedEmployeeId == RadGrid1.Items[i]["EmployeeID"].Text){
RadGrid1.Items[i].Selected = true;
}
}
}
this.RadGrid2.Rebind();
}
protected void btnTimeImport_Click(object sender, EventArgs e)
{
int customerid = (int)this.CustomerIDField.CustomerId;
int periodid = int.Parse(this.rcCustomerPeriod.SelectedValue);
string page = "";
using (var client = new svcHelm.HelmClient()){
var cvalid = client.CustomerVaildateImport(int.Parse(this.hidCustomerId.Value));
if (!cvalid.isTimeImport){
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "err_msg", "alert('Customer Payroll Frequency not valid for Time Import');", true);
}
else{
page = "~/Modules/TimeClock/ImportTime.aspx?customerid=" + customerid.ToString() + "&periodid=" + periodid.ToString();
Response.Redirect(page);
}
}
}
protected void rcbEarningSelection_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
RadGrid1.Rebind();
RadGrid2.Visible = false;
btnAdd.Visible = false;
btnPunchLog.Visible = false;
if (this.rcCustomerPeriod.SelectedItem.Text.Contains("Closed"))
{ btnTimeImport.Visible = false; }
else { btnTimeImport.Visible = true; }
}
protected void btnExportGrid_Click(object sender, ImageClickEventArgs e)
{
RadGrid1.ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), "Xlsx");
RadGrid1.ExportSettings.IgnorePaging = true;
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.MasterTableView.ExportToExcel();
}
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
var gridItem = (GridDataItem)e.Item;
var item = (svcHelm.WC_EmployeeDetailItem)gridItem.DataItem;
if (item.isEdit)
{
gridItem.BackColor = Color.Yellow;
}
}
}
protected void btnExportGrid2_Click(object sender, ImageClickEventArgs e)
{
RadGrid2.ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), "Xlsx");
RadGrid2.ExportSettings.IgnorePaging = true;
RadGrid2.ExportSettings.ExportOnlyData = true;
RadGrid2.ExportSettings.OpenInNewWindow = true;
RadGrid2.MasterTableView.ExportToExcel();
}
}
}