Exemple #1
0
        /// <summary>
        /// Parse string to Document Identity
        /// </summary>
        /// <param name="docIdStr"></param>
        /// <returns></returns>
        /// <exception cref="DocumentIdentityFormatException">Document Identity Exception</exception>
        public static DocumentIdentity Parse(String docIdStr)
        {
            try
            {
                String docNumStr  = docIdStr.Substring(0, 10);
                String monthIdStr = docIdStr.Substring(11, 7);

                DocumentNumber id      = new DocumentNumber(docNumStr.ToCharArray());
                MonthIdentity  monthId = MonthIdentity.Parse(monthIdStr);

                return(new DocumentIdentity(id, monthId));
            }
            catch (ArgumentOutOfRangeException)
            {
                throw new DocumentIdentityFormatException(docIdStr);
            }
            catch (IdentityTooLong)
            {
                throw new DocumentIdentityFormatException(docIdStr);
            }
            catch (IdentityNoData)
            {
                throw new DocumentIdentityFormatException(docIdStr);
            }
            catch (IdentityInvalidChar)
            {
                throw new DocumentIdentityFormatException(docIdStr);
            }
            catch (MonthIdentityFormatException)
            {
                throw new DocumentIdentityFormatException(docIdStr);
            }
        }
        /// <summary>
        /// Parse string to Document Identity
        /// </summary>
        /// <param name="docIdStr"></param>
        /// <returns></returns>
        /// <exception cref="DocumentIdentityFormatException">Document Identity Exception</exception>
        public static DocumentIdentity Parse(String docIdStr)
        {
            try
            {
                String docNumStr = docIdStr.Substring(0, 10);
                String monthIdStr = docIdStr.Substring(11, 7);

                DocumentNumber id = new DocumentNumber(docNumStr.ToCharArray());
                MonthIdentity monthId = MonthIdentity.Parse(monthIdStr);

                return new DocumentIdentity(id, monthId);
            }
            catch (ArgumentOutOfRangeException)
            {
                throw new DocumentIdentityFormatException(docIdStr);
            }
            catch (IdentityTooLong)
            {
                throw new DocumentIdentityFormatException(docIdStr);
            }
            catch (IdentityNoData)
            {
                throw new DocumentIdentityFormatException(docIdStr);
            }
            catch (IdentityInvalidChar)
            {
                throw new DocumentIdentityFormatException(docIdStr);
            }
            catch (MonthIdentityFormatException)
            {
                throw new DocumentIdentityFormatException(docIdStr);
            }
        }
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="docNum"></param>
 /// <param name="monthIdentity"></param>
 public DocumentIdentity(DocumentNumber docNum, MonthIdentity monthIdentity)
 {
     _docNumber = docNum;
     _monthIdentity = monthIdentity;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="docNum"></param>
 /// <param name="fiscalYear"></param>
 /// <param name="fiscalMonth"></param>
 /// <exception cref="FiscalYearRangeException"></exception>
 /// <exception cref="FiscalMonthRangeException"></exception>
 public DocumentIdentity(DocumentNumber docNum, int fiscalYear,
         int fiscalMonth)
 {
     _docNumber = docNum;
     _monthIdentity = new MonthIdentity(fiscalYear, fiscalMonth);
 }
Exemple #5
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="docNum"></param>
 /// <param name="monthIdentity"></param>
 public DocumentIdentity(DocumentNumber docNum, MonthIdentity monthIdentity)
 {
     _docNumber     = docNum;
     _monthIdentity = monthIdentity;
 }
Exemple #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="docNum"></param>
 /// <param name="fiscalYear"></param>
 /// <param name="fiscalMonth"></param>
 /// <exception cref="FiscalYearRangeException"></exception>
 /// <exception cref="FiscalMonthRangeException"></exception>
 public DocumentIdentity(DocumentNumber docNum, int fiscalYear,
                         int fiscalMonth)
 {
     _docNumber     = docNum;
     _monthIdentity = new MonthIdentity(fiscalYear, fiscalMonth);
 }
Exemple #7
0
        /// <summary>
        /// save document
        /// </summary>
        /// <param name="head"></param>
        /// <param name="needStroe"></param>
        /// <exception cref="SystemException"></exception>
        /// <exception cref="SaveClosedLedgerException"></exception>
        internal async Task saveDocumentAsync(HeadEntity head, bool needStroe)
        {
            _coreDriver.logDebugInfo(this.GetType(), 231,
                                     "Call transaction to save the document", MessageType.INFO);

            if (head.IsSaved)
            {
                _coreDriver.logDebugInfo(this.GetType(), 235,
                                         "Document is saved, just to store the update on disk.",
                                         MessageType.INFO);
            }
            else
            {
                _coreDriver.logDebugInfo(this.GetType(), 239,
                                         "Document is never saved", MessageType.INFO);

                MonthIdentity monthId = head.MonthID;
                MonthLedger   ledger  = this.GetLedger(monthId);
                if (ledger == null)
                {
                    _coreDriver.logDebugInfo(this.GetType(), 239,
                                             "Error in document month identity", MessageType.ERRO);
                    throw new SaveClosedLedgerException();
                }

                // set document number
                DocumentNumber    num;
                List <HeadEntity> entities = ledger.Entities;
                if (entities.Count == 0)
                {
                    try
                    {
                        num = new DocumentNumber("1000000001".ToCharArray());
                    }
                    catch (IdentityTooLong e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                                 e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                    catch (IdentityNoData e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                                 e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                    catch (IdentityInvalidChar e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                                 e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                }
                else
                {
                    HeadEntity last = entities[entities.Count - 1];
                    num = last.DocNumber.Next();
                }
                _coreDriver.logDebugInfo(this.GetType(), 239,
                                         "Generate document number " + num.ToString(),
                                         MessageType.INFO);
                head._docNumber = num;

                ledger.Add(head);
            }

            if (needStroe)
            {
                await StoreAsync(head.MonthID);

                _coreDriver.logDebugInfo(this.GetType(), 465,
                                         "Memory has been stored to disk", MessageType.INFO);
            }
            else
            {
                _coreDriver.logDebugInfo(this.GetType(), 465,
                                         "Memory has NOT been stored to disk", MessageType.INFO);
            }

            _coreDriver.logDebugInfo(this.GetType(), 278,
                                     "Call transaction to save the document successfully",
                                     MessageType.INFO);
        }
 public void TestDocumentIdentity()
 {
     DocumentNumber docNum = new DocumentNumber(
         TestUtilities.TEST_DOC_NUM.ToCharArray());
     DocumentIdentity id = new DocumentIdentity(docNum, 2012, 07);
     String idStr = id.ToString();
     Assert.AreEqual(TestUtilities.TEST_DOC_ID, idStr);
     DocumentIdentity newId = DocumentIdentity.Parse(idStr);
     Assert.AreEqual(newId, id);
 }
        /// <summary>
        /// save document
        /// </summary>
        /// <param name="head"></param>
        /// <param name="needStroe"></param>
        /// <exception cref="SystemException"></exception>
        /// <exception cref="SaveClosedLedgerException"></exception>
        internal async Task saveDocumentAsync(HeadEntity head, bool needStroe)
        {
            _coreDriver.logDebugInfo(this.GetType(), 231,
                    "Call transaction to save the document", MessageType.INFO);

            if (head.IsSaved)
            {
                _coreDriver.logDebugInfo(this.GetType(), 235,
                        "Document is saved, just to store the update on disk.",
                        MessageType.INFO);
            }
            else
            {
                _coreDriver.logDebugInfo(this.GetType(), 239,
                        "Document is never saved", MessageType.INFO);

                MonthIdentity monthId = head.MonthID;
                MonthLedger ledger = this.GetLedger(monthId);
                if (ledger == null)
                {
                    _coreDriver.logDebugInfo(this.GetType(), 239,
                            "Error in document month identity", MessageType.ERRO);
                    throw new SaveClosedLedgerException();
                }

                // set document number
                DocumentNumber num;
                List<HeadEntity> entities = ledger.Entities;
                if (entities.Count == 0)
                {
                    try
                    {
                        num = new DocumentNumber("1000000001".ToCharArray());
                    }
                    catch (IdentityTooLong e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                    catch (IdentityNoData e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                    catch (IdentityInvalidChar e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                }
                else
                {
                    HeadEntity last = entities[entities.Count - 1];
                    num = last.DocNumber.Next();
                }
                _coreDriver.logDebugInfo(this.GetType(), 239,
                        "Generate document number " + num.ToString(),
                        MessageType.INFO);
                head._docNumber = num;

                ledger.Add(head);
            }

            if (needStroe)
            {
                await StoreAsync(head.MonthID);
                _coreDriver.logDebugInfo(this.GetType(), 465,
                        "Memory has been stored to disk", MessageType.INFO);
            }
            else
            {
                _coreDriver.logDebugInfo(this.GetType(), 465,
                        "Memory has NOT been stored to disk", MessageType.INFO);
            }

            _coreDriver.logDebugInfo(this.GetType(), 278,
                    "Call transaction to save the document successfully",
                    MessageType.INFO);
        }