/// <summary> /// constructor /// </summary> /// <param name="coreDriver"></param> /// <param name="id"></param> /// <param name="type"></param> internal DocumentIndexItemWithBalance(CoreDriver coreDriver, MasterDataIdentity id, MasterDataType type) : base(coreDriver, id) { _type = type; _sum = new CurrencyAmount(); }
/// <summary> /// Constructor /// </summary> /// <param name="coreDriver"></param> /// <param name="id"></param> internal DocumentIndexItem(CoreDriver coreDriver, MasterDataIdentity id) { _coreDriver = coreDriver; _id = id; _list = new List<HeadEntity>(); _amountList = new Dictionary<MonthIdentity, CurrencyAmount>(); }
/// <summary> /// Constructor /// </summary> /// <param name="coreDriver"></param> /// <param name="management"></param> /// <param name="id"></param> /// <param name="descp"></param> /// <param name="bankAccount"></param> /// <exception cref="ArgumentNullException">Argument is null.</exception> /// <exception cref="NoGLAccountGroupException">No such G\L account group exception</exception> public GLAccountMasterData(CoreDriver coreDriver, MasterDataManagement management, MasterDataIdentity_GLAccount id, String descp, MasterDataIdentity bankAccount) : base(coreDriver, management, id, descp) { // check id and get group String groupId = id.ToString().Substring(0, 4); try { _group = GLAccountGroup.Parse(groupId); } catch (GLAccountGroupFormatException) { throw new NoGLAccountGroupException(groupId); } if (bankAccount == null) { _bankAccount = null; } else { MasterDataBase bankAccountId = _management.GetMasterData( bankAccount, MasterDataType.BANK_ACCOUNT); if (bankAccountId == null) { throw new MasterDataIdentityNotDefined(bankAccount, MasterDataType.BANK_ACCOUNT); } _bankAccount = bankAccountId.GetIdentity(); } // init amount _initAmount = new CurrencyAmount(); }
/// <summary> /// Create new master data /// </summary> /// <param name="identity"></param> /// <param name="descp"></param> /// <param name="?"></param> /// <returns></returns> /// <exception cref="ParametersException">Parameters Exception</exception> /// <exception cref="MasterDataIdentityExists">Duplicated master data identity exists </exception> /// <exception cref="MasterDataIdentityNotDefined">Master data identity is not defined</exception> /// <exception cref="SystemException">Bug</exception> public override MasterDataBase CreateNewMasterDataBase(MasterDataIdentity id , string descp, params object[] objects) { if (id == null || descp == null) { throw new ArgumentNullException(); } if (objects.Length > 0) { throw new ParametersException(0, objects.Length); } // check identity is duplicated if (_list.ContainsKey(id)) { throw new MasterDataIdentityExists(); } BankKeyMasterData bankKey = new BankKeyMasterData(_coreDriver, _management, id, descp); this._containDirtyData = true; this._list.Add(id, bankKey); // raise create master data _coreDriver.ListenerMgmt.CreateMasterData(this, bankKey); _coreDriver.logDebugInfo(this.GetType(), 47, String.Format("Create bank key ({0}).", bankKey.Identity.ToString()), MessageType.INFO); return bankKey; }
protected override void newDoc(HeadEntity head) { List <ItemEntity> items = head.Items; foreach (ItemEntity itemEntity in items) { MasterDataIdentity id = itemEntity.GLAccount; if (id != null) { DocumentIndexItem item; if (!_list.TryGetValue(id, out item)) { item = new DocumentIndexItemWithBalance(_coreDriver, id, MasterDataType.BUSINESS_AREA); _list.Add(id, item); } // add document item.addDoc(head); // add amount CurrencyAmount amount = itemEntity.Amount; if (itemEntity.CdIndicator == CreditDebitIndicator.CREDIT) { amount.Negate(); } item.addAmount(head.MonthID, amount); } } }
/// <summary> /// Constructor /// </summary> /// <param name="coreDriver"></param> /// <param name="id"></param> internal DocumentIndexItem(CoreDriver coreDriver, MasterDataIdentity id) { _coreDriver = coreDriver; _id = id; _list = new List <HeadEntity>(); _amountList = new Dictionary <MonthIdentity, CurrencyAmount>(); }
/// <summary> /// Create new master data /// </summary> /// <param name="identity"></param> /// <param name="descp"></param> /// <param name="?"></param> /// <returns></returns> /// <exception cref="ParametersException">Parameters Exception</exception> /// <exception cref="MasterDataIdentityExists">Duplicated master data identity exists </exception> /// <exception cref="MasterDataIdentityNotDefined">Master data identity is not defined</exception> /// <exception cref="ArgumentNullException">Argument is null</exception> /// <exception cref="SystemException">Bug</exception> public override MasterDataBase CreateNewMasterDataBase(MasterDataIdentity identity, String descp, params Object[] objects) { // check id is G/L identity MasterDataIdentity_GLAccount identity_gl = identity as MasterDataIdentity_GLAccount; if (identity_gl == null) { throw new ParametersException(); } // check duplicated if (_list.ContainsKey(identity)) { throw new MasterDataIdentityExists(); } MasterDataIdentity bankAccount = null; if (objects.Length == 0 || objects.Length == 1) { } else { throw new ParametersException(1, objects.Length); } if (objects.Length == 1) { // contain bank account bankAccount = objects[0] as MasterDataIdentity; if (bankAccount == null) { throw new ParametersException(); } } GLAccountMasterData glAccount; try { glAccount = new GLAccountMasterData(_coreDriver, _management, identity_gl, descp, bankAccount); } catch (ArgumentNullException e) { throw new SystemException(e); } catch (NoGLAccountGroupException) { throw new ParametersException(); } this._containDirtyData = true; this._list.Add(identity_gl, glAccount); // raise create master data _coreDriver.ListenerMgmt.CreateMasterData(this, glAccount); _coreDriver.logDebugInfo(this.GetType(), 84, String.Format("Create G/L account ({0}).", glAccount.Identity.ToString()), MessageType.INFO); return glAccount; }
/// <summary> /// reverse document /// </summary> /// <param name="head"></param> protected override void reverseDoc(HeadEntity head) { List <ItemEntity> items = head.Items; foreach (ItemEntity itemEntity in items) { MasterDataIdentity id = itemEntity.GLAccount; if (!_list.ContainsKey(id)) { continue; } DocumentIndexItem item; if (_list.TryGetValue(id, out item) == false) { continue; } // remove document item.removeDoc(head); // remove amount CurrencyAmount amount = itemEntity.Amount; if (itemEntity.CdIndicator == CreditDebitIndicator.DEBIT) { amount.Negate(); } item.addAmount(head.MonthID, amount); } }
/// <summary> /// Set business area /// </summary> /// <param name="businessArea"></param> /// <returns></returns> /// <exception cref="MasterDataIdentityNotDefined"></exception> public bool SetBusinessArea(MasterDataIdentity businessArea) { if (_isSaved) { return(false); } if (businessArea == null) { _businessArea = null; return(true); } MasterDataBase accountId = _management.GetMasterData(businessArea, MasterDataType.BUSINESS_AREA); if (accountId == null) { throw new MasterDataIdentityNotDefined(businessArea, MasterDataType.BUSINESS_AREA); } _businessArea = businessArea; return(true); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="descp"></param> /// <param name="?"></param> /// <returns></returns> /// <exception cref="ParametersException">Parameters Exception</exception> /// <exception cref="MasterDataIdentityExists">Duplicated master data identity exists </exception> /// <exception cref="MasterDataIdentityNotDefined">Master data identity is not defined</exception> /// <exception cref="ArgumentNullException">Argument is null</exception> /// <exception cref="SystemException">Bug</exception> public override MasterDataBase CreateNewMasterDataBase(MasterDataIdentity id, String descp, params Object[] objects) { // check parameters if (id == null || descp == null) { throw new ArgumentNullException(); } if (objects.Length != 0) { throw new ParametersException(0, objects.Length); } // check identity is duplicated if (_list.ContainsKey(id)) { throw new MasterDataIdentityExists(); } CustomerMasterData customer = new CustomerMasterData(_coreDriver, _management, id, descp); this._containDirtyData = true; this._list.Add(id, customer); // raise create master data _coreDriver.ListenerMgmt.CreateMasterData(this, customer); _coreDriver.logDebugInfo(this.GetType(), 84, String.Format("Create customer (%s).", customer.Identity.ToString()), MessageType.INFO); return customer; }
public MasterDataIdentityNotDefined(MasterDataIdentity id, MasterDataType type) : base(String.Format("Bank Key %s is not defined %s", id.ToString(), type.ToString())) { MdId = id; MdType = type; }
/// <summary> /// get the amount from item /// </summary> /// <param name="item"></param> /// <returns></returns> private CurrencyAmount getAmountFromItem(ItemEntity item) { if (_type == MasterDataType.BUSINESS_AREA) { MasterDataIdentity business = item.BusinessArea; if (this._id.Equals(business)) { if (item.CdIndicator == CreditDebitIndicator.DEBIT) { return(item.Amount); } else { CurrencyAmount amount = item.Amount; amount.Negate(); return(amount); } } } else if (_type == MasterDataType.CUSTOMER) { MasterDataIdentity customer = item.Customer; if (this._id.Equals(customer)) { if (item.CdIndicator == CreditDebitIndicator.DEBIT) { return(item.Amount); } else { CurrencyAmount amount = item.Amount; amount.Negate(); return(amount); } } } else if (_type == MasterDataType.VENDOR) { MasterDataIdentity vendor = item.Vendor; if (this._id.Equals(vendor)) { if (item.CdIndicator == CreditDebitIndicator.DEBIT) { return(item.Amount); } else { CurrencyAmount amount = item.Amount; amount.Negate(); return(amount); } } } return(new CurrencyAmount()); }
/// <summary> /// get index item /// </summary> /// <param name="key"></param> /// <returns></returns> public DocumentIndexItem getIndexItem(MasterDataIdentity key) { DocumentIndexItem item; if (_list.TryGetValue(key, out item)) { return(item); } return(null); }
/// <summary> /// set customer /// </summary> /// <param name="customer"></param> /// <exception cref="NotInValueRangeException"></exception> private void setCustomer(MasterDataIdentity customer) { if (customer == null) { throw new NotInValueRangeException(CUSTOMER, ""); } if (!_mdMgmt.ContainsMasterData(customer, MasterDataType.CUSTOMER)) { throw new NotInValueRangeException(CUSTOMER, customer); } _customer = customer; }
/// <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; }
/// <summary> /// set vendor /// </summary> /// <param name="vendor"></param> /// <exception cref="NotInValueRangeException"></exception> private void setVendor(MasterDataIdentity vendor) { if (vendor == null) { throw new NotInValueRangeException(VENDOR, ""); } if (!this._mdMgmt.ContainsMasterData(vendor, MasterDataType.VENDOR)) { throw new NotInValueRangeException(VENDOR, vendor); } _vendor = vendor; }
/// <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 business area /// </summary> /// <param name="businessArea"></param> /// <exception cref="NotInValueRangeException"></exception> private void setBusinessArea(MasterDataIdentity businessArea) { if (businessArea == null) { throw new NotInValueRangeException(BUSINESS_AREA, ""); } if (!_mdMgmt.ContainsMasterData(businessArea, MasterDataType.BUSINESS_AREA)) { throw new NotInValueRangeException(BUSINESS_AREA, businessArea); } _businessArea = businessArea; }
/// <summary> /// Parse master data from XML /// </summary> /// <param name="coreDriver"></param> /// <param name="elem"></param> /// <returns></returns> /// <exception cref="MasterDataFileFormatException">Master Data file exception</exception> /// <exception cref="ArgumentNullException">Argument is null</exception> /// <exception cref="SystemException">Bug</exception> public override MasterDataBase ParseMasterData(CoreDriver coreDriver, XElement elem) { XAttribute idAttr = elem.Attribute(MasterDataUtils.XML_ID); XAttribute descpAttr = elem.Attribute(MasterDataUtils.XML_DESCP); MasterDataIdentity identity; try { identity = new MasterDataIdentity(idAttr.Value); BankKeyMasterData bankKey = (BankKeyMasterData)this .CreateNewMasterDataBase(identity, descpAttr.Value); _coreDriver.logDebugInfo(this.GetType(), 61, String.Format("Parse bank key ({0}).", bankKey.Identity.ToString()), MessageType.INFO); return bankKey; } catch (IdentityTooLong e) { _coreDriver.logDebugInfo(this.GetType(), 150, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException(MasterDataType.BANK_KEY); } catch (IdentityNoData e) { _coreDriver .logDebugInfo(this.GetType(), 154, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException(MasterDataType.BANK_KEY); } catch (IdentityInvalidChar e) { _coreDriver.logDebugInfo(this.GetType(), 160, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException(MasterDataType.BANK_KEY); } catch (ParametersException e) { _coreDriver.logDebugInfo(this.GetType(), 164, "Function parameter set error: " + e.Message, MessageType.ERRO); throw new SystemException(e); } catch (MasterDataIdentityExists e) { _coreDriver.logDebugInfo(this.GetType(), 168, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException(MasterDataType.BANK_KEY); } }
/// <summary> /// Construct /// </summary> /// <param name="coreDriver">Core Driver</param> /// <param name="management">Matadata management</param> /// <param name="id"></param> /// <param name="descp"></param> /// <param name="accNumber"></param> /// <param name="bankKey"></param> /// <param name="type"></param> /// <exception cref="ArgumentNullException">Arguments null</exception> /// <exception cref="MasterDataIdentityNotDefined">Master data identity is not defined.</exception> public BankAccountMasterData(CoreDriver coreDriver, MasterDataManagement management, MasterDataIdentity id, String descp, BankAccountNumber accNumber, MasterDataIdentity bankKey, BankAccountType type) : base(coreDriver, management, id, descp) { _accNumber = accNumber; _bankAccType = type; MasterDataBase bankKeyId = management.GetMasterData(bankKey, MasterDataType.BANK_KEY); if (bankKeyId == null) { throw new MasterDataIdentityNotDefined(bankKey, MasterDataType.BANK_KEY); } _bankKey = bankKeyId.GetIdentity(); }
/// <summary> /// /// </summary> /// <param name="coreDriver"></param> /// <param name="management"></param> /// <param name="id"></param> /// <param name="descp"></param> /// <param name="level"></param> /// <exception cref="ArgumentNullException">argument is null</exception> public override MasterDataBase CreateNewMasterDataBase(MasterDataIdentity identity, String descp, params Object[] objects) { if (objects.Length != 1) { throw new ParametersException(1, objects.Length); } // check identity is duplicated if (_list.ContainsKey(identity)) { throw new MasterDataIdentityExists(); } if (!(objects[0] is CriticalLevel)) { throw new ParametersException(); } CriticalLevel l = (CriticalLevel)objects[0]; BusinessAreaMasterData businessArea; try { businessArea = new BusinessAreaMasterData(_coreDriver, _management, identity, descp, l); } catch (ArgumentNullException e) { throw new SystemException(e); } this._containDirtyData = true; this._list.Add(identity, businessArea); // raise create master data _coreDriver.ListenerMgmt.CreateMasterData(this, businessArea); _coreDriver.logDebugInfo( this.GetType(), 59, String.Format("Create business area (%s).", businessArea.Identity.ToString()), MessageType.INFO); return businessArea; }
/// <summary> /// get index item /// </summary> /// <param name="key"></param> /// <returns></returns> public DocumentIndexItem getIndexItem(MasterDataIdentity key) { DocumentIndexItem item; if (_list.TryGetValue(key, out item)) { return item; } return null; }
/// <summary> /// get master data with identity /// </summary> /// <param name="idStr"></param> /// <param name="type"></param> /// <returns></returns> /// <exception cref="IdentityInvalidChar"></exception> /// <exception cref="IdentityNoData"></exception> /// <exception cref="IdentityTooLong"></exception> public MasterDataBase GetMasterData(char[] idStr, MasterDataType type) { MasterDataFactoryBase factory = this.GetMasterDataFactory(type); MasterDataIdentity id = new MasterDataIdentity(idStr); return factory.GetEntity(id); }
/// <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); } }
/// <summary> /// set bank key /// </summary> /// <param name="bankKey"></param> /// <exception cref="ArgumentNullException">Arguments null</exception> /// <exception cref="MasterDataIdentityNotDefined">Master data identity is not defined.</exception> public void SetBankKey(MasterDataIdentity bankKey) { if (bankKey == null) { throw new ArgumentNullException("Bank Key"); } MasterDataManagement management = this._management; MasterDataBase bankKeyId = management.GetMasterData(bankKey, MasterDataType.BANK_KEY); if (bankKeyId == null) { throw new MasterDataIdentityNotDefined(bankKey, MasterDataType.BANK_KEY); } this.SetDirtyData(); _bankKey = bankKeyId.GetIdentity(); }
/// <summary> /// Create new master data /// </summary> /// <param name="identity"></param> /// <param name="descp"></param> /// <param name="BankAccountNumber">Bank Account Number</param> /// <param name="MasterDataIdentity">Bank Key</param> /// <returns></returns> /// <exception cref="ParametersException">Parameters Exception</exception> /// <exception cref="MasterDataIdentityExists">Duplicated master data identity exists </exception> /// <exception cref="MasterDataIdentityNotDefined">Master data identity is not defined</exception> /// <exception cref="ArgumentNullException">Argument is null</exception> /// <exception cref="SystemException">Bug</exception> public override MasterDataBase CreateNewMasterDataBase( MasterDataIdentity identity, String descp, params Object[] objects) { if (identity == null || descp == null) { throw new ArgumentNullException(); } if (objects.Length != 3) { throw new ParametersException(3, objects.Length); } // check identity is duplicated if (_list.ContainsKey(identity)) { throw new MasterDataIdentityExists(); } BankAccountNumber accNumber = null; MasterDataIdentity bankKey = null; BankAccountType type; accNumber = objects[0] as BankAccountNumber; if (accNumber == null) { throw new ParametersException(); } bankKey = objects[1] as MasterDataIdentity; if (bankKey == null) { throw new ParametersException(); } if (!(objects[2] is BankAccountType)) { throw new ParametersException(); } type = (BankAccountType)objects[2]; try { BankAccountMasterData bankAccount = new BankAccountMasterData(_coreDriver, _management, identity, descp, accNumber, bankKey, type); // add to list this._list.Add(identity, bankAccount); this._containDirtyData = true; // raise create master data _coreDriver.ListenerMgmt .CreateMasterData(this, bankAccount); _coreDriver .logDebugInfo( this.GetType(), 84, String.Format("Create bank account ({0}).", bankAccount.Identity.ToString()), MessageType.INFO); return bankAccount; } catch (Exception e) {// bug throw new SystemException(e); } }
public static void CreateMasterData(CoreDriver coreDriver) { /// /// check the factory is initialized, and the factory with no master data /// MasterDataManagement masterDataManagement = coreDriver.MdMgmt; // vendor VendorMasterDataFactory vendorFactory = (VendorMasterDataFactory)masterDataManagement .GetMasterDataFactory(MasterDataType.VENDOR); Assert.AreEqual(0, vendorFactory.MasterDataCount); // customer CustomerMasterDataFactory customerFactory = (CustomerMasterDataFactory)masterDataManagement .GetMasterDataFactory(MasterDataType.CUSTOMER); Assert.AreEqual(0, customerFactory.MasterDataCount); // business area BusinessAreaMasterDataFactory businessFactory = (BusinessAreaMasterDataFactory)masterDataManagement .GetMasterDataFactory(MasterDataType.BUSINESS_AREA); Assert.AreEqual(0, businessFactory.MasterDataCount); // bank key BankKeyMasterDataFactory bankKeyFactory = (BankKeyMasterDataFactory)masterDataManagement .GetMasterDataFactory(MasterDataType.BANK_KEY); Assert.AreEqual(0, bankKeyFactory.MasterDataCount); // bank account BankAccountMasterDataFactory bankAccountFactory = (BankAccountMasterDataFactory)masterDataManagement .GetMasterDataFactory(MasterDataType.BANK_ACCOUNT); Assert.AreEqual(0, bankAccountFactory.MasterDataCount); // GL account GLAccountMasterDataFactory accountFactory = (GLAccountMasterDataFactory)masterDataManagement .GetMasterDataFactory(MasterDataType.GL_ACCOUNT); Assert.AreEqual(0, accountFactory.MasterDataCount); /** add master data entities */ // vendor VendorMasterData vendor = (VendorMasterData)vendorFactory .CreateNewMasterDataBase(new MasterDataIdentity( TestData.VENDOR_BUS), TestData.VENDOR_BUS_DESCP); Assert.IsTrue(vendor != null); vendor = (VendorMasterData)vendorFactory.CreateNewMasterDataBase( new MasterDataIdentity(TestData.VENDOR_SUBWAY), TestData.VENDOR_SUBWAY_DESCP); Assert.IsTrue(vendor != null); // duplicate id try { vendorFactory.CreateNewMasterDataBase(new MasterDataIdentity( TestData.VENDOR_SUBWAY), TestData.VENDOR_SUBWAY_DESCP); Assert.Fail("Duplicate Id"); } catch (MasterDataIdentityExists) { } // customer CustomerMasterData customer = (CustomerMasterData)customerFactory .CreateNewMasterDataBase(new MasterDataIdentity( TestData.CUSTOMER1), TestData.CUSTOMER1_DESCP); Assert.IsTrue(customer != null); customer = (CustomerMasterData)customerFactory .CreateNewMasterDataBase(new MasterDataIdentity( TestData.CUSTOMER2), TestData.CUSTOMER2_DESCP); Assert.IsTrue(customer != null); // duplicate id try { customerFactory.CreateNewMasterDataBase(new MasterDataIdentity( TestData.CUSTOMER2), TestData.CUSTOMER2_DESCP); Assert.Fail("Duplicate Id"); } catch (MasterDataIdentityExists) { } // bank key BankKeyMasterData bankKey = (BankKeyMasterData)bankKeyFactory .CreateNewMasterDataBase(new MasterDataIdentity( TestData.BANK_KEY), TestData.BANK_KEY_DESCP); Assert.IsTrue(bankKey != null); // duplicate id try { bankKeyFactory.CreateNewMasterDataBase(new MasterDataIdentity( TestData.BANK_KEY), TestData.BANK_KEY_DESCP); Assert.Fail("Duplicate Id"); } catch (MasterDataIdentityExists) { } // bank account MasterDataIdentity bankKeyId = new MasterDataIdentity(TestData.BANK_KEY); BankAccountNumber accountNum = new BankAccountNumber( TestData.BANK_ACCOUNT_CMB_6235_ACC); BankAccountMasterData bankAcc = (BankAccountMasterData)bankAccountFactory .CreateNewMasterDataBase(new MasterDataIdentity( TestData.BANK_ACCOUNT_CMB_6235), TestData.BANK_ACCOUNT_CMB_6235_DESCP, accountNum, bankKeyId, BankAccountType.SAVING_ACCOUNT); Assert.IsTrue(bankAcc != null); accountNum = new BankAccountNumber(TestData.BANK_ACCOUNT_CMB_6620_ACC); bankAcc = (BankAccountMasterData)bankAccountFactory .CreateNewMasterDataBase(new MasterDataIdentity( TestData.BANK_ACCOUNT_CMB_6620), TestData.BANK_ACCOUNT_CMB_6620_DESCP, accountNum, bankKeyId, BankAccountType.CREDIT_CARD); Assert.IsTrue(bankAcc != null); // duplicate id try { bankAccountFactory.CreateNewMasterDataBase(new MasterDataIdentity( TestData.BANK_ACCOUNT_CMB_6620), TestData.BANK_ACCOUNT_CMB_6620_DESCP, accountNum, bankKey, BankAccountType.SAVING_ACCOUNT); Assert.Fail("Duplicate Id"); } catch (MasterDataIdentityExists) { } // business area BusinessAreaMasterData businessArea = (BusinessAreaMasterData)businessFactory .CreateNewMasterDataBase(new MasterDataIdentity( TestData.BUSINESS_AREA_ENTERTAIN), TestData.BUSINESS_AREA_ENTERTAIN_DESCP, CriticalLevel.MEDIUM); Assert.IsTrue(businessArea != null); businessArea = (BusinessAreaMasterData)businessFactory .CreateNewMasterDataBase(new MasterDataIdentity( TestData.BUSINESS_AREA_WORK), TestData.BUSINESS_AREA_WORK_DESCP, CriticalLevel.HIGH); Assert.IsTrue(businessArea != null); businessArea = (BusinessAreaMasterData)businessFactory .CreateNewMasterDataBase(new MasterDataIdentity( TestData.BUSINESS_AREA_SNACKS), TestData.BUSINESS_AREA_SNACKS_DESCP, CriticalLevel.LOW); Assert.IsTrue(businessArea != null); // duplicate id try { businessArea = (BusinessAreaMasterData)businessFactory .CreateNewMasterDataBase(new MasterDataIdentity( TestData.BUSINESS_AREA_SNACKS), TestData.BUSINESS_AREA_SNACKS_DESCP, CriticalLevel.LOW); Assert.Fail("Duplicate Id"); } catch (MasterDataIdentityExists) { } // G/L account MasterDataIdentity bankAccId = new MasterDataIdentity( TestData.BANK_ACCOUNT_CMB_6235); GLAccountMasterData glAccount = (GLAccountMasterData)accountFactory .CreateNewMasterDataBase(new MasterDataIdentity_GLAccount( TestData.GL_ACCOUNT_BANK), TestData.GL_ACCOUNT_BANK_DESCP, bankAccId); Assert.IsTrue(glAccount != null); glAccount = (GLAccountMasterData)accountFactory .CreateNewMasterDataBase(new MasterDataIdentity_GLAccount( TestData.GL_ACCOUNT_CASH), TestData.GL_ACCOUNT_CASH_DESCP); Assert.IsTrue(glAccount != null); glAccount.SetInitAmount(TestData.AMOUNT_VENDOR); glAccount = (GLAccountMasterData)accountFactory .CreateNewMasterDataBase(new MasterDataIdentity_GLAccount( TestData.GL_ACCOUNT_COST), TestData.GL_ACCOUNT_COST_DESCP); Assert.IsTrue(glAccount != null); glAccount = (GLAccountMasterData)accountFactory .CreateNewMasterDataBase(new MasterDataIdentity_GLAccount( TestData.GL_ACCOUNT_EQUITY), TestData.GL_ACCOUNT_EQUITY_DESCP); Assert.IsTrue(glAccount != null); glAccount = (GLAccountMasterData)accountFactory .CreateNewMasterDataBase(new MasterDataIdentity_GLAccount( TestData.GL_ACCOUNT_REV), TestData.GL_ACCOUNT_REV_DESCP); Assert.IsTrue(glAccount != null); // duplicate id try { accountFactory.CreateNewMasterDataBase( new MasterDataIdentity_GLAccount(TestData.GL_ACCOUNT_REV), TestData.GL_ACCOUNT_REV_DESCP); Assert.Fail("Duplicate Id"); } catch (MasterDataIdentityExists) { } }
/// <summary> /// constains key /// </summary> /// <param name="id"></param> /// <returns></returns> /// <exception cref="ArgumentNullException">Argument is null.</exception> public bool Contains(MasterDataIdentity id) { return _list.ContainsKey(id); }
/// <summary> /// Create new master data /// </summary> /// <param name="identity"></param> /// <param name="descp"></param> /// <param name="?"></param> /// <returns></returns> /// <exception cref="ParametersException">Parameters Exception</exception> /// <exception cref="MasterDataIdentityExists">Duplicated master data identity exists </exception> /// <exception cref="MasterDataIdentityNotDefined">Master data identity is not defined</exception> /// <exception cref="ArgumentNullException">Argument is null</exception> /// <exception cref="SystemException">Bug</exception> public abstract MasterDataBase CreateNewMasterDataBase( MasterDataIdentity identity, String descp, params Object[] objects);
/// <summary> /// /// </summary> /// <param name="coreDriver"></param> /// <param name="management"></param> /// <param name="id"></param> /// <param name="descp"></param> /// <param name="level"></param> /// <exception cref="ArgumentNullException">argument is null</exception> public BusinessAreaMasterData(CoreDriver coreDriver, MasterDataManagement management, MasterDataIdentity id, String descp, CriticalLevel level) : base(coreDriver, management, id, descp) { _criticalLevel = level; }
/// <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); } }
/// <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> /// Parse master data from XElement /// </summary> /// <param name="coreDriver"></param> /// <param name="elem"></param> /// <returns></returns> /// <exception cref="MasterDataFileFormatException">Master Data file exception</exception> /// <exception cref="ArgumentNullException">Argument is null.</exception> /// <exception cref="SystemException">Bug</exception> public override MasterDataBase ParseMasterData(CoreDriver coreDriver, XElement elem) { if (coreDriver == null || elem == null) { throw new ArgumentNullException(); } XAttribute idAttr = elem.Attribute(MasterDataUtils.XML_ID); XAttribute descpAttr = elem.Attribute(MasterDataUtils.XML_DESCP); try { MasterDataIdentity identity = new MasterDataIdentity( idAttr.Value); CustomerMasterData customer = (CustomerMasterData)this .CreateNewMasterDataBase(identity, descpAttr.Value); _coreDriver.logDebugInfo(this.GetType(), 130, String.Format("Parse customer ({0}).", customer.Identity.ToString()), MessageType.INFO); return customer; } catch (IdentityTooLong e) { _coreDriver.logDebugInfo(this.GetType(), 150, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException(MasterDataType.CUSTOMER); } catch (IdentityNoData e) { _coreDriver .logDebugInfo(this.GetType(), 154, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException(MasterDataType.CUSTOMER); } catch (IdentityInvalidChar e) { _coreDriver.logDebugInfo(this.GetType(), 160, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException(MasterDataType.CUSTOMER); } catch (ParametersException e) { _coreDriver.logDebugInfo(this.GetType(), 164, e.Message, MessageType.ERRO); throw new SystemException(e); } catch (MasterDataIdentityExists e) { _coreDriver.logDebugInfo(this.GetType(), 168, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException(MasterDataType.CUSTOMER); } }
/// <summary> /// get master data /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> public MasterDataBase GetMasterData(MasterDataIdentity id, MasterDataType type) { MasterDataFactoryBase factory = this.GetMasterDataFactory(type); return factory.GetEntity(id); }
/// <summary> /// Get entity /// </summary> /// <param name="id"></param> /// <returns></returns> /// <exception cref="ArgumentNullException">Argument is null.</exception> public MasterDataBase GetEntity(MasterDataIdentity id) { if (!Contains(id)) { return null; } MasterDataBase md; _list.TryGetValue(id, out md); return md; }
/// <summary> /// constain master data /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> public bool ContainsMasterData(MasterDataIdentity id, MasterDataType type) { MasterDataFactoryBase factory = this.GetMasterDataFactory(type); return factory.Contains(id); }
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> /// Parse master data from XML /// </summary> /// <param name="coreDriver"></param> /// <param name="elem"></param> /// <returns></returns> /// <exception cref="MasterDataFileFormatException">Master Data file exception</exception> /// <exception cref="ArgumentNullException">Argument is null</exception> /// <exception cref="SystemException">Bug</exception> public override MasterDataBase ParseMasterData(CoreDriver coreDriver, XElement elem) { XAttribute id = elem.Attribute(MasterDataUtils.XML_ID); XAttribute descp = elem.Attribute(MasterDataUtils.XML_DESCP); XAttribute bankAccStr = elem.Attribute(MasterDataUtils.XML_BANK_ACCOUNT); XAttribute initAmountAttr = elem.Attribute(MasterDataUtils.XML_INIT_AMOUNT); MasterDataIdentity_GLAccount identity; MasterDataIdentity bankAccId = null; try { identity = new MasterDataIdentity_GLAccount( id.Value); // bank account if (bankAccStr != null) { bankAccId = new MasterDataIdentity( bankAccStr.Value); } } catch (Exception e) { _coreDriver.logDebugInfo(this.GetType(), 150, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException(MasterDataType.GL_ACCOUNT); } CurrencyAmount initAmount = new CurrencyAmount(); if (initAmountAttr != null) { try { initAmount = CurrencyAmount.Parse(initAmountAttr.Value); } catch (CurrencyAmountFormatException e) { _coreDriver.logDebugInfo(this.GetType(), 150, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException(MasterDataType.GL_ACCOUNT); } } try { GLAccountMasterData glAccount; if (bankAccId == null) { glAccount = (GLAccountMasterData)this.CreateNewMasterDataBase( identity, descp.Value); } else { glAccount = (GLAccountMasterData)this.CreateNewMasterDataBase( identity, descp.Value, bankAccId); } glAccount.setInitAmountInternal(initAmount); _coreDriver .logDebugInfo( this.GetType(), 167, String.Format("Parse G/L account ({0}).", glAccount.Identity.ToString()), MessageType.INFO); return glAccount; } catch (Exception e) { throw new SystemException(e); } }
/// <summary> /// Set bank account /// </summary> /// <param name="bankAccount"></param> /// <exception cref="MasterDataIdentityNotDefined"></exception> public void SetBankAccount(MasterDataIdentity bankAccount) { if (bankAccount == null) { // clear _bankAccount = null; return; } MasterDataBase bankAccountId = this._management.GetMasterData(bankAccount, MasterDataType.BANK_ACCOUNT); if (bankAccountId == null) { throw new MasterDataIdentityNotDefined(bankAccount, MasterDataType.BANK_ACCOUNT); } this.SetDirtyData(); _bankAccount = bankAccountId.Identity; }
/// <summary> /// Construct /// </summary> /// <param name="coreDriver">Core Driver</param> /// <param name="management">Master Data management</param> /// <param name="id">Identity</param> /// <param name="descp">Description</param> /// <exception cref="ArgumentNullException">Arguments null</exception> public BankKeyMasterData(CoreDriver coreDriver, MasterDataManagement management, MasterDataIdentity id, String descp) : base(coreDriver, management, id, descp) { }
/// <summary> /// Parse master data from XML /// </summary> /// <param name="coreDriver"></param> /// <param name="elem"></param> /// <returns></returns> /// <exception cref="MasterDataFileFormatException">Master Data file exception</exception> /// <exception cref="ArgumentNullException">Argument is null</exception> /// <exception cref="SystemException">Bug</exception> public override MasterDataBase ParseMasterData(CoreDriver coreDriver, XElement elem) { XAttribute id = elem.Attribute(MasterDataUtils.XML_ID); XAttribute descp = elem.Attribute(MasterDataUtils.XML_DESCP); XAttribute criticalLevel = elem .Attribute(MasterDataUtils.XML_CRITICAL_LEVEL); // check attribute if (criticalLevel == null) { throw new MasterDataFileFormatException( MasterDataType.BUSINESS_AREA); } if (criticalLevel.Value.Length != 1 || (criticalLevel.Value[0] != (char)CriticalLevel.HIGH && criticalLevel.Value[0] != (char)CriticalLevel.MEDIUM && criticalLevel.Value[0] != (char)CriticalLevel.LOW)) { _coreDriver .logDebugInfo(this.GetType(), 154, "Format of critical level is error", MessageType.ERRO); throw new MasterDataFileFormatException( MasterDataType.BUSINESS_AREA); } CriticalLevel l = (CriticalLevel)criticalLevel.Value[0]; MasterDataIdentity identity; try { identity = new MasterDataIdentity(id.Value); } catch (Exception e) { _coreDriver .logDebugInfo(this.GetType(), 154, e.Message, MessageType.ERRO); throw new MasterDataFileFormatException( MasterDataType.BUSINESS_AREA); } try { BusinessAreaMasterData businessArea = (BusinessAreaMasterData)this .CreateNewMasterDataBase(identity, descp.Value, l); _coreDriver.logDebugInfo( this.GetType(), 130, String.Format("Parse business area ({0}).", businessArea.Identity.ToString()), MessageType.INFO); return businessArea; } catch (Exception e) { throw new SystemException(e); } }
/// <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); }