예제 #1
0
        public LibBcfBase GetBcfInstance(string progId, LibDataAccess dataAccess = null)
        {
            LibBcfBase destObj = null;

            if (ProgIdHost.Instance.ProgIdRef.ContainsKey(progId))
            {
                BcfServerInfo info     = ProgIdHost.Instance.ProgIdRef[progId];
                string        path     = Path.Combine(EnvProvider.Default.MainPath, "Bcf", info.DllName);
                Assembly      assembly = Assembly.LoadFrom(path);
                Type          t        = assembly.GetType(info.ClassName);
                destObj        = (LibBcfBase)t.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);
                destObj.Handle = LibHandleCache.Default.GetSystemHandle();
                if (dataAccess != null)
                {
                    destObj.DataAccess = dataAccess;
                }
                return(destObj);
            }
            return(destObj);
        }
예제 #2
0
        public IList <FuzzyResult> FuzzySearchField(int tableIndex, string fieldName, string relSource, string relName,
                                                    string query, object[] curPks = null, Dictionary <string, object> selConditionParam = null, string[] currentPks = null)
        {
            IList <FuzzyResult>      list         = new List <FuzzyResult>();
            RelativeSourceCollection relSources   = (RelativeSourceCollection)this.DataSet.Tables[tableIndex].Columns[fieldName].ExtendedProperties[FieldProperty.RelativeSource];
            RelativeSource           curRelSource = null;

            foreach (RelativeSource item in relSources)
            {
                if (string.Compare(relSource, item.RelSource, true) == 0)
                {
                    curRelSource = item;
                    break;
                }
            }
            if (curRelSource == null)
            {
                return(list);
            }
            SqlBuilder    sqlBuilder = new SqlBuilder(relSource);
            StringBuilder builder    = new StringBuilder();
            LibBcfBase    bcfBase    = LibBcfSystem.Default.GetBcfInstance(relSource);
            BillType      billType   = bcfBase.Template.BillType;

            if (relSource.Split(new string[] { "axp" }, StringSplitOptions.None).Length == 1 && (billType == BillType.Bill || billType == BillType.Master))
            {
                builder.AppendFormat("And A.CURRENTSTATE=2");
            }
            if (curPks != null && curPks.Length > 0)
            {
                builder.AppendFormat(" And {0}", GetRelWhere(relSource, curRelSource.TableIndex, 'A', curPks));
            }
            string selCondition = string.Empty;

            if (curRelSource.SelConditions.Count > 0)
            {
                foreach (SelCondition item in curRelSource.SelConditions)
                {
                    builder.AppendFormat(" And {0}", item.Condition);
                }
                selCondition = builder.ToString();
                selCondition = selCondition.Replace("CURRENT_PERSON", LibStringBuilder.GetQuotObject(this.Handle.PersonId));
                if (selConditionParam != null && selConditionParam.Count > 0)
                {
                    LibSqlModel model = LibSqlModelCache.Default.GetSqlModel(this.ProgId);
                    if (model != null)
                    {
                        foreach (KeyValuePair <string, object> item in selConditionParam)
                        {
                            string[]    temp     = item.Key.Split('.');
                            int         index    = (int)temp[0][0] - (int)'A';
                            DataColumn  col      = model.Tables[index].Columns[temp[1]];
                            LibDataType dataType = (LibDataType)col.ExtendedProperties[FieldProperty.DataType];
                            if (dataType == LibDataType.Text)
                            {
                                selCondition = selCondition.Replace(string.Format("@{0}", item.Key), LibStringBuilder.GetQuotObject(item.Value));
                            }
                            else
                            {
                                selCondition = selCondition.Replace(string.Format("@{0}", item.Key), item.Value.ToString());
                            }
                        }
                    }
                }
            }
            else
            {
                selCondition = builder.ToString();
            }
            string powerStr = LibPermissionControl.Default.GetShowCondition(this.Handle, relSource, this.Handle.PersonId);

            if (!string.IsNullOrEmpty(powerStr))
            {
                selCondition = string.Format("{0} and {1}", selCondition, powerStr);
            }
            if (curRelSource.ContainsSub == false && string.IsNullOrEmpty(curRelSource.ParentColumnName) == false &&
                currentPks != null && currentPks.Length > 0 && string.IsNullOrEmpty(currentPks[0]) == false)
            {
                //对于父子结构数据,如果不包含子数据且指定了父列外键列的名称,则添加额外的查询条件 Zhangkj 20170316
                DataColumn    keyColumn     = this.DataSet.Tables[tableIndex].PrimaryKey[0];
                string        keyColumnName = this.DataSet.Tables[tableIndex].PrimaryKey[0].ColumnName;//目前仅支持单主键
                string        dataId        = currentPks[0];
                LibDataType   dataType      = keyColumn.ExtendedProperties.ContainsKey(FieldProperty.DataType) ? (LibDataType)keyColumn.ExtendedProperties[FieldProperty.DataType] : LibDataTypeConverter.ConvertToLibType(keyColumn.DataType);
                List <object> subIds        = this.GetSubDataIds(dataType, dataId, this.DataSet.Tables[tableIndex].TableName, keyColumnName, curRelSource.ParentColumnName, true);
                if (subIds != null && subIds.Count > 0)
                {
                    bool          needQuot   = dataType == LibDataType.Text || dataType == LibDataType.NText;
                    List <object> quotSubIds = new List <object>();
                    foreach (object obj in subIds)
                    {
                        quotSubIds.Add((needQuot) ? LibStringBuilder.GetQuotObject(obj) : obj);
                    }
                    selCondition = string.Format("{0} and A.{1} not in ({2})", selCondition, keyColumnName, string.Join(",", quotSubIds));
                }
            }
            string        sql         = sqlBuilder.GetFuzzySql(curRelSource.TableIndex, relSources, query, selCondition, curRelSource.ParentColumnName);
            LibDataAccess dataAccess  = new LibDataAccess();
            int           count       = 0;
            int           filterCount = curRelSource.SearchFilterCount;

            using (IDataReader reader = dataAccess.ExecuteDataReader(sql))
            {
                while (reader.Read())
                {
                    if (reader.FieldCount == 1)
                    {
                        list.Add(new FuzzyResult(LibSysUtils.ToString(reader[0]), string.Empty));
                    }
                    else if (reader.FieldCount == 2)
                    {
                        list.Add(new FuzzyResult(LibSysUtils.ToString(reader[0]), LibSysUtils.ToString(reader[1])));
                    }
                    else if (reader.FieldCount == 3)
                    {
                        FuzzyResult fuzzyResult = new FuzzyResult(LibSysUtils.ToString(reader[0]), LibSysUtils.ToString(reader[1]));
                        fuzzyResult.ContainsKeyField = LibSysUtils.ToString(reader[2]);//将除Id Name列以外的包含查询关键字的列的内容
                        list.Add(fuzzyResult);
                    }
                    else if (reader.FieldCount == 4)
                    {
                        FuzzyResult fuzzyResult = new FuzzyResult(LibSysUtils.ToString(reader[0]), LibSysUtils.ToString(reader[1]));
                        fuzzyResult.ContainsKeyField = LibSysUtils.ToString(reader[2]); //将除Id Name列以外的包含查询关键字的列的内容
                        fuzzyResult.ParentId         = LibSysUtils.ToString(reader[3]); //树形结构的父数据Id
                        if (curRelSource.ExpandAll)
                        {
                            fuzzyResult.TreeNodeExpanded = true;
                        }
                        list.Add(fuzzyResult);
                    }
                    count++;
                    if (count == filterCount)
                    {
                        break;
                    }
                }
            }
            if (list.Count > 1)
            {
                LibControlType controlType = (LibControlType)this.DataSet.Tables[tableIndex].Columns[fieldName].ExtendedProperties[FieldProperty.ControlType];
                if (controlType == LibControlType.IdNameTree && string.IsNullOrEmpty(curRelSource.ParentColumnName) == false)
                {
                    //处理树形结构数据
                    List <FuzzyResult> newList = list.ToList();//先全部放入

                    List <FuzzyResult> tempList = null;
                    using (MemoryStream stream = new MemoryStream())
                    {
                        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        formatter.Serialize(stream, list.ToList());
                        stream.Position = 0;
                        tempList        = formatter.Deserialize(stream) as List <FuzzyResult>;//深度复制一份
                    }

                    //查找是其他节点的子节点的进行处理
                    int index = 0;
                    while (index < list.Count)
                    {
                        FuzzyResult child  = list[index];
                        FuzzyResult parent = (from re in list
                                              where re != null && re.Id.Equals(child.ParentId)
                                              select re).FirstOrDefault();
                        if (parent != default(FuzzyResult))
                        {
                            newList.Remove(child);
                            parent.Children.Add(child);
                        }
                        index++;
                    }
                    newList[0].TotalList = tempList;
                    list = newList;
                }
            }

            return(list);
        }