Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form in that bankname,accountno,accounttype,checkno and checkbookno.What i want is if i select the bank name combobox accontno,accounttype and chequeno,checkbookno should be filled how to do that.
In bankcheques table i will insert the chequestartno,noofleaves and chequeendno.After i will use all the cheques i will update the status. I will insert new row.
What i want is while using chqleaves of first row show the chequebookno 1.
After totalnoofleaves is completed using and another row insert into the chequetable and update status of the firstrow.I want to show checkbookno 2.How to do that Please help me on this.I tried this.But i am not getting how to increment the checkbook no.And show the message for cheques completed.
Thanks in Advance.

What I have tried:


C#
int id;
int chequeno;
int chqlvscount;
int chqendno;
int lastchequeno;
int totalckbno;
int ckbno;
private void FillCheckNo()
{
    SqlConnection con = new SqlConnection(connectionString);
    con.Open();
    SqlCommand cmd = new SqlCommand("SELECT [bank_Id],[bank_Chqstartno],[bank_Chqlvscount],[bank_Chqendno] FROM [ChequeManager].[dbo].[bankcheques] where bank_Id=@bankid and bank_Stat=0", con);
    cmd.Parameters.AddWithValue("@bankid", cmbBankname.SelectedValue.ToString());
    SqlCommand cmd1 = new SqlCommand("SELECT top 1 [id],[bank_Id],[ChequeNo] FROM [ChequeManager].[dbo].[Cheques] where bank_Id=@bankid order by id desc", con);
    cmd1.Parameters.AddWithValue("@bankid", cmbBankname.SelectedValue.ToString());
    SqlDataAdapter sd = new SqlDataAdapter(cmd1);
    DataTable dt1 = new DataTable();
    sd.Fill(dt1);
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    sda.Fill(dt);
    if (dt.Rows.Count > 0)
    {
        DataRow row = dt.Rows[0];
        id = Convert.ToInt32(row["bank_Id"].ToString());
        chequeno = Convert.ToInt32(row["bank_Chqstartno"].ToString());
        chqlvscount = Convert.ToInt32(row["bank_Chqlvscount"].ToString());
        chqendno = Convert.ToInt32(row["bank_Chqendno"].ToString());
        if (dt1.Rows.Count > 0)
        {
            DataRow row1 = dt1.Rows[0];
            lastchequeno = Convert.ToInt32(row1["ChequeNo"].ToString());
        }

         if (lastchequeno == null || lastchequeno == 0)
        {
            lastchequeno = Convert.ToInt32(row["bank_Chqstartno"].ToString());
            txtcheckno.Text = Convert.ToString(lastchequeno);
        }
        else if (chqendno >= lastchequeno)
        {
            txtcheckno.Text = Convert.ToString(lastchequeno + 1);
            lastchequeno = lastchequeno + 1;

            if (lastchequeno > chqendno)
            {
                txtcheckno.Text = "";
                //txtcheckno.Text = Convert.ToString(lastchequeno);
            }
        }
       con.Close();
    }
}
private void FillChequeBookNo()
{
    SqlConnection con = new SqlConnection(connectionString);
    con.Open();
    SqlCommand cmd = new SqlCommand("SELECT [bank_Id],chqs_Chequebookno,count([chqs_Chequebookno]) as totalcheques  FROM [ChequeManager].[dbo].[chequedetails] where bank_Id=@bankid group by bank_Id,chqs_Chequebookno", con);
    cmd.Parameters.AddWithValue("@bankid", cmbBankname.SelectedValue.ToString());
    SqlDataAdapter sd = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    sd.Fill(dt);
    if (dt.Rows.Count > 0)
    {
        DataRow dr = dt.Rows[0];
        totalckbno = Convert.ToInt32(dr["totalcheques"].ToString());
        ckbno = Convert.ToInt32(dr["chqs_Chequebookno"].ToString());
        txtckbno.Text = Convert.ToString(ckbno);
    }
         if (chqlvscount == totalckbno)
        {
            txtckbno.Text =Convert.ToString(ckbno);
           // totalckbno = totalckbno + 1;
        }
          if(totalckbno>chqlvscount)
         {
            txtckbno.Text=Convert.ToString(ckbno + 1);
         }

else if (chqlvscount > totalckbno)
    {
        txtckbno.Text = Convert.ToString(ckbno);
    }
}

Posted
Comments
Richard MacCutchan 5-Jun-17 8:05am    
You need a table in the database that holds these values, linked to each bank account. When the selected bank account changes you load the new values from the database inot your controls.
Member 13153537 5-Jun-17 8:07am    
I did that.Please Check My code Once.Thanks in Advance.
Richard MacCutchan 5-Jun-17 8:29am    
Sorry this is not a code checking service, that is your job. If you have a specific problem then please post the details and people will try to help you.
Member 13153537 6-Jun-17 0:17am    
My Problem is in my bankdetails table example bank is sbi i insert record like like chequestartno,noofleaves,chequeendno and status.
I used cheques like startno to endno showing in the chequeno and chequebook no is 1 for the after completed the totalcheques.If i used total cheques and update the status and insert another record in table i want to show the chequebook no 2.How to do that.please help me.Thanks in Advance.
Richard MacCutchan 6-Jun-17 3:31am    
Think about what you are trying to do. Each chequebook starts with a certain number and contains another certain number of cheques. So the first book starts with 1 to 30 for example, and when page number 30 is used you set the start number to the final number plus 1 and continue.

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