2016-02-24 55 views
0

我使用Telerik的報告,我有一個表。 textbox16具有我需要用於查詢的值來設置textbox26上的值。每行在textbox16上都有不同的值(唯一)。Telerik報告表設置文本框的值從代碼

的問題是,在textbox26我收到了錯誤的值,所有行!

當調試我的程序textbox26_itemdatabound把正確的價值觀。

什麼我做錯了,我該如何解決?

MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["stockConnectionString"].ConnectionString); 

     private void textBox26_ItemDataBound(object sender, EventArgs e) 
     { 
      decimal balance = 0, debit = 0; 

      Telerik.Reporting.Processing.TextBox textBox = (Telerik.Reporting.Processing.TextBox)sender; 

      string text = textBox.Text; 
      textBox26.Value = text; 

      string querty = "SELECT Sum(st.Debit),comp.balance FROM statemnt st left join companie comp on st.accountcode=comp.code and comp.type=1 " + 
          "where [email protected] and (Date(st.DocDate)>=(CURDATE() - interval 30 day)) "; 

      MySqlCommand cmd = new MySqlCommand(querty, con); 

      cmd.Parameters.AddWithValue("compcode", text); 
      con.Open(); 

      MySqlDataReader Reader = cmd.ExecuteReader(); 
      if (!Reader.HasRows) 
      { 
       return; 
      } 
      while (Reader.Read()) 
      { 
       try 
       { 
        debit = Convert.ToDecimal(Reader.GetString(0)); 
       } 
       catch { debit = 0; } 
       try 
       { 
        balance = Convert.ToDecimal(Reader.GetString(1)); 
        this.textBox26.Value = balance.ToString("#.##"); 
       } 
       catch 
       { 
        balance = 0; 
       } 
      } 
      Reader.Close(); 
      con.Close(); 


      if (balance <= 0) 
      { 
       this.textBox26.Value = "0.00"; 
       this.textBox26.Value = "0.00"; 
       this.textBox26.Value = "0.00"; 
       this.textBox26.Value = "0.00"; 
       this.textBox26.Value = "0.00"; 
       return; 
      } 
      else 
      { 
       if (debit < balance) 
       { 
        balance = balance - debit; 
        this.textBox26.Value = debit.ToString("#.##"); 
       } 
      } 

     } 



     private void textBox16_ItemDataBound(object sender, EventArgs e) 
     { 
      textBox26.Value = textBox16.Value; 
     } 

結果:

Results

+0

是在textBox.text用戶輸入?爲什麼連續給textBox26分配5次值0.00? – FeliceM

+0

的textbox.text不是用戶input.The 5次有你看到的是爲5列,我將創世textbox26-31後,我管理與價值做..在textbox26我想把值我想要。 – marios

回答

0

我可以用下面的代碼來做到這一點!我將它從textBox26_ItemDataBound中移除,並將我的代碼添加到textBox16_ItemDataBound,並且它工作的很完美!

private void textBox16_ItemDataBound(object sender, EventArgs e) 
      { 
       decimal balance = 0, debit = 0; 



      Telerik.Reporting.Processing.TextBox txt = (Telerik.Reporting.Processing.TextBox)sender; 

      string text = txt.ToString(); 

      //SPLIT WARD (textBox26) TextBox[Text=-99] 
      string s = text; 
      string[] words = s.Split('='); 
      text = words[1]; 
      words = text.Split(']'); 
      text = words[0]; 


      string querty = "SELECT Sum(st.Debit),comp.balance FROM companie comp left join statemnt st on st.accountcode=comp.code and st.AccountType='DB' and comp.type=1 and (Date(st.DocDate)>=(CURDATE() - interval 30 day))" + 
          "where [email protected] "; 

      MySqlCommand cmd = new MySqlCommand(querty, con); 

      cmd.Parameters.AddWithValue("compcode", text); 
      con.Open(); 

      MySqlDataReader Reader = cmd.ExecuteReader(); 
      if (!Reader.HasRows) 
      { 
       return; 
      } 
      while (Reader.Read()) 
      { 
       try 
       { 
        debit = Convert.ToDecimal(Reader.GetString(0)); 
       } 
       catch { debit = 0; } 
       try 
       { 
        balance = Convert.ToDecimal(Reader.GetString(1)); 
        this.textBox6.Value = balance.ToString("n2"); 
       } 
       catch 
       { 
        balance = 0; 
       } 
      } 
      Reader.Close(); 



      if (balance <= 0) 
      { 
       this.textBox7.Value = "0.00"; 
       this.textBox15.Value = "0.00"; 
       this.textBox13.Value = "0.00"; 
       this.textBox26.Value = "0.00"; 
       //textbox6 
       con.Close(); 
       return; 

      } 
      else 
      { 
       if (debit < balance) 
       { 
        balance = balance - debit; 
        if (debit == 0) 
        { 
         this.textBox7.Value = "0.00"; 
        } 
        else 
        { 
         this.textBox7.Value = debit.ToString("n2"); 
        } 
       } 
       else 
       { 
        this.textBox7.Value = balance.ToString("n2"); 
        this.textBox15.Value = "0.00"; 
        this.textBox13.Value = "0.00"; 
        this.textBox26.Value = "0.00"; 
        con.Close(); 
        return; 
       } 
       querty = " SELECT Sum(st.Debit) FROM companie comp left join statemnt st on st.accountcode=comp.code and st.AccountType='DB' and comp.type=1 and Date(st.DocDate)<=(CURDATE() - interval 31 day) and (Date(st.DocDate)>=(CURDATE() - interval 60 day)) " + 
           "where [email protected] "; 

       cmd = new MySqlCommand(querty, con); 

       cmd.Parameters.AddWithValue("compcode", text); 
       try 
       {//string x=cmd.ExecuteScalar().ToString(); 
       debit = Convert.ToDecimal(cmd.ExecuteScalar()); 
       } 
       catch { debit = 0; } 

       if (debit < balance) 
       { 
        this.textBox15.Value = debit.ToString("n2"); 
        balance = balance - debit; 
       } 
       else 
       { 
        this.textBox15.Value = balance.ToString("n2"); 
        this.textBox13.Value = "0.00"; 
        this.textBox26.Value = "0.00"; 
        con.Close(); 
        return; 

       } 
       querty = " SELECT Sum(st.Debit) FROM companie comp left join statemnt st on st.accountcode=comp.code and st.AccountType='DB' and comp.type=1 and Date(st.DocDate)<=(CURDATE() - interval 61 day) and (Date(st.DocDate)>=(CURDATE() - interval 90 day))" + 
           "where [email protected] "; 

       cmd = new MySqlCommand(querty, con); 

       cmd.Parameters.AddWithValue("compcode", text); 

       try 
       { 
        debit = Convert.ToDecimal(cmd.ExecuteScalar()); 
       } 
       catch 
       { 
        debit = 0; 
       } 
       if (debit < balance) 
       { 
        this.textBox13.Value = debit.ToString("n2"); 
        balance = balance - debit; 
        this.textBox26.Value = balance.ToString("n2"); 
        con.Close(); 

       } 
       else 
       { 
        this.textBox13.Value = balance.ToString("n2"); 
        this.textBox26.Value = "0.00"; 
        con.Close(); 
        return; 
       } 




      }