public CodeRuleStringData Insert(Session session, Guid codeRuleDefinitionId, Guid codeRuleDataFormatId, string stringValue) { CodeRuleStringData codeRuleStringData = null; try { //Get CodeRuleDefinition CodeRuleDefinition codeRuleDefinition = session.GetObjectByKey <CodeRuleDefinition>(codeRuleDefinitionId); //Get CodeRuleDataFormat CodeRuleDataFormat codeRuleDataFormat = session.GetObjectByKey <CodeRuleDataFormat>(codeRuleDataFormatId); //Create new CodeRuleStringData codeRuleStringData = new CodeRuleStringData(session) { CodeRuleDataFormatId = codeRuleDataFormat, CodeRuleDataId = Guid.NewGuid(), CodeRuleDefinitionId = codeRuleDefinition, CreateDate = DateTime.Now, RowStatus = Utility.Constant.ROWSTATUS_ACTIVE, StringValue = stringValue }; codeRuleStringData.Save(); return(codeRuleStringData); } catch (Exception ex) { return(null); } }
public CodeRuleStringData Update(Session session, Guid codeRuleDefinitionId, Guid codeRuleDataFormatId, string stringValue) { CodeRuleStringData codeRuleStringData = null; try { CodeRuleDataBO codeRuleDataBO = new CodeRuleDataBO(); //Check updating CodeRuleDataType already exist //Get CodeRuleDataFormat CodeRuleDataFormat codeRuleDataFormat = session.GetObjectByKey <CodeRuleDataFormat>(codeRuleDataFormatId); //Get CodeRuleDefinition CodeRuleDefinition codeRuleDefinition = session.GetObjectByKey <CodeRuleDefinition>(codeRuleDefinitionId); codeRuleStringData = (CodeRuleStringData)codeRuleDataBO.GetCodeRuleData(session, codeRuleDefinition.CodeRuleDefinitionId, codeRuleDataFormat.CodeRuleDataTypeId.CodeRuleDataTypeId); foreach (var item in codeRuleDefinition.CodeRuleData) { item.RowStatus = Utility.Constant.ROWSTATUS_INACTIVE; item.Save(); } if (codeRuleStringData == null) { codeRuleStringData = Insert(session, codeRuleDefinition.CodeRuleDefinitionId, codeRuleDataFormatId, stringValue); } else { codeRuleStringData.StringValue = stringValue; codeRuleStringData.CodeRuleDataFormatId = codeRuleDataFormat; codeRuleStringData.RowStatus = Utility.Constant.ROWSTATUS_ACTIVE; codeRuleStringData.Save(); } return(codeRuleStringData); } catch (Exception ex) { throw; } }
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(); } } }
public string GetCodeDefinition(Session session, CodeRuleDefinition codeRuleDefinition, bool isUpdateLastestWhenIsNumber) { string codeDefinition = String.Empty; ArtifactCodeFormater.CodeRuleData data = null; ArtifactCodeFormater.CodeRuleDataFormater formater = null; int beginNum = 0; int step = 0; int endNum = 0; int lastestNum = 0; int currentNum = 0; //2.1. Get data type //2.2. Get format type CodeRuleData codeRuleData = codeRuleDefinition.CodeRuleData.FirstOrDefault(r => r.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE); //Get format code string dataFormat = codeRuleData.CodeRuleDataFormatId.Code; //2.3. Determine the data type //2.3.1. When is STRING #region STRING if (codeRuleDefinition.CodeRuleDataTypeId.Code.Equals("STRING")) { CodeRuleStringData _codeRuleStringData = (CodeRuleStringData)codeRuleData; data = new ArtifactCodeFormater.CodeRuleData(); switch (dataFormat) { case "NORMAL": formater = new ArtifactCodeFormater.CodeRuleDataFormaterString(); break; case "LOWERCASE": formater = new ArtifactCodeFormater.CodeRuleDataFormaterStringLowerCase(); break; case "UPPERCASE": formater = new ArtifactCodeFormater.CodeRuleDataFormaterStringUpperCase(); break; case "ACSII": formater = new ArtifactCodeFormater.CodeRuleDataFormaterStringACSI(); break; case "UPPERCASE_ACSII": formater = new ArtifactCodeFormater.CodeRuleDataFormaterStringACSI( new ArtifactCodeFormater.CodeRuleDataFormaterStringUpperCase() ); break; case "LOWERCASE_ACSII": formater = new ArtifactCodeFormater.CodeRuleDataFormaterStringACSI( new ArtifactCodeFormater.CodeRuleDataFormaterStringLowerCase() ); break; default: break; } data.Value = _codeRuleStringData.StringValue; data.FormatString = _codeRuleStringData.CodeRuleDataFormatId.FormatString; } #endregion //2.3.2. When is NUMBER #region NUMBER else if (codeRuleDefinition.CodeRuleDataTypeId.Code.Equals("NUMBER")) { CodeRuleNumberData _codeRuleNumberData = (CodeRuleNumberData)codeRuleData; //2.3.2.1. Get begin number beginNum = _codeRuleNumberData.BeginNumberValue; //2.3.2.2. Get step step = _codeRuleNumberData.Step; //2.3.2.3. Get end number endNum = _codeRuleNumberData.EndNumberValue; //2.3.2.4. Get lastest number lastestNum = _codeRuleNumberData.LastNumber; //check can get more code if (isUpdateLastestWhenIsNumber) { if (step > 0) { if ((step + lastestNum) > endNum) { throw new Exception("Definition is invalid"); } } else if (step < 0) { if ((step + lastestNum) < endNum) { throw new Exception("Definition is invalid"); } } currentNum = lastestNum + step; } else { currentNum = beginNum; } formater = new ArtifactCodeFormater.CodeRuleDataFormaterNumber(); data = new ArtifactCodeFormater.CodeRuleData(); data.Value = currentNum; data.FormatString = _codeRuleNumberData.CodeRuleDataFormatId.FormatString; if (isUpdateLastestWhenIsNumber) { _codeRuleNumberData.LastNumber = currentNum; _codeRuleNumberData.Save(); } } #endregion //2.3.3. When is DATETIME #region DATETIME //Get system datetime else if (codeRuleDefinition.CodeRuleDataTypeId.Code.Equals("DATETIME")) { formater = new ArtifactCodeFormater.CodeRuleDataFormaterDateTime(); data = new ArtifactCodeFormater.CodeRuleData(); data.Value = DateTime.Now; data.FormatString = codeRuleData.CodeRuleDataFormatId.FormatString; } #endregion data.UseFormater(formater); codeDefinition = data.GetFormatedValue(); int countChild = codeRuleDefinition.CodeRuleDefinitions.Where(r => r.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE).Count(); if (countChild == 0) { return(codeDefinition); } else { CodeRuleDefinition childCodeRuleDefinition = codeRuleDefinition.CodeRuleDefinitions .Where(r => r.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE) .First(); return(codeDefinition += GetCodeDefinition(session, childCodeRuleDefinition, isUpdateLastestWhenIsNumber)); } }