private bool ReadXMLConfiguration(String reportType)
        {
            //String folderPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
            //TextBox1.Text += folderPath;
            bool isReadingTables = false;
            bool isReadingReportParameter = false;
            bool isReadingTableParameter = false;
            bool isReadingTableRelationParameter = false;

            try
            {
                XmlTextReader reader = new XmlTextReader(dir.FullName + "\\" + reportType + ".xml");
                String value = null;
                TextBox1.Text += dir.FullName + "\\"+ reportType +".xml";
                Report report = null;
                ReportTable reportTable = null;
                ReportTableParameter tableParam = null;
                ReportTableRelationParameter rtrParameter = null;
                ReportParameter rpParam = null;

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element: // The node is an element.
                            if (reader.Name == "Report")
                            {
                                report = new Report();
                                TextBox1.Text += "\n <Report>";
                            }
                            else if (reader.Name == "ReportParameters")
                            {
                                isReadingReportParameter = true;
                                TextBox1.Text += "\n <ReportParameters>";
                            }
                            else if (reader.Name == "Table")
                            {
                                //isReadingTableParameter = true;
                                isReadingTables = true;
                                reportTable = new ReportTable();
                                TextBox1.Text += "\n <Table>";
                            }
                            else if (reader.Name == "Parameter")
                            {
                                if (isReadingReportParameter)
                                    rpParam = new ReportParameter();
                                else if (isReadingTableRelationParameter)
                                    rtrParameter = new ReportTableRelationParameter();
                                else
                                    tableParam = new ReportTableParameter();
                                TextBox1.Text += "\n <Parameter>";
                            }
                            break;
                        case XmlNodeType.Text: //Display the text in each element.
                            value = reader.Value;
                            break;
                        case XmlNodeType.EndElement: //Display the end of the element.
                            if (reader.Name == "ID")
                            {
                                report.ID = value;
                                TextBox1.Text += "\n <ID>" + value + "</ID>";
                            }
                            else if (reader.Name == "Name")
                            {
                                if (isReadingReportParameter)
                                    TextBox1.Text += "\nisReadingReportParameter";
                                else if (isReadingTableParameter)
                                    TextBox1.Text += "\nisReadingTableParameter";
                                else if (isReadingTables)
                                    TextBox1.Text += "\nisReadingTables";

                                if (isReadingReportParameter)
                                    rpParam.ParameterName = value;
                                else if (isReadingTableParameter)
                                    tableParam.ColumnName = value;
                                else if (isReadingTables)
                                    report.TableName.Add(value);
                                TextBox1.Text += "\n <Name>" + value + "</Name>";

                            }
                            else if (reader.Name == "RelationName")
                            {
                                report.TableRelation.Add(value);
                                TextBox1.Text += "\n <RelationName>" + value + "</RelationName>";
                            }
                            else if (reader.Name == "UseDataSetSchema")
                            {
                                bool res = false;
                                Boolean.TryParse(value, out res);
                                reportTable.UseDataSetSchema = res;
                                TextBox1.Text += "\n <UseDataSetSchema>" + value + "</UseDataSetSchema>";
                            }
                            else if (reader.Name == "RPTFileName")
                            {
                                report.RPTFileName = value;
                                TextBox1.Text += "\n <RPTFileName>" + value + "</RPTFileName>";
                            }
                            else if (reader.Name == "Querry")
                            {
                                //report.Tables.Add(reportTable);
                                report.Table.Add(value);
                                TextBox1.Text += "\n <Querry>" + value + "</Querry>";
                            }
                            else if (reader.Name == "Table")
                            {
                                //report.Tables.Add(reportTable);
                                //report.Table.Add(value);
                                isReadingTables = false;
                                TextBox1.Text += "\n </Table>";
                            }
                            else if (reader.Name == "Parameter")
                            {
                                if (isReadingReportParameter)
                                    report.ReportParamaters.Add(rpParam);
                                else if (isReadingTableRelationParameter)
                                    reportTable.TableRelationParameters.Add(rtrParameter);
                                else
                                    reportTable.TableParameters.Add(tableParam);
                                TextBox1.Text += "\n </Parameter>";
                            }
                            else if (reader.Name == "ReportParameters")
                            {
                                isReadingReportParameter = false;
                                TextBox1.Text += "\n </ReportParameters>";
                            }
                            else if (reader.Name == "Report")
                            {
                                reportsDict.Add(report.ID, report);
                                TextBox1.Text += "\n </Report>";
                            }
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                TextBox1.Text += "\n" + ex.Message;
                TextBox1.Text += "\n" + ex.StackTrace;
            }

            return true;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Session[Authenticate.CALLER_URL] = null;
            dsReport = new SimplicityDBSchema();
            dsTempReport = new DataSet();

            if (Request["environment"] != null) //request for page environment
            {
                RequestedEnvironment = Request["environment"];
            }
            else
                RequestedEnvironment = Authenticate.PRODUCTION; //put production in requested Environment

            errorLabel.Text = "";
            //if (Request["environment"].CompareTo("SANDBOX") == 0)
                if (SchemaUtilty.isDebugMode)
                    TextBox1.Visible = true;

            try
            {
                dir = new System.IO.DirectoryInfo(path); //dir k ander reports ka path rakh day ga
                if (!dir.Exists)
                    dir.Create();

            }
            catch (Exception ex)
            {
                TextBox1.Text += "\n" + ex.Message;
            }

            TextBox1.Text += "\nOutside auth";
            auth = (AuthenticationObject)Session[Authenticate.ACCESS_TOKEN];//////Taking Authentication from Session
            if (auth != null && Session[Authenticate.AUTHENTICATED_ENVIRONMENT] != null && Session[Authenticate.AUTHENTICATED_ENVIRONMENT].ToString().CompareTo(RequestedEnvironment) == 0)////Check Authenticated and Environment
            {
                TextBox1.Text += "\nInside auth";
                reportType = Request[REPORT_TYPE];
                if (reportType != null && reportType.Length > 0)
                {
                    if (reportType.Equals("A372A8CC-36A1-11E1-9011-43B44724019B") || reportType.Equals("6ef14e46-7c87-4b05-b5f6-25b9c9fa2254") || reportType.Equals("d647d86b-07ce-4403-85d3-7f2ae2442c50") || reportType.Equals("58285e53-edb6-4b9b-936c-0f327da8a451") || reportType.Equals("845b72ec-90ab-493b-9e66-355a3ee62b99") || reportType.Equals("27356f2b-0a23-45c4-8600-842ea839f318"))
                        Response.Redirect("ShowResult.aspx?" + Request.QueryString.ToString());
                    TextBox1.Text += "\nInside report Type " + reportType;
                    ReadXMLConfiguration();

                    if (reportsDict.ContainsKey(reportType))
                    {
                        Report report = reportsDict[reportType];
                        TextBox1.Text += "\nReport_TYPE" + reportType;

                        foreach (ReportParameter param in report.ReportParamaters)
                        {
                            ReportParameter temp_param = new ReportParameter();
                            temp_param.ParameterName = param.ParameterName;
                            if (Request[param.ParameterName] != null)
                            {
                                temp_param.Value = Request[param.ParameterName];
                                reportParameter.Add(temp_param);
                                TextBox1.Text += "\n" + temp_param.ParameterName + " = " + temp_param.Value;
                            }
                            else
                            {
                                error = true;
                                ShowError("Missing report parameter " + temp_param.ParameterName);
                            }
                        }

                        if (!error)
                        {
                            foreach (ReportTable table in report.Tables)
                            {
                                try
                                {
                                    SchemaUtilty.PopulateDataSet(Page.Server, auth, dsReport, table, reportParameter, TextBox1);
                                }
                                catch (Exception ex)
                                {
                                    TextBox1.Text += "\n" + ex.Message;
                                    TextBox1.Text += "\n" + ex.StackTrace;
                                }

                            }

                            ReportDocument ReportDoc = new ReportDocument();
                            ReportDoc.Load(dir + "\\Reports\\" + report.RPTFileName);
                            ReportDoc.SetDataSource(dsReport);

                            MyCrystalReportViewer.ReportSource = ReportDoc;
                            MyCrystalReportViewer.RefreshReport();
                            MyCrystalReportViewer.Visible = true;
                            TextBox1.Text += "\n Reports Loaded ";
                        }

                    }
                    else
                        ShowError("No report with type " + reportType + " is found");

                    //String folderPath = Environment.GetFolderPath(Environment.SpecialFolder.System);

                    //TextBox1.Text = Environment.CurrentDirectory.ToString();

                    //invoiceId = Request[INVOICE_ID];
                    //ReadXMLConfiguration();

                }
            }
            else
            {
                Session["environment"] = RequestedEnvironment;
                Session[Authenticate.ACCESS_TOKEN] = null;/////Assuring to Redirect Other Environment If Login Already
                Session[Authenticate.CALLER_URL] = HttpContext.Current.Request.Url.AbsoluteUri;
                Response.Redirect("~/Authenticate.aspx");
                //lblInvoice.Text = "no auth";
            }
        }