Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void button4_Click(object sender, EventArgs e)
       {


           if (txttenure.Text == "1")
           {
               b = Convert.ToInt32(txtijarahamount.Text);



               for (int j = 1; j <= 12; j++)
               {
                   int newRowIndex = dataGridView1.Rows.Add();
                   int z = 12;

                   markup = double.Parse(txtmarkup.Text);
                   Double a = (b / 100) * 80;
                   prfrate = (markup + 3.00) / 100.00;
                   bnkprf = (a * prfrate * 31.00) / 365.00;
                   rental = (a + bnkprf + 30000) / z;

                   z--;
                   string r = Convert.ToString(rental);
                   dataGridView1.Rows[newRowIndex].Cells["Amount"].Value = r.ToString();

                   a = a - Convert.ToDouble(dataGridView1.Rows[newRowIndex].Cells["Amount"].Value);
                   r = Convert.ToString(rental);



                   dataGridView1.Rows[newRowIndex].Cells["Date"].Value = dateTimePicker1.Value.Date.AddMonths(j).ToString();
                   dataGridView1.Rows[newRowIndex].Cells["ijarah_id"].Value = txtijarahid.Text;

               }
Posted
Comments
deepak.m.shrma 7-Nov-12 3:06am    
Please specify or illiterate your question. i have check with
if (textBox1.Text == "1")
MessageBox.Show("bingo");
its working fine.
OriginalGriff 7-Nov-12 3:07am    
And?
What is it doing that it shouldn't, or not doing that it should?
Remember that we can't see your screen, access your HDD, or read your mind!
zeshanazam 7-Nov-12 3:17am    
i want to calculate installment record on the basis of if conditions, if value of textbox is 1, loop will calculate the installments of 12 months, if value is 2 it will count installments of 24 months and result will show in gridview.
zeshanazam 7-Nov-12 3:18am    
if (txttenure.Text == "1")
{
b = Convert.ToInt32(txtijarahamount.Text);



for (int j = 1; j <= 12; j++)
{
int newRowIndex = dataGridView1.Rows.Add();
int z = 12;

markup = double.Parse(txtmarkup.Text);
Double a = (b / 100) * 80;
prfrate = (markup + 3.00) / 100.00;
bnkprf = (a * prfrate * 31.00) / 365.00;
rental = (a + bnkprf + 30000) / z;

z--;
string r = Convert.ToString(rental);
dataGridView1.Rows[newRowIndex].Cells["Amount"].Value = r.ToString();

a = a - Convert.ToDouble(dataGridView1.Rows[newRowIndex].Cells["Amount"].Value);
r = Convert.ToString(rental);



dataGridView1.Rows[newRowIndex].Cells["Date"].Value = dateTimePicker1.Value.Date.AddMonths(j).ToString();
dataGridView1.Rows[newRowIndex].Cells["ijarah_id"].Value = txtijarahid.Text;

}

}




else if (txttenure.Text == "2")
{

// b = Convert.ToInt32(txtijarahamount.Text);



for (int j = 1; j <= 24; j++)
{
int newRowIndex = dataGridView1.Rows.Add();
int z = 24;
markup = double.Parse(txtmarkup.Text);
Double a = (b / 100) * 80;
prfrate = (markup + 3.00) / 100.00;
bnkprf = (a * prfrate * 31.00) / 365.00;
rental = (a + bnkprf + 30000) / z;

z--;
string r = Convert.ToString(rental);
dataGridView1.Rows[newRowIndex].Cells["Amount"].Value = r.ToString();

a = a - Convert.ToDouble(dataGridView1.Rows[newRowIndex].Cells["Amount"].Value);
r = Convert.ToString(rental);



dataGridView1.Rows[newRowIndex].Cells["Date"].Value = dateTimePicker1.Value.Date.AddMonths(j).ToString();
dataGridView1.Rows[newRowIndex].Cells["Ijarah_id"].Value = txtijarahid.Text;



}
}
else if (txttenure.Text == "3")
{



for (int j = 1; j <= 36; j++)
{
int newRowIndex = dataGridView1.Rows.Add();
int z = 36;
markup = double.Parse(txtmarkup.Text);
Double a = (b / 100) * 80;
prfrate = (markup + 3.00) / 100.00;
bnkprf = (a * prfrate * 31.00) / 365.00;
rental = (a + bnkprf + 30000) / z;

z--;
string r = Convert.ToString(rental);
dataGridView1.Rows[newRowIndex].Cells["Amount"].Value = r.ToString();

a = a - Convert.ToDouble(dataGridView1.Rows[newRowIndex].Cells["Amount"].Value);
r = Convert.ToString(rental);



dataGridView1.Rows[newRowIndex].Cells["Date"].Value = dateTimePicker1.Value.Date.AddMonths(j).ToString();
dataGridView1.Rows[newRowIndex].Cells["ijarah_id"].Value = txtijarahid.Text;



}


}
}
OriginalGriff 7-Nov-12 3:32am    
OK - and what is the problem? Apart from you are duplicating a lot of code there which would be better in a method called in three places with appropriate parameters, what is the problem? Does the code you have work? Not work? Explode? :laugh:
I can't see what you are trying to do, so I can't answer!

Change this line
C#
if (txttenure.Text == "1")

to this
C#
if (int.TryParse(txttenure.Text, out b))
 
Share this answer
 
Comments
zeshanazam 7-Nov-12 3:40am    
its working but it is disturbing my installments amount per month, due to out b
adriancs 7-Nov-12 8:48am    
If it is disturbing your b, then you can make it out a or out c or out anything you like.
By this, it won't affect your b.
1. there might be error in your comparing so use string compare function, to compare values and locations.
2. use a try catch block to see if there is any error, (you are casting a lot of strings to double and float, may be some/any of them not correct order).

try this


try{
if(string.Compare (txttenure.Text, "1", true)==0)
{
}
}//end of try
catch(Excetion ex)
{ MessageBox.Show(ex.Message); }
 
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