Example #1
0
 private void CheckDataType(ConfigField cfgFld, ConfigCheck chk, string value, string headerText)
 {
     if (chk.CheckDataType == "integer")
     {
         try
         {
             if ((Convert.ToDecimal(value) * 10) / 10 != Convert.ToInt32(value))
             {
                 throw new Exception("$Import_CheckDataType_Integer_Error [" + headerText + ": " + value + "]");
             }
         }
         catch
         {
             throw new Exception("$Import_CheckDataType_Integer_Error [" + headerText + ": " + value + "]");
         }
     }
     else if (chk.CheckDataType == "numeric")
     {
         try
         {
             decimal d = Convert.ToDecimal(value);
         }
         catch
         {
             throw new Exception("$Import_DataFormat_Error [" + headerText + ": " + value + "]");
         }
     }
 }
Example #2
0
        private static ConfigCheck GetConfigCheckFromXmlNode(XmlNode nodeCheck)
        {
            ConfigCheck chk = new ConfigCheck();

            chk.Type                = GetNodeAttribute(nodeCheck, "Type");
            chk.ParentObjectType    = GetNodeAttribute(nodeCheck, "ParentObjectType");
            chk.ParentObjectField   = GetNodeAttribute(nodeCheck, "ParentObjectField");
            chk.CheckDataType       = GetNodeAttribute(nodeCheck, "CheckDataType");
            chk.LengthExpression    = GetNodeAttribute(nodeCheck, "LengthExpression");
            chk.DataRangeExpression = GetNodeAttribute(nodeCheck, "DataRangeExpression");
            chk.ExistCheckSql       = GetNodeAttribute(nodeCheck, "ExistCheckSql");
            return(chk);
        }
Example #3
0
        private void CheckDataRange(object objIns, ConfigField cfgFld, ConfigCheck chk, string value, string headerText)
        {
            string strRngExp = chk.DataRangeExpression;

            if (strRngExp.IndexOf("{0}") >= 0)
            {
                strRngExp = strRngExp.Replace("{0}", value);
            }
            else
            {
                strRngExp = value + strRngExp;
            }
            int iIdxFrom = 0;

            while (true)
            {
                int iFrom = strRngExp.IndexOf("{", iIdxFrom);
                if (iFrom < 0)
                {
                    break;
                }
                int iTo = strRngExp.IndexOf("}", iFrom);
                if (iTo < 0)
                {
                    break;
                }
                string strFieldName = strRngExp.Substring(iFrom + 1, iTo - iFrom - 1);
                if (DomainObjectUtility.GetFieldName(objIns.GetType(), strFieldName) != null)
                {
                    string strRepVal = DomainObjectUtility.GetValue(objIns, strFieldName, null).ToString();
                    strRngExp = strRngExp.Substring(0, iFrom) + strRepVal + strRngExp.Substring(iTo + 1);
                    iIdxFrom  = iFrom;
                }
                else
                {
                    iIdxFrom = iTo;
                }
            }
            string strExp    = strRngExp;
            object objResult = Microsoft.JScript.Eval.JScriptEvaluate(strExp, Microsoft.JScript.Vsa.VsaEngine.CreateEngine());

            if (Convert.ToBoolean(objResult) == false)
            {
                throw new Exception("$Import_DataRange_Error [" + headerText + ": " + value + "]");
            }
        }
Example #4
0
 /// <summary>
 /// 检查数据值
 /// </summary>
 /// <returns></returns>
 private void CheckData(object objIns, ConfigField cfgFld, string value, string headerText)
 {
     if (cfgFld.CheckList == null || cfgFld.CheckList.Count == 0)
     {
         return;
     }
     for (int i = 0; i < cfgFld.CheckList.Count; i++)
     {
         ConfigCheck chk = cfgFld.CheckList[i];
         if (chk.Type == FieldCheckType.Length)
         {
             string strExp = chk.LengthExpression;
             if (strExp.IndexOf("{0}") >= 0)
             {
                 strExp = strExp.Replace("{0}", value.Length.ToString());
             }
             else
             {
                 strExp = value.Length.ToString() + strExp;
             }
             object objResult = Microsoft.JScript.Eval.JScriptEvaluate(strExp, Microsoft.JScript.Vsa.VsaEngine.CreateEngine());
             if (Convert.ToBoolean(objResult) == false)
             {
                 throw new Exception("$Import_Length_Error [" + headerText + ": " + value + "]");
             }
         }
         else if (chk.Type == FieldCheckType.DataRange)
         {
             CheckDataRange(objIns, cfgFld, chk, value, headerText);
         }
         else if (chk.Type == FieldCheckType.DataType)
         {
             CheckDataType(cfgFld, chk, value, headerText);
         }
         else if (chk.Type == FieldCheckType.Exist)
         {
             if (value != null && value != string.Empty)
             {
                 CheckDataExist(cfgFld, chk, value, headerText);
             }
         }
     }
 }
Example #5
0
 private void CheckDataExist(ConfigField cfgFld, ConfigCheck chk, string value, string headerText)
 {
     if (chk.ParentObjectType != "" && chk.ParentObjectField != "")
     {
         System.Type type    = GetTypeFromDomain(chk.ParentObjectType);
         object[]    objsTmp = this.dataProvider.CustomSearch(type, new string[] { chk.ParentObjectField }, new object[] { value });
         if (objsTmp == null || objsTmp.Length == 0)
         {
             throw new Exception("$Data_Not_Exist [" + headerText + ": " + value + "]");
         }
     }
     else if (chk.ExistCheckSql != "")
     {
         string strSql = string.Format(chk.ExistCheckSql, value);
         if (this.dataProvider.GetCount(new SQLCondition(strSql)) <= 0)
         {
             throw new Exception("$Data_Not_Exist [" + headerText + ": " + value + "]");
         }
     }
 }