Last active
November 21, 2019 07:32
-
-
Save hendrasyp/324c10da0dfb6a83592894b9b1be9ebf to your computer and use it in GitHub Desktop.
Formatted Sequence Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// db = Instance of Entities Object | |
public static void StoreLastSequence(int lastSequence, string prefix) | |
{ | |
applicationoption applicationoption = db.applicationoption.Where(m => m.CODE == "NOMOR_INVOICE").Single(); | |
applicationoption.VALUE = lastSequence.ToString(); | |
db.Entry(applicationoption).State = System.Data.EntityState.Modified; | |
db.SaveChanges(); | |
} | |
public static string[] GetNextSequenceNumber(string prefix) | |
{ | |
applicationoption applicationoption = db.applicationoption.Where(m => m.CODE == "NOMOR_INVOICE").Single(); | |
var today = DateTime.Today; | |
int currentSequenceNo = Convert.ToInt32(applicationoption.VALUE); | |
currentSequenceNo = currentSequenceNo + 1; | |
var formattedSequenceNo = "00000000" + currentSequenceNo.ToString(); | |
formattedSequenceNo = formattedSequenceNo.Substring(formattedSequenceNo.Length - 7); | |
string NextSequence = $"{prefix}{today.Year}{formattedSequenceNo}"; //e.g SYP20190000001, SYP20190000002 | |
string[] returns = { NextSequence, currentSequenceNo.ToString() }; | |
return returns; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `applicationoption` ( | |
`CODE` varchar(50) NOT NULL, | |
`DESCRIPTION` varchar(200) DEFAULT NULL, | |
`VALUE` text | |
PRIMARY KEY (`CODE`) USING BTREE | |
); | |
INSERT INTO `applicationoption` (`CODE`, `DESCRIPTION`, `VALUE`) VALUES ('NOMOR_INVOICE', 'Sequence Number untuk invoice', '0'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
string[] NextSequenceNumber = CommonHelper.GetNextSequenceNumber("SYP"); | |
// Save your generated formatted number | |
// ... here | |
// db.SaveChanges(); | |
string SequenceNumber = NextSequenceNumber[0]; | |
int LastSequenceNumber = Convert.ToInt32(NextSequenceNumber[1]); | |
Console.WriteLine("'{0}'", SequenceNumber); | |
Console.WriteLine("'{0}'", LastSequenceNumber); | |
// Update Last Sequence Number | |
CommonHelper.StoreLastSequence("SYP"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment