示例#1
0
        /// <summary>
        /// 建立運數子
        /// </summary>
        /// <param name="whereMode">運數子種類</param>
        /// <returns></returns>
        public static IOperator ConstructOperator(WhereMode whereMode)
        {
            switch (whereMode)
            {
            case WhereMode.Equal:
                return(new WhereEqual());

            case WhereMode.Like:
                return(new WhereLike());

            case WhereMode.IsGreaterThen:
                return(new WhereGreaterThen());

            case WhereMode.IsLessThen:
                return(new WhereLessThen());

            case WhereMode.IsGreaterThenAndEqual:
                return(new WhereGreaterThenEqual());

            case WhereMode.IsLessThenAndEqual:
                return(new WhereLessThenEqual());
            }
            return(null);
        }
 public PredicateWhere(Expression <Func <T, bool> > condition, WhereMode mode) : base(typeof(T))
 {
     Condition = condition;
     PanMode   = mode;
 }
示例#3
0
文件: LkXml.cs 项目: Lonka/LK.Util
 /// <summary>
 /// 判斷兩數是否有符合運算子
 /// </summary>
 /// <param name="keyValue">來源值</param>
 /// <param name="whereValue">比較值</param>
 /// <param name="whereMode">運算子種類</param>
 /// <returns></returns>
 private bool CheckWhere(string keyValue, string whereValue, WhereMode whereMode)
 {
     Xml.IOperator iOperator = Xml.Expression.ConstructOperator(whereMode);
     return(iOperator.IsCompare(keyValue, whereValue));
 }
示例#4
0
文件: LkXml.cs 项目: Lonka/LK.Util
        /// <summary>
        /// 遞迴找Element
        /// </summary>
        /// <param name="source">來源的Element</param>
        /// <param name="searchElementName">目標的Element Name</param>
        /// <param name="whereKey">要查詢的Key</param>
        /// <param name="whereValue">要符合條件的Value</param>
        /// <param name="whereMode">比對條件</param>
        /// <returns></returns>
        private List <XmlElement> RecursiveSelElements(XmlElement source, string searchElementName, string whereKey, string whereValue, WhereMode whereMode)
        {
            List <XmlElement> result = new List <XmlElement>();

            foreach (XmlElement element in source.ChildNodes)
            {
                if (element.Name == searchElementName)
                {
                    if (string.IsNullOrEmpty(whereKey))
                    {
                        result.Add(element);
                    }
                    else if (element.Attributes[whereKey] == null)
                    {
                        throw new Exception(whereKey + "-無法對應的Key值");
                    }
                    else if (CheckWhere(element.Attributes[whereKey].Value, whereValue, whereMode))
                    {
                        result.Add(element);
                    }
                }
                else if (element.ChildNodes.Count > 0)
                {
                    List <XmlElement> nodesResult = RecursiveSelElements(element, searchElementName, whereKey, whereValue, whereMode);
                    foreach (XmlElement xe in nodesResult)
                    {
                        result.Add(xe);
                    }
                }
            }
            return(result);
        }
示例#5
0
文件: LkXml.cs 项目: Lonka/LK.Util
        /// <summary>
        /// 實際執行找Element
        /// </summary>
        /// <param name="elementName">Element Name</param>
        /// <param name="whereKey">要查詢的Key</param>
        /// <param name="whereValue">要符合條件的Value</param>
        /// <param name="whereMode">比對條件</param>
        /// <returns></returns>
        private List <XmlElement> DoSelElements(string elementName, string whereKey, string whereValue, WhereMode whereMode)
        {
            List <XmlElement> result = new List <XmlElement>();
            XmlNodeList       nodes  = doc.SelectNodes(elementName);

            if (nodes.Count == 0)
            {
                return(RecursiveSelElements(doc.DocumentElement, elementName, whereKey, whereValue, whereMode));
            }
            else
            {
                foreach (XmlNode node in nodes)
                {
                    if (string.IsNullOrEmpty(whereKey))
                    {
                        result.Add(node as XmlElement);
                    }
                    else if (node.Attributes[whereKey] == null)
                    {
                        throw new Exception(whereKey + "-無法對應的Key值");
                    }
                    else if (CheckWhere(node.Attributes[whereKey].Value, whereValue, whereMode))
                    {
                        result.Add(node as XmlElement);
                    }
                }
            }
            return(result);
        }
示例#6
0
文件: LkXml.cs 项目: Lonka/LK.Util
 /// <summary>
 /// 找多個Element
 /// </summary>
 /// <param name="elementName">Element Name</param>
 /// <param name="whereKey">要查詢的Key</param>
 /// <param name="whereValue">要符合條件的Value</param>
 /// <param name="whereMode">比對條件</param>
 /// <returns></returns>
 public List <XmlElement> SelElements(string elementName, string whereKey, string whereValue, WhereMode whereMode)
 {
     return(DoSelElements(elementName, whereKey, whereValue, whereMode));
 }
