Пример #1
0
        public static ModuleFieldInfo GetModuleFieldByName(string moduleID, string fieldGroup, string fieldName)
        {
            var fieldInfos = (from field in AllCaches.ModuleFieldsInfo
                              where field.ModuleID == moduleID && field.FieldGroup == fieldGroup && field.FieldName == fieldName
                              select field).ToArray();

            if (fieldInfos.Length == 0)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_FIELD_NOT_FOUND, fieldName);
            }
            if (fieldInfos.Length > 1)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_FIELD_DUPLICATED, fieldName);
            }

            return(fieldInfos[0]);
        }
Пример #2
0
 public static ModuleFieldInfo GetModuleFieldByModule(ModuleInfo modInfo, string fieldID)
 {
     try
     {
         return((from field in AllCaches.ModuleFieldsInfo
                 where (field.ModuleID == modInfo.ModuleID || field.ModuleID == modInfo.ModuleType) && field.FieldID == fieldID
                 select field).Single());
     }
     catch (FaultException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_MODULE_FIELD_NOT_FOUND_OR_DUPLICATE, ex.Message,
                                                    "GetModuleFieldByID", modInfo.ModuleID, fieldID);
     }
 }
Пример #3
0
        public static ModuleInfo GetModuleInfo(string moduleID, string subModule)
        {
            var module = (from item in AllCaches.ModulesInfo
                          where item.ModuleID == moduleID && (string.IsNullOrEmpty(subModule) || subModule == item.SubModule)
                          select item).ToList();

            if (module.Count == 0)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_MODULE_NOT_FOUND, moduleID + "." + subModule);
            }

            if (module.Count > 1)
            {
                throw ErrorUtils.CreateError(ERR_SYSTEM.ERR_SYSTEM_MODULE_HAVE_TO_CALL_SUB, moduleID + "." + subModule);
            }

            return(NewCopyModule(module[0]));
        }
Пример #4
0
        public static object ConvertImport(ModuleFieldInfo fieldInfo, object value, string fieldName)
        {
            try
            {
                if (fieldInfo.Nullable == CODES.DEFMODFLD.NULLABLE.YES &&
                    (value == null || string.IsNullOrEmpty(value.ToString().Trim())))
                {
                    return(null);
                }

                switch (fieldInfo.ImportType)
                {
                case CODES.DEFMODFLD.FLDTYPE.INT32:
                    return(System.Convert.ToInt32(value, App.Environment.ClientInfo.Culture));

                case CODES.DEFMODFLD.FLDTYPE.INT64:
                    return(System.Convert.ToInt64(value, App.Environment.ClientInfo.Culture));

                case CODES.DEFMODFLD.FLDTYPE.FLOAT:
                    return(System.Convert.ToSingle(value, App.Environment.ClientInfo.Culture));

                case CODES.DEFMODFLD.FLDTYPE.DOUBLE:
                    return(System.Convert.ToDouble(value, App.Environment.ClientInfo.Culture));

                case CODES.DEFMODFLD.FLDTYPE.DATE:
                    if (string.IsNullOrEmpty(fieldInfo.FieldFormat))
                    {
                        return(DateTime.ParseExact(value.ToString(), CONSTANTS.DEFAULT_DATETIME_FORMAT, null));
                    }
                    return(DateTime.ParseExact(value.ToString(), fieldInfo.FieldFormat, null));

                default:
                    return(value);
                }
            }
            catch
            {
                var errorFormat = LangUtils.TranslateBasic("Convert column {0} failed", "IMPORT_DATA_CONVERT_FAIL");
                throw ErrorUtils.CreateErrorWithSubMessage(ERR_IMPORT.ERR_CONVERT_IMPORT_DATA_FAIL,
                                                           string.Format(errorFormat, fieldName));
            }
        }
Пример #5
0
        public static ModuleInfo GetModuleInfo(string moduleID)
        {
            var module = (from item in AllCaches.ModulesInfo
                          where
                          item.ModuleID == moduleID &&
                          ((item.SubModule == CODES.DEFMOD.SUBMOD.MAINTAIN_ADD) ||
                           (item.SubModule == CODES.DEFMOD.SUBMOD.MODULE_MAIN))
                          select item).ToList();

            if (module.Count == 0)
            {
                throw ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_MODULE_NOT_FOUND, moduleID);
            }

            if (module.Count > 1)
            {
                throw ErrorUtils.CreateError(ERR_SYSTEM.ERR_SYSTEM_MODULE_HAVE_TO_CALL_SUB, moduleID);
            }

            return(NewCopyModule(module[0]));
        }
Пример #6
0
        public static ProcExpression ParseScript(string source)
        {
            if (!string.IsNullOrEmpty(source))
            {
                var procExpression = new ProcExpression();
                var match          = Regex.Match(source, "([^\\(]+)\\(([^\\)]*)\\)");

                if (match.Success)
                {
                    procExpression.StoreProcName = match.Groups[1].Value;
                    //
                    var strParams = match.Groups[2].Value + ",";
                    if (!string.IsNullOrEmpty(match.Groups[2].Value))
                    {
                        var    cur    = 0;
                        var    opened = false;
                        string param  = null;
                        string value  = null;

                        while (cur < strParams.Length)
                        {
                            if (strParams[cur] == '\'')
                            {
                                if (cur + 1 < strParams.Length && strParams[cur + 1] == '\'' && opened)
                                {
                                    value += '\'';
                                    cur++;
                                }
                                else
                                {
                                    opened = !opened;
                                }
                            }
                            else if (strParams[cur] == ',')
                            {
                                if (opened)
                                {
                                    value += ',';
                                }
                                else
                                {
                                    decimal num;
                                    param = param == null ? param : param.Trim();
                                    if (string.IsNullOrEmpty(param))
                                    {
                                        procExpression.Operands.Add(new Operand(OperandType.VALUE, value));
                                    }
                                    else if (decimal.TryParse(param, out num))
                                    {
                                        procExpression.Operands.Add(new Operand(OperandType.VALUE, num.ToString()));
                                    }
                                    else if (value == null)
                                    {
                                        procExpression.Operands.Add(new Operand(OperandType.NAME, param));
                                    }
                                    else
                                    {
                                        throw ErrorUtils.CreateErrorWithSubMessage(ERR_SYSTEM.ERR_SYSTEM_PARSE_SQL_SCRIPT_ERROR,
                                                                                   "ParseScript", source);
                                    }

                                    param = null;
                                    value = null;
                                }
                            }
                            else
                            {
                                if (opened)
                                {
                                    value += strParams[cur];
                                }
                                else
                                {
                                    param += strParams[cur];
                                }
                            }
                            cur++;
                        }
                    }

                    return(procExpression);
                }

                throw ErrorUtils.CreateError(ERR_SYSTEM.ERR_SYSTEM_PARSE_SQL_SCRIPT_ERROR,
                                             "ParseScript", source);
            }
            return(null);
        }