Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sir,

Please give idea about

How to generate bill numbers dynamically...
Posted
Comments
bbirajdar 12-Oct-12 2:58am    
use primary key in sql....
I.explore.code 12-Oct-12 3:01am    
Please improve your question rather than posting such ambiguous questions. What bill number? Does it have to be random or sequenced? What have u tried so far? Where exactly are u stuck? Where is your code?

1 solution

This is the code i created for my project to create dynamically voucher No
It will sure help u , same concept.Let me know if u feel confusion

public void GenerateCashVoucherNo(bool PR)
        {
            int MaxEntryMonth = 0, MinEntryMont = 0, diff = 0;
            DateTime Today = DateTime.Now;
            int Year = Today.Year;
            int Month = Today.Month;
            DateTime Yesterday = DateTime.Now.AddDays(-1);
            int MonthDiff = Today.Month - Yesterday.Month;
            clsBLCashBook oCash = clsBLCashBook.getObject();
            oCash.EntityID = clsGlobalVar.CompanyID;
            oCash.value = 4;
            DataTable dt = oCash.getCBData();
            string dbSeqNo = dt.Rows[0][0].ToString();
            string dblastSeqNo = dt.Rows[0][1].ToString();

            if (dbSeqNo != "")
            {
                MaxEntryMonth = Convert.ToInt16(dbSeqNo.Substring(4, 2));
                MinEntryMont = Convert.ToInt16(dblastSeqNo.Substring(4, 2));
                diff = MaxEntryMonth - MinEntryMont;
            }
            

            if (MonthDiff == 0)
            {

                if (dbSeqNo == "" || MaxEntryMonth!=Month)
                {
                    int Seq = 1;
                    if (Month.ToString().Length == 1)
                    {
                        SeqNo = Year.ToString() + "0" + Month.ToString() + "000" + Seq.ToString();
                    }

                    else
                    {
                        SeqNo = Year.ToString() + Month.ToString() + "000" + Seq.ToString();
                    }
                }

                else
                {
                    int Seq = Convert.ToInt32(dbSeqNo) + 1;
                    SeqNo = Seq.ToString();
                }


                if (PR == true)
                {
                    txtVoucherNo.Text = "CB/P/" + SeqNo;
                }
                else
                {
                    txtVoucherNo.Text = "CB/R/"  + SeqNo;
                }
            }
            else
            
            {
                if (diff == 0)
                {
                    if (dbSeqNo == "" || dbSeqNo.Equals(null))
                    {
                        int Seq = 1;
                        if (Month.ToString().Length == 1)
                        {

                            SeqNo = Year.ToString() + "0" + Month.ToString() + "000" + Seq.ToString();
                        }
                        else
                        {
                            SeqNo = Year.ToString() + Month.ToString() + "000" + Seq.ToString();
                        }
                    }
                    else
                    {
                        int Seq = Convert.ToInt32(dbSeqNo) + 1;
                        SeqNo = Seq.ToString();
                    }

                    if (PR == true)
                    {
                        txtVoucherNo.Text = "CB/P/" + SeqNo;
                    }
                    else
                    {
                        txtVoucherNo.Text = "CB/R/" + SeqNo;
                    }
                }

                else
                {

                }
            }
        }


This is the Query for Value 4 from the database that is called from upper.

SQL
IF (@value=4)
BEGIN
Select MAX(SeqNo) as SeqNo,MIN(SeqNo) as LastSeqNo from tbl_Cash where SeqNo IN (Select top 2 SeqNo from tbl_Cash order by SeqNo desc)
END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900