コード例 #1
0
        private string GetMultipleConstraintString()
        {
            ITableDescriptor Table = Context.Table;
            IReadOnlyCollection <IColumnValuePair> MultipleConstraintList = Context.MultipleConstraintList;

            string TableName = Table.Name;

            string ConstraintString = "";

            foreach (IColumnValuePair Entry in MultipleConstraintList)
            {
                IColumnDescriptor ConstraintColumn = Entry.Column;
                object            Value            = Entry.Value;
                string            ColumnName       = ConstraintColumn.Name;
                IColumnType       ColumnType       = ConstraintColumn.Type;

                if (ConstraintString.Length > 0)
                {
                    ConstraintString += " AND ";
                }

                string FormattedValue = ColumnType.ToSqlFormat(Value);
                ConstraintString += $"({ColumnName}={FormattedValue})";
            }

            return(ConstraintString);
        }
コード例 #2
0
        protected virtual string GetConstraintString()
        {
            ITableDescriptor Table = Context.Table;
            IReadOnlyCollection <IColumnValuePair> ConstraintList = Context.ConstraintList;

            Debug.Assert(ConstraintList != null);
            Debug.Assert(ConstraintList.Count > 0);

            string TableName = Table.Name;

            string ConstraintString = "";

            foreach (IColumnValuePair Entry in ConstraintList)
            {
                IColumnDescriptor Column = Entry.Column;
                object            Value  = Entry.Value;

                if (ConstraintString.Length > 0)
                {
                    ConstraintString += " AND ";
                }

                string ColumnName = Column.Name;

                IColumnType ColumnType     = Column.Type;
                string      FormattedValue = ColumnType.ToSqlFormat(Value);

                ConstraintString += "(" + ColumnName + "=" + FormattedValue + ")";
            }

            Debug.Assert(!string.IsNullOrEmpty(ConstraintString));
            return(ConstraintString);
        }
コード例 #3
0
        protected virtual bool GetSingleConstraintString(out string constraintString)
        {
            ITableDescriptor           Table = Context.Table;
            IColumnValueCollectionPair SingleConstraintEntry = Context.SingleConstraintEntry;

            if (SingleConstraintEntry != null)
            {
                string            TableName        = Table.Name;
                IColumnDescriptor ConstraintColumn = SingleConstraintEntry.Column;
                string            ColumnName       = ConstraintColumn.Name;
                IColumnType       ColumnType       = ConstraintColumn.Type;

                constraintString = "";
                foreach (object Value in SingleConstraintEntry.ValueCollection)
                {
                    if (constraintString.Length > 0)
                    {
                        constraintString += " OR ";
                    }

                    string FormattedValue = ColumnType.ToSqlFormat(Value);

                    constraintString += "(" + ColumnName + "=" + FormattedValue + ")";
                }

                return(true);
            }
            else
            {
                constraintString = null;
                return(false);
            }
        }
コード例 #4
0
        private bool GetMultipleConstraintString(out string constraintString)
        {
            ITableDescriptor Table = Context.Table;
            IReadOnlyCollection <IColumnValuePair> MultipleConstraintList = Context.MultipleConstraintList;

            string TableName = Table.Name;

            constraintString = "";
            foreach (IColumnValuePair Entry in MultipleConstraintList)
            {
                IColumnDescriptor ConstraintColumn = Entry.Column;
                object            Value            = Entry.Value;
                string            ColumnName       = ConstraintColumn.Name;
                IColumnType       ColumnType       = ConstraintColumn.Type;

                if (constraintString.Length > 0)
                {
                    constraintString += " AND ";
                }

                string FormattedValue = ColumnType.ToSqlFormat(Value);
                constraintString += "(" + ColumnName + "=" + FormattedValue + ")";
            }

            return(true);
        }
