Beispiel #1
0
        static internal CodePrefix FromExpression(string expression, IUnitOfWork unitOfWork, Guid userLoginID, Sys_CodeObject codeObject)
        {
            expression = expression.Trim();
            try
            {
                CodePrefix result = new CodePrefix(userLoginID, codeObject);
                result.unitOfWork = unitOfWork;
                result.isResetByDate = codeObject.IsResetByDate != null ? codeObject.IsResetByDate.Value : false;
                result.isResetByMonth = codeObject.IsResetByMonth != null ? codeObject.IsResetByMonth.Value : false;
                result.isResetByYear = codeObject.IsResetByYear != null ? codeObject.IsResetByYear.Value : false;
                result.isResetByUser = codeObject.IsResetByUser != null ? codeObject.IsResetByUser.Value : false;
                result.isResetByObject = codeObject.IsResetByObject != null ? codeObject.IsResetByObject.Value : false;
                result.resetObjectName = result.isResetByObject ? codeObject.ResetObjectName : string.Empty;
                result.resetFieldName = result.isResetByObject ? codeObject.ResetFieldName : string.Empty;
                result.resetObjectName1 = result.isResetByObject ? codeObject.ResetObjectName1 : string.Empty;
                result.resetFieldName1 = result.isResetByObject ? codeObject.ResetFieldName1 : string.Empty;

                if (result.resetFieldName == null || string.IsNullOrEmpty(result.resetFieldName.Trim()))
                {
                    if (!string.IsNullOrWhiteSpace(codeObject.ResetObjectName))
                    {
                        result.resetFieldName = Constant.ID;
                    }
                }

                if (result.resetFieldName1 == null || string.IsNullOrEmpty(result.resetFieldName1.Trim()))
                {
                    if (!string.IsNullOrWhiteSpace(codeObject.ResetObjectName1))
                    {
                        result.resetFieldName1 = Constant.ID;
                    }
                }

                string function = GetFunction(expression);

                try
                {
                    result.functionType = Common.GetEnumValue<FunctionTypes>(function.Trim().ToUpper());
                }
                catch
                {
                }

                switch (result.functionType)
                {
                    case FunctionTypes.DATE:
                        result.GetDateFormat(expression);
                        break;
                    case FunctionTypes.ORDINAL:
                    case FunctionTypes.OBJECT:
                        result.GetNumber(expression);
                        break;
                    case FunctionTypes.TEXT:
                    default:
                        result.strText = function;
                        break;
                }
                return result;
            }
            catch (Exception e)
            {
                throw new VNRException(ExceptionType.FRAMEWORK, "Wrong expression syntax!", e);
            }
        }
Beispiel #2
0
 internal CodePrefix(Guid userLoginID, Sys_CodeObject codeObject)
 {
     _userLoginID = userLoginID;
     _codeObjectID = codeObject.ID;
     _codeObject = codeObject;
 }
