コード例 #1
0
ファイル: LibSqlModel.cs プロジェクト: liusj666/AxNew
        public void WriteObjectData(LibSerializationInfo info)
        {
            info.WriteString(this.ColumnName);
            info.WriteInt32(this.MaxLength);
            FieldType fieldType = FieldType.None;

            if (this.ExtendedProperties.ContainsKey(FieldProperty.FieldType))
            {
                fieldType = (FieldType)this.ExtendedProperties[FieldProperty.FieldType];
            }
            info.WriteInt32((int)fieldType);
            info.WriteInt32((int)this.ExtendedProperties[FieldProperty.DataType]);
            RelativeSourceCollection relColl = this.ExtendedProperties[FieldProperty.RelativeSource] as RelativeSourceCollection;

            if (relColl != null)
            {
                info.WriteInt32(relColl.Count);
                for (int i = 0; i < relColl.Count; i++)
                {
                    info.WriteObject(relColl[i]);
                }
            }
            else
            {
                info.WriteInt32(0);
            }
        }
コード例 #2
0
ファイル: LibSqlModel.cs プロジェクト: liusj666/AxNew
        public void ReadObjectData(LibSerializationInfo info)
        {
            this.ColumnName = info.ReadString();
            this.MaxLength  = info.ReadInt32();
            this.ExtendedProperties.Add(FieldProperty.FieldType, (FieldType)info.ReadInt32());
            LibDataType libDataType = (LibDataType)info.ReadInt32();

            this.ExtendedProperties.Add(FieldProperty.DataType, libDataType);
            int count = info.ReadInt32();
            RelativeSourceCollection relColl = null;

            for (int i = 0; i < count; i++)
            {
                if (relColl == null)
                {
                    relColl = new RelativeSourceCollection();
                }
                relColl.Add((RelativeSource)info.ReadObject());
            }
            this.ExtendedProperties.Add(FieldProperty.RelativeSource, relColl);
            this.DataType = LibDataTypeConverter.ConvertType(libDataType);
        }
コード例 #3
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);
        }
コード例 #4
0
        //字段检查
        public Dictionary <string, object> CheckFieldValue(int tableIndex, string fieldName, string relSource, object[] curPks, Dictionary <string, object> fieldValue)
        {
            Dictionary <string, object> returnValue = new Dictionary <string, object>();
            RelativeSourceCollection    relSources  = (RelativeSourceCollection)this.DataSet.Tables[tableIndex].Columns[fieldName].ExtendedProperties[FieldProperty.RelativeSource];
            int           groupIndex = -1;
            bool          isFind     = false;
            StringBuilder builder    = new StringBuilder();
            Dictionary <string, string> asNameDic = new Dictionary <string, string>();

            foreach (RelativeSource item in relSources)
            {
                if (string.Compare(relSource, item.RelSource, true) == 0)
                {
                    isFind     = true;
                    groupIndex = item.GroupIndex;
                }
                if (isFind)
                {
                    if (item.GroupIndex == groupIndex)
                    {
                        StringBuilder selectBuilder = new StringBuilder();
                        char          prefix        = (char)(item.TableIndex + (int)'A');
                        foreach (RelField relField in item.RelFields)
                        {
                            string name;
                            if (string.IsNullOrEmpty(relField.AsName))
                            {
                                name = relField.Name;
                            }
                            else
                            {
                                name = relField.AsName;
                                asNameDic.Add(relField.Name, relField.AsName);
                            }
                            returnValue.Add(name, "");
                            selectBuilder.AppendFormat("{0}.{1},", prefix, relField.Name);
                        }
                        foreach (SetValueField relField in item.SetValueFields)
                        {
                            string name;
                            if (string.IsNullOrEmpty(relField.AsName))
                            {
                                name = relField.Name;
                            }
                            else
                            {
                                name = relField.AsName;
                                asNameDic.Add(relField.Name, relField.AsName);
                            }
                            returnValue.Add(name, "");
                            selectBuilder.AppendFormat("{0}.{1},", prefix, relField.Name);
                        }
                        if (selectBuilder.Length > 0)
                        {
                            selectBuilder.Remove(selectBuilder.Length - 1, 1);
                            SqlBuilder sqlBuilder = new SqlBuilder(item.RelSource);
                            string     sql        = sqlBuilder.GetQuerySql(item.TableIndex, selectBuilder.ToString(), GetRelWhere(item.RelSource, item.TableIndex, prefix, curPks));
                            builder.AppendLine(sql);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (builder.Length > 0)
            {
                LibDataAccess dataAccess = new LibDataAccess();
                using (IDataReader reader = dataAccess.ExecuteDataReader(builder.ToString()))
                {
                    do
                    {
                        while (reader.Read())
                        {
                            int count = reader.FieldCount;
                            for (int i = 0; i < count; i++)
                            {
                                string name = reader.GetName(i);
                                if (asNameDic.ContainsKey(name))
                                {
                                    name = asNameDic[name];
                                }
                                if (returnValue.ContainsKey(name))
                                {
                                    returnValue[name] = reader[i] == null ? "" : reader[i];
                                }
                            }
                        }
                    } while (reader.NextResult());
                }
            }
            CheckFieldReturn(tableIndex, fieldName, curPks, fieldValue, returnValue);
            return(returnValue);
        }