コード例 #5
0
        private string GetSingleConstraintString()
        {
            ITableDescriptor           Table = Context.Table;
            IColumnValueCollectionPair SingleConstraintEntry = Context.SingleConstraintEntry;

            Debug.Assert(SingleConstraintEntry != null);

            string            TableName        = Table.Name;
            IColumnDescriptor ConstraintColumn = SingleConstraintEntry.Column;
            string            ColumnName       = ConstraintColumn.Name;
            IColumnType       ColumnType       = ConstraintColumn.Type;

            string ConstraintString = "";

            foreach (object Value in SingleConstraintEntry.ValueCollection)
            {
                if (ConstraintString.Length > 0)
                {
                    ConstraintString += " OR ";
                }

                string FormattedValue = ColumnType.ToSqlFormat(Value);

                ConstraintString += $"({ColumnName}={FormattedValue})";
            }

            return(ConstraintString);
        }
コード例 #6
0
        public SqlSvr2012SchemaBuilder()
        {
            _c = new SqlSvr2012ColumnType();

            _n = new SqlSvr2012NullabilityType();

            _d = new SqlSvr2012DefaultValue();
        }
コード例 #7
0
 public TableMetadata Column(string name, IColumnType type)
 {
     return(Column(new ColumnMetadata
     {
         Name = name,
         Type = type
     }));
 }
コード例 #8
0
 protected GenericArrayColumn(IColumnType baseType)
 {
     BaseType   = baseType;
     ArrayLevel = baseType.ArrayLevel + 1;
     if (ArrayLevel > 3)
     {
         throw new Exception("Array Define过深,不能超过三层");
     }
 }
コード例 #9
0
        public IColumnType GetColumnType(string colType)
        {
            IColumnType t = NullColumnType.Instance;

            if (m_avaliableTypes.ContainsKey(colType))
            {
                t = m_avaliableTypes[colType];
            }

            return(t);
        }
コード例 #10
0
        protected virtual string GetChangeString()
        {
            ITableDescriptor Table = Context.Table;
            IReadOnlyCollection <IColumnValuePair>           EntryList     = Context.EntryList;
            IReadOnlyCollection <IColumnValuePair <byte[]> > DataEntryList = GetDataEntryList();

            string TableName = Table.Name;

            Debug.Assert(EntryList.Count > 0);

            string ChangeString = "";

            int i = 0;

            foreach (IColumnValuePair <byte[]> DataEntry in DataEntryList)
            {
                if (ChangeString.Length > 0)
                {
                    ChangeString += ", ";
                }

                string ColumnName = DataEntry.Column.Name;
                string DataName   = $"data{i}";
                ChangeString += ColumnName + "=" + "?" + DataName;

                i++;
            }

            foreach (IColumnValuePair Entry in EntryList)
            {
                IColumnDescriptor Column = Entry.Column;
                if (Column is IColumnDescriptorByteArray)
                {
                    continue;
                }

                if (ChangeString.Length > 0)
                {
                    ChangeString += ", ";
                }

                string      ColumnName     = Column.Name;
                IColumnType ColumnType     = Column.Type;
                object      Value          = Entry.Value;
                string      FormattedValue = ColumnType.ToSqlFormat(Value);

                ChangeString += ColumnName + "=" + FormattedValue;
            }

            return(ChangeString);
        }
コード例 #11
0
        public IColumnType ParseColumnType(string excelString, string columnName)
        {
            IColumnType type = null;

            foreach (var builtinType in BuiltinColumnTypes.BuiltinTypes)
            {
                if (excelString.StartsWith(builtinType.TypeName, StringComparison.OrdinalIgnoreCase))
                {
                    type        = builtinType;
                    excelString = excelString.Substring(builtinType.TypeName.Length);
                    break;
                }
            }
            if (type == null)
            {
                //先处理各种类型
                if (excelString.StartsWith("id", StringComparison.OrdinalIgnoreCase))
                {
                    type = ParseIdType(ref excelString);
                }
                else if (excelString.StartsWith("struct", StringComparison.OrdinalIgnoreCase) ||
                         excelString.StartsWith("class", StringComparison.OrdinalIgnoreCase))
                {
                    type = ParseCustomType(ref excelString, columnName);
                }
                else if (excelString.StartsWith("enum", StringComparison.OrdinalIgnoreCase))
                {
                    type = ParseEnumType(ref excelString, columnName);
                }
                else
                {
                    throw new Exception("解析失败,不支持的类型");
                }
                CustomTypes.Add(type);
            }
            while (excelString != "")
            {
                if (excelString.StartsWith("[]"))
                {
                    excelString = excelString.Substring(2).TrimStart();
                    type        = new BuiltinColumnTypes.ArrayColumn(type);
                    CustomTypes.Add(type);
                }
                else
                {
                    throw new Exception($"含有多余的末尾{excelString}");
                }
            }
            return(type);
        }
コード例 #12
0
        private string GetReadFromBinaryString(IColumnType type)
        {
            var pooledColumnType = type as IPooledColumnType;

            if (pooledColumnType != null)
            {
                return($"{GetPoolName(pooledColumnType)}[binary.ReadInt()]");
            }
            var primitiveColomnType = type as IPrimitiveColomnType;

            if (primitiveColomnType != null)
            {
                return(GetReadFromPrimitiveTypeString(primitiveColomnType));
            }
            throw new Exception();
        }
コード例 #13
0
        /// <summary>
        ///  Метод для парсинга входящего заголовка Csv файла с целью найти тип данных и индекс искомого столбца columnName
        /// </summary>
        public static Column ParseCsvHeader(string csvHeader, string columnName, char colSplitter,
                                            char headerSplitter)
        {
            if (string.IsNullOrWhiteSpace(csvHeader))
            {
                throw new CsvHeaderIsEmptyException();
            }
            if (string.IsNullOrWhiteSpace(columnName))
            {
                throw new CsvHeaderNoColumnNameException();
            }
            // в заголовке CSV файла столбцы разделяются colSplitter,
            // а сам столбец - на название и тип данных - разделяется headerSplitter-ом;
            byte nameIndex = 0; // название столбца д.б. первым, а тип данных - вторым
            byte typeIndex = 1;
            // получаем массив столбцов (строками вида "имя тип")
            var arr = csvHeader.Split(colSplitter);

            for (int i = 0; i < arr.Length; i++)
            {
                var colArray = arr[i].Split(headerSplitter, StringSplitOptions.RemoveEmptyEntries);
                if (colArray.Length > 2)
                {
                    throw new ExcessInfoInColumnException(csvHeader, headerSplitter, colArray);
                }
                if (colArray.Length == 1)
                {
                    throw new NoTypeInColumnException(csvHeader, columnName);
                }
                if (colArray.Length == 0)
                {
                    throw new EmptyColumnException(i);
                }

                if (colArray[nameIndex].ToLower() == columnName.ToLower())
                {
                    IColumnType colType = ColumnTypeFactory.GetColumnType(colArray[typeIndex]);
                    return(new Column(colArray[nameIndex], colType, i));
                }
            }

            throw new NoSuchColumnInCsvHeaderException(columnName, csvHeader);
        }
コード例 #14
0
        protected virtual bool GetConstraintString(out string constraintString)
        {
            IReadOnlyDictionary <ITableDescriptor, IColumnValueCollectionPair> Constraints = Context.Constraints;

            if (Constraints.Count > 0)
            {
                constraintString = "";
                foreach (KeyValuePair <ITableDescriptor, IColumnValueCollectionPair> Entry in Constraints)
                {
                    ITableDescriptor  Table     = Entry.Key;
                    IColumnDescriptor Column    = Entry.Value.Column;
                    IEnumerable       ValueList = Entry.Value.ValueCollection;

                    string TableName  = Table.Name;
                    string ColumnName = Column.Name;

                    foreach (object Value in ValueList)
                    {
                        if (constraintString.Length > 0)
                        {
                            constraintString += " OR ";
                        }

                        IColumnType ColumnType     = Column.Type;
                        string      FormattedValue = ColumnType.ToSqlFormat(Value);

                        constraintString += "(" + TableName + "." + ColumnName + "=" + FormattedValue + ")";
                    }
                }

                return(true);
            }

            else
            {
                constraintString = null;
                return(false);
            }
        }
コード例 #15
0
 public DbByteArrayCastFunction(IDbFragment lhs, IColumnType columnType)
 {
     this.lhs        = lhs;
     this.columnType = columnType;
 }
