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: ...
随机推荐
- CodeForces Round #250 Div2
A. The Child and Homework 注意仔细读题,WA了好多次,=_= #include <cstdio> #include <cstring> #includ ...
- 漫游Kafka设计篇之消息传输的事务定义
之前讨论了consumer和producer是怎么工作的,现在来讨论一下数据传输方面.数据传输的事务定义通常有以下三种级别: 最多一次: 消息不会被重复发送,最多被传输一次,但也有可能一次不传输. 最 ...
- Hide/Show running Console
http://stackoverflow.com/questions/3571627/show-hide-the-console-window-of-a-c-sharp-console-applica ...
- context-param引发spring容器以及servlet容器的关联
转自:http://blog.csdn.net/liaoxiaohua1981/article/details/6759206 格式定义: [html] view plaincopy <cont ...
- Java中String为什么是final
final概念: 如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父亲被继承.因此,一个类不能既被声明为abstract,又被声明为final. 将变量或方法声明为final,可以 ...
- 查看MySQL的警告信息
在王MySQL数据库导入数据的时候经常会出现警告,这些警告很容易被忽视,今天到数据的时候突然想看看警告的内容是什么,百度了一下mysql查看警告的命令 show warnings; 命令很简明,一查看 ...
- JQuery开发之Galleriffic图片插件介绍
Galleriffic是一个用于创建快速展示相册中照片的jQuery插件.从图一中可以看成,图片既可以以幻灯片的方式查看,也可以手动点击缩略图查看.Galleriffic还支持分页,从而使得它能够展示 ...
- 用 Javascript 获取页面大小、窗口大小和滚动条位置
页面大小.窗口大小和滚动条位置这三个数值在不同的浏览器例如 Firefox 和 IE 中有着不同的实现.即使在同一种浏览器例如 IE 中,不同版本也有不同的实现. 本文给出两个能兼容目前所有浏览器的 ...
- struts2 action 返回图片流
数据库为mssql zp字段为image类型 java代码 OutputStream out = null; try { String contenttype = "image/jpeg&q ...
- LINUX下的tty,console与串口分析
1.LINUX下TTY.CONSOLE.串口之间是怎样的层次关系?具体的函数接口是怎样的?串口是如何被调用的? 2.printk函数是把信息发送到控制台上吧?如何让PRINTK把信息通过串口送出?或者 ...