Exemplo n.º 1
0
            /// <summary>
            /// Given a string, contents, and format block in the string, fills format block with contents.
            /// </summary>
            /// <param name="template">String with block to be filled.</param>
            /// <param name="formatBlock">The format of the block to be filled in the template string.</param>
            /// <param name="contents">String to put into the template block.</param>
            /// <returns>The fill block.</returns>
            private static string FillBlock(string template, FormatBlock formatBlock, string contents)
            {
                string filledTemplate = template;

                string trimmed = contents.PadLeft(formatBlock.Length, '0');

                trimmed = trimmed.Substring(trimmed.Length - formatBlock.Length);

                filledTemplate = filledTemplate.Remove(formatBlock.StartIndex, formatBlock.Length);
                filledTemplate = filledTemplate.Insert(formatBlock.StartIndex, trimmed);

                return(filledTemplate);
            }
Exemplo n.º 2
0
            /// <summary>
            /// Extracts the number sequence value from the receipt mask.
            /// </summary>
            /// <param name="receiptMask">Template mask for receipt identifier.</param>
            /// <param name="receiptId">The receipt identifier to extract number sequence value.</param>
            /// <returns>Returns the number sequence value of the receipt.</returns>
            public static long GetNumberSequenceFromReceipt(string receiptMask, string receiptId)
            {
                ReadOnlyCollection <FormatBlock> formatBlocks = GetFormatBlocks(receiptMask, new[] { '#' });

                FormatBlock formatBlock = formatBlocks.SingleOrDefault();

                if (formatBlock != default(FormatBlock))
                {
                    string numberSequenceValue = receiptId.Substring(formatBlock.StartIndex, formatBlock.Length);

                    long numberSequence;
                    if (long.TryParse(numberSequenceValue, out numberSequence))
                    {
                        return(numberSequence);
                    }
                }

                return(0L);
            }
Exemplo n.º 3
0
 private bool Equals(FormatBlock other)
 {
     return(this.StartIndex == other.StartIndex && this.Length == other.Length);
 }