private void BindFilter(string command) { DataTable dtFilters = (DataTable)ViewState["FiltersTable"]; IBNReportTemplate repTemp = null; if (ResultXML.Value != "") { repTemp = IBNReportTemplate.Load(ResultXML.Value); } if (repTemp == null) repTemp = new IBNReportTemplate(); if (_qItem == null) BindQObject(); #region PastStep if (pastCommand.Value != "") { QField qPast = _qItem.Fields[pastCommand.Value]; QDictionary qDicPast = _qItem.GetDictionary(qPast); bool isCheck = false; DataRow[] dr = dtFilters.Select("FieldName = '" + qPast.Name + "'"); if (dr.Length > 0) isCheck = (bool)dr[0]["IsChecked"]; FilterInfo fi = new FilterInfo(); fi.FieldName = qPast.Name; fi.DataType = qPast.DataType.ToString(); object curValue = null; if (qDicPast != null) { curValue = dictFltr.Value; if (curValue != null) { foreach (string sValue in (string[])curValue) fi.Values.Add(sValue); } } else { switch (qPast.DataType) { case DbType.Decimal: case DbType.Int32: curValue = intFltr.Value; if (curValue != null) { fi.Values.Add(((IntFilterValue)curValue).TypeValue); fi.Values.Add(((IntFilterValue)curValue).FirstValue); fi.Values.Add(((IntFilterValue)curValue).SecondValue); } break; case DbType.DateTime: case DbType.Date: curValue = dtFltr.Value; if (curValue != null) { fi.Values.Add(((DateFilterValue)curValue).TypeValue); fi.Values.Add(((DateFilterValue)curValue).FirstValue); fi.Values.Add(((DateFilterValue)curValue).SecondValue); } break; case DbType.String: curValue = strFltr.Value; if (curValue != null) fi.Values.Add(curValue.ToString()); break; case DbType.Time: curValue = timeFltr.Value; if (curValue != null) { fi.Values.Add(((TimeFilterValue)curValue).TypeValue); fi.Values.Add(((TimeFilterValue)curValue).FirstValue); fi.Values.Add(((TimeFilterValue)curValue).SecondValue); } break; } } if (isCheck) { int index = repTemp.Filters.IndexOf(repTemp.Filters[fi.FieldName]); if (index >= 0) { repTemp.Filters.RemoveAt(index); repTemp.Filters.Insert(index, fi); } else repTemp.Filters.Add(fi); } else { int index = repTemp.Filters.IndexOf(repTemp.Filters[fi.FieldName]); if (index >= 0) { repTemp.Filters.RemoveAt(index); } else if (fi.Values.Count > 0) { dr[0]["IsChecked"] = true; repTemp.Filters.Add(fi); } } } #endregion #region CurrentStep if (command != "") { DataRow[] dr = dtFilters.Select("FieldName = '" + command + "'"); bool isCheckCur = false; if (dr.Length > 0) isCheckCur = (bool)dr[0]["IsChecked"]; QField qField = _qItem.Fields[command]; QDictionary qDict = _qItem.GetDictionary(qField); dictFltr.Visible = false; intFltr.Visible = false; dtFltr.Visible = false; strFltr.Visible = false; timeFltr.Visible = false; IFilterControl control = null; IDataReader reader = null; if (qDict != null) { control = dictFltr; string sqlCommand = qDict.GetSQLQuery(Security.CurrentUser.LanguageId); reader = Report.GetQDictionary(sqlCommand); } else { switch (qField.DataType) { case DbType.Decimal: case DbType.Int32: control = intFltr; break; case DbType.DateTime: case DbType.Date: control = dtFltr; break; case DbType.String: control = strFltr; break; case DbType.Time: control = timeFltr; break; } } if (control != null) { ((System.Web.UI.UserControl)control).Visible = true; control.InitControl(reader); control.FilterTitle = qField.FriendlyName; FilterInfo flt = repTemp.Filters[command]; if (flt != null && isCheckCur) { switch (control.FilterType) { case "Dictionary": ArrayList alValue = new ArrayList(); foreach (string sValue in flt.Values) alValue.Add(sValue); dictFltr.Value = alValue.ToArray(typeof(string)); break; case "Int": if (flt.Values.Count > 0) { IntFilterValue ifValue = new IntFilterValue(); ifValue.TypeValue = flt.Values[0]; ifValue.FirstValue = flt.Values[1]; ifValue.SecondValue = flt.Values[2]; intFltr.Value = ifValue; } break; case "DateTime": if (flt.Values.Count > 0) { DateFilterValue dtValues = new DateFilterValue(); dtValues.TypeValue = flt.Values[0]; dtValues.FirstValue = flt.Values[1]; dtValues.SecondValue = flt.Values[2]; dtFltr.Value = dtValues; } break; case "String": if (flt.Values.Count > 0) strFltr.Value = flt.Values[0]; break; case "Time": if (flt.Values.Count > 0) { TimeFilterValue tfValue = new TimeFilterValue(); tfValue.TypeValue = flt.Values[0]; tfValue.FirstValue = flt.Values[1]; tfValue.SecondValue = flt.Values[2]; timeFltr.Value = tfValue; } break; } } else if (flt == null && isCheckCur) { control.Value = null; FilterInfo fi = new FilterInfo(); fi.FieldName = qField.Name; fi.DataType = qField.DataType.ToString(); repTemp.Filters.Add(fi); } else if (flt != null && !isCheckCur) { control.Value = null; int index = repTemp.Filters.IndexOf(flt); repTemp.Filters.RemoveAt(index); } } } #endregion ResultXML.Value = repTemp.CreateXMLTemplate().InnerXml; ViewState["FiltersTable"] = dtFilters; DataView dvFilters = dtFilters.DefaultView; dvFilters.Sort = "FriendlyName"; dlFilterFields.DataSource = dvFilters; dlFilterFields.DataBind(); dlFilterFields.SelectedIndex = -1; foreach (DataListItem liItem in dlFilterFields.Items) { dlFilterFields.SelectedIndex++; LinkButton lb = (LinkButton)liItem.FindControl("lbField"); if (lb != null && lb.CommandName == command) break; } lblCurrentFilter.Text = MakeFilterText(repTemp); pastCommand.Value = command; }
public IBNReportTemplate(XmlDocument xmlDoc) { this.Name = xmlDoc.SelectSingleNode("IBNReportTemplate/Name").InnerXml; this.Created = DateTime.Parse(xmlDoc.SelectSingleNode("IBNReportTemplate/Created").InnerXml); this.Author = xmlDoc.SelectSingleNode("IBNReportTemplate/Author").InnerXml; this.ViewType = xmlDoc.SelectSingleNode("IBNReportTemplate/ViewType").InnerXml; this.ObjectName = xmlDoc.SelectSingleNode("IBNReportTemplate/ObjectName").InnerXml; this.Version = xmlDoc.SelectSingleNode("IBNReportTemplate/Version").InnerXml; // Fields [12/14/2004] XmlNodeList xmlFields = xmlDoc.SelectNodes("IBNReportTemplate/Fields/Field"); foreach(XmlNode xmlItem in xmlFields) { this.Fields.Add(new FieldInfo(xmlItem.Attributes["Name"].Value,xmlItem.Attributes["DataType"].Value)); } // Group [12/14/2004] XmlNodeList xmlGroups = xmlDoc.SelectNodes("IBNReportTemplate/Groups/Field"); this.ShowEmptyGroup = xmlDoc.SelectSingleNode("IBNReportTemplate/Groups").Attributes["ShowEmpty"].Value=="1"; foreach(XmlNode xmlItem in xmlGroups) { this.Groups.Add(new FieldInfo(xmlItem.Attributes["Name"].Value,xmlItem.Attributes["DataType"].Value)); } // Filters [12/14/2004] XmlNodeList xmlFilters = xmlDoc.SelectNodes("IBNReportTemplate/Filters/Filter"); foreach(XmlNode xmlItem in xmlFilters) { FilterInfo filter = new FilterInfo(xmlItem.Attributes["FieldName"].Value,xmlItem.Attributes["DataType"].Value); foreach(XmlNode xmlValue in xmlItem.SelectNodes("Value")) { filter.Values.Add(xmlValue.InnerXml); } this.Filters.Add(filter); } // Sorting [12/14/2004] XmlNodeList xmlSorts = xmlDoc.SelectNodes("IBNReportTemplate/Sorting/Sort"); foreach(XmlNode xmlItem in xmlSorts) { this.Sorting.Add(new SortInfo(xmlItem.Attributes["FieldName"].Value,xmlItem.Attributes["DataType"].Value,xmlItem.Attributes["Asc"].Value=="1"?SortDirection.ASC:SortDirection.DESC )); } }
public void Insert(int index, FilterInfo field) { if(field==null) throw new ArgumentNullException(); this.InnerList.Insert(index,field); }
public int IndexOf(FilterInfo field) { return this.InnerList.IndexOf(field); }
public void Add(FilterInfo field) { if(field==null) throw new ArgumentNullException(); this.InnerList.Add(field); }
protected void btnSave_ServerClick(object sender, System.EventArgs e) { XmlDocument temp = new XmlDocument(); bool isGlobal = true; using (IDataReader reader = Report.GetReportTemplate(TemplateId)) { if (reader.Read()) { // O.R. [2009-06-05]: If report name contains "&" then we got the exception //temp.InnerXml = HttpUtility.HtmlDecode(reader["TemplateXML"].ToString()); temp.InnerXml = reader["TemplateXML"].ToString(); isGlobal = (bool)reader["IsGlobal"]; } } IBNReportTemplate repTemplate = new IBNReportTemplate(temp); QObject qItem = GetQObject(repTemplate); switch (Tab) { case "Fields": string sFields = iFields.Value; ArrayList alFields = new ArrayList(); while (sFields.Length > 0) { alFields.Add(sFields.Substring(0, sFields.IndexOf(","))); sFields = sFields.Remove(0, sFields.IndexOf(",") + 1); } repTemplate.Fields.Clear(); foreach (string s in alFields) { repTemplate.Fields.Add(new FieldInfo(s, qItem.Fields[s].DataType.ToString())); if (repTemplate.Groups[s] != null) repTemplate.Groups.RemoveAt(repTemplate.Groups.IndexOf(repTemplate.Groups[s])); } ArrayList alSort = new ArrayList(); foreach (SortInfo si in repTemplate.Sorting) alSort.Add(si.FieldName); foreach (string s in alSort) { if (repTemplate.Fields[s] == null) repTemplate.Sorting.RemoveAt(repTemplate.Sorting.IndexOf(repTemplate.Sorting[s])); } break; case "Groups": repTemplate.Groups.Clear(); if (ddGroup1.SelectedItem.Value != "01") repTemplate.Groups.Add(new FieldInfo(ddGroup1.SelectedItem.Value, qItem.Fields[ddGroup1.SelectedItem.Value].DataType.ToString())); if (ddGroup2.SelectedItem.Value != "02") repTemplate.Groups.Add(new FieldInfo(ddGroup2.SelectedItem.Value, qItem.Fields[ddGroup2.SelectedItem.Value].DataType.ToString())); break; case "Filters": if (!generate) { BindFilter(""); IBNReportTemplate repTemp = IBNReportTemplate.Load(ResultXML.Value); if (repTemp != null) { repTemplate.Filters.Clear(); foreach (FilterInfo fi in repTemp.Filters) repTemplate.Filters.Add(fi); } } else { foreach (HtmlTableRow row in tblFiltersValues.Rows) { HtmlTableCell cell = row.Cells[0]; IFilterControl ctrl = (IFilterControl)cell.Controls[0]; string FieldName = ctrl.FilterField; FilterInfo flt = new FilterInfo(); flt.FieldName = FieldName; flt.DataType = repTemplate.Filters[FieldName].DataType; repTemplate.Filters.RemoveAt(repTemplate.Filters.IndexOf(repTemplate.Filters[FieldName])); object curValue = null; switch (ctrl.FilterType) { case "Dictionary": curValue = ctrl.Value; if (curValue != null) { foreach (string _s in (string[])curValue) flt.Values.Add(_s); } break; case "DateTime": curValue = ctrl.Value; if (curValue != null) { flt.Values.Add(((DateFilterValue)curValue).TypeValue); flt.Values.Add(((DateFilterValue)curValue).FirstValue); flt.Values.Add(((DateFilterValue)curValue).SecondValue); } break; case "Int": curValue = ctrl.Value; if (curValue != null) { flt.Values.Add(((IntFilterValue)curValue).TypeValue); flt.Values.Add(((IntFilterValue)curValue).FirstValue); flt.Values.Add(((IntFilterValue)curValue).SecondValue); } break; case "String": curValue = ctrl.Value; if (curValue != null) flt.Values.Add(curValue.ToString()); break; case "Time": curValue = ctrl.Value; if (curValue != null) { flt.Values.Add(((TimeFilterValue)curValue).TypeValue); flt.Values.Add(((TimeFilterValue)curValue).FirstValue); flt.Values.Add(((TimeFilterValue)curValue).SecondValue); } break; default: break; } repTemplate.Filters.Add(flt); } } break; case "Sorts": DataTable dt = (DataTable)ViewState["SortFields"]; repTemplate.Sorting.Clear(); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { SortInfo si = new SortInfo(); string sS = dr["Field"].ToString(); si.FieldName = sS; si.DataType = qItem.Fields[sS].DataType.ToString(); if (dr["SortDirect"].ToString() == "0") si.SortDirection = Mediachase.IBN.Business.Reports.SortDirection.DESC; else si.SortDirection = Mediachase.IBN.Business.Reports.SortDirection.ASC; repTemplate.Sorting.Add(si); } } break; default: break; } if (!generate) { Report.UpdateReportTemplate(TemplateId, repName.Text, repTemplate.CreateXMLTemplate().InnerXml, isGlobal, false); BindCurrentTab(); } else { XmlDocument doc = GetReportDoc(repTemplate); int iReportId = Report.CreateReportByTemplate(TemplateId, doc.InnerXml); Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "OpenWindow('../Reports/XMLReportOutput.aspx?ReportId=" + iReportId.ToString() + "',screen.width,screen.height,true);window.location.href='../Reports/ReportHistory.aspx?TemplateId=" + TemplateId.ToString() + "';", true); } }