Click here to Skip to main content
Sign Up to vote bad
good
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 - 20:55

Comments
deepak.m.shrma - 7 Nov '12 - 3:06
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:07
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:17
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:18
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:32
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!

2 solutions

Change this line
if (txttenure.Text == "1")
to this
if (int.TryParse(txttenure.Text, out b))
  Permalink  
Comments
zeshanazam - 7 Nov '12 - 3:40
its working but it is disturbing my installments amount per month, due to out b
adriancs - 7 Nov '12 - 8:48
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); }
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 208
1 Maciej Los 156
2 Richard MacCutchan 145
3 Tadit Dash 140
4 Santhosh G_ 135
0 Sergey Alexandrovich Kryukov 10,264
1 OriginalGriff 7,957
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,155


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid