public void Page_Load(object sender, System.EventArgs e) { Context.User = Streamline.BaseLayer.StreamlinePrinciple(); // log user ApplicationLog.WriteTrace(string.Format("Page request (for, from, as): {0}, {1}, {2}", GetType().ToString(), Context.User.Identity.Name, WindowsIdentity.GetCurrent().Name)); rm = ConfigureResources(Request); InitZfComponents(); }
/// <summary> /// Function called when a user session object is nuked from the cache. /// Logs off the user. /// </summary> /// <param name="key"></param> /// <param name="val"></param> /// <param name="reason"></param> private static void UserSessionExpiryCallback(string key, object val, CacheItemRemovedReason reason) { try { ZfLib.UserSession zfUserSession = (ZfLib.UserSession)val; // we cannot user "FromName" because this function doesn't run as the Zetafax user, // and therefore may not have permission to access the user's files to read information // such as the user's from name string strUser = zfUserSession.UserInDir; int nEnd = strUser.LastIndexOf('\\', strUser.LastIndexOf('\\') - 1); int nStart = 1 + strUser.LastIndexOf('\\', nEnd - 1); strUser = strUser.Substring(nStart, nEnd - nStart); ApplicationLog.WriteTrace("Cache remove: " + strUser.ToLower()); zfUserSession.Logoff(); } catch (Exception ex) { // this error usually occurs if NT authentication is used to protect the Zetafax // directories and the ASPNET process doesn't have authority to release the LOK file. ApplicationLog.WriteTrace(ApplicationLog.FormatException(ex, "Failed to log off user session")); } }
/// <summary> /// Find the API objects in the cache, or create them if they don't exist. /// <remarks> /// We only need one instance of the API object in the cache, /// but each user has their own session object. /// If the main API object expires, the session objects expire as well /// </remarks> /// <param name="strZfName"> /// The Zetafax user name of the session we wish to retrieve from the cache. /// </param> /// </summary> private void InitZfAPIFromCache(string strZfName) { string strFromName = string.Empty; zfAPI = Cache[CACHE_API] as ZfLib.ZfAPI; zfUserSession = Cache[CACHE_SESSION + "_" + strZfName] as ZfLib.UserSession; try { // proper test to see if object is valid strFromName = zfUserSession.FromName; } catch (Exception) { } if (zfAPI != null && zfUserSession != null && strFromName != string.Empty) { // found in cache - nothing more to do! ApplicationLog.WriteTrace("Cache hit: " + strFromName); return; } ApplicationLog.WriteTrace("Cache miss: " + strZfName); TimeSpan ts = TimeSpan.FromMinutes(ZetafaxConfiguration.APICacheExpiresInMins); if (zfAPI == null) { CreateZfAPIObject(); Cache.Insert(CACHE_API, zfAPI, null, Cache.NoAbsoluteExpiration, ts); } zfUserSession = zfAPI.Logon(strZfName, fExclusive_Logon); ApplicationLog.WriteTrace("Logged on: " + strZfName); Cache.Insert(CACHE_SESSION + "_" + strZfName, zfUserSession, new CacheDependency(null, new string[] { CACHE_API }), Cache.NoAbsoluteExpiration, ts, CacheItemPriority.Normal, new CacheItemRemovedCallback(UserSessionExpiryCallback)); }
/// <summary> /// Load Report Depending On Invoice Type /// </summary> private ReportBase LoadReport() { // Configure the Session variables used to pass data to the report NameValueCollection reportParams = new NameValueCollection(); //------------------------------------------------------------------------------------- // Job/Collect-Drops/References/Demurrages Section //------------------------------------------------------------------------------------- Facade.IInvoice facInv = new Facade.Invoice(); DataSet dsInv = null; if (m_isUpdate) { dsInv = facInv.GetJobsForInvoiceId(Convert.ToInt32(lblInvoiceNo.Text)); } else { dsInv = facInv.GetJobsToInvoice(m_jobIdCSV); } reportParams.Add("JobIds", m_jobIdCSV); reportParams.Add("ExtraIds", m_extraIdCSV); //------------------------------------------------------------------------------------- // Param Section //------------------------------------------------------------------------------------- // Fuel Type & Rate eInvoiceDisplayMethod fuelType; decimal newRate = 0; if (chkIncludeFuelSurcharge.Checked) { reportParams.Add("Fuel", "Include"); // Pass The New Rate To Report if so... newRate = Convert.ToDecimal(txtFuelSurchargeRate.Text); reportParams.Add("FuelRate", newRate.ToString()); // Pass FuelSurchargeType fuelType = (eInvoiceDisplayMethod)Enum.Parse(typeof(eInvoiceDisplayMethod), rdoFuelSurchargeType.SelectedValue); reportParams.Add("FuelType", fuelType.ToString()); } // Override if (chkOverride.Checked) { reportParams.Add("Override", "Include"); reportParams.Add("OverrideVAT", txtOverrideVAT.Text); reportParams.Add("OverrideNET", txtOverrideNetAmount.Text); reportParams.Add("OverrideGross", txtOverrideGrossAmount.Text); reportParams.Add("OverrideReason", txtOverrideReason.Text); } // PODs if (chkIncludePODs.Checked) { reportParams.Add("PODs", "Include"); } // References if (chkIncludeReferences.Checked) { reportParams.Add("References", "Include"); } // Job if (chkJobDetails.Checked) { reportParams.Add("JobDetails", "Include"); // Demuragge if (chkIncludeDemurrage.Checked) { reportParams.Add("Demurrage", "Include"); // Demurrage Type try { eInvoiceDisplayMethod demurrageType = (eInvoiceDisplayMethod)Enum.Parse(typeof(eInvoiceDisplayMethod), rdoDemurrageType.SelectedValue); reportParams.Add("DemurrageType", demurrageType.ToString()); } catch (Exception) { } } } if (pnlExtras.Visible) { reportParams.Add("ExtraIds", Convert.ToString(ViewState["ExtraIdCSV"])); reportParams.Add("Extras", "Include"); } // Extra details if (chkExtraDetails.Visible && chkExtraDetails.Checked) { reportParams.Add("ExtraDetail", "include"); } // Self Bill Invoice Number if ((eInvoiceType)Enum.Parse(typeof(eInvoiceType), lblInvoiceType.Text) == eInvoiceType.SelfBill) { reportParams.Add("InvoiceType", "SelfBill"); reportParams.Add("SelfBillInvoiceNumber", txtClientSelfBillInvoiceNumber.Text); } else { reportParams.Add("InvoiceType", "Normal"); } // Client Name & Id if (m_isUpdate) { Facade.IInvoice facClient = new Facade.Invoice(); DataSet ds = facClient.GetClientForInvoiceId(Convert.ToInt32(lblInvoiceNo.Text)); try { reportParams.Add("Client", Convert.ToString(ds.Tables[0].Rows[0]["Client"])); reportParams.Add("ClientId", Convert.ToString(ds.Tables[0].Rows[0]["ClientId"])); m_clientId = int.Parse(ds.Tables[0].Rows[0]["ClientId"].ToString()); if (!chkPostToExchequer.Checked) { btnSendToAccounts.Visible = true; pnlInvoiceDeleted.Visible = true; } } catch { } } else { if (Convert.ToString(Session["ClientName"]) != "") { reportParams.Add("Client", Convert.ToString(Session["ClientName"])); } if (Convert.ToString(Session["ClientId"]) != "") { reportParams.Add("ClientId", Convert.ToString(Session["ClientId"])); } if (m_clientId == 0) { m_clientId = int.Parse(Session["ClientId"].ToString()); } else { Facade.IOrganisation facOrg = new Facade.Organisation(); Entities.Organisation enOrg = new Entities.Organisation(); enOrg = facOrg.GetForIdentityId(m_clientId); reportParams.Add("Client", enOrg.OrganisationName.ToString()); reportParams.Add("ClientId", m_clientId.ToString()); } } // Date Range if (Convert.ToDateTime(Session["StartDate"]).Date != DateTime.MinValue) { reportParams.Add("startDate", Convert.ToDateTime(Session["StartDate"]).ToString("dd/MM/yy")); } if (Convert.ToDateTime(Session["EndDate"]).Date != DateTime.MinValue) { reportParams.Add("endDate", Convert.ToDateTime(Session["EndDate"]).ToString("dd/MM/yy")); } // Invoice Id if (lblInvoiceNo.Text != "To Be Issued ... (This invoice has not yet been saved, add invoice to allocate Invoice No.)") { reportParams.Add("invoiceId", lblInvoiceNo.Text); } else { reportParams.Add("invoiceId", "0"); } // Posted To Accounts if (chkPostToExchequer.Checked) { reportParams.Add("Accounts", "true"); } int vatNo = 0; decimal vatRate = 0.00M; // VAT Rate facInv.GetVatRateForVatType(eVATType.Standard, dteInvoiceDate.SelectedDate.Value, out vatNo, out vatRate); reportParams.Add("VATrate", vatRate.ToString()); // Invoice Date reportParams.Add("InvoiceDate", dteInvoiceDate.SelectedDate.Value.ToShortDateString()); //------------------------------------------------------------------------------------- // Load Report Section //------------------------------------------------------------------------------------- Session[Orchestrator.Globals.Constants.ReportTypeSessionVariable] = eReportType.Invoice; Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable] = dsInv; Session[Orchestrator.Globals.Constants.ReportDataSessionSortVariable] = rdoSortType.SelectedItem.Text.Replace(" ", ""); Session[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable] = "Table"; Session[Orchestrator.Globals.Constants.ReportParamsSessionVariable] = reportParams; Orchestrator.Reports.ReportBase activeReport = null; eReportType reportType = 0; reportType = (eReportType)Session[Orchestrator.Globals.Constants.ReportTypeSessionVariable]; try { activeReport = new Orchestrator.Reports.Invoicing.rptInvoice(); } catch (NullReferenceException e) { Response.Write(e.Message); Response.Flush(); return(null); } if (activeReport != null) { try { ApplicationLog.WriteTrace("Getting Data From Session Variable"); DataView view = null; DataSet ds = (DataSet)Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]; string sortExpression = (string)Session[Orchestrator.Globals.Constants.ReportDataSessionSortVariable]; ApplicationLog.WriteTrace("sortExpression ::" + sortExpression); try { if (sortExpression.Length > 0) { view = new DataView(ds.Tables[0]); view.Sort = sortExpression; activeReport.DataSource = view; } else { activeReport.DataSource = ds; } activeReport.DataMember = (string)Session[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable]; } catch (Exception eX) { this.Trace.Write("Err1:" + eX.Message); ApplicationLog.WriteTrace("GetReport :: Err1:" + eX.Message); } activeReport.Document.Printer.PrinterName = string.Empty; activeReport.Document.Printer.PaperKind = System.Drawing.Printing.PaperKind.A4; //activeReport.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.A4; //activeReport.PrintWidth = activeReport.PageSettings.PaperWidth - (activeReport.PageSettings.Margins.Right + activeReport.PageSettings.Margins.Left); activeReport.Run(false); } catch (Exception e) { Response.Write(e.Message); Response.Flush(); return(null); } } Session[Orchestrator.Globals.Constants.ReportSessionVariable] = activeReport; return(activeReport); }
private ReportBase GetReport(HttpSessionState session, TraceContext trace, string reportParametersSessionKey, out bool noData) { ReportBase activeReport = null; noData = false; eReportType reportType = 0; bool enforceDataExistence = false; bool useReportParametersKey = !string.IsNullOrWhiteSpace(reportParametersSessionKey); Hashtable htReportInformation = null; try { if (useReportParametersKey) { htReportInformation = (Hashtable)session[reportParametersSessionKey]; reportType = (eReportType)htReportInformation[Orchestrator.Globals.Constants.ReportTypeSessionVariable]; } else { reportType = (eReportType)session[Orchestrator.Globals.Constants.ReportTypeSessionVariable]; } activeReport = Orchestrator.Reports.Utilities.GetActiveReport(reportType, reportParametersSessionKey, out enforceDataExistence); } catch (Exception ex) { Utilities.LastError = ex; return(null); } if (activeReport != null) { try { ApplicationLog.WriteTrace("Getting Data From Session Variable"); DataView view = null; var sortExpression = string.Empty; object ds = null; if (useReportParametersKey) { if (htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionTableVariable] is DataSet) { ds = (DataSet)htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]; } else { ds = htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]; } sortExpression = (string)htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionSortVariable]; } else { if (session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable] is DataSet) { ds = (DataSet)session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]; } else { ds = session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]; } sortExpression = (string)session[Orchestrator.Globals.Constants.ReportDataSessionSortVariable]; } ApplicationLog.WriteTrace("sortExpression ::" + sortExpression); try { if (sortExpression.Length > 0) { if (ds is DataSet) { view = new DataView(((DataSet)ds).Tables[0]); } view.Sort = sortExpression; activeReport.DataSource = view; } else { activeReport.DataSource = ds; } if (enforceDataExistence && ds != null && ds is DataSet && ((DataSet)ds).Tables.Count > 0 && ((DataSet)ds).Tables[0].Rows.Count == 0) { noData = true; return(null); } if (useReportParametersKey) { activeReport.DataMember = (string)htReportInformation[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable]; } else { activeReport.DataMember = (string)session[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable]; } } catch (Exception eX) { Utilities.LastError = eX; trace.Write("Err1:" + eX.Message); ApplicationLog.WriteTrace("GetReport :: Err1:" + eX.Message); } activeReport.SetReportCulture(); activeReport.Run(false); } catch (Exception e) { Utilities.LastError = e; return(null); } } trace.Write("Returning Report"); ApplicationLog.WriteTrace("GetReport :: Returning Report"); return(activeReport); }
private Orchestrator.Reports.ReportBase GetManifestReport() { Orchestrator.Reports.ReportBase activeReport = null; Orchestrator.Reports.IDriverRunSheet report = Orchestrator.Application.GetSpecificImplementation <IDriverRunSheet>(); if (report != null) { activeReport = (Orchestrator.Reports.ReportBase)report; } else { activeReport = new Orchestrator.Reports.rptDriverRunSheet(); } activeReport.Document.Printer.PrinterName = string.Empty; activeReport.Document.Printer.PaperKind = System.Drawing.Printing.PaperKind.A4; if (activeReport != null) { try { ApplicationLog.WriteTrace("Getting Data From Session Variable"); DataView view = null; string sortExpression = string.Empty; object ds = null; //if (useReportParametersKey) //{ // if (htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionTableVariable] is DataSet) // ds = (DataSet)htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]; // else // ds = htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]; // sortExpression = (string)htReportInformation[Orchestrator.Globals.Constants.ReportDataSessionSortVariable]; //} //else //{ if (Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable] is DataSet) { ds = (DataSet)Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]; } else { ds = Session[Orchestrator.Globals.Constants.ReportDataSessionTableVariable]; } sortExpression = (string)Session[Orchestrator.Globals.Constants.ReportDataSessionSortVariable]; //} ApplicationLog.WriteTrace("sortExpression ::" + sortExpression); try { if (sortExpression.Length > 0) { if (ds is DataSet) { view = new DataView(((DataSet)ds).Tables[0]); } view.Sort = sortExpression; activeReport.DataSource = view; } else { activeReport.DataSource = ds; } //if (enforceDataExistence && ds != null) //{ // if (ds is DataSet) // if (((DataSet)ds).Tables.Count > 0 && ((DataSet)ds).Tables[0].Rows.Count == 0) // { // // There is no data to display so redirect to a page. // Response.Clear(); // Server.Transfer("blankReport.aspx"); // } //} //if (useReportParametersKey) //{ // activeReport.DataMember = (string)htReportInformation[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable]; //} //else //{ activeReport.DataMember = (string)Session[Orchestrator.Globals.Constants.ReportDataMemberSessionVariable]; //} } catch (Exception eX) { Utilities.LastError = eX; this.Trace.Write("Err1:" + eX.Message); ApplicationLog.WriteTrace("GetReport :: Err1:" + eX.Message); } activeReport.SetReportCulture(); activeReport.Run(false); } catch (Exception e) { Utilities.LastError = e; return(null); } } this.Trace.Write("Returning Report"); ApplicationLog.WriteTrace("GetReport :: Returning Report"); return(activeReport); }