Beispiel #1
0
        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;
        }
Beispiel #2
0
        private void BindGenerateFilters(IBNReportTemplate repTemplate, QObject qItem)
        {
            tblName.Visible = false;
            foreach (FilterInfo fi in repTemplate.Filters)
            {
                HtmlTableRow row = new HtmlTableRow();
                HtmlTableCell cellValue = new HtmlTableCell();
                cellValue.Attributes.Add("width", "100%");

                QField qField = qItem.Fields[fi.FieldName];
                if (qField == null)
                    continue;
                QDictionary qDict = qItem.GetDictionary(qField);

                System.Web.UI.UserControl control = null;
                IDataReader reader = null;

                if (qDict != null)
                {
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Reports/Modules/FilterControls/DictionaryFilter.ascx");
                    string sqlCommand = qDict.GetSQLQuery(Security.CurrentUser.LanguageId);
                    reader = Report.GetQDictionary(sqlCommand);
                    ((Mediachase.UI.Web.Reports.Modules.DictionaryFilter)control).tdTitle.Attributes.Add("width", "150px");
                }
                else
                {
                    switch (qField.DataType)
                    {
                        case DbType.Decimal:
                        case DbType.Int32:
                            control = (System.Web.UI.UserControl)Page.LoadControl("~/Reports/Modules/FilterControls/IntFilter.ascx");
                            ((Mediachase.UI.Web.Reports.Modules.IntFilter)control).tdTitle.Attributes.Add("width", "150px");
                            break;
                        case DbType.DateTime:
                        case DbType.Date:
                            control = (System.Web.UI.UserControl)Page.LoadControl("~/Reports/Modules/FilterControls/DateFilter.ascx");
                            ((Mediachase.UI.Web.Reports.Modules.DateFilter)control).tdTitle.Attributes.Add("width", "150px");
                            break;
                        case DbType.String:
                            control = (System.Web.UI.UserControl)Page.LoadControl("~/Reports/Modules/FilterControls/StringFilter.ascx");
                            ((Mediachase.UI.Web.Reports.Modules.StringFilter)control).tdTitle.Attributes.Add("width", "150px");
                            break;
                        case DbType.Time:
                            control = (System.Web.UI.UserControl)Page.LoadControl("~/Reports/Modules/FilterControls/TimeFilter.ascx");
                            ((Mediachase.UI.Web.Reports.Modules.TimeFilter)control).tdTitle.Attributes.Add("width", "150px");
                            break;
                    }
                }
                if (control != null)
                {
                    cellValue.Controls.Add(control);
                }
                row.Cells.Add(cellValue);
                tblFiltersValues.Rows.Add(row);
                if (control != null)
                {
                    ((IFilterControl)control).InitControl(reader);
                    ((IFilterControl)control).FilterField = qField.Name;
                    ((IFilterControl)control).FilterTitle = qField.FriendlyName;
                    if (fi.Values != null)
                    {
                        switch (((IFilterControl)control).FilterType)
                        {
                            case "Dictionary":
                                ArrayList alValue = new ArrayList();
                                foreach (string _s in fi.Values)
                                    alValue.Add(_s);
                                ((IFilterControl)control).Value = alValue.ToArray(typeof(string));
                                break;
                            case "Int":
                                if (fi.Values.Count > 0)
                                {
                                    IntFilterValue ifValue = new IntFilterValue();
                                    ifValue.TypeValue = fi.Values[0];
                                    ifValue.FirstValue = fi.Values[1];
                                    ifValue.SecondValue = fi.Values[2];
                                    ((IFilterControl)control).Value = ifValue;
                                }
                                break;
                            case "DateTime":
                                if (fi.Values.Count > 0)
                                {
                                    DateFilterValue dtValues = new DateFilterValue();
                                    dtValues.TypeValue = fi.Values[0];
                                    dtValues.FirstValue = fi.Values[1];
                                    dtValues.SecondValue = fi.Values[2];
                                    ((IFilterControl)control).Value = dtValues;
                                }
                                break;
                            case "String":
                                if (fi.Values.Count > 0)
                                    ((IFilterControl)control).Value = fi.Values[0];
                                break;
                            case "Time":
                                if (fi.Values.Count > 0)
                                {
                                    TimeFilterValue tfValue = new TimeFilterValue();
                                    tfValue.TypeValue = fi.Values[0];
                                    tfValue.FirstValue = fi.Values[1];
                                    tfValue.SecondValue = fi.Values[2];
                                    ((IFilterControl)control).Value = tfValue;
                                }
                                break;
                        }
                    }
                    else if (fi.Values == null)
                        ((IFilterControl)control).Value = null;
                }
            }
            if (repTemplate.Filters.Count == 0)
            {
                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);
            }
        }