Beispiel #1
0
        public bool ArtifactCodeRuleEditing_PreTransitionCRUD(string transition)
        {
            try
            {
                switch (transition)
                {
                case "Save":

                    Guid   artifactTypeId = Guid.Parse(cbbArtifactType.SelectedItem.Value.ToString());
                    string name           = txtArtifactCodeRuleName.Text;
                    string description    = txtArtifactCodeRuleDescription.Text;

                    ArtifactType artifactType       = session.GetObjectByKey <ArtifactType>(artifactTypeId);
                    Guid         artifactCodeRuleId = ArtifactCodeRuleId;

                    ArtifactCodeRule artifactCodeRule =
                        session.GetObjectByKey <ArtifactCodeRule>(artifactCodeRuleId);
                    artifactCodeRule.ArtifactTypeId = artifactType;
                    artifactCodeRule.Description    = description;
                    artifactCodeRule.LastUpdateDate = DateTime.Now;
                    artifactCodeRule.Name           = name;
                    artifactCodeRule.Save();

                    break;

                default:
                    break;
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #2
0
        public void Delete(Session session, Guid artifactCodeRuleId)
        {
            try
            {
                ArtifactCodeRule artifactCodeRule =
                    session.GetObjectByKey <ArtifactCodeRule>(artifactCodeRuleId);

                artifactCodeRule.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                artifactCodeRule.Save();
                if (artifactCodeRule != null)
                {
                    if (artifactCodeRule.CodeRuleDefinitions != null)
                    {
                        CodeRuleDefinitionBO codeRuleDefinitionBO = new CodeRuleDefinitionBO();
                        foreach (var definition in artifactCodeRule.CodeRuleDefinitions)
                        {
                            codeRuleDefinitionBO.Delete(session, definition.CodeRuleDefinitionId);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #3
0
        public string GetArtifactCodeOfArtifactType(Guid artifactTypeId)
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                //Get first active artifact code rule of the artifact type
                ArtifactCodeRule artifactCodeRule =
                    session.GetObjectByKey <ArtifactType>(artifactTypeId).ArtifactCodeRules
                    .Where(r => r.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE)
                    .FirstOrDefault();
                if (artifactCodeRule == null)
                {
                    return(String.Empty);
                }
                return(GetArtifactCode(artifactCodeRule.ArtifactCodeRuleId, true));
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Beispiel #4
0
        public CodeRuleDefinition Insert(Session session, Guid artifactCodeRuleId, Guid codeRuleDataTypeId, Guid parentCodeRuleDefinitionId)
        {
            CodeRuleDefinition codeRuleDefinition = null;

            try
            {
                //Get ArtifactCodeRule
                ArtifactCodeRule artifactCodeRule =
                    session.GetObjectByKey <ArtifactCodeRule>(artifactCodeRuleId);
                //Get CodeRuleDataType
                CodeRuleDataType codeRuleDataType =
                    session.GetObjectByKey <CodeRuleDataType>(codeRuleDataTypeId);
                //Get parent CodeRuleDefinition
                CodeRuleDefinition parentCodeRuleDefinition = null;
                if (parentCodeRuleDefinitionId != Guid.Empty)
                {
                    parentCodeRuleDefinition = session.GetObjectByKey <CodeRuleDefinition>(parentCodeRuleDefinitionId);
                }
                //Validate
                bool isInsertingValid =
                    isInsertingCodeRuleDefinitionValid(session, artifactCodeRuleId, parentCodeRuleDefinition);

                if (isInsertingValid)
                {
                    //Create new CodeRuleDefinition
                    codeRuleDefinition = new CodeRuleDefinition(session)
                    {
                        ArtifactCodeRuleId         = artifactCodeRule,
                        CodeRuleDataTypeId         = codeRuleDataType,
                        CodeRuleDefinitionId       = Guid.NewGuid(),
                        ParentCodeRuleDefinitionId = parentCodeRuleDefinition,
                        RowStatus = Utility.Constant.ROWSTATUS_ACTIVE
                    };
                    codeRuleDefinition.Save();
                }

                return(codeRuleDefinition);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #5
0
        public bool ArtifactCodeRuleCreating_PreTransitionCRUD(string transition)
        {
            try
            {
                switch (transition)
                {
                case "Save":

                    Guid   artifactTypeId = Guid.Parse(cbbArtifactType.SelectedItem.Value.ToString());
                    string name           = txtArtifactCodeRuleName.Text;
                    string description    = txtArtifactCodeRuleDescription.Text;

                    ArtifactType artifactType = session.GetObjectByKey <ArtifactType>(artifactTypeId);

                    ArtifactCodeRule newArtifactCodeRule = new ArtifactCodeRule(session)
                    {
                        ArtifactCodeRuleId = Guid.NewGuid(),
                        ArtifactTypeId     = artifactType,
                        CreateDate         = DateTime.Now,
                        Description        = description,
                        IssueDate          = DateTime.Now,
                        LastUpdateDate     = DateTime.Now,
                        Name      = name,
                        RowStatus = Utility.Constant.ROWSTATUS_ACTIVE
                    };

                    newArtifactCodeRule.Save();

                    ArtifactCodeRuleId = newArtifactCodeRule.ArtifactCodeRuleId;

                    break;

                default:
                    break;
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #6
0
        public bool isInsertingCodeRuleDefinitionValid(Session session, Guid artifactCodeRuleId, CodeRuleDefinition parentCodeRuleDefinition)
        {
            try
            {
                //Get ArtifactCodeRule
                ArtifactCodeRule artifactCodeRule = session.GetObjectByKey <ArtifactCodeRule>(artifactCodeRuleId);

                if (parentCodeRuleDefinition == null)
                {
                    //Is CodeRuleDefinition root of the ArtifactCodeRule exist
                    int rootCount =
                        artifactCodeRule.CodeRuleDefinitions
                        .Where(r => r.RowStatus > 0 && r.ParentCodeRuleDefinitionId == null)
                        .Count();
                    if (rootCount != 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    //Check parentCodeRuleDefinition already has child
                    int countChild = parentCodeRuleDefinition.CodeRuleDefinitions.Count(r => r.RowStatus > 0);
                    if (countChild != 0)
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #7
0
        public List <CodeRuleDefinitionView> GetCodeRuleDefinitionView(Guid artifactCodeRuleId)
        {
            List <CodeRuleDefinitionView> ret = null;
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                ArtifactCodeRule artifactCodeRule = session.GetObjectByKey <ArtifactCodeRule>(artifactCodeRuleId);

                XPQuery <CodeRuleData>       codeRuleDataQuery       = session.Query <CodeRuleData>();
                XPQuery <CodeRuleDefinition> codeRuleDefinitionQuery = session.Query <CodeRuleDefinition>();

                List <CodeRuleData> codeRuleDataList = (from da in codeRuleDataQuery
                                                        join de in codeRuleDefinitionQuery
                                                        on da.CodeRuleDefinitionId equals de
                                                        where de.ArtifactCodeRuleId == artifactCodeRule &&
                                                        de.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE &&
                                                        da.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE
                                                        select da).ToList();

                if (codeRuleDataList != null)
                {
                    ret = new List <CodeRuleDefinitionView>();
                    foreach (CodeRuleData item in codeRuleDataList)
                    {
                        CodeRuleDefinitionView codeRuleDefinitionView;
                        if (item is CodeRuleStringData)
                        {
                            CodeRuleStringData actualCodeRuleData = (CodeRuleStringData)item;
                            Guid parentCodeRuleDefinitionId       = Guid.Empty;
                            if (actualCodeRuleData.CodeRuleDefinitionId.ParentCodeRuleDefinitionId != null)
                            {
                                parentCodeRuleDefinitionId =
                                    actualCodeRuleData.CodeRuleDefinitionId.ParentCodeRuleDefinitionId.CodeRuleDefinitionId;
                            }
                            codeRuleDefinitionView = new CodeRuleDefinitionView()
                            {
                                CodeRuleDefinitionId       = actualCodeRuleData.CodeRuleDefinitionId.CodeRuleDefinitionId,
                                ParentCodeRuleDefinitionId = parentCodeRuleDefinitionId,
                                DataFormat = actualCodeRuleData.CodeRuleDataFormatId.Name,
                                DataType   = actualCodeRuleData.CodeRuleDefinitionId.CodeRuleDataTypeId.Name,
                                DataValue  = actualCodeRuleData.StringValue
                            };
                        }
                        else if (item is CodeRuleNumberData)
                        {
                            CodeRuleNumberData actualCodeRuleData = (CodeRuleNumberData)item;
                            Guid parentCodeRuleDefinitionId       = Guid.Empty;
                            if (actualCodeRuleData.CodeRuleDefinitionId.ParentCodeRuleDefinitionId != null)
                            {
                                parentCodeRuleDefinitionId =
                                    actualCodeRuleData.CodeRuleDefinitionId.ParentCodeRuleDefinitionId.CodeRuleDefinitionId;
                            }
                            codeRuleDefinitionView = new CodeRuleDefinitionView()
                            {
                                CodeRuleDefinitionId       = actualCodeRuleData.CodeRuleDefinitionId.CodeRuleDefinitionId,
                                ParentCodeRuleDefinitionId = parentCodeRuleDefinitionId,
                                DataFormat = actualCodeRuleData.CodeRuleDataFormatId.Name,
                                DataType   = actualCodeRuleData.CodeRuleDefinitionId.CodeRuleDataTypeId.Name,
                                DataValue  = actualCodeRuleData.BeginNumberValue.ToString()
                            };
                        }
                        else
                        {
                            CodeRuleData actualCodeRuleData         = item;
                            Guid         parentCodeRuleDefinitionId = Guid.Empty;
                            if (actualCodeRuleData.CodeRuleDefinitionId.ParentCodeRuleDefinitionId != null)
                            {
                                parentCodeRuleDefinitionId =
                                    actualCodeRuleData.CodeRuleDefinitionId.ParentCodeRuleDefinitionId.CodeRuleDefinitionId;
                            }
                            codeRuleDefinitionView = new CodeRuleDefinitionView()
                            {
                                CodeRuleDefinitionId       = actualCodeRuleData.CodeRuleDefinitionId.CodeRuleDefinitionId,
                                ParentCodeRuleDefinitionId = parentCodeRuleDefinitionId,
                                DataFormat = actualCodeRuleData.CodeRuleDataFormatId.Name,
                                DataType   = actualCodeRuleData.CodeRuleDefinitionId.CodeRuleDataTypeId.Name,
                                DataValue  = String.Empty
                            };
                        }
                        ret.Add(codeRuleDefinitionView);
                    }
                }
                return(ret);
            }
            catch (Exception)
            {
                return(null);
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }