private void OnFormLoad(object sender, EventArgs e) { //Event handler for form load event this.Cursor = Cursors.WaitCursor; try { this.cboRouteClass.DisplayMember = "Name"; this.cboRouteClass.ValueMember = "Number"; this.cboDriver.DisplayMember = "Name"; this.cboDriver.ValueMember = "Name"; this.cboRouteClass.DataSource = RoadshowGateway.GetDepots(); this.cboRouteClass.SelectedIndex = 0; OnRouteClassChanged(null, EventArgs.Empty); } catch (Exception ex) { App.ReportError(ex, true, LogLevel.Error); } finally { this.Cursor = Cursors.Default; } }
private void OnRouteClassChanged(object sender, EventArgs e) { //Event handler for change in selected route class this.Cursor = Cursors.WaitCursor; try { if (this.cboRouteClass.SelectedValue != null) { this.cboDriver.DataSource = RoadshowGateway.GetDrivers(int.Parse(this.cboRouteClass.SelectedValue.ToString())); } if (this.cboDriver.Items.Count > 0) { this.cboDriver.SelectedIndex = 0; } OnDriverChanged(null, EventArgs.Empty); } catch (Exception ex) { App.ReportError(ex, true, LogLevel.Error); } finally { this.Cursor = Cursors.Default; } }
protected void OnButtonCommand(object sender, CommandEventArgs e) { //Event handler for command button clicked try { //Change view to Viewer and reset to clear existing data Master.Viewer.Reset(); //Get parameters for the query string _dateS = this.ddpRouteDate.FromDate.ToString("yyyy-MM-dd"); string _dateE = this.ddpRouteDate.ToDate.ToString("yyyy-MM-dd"); string _depot = this.cboDepot.SelectedValue != "" ? this.cboDepot.SelectedValue : null; //Initialize control values LocalReport report = Master.Viewer.LocalReport; report.DisplayName = this.mTitle; report.EnableExternalImages = true; RoadshowGateway enterprise = new RoadshowGateway(); DataSet ds = enterprise.FillDataset(this.mUSPName, mTBLName, new object[] { _dateS, _dateE, _depot }); if (ds.Tables[mTBLName] == null) { ds.Tables.Add(mTBLName); } switch (e.CommandName) { case "Run": //Set local report and data source System.IO.Stream stream = Master.GetReportDefinition(this.mSource); report.LoadReportDefinition(stream); report.DataSources.Clear(); report.DataSources.Add(new ReportDataSource(this.mDSName, ds.Tables[mTBLName])); //Set the report parameters for the report ReportParameter date = new ReportParameter("RouteDate", _dateE); ReportParameter depot = new ReportParameter("RouteClass", _depot); report.SetParameters(new ReportParameter[] { date, depot }); //Update report rendering with new data report.Refresh(); if (!Master.Viewer.Enabled) { Master.Viewer.CurrentPage = 1; } break; case "Data": //Set local export report and data source report.LoadReportDefinition(Master.CreateExportRdl(ds, this.mDSName)); report.DataSources.Clear(); report.DataSources.Add(new ReportDataSource(this.mDSName, ds.Tables[mTBLName])); report.Refresh(); break; case "Excel": //Create Excel mime-type page Response.ClearHeaders(); Response.Clear(); Response.Charset = ""; Response.AddHeader("Content-Disposition", "inline; filename=DailyRouteDetail.xls"); Response.ContentType = "application/vnd.ms-excel"; //application/octet-stream"; System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw); DataGrid dg = new DataGrid(); dg.DataSource = ds.Tables[mTBLName]; dg.DataBind(); dg.RenderControl(hw); Response.Write(sw.ToString()); Response.End(); break; } } catch (Exception ex) { Master.ReportError(ex); } }