public void AutoInvoiceGenerate() { decimal AlreadyExistInvoice = _SalesRepository.AlreadyExistInvoice(); int code = 1; if (AlreadyExistInvoice >= 1) { var LastExistInvoice = _SalesRepository.LastExistInvoice(); if (LastExistInvoice != null) { code = Convert.ToInt32(LastExistInvoice.Invoice); code++; } txtInvoice.Text = code.ToString("000"); } else { txtInvoice.Text = "100"; } }