コード例 #16
0
        protected virtual void GetInitialValueString(out string columnString, out ICollection <string> valueStringList)
        {
            ITableDescriptor Table = Context.Table;
            IReadOnlyCollection <IColumnValueCollectionPair>           EntryList     = Context.EntryList;
            IReadOnlyCollection <IColumnValueCollectionPair <byte[]> > DataEntryList = GetDataEntryList();
            int RowCount = Context.RowCount;

            Debug.Assert(EntryList.Count > 0);
            string TableName = GetTableName();

            columnString = "";
            string[] StringList = new string[RowCount];
            for (int i = 0; i < RowCount; i++)
            {
                StringList[i] = "";
            }

            int DataCount = 0;

            foreach (IColumnValueCollectionPair <byte[]> DataEntry in DataEntryList)
            {
                IColumnDescriptor Column          = DataEntry.Column;
                IColumnType       ColumnType      = Column.Type;
                IEnumerable       ValueCollection = DataEntry.ValueCollection;
                string            ColumnName      = Column.Name;

                if (columnString.Length > 0)
                {
                    columnString += ", ";
                }
                columnString += ColumnName;

                int i = 0;
                foreach (object Value in ValueCollection)
                {
                    if (i < RowCount)
                    {
                        string ValueString = StringList[i];
                        if (ValueString.Length > 0)
                        {
                            ValueString += ", ";
                        }

                        ValueString  += $"?data{DataCount}";
                        StringList[i] = ValueString;

                        DataCount++;
                        i++;
                    }
                }

                Debug.Assert(i == RowCount);
            }

            foreach (IColumnValueCollectionPair Entry in EntryList)
            {
                IColumnDescriptor Column = Entry.Column;
                if (Column is IColumnDescriptorByteArray)
                {
                    continue;
                }

                IColumnType ColumnType      = Column.Type;
                IEnumerable ValueCollection = Entry.ValueCollection;
                string      ColumnName      = Column.Name;

                if (columnString.Length > 0)
                {
                    columnString += ", ";
                }
                columnString += ColumnName;

                int i = 0;
                foreach (object Value in ValueCollection)
                {
                    if (i < RowCount)
                    {
                        string ValueString = StringList[i];
                        if (ValueString.Length > 0)
                        {
                            ValueString += ", ";
                        }

                        ValueString  += ColumnType.ToSqlFormat(Value);
                        StringList[i] = ValueString;

                        i++;
                    }
                }

                Debug.Assert(i == RowCount);
            }

            valueStringList = StringList;
        }
コード例 #17
0
ファイル: ucAudit.cs プロジェクト: guochao2299/LogManage
        private void btnAudit_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            try
            {
                SetControlEnabled(false);

                List <LogFilterCondition> lstConditions = new List <LogFilterCondition>();
                LogFilterCondition        condition     = null;

                // 检查过滤条件是否完整
                #region 检查过滤条件是否完整

                List <OperateParam> lstParams = new List <OperateParam>();
                int rowIndex = 0;
                foreach (DataGridViewRow dgvr in this.dgvConditions.Rows)
                {
                    rowIndex++;

                    if (Convert.ToBoolean(dgvr.Cells[SelectColumnIndex].Value))
                    {
                        lstParams.Clear();

                        LogColumn lc = LogColumnService.Instance.GetLogColumn(Convert.ToInt32(dgvr.Tag));

                        IColumnType colType = TableColumnTypeService.Instance.GetColumnType(lc.Type);

                        IRelation relation = RelationService.Instance.GetRelation(lc.Type,
                                                                                  Convert.ToString(dgvr.Cells[RelationColumnIndex].Value));

                        // 目前仅支持与一个值比较或者两个值比较
                        // 这里还可以改的更通用一些,把if去掉
                        if (relation.ParamsCount == 1)
                        {
                            string value = Convert.ToString(dgvr.Cells[ContentColumnIndex].Value);

                            if (!colType.Validate(value))
                            {
                                dgvr.Cells[ContentColumnIndex].Selected = true;
                                throw new Exception(string.Format("行{0}的值有误,不符合类型“{1}”的格式要求", rowIndex, lc.Type));
                            }

                            lstParams.Add(new OperateParam(value));
                            if (!relation.Validate(lstParams))
                            {
                                dgvr.Cells[ContentColumnIndex].Selected = true;
                                throw new Exception(string.Format("行{0}的值有误,不符合关系“{1}”的格式要求", rowIndex, relation.Group));
                            }

                            condition          = new LogFilterCondition(lc.Index, lc.Type);
                            condition.Content  = Convert.ToString(dgvr.Cells[ContentColumnIndex].Value);
                            condition.Relation = relation.Name;

                            lstConditions.Add(condition);
                        }
                        else if (relation.ParamsCount == 2)
                        {
                            string leftValue = Convert.ToString(dgvr.Cells[StartDateColumnIndex].Value);
                            if (!colType.Validate(leftValue))
                            {
                                dgvr.Cells[StartDateColumnIndex].Selected = true;
                                throw new Exception(string.Format("行{0}的值有误,不符合类型“{1}”的格式要求", rowIndex, lc.Type));
                            }

                            string rightValue = Convert.ToString(dgvr.Cells[EndDateColumnIndex].Value);

                            if (!colType.Validate(rightValue))
                            {
                                dgvr.Cells[EndDateColumnIndex].Selected = true;
                                throw new Exception(string.Format("行{0}的值有误,不符合类型“{1}”的格式要求", rowIndex, lc.Type));
                            }

                            lstParams.Add(new OperateParam(leftValue));
                            lstParams.Add(new OperateParam(rightValue));

                            if (!relation.Validate(lstParams))
                            {
                                dgvr.Cells[StartDateColumnIndex].Selected = true;
                                throw new Exception(string.Format("行{0}的值有误,不符合关系“{1}”的格式要求", rowIndex, relation.Group));
                            }

                            condition            = new LogFilterCondition(lc.Index, lc.Type);
                            condition.LeftBound  = leftValue;
                            condition.RightBound = rightValue;
                            condition.Relation   = relation.Name;

                            lstConditions.Add(condition);
                        }
                    }
                }
                #endregion

                #region 开始检索日志
                foreach (LogShowTabPage page in m_tabPages.Values)
                {
                    if (page.Parent == null)
                    {
                        continue;
                    }

                    string tableGuid = Convert.ToString(page.TableGuid);

                    List <LogRecord> lstRecords = LogContentService.Instance.GetAppLogs(m_app.AppGUID, tableGuid, lstConditions);
                    page.SetLogs(lstRecords);
                }
                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("检索{0}的日志时出错,错误消息为:{1}", m_app.Name, ex.Message));
            }
            finally
            {
                this.Cursor = Cursors.Default;
                SetControlEnabled(true);
            }
        }
コード例 #18
0
 public DbDateTimeCastFunction(IDbFragment lhs, IColumnType columnType)
 {
     this.lhs        = lhs;
     this.columnType = columnType;
 }
コード例 #19
0
 public ArrayData(IColumnType columnType)
 {
     ColumnType = columnType;
 }
コード例 #20
0
 public DbStringCastFunction(IDbFragment lhs, IColumnType columnType)
 {
     this.lhs        = lhs;
     this.columnType = columnType;
 }
コード例 #21
0
 public IdData(IColumnType columnType, object obj, string atlas)
     : base(columnType, obj)
 {
     Atlas = atlas;
 }
コード例 #22
0
 public Data(IColumnType columnType, object obj)
 {
     ColumnType = columnType;
     Object     = obj;
 }
コード例 #23
0
        public void GetColumnType_StringType_ExcpectSuccess(string typeString)
        {
            IColumnType testObj = ColumnTypeFactory.GetColumnType(typeString);

            Assert.IsInstanceOf <ColumnTypeString>(testObj);
        }
コード例 #24
0
 public Column(string name, IColumnType type, int index)
 {
     Name  = name ?? throw new MissingColumnNameException();
     Type  = type ?? throw new MissingColumnTypeException(name);
     Index = index;
 }
コード例 #25
0
 public ArrayColumn(IColumnType baseType)
     : base(baseType)
 {
 }