public void EnsureTextByValue(Object value)
        {
            if (!String.IsNullOrEmpty(Convert.ToString(value)))
            {
                TableDataSourceView _data = (TableDataSourceView)GetData();
                TableDataSourceView tableDataSourceView = new TableDataSourceView(
                    null,
                    _data.ShowHistoricalData,
                    _data.LoadAllHistoricalData,
                    _data.EndDateField,
                    _data.StartDateField,
                    _data.HistolicalPoint,
                    _data.CustomConditions,
                    _data.SelectMethod,
                    _data.TypeName,
                    _data.GetSelectParameters(),
                    _data.GetFilterParameters(),
                    _data.FilterExpression,
                    _data.SetFilterByCustomConditions);
                if (_data.HistoricalCountKeys == 1)
                {
                    tableDataSourceView.HistoricalKey          = _data.HistoricalKey;
                    tableDataSourceView.HistoricalSelectMethod = _data.HistoricalSelectMethod;
                    tableDataSourceView.HistoricalCountKeys    = 1;
                    tableDataSourceView.HistoricalValues[0]    = value;
                }
                QueryCondition queryCondition = new QueryCondition(DataValueField, ColumnFilterType.Equal, value, null);
                tableDataSourceView.CustomConditions.Add(queryCondition);
                DataView dataView;
                try
                {
                    DataSourceSelectArguments arguments = new DataSourceSelectArguments();
                    dataView =
                        (DataView)tableDataSourceView.Select(true, arguments, new DataSourceSelectExtArguments(1));
                }
                finally
                {
                    tableDataSourceView.CustomConditions.Remove(queryCondition);
                }

                //выполнение запроса должно помещать 1 запись в таблицу
                if (dataView.Table.Rows.Count == 1)
                {
                    Text = dataView.Table.Rows[0][DataTextField].ToString();
                }
                else if (dataView.Count == 1)
                {
                    Text = dataView[0][DataTextField].ToString();
                }
                else
                {
                    Text = "";
                }
            }
            else
            {
                Text = "";
            }
            textBox.Text = Text;
        }
예제 #2
0
 /// <summary>
 /// Заполнение данных не смотря на запрет от FillType
 /// </summary>
 public void Select(bool anyWay)
 {
     _view.Select(anyWay, DataSourceSelectArguments.Empty);
 }
예제 #3
0
        public string[] GetCompletionList(string prefixText, int count, string contextKey)
        {
            Hashtable props = (Hashtable)Session[contextKey];

            TableDataSourceView tableDataSourceView = new TableDataSourceView(
                null,
                (Boolean)props["ShowHistoricalData"],
                (Boolean)props["LoadAllHistoricalData"],
                (String)props["EndDateField"],
                (String)props["StartDateField"],
                (DateTime?)props["HistolicalPoint"],
                (QueryConditionList)props["QueryConditionsList"],
                (String)props["SelectMethod"],
                (String)props["TypeName"],
                (List <Triplet>)props["SelectParameters"],
                (Dictionary <String, String>)props["FilterParameters"],
                (String)props["FilterExpression"],
                (Boolean)props["SetFilterByCustomConditions"]);

            QueryCondition queryCondition = new QueryCondition((String)props["DataTextField"],
                                                               ColumnFilterType.StartWith, prefixText, null);

            tableDataSourceView.CustomConditions.Add(queryCondition);

            QueryCondition disableRowFieldQueryCondition = null;
            String         disableRowField = (String)props["DataDisableRowField"];

            if (!String.IsNullOrEmpty(disableRowField))
            {
                Int32 disableRowCondition = (Int32)props["ConditionValue"];
                disableRowFieldQueryCondition = new QueryCondition(disableRowField,
                                                                   ColumnFilterType.Equal, disableRowCondition, null);

                tableDataSourceView.CustomConditions.Add(disableRowFieldQueryCondition);
            }

            DataView dataView;

            try
            {
                string filterString = tableDataSourceView.GetFilterString();
                dataView           = (DataView)tableDataSourceView.Select(true, new DataSourceSelectArguments(), new DataSourceSelectExtArguments(count));
                dataView.RowFilter = filterString;
            }
            finally
            {
                tableDataSourceView.CustomConditions.Remove(queryCondition);

                if (disableRowFieldQueryCondition != null)
                {
                    tableDataSourceView.CustomConditions.Remove(disableRowFieldQueryCondition);
                }
            }

            List <string>        items = new List <string>();
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

            foreach (DataRowView dataRowView in dataView)
            {
                String text = dataRowView[(String)props["DataTextField"]].ToString();
                String code = String.IsNullOrEmpty((String)props["DataCodeField"]) ?
                              "-1" : dataRowView[(String)props["DataCodeField"]].ToString();
                String id    = dataRowView[(String)props["DataValueField"]].ToString();
                String value = javaScriptSerializer.Serialize(new Pair(id, code));
                String item  = javaScriptSerializer.Serialize(new Pair(text, value));
                items.Add(item);
            }
            return(items.ToArray());
        }