public static string getBizDocumentTypeCode( EnumBizDocumentType bizDocumentType) { return(BizDocumentTypeList.Where( item => item.Item1 == bizDocumentType). FirstOrDefault().Item2); }
public string generateDocumentSerialNo( EnumBizDocumentType bizDocumentType, string organizationCode, string locationCode, string yearCode, string departmentCode ) { using (var db = new OPAS2DbContext()) { var currentRecord = db.bizDocumentSerialNoGenerators.Where( record => record.bizDocumentType == bizDocumentType && record.organizationCode == organizationCode && record.locationCode == locationCode && record.yearCode == yearCode && record.departmentCode == departmentCode).FirstOrDefault(); if (currentRecord == null) // No existing generator, need init { currentRecord = db.bizDocumentSerialNoGenerators.Create(); currentRecord.name = BizSettings.getBizDocumentTypeCode(bizDocumentType) + organizationCode + locationCode + yearCode + departmentCode; currentRecord.bizDocumentType = bizDocumentType; currentRecord.organizationCode = organizationCode; currentRecord.locationCode = locationCode; currentRecord.yearCode = yearCode; currentRecord.departmentCode = departmentCode; db.bizDocumentSerialNoGenerators.Add(currentRecord); db.SaveChanges(); currentRecord.currentNo = currentRecord.startNo; } else // generator exists { currentRecord.currentNo = currentRecord.currentNo + 1; } db.SaveChanges(); return(currentRecord.name + currentRecord.currentNo.ToString( "D" + currentRecord.numberPartLength)); } }