示例#7
0
        private List<TransKeyField> GetTransKeyFieldsList(Transaction transaction, DataTable transTableSchema,
            WhereMode noWhereMode)
        {
            if (transaction == null)
                return null;

            List<TransKeyField> transKeyFieldsList = new List<TransKeyField>();
            TransKeyFieldCollection transKFList = transaction.TransKeyFields;

            foreach (TransKeyField kF in transKFList)
            {
                String desField = kF.DesField;
                String srcField = kF.SrcField;

                if (kF.WhereMode != noWhereMode)
                {
                    if (srcField == null || srcField.Length == 0)
                    {
                        // if (_srcRow.RowState == DataRowState.Added && kF.SrcGetValue != null && kF.SrcGetValue.Length != 0)
                        if (kF.SrcGetValue != null && kF.SrcGetValue.Length != 0)
                        {
                            if (!IsInSchema(desField, transTableSchema))
                            {
                                String message = SysMsg.GetSystemMessage(((transaction.Owner as InfoTransaction).OwnerComp as DataModule).Language, "Srvtools", "InfoTransaction", "msg_TransFieldDesExistInTable");
                                throw new ArgumentException(String.Format(message, _transaction.Name, kF.DesField, desField, transTableSchema));
                            }

                            kF.FieldType = GetFieldType(desField, transTableSchema);

                            if (type == ClientType.ctMsSql || type == ClientType.ctOleDB)
                            {
                                kF.FieldTypeName = GetFieldTypeName(desField, transTableSchema);
                            }

                            if (_srcRow.RowState == DataRowState.Added)
                            {
                                kF.DesValue = null;
                            }
                            else
                            {
                                if (kF.DesValue == null)
                                {
                                    kF.DesValue = GetFieldDefaultValue(kF);
                                }
                            }

                            if (_srcRow.RowState == DataRowState.Deleted)
                            {
                                kF.SrcValue = null;
                            }
                            else
                            {
                                if (kF.SrcValue == null)
                                {
                                    kF.SrcValue = GetFieldDefaultValue(kF);
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (!IsInSchema(desField, transTableSchema))
                        {
                            String message = SysMsg.GetSystemMessage(((transaction.Owner as InfoTransaction).OwnerComp as DataModule).Language, "Srvtools", "InfoTransaction", "msg_TransKeyFieldDesExistInTable");
                            throw new ArgumentException(String.Format(message, _transaction.Name, kF.DesField, desField, transTableSchema));
                        }

                        if (!IsInSchema(srcField, _srcSchema))
                        {
                            String message = SysMsg.GetSystemMessage(((transaction.Owner as InfoTransaction).OwnerComp as DataModule).Language, "Srvtools", "InfoTransaction", "msg_TransKeyFieldSrcExistInTable");
                            throw new ArgumentException(String.Format(message, _transaction.Name, kF.DesField, srcField, _srcTableName));
                        }

                        //if (!IsInSchema(desField, transTableSchema))
                        //    throw new Exception("The " + desField + " is not " + transaction.TransTableName + "'s column.");

                        //if (!IsInSchema(srcField, _srcSchema))
                        //    throw new Exception("The " + srcField + " is not " + _srcTableName + "'s column.");

                        String desFieldType = GetFieldType(desField, transTableSchema);
                        String srcFieldType = GetFieldType(srcField, _srcSchema);
                        String srcFieldTypeName = "";

                        if (type == ClientType.ctMsSql || type == ClientType.ctOleDB)
                        {
                            srcFieldTypeName = GetFieldTypeName(srcField, _srcSchema);
                        }

                        if (desFieldType != srcFieldType)
                        {
                            // throw new Exception("The " + desField + " and " + srcField + " are not same type.");
                            String message = SysMsg.GetSystemMessage(((transaction.Owner as InfoTransaction).OwnerComp as DataModule).Language, "Srvtools", "InfoTransaction", "msg_TransKeyFieldDesAndSrcNotSameType");
                            throw new ArgumentException(String.Format(message, new Object[] { _transaction.Name, kF.DesField, desField, srcField }));
                        }

                        if (kF.WhereMode == WhereMode.Both || kF.WhereMode == WhereMode.InsertOnly)
                        {

                            if (type != ClientType.ctOracle)
                            {
                                if (IsReadOnly(desField, transTableSchema))
                                    kF.ReadOnly = true;
                                else
                                    kF.ReadOnly = false;
                            }
                        }

                        if (kF.WhereMode == WhereMode.WhereOnly)
                        {
                            if (!IsIncludedInWhereClause(desField, transTableSchema))
                            {
                                throw new Exception("The " + desField + " column has a error.");
                            }
                        }

                        if (_srcRow.RowState == DataRowState.Added)
                        {
                            kF.DesValue = null;
                        }
                        else
                        {
                            kF.DesValue = _srcRow[srcField, DataRowVersion.Original];
                        }

                        if (_srcRow.RowState == DataRowState.Deleted)
                        {
                            kF.SrcValue = null;
                        }
                        else
                        {
                            kF.SrcValue = _srcRow[srcField, DataRowVersion.Current];
                        }

                        kF.FieldType = srcFieldType;
                        kF.FieldTypeName = srcFieldTypeName == null ? "" : srcFieldTypeName;
                    }

                    transKeyFieldsList.Add(kF);
                }
            }

            return transKeyFieldsList;
        }
示例#8
0
 public TransKeyField(String desField)
     : base(desField)
 {
     _wherMode = WhereMode.Both;
 }
示例#9
0
 public TransKeyField()
     : base("")
 {
     _wherMode = WhereMode.Both;
 }
示例#10
0
 /// <summary>
 /// Creates a new Where item
 /// </summary>
 /// <param name="mode">the Wheremode of the new item</param>
 /// <param name="column">the search column of this query</param>
 /// <returns>the created where for further usage</returns>
 private Where CreateWhere(WhereMode mode, Column column)
 {
     return(new Where {
         whereMode = mode, column = column, parent = this
     });
 }