| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using System;
- using System.Collections.Generic;
- namespace WePlatform.Views.Shared.Query
- {
- #region Query
- public class QueryViewModel
- {
- public QueryViewModel(string name, string url, List<QueryItem> queryItems, string originField, string targetField = null, string submitEventName = null,
- string modalId = "query_modal", int modalWidth = 900, string itemDbClickEventName = null,
- string itemClickEventName = null,bool isMultiple=false, QueryTreeSearch queryTreeSearch = null, string searchBindFunc = "")
- {
- ModalName = name;
- QueryUrl = url;
- QueryItems = queryItems;
- SearchBindFunc = searchBindFunc;
- QueryTreeSearch = queryTreeSearch;
- OriginFields = originField.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- var targets = new string[OriginFields.Length];
- TargetFields = new List<string[]>();
- IsMultiple = isMultiple;
- if (string.IsNullOrEmpty(targetField))
- {
- for (int i = 0; i < targets.Length; i++)
- {
- TargetFields.Add(new[] { "#" + OriginFields[i] });
- }
- }
- else
- {
- var targetArr = targetField.Split(new[] { ',' }, StringSplitOptions.None);
- for (int i = 0; i < targets.Length; i++)
- {
- if (i < targetArr.Length)
- {
- if (!string.IsNullOrEmpty(targetArr[i]))
- {
- var unitArr = targetArr[i].Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
- if (unitArr.Length > 1)
- {
- if (int.TryParse(unitArr[0], out int index) && index < OriginFields.Length && index >= i)
- {
- for (; i < index; i++)
- {
- TargetFields.Add(new[] { "#" + OriginFields[i] });
- }
- AddTargetField(unitArr[1], i);
- }
- else
- {
- AddTargetField(unitArr[1], i);
- }
- }
- else
- {
- AddTargetField(targetArr[i], i);
- }
- }
- else
- {
- TargetFields.Add(new[] { "#" + OriginFields[i] });
- }
- }
- else
- {
- TargetFields.Add(new[] { "#" + OriginFields[i] });
- }
- }
- }
- SubmitEventName = submitEventName;
- ModalId = modalId;
- ModalWidth = modalWidth;
- ItemClickEventName = itemClickEventName;
- ItemDbClickEventName = itemDbClickEventName ?? submitEventName;
- }
- public string QueryUrl { get; set; }
- public List<QueryItem> QueryItems { get; set; }
- public string ModalId { get; set; }
- public string ModalName { get; set; }
- public int ModalWidth { get; set; }
- public string[] OriginFields { get; set; }
- public List<string[]> TargetFields { get; set; }
- public string SubmitEventName { get; set; }
- public string ItemClickEventName { get; set; }
- public string ItemDbClickEventName { get; set; }
- public QueryTreeSearch QueryTreeSearch { get; set; }
- public string SearchBindFunc { get; set; }
- public bool IsMultiple { get; set; }
- private void AddTargetField(string targetStr, int index)
- {
- var target = targetStr.Split(new[] { '|' }, StringSplitOptions.None);
- for (int i = 0; i < target.Length; i++)
- {
- target[i] = string.IsNullOrEmpty(target[i]) ? "#" + OriginFields[index] : (target[i].StartsWith("#") || target[i].StartsWith("."))
- ? target[i]
- : "#" + target[i];
- }
- TargetFields.Add(target);
- }
- }
- //public class SearchBindDto
- //{
- // public string KeyField { get; set; }
- // public string KeyWords { get; set; }
- // public int FieldType { get; set; }
- // public int ExpType { get; set; }
- //}
- #endregion
- }
|