@TOC


前言

刚进公司,需要学开发需要的新框架及现成框架,完成自己的需求。那么在此期间,碰到好的代码就要收集起来,【(一个Form页面有个控件要显示奇怪的内容,比如显示12-1、13-1,但是存到数据库的又得是12、13…,存到数据库的内容对应6个比特位,存到内存的又得是这六个比特位的值,你还得保证存到数据库的值和存到内存的比特位组合一致】,总结一下,以供后面参考学习,查看。肯定大家都有一定差异啦,大家作为参考哦,与诸君共勉。

芯片开发流程,前情回顾

一、需求:(一个Form页面需要显示一个值,通过需要分析,咱们能通过下拉框Combox展示这个值,以供用户选择并查看这个值

1.需求进一步梳理:需求给的是二进制的与十进制的对应关系,000000对应11、000010对应12(模式1)、001000对应12(模式2)、001010对应13(模式1)、001011对应12(模式2)、…101010对应16(模式1)、111011对应16(模式2),确定,二进制和十进制数是一一对应的,然后,开始:

2.再页面上定义控件,比如你可以创建Form、UserController等,在上面玩呗

1
2
3
4
5
6
7
8
9
10
11
12
13
...
//ComboBox_GrayDepth
//
// label_GrayScale50
//
this.label_GrayScale50.AutoEllipsis = true;
this.label_GrayScale50.Location = new System.Drawing.Point(6, 46);
this.label_GrayScale50.Name = "label_GrayScale50";
this.label_GrayScale50.Size = new System.Drawing.Size(95, 20);
this.label_GrayScale50.TabIndex = 230;
this.label_GrayScale50.Text = "灰度级数:";
this.label_GrayScale50.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
...

3.然后就是后端的实现一:把控件的值存下去到内存中、到数据库中、到容器中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//封装一个容器
class GrayDepthPair
{
public string valuemember { get; set; }
public string namemember { get; set; }
}

//初始化,可以放在页面类的构造器或者_load方法中
private void InitGrayDepth()
{
//绑定试题类和控件的属性
ComboBox_GrayDepth.ValueMember = "valuemember";
ComboBox_GrayDepth.DisplayMember = "namemember";

//key对应Combox空间要显示的值
//value对应要存到内存的6个比特位组合对应的十进制数
List<GrayDepthPair> lstDataSource = new List<GrayDepthPair>();
lstDataSource.Add(new GrayDepthPair() { namemember = "11", valuemember = "2" });
lstDataSource.Add(new GrayDepthPair() { namemember = "12-1", valuemember = "16" });
lstDataSource.Add(new GrayDepthPair() { namemember = "12-2", valuemember = "1" });
lstDataSource.Add(new GrayDepthPair() { namemember = "13-1", valuemember = "32" });
...
lstDataSource.Add(new GrayDepthPair() { namemember = "13-2", valuemember = "17" });
lstDataSource.Add(new GrayDepthPair() { namemember = "13-3", valuemember = "2" });
lstDataSource.Add(new GrayDepthPair() { namemember = "14-1", lstDataSource.Add(new GrayDepthPair() { namemember = "16-3", valuemember = "20" });

ComboBox_GrayDepth.DataSource = lstDataSource;
//给控件一个默认值,非必需
ComboBox_GrayDepth.SelectedValue = "32";
}

//存到数据库中
...
_scanBdProperty.GrayDepth = Convert.ToByte(ComboBox_GrayDepth.Text.Split('-')[0]);
...

//存到内存中
...
(_scanBdProperty.ChipPropey as ChipRT5977RGBVExtendProperty).GrayDepth = Convert.ToByte(ComboBox_GrayDepth.SelectedValue);
...

//整体封装方法如下:
private void SaveGrayDepth()
{
if (!_bInitControl && _scanBdProperty == null) return;

if (ComboBox_GrayDepth.SelectedIndex != -1)
{
_scanBdProperty.GrayDepth = Convert.ToByte(ComboBox_GrayDepth.Text.Split('-')[0]);
//byte gratDepth = _scanBdProperty.GrayDepth;
(_scanBdProperty.ChipPropey as ChipRT5977RGBVExtendProperty).GrayDepth = Convert.ToByte(ComboBox_GrayDepth.SelectedValue);
}
}


巨人的肩膀

  • 周志明老师的凤凰架构
  • C#高级编程
  • C#函数式编程
  • 叩响C#之门
  • 组内各位前辈的指导