You must Sign In to post a response.
  • Category: .NET

    How to reset bill number every day starts from 1

    i am creating windows application using c# 2010, here i want set bill number for my form, but i want that bill number every day stats from 1. how to create give me any one ideas.
  • #768830
    Hi,

    You can do that simply by checking the system date with time.
    Every time when the bill number is generating check the Time stamp of the system. If the Time stamp is equal or more than 12am. Then we can considered it has next day and we reset the count to 1.


    Public generateBill( BillNo)
    {
    public substring CheckTimestamp();
    {
    If (Systemdatetimestamp >= 12)
    {
    BillNo =1 ;
    }

    }

    //Your Bill generating logic

    }

    Thanks,
    Mani

  • #768831
    Now i am using below this code for bill number, how to integrated above your code in my below code give me some ideas


    public void AutoNumber()
    {

    SqlConnection con = new SqlConnection(db.Connectionstring());
    con.Open();

    SqlCommand cmd = new SqlCommand("SELECT max(billno) +1 FROM billing", con);

    SqlDataReader dr = cmd.ExecuteReader();

    if (dr.HasRows)
    {

    while (dr.Read())
    {
    lblbillno.Text = dr[0].ToString();

    if (lblbillno.Text == "")
    {
    lblbillno.Text = "1";
    }


    }
    }

    else
    {
    lblbillno.Text = "1";

    }
    con.Close();
    }

  • #768836
    Hi,

    How are you incrementing numbers here? I don't find any incrementation over the code.
    Are the incrementing happening through DB side?

    So as per my understanding your above code is perfectly working for a single day without any issues?
    If so, You need to implement the condition about the IF statement.



    if( If its more than 12PM)
    {
    lblbillno.Text = "1";
    }

    else if (dr.HasRows)
    {

    while (dr.Read())
    {
    lblbillno.Text = dr[0].ToString();

    if (lblbillno.Text == "")
    {
    lblbillno.Text = "1";
    }

    else
    {
    //Issue with the generation
    }
    }
    }




    Thanks,
    Mani

  • #768846
    Hi,

    you are using the below sql query to increment your bill no


    SELECT max(billno) +1 FROM billing


    but this is not enough to achieve your task, you have some condition i.e. increase the bill no day to day, if you don't have this condition whatever query you written is enough but in your case you have to increase the bill no day to day, so put the condition in your query using date filter.

    Ex:

    SELECT max(billno) +1 FROM billing where Convert(DATETIME,datefield,101)=Convert(DATETIME, GetDate(),101)


    by this way you can get the current date and it's increase the bill no based on date wise.

    I didn't test the above query you should use the concept and if any modifications do it and implement as you need.

    Hope this helps you....

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments