时间:2021-07-01 10:21:17 帮助过:42人阅读
大哥们我的Winform的DataGridview的数据源是数据库连接得到的,你帮小的看看这个怎么定义动态生成的DataGridview进行数据修改操作的事件呗。不胜感激啊! 简单的说下自己的具体编码实现功能吧: 1.根据用户输入的一个方程,解析出来其自变量如:x1,x2 2.在Da
大哥们我的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]