/// <summary> /// Generate billing client code /// </summary> /// <returns></returns> public string GenerateBillingClientCode() { string strBillingClientCode = string.Empty; try { //1. Get next running no ICommonHandler handler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; List <doRunningNo> run = handler.GetNextRunningCode(NameCode.C_NAME_CODE_BILLING_CLIENT_CODE); if (run.Count > 0) { string strRunningNo = run[0].RunningNo; //2. Generate check digit string strCheckDigit = handler.GenerateCheckDigit(strRunningNo); //3. Set strBillingClientCode =strRunningNo+ strCheckDigit strBillingClientCode = strRunningNo + strCheckDigit; } } catch (Exception) { throw; } return(strBillingClientCode); }
///<summary> ///Purpose: /// Consistency check /// ///Parameters: /// strRunningNo: Input strRunningNo of length 9. Use same input for both times. /// ///Expected: /// iCheckDigit as 1 digit number. The output must be the same for both times. ///</summary> public string Case4() { ICommonHandler target = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; string strRunningNo = "984756341"; string expected; string actual; try { actual = target.GenerateCheckDigit(strRunningNo); expected = target.GenerateCheckDigit(strRunningNo); } catch (ApplicationErrorException ex) { actual = ex.ErrorResult.Message.Code; expected = "-2"; } catch (Exception ex) { actual = ex.StackTrace; expected = "-2"; } return(string.Format(RESULT_FORMAT, 5, expected, actual, CompareResult_String(expected, actual))); }
/// <summary> /// To generate project code /// </summary> /// <returns></returns> public string GenerateProjectCode() { try { ICommonHandler hand = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; //1. Call method for get next running code List <doRunningNo> doRunningNo = null; try { doRunningNo = hand.GetNextRunningCode(NameCode.C_NAME_CODE_PROJECT_CODE, true); } catch { } bool isFound = false; if (doRunningNo != null) { if (doRunningNo.Count > 0) { if (CommonUtil.IsNullOrEmpty(doRunningNo[0].RunningNo) == false) { isFound = true; } } } if (isFound == false) { throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3131); } //2. Call method for get the check digit string strCheckDigit = hand.GenerateCheckDigit(doRunningNo[0].RunningNo); //3. Create project code string strProjectCode = ProjectCode.C_PROJECT_CODE_PREFIX + doRunningNo[0].RunningNo + strCheckDigit; //4. Return strProjectCode return(strProjectCode); } catch (Exception) { throw; } }
///<summary> ///Purpose: /// Output check /// ///Parameters: /// strRunningNo: Try to input strRunningNo as several random numbers of length 6 and 9. /// ///Expected: /// iCheckDigit as 1 digit number. ///</summary> public string Case2_2() { ICommonHandler target = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; string strRunningNo = "384790263"; int expected = 1; int actual; try { actual = target.GenerateCheckDigit(strRunningNo).Length; } catch (ApplicationErrorException ex) { actual = -1; } catch (Exception ex) { actual = -1; } return(string.Format(RESULT_FORMAT, 3, expected, actual, CompareResult_int(expected, actual))); }
/// <summary> /// Generate customer code /// </summary> /// <returns></returns> public string GenerateCustomerCode() { try { ICommonHandler handler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; List <doRunningNo> run = handler.GetNextRunningCode(NameCode.C_NAME_CODE_CUSTOMER_CODE); if (run.Count > 0) { string digit = handler.GenerateCheckDigit(run[0].RunningNo); return(CommonValue.C_CUST_CODE_PREFIX + run[0].RunningNo + digit); } return(null); } catch (Exception) { throw; } }
/// <summary> /// Generate unique GroupCode.<br /> /// - Get next running code.<br /> /// - Generate check digit.<br /> /// - Combind GroupCode Prefix + runningNo + check digit /// </summary> /// <returns></returns> public string GenerateGroupCode() { string strGroupCode = string.Empty; //1. Get next running no ICommonHandler commHand = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; List <doRunningNo> runningList = commHand.GetNextRunningCode(NameCode.C_NAME_CODE_GROUP_CODE); //2. Generate check digit string strRunningNo = runningList[0].RunningNo; if (runningList.Count > 0) { string strCheckDigit = commHand.GenerateCheckDigit(strRunningNo); strGroupCode = GroupCode.C_GROUP_CODE_PREFIX + strRunningNo + strCheckDigit; } return(strGroupCode); }
/// <summary> /// To generate contract code /// </summary> /// <param name="strProductTypeCode"></param> /// <returns></returns> public string GenerateContractCode(string strProductTypeCode) { try { //1. Get product type data ICommonHandler hand = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; List <tbs_ProductType> productTypeList = hand.GetTbs_ProductType(null, strProductTypeCode); //1.2. Check existing of returned data if (productTypeList.Count <= 0 || productTypeList[0].ContractPrefix == null || productTypeList[0].ContractPrefix == string.Empty) { throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3022); } //2. Call method for get next running code List <doRunningNo> runningNoList = hand.GetNextRunningCode(NameCode.C_NAME_CODE_CONTRACT_CODE); if (runningNoList.Count <= 0 || runningNoList[0].RunningNo == null || runningNoList[0].RunningNo == string.Empty) { throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3130); } //3. Call method for get the check digit //3.1. Call CommonHandler.GenerateCheckDigit string iCheckDigit = hand.GenerateCheckDigit(runningNoList[0].RunningNo); //4. Create contract code //4.1. Set strContractCode = dtTbs_ProductType[0].ContractPrefix + strRunningCode + iCheckDigit string strContractCode = productTypeList[0].ContractPrefix + runningNoList[0].RunningNo + iCheckDigit; //5. Return strContractCode return(strContractCode); } catch (Exception) { throw; } }