/// <summary> /// Set gl account /// </summary> /// <param name="glAccount"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="MasterDataIdentityNotDefined"></exception> public bool SetGLAccount(MasterDataIdentity_GLAccount glAccount) { if (_isSaved) { return(false); } // check G/L account if (glAccount == null) { throw new ArgumentNullException("G/L account"); } MasterDataBase accountId = _management.GetMasterData(glAccount, MasterDataType.GL_ACCOUNT); if (accountId == null) { throw new MasterDataIdentityNotDefined(glAccount, MasterDataType.GL_ACCOUNT); } _type = AccountType.GL_ACCOUNT; _glAccount = glAccount; _vendor = null; _customer = null; return(true); }
public static async Task <HeadEntity> CreateVendorDoc(CoreDriver coreDriver, DateTime date) { HeadEntity headEntity = new HeadEntity(coreDriver, coreDriver.MdMgmt); headEntity.setPostingDate(date); headEntity.SetDocumentType(DocumentType.VENDOR_INVOICE); headEntity.SetDocText(TestData.TEXT_VENDOR_DOC); ItemEntity item1 = headEntity.CreateEntity(); MasterDataIdentity_GLAccount rec_account = new MasterDataIdentity_GLAccount( TestData.GL_ACCOUNT_CASH); item1.SetVendor(new MasterDataIdentity(TestData.VENDOR_BUS), rec_account); item1.SetAmount(CreditDebitIndicator.CREDIT, TestData.AMOUNT_VENDOR); ItemEntity item2 = headEntity.CreateEntity(); item2.SetGLAccount(new MasterDataIdentity_GLAccount( TestData.GL_ACCOUNT_COST)); item2.SetAmount(CreditDebitIndicator.DEBIT, TestData.AMOUNT_VENDOR); item2.SetBusinessArea(new MasterDataIdentity( TestData.BUSINESS_AREA_WORK)); try { await headEntity.SaveAsync(true); } catch (Exception e) { Assert.Fail(e.ToString()); } return(headEntity); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="glAccountId"></param> /// <param name="orgAmount"></param> /// <param name="newAmount"></param> public void GLAccountInitAmountChanged(Object source, MasterDataIdentity_GLAccount glAccountId, CurrencyAmount orgAmount, CurrencyAmount newAmount) { foreach (GLAccountInitAmountChanged d in GLAccountInitAmountChangedHandler.GetInvocationList()) { d(glAccountId, orgAmount, newAmount); } }
/// <summary> /// get balance item /// </summary> /// <param name="glAccount"></param> /// <returns></returns> public GLAccountBalanceItem GetBalanceItem( MasterDataIdentity_GLAccount glAccount) { GLAccountBalanceItem item; if (!_items.TryGetValue(glAccount, out item)) { return(null); } return(item); }
/// <summary> /// Set vendor /// </summary> /// <param name="vendor"></param> /// <param name="glAccount"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="MasterDataIdentityNotDefined"></exception> public bool SetVendor(MasterDataIdentity vendor, MasterDataIdentity_GLAccount glAccount) { if (_isSaved) { return(false); } // check customer if (vendor == null) { throw new ArgumentNullException("Vendor"); } MasterDataBase vendorId = _management.GetMasterData(vendor, MasterDataType.VENDOR); if (vendorId == null) { throw new MasterDataIdentityNotDefined(vendor, MasterDataType.VENDOR); } // check G/L account if (glAccount == null) { throw new ArgumentNullException("G/L account"); } MasterDataBase data = _management.GetMasterData(glAccount, MasterDataType.GL_ACCOUNT); if (data == null) { throw new MasterDataIdentityNotDefined(glAccount, MasterDataType.GL_ACCOUNT); } MasterDataIdentity accountId = data.Identity; if (accountId == null) { throw new MasterDataIdentityNotDefined(glAccount, MasterDataType.GL_ACCOUNT); } _type = AccountType.VENDOR; _glAccount = glAccount; _vendor = vendor; _customer = null; return(true); }
public VendorEntry(CoreDriver coreDriver, MasterDataManagement mdMgmt) { _coreDriver = coreDriver; _mdMgmt = mdMgmt; _text = ""; _recAcc = null; _glAccount = null; _vendor = null; _amount = new CurrencyAmount(); _businessArea = null; _doc = null; }
private void glAccountInitAmountChanged(MasterDataIdentity_GLAccount glAccountId , CurrencyAmount orgAmount, CurrencyAmount newAmount) { GLAccountBalanceItem item; if (!_items.TryGetValue(glAccountId, out item)) { return; } // ret += newAmount - orgAmount item.AddAmount(_coreDriver.StartMonthId , CurrencyAmount.Minus(newAmount, orgAmount)); }
/// <summary> /// Only internal can invoke /// </summary> /// <param name="coreDriver"></param> /// <param name="management"></param> /// <param name="head"></param> /// <param name="lineNum"></param> internal ItemEntity(CoreDriver coreDriver, MasterDataManagement management, HeadEntity head, int lineNum) { _coreDriver = coreDriver; _management = management; _head = head; _lineNum = lineNum; _glAccount = null; _customer = null; _vendor = null; _amount = new CurrencyAmount(); _businessArea = null; }
/// <summary> /// set dst account /// </summary> /// <param name="fieldName"></param> /// <param name="value"></param> /// <exception cref="NoFieldNameException">No such field name</exception> /// <exception cref="NotInValueRangeException">The value is not supported</exception> private void setDstAccount(MasterDataIdentity_GLAccount dstAccount) { if (dstAccount == null) { throw new NotInValueRangeException(DST_ACCOUNT, ""); } List <MasterDataBase> valueSet = this.GetValueSet(DST_ACCOUNT); foreach (Object obj in valueSet) { GLAccountMasterData glAccount = (GLAccountMasterData)obj; if (glAccount.GLIdentity.Equals(dstAccount)) { _dstAccount = dstAccount; return; } } throw new NotInValueRangeException(SRC_ACCOUNT, dstAccount); }
/// <summary> /// set recconciliation account /// </summary> /// <param name="recAcc"></param> /// <exception cref="NotInValueRangeException"></exception> /// <exception cref="NoFieldNameException"></exception> private void setRecAccount(MasterDataIdentity_GLAccount recAcc) { if (recAcc == null) { throw new NotInValueRangeException(REC_ACC, ""); } List <MasterDataBase> valueSet = this.GetValueSet(REC_ACC); foreach (Object obj in valueSet) { GLAccountMasterData glAccount = (GLAccountMasterData)obj; if (glAccount.GLIdentity.Equals(recAcc)) { _recAcc = recAcc; return; } } throw new NotInValueRangeException(REC_ACC, recAcc); }
/// <summary> /// set G/L account /// </summary> /// <param name="glAccount"></param> /// <exception cref="NotInValueRangeException"></exception> /// <exception cref="NoFieldNameException"></exception> private void setGLAccount(MasterDataIdentity_GLAccount glAccount) { if (glAccount == null) { throw new NotInValueRangeException(GL_ACCOUNT, ""); } List <MasterDataBase> valueSet = this.GetValueSet(GL_ACCOUNT); foreach (Object obj in valueSet) { GLAccountMasterData glAcc = (GLAccountMasterData)obj; if (glAcc.GLIdentity.Equals(glAccount)) { _glAccount = glAccount; return; } } throw new NotInValueRangeException(GL_ACCOUNT, glAccount); }
public static void CheckAccountBalance(CoreDriver coreDriver) { TransactionDataManagement transMgmt = coreDriver.TransMgmt; GLAccountBalanceCollection balCol = transMgmt.AccountBalanceCol; MonthIdentity month07 = new MonthIdentity(2012, 7); MonthIdentity month08 = new MonthIdentity(2012, 8); MasterDataIdentity_GLAccount glAccount2 = new MasterDataIdentity_GLAccount( TestData.GL_ACCOUNT_CASH); GLAccountBalanceItem balItem = balCol.GetBalanceItem(glAccount2); CurrencyAmount amount2 = new CurrencyAmount(123.45 - 23.45); Assert.AreEqual(amount2, balItem.Sum); Assert.AreEqual(amount2, balItem.GetAmount(month07)); Assert.AreEqual(new CurrencyAmount(), balItem.GetAmount(month08)); Assert.AreEqual(amount2, balCol.GetGroupBalance(GLAccountGroupENUM.CASH)); Assert.AreEqual(amount2, balCol.GetGroupBalance(GLAccountGroupENUM.CASH, month07, month07)); Assert.AreEqual(new CurrencyAmount(), balCol.GetGroupBalance(GLAccountGroupENUM.CASH, month08, month08)); // cost Assert.AreEqual(new CurrencyAmount(123.45), balCol.GetGroupBalance(GLAccountGroupENUM.COST_PURE)); Assert.AreEqual(new CurrencyAmount(123.45), balCol.GetGroupBalance( GLAccountGroupENUM.COST_PURE, month07, month07)); Assert.AreEqual(new CurrencyAmount(), balCol.GetGroupBalance( GLAccountGroupENUM.COST_PURE, month08, month08)); // revenue Assert.AreEqual(new CurrencyAmount(-543.21), balCol.GetGroupBalance(GLAccountGroupENUM.SALARY)); Assert.AreEqual(new CurrencyAmount(-543.21), balCol.GetGroupBalance(GLAccountGroupENUM.SALARY, month07, month07)); Assert.AreEqual(new CurrencyAmount(), balCol.GetGroupBalance(GLAccountGroupENUM.SALARY, month08, month08)); }
public static async Task <HeadEntity> CreateCustomerDoc(CoreDriver coreDriver, DateTime date) { HeadEntity headEntity = new HeadEntity(coreDriver, coreDriver.MdMgmt); headEntity.setPostingDate(date); headEntity.SetDocumentType(DocumentType.CUSTOMER_INVOICE); headEntity.SetDocText(TestData.TEXT_CUSTOMER_DOC); ItemEntity item1 = headEntity.CreateEntity(); item1.SetGLAccount(new MasterDataIdentity_GLAccount( TestData.GL_ACCOUNT_REV)); item1.SetAmount(CreditDebitIndicator.CREDIT, TestData.AMOUNT_CUSTOMER); ItemEntity item2 = headEntity.CreateEntity(); MasterDataIdentity_GLAccount account2 = new MasterDataIdentity_GLAccount( TestData.GL_ACCOUNT_BANK); item2.SetCustomer(new MasterDataIdentity(TestData.CUSTOMER1), account2); item2.SetAmount(CreditDebitIndicator.DEBIT, TestData.AMOUNT_CUSTOMER); try { await headEntity.SaveAsync(true); } catch (Exception e) { Assert.Fail(e.ToString()); } return(headEntity); }
internal GLAccountBalanceItem(MasterDataIdentity_GLAccount glAccount) { _glAccount = glAccount; _list = new Dictionary <MonthIdentity, CurrencyAmount>(); _sum = new CurrencyAmount(); }
/// <summary> /// parse XML to template /// </summary> /// <param name="coreDriver"></param> /// <param name="elem"></param> /// <returns></returns> /// <exception cref="TemplateFormatException"></exception> public static EntryTemplate Parse(CoreDriver coreDriver, MasterDataManagement mdMgmt , XElement elem) { XAttribute idStr = elem.Attribute(XML_ID); XAttribute name = elem.Attribute(XML_NAME); XAttribute typeStr = elem.Attribute(XML_TYPE); if (name == null) { coreDriver.logDebugInfo(typeof(EntryTemplate), 228, "No value in template name", MessageType.ERRO); throw new TemplateFormatException(); } int id; if (int.TryParse(idStr.Value, out id) == false) { throw new TemplateFormatException(); } EntryType type; if (typeStr.Value.Equals(XML_VENDOR)) { type = EntryType.VendorEntry; } else if (typeStr.Value.Equals(XML_CUSTOMER)) { type = EntryType.CustomerEntry; } else if (typeStr.Value.Equals(XML_GL)) { type = EntryType.GLEntry; } else { coreDriver.logDebugInfo(typeof(EntryTemplate), 252, "template type is not correct: " + typeStr.Value, MessageType.ERRO); throw new TemplateFormatException(); } EntryTemplate template = new EntryTemplate(coreDriver, mdMgmt , type, id, name.Value); foreach (XElement fieldElem in elem.Elements(XML_FIELD)) { XAttribute fieldName = fieldElem.Attribute(XML_NAME); XAttribute fieldValue = fieldElem.Attribute(XML_VALUE); if (fieldName.Value.Equals(EntryTemplate.AMOUNT)) { try { CurrencyAmount amount = CurrencyAmount .Parse(fieldValue.Value); template.AddDefaultValue(fieldName.Value, amount); } catch (CurrencyAmountFormatException e) { coreDriver.logDebugInfo(typeof(EntryTemplate), 287, e.Message, MessageType.ERRO); throw new TemplateFormatException(); } catch (NotInValueRangeException e) { coreDriver.logDebugInfo(typeof(EntryTemplate), 287, e.Message, MessageType.ERRO); throw new TemplateFormatException(); } catch (NoFieldNameException e) { coreDriver.logDebugInfo(typeof(EntryTemplate), 287, e.Message, MessageType.ERRO); throw new TemplateFormatException(); } } else if (fieldName.Value.Equals(EntryTemplate.TEXT)) { try { template.AddDefaultValue(fieldName.Value, fieldValue.Value); } catch (NotInValueRangeException e) { coreDriver.logDebugInfo(typeof(EntryTemplate), 287, e.Message, MessageType.ERRO); throw new TemplateFormatException(); } catch (NoFieldNameException e) { coreDriver.logDebugInfo(typeof(EntryTemplate), 287, e.Message, MessageType.ERRO); throw new TemplateFormatException(); } } else { try { switch (type) { case EntryType.VendorEntry: if (fieldName.Value.Equals(VendorEntry.REC_ACC) || fieldName .Value.Equals(VendorEntry.GL_ACCOUNT)) { MasterDataIdentity_GLAccount accountId = new MasterDataIdentity_GLAccount( fieldValue.Value); template.AddDefaultValue(fieldName.Value, accountId); } else { MasterDataIdentity dataId = new MasterDataIdentity( fieldValue.Value); template.AddDefaultValue(fieldName.Value, dataId); } break; case EntryType.CustomerEntry: if (fieldName.Value.Equals(CustomerEntry.REC_ACC) || fieldName.Value .Equals(CustomerEntry.GL_ACCOUNT)) { MasterDataIdentity_GLAccount accountId = new MasterDataIdentity_GLAccount( fieldValue.Value); template.AddDefaultValue(fieldName.Value, accountId); } else { MasterDataIdentity dataId = new MasterDataIdentity( fieldValue.Value); template.AddDefaultValue(fieldName.Value, dataId); } break; case EntryType.GLEntry: MasterDataIdentity_GLAccount accId = new MasterDataIdentity_GLAccount( fieldValue.Value); template.AddDefaultValue(fieldName.Value, accId); break; } } catch (Exception e) { coreDriver.logDebugInfo(typeof(EntryTemplate), 309, e.Message, MessageType.ERRO); throw new TemplateFormatException(); } } } return(template); }
/// <summary> /// parse XML to item entity /// </summary> /// <param name="coreDriver"></param> /// <param name="management"></param> /// <param name="head"></param> /// <param name="elem"></param> /// <returns></returns> /// <exception cref="TransactionDataFileFormatException"></exception> /// <exception cref="SystemException"></exception> public static ItemEntity Parse(CoreDriver coreDriver, MasterDataManagement management, HeadEntity head, XElement elem) { #region get line number XAttribute lineNumStr = elem.Attribute(TransDataUtils.XML_LINE_NUM); if (lineNumStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 363, String.Format( "Field {0} is missing in.", TransDataUtils.XML_LINE_NUM), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } int lineNum; if (!Int32.TryParse(lineNumStr.Value, out lineNum)) { coreDriver.logDebugInfo(typeof(HeadEntity), 363, String.Format( "Format of field {0} is error.", TransDataUtils.XML_LINE_NUM), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } #endregion #region get account type XAttribute typeStr = elem.Attribute(TransDataUtils.XML_ACCOUNT_TYPE); if (typeStr == null) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, String.Format( "Field {0} is missing in.", TransDataUtils.XML_ACCOUNT_TYPE), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } if (typeStr.Value.Length != 1 || (typeStr.Value[0] != (char)AccountType.CUSTOMER && typeStr.Value[0] != (char)AccountType.GL_ACCOUNT && typeStr.Value[0] != (char)AccountType.VENDOR)) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, String.Format( "Format of field {0} is error.", TransDataUtils.XML_ACCOUNT_TYPE), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } AccountType type = (AccountType)typeStr.Value[0]; #endregion #region amount XAttribute amountStr = elem.Attribute(TransDataUtils.XML_AMOUNT); if (amountStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 375, String.Format( "Field {0} is missing in.", TransDataUtils.XML_AMOUNT), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } CurrencyAmount amount; try { amount = CurrencyAmount.Parse(amountStr.Value); } catch (Exception e) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } #endregion #region credit debit indicator XAttribute cdIndStr = elem.Attribute(TransDataUtils.XML_CD_INDICATOR); if (cdIndStr == null) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, String.Format( "Field {0} is missing in.", TransDataUtils.XML_CD_INDICATOR), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } if (cdIndStr.Value.Length != 1 || (cdIndStr.Value[0] != (char)CreditDebitIndicator.CREDIT && cdIndStr.Value[0] != (char)CreditDebitIndicator.DEBIT)) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, String.Format( "Format of field {0} is error.", TransDataUtils.XML_CD_INDICATOR), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } CreditDebitIndicator indicator = (CreditDebitIndicator)cdIndStr.Value[0]; #endregion #region G/L account XAttribute glAccountStr = elem.Attribute(TransDataUtils.XML_GL_ACCOUNT); if (glAccountStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 414, String.Format( "Field {0} is missing in.", TransDataUtils.XML_GL_ACCOUNT), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } MasterDataIdentity_GLAccount glAccount; try { glAccount = new MasterDataIdentity_GLAccount( glAccountStr.Value); } catch (Exception e) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } #endregion // vendor XAttribute vendorStr = elem.Attribute(TransDataUtils.XML_VENDOR); // customer XAttribute customerStr = elem.Attribute(TransDataUtils.XML_CUSTOMER); XAttribute businessAreaStr = elem .Attribute(TransDataUtils.XML_BUSINESS_AREA); try { ItemEntity newItem = new ItemEntity(coreDriver, management, head, lineNum); #region set account, vendor and customer if (type == AccountType.GL_ACCOUNT) { newItem.SetGLAccount(glAccount); } else if (type == AccountType.VENDOR) { if (vendorStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 414, String .Format("Field %s is missing in.", TransDataUtils.XML_VENDOR), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } MasterDataIdentity vendorId = new MasterDataIdentity( vendorStr.Value); newItem.SetVendor(vendorId, glAccount); } else if (type == AccountType.CUSTOMER) { if (customerStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 414, String .Format("Field %s is missing in.", TransDataUtils.XML_CUSTOMER), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } MasterDataIdentity customerId = new MasterDataIdentity( customerStr.Value); newItem.SetCustomer(customerId, glAccount); } #endregion newItem.SetAmount(indicator, amount); if (businessAreaStr != null) { newItem.SetBusinessArea(new MasterDataIdentity(businessAreaStr.Value)); } coreDriver.logDebugInfo( typeof(ItemEntity), 455, String.Format("Parsed line Item {0}.", newItem.LineNum), MessageType.INFO); return(newItem); } catch (IdentityTooLong e) { coreDriver.logDebugInfo(typeof(ItemEntity), 463, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } catch (IdentityNoData e) { coreDriver.logDebugInfo(typeof(ItemEntity), 463, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } catch (IdentityInvalidChar e) { coreDriver.logDebugInfo(typeof(ItemEntity), 463, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } catch (ArgumentNullException e) { coreDriver.logDebugInfo(typeof(ItemEntity), 463, e.Message, MessageType.ERRO); throw new SystemException(e); } catch (MasterDataIdentityNotDefined e) { coreDriver.logDebugInfo(typeof(ItemEntity), 463, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } catch (CurrencyAmountFormatException e) { throw new TransactionDataFileFormatException(e.Message); } }
public CostReportItem(MasterDataIdentity_GLAccount id , String name, CurrencyAmount amount, CostReportsAdapter parent) : base(id, name, parent) { _amount = amount; }
/// <summary> /// Set value /// </summary> /// <param name="fieldName"></param> /// <param name="value"></param> /// <exception cref="NoFieldNameException"></exception> /// <exception cref="NotInValueRangeException"></exception> public void SetValue(String fieldName, Object value) { if (_isSaved) { return; } if (value == null) { throw new NotInValueRangeException(fieldName, ""); } if (fieldName.Equals(CUSTOMER)) { MasterDataIdentity customer = value as MasterDataIdentity; if (customer == null) { throw new NotInValueRangeException(fieldName, value); } setCustomer(customer); } else if (fieldName.Equals(GL_ACCOUNT)) { MasterDataIdentity_GLAccount glAccount = value as MasterDataIdentity_GLAccount; if (glAccount == null) { throw new NotInValueRangeException(fieldName, value); } setGLAccount(glAccount); } else if (fieldName.Equals(REC_ACC)) { MasterDataIdentity_GLAccount recAcc = value as MasterDataIdentity_GLAccount; if (recAcc == null) { throw new NotInValueRangeException(fieldName, value); } setRecAccount(recAcc); } else if (fieldName.Equals(EntryTemplate.POSTING_DATE)) { if (!(value is DateTime)) { throw new NotInValueRangeException(fieldName, value); } DateTime date = (DateTime)value; _date = date; } else if (fieldName.Equals(EntryTemplate.AMOUNT)) { try { CurrencyAmount amount = CurrencyAmount.Parse(value.ToString()); if (amount.IsZero() || amount.IsNegative()) { throw new NotInValueRangeException(fieldName, value); } _amount = amount; } catch (CurrencyAmountFormatException) { throw new NotInValueRangeException(fieldName, value); } } else if (fieldName.Equals(EntryTemplate.TEXT)) { _text = value.ToString(); } else { throw new NoFieldNameException(fieldName); } }
/// <summary> /// set value /// </summary> /// <param name="fieldName"></param> /// <param name="value"></param> /// <exception cref="NoFieldNameException">No such field name</exception> /// <exception cref="NotInValueRangeException">The value is not supported</exception> public void SetValue(String fieldName, Object value) { if (_isSaved) { return; } if (value == null) { throw new NotInValueRangeException(fieldName, ""); } if (fieldName.Equals(VENDOR)) { if (!(value is MasterDataIdentity)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity vendor = (MasterDataIdentity)value; setVendor(vendor); } else if (fieldName.Equals(GL_ACCOUNT)) { if (!(value is MasterDataIdentity_GLAccount)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity_GLAccount glAccount = (MasterDataIdentity_GLAccount)value; setGLAccount(glAccount); } else if (fieldName.Equals(REC_ACC)) { if (!(value is MasterDataIdentity_GLAccount)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity_GLAccount recAcc = (MasterDataIdentity_GLAccount)value; setRecAccount(recAcc); } else if (fieldName.Equals(EntryTemplate.POSTING_DATE)) { if (!(value is DateTime)) { throw new NotInValueRangeException(fieldName, value); } DateTime date = (DateTime)value; _date = date; } else if (fieldName.Equals(EntryTemplate.AMOUNT)) { try { CurrencyAmount amount = CurrencyAmount.Parse(value.ToString()); if (amount.IsZero() || amount.IsNegative()) { throw new NotInValueRangeException(fieldName, value); } _amount = amount; } catch (CurrencyAmountFormatException) { throw new NotInValueRangeException(fieldName, value); } } else if (fieldName.Equals(EntryTemplate.TEXT)) { _text = value.ToString(); } else if (fieldName.Equals(BUSINESS_AREA)) { if (!(value is MasterDataIdentity)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity businessArea = (MasterDataIdentity)value; setBusinessArea(businessArea); } else { throw new NoFieldNameException(fieldName); } }
public void TestMasterDataIdentity() { MasterDataIdentity test; // test length StringBuilder builder = new StringBuilder(); for (int i = 1; i <= 10; ++i) { builder.Append('A'); try { test = new MasterDataIdentity(builder.ToString()); test.ToString(); } catch (Exception e) { Assert.Fail(e.Message); } } // test low case test = new MasterDataIdentity("abcdefg"); Assert.AreEqual(test.ToString(), "000ABCDEFG"); // test number test = new MasterDataIdentity("123456789"); Assert.AreEqual(test.ToString(), "0123456789"); // test '_' test = new MasterDataIdentity("_123456789"); Assert.AreEqual(test.ToString(), "_123456789"); // test equals MasterDataIdentity test1 = new MasterDataIdentity("123"); MasterDataIdentity test2 = new MasterDataIdentity("123"); Assert.AreEqual(test1, test2); Assert.AreEqual(test1.GetHashCode(), test2.GetHashCode()); // zero length try { test = new MasterDataIdentity(""); test.ToString(); Assert.Fail("IdentityNoData should occur when length is zero"); } catch (IdentityNoData) { // pass } catch (Exception) { Assert.Fail("IdentityNoData should occur when length is zero, but it is other exception"); } // no data try { test = new MasterDataIdentity("00"); test.ToString(); Assert.Fail("IdentityNoData should occur when there is no data"); } catch (IdentityNoData) { // pass } catch (Exception) { Assert.Fail("IdentityNoData should occur when length is zero, but it is other exception"); } // format error try { test = new MasterDataIdentity("a?"); test.ToString(); Assert.Fail("IdentityNoData should occur when there is no data"); } catch (IdentityInvalidChar) { // pass } catch (Exception) { Assert.Fail("IdentityInvalidChar should occur when length is zero, but it is other exception"); } // too long try { test = new MasterDataIdentity("12345678901"); test.ToString(); Assert.Fail("IdentityNoData should occur when there is no data"); } catch (IdentityTooLong) { // pass } catch (Exception) { Assert.Fail("IdentityInvalidChar should occur when length is zero, but it is other exception"); } // identity for gl account MasterDataIdentity_GLAccount glAccountTest = new MasterDataIdentity_GLAccount( "113100"); Assert.AreEqual(glAccountTest.ToString(), "0000113100"); // identity for gl account // format error try { glAccountTest = new MasterDataIdentity_GLAccount("abcd"); test.ToString(); Assert.Fail("IdentityNoData should occur when there is no data"); } catch (IdentityInvalidChar) { // pass } catch (Exception) { Assert.Fail("IdentityInvalidChar should occur when length is zero, but it is other exception"); } }
/// <summary> /// set value /// </summary> /// <param name="fieldName"></param> /// <param name="value"></param> /// <exception cref="NoFieldNameException">No such field name</exception> /// <exception cref="NotInValueRangeException">The value is not supported</exception> public void SetValue(String fieldName, Object value) { if (_isSaved) { return; } if (value == null) { throw new NotInValueRangeException(fieldName, ""); } if (fieldName.Equals(DST_ACCOUNT)) { if (!(value is MasterDataIdentity_GLAccount)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity_GLAccount id = (MasterDataIdentity_GLAccount)value; setDstAccount(id); } else if (fieldName.Equals(SRC_ACCOUNT)) { if (!(value is MasterDataIdentity_GLAccount)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity_GLAccount id = (MasterDataIdentity_GLAccount)value; setSourceAccount(id); } else if (fieldName.Equals(EntryTemplate.TEXT)) { _text = value.ToString(); } else if (fieldName.Equals(EntryTemplate.AMOUNT)) { try { CurrencyAmount amount = CurrencyAmount.Parse(value.ToString()); if (amount.IsZero() || amount.IsNegative()) { throw new NotInValueRangeException(fieldName, value); } _amount = amount; } catch (CurrencyAmountFormatException) { throw new NotInValueRangeException(fieldName, value); } } else if (fieldName.Equals(EntryTemplate.POSTING_DATE)) { if (!(value is DateTime)) { throw new NotInValueRangeException(fieldName, value); } DateTime pstDate = (DateTime)value; _pstDate = pstDate; } else { throw new NoFieldNameException(fieldName); } }