收集和显示收集的数据 [英] Gathering and Displaying Gathered Data

查看:84
本文介绍了收集和显示收集的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建议需要收集数据.  该数据将由电缆和变压器阻抗(代表电阻和电感的复数)组成.当我在系统模型中添加一段电缆或变压器时, 显示它.

I propose a need to gather data.  That data will be comprised of cable and transformer impedances (complex numbers representing resistance and inductance).  When I add a length of cable or a transformer to the model of the system, I will want to display it.

因此,我提出了两种操作模式.首先,我提供了具有每单位长度阻抗的电缆类型列表,并在下拉"菜单中提供了标准变压器输入.盒子.  在第二个步骤中,我添加了已输入的电缆,然后 它的特定名称到另一个下拉框.我有第三个用于变压器的下拉框,名称如下.我希望能够允许用户调用旧数据并进行修改或删除.  该怎么做?  是否有示例?

I therefore propose two modes of operation.  In the first, I offer a list of cable types with impedances per unit length, and a standard transformer input in a "drop down" box.  In the second, I add the cable that has been entered and its specific name TO another drop down box.  I have a third drop down box for transformers, with the names.  I would like to be able to allow the user to call up old data and modify or delete it.  How do I do that?  Is there an example?

推荐答案

您将使用数据库.让我用Entity Framework和C#作一个简单的例子.

You will use a database. Let me make a quick example with Entity Framework and C#.

首先定义我们的模型实体类:

First define our model entity classes: 

public class Cable

{

public int ID {get; set;}

public int Id {get;set;}

公共字符串CableName {get ; set;}

public string CableName {get;set;}

public 电缆长度 {get; set;}

public CableLength CableLength{get;set;}

}

公共类CableLength

public class CableLength

{

public int Length {get; set;} 公共 阻抗{get; set;}//我不确定哪种类型的阻抗值

}

public class Transformer

public class Transformer

{

public int ID {get ; set;}

public int Id {get;set;}

公共字符串名称{get; set;}

public string Name {get;set;}

public

public Impedance Impedance {get;set;}

}

公共类阻抗

{

public int ID {get; set;}

public int Id {get;set;}

public int Resistance {get;set;}

public int Inductance {get;set;}

}

//实体框架数据库上下文

// Entity Framework Database Context

公共类Context:DbContext

public class Context:DbContext

{

}

现在您需要为数据库创建CRUD方法,我将仅创建read方法,您可以自己尝试其余的方法.

Now you need to make CRUD methods for database, I will just make read method, you can try the rest on your own.

public List<Cable> GetCables()

{

       List<Cable> cables;

	  (using db = new Context())

	{

		cables = db.Cables.ToList(); 

	}

	return cables;

}

public GetTransformer(int ImpedanceId)

{

        List<Transformer> transformers;

 	 (using db = new Context())

	{

		transformers= db.Transformer.Where(x=>x.Impedance.Id == ImpedanceId).ToList();

	}

	return transformers;

}

现在我们需要填充Dropdownlist,但这属于Asp.NET,在winforms中有Combobox.如果您有Asp.NET问题,可以在 forums.asp.net

Now we need to populate Dropdownlist, however this belongs to Asp.NET, in winforms there is Combobox. If you have an Asp.NET question, you can ask it on forums.asp.net

另外,我们需要模型和查询方法,我们需要调用这些方法来填充组合框.

After we have the model and query methods what we need to do is calling those methods to populate our comboboxes. 

comboBox1.DataSource = GetCables();

//下一个组合是关于变形器的,我以两个组合为例,您可以对其进行扩展.

// the next combo is about transformers, I am making two combos for the example, you can extend it.

//您需要添加一个combobox1选定的索引更改事件

// You need to add a combobox1 selected index changed event

//,在该操作中,您需要设置combobox2的值

// in that action you need to set the values of combobox2

private void comboBox1_SelectedIndexChanged(对象发送者,EventArgs e)
{

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

combobox2.Clear();

combobox2.Clear();

//读取combox1的值并从数据库中获取变压器的值

// read the value of combox1 and get values for transformers from the database

变量转换器= GetTransformers(comboBox1.SelectedItem);

var transformers = GetTransformers(comboBox1.SelectedItem);

foreach(var item in transformers)

combobox2.Items.Add(item.Name);

}

}

这是简化的迷你版本,我没有测试过,可能会有错误,但是它基本上说明了如何获得所需的东西.希望对您有帮助.

This is a simplified mini version and I have not tested it and there can be errors but it basically shows how you can get what you need. I hope it helps.


这篇关于收集和显示收集的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