【问题标题】:Telerik Reporting Table Set Textbox Value From CodeTelerik 报告表从代码中设置文本框值
【发布时间】:2016-02-24 14:54:06
【问题描述】:

我正在使用 Telerik 报告,并且我有一张桌子。 textbox16 具有我需要在查询中使用的值来设置 textbox26 上的值。每行在 textbox16 (unique) 上都有不同的值。

问题是在 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   st.accountcode=@compcode 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;
        }

结果:

【问题讨论】:

  • textBox.text 是用户输入吗?为什么要连续 5 次将值 0.00 分配给 textBox26?
  • textbox.text 不是用户输入。您看到的 5 次是针对 5 列,在我设法使用 textbox26 上的值执行此操作后,我将创建 textbox26-31我想输入我想要的值。

标签: c# textbox telerik report telerik-reporting


【解决方案1】:

我可以用下面的代码做到这一点!我从 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   comp.code=@compcode ";

            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   comp.code=@compcode ";

                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   comp.code=@compcode   ";

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




            }

【讨论】:

    猜你喜欢
    • 2020-04-10
    • 1970-01-01
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2016-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多