Click here to Skip to main content
12,630,137 members (26,279 online)
Rate this:
 
Please Sign up or sign in to vote.
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 6-Nov-12 21:55pm
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!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Change this line
if (txttenure.Text == "1")
to this
if (int.TryParse(txttenure.Text, out b))
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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); }
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100