private void FilterReport(string action) { string foldername = Server.MapPath("~/CS_REPORT/rpt/ftmandytdsellinperareareport.rpt"); _User Ousr = new _User(Session["username"].ToString()); string[] No_Filter_Users = { "ceo", "vpbsm", "vptfi", "ssgm", "ssm", "brd", "admin" }; string[] User_more_roles = { "6", "14", "20", "21", "23", "31", "36", "52", "62", "64", "65", "71", "72", "77", "79", "90" }; string orig_ids = string.Join(",", User_more_roles); string tmp_ids = ""; DataTable user_counterid = SqlDbHelper.getDataDT("SELECT counterid FROM userheader WHERE username='******'"); foreach (DataRow ids in user_counterid.Rows) { tmp_ids = ids["counterid"].ToString(); } string val_region = txt_region.Text.ToUpper(); if (val_region.Trim() != "") { ReportDocument ReportDoc = new ReportDocument(); ReportDoc.Load(foldername); ReportDoc.SetDatabaseLogon("sa", "p@ssw0rd"); ParameterFields PFIELDS = ReportDoc.ParameterFields; ParameterDiscreteValue[] param_values = new ParameterDiscreteValue[] { }; ParameterDiscreteValue region_default_val = new ParameterDiscreteValue(); region_default_val.Value = "C"; ParameterDiscreteValue channel_default_val = new ParameterDiscreteValue(); channel_default_val.Value = "All"; ParameterDiscreteValue area_default_val = new ParameterDiscreteValue(); area_default_val.Value = "All"; ParameterDiscreteValue so_default_val = new ParameterDiscreteValue(); so_default_val.Value = "All"; ParameterDiscreteValue brand_default_val = new ParameterDiscreteValue(); brand_default_val.Value = "All"; PFIELDS["Region"].CurrentValues.Clear(); PFIELDS["Area"].CurrentValues.Clear(); PFIELDS["Channel"].CurrentValues.Clear(); PFIELDS["SO"].CurrentValues.Clear(); PFIELDS["Brand"].CurrentValues.Clear(); if (action == "button_click" && (Ousr.HasPositionsOf(No_Filter_Users) || orig_ids.IndexOf(tmp_ids) != -1)) { if (val_region == "LUZON") { region_default_val.Value = "CL"; } else if (val_region == "VISMIN") { region_default_val.Value = "CV"; } else { region_default_val.Value = "C"; } } else { ReportHelper.GetRegions(Session["username"].ToString(), "Region", ref PFIELDS, ref param_values); foreach (ParameterDiscreteValue pd in PFIELDS["Region"].CurrentValues) { if (pd.Value.ToString() == "LUZON") { pd.Value = "CL"; } if (pd.Value.ToString() == "VISMIN") { pd.Value = "CV"; } } } ReportHelper.GetChannels(Session["username"].ToString(), "Channel", ref PFIELDS, ref param_values); ReportHelper.GetAreas(Session["username"].ToString(), "Area", ref PFIELDS, ref param_values); ReportHelper.GetBrands(Session["username"].ToString(), "Brand", ref PFIELDS, ref param_values); if (Ousr.HasPositionOf("so") != -1) { so_default_val.Value = Ousr.SlpName; } bool has_region = false, has_channel = false, has_area = false, has_so = false, has_brand = false; foreach (ParameterField pd in PFIELDS) { bool has_val = pd.CurrentValues.Count > 0 ? true : false; if (has_val) { switch (pd.Name.ToUpper()) { case "REGION": has_region = true; break; case "CHANNEL": has_channel = true; break; case "AREA": has_area = true; break; case "SO": has_so = true; break; case "BRAND": has_brand = true; break; } } } if (!has_region) { ReportDoc.ParameterFields["Region"].CurrentValues.Add(region_default_val); } if (!has_channel) { ReportDoc.ParameterFields["Channel"].CurrentValues.Add(channel_default_val); } if (!has_area) { ReportDoc.ParameterFields["Area"].CurrentValues.Add(area_default_val); } if (!has_so) { ReportDoc.ParameterFields["SO"].CurrentValues.Add(so_default_val); } if (!has_brand) { ReportDoc.ParameterFields["Brand"].CurrentValues.Add(brand_default_val); } CrystalReportViewer1.ReportSource = ReportDoc; } }
protected void Page_Load(object sender, EventArgs e) { //string foldername = Server.MapPath("~/CS_REPORT/rpt/summarybusinessreviews.rpt"); try { //CrystalReportSource1.Report.FileName = foldername; //CrystalReportViewer1.ReportSource = CrystalReportSource1; //CrystalReportViewer1.RefreshReport(); //Label2.Text = CrystalReportViewer1.ParameterFieldInfo[0].Name + "-" + CrystalReportViewer1.ParameterFieldInfo[1].Name; string foldername = Server.MapPath("~/CS_REPORT/rpt/summarybusinessreviews.rpt"); _User Ousr = new _User(Session["username"].ToString()); ReportDocument ReportDoc = new ReportDocument(); ReportDoc.Load(foldername); ReportDoc.SetDatabaseLogon("sa", "p@ssw0rd"); ParameterFields PFIELDS = ReportDoc.ParameterFields; ParameterDiscreteValue[] param_values = new ParameterDiscreteValue[] { }; ParameterDiscreteValue region_default_val = new ParameterDiscreteValue(); region_default_val.Value = "C"; ParameterDiscreteValue channel_default_val = new ParameterDiscreteValue(); channel_default_val.Value = "All"; ParameterDiscreteValue area_default_val = new ParameterDiscreteValue(); area_default_val.Value = "All"; ParameterDiscreteValue so_default_val = new ParameterDiscreteValue(); so_default_val.Value = "All"; ParameterDiscreteValue start_date_default_val = new ParameterDiscreteValue(); PFIELDS["Region"].CurrentValues.Clear(); PFIELDS["Area"].CurrentValues.Clear(); PFIELDS["Channel"].CurrentValues.Clear(); PFIELDS["SO"].CurrentValues.Clear(); ReportHelper.GetRegions(Session["username"].ToString(), "Region", ref PFIELDS, ref param_values); foreach (ParameterDiscreteValue pd in PFIELDS["Region"].CurrentValues) { if (pd.Value.ToString() == "LUZON") { pd.Value = "CL"; } if (pd.Value.ToString() == "VISMIN") { pd.Value = "CV"; } } ReportHelper.GetChannels(Session["username"].ToString(), "Channel", ref PFIELDS, ref param_values); ReportHelper.GetAreas(Session["username"].ToString(), "Area", ref PFIELDS, ref param_values); if (Ousr.HasPositionOf("so") != -1) { so_default_val.Value = Ousr.SlpName; } bool has_region = false, has_channel = false, has_area = false, has_so = false; foreach (ParameterField pd in PFIELDS) { bool has_val = pd.CurrentValues.Count > 0 ? true : false; if (has_val) { switch (pd.Name.ToUpper()) { case "REGION": has_region = true; break; case "CHANNEL": has_channel = true; break; case "AREA": has_area = true; break; case "SO": has_so = true; break; } } } if (!has_region) { ReportDoc.ParameterFields["Region"].CurrentValues.Add(region_default_val); } if (!has_channel) { ReportDoc.ParameterFields["Channel"].CurrentValues.Add(channel_default_val); } if (!has_area) { ReportDoc.ParameterFields["Area"].CurrentValues.Add(area_default_val); } if (!has_so) { ReportDoc.ParameterFields["SO"].CurrentValues.Add(so_default_val); } CrystalReportViewer1.ReportSource = ReportDoc; } catch (Exception ex) { Label2.Text = "Error-" + ex.Message; } }