Beispiel #3
0
        internal string GetString(object entityBase, Sys_CodeObject codeObject, DateTime date)
        {
            //var repoUser = new CustomBaseRepository<Sys_UserInfo>(unitOfWork);
            var repoObjDate = new CustomBaseRepository<Sys_CodeObjectByUserNDate>(unitOfWork);

            switch (functionType)
            {
                case FunctionTypes.DATE:
                    return date.ToString(strText);
                case FunctionTypes.OBJECT:
                    string resultObject = string.Empty;
                    if (entityBase != null)
                    {
                        object objectFieldValue = null;
                        object entityObject = null;

                        if (ListObjectTableNames != null && ListObjectTableNames.Count() > 0)
                        {
                            foreach (string resetName in ListObjectTableNames)
                            {
                                if (entityBase.HasProperty(resetName) && entityBase.HasProperty("ID"))
                                {
                                    unitOfWork.Context.Entry(entityBase).Reference(resetName).Load();
                                }

                                entityObject = entityBase.GetPropertyValue(resetName);
                                var entityID = entityObject.GetPropertyValue("ID");
                                if (entityObject != null && entityID.ToString() != Guid.Empty.ToString())
                                {
                                    objectFieldValue = entityObject.GetPropertyValue(objectFieldName);
                                }
                            }
                        }
                        else
                        {
                            objectFieldValue = entityBase.GetPropertyValue(objectFieldName);
                        }

                        if (objectFieldValue != null)
                        {
                            resultObject = GetNumberCharater(objectFieldValue.ToString());
                        }
                    }
                    return resultObject;
                case FunctionTypes.ORDINAL:
                    Sys_CodeObjectByUserNDate codeObjectByUserNDate = null;
                    if (isResetByUser || isResetByObject)
                    {
                        object objectFieldValue = null;
                        object objectFieldValue1 = null;

                        if (entityBase != null && isResetByObject)
                        {
                            if (ListResetObjectNames != null && ListResetObjectNames.Count() > 0)
                            {
                                object entityObject = null;

                                foreach (string resetName in ListResetObjectNames)
                                {
                                    if (entityBase.HasProperty(resetName) && entityBase.HasProperty("ID"))
                                    {
                                        unitOfWork.Context.Entry(entityBase).Reference(resetName).Load();
                                    }
                                    entityObject = entityBase.GetPropertyValue(resetName);
                                    var entityID = entityObject.GetPropertyValue("ID");

                                    if (entityObject != null && entityID.ToString() != Guid.Empty.ToString())
                                    {
                                        objectFieldValue = entityObject.GetPropertyValue(ResetFieldName);
                                    }
                                }
                            }
                            else if (!string.IsNullOrWhiteSpace(ResetFieldName))
                            {
                                objectFieldValue = entityBase.GetPropertyValue(ResetFieldName);
                            }

                            if (ListResetObjectNames1 != null && ListResetObjectNames1.Count() > 0)
                            {
                                object entityObject = null;

                                foreach (string resetName in ListResetObjectNames1)
                                {
                                    entityObject = entityBase.GetPropertyValue(resetName);
                                    var entityID = entityObject.GetPropertyValue("ID");
                                    if (entityObject != null && entityID.ToString() != Guid.Empty.ToString())
                                    {
                                        objectFieldValue1 = entityObject.GetPropertyValue(ResetFieldName1);
                                    }
                                }
                            }
                            else if (!string.IsNullOrWhiteSpace(ResetFieldName1))
                            {
                                objectFieldValue1 = entityBase.GetPropertyValue(ResetFieldName1);
                            }
                        }

                        //ID đối tượng reset theo người dùng hoặc theo đối tượng bất kì
                        objectFieldValue = objectFieldValue != null ? objectFieldValue : string.Empty;
                        objectFieldValue1 = objectFieldValue1 != null ? objectFieldValue1 : string.Empty;

                        string resetObjectID = objectFieldValue.ToString();
                        string resetObjectID1 = objectFieldValue1.ToString();

                        if (isResetByUser)
                        {
                            resetObjectID = _userLoginID.ToString();
                            resetObjectID1 = string.Empty;
                        }

                        if ((string.IsNullOrEmpty(resetObjectID.Trim()) || resetObjectID == Guid.Empty.ToString())
                            && (string.IsNullOrEmpty(resetObjectID1.Trim()) || resetObjectID1 == Guid.Empty.ToString()))
                        {
                            return string.Empty;
                        }

                        if (IsResetByTime)
                        {
                            codeObjectByUserNDate = repoObjDate.FindBy(cobund => cobund.CodeObjectID == _codeObjectID && cobund.ResetObjectID == resetObjectID &&
                                ((cobund.ResetObjectID1 == null && resetObjectID1 == "") || cobund.ResetObjectID1 == resetObjectID1)
                                    && cobund.Date != null).ToList().Where(cobund => cobund.Date.Value.ToString(TimeFormat) == date.ToString(TimeFormat)).FirstOrDefault();
                        }
                        else
                        {
                            codeObjectByUserNDate = repoObjDate.FindBy(cobund => cobund.CodeObjectID == _codeObjectID && cobund.ResetObjectID == resetObjectID
                               && ((cobund.ResetObjectID1 == null && resetObjectID1 == "") || cobund.ResetObjectID1 == resetObjectID1)).FirstOrDefault();
                        }

                        if (codeObjectByUserNDate == null)
                        {
                            codeObjectByUserNDate = new Sys_CodeObjectByUserNDate();
                            codeObjectByUserNDate.ID = Guid.NewGuid();
                            codeObjectByUserNDate.CodeObjectID = _codeObjectID;
                            codeObjectByUserNDate.ResetObjectID = resetObjectID;
                            codeObjectByUserNDate.ResetObjectID1 = resetObjectID1;
                            codeObjectByUserNDate.Ordinal = 1;

                            if (IsResetByTime)
                            {
                                codeObjectByUserNDate.Date = date;
                            }
                            repoObjDate.Add(codeObjectByUserNDate);
                        }
                    }
                    else if (IsResetByTime)
                    {
                        codeObjectByUserNDate = repoObjDate.FindBy(cobund => cobund.CodeObjectID == _codeObjectID && cobund.Date != null).ToList().Where(cobund =>
                            cobund.Date.Value.ToString(TimeFormat) == date.ToString(TimeFormat)).FirstOrDefault();

                        if (codeObjectByUserNDate == null)
                        {
                            codeObjectByUserNDate = new Sys_CodeObjectByUserNDate();
                            codeObjectByUserNDate.ID = Guid.NewGuid();
                            codeObjectByUserNDate.CodeObjectID = _codeObjectID;
                            codeObjectByUserNDate.Ordinal = 1;
                            codeObjectByUserNDate.Date = date;
                            repoObjDate.Add(codeObjectByUserNDate);
                        }
                    }

                    string result = string.Empty;
                    if (codeObjectByUserNDate != null)
                    {
                        int ordinal = codeObjectByUserNDate.Ordinal.GetInteger();
                        result = GetNumberCharater(ordinal.ToString());
                        codeObjectByUserNDate.Ordinal += 1;
                    }
                    else
                    {
                        int ordinal = _codeObject.Ordinal.GetInteger();
                        result = GetNumberCharater(ordinal.ToString());
                    }
                    return result;

                case FunctionTypes.TEXT:
                default:
                    return strText;
            }
        }