winform 映射字段的写法:
public partial class FrmFieldMapping : DevComponents.DotNetBar.Office2007Form
{
private AMDataFieldCollection linkEntryFields; string linkCategoryId;
AMCategory[] categorys;
/// <summary>
/// 当前的分类
/// </summary>
string currCategoryId;
///// <summary>
///// 数据库里面读取过来的集合
///// </summary>
List<AMLinkFieldItem> LstLinkDataGridViewFieldItem = new List<AMLinkFieldItem>();
/// <summary>
/// 存储序列化信息的类
/// </summary>
AMBusinessLinkArchival currLink = new AMBusinessLinkArchival();
public FrmFieldMapping()
{
if (currLink == null)
{
currLink.LinkCategoryId = string.Empty;
currLink.LstLinkFieldItem = new List<AMLinkFieldItem>();
}
InitializeComponent();
this.dataGridView.AllowUserToResizeRows = false;
//防止出现 datagridviewcomboboxcell 值无效 这个错误
this.dataGridView.DataError += delegate(object sender, DataGridViewDataErrorEventArgs e) { };
//控件事件
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
this.cbxCategory.SelectedIndexChanged += new EventHandler(cbxCategory_SelectedIndexChanged);
this.dataGridView.CellEnter += dataGridView_CellEnter; //下拉框数据
this.categorys = ApplicationEx.ClientInterface.ListCategories();
List<ComboxItem> lstComboItem = new List<ComboxItem>();
for (int i = ; i < this.categorys.Length; i++)
{
ComboxItem item = new ComboxItem();
item.ItemText = this.categorys[i].CategoryId + "." + this.categorys[i].Name;
item.ItemValue = this.categorys[i].CategoryId;
lstComboItem.Add(item);
} this.cbxCategory.Items.Clear();
this.cbxCategory.Items.AddRange(lstComboItem.ToArray());
this.cbxCategory.DisplayMember = "ItemText";
this.cbxCategory.ValueMember = "ItemValue"; string[,] arryFields = new string[,]
{
{ "string", "DJH", "地籍号" },
{ "string", "TDQLR", "土地权利人" },
{ "string", "ZJMC", "证件名称" },
{ "string", "ZJHM", "证件号码" },
{ "string", "ZSH", "土地证号" },
{ "string", "ZDH", "宗地号" },
{ "string", "DJFZSJ", "登记发证时间" },
{ "string", "SYQMJ", "使用权面积"},
{ "string", "QSXZ", "权利性质" },
{ "string", "SYQLX", "使用权类型"},
{ "string", "SYQX", "使用期限" },
{ "string", "TDYT", "土地用途" },
{ "string", "TDDJ", "土地等级" },
{ "string", "JZZDMJ", "建筑占地面积" },
{ "string", "DZSYMJ", "独自使用面积"},
{ "string", "QTSX", "其他事项"},
{ "string", "BZ", "备注" },
{ "string", "TDZL", "土地坐落"},
{ "string", "TDMJ", "土地面积" },
}; for (int k = ; k < arryFields.GetLength(); k++)
{
AMLinkFieldItem fieldItem = new AMLinkFieldItem();
for (int j = ; j < arryFields.GetLength(); j++)
{
if (j == )
{
fieldItem.BusinessFiledDateType = arryFields[k, j];
}
else if (j == )
{
fieldItem.BusinessFiledName = arryFields[k, j];
}
else if (j == )
{
fieldItem.BusinessFiledCaption = arryFields[k, j];
}
}
LstLinkDataGridViewFieldItem.Add(fieldItem);
} //前两列数据绑定
foreach (AMLinkFieldItem field in LstLinkDataGridViewFieldItem)
{
DataGridViewRow dgvRow = this.dataGridView.Rows[this.dataGridView.Rows.Add()];
dgvRow.Cells[DateType.Index].Value = field.BusinessFiledDateType;
dgvRow.Cells[currFieldName.Index].Value = field.BusinessFiledName;
dgvRow.Cells[currCategoryField.Index].Value = field.BusinessFiledCaption;
//事先设定好行的tag
dgvRow.Tag = field;
} //从数据库加载列表集合
string queryKey = string.Format("FrmFieldMapping").ToUpper();
string favoritesKeyValue = ApplicationEx.ConnectionInterface.GetPropertyValue(queryKey);
currLink = ApplicationEx.DeserializeToObject(Convert.FromBase64String(favoritesKeyValue)) as AMBusinessLinkArchival; if(currLink!=null&&currLink.LinkCategoryId!=null)
{
//绑定类别的下拉表
for (int i = ; i < cbxCategory.Items.Count; i++)
{
if ((cbxCategory.Items[i] as ComboxItem).ItemValue.ToString() == currLink.LinkCategoryId)
{
cbxCategory.SelectedItem = cbxCategory.Items[i];
break;
}
}
}
} void dataGridView_CellEnter(object sender, DataGridViewCellEventArgs e)
{
//实现单击一次显示下拉列表框
if (dataGridView.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn && e.RowIndex != -)
{
SendKeys.Send("{F4}");
}
} /// <summary>
/// 点击类别列表的时候切换关联信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void cbxCategory_SelectedIndexChanged(object sender, EventArgs e)
{
this.linkCategoryId = ((this.cbxCategory.SelectedItem as ComboxItem).ItemValue as string);
this.linkEntryFields = ApplicationEx.ClientInterface.ListDataFields(this.linkCategoryId); BuildMapFieldListCBX(); this.dataGridView.Focus();
currCategoryId = linkCategoryId;
//如果数据库有信息就加载数据库的
if (currLink!=null&&currLink.LinkCategoryId == currCategoryId)
{
foreach (DataGridViewRow dgvRow in this.dataGridView.Rows)
{
foreach (AMLinkFieldItem comboxField in currLink.LstLinkFieldItem)
{
if (comboxField.BusinessFiledName == dgvRow.Cells[currFieldName.Index].Value.ToString())
{
if (this.linkEntryFields.Contains(comboxField.LinkArchivalFiledName))
{
dgvRow.Cells[cmbLinkField.Index].Value = this.linkEntryFields[comboxField.LinkArchivalFiledName];
}
break;
}
}
}
}
else
{
//如果数据库没有信息就加载默认的匹配讯息
foreach (DataGridViewRow dgvRow in this.dataGridView.Rows)
{
//遍历行然后转换每一行的tag成为AMLinkFieldItem类
AMLinkFieldItem linkItem = dgvRow.Tag as AMLinkFieldItem;
/*然后循环AMDataField找到和AMLinkFieldItem里面的caption显示名称一样的类,然后再赋值给当前行的下拉表的默认值,如果没有的话就制空该行的下拉框
*保证把每行的下拉列表的默认值做一个初始化设置默认值的操作,
*关键字:下拉列表绑定类:AMDataField dagairidview绑定类:AMLinkFieldItem 比较对象:caption
*/
foreach (AMDataField field in this.linkEntryFields)
{
if (field.Caption == linkItem.BusinessFiledCaption)
{
dgvRow.Cells[this.cmbLinkField.Index].Value = field;
break;
}
else
{
dgvRow.Cells[this.cmbLinkField.Index].Value = null;
}
}
} }
} /// <summary>
/// 构造gridview下拉框的数据
/// </summary>
void BuildMapFieldListCBX()
{
Dictionary<string, string> dicComboxItems = new Dictionary<string, string>();
List<ComboxItem> test = new List<ComboxItem>(); cmbLinkField.Items.Clear();
List<ComboxItem> lstComboItem = new List<ComboxItem>();
ComboxItem item = new ComboxItem();
//空格选项
item.ItemText ="";
item.ItemValue = "";
lstComboItem.Add(item);
for (int i = ; i < this.linkEntryFields.Count; i++)
{
item = new ComboxItem();
item.ItemText = this.linkEntryFields[i].Caption;
item.ItemValue = this.linkEntryFields[i];
lstComboItem.Add(item);
}
cmbLinkField.Items.AddRange(lstComboItem.ToArray());
cmbLinkField.DisplayMember = "ItemText";
cmbLinkField.ValueMember = "ItemValue";
} public class ComboxItem
{
private string itemText; public string ItemText
{
get { return itemText; }
set { itemText = value; }
}
private Object itemValue; public Object ItemValue
{
get { return itemValue; }
set { itemValue = value; }
}
public override string ToString()
{
return this.ItemText;
} }
/// <summary>
/// 建立关联信息并且放入数据库
/// </summary>
void BuildLinkCondition()
{
try
{
//初始化集合
if(currLink!=null)
{
currLink.LstLinkFieldItem.Clear();
}
int index = ;
List<AMLinkFieldItem> LstLinkFieldItem = new List<AMLinkFieldItem>();
foreach (DataGridViewRow dgvRow in this.dataGridView.Rows)
{
if (!string.IsNullOrEmpty(dgvRow.Cells[DateType.Index].Value.ToString()))
{
//加载的时候自动匹配的数据
if (dgvRow.Cells[cmbLinkField.Index].Value != null)
{
AMLinkFieldItem fieldItems = new AMLinkFieldItem();
fieldItems.BusinessFiledDateType = dgvRow.Cells[DateType.Index].Value.ToString();
fieldItems.BusinessFiledName = dgvRow.Cells[currFieldName.Index].Value.ToString();
fieldItems.BusinessFiledCaption = dgvRow.Cells[currCategoryField.Index].Value.ToString();
fieldItems.LinkArchivalFiledName = (dgvRow.Cells[cmbLinkField.Index].Value as AMDataField).Name;
LstLinkFieldItem.Add(fieldItems);
}
}
index++;
}
//构造信息的类并且加入数据库
AMBusinessLinkArchival currSaveLink = new AMBusinessLinkArchival();
currSaveLink.LinkCategoryId = currCategoryId;
currSaveLink.LstLinkFieldItem = LstLinkFieldItem;
//序列化并且调用加入数据库的方法存入属性表
string queryKey = string.Format("FrmFieldMapping").ToUpper();
string queryKeyValue = string.Empty;
queryKeyValue = Convert.ToBase64String(ApplicationEx.SerializerToByte(currSaveLink));
ApplicationEx.ConnectionInterface.SetPropertyValue(queryKey, queryKeyValue);
//最后关闭窗体
this.Close();
}
catch (Exception ex)
{
ApplicationEx.ShowErrorMessageBox(this, ex);
}
} private void btnOk_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.linkCategoryId))
{
ApplicationEx.ShowMessageBox(this, "关联分类为空,请选择!");
return;
}
BuildLinkCondition();
} private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
//清空记录
for (int j = ; j < dataGridView.Rows.Count; j++)
{
this.dataGridView.Rows[j].Cells[cmbLinkField.Index].Value = null;
}
}
}
注:ApplicationEx.ConnectionInterface.Set/Get PropertyValue 为数据库的处理方法
winform 映射字段的写法:的更多相关文章
- mybatis-plus忽略映射字段
mybatis-plus使用对象属性进行SQL操作,经常会出现对象属性非表字段的情况,忽略映射字段使用以下注解: @TableField(exist = false):表示该属性不为数据库表字段,但又 ...
- MyBatisPlus忽略映射字段注解
MyBatisPlus忽略映射字段注解 @TableField(exist = false):表示该属性不为数据库表字段,但又是必须使用的. @TableField(exist = true):表示该 ...
- Mybatis配置——自动使用驼峰命名 属性映射字段(默认为false)
开发一个新项目,用的springboot,相关配置不太熟悉,导致一些配置没配,到具体开发时问题就暴露出来了,记录第一个配置问题----Mybatis配置-自动使用驼峰命名 属性(userId)映射字段 ...
- sqlmap映射继承机制及映射字段顺序与SQL查询字段顺序无关
<typeAlias alias="TblSpPartsinfo" type="com.bn.car.biz.supply.dao.po.PartsInfoPO&q ...
- Hibernate 映射字段问题[ImprovedNamingStrategy]
Hibernate 使用JPA 对于映射有3种规则能够配置:DefaultNamingStrategy,ImprovedNamingStrategy,EJB3NamingStrategy 这里仅仅说I ...
- ServiceStack.Ormlit sqlserver枚举类型映射字段类型为varchar
请当枚举类型上面加上[Flags]特性就可以了.
- mybatis---属性和字段映射
1. 查询时使用别名,别名和属性名保持一致 <select id="getUser" parameterType="int" resultType=&qu ...
- Hibernatel框架关联映射
Hibernatel框架关联映射 Hibernate程序执行流程: 1.集合映射 需求:网络购物时,用户购买商品,填写地址 每个用户会有不确定的地址数目,或者只有一个或者有很多.这个时候不能把每条地址 ...
- Hibernate之关联映射(一对多和多对一映射,多对多映射)
~~~接着之前的Hibernate框架接着学习(上篇面试过后发现真的需要学习以下框架了,不然又被忽悠让去培训.)~~~ 1:Hibernate的关联映射,存在一对多和多对一映射,多对多映射: 1.1: ...
随机推荐
- Nginx安全配置
nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端.nginx一般是把请求发fastcgi管理进程处理,fastcgi管 ...
- 如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)?
Java time JavaScript Math.round(new Date().getTime()/1000) 之所以除以1000是因为getTime()返回数值的单位是毫秒 Microsoft ...
- C++实现日期类(Date类)
#include<iostream>using namespace std;class Date{public: Date(int year = 1900, int month = ...
- App开放接口api安全性—Token签名sign的设计与实现
前言 在app开放接口api的设计中,避免不了的就是安全性问题,因为大多数接口涉及到用户的个人信息以及一些敏感的数据,所以对这些接口需要进行身份的认证,那么这就需要用户提供一些信息,比如用户名密码等, ...
- HDU 5348 MZL's endless loop 给边定向(欧拉回路,最大流)
题意: 给一个所有你可能想得到的奇葩无向图,要求给每条边定向,使得每个点的入度与出度之差不超过1.输出1表示定向往右,输出0表示定向往左. 思路: 网络流也是可以解决的!!应该挺简单理解的.但是由于复 ...
- acdream 1683 村民的怪癖(KMP,经典变形)
Problem Description 娜娜费劲九牛二虎之力终于把糖果吃完了(说好的吃不完呢?骗人,口亨~),于是,缘溪行,忘路之远近.忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷,娜娜甚异之 ...
- (六)6.4 Neurons Networks Autoencoders and Sparsity
BP算法是适合监督学习的,因为要计算损失函数,计算时y值又是必不可少的,现在假设有一系列的无标签train data: ,其中 ,autoencoders是一种无监督学习算法,它使用了本身作为标签以 ...
- MySQL与Oracle 差异比较之二基本语法
基本语法 编号 类别 ORACLE MYSQL 注释 1 变量的声明方式不同 li_index NUMBER := 0 DECLARE li_index INTEGER DEFAULT 0 1. my ...
- 嵌入式 十个最值得阅读学习的C开源项目代码
开源世界有许多优秀的开源项目,我选取其中十个最优秀的.最轻量级的C语言的项目,希望可以为C语言开发人员提供参考. 十个最值得阅读学习的C开源项目代码 1. Webbench 2. Tinyhttpd ...
- 【原创】Linux下编译链接中常见问题总结
前言 一直以来对Linux下编译链接产生的问题没有好好重视起来,出现问题就度娘一下,很多时候的确是在搜索帮助下解决了BUG,但由于对原因不求甚解,没有细细研究,结果总是在遇到在BUG时弄得手忙脚乱得. ...