using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using ns_MoneyFlow.DAL; using Stimulsoft.Controls; using Stimulsoft.Base; using Stimulsoft.Report; using System.Data; using Stimulsoft.Report.Components; using System.Data.SqlClient; using System.IO; using System.Data.Sql; using Stimulsoft.Report.Dictionary; using Stimulsoft.Report.Export; using Stimulsoft.Base.Services; using System.Web.Configuration; using System.Web.Security; using Stimulsoft.Report.Components; using Stimulsoft.Base.Drawing; using Stimulsoft.Report.Web; using System.Drawing; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { btnOk.Enabled = false; int Count = 0; SqlDataReader sdrSelectedComp = null; try { cs_Company.cs_ReportingCode objSelActComp = new cs_Company.cs_ReportingCode(); objSelActComp.Login = (string)Session["UserID"]; objSelActComp.LoginPassword = (string)Session["Password"]; //finds the list of companies that the user has access and are active and have ITRNum ITR4 and above sdrSelectedComp = objSelActComp.m_ListActvCompForUsrAboveITR4((string)Session["UserID"], ""); } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=2&Page=" + Page.Title); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=1&Page=" + Page.Title); } if (sdrSelectedComp.HasRows) { sdrSelectedComp.Read(); Count = Convert.ToInt32(sdrSelectedComp["RecCount"].ToString()); try { cs_Company.cs_CompMaster objIsCompActive = new cs_Company.cs_CompMaster(); objIsCompActive.Login = (string)Session["UserID"]; objIsCompActive.LoginPassword = (string)Session["Password"]; //finds if the selected company is active or not. bool Comp_Active = objIsCompActive.m_IsCompActive((int)Session["LoggedinComp"]); if (Comp_Active == true) { txtCompany.Text = Session["CompanyName"].ToString(); hdfdlCompNum.Value = ((int)Session["LoggedinComp"]).ToString(); if (Count == 1) { txtCompany.Enabled = false; } else { txtCompany.Enabled = true; } ListLedgerTypesForUser(); chkProfitCenter.Checked = false; chkProfitCenter.Enabled = false; } else { if (Count > 0) { txtCompany.Text = ""; txtCompany.Enabled = true; } else { string myStringVariable = "There are no other active companies with ITR4 or above that you have access to. To view the COA of the company " + "\"" + txtCompany.Text.Trim() + "\"" + " Please see the COA report."; Page page = HttpContext.Current.Handler as Page; ScriptManager.RegisterClientScriptBlock(page, this.GetType(), "err_msg", "alert('" + myStringVariable + "');window.location='../../Home.aspx';", true); } } } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=2&Page=" + Page.Title); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=1&Page=" + Page.Title); } } else { string myStringVariable = "There are no other active companies with ITR4 or above that you have access to. To view the COA of the company " + "\"" + txtCompany.Text.Trim() + "\"" + " Please see the COA report."; Page page = HttpContext.Current.Handler as Page; ScriptManager.RegisterClientScriptBlock(page, this.GetType(), "err_msg", "alert('" + myStringVariable + "');window.location='../../Home.aspx';", true); } SelCompDates(); } else { //Autocomplete list for Company is called to select Company from the existing database if (Request.Form["__EVENTTARGET"] == "Company" && Request.Form["__EVENTARGUMENT"] != null) { string Selected_Comp = Request.Form["__EVENTARGUMENT"]; txtCompany.Text = Selected_Comp; SqlDataReader sdrSelectedComp = null; try { //finds the list of companies that the user has access and are active and have ITRNum ITR4 and above cs_Company.cs_ReportingCode objSelActComp = new cs_Company.cs_ReportingCode(); objSelActComp.Login = (string)Session["UserID"]; objSelActComp.LoginPassword = (string)Session["Password"]; sdrSelectedComp = objSelActComp.m_ListActvCompForUsrAboveITR4((string)Session["UserID"], Selected_Comp); } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=2&Page=" + Page.Title); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=1&Page=" + Page.Title); } if (sdrSelectedComp.HasRows) { sdrSelectedComp.Read(); hdfdlCompNum.Value = sdrSelectedComp["CompanyNum"].ToString(); ListLedgerTypesForUser(); SelCompDates(); chkProfitCenter.Checked = false; chkProfitCenter.Enabled = false; } } } } protected void txtCompany_TextChanged(object sender, EventArgs e) { //It finds all active users that start with the search text by using the stored procedure uspListActvCompForUsrAboveITR4. SqlDataReader sdrListCompanies = null; try { cs_Company.cs_ReportingCode objListAllCompForUser = new cs_Company.cs_ReportingCode(); objListAllCompForUser.Login = (string)(HttpContext.Current.Session["UserID"]); objListAllCompForUser.LoginPassword = (string)(HttpContext.Current.Session["Password"]); sdrListCompanies = objListAllCompForUser.m_ListActvCompForUsrAboveITR4(HttpContext.Current.Session["UserID"].ToString(), txtCompany.Text.Trim()); } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=2&Page=" + Page.Title); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=1&Page=" + Page.Title); } if (sdrListCompanies.HasRows) { ddlLedgerType.Enabled = true; txtDate.Enabled = true; } else { if (hdfdlCompNum.Value != "") { SqlDataReader sdrUserLockingComp = null; txtCompany.Focus(); //Find the User who is locking the company. try { cs_Company.cs_CompLock objUserLockingComp = new cs_Company.cs_CompLock(); objUserLockingComp.Login = (string)Session["UserID"]; objUserLockingComp.LoginPassword = (string)Session["Password"]; sdrUserLockingComp = objUserLockingComp.m_SelUserLockingComp(Convert.ToInt32(hdfdlCompNum.Value)); } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=2&Page=" + Page.Title); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=1&Page=" + Page.Title); } if (sdrUserLockingComp.HasRows) { sdrUserLockingComp.Read(); string Admin_UserID = sdrUserLockingComp["UserID"].ToString(); if (Admin_UserID.ToUpper() == Session["UserID"].ToString().ToUpper()) { ddlLedgerType.Enabled = true; txtDate.Enabled = true; } else { ddlLedgerType.Enabled = false; txtDate.Enabled = false; } } else { txtCompany.Text = ""; txtCompany.Focus(); ddlLedgerType.Enabled = false; txtDate.Enabled = false; btnOk.Enabled = false; } } else { txtCompany.Text = ""; txtCompany.Focus(); ddlLedgerType.Enabled = false; txtDate.Enabled = false; btnOk.Enabled = false; } } } //when the DDL ledgertype is changes protected void ddlLedgerType_SelectedIndexChanged(object sender, EventArgs e) { //Find the name of the page the user is trying to access string[] file = Request.CurrentExecutionFilePath.Split('/'); string PageName = file[file.Length - 1]; DataSet dsLedgerType = null; cs_GeneralLedger.cs_GLCreation objLedgerType = new cs_GeneralLedger.cs_GLCreation(); objLedgerType.Login = (string)Session["UserID"]; objLedgerType.LoginPassword = (string)Session["Password"]; try { // Lists the ledger types for the selected user. dsLedgerType = objLedgerType.m_ListLedgerTypesForUser((string)Session["UserID"], PageName, Convert.ToInt32(hdfdlCompNum.Value), (string)Session["UserType"], 2); } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=2&Page=" + Page.Title); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=1&Page=" + Page.Title); } //if there are many LedgerTypes in the table for that company. if (dsLedgerType.Tables[0].Rows.Count > 1) { string Configured = "False"; foreach (DataRow dr in dsLedgerType.Tables[0].Rows) { //if the company does not have Configured Budget if (Configured == "False") { // if the Selected value is Same as the that in the Table and if it is Configured if (ddlLedgerType.SelectedValue.ToString() == dr["LedgerType"].ToString() && dr["IsConfigured"].ToString() == "True") { Configured = "True"; } } } //if its Configured then second level password popup is opened if (Configured == "True") { string SecPwdPagePath = System.Web.VirtualPathUtility.MakeRelative(System.Web.HttpContext.Current.Request.CurrentExecutionFilePath, "~/SecondLevelPassword.aspx"); Session["PreviousPage"] = Request.UrlReferrer.AbsolutePath; string jsOpenSecLvlPwdPage = ""; jsOpenSecLvlPwdPage = "modalWin('" + SecPwdPagePath + "?Page='," + "'BalanceSheetReport', 800,300);"; if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "OpenSecLvlPwdPage")) { ClientScript.RegisterClientScriptBlock(this.GetType(), "OpenSecLvlPwdPage", jsOpenSecLvlPwdPage, true); } } } if (ddlLedgerType.SelectedItem.Text == "Select Ledger Type" || txtCompany.Text.Trim() == "" || txtDate.Text.Trim() == "") { btnOk.Enabled = false; } else { btnOk.Enabled = true; btnOk.Focus(); } } protected void txtDate_TextChanged(object sender, EventArgs e) { } protected void btnOk_Click(object sender, EventArgs e) { System.Globalization.DateTimeFormatInfo dateInfodd = new System.Globalization.DateTimeFormatInfo(); dateInfodd.ShortDatePattern = "dd/MM/yyyy"; System.Globalization.DateTimeFormatInfo dateInfomm = new System.Globalization.DateTimeFormatInfo(); dateInfomm.ShortDatePattern = "MM/dd/yyyy"; string Date = ""; if (hdfldDataEntryFormat.Value == "MM/dd/yyyy") { DateTime StartDate = Convert.ToDateTime(txtDate.Text, dateInfomm); Date = Convert.ToDateTime(StartDate).ToString("dd/MM/yyyy"); } else { Date = txtDate.Text; } try { cs_GeneralLedger.cs_GLReports objBalanceSheetRep = new cs_GeneralLedger.cs_GLReports(); objBalanceSheetRep.Login = (string)Session["UserID"]; objBalanceSheetRep.LoginPassword = (string)Session["Password"]; cs_ConnectionString ConStr = new cs_ConnectionString(); string SqldBConnectString = ConStr.ConnectionString; StiReport report = new StiReport(); report.Dictionary.Clear(); report.Dictionary.Databases.Clear(); report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("SQLConnection", SqldBConnectString)); DataSet dsBSReport = objBalanceSheetRep.m_BalanceSheetReport(26, "01/07/2013", "GL",false, "Admin12"); string Reporting_Format = ""; SqlDataReader sdrSelReptSettings = null; try { //finds the reporting settings for the selected company from the table tblCompReptSettings. cs_Company.cs_CompanyAcctSettings objSelReptSettings = new cs_Company.cs_CompanyAcctSettings(); objSelReptSettings.Login = (string)Session["UserID"]; objSelReptSettings.LoginPassword = (string)Session["Password"]; sdrSelReptSettings = objSelReptSettings.m_SelCompReptSettings(Convert.ToInt32(hdfdlCompNum.Value), Date); } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=2&Page=" + Page.Title); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=1&Page=" + Page.Title); } if (sdrSelReptSettings.HasRows) { sdrSelReptSettings.Read(); Reporting_Format = Enum.GetName(typeof(cs_Company.cs_CompanyAcctSettings.ReportDisplayFormat), Convert.ToInt32(Convert.ToBoolean(sdrSelReptSettings["ReportFormat"].ToString()))); } report.Load(HttpContext.Current.Request.MapPath("StimReports\\BS_Horz_NoPC2.mrt")); dsBSReport.Tables[0].TableName = "dtBSRepTitleDetails"; dsBSReport.Tables[1].TableName = "dtBSRepLiabs"; dsBSReport.Tables[2].TableName = "dtBSRepAssets"; report.DataSources.Clear(); report.RegData(dsBSReport.Tables["dtBSRepTitleDetails"]); report.RegData(dsBSReport.Tables["dtBSRepLiabs"]); report.RegData(dsBSReport.Tables["dtBSRepAssets"]); report.Dictionary.Synchronize(); DataTable dt = dsBSReport.Tables[0]; DataRow dr = dt.Rows[0]; if (dr["CompLogoPath"].ToString() != "") { if (File.Exists(Server.MapPath(dr["CompLogoPath"].ToString()))) { ((Stimulsoft.Report.Components.StiImage)report.GetComponentByName("stiImgCompLogo")).Image = Stimulsoft.Base.Drawing.StiImageFromURL.LoadBitmap(Server.MapPath(dr["CompLogoPath"].ToString())); } } if (Convert.ToBoolean(dr["DispPrevYrFig"].ToString()) == false) { ((Stimulsoft.Report.Components.StiText)report.GetComponentByName("stitxtPrevYrLiab")).Enabled = false; ((Stimulsoft.Report.Components.StiText)report.GetComponentByName("stitxtPrevYrAsset")).Enabled = false; ((Stimulsoft.Report.Components.StiVerticalLinePrimitive)report.GetComponentByName("stiVlpPrevYrBalLiab")).Enabled = false; ((Stimulsoft.Report.Components.StiVerticalLinePrimitive)report.GetComponentByName("stiVlpPrevYrBalAsset")).Enabled = false; } MultiView1.ActiveViewIndex++; report.Render(); // StiWebViewer1.ZoomPercent = 75; // StiWebViewer1.Report = report; StiReportResponse.ResponseAsPdf(this.Page, report, false); StiOptions.Web.AllowUseResponseFlush = false; //StiPdfExportSettings abc = new StiPdfExportSettings(); } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=2&Page=" + Page.Title); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=1&Page=" + Page.Title); } } [System.Web.Services.WebMethod()] [System.Web.Script.Services.ScriptMethod()] public static List GetCompletionList(string prefixText) { List lsCompanies = new List(); //It finds all active users that start with the search text by using the stored procedure uspListActvCompForUsrAboveITR4. try { cs_Company.cs_ReportingCode objListAllCompForUser = new cs_Company.cs_ReportingCode(); objListAllCompForUser.Login = (string)(HttpContext.Current.Session["UserID"]); objListAllCompForUser.LoginPassword = (string)(HttpContext.Current.Session["Password"]); SqlDataReader sdrListCompanies = objListAllCompForUser.m_ListActvCompForUsrAboveITR4(HttpContext.Current.Session["UserID"].ToString(), prefixText); if (sdrListCompanies.HasRows) while (sdrListCompanies.Read()) { lsCompanies.Add(sdrListCompanies[0].ToString()); } } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); } return (lsCompanies); } private void ListLedgerTypesForUser() { //Find the name of the page the user is trying to access string[] file = Request.CurrentExecutionFilePath.Split('/'); string PageName = file[file.Length - 1]; DataSet dsLedgerType = null; cs_GeneralLedger.cs_GLCreation objLedgerType = new cs_GeneralLedger.cs_GLCreation(); objLedgerType.Login = (string)Session["UserID"]; objLedgerType.LoginPassword = (string)Session["Password"]; try { // lists the ledger types for the selected user. dsLedgerType = objLedgerType.m_ListLedgerTypesForUser((string)Session["UserID"], PageName, (int)Session["LoggedinComp"], (string)Session["UserType"], 2); } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=2&Page=" + Page.Title); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=1&Page=" + Page.Title); } //If the table has more than one Row. if (dsLedgerType.Tables[0].Rows.Count > 1) { ddlLedgerType.DataTextField = "LedgerName"; ddlLedgerType.DataValueField = "LedgerType"; ddlLedgerType.DataSource = dsLedgerType; ddlLedgerType.DataBind(); ddlLedgerType.Items.Insert(0, new ListItem("Select Ledger Type", "Select Ledger Type")); } else if (dsLedgerType.Tables[0].Rows.Count == 1) { ddlLedgerType.DataTextField = "LedgerName"; ddlLedgerType.DataValueField = "LedgerType"; ddlLedgerType.DataSource = dsLedgerType; ddlLedgerType.DataBind(); ddlLedgerType.Enabled = false; string Configured = "False"; foreach (DataRow dr in dsLedgerType.Tables[0].Rows) { //if the company does not have Configured Budget if (Configured == "False") { // if the Selected value is Same as the that in the Table and if it is Configured if (ddlLedgerType.SelectedValue.ToString() == dr["LedgerType"].ToString() && dr["IsConfigured"].ToString() == "True") { Configured = "True"; } } } //if its Configured then second level password popup is opened if (Configured == "True") { string SecPwdPagePath = System.Web.VirtualPathUtility.MakeRelative(System.Web.HttpContext.Current.Request.CurrentExecutionFilePath, "~/SecondLevelPassword.aspx"); Session["PreviousPage"] = Request.UrlReferrer.AbsolutePath; string jsOpenSecLvlPwdPage = ""; jsOpenSecLvlPwdPage = "modalWin('" + SecPwdPagePath + "?Page='," + "'BalanceSheetReport', 800,300);"; if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "OpenSecLvlPwdPage")) { ClientScript.RegisterClientScriptBlock(this.GetType(), "OpenSecLvlPwdPage", jsOpenSecLvlPwdPage, true); } } } } private void SelCompDates() { SqlDataReader sdrCompDates = null; try { //finds the Earliest Start Date,Date Entry format for the selected company. cs_Company.cs_CompMaster objSelCompDates = new cs_Company.cs_CompMaster(); objSelCompDates.Login = (string)Session["UserID"]; objSelCompDates.LoginPassword = (string)Session["Password"]; sdrCompDates = objSelCompDates.m_SelCompDates(Convert.ToInt32(hdfdlCompNum.Value)); if (sdrCompDates.HasRows) { sdrCompDates.Read(); hdfldDataEntryFormat.Value = sdrCompDates["DataEntryDateFormat"].ToString(); ajxcalDate.Format = hdfldDataEntryFormat.Value; txtDate.ToolTip = "Enter date in format: '" + hdfldDataEntryFormat.Value + "'"; if (hdfldDataEntryFormat.Value == "dd/MM/yyyy") { hdfldDateMaintined.Value = Convert.ToDateTime(sdrCompDates["DateFromWhenDataIsMaintained"]).ToString("dd/MM/yyyy"); } if (hdfldDataEntryFormat.Value == "MM/dd/yyyy") { hdfldDateMaintined.Value = Convert.ToDateTime(sdrCompDates["DateFromWhenDataIsMaintained"]).ToString("MM/dd/yyyy"); } } } catch (SqlException ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=2&Page=" + Page.Title); } catch (Exception ex) { ErrorExtension ErrorExtension = new ErrorExtension(); ErrorExtension.ToLogString(ex, ""); Response.Redirect("../../ErrorPage.aspx?Error=1&Page=" + Page.Title); } } }