Ejemplo n.º 1
0
        public ShiftDataset GetShifts(string terminal, DateTime date)
        {
            //Event handler for change in selected terminal
            ShiftDataset shifts = null;

            try {
                shifts = new ShiftDataset();
                DataSet ds = FillDataset(USP_SHIFTS, TBL_SHIFTS, new object[] { terminal, date.ToString("yyyy-MM-dd") });
                if (ds.Tables[TBL_SHIFTS] != null && ds.Tables[TBL_SHIFTS].Rows.Count > 0)
                {
                    shifts.Merge(ds);
                }
            }
            catch (ApplicationException ex) { throw ex; }
            catch (Exception ex) { throw new ApplicationException("Unexpected exception creating shift list.", ex); }
            return(shifts);
        }
Ejemplo n.º 2
0
    protected void OnButtonCommand(object sender, CommandEventArgs e)
    {
        //Event handler for view button clicked
        try {
            //Change view to Viewer and reset to clear existing data
            Master.Viewer.Reset();

            //Get parameters for the query
            string _start    = this.ddpPickups.ToDate.ToString("yyyy-MM-dd");
            string _terminal = this.cboTerminal.SelectedValue;
            int    _shift    = int.Parse(this.cboShift.SelectedValue);
            string _header   = "Shift Report";

            //Initialize control values
            LocalReport report = Master.Viewer.LocalReport;
            report.DisplayName          = this.mTitle;
            report.EnableExternalImages = true;
            EnterpriseGateway enterprise = new EnterpriseGateway();
            DataSet           ds         = new DataSet(this.mDSName);
            DataSet           _ds        = enterprise.FillDataset(this.mUSPName, mTBLName, new object[] { _terminal, _start, _shift });
            if (_ds.Tables[mTBLName] == null)
            {
                _ds.Tables.Add(mTBLName);
            }
            string filter = "";
            switch (this.cboType.SelectedValue.ToLower())
            {
            case "tsort": filter = "FreightType = 'Tsort'"; _header = "Tsort"; break;

            case "returns": filter = "FreightType = 'Returns'"; _header = "Return"; break;

            case "both": filter = null; _header = "Tsort & Return"; break;
            }
            DataRow[] rows = _ds.Tables[mTBLName].Select(filter);
            ds.Merge(rows);
            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 terminalID  = new ReportParameter("TerminalID", _terminal);
                ReportParameter start       = new ReportParameter("Date", _start);
                ReportParameter shift       = new ReportParameter("ShiftNumber", _shift.ToString());
                ReportParameter terminal    = new ReportParameter("SortedLocation", this.cboTerminal.SelectedItem.Text);
                ReportParameter freigthType = new ReportParameter("FreightType", _header);

                ShiftDataset shiftDS = new ShiftDataset();
                shiftDS.Merge(enterprise.GetShifts(_terminal, this.ddpPickups.ToDate));
                ShiftDataset.ShiftTableRow row           = (ShiftDataset.ShiftTableRow)shiftDS.ShiftTable.Select("NUMBER='" + this.cboShift.SelectedValue.ToString() + "'")[0];
                ReportParameter            shiftTimeIn   = new ReportParameter("ShiftTimeIn", row.StartTime.ToString("yyyy-MM-dd"));
                ReportParameter            shiftTimeOut  = new ReportParameter("ShiftTimeOut", row.EndTime.ToString("yyyy-MM-dd"));
                ReportParameter            shiftBreak    = new ReportParameter("ShiftBreak", row.BreakTime.ToString("yyyy-MM-dd"));
                ReportParameter            shiftProdTime = new ReportParameter("ProductionTime", string.Concat(Decimal.Truncate((row.ProductionTime / 60)), ":", Convert.ToString(row.ProductionTime % 60)));
                report.SetParameters(new ReportParameter[] { terminalID, start, shift, terminal, shiftTimeIn, shiftTimeOut, shiftBreak, shiftProdTime, freigthType });

                //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=Shift.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); }
    }