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: ...
随机推荐
- Flume环境部署和配置详解及案例大全
flume是一个分布式.可靠.和高可用的海量日志采集.聚合和传输的系统.支持在日志系统中定制各类数据发送方,用于收集数据;同时,Flume提供对数据进行简单处理,并写到各种数据接受方(比如文本.HDF ...
- UVa 12325 Zombie's Treasure Chest【暴力】
题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 #include<iostream> #inclu ...
- PHP全栈工程师学习大纲
一.高性能网站开发功力提升 时间 标题 内容概要 2015-12-28 开学典礼以及工程师成长路线图 工程师成长的发展路径图.三个阶段,在各个阶段需要提升自己的地方,从技术上也讲了一些提高分析代码的工 ...
- mysql 调用带返回值的存储过程
存储过程: create procedure proc_t(out uname varchar(50),out upwd varchar(50),in uid int) BEGIN select na ...
- volley(2) 参数code : or_barcode, pr_ismsd:false , method:GET
1. 来自于WHCombineBatchFragment.java /** * 当编辑框里面的内容完成的时候,自动的,同时获取服务器的批量数 */private void barcodeEnterEv ...
- [原创] - C#编程大幅提高OUTLOOK的邮件搜索能力!
使用OUTLOOK, 你有没有遇到过上图的问题? 多达18419封邮件! 太多了, 每次想找一个邮件都非常耗时, 想办法解决这个问题成了一件非常紧迫的事情. 利用MS Search当然可以, 但是它太 ...
- ApplicationContext.xml 的最终xml声明,包括注解 aop
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 每天一个Linux命令(2): ls
ls命令是linux下最常用的命令.ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...
- Heritrix源码分析(九) Heritrix的二次抓取以及如何让Heritrix抓取你不想抓取的URL
本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/644396 本博客已迁移到本人独立博客: http://www.yun5u ...
- T-SQL备忘(4):分页
set statistics io on set statistics time on --SQL Server 2012分页方式 select * from Production.Product o ...