首页 新闻 会员 周边 捐助

根据用户输入动态生成多个由SQLServer查询出的DataGridview并对其进行事件定义以实现更新

0
悬赏园豆:140 [已关闭问题] 关闭于 2012-11-30 14:03

大哥们我的Winform的DataGridview的数据源是数据库连接得到的,你帮小的看看这个怎么定义动态生成的DataGridview进行“数据修改操作”的事件呗。不胜感激啊!
简单的说下自己的具体编码实现功能吧:
1.根据用户输入的一个方程,解析出来其自变量如:x1,x2
2.在DataGridView1中定义每个变量的分布类型,

x1 正态分布

x2 对数正态分布

定义完毕后便是下面的代码,上面的功能小的已经实现了;
3.下面的代码是对各个变量在服从相应分布类型时所需要的参数信息,比如正态分布需要均值和方差;之所以选择动态生成自变量数个datagridview是因为各分布类型的参数个数和名称并不完全相同。
4.每个分布类型(如正态分布,对数正态分布)都在数据库中初建一个数据表。
[code=csharp]
        private void button2_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView1.Rows.Count;i++ )
            {
                 
                DataGridView dgv = new DataGridView();
                Button btn=new Button();
                dgv.Parent = panel1;
                btn.Parent = panel1;
                dgv.Top = 5 + 100 * i;
                dgv.Left = 5;
                int w = Screen.PrimaryScreen.Bounds.Width;
                dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                dgv.Width = w;
                dgv.Height = 60;
                btn.Top = dgv.Bottom + 5;
                btn.Left = 5;
                btn.Width =75;
                btn.Height = 23;
                btn.Text="刷新参数";
 
                string strcon = "";
                string strcon1 = "";
                string varname=dataGridView1.Rows[i].Cells[0].Value.ToString();
                string varDisType = dataGridView1.Rows[i].Cells[1].Value.ToString();
                switch(varDisType)
                {
                    case "正态分布"://normal shape scale
                    strcon = "truncate table NormalDistribution; insert into NormalDistribution (name) values('" + varname + "')";
                    strcon1 = "select name as N'变量名' , shapePara as '均值(μ)' , scalePara as N'标准差(σ)' from NormalDistribution";
                    break;
                case "对数正态分布"://lognormal shape scale
                     
                    strcon = "truncate table LognormalDistribution; insert into LognormalDistribution (name) values('" + varname + "')";
                    strcon1 = "select name as N'变量名' , shapePara as '均值(μ)' , scalePara as N'标准差(σ)' from LognormalDistribution";
                    break;
                case "威布尔分布"://weibull shape scale
                     
                    strcon = "truncate table WeibullDistribution; insert into WeibullDistribution (name) values('" + varname + "')";
                    strcon1 = "select name as N'变量名' , shapePara as N'形状参数(k)' , scalePara as N'尺度参数(λ)' from WeibullDistribution";
                    break;
                case "伽马分布"://gamma shape scale
                     
                    strcon = "truncate table GammaDistribution; insert into GammaDistribution (name) values('" + varname + "')";
                    strcon1 = "select name as N'变量名' , shapePara as N'阿尔法(α)' , scalePara as N'贝塔(β)' from GammaDistribution";
                    break;
                case "贝塔分布"://beta alpha beta
                     
                    strcon = "truncate table BetaDistribution; insert into BetaDistribution (name) values('" + varname + "')";
                    strcon1 = "select name as N'变量名' , alpha as N'阿尔法(α)' , beta as N'贝塔(β)' from BetaDistribution";
                    break;
                case "连续型均匀分布"://uniform a b
                     
                    strcon = "truncate table UniformDistribution; insert into UniformDistribution (name) values('" + varname + "')";
                    strcon1 = "select name as N'变量名' , a as N'区间下限(a)' , b as N'区间上限(b)' from UniformDistribution";
                    break;
                case "三角分布"://triangular a b c
                     
                    strcon = "truncate table TriangularDistribution; insert into TriangularDistribution (name) values('" + varname + "')";
                    strcon1 = "select name as N'变量名' , a as N'低限(a)' , b as N'上限(b)' ,c as N'众数(c)' from TriangularDistribution";
                    break;
                case "X2分布"://X2 x2para
                     
                    strcon = "truncate table X2Distribution; insert into X2Distribution (name) values('" + varname + "')";
                    strcon1 = "select name as N'变量名' , x2para as N'自由度(k)'  from X2Distribution";
                    break;
                case "指数分布"://exponential ratePara
 
                    strcon = "truncate table ExponentialDistribution; insert into ExponentialDistribution (name) values('" + varname + "')";
                    strcon1 = "select name as N'变量名' , ratePara as N'率参数(λ)' from ExponentialDistribution";
                    break;
                }
                SqlHelper.ExecuteNonQuery(strcon);
                DataTable dt = SqlHelper.getDataTable(strcon1);
                dgv.DataSource = dt;
            }
        }
[/code]

老付的主页 老付 | 初学一级 | 园豆:69
提问于:2012-11-26 14:56
< >
分享
所有回答(1)
0

你要做什么?

az235 | 园豆:8483 (大侠五级) | 2012-11-27 14:10

做一个动态的用户输入界面,因为动态生成的控件的属性都是由用户的输入而变化的,我在想是不是可以用控件传值来实现~~应该是可以的吧??

支持(0) 反对(0) 老付 | 园豆:69 (初学一级) | 2012-11-27 14:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册