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 映射字段的写法:的更多相关文章

  1. mybatis-plus忽略映射字段

    mybatis-plus使用对象属性进行SQL操作,经常会出现对象属性非表字段的情况,忽略映射字段使用以下注解: @TableField(exist = false):表示该属性不为数据库表字段,但又 ...

  2. MyBatisPlus忽略映射字段注解

    MyBatisPlus忽略映射字段注解 @TableField(exist = false):表示该属性不为数据库表字段,但又是必须使用的. @TableField(exist = true):表示该 ...

  3. Mybatis配置——自动使用驼峰命名 属性映射字段(默认为false)

    开发一个新项目,用的springboot,相关配置不太熟悉,导致一些配置没配,到具体开发时问题就暴露出来了,记录第一个配置问题----Mybatis配置-自动使用驼峰命名 属性(userId)映射字段 ...

  4. sqlmap映射继承机制及映射字段顺序与SQL查询字段顺序无关

    <typeAlias alias="TblSpPartsinfo" type="com.bn.car.biz.supply.dao.po.PartsInfoPO&q ...

  5. Hibernate 映射字段问题[ImprovedNamingStrategy]

    Hibernate 使用JPA 对于映射有3种规则能够配置:DefaultNamingStrategy,ImprovedNamingStrategy,EJB3NamingStrategy 这里仅仅说I ...

  6. ServiceStack.Ormlit sqlserver枚举类型映射字段类型为varchar

    请当枚举类型上面加上[Flags]特性就可以了.

  7. mybatis---属性和字段映射

    1. 查询时使用别名,别名和属性名保持一致 <select id="getUser" parameterType="int" resultType=&qu ...

  8. Hibernatel框架关联映射

    Hibernatel框架关联映射 Hibernate程序执行流程: 1.集合映射 需求:网络购物时,用户购买商品,填写地址 每个用户会有不确定的地址数目,或者只有一个或者有很多.这个时候不能把每条地址 ...

  9. Hibernate之关联映射(一对多和多对一映射,多对多映射)

    ~~~接着之前的Hibernate框架接着学习(上篇面试过后发现真的需要学习以下框架了,不然又被忽悠让去培训.)~~~ 1:Hibernate的关联映射,存在一对多和多对一映射,多对多映射: 1.1: ...

随机推荐

  1. Bundle对象的使用

    在Android开发中,如果要通过一个Activity启动另外一个Activity,需要调用startActivity()函数,这个函数的参数是一个Intent对象,这个对象通常的初始化方式如下: I ...

  2. 51nod1119 机器人走方格 V2

    终于学到了求组合数的正确姿势 //C(n+m-2,m-1) #include<cstdio> #include<cstring> #include<cctype> ...

  3. 浅谈网络爬虫爬js动态加载网页(三)

    上一篇讨论了web driver对动态网页的抓取与分析,可以很清楚的看出这是一种集中式处理方式,简单说,就是利用服务器,打开一个真正的brower,然后将需要解析的地址交给浏览器,浏览器去解析,然后将 ...

  4. php实现一致性哈希算法

    <?php//原理概念请看我的上一篇随笔(http://www.cnblogs.com/tujia/p/5416614.html)或直接百度 /** * 接口:hash(哈希插口).distri ...

  5. shell动态解析sql的binlog

    #!/usr/bin #设置数据库连接 conn='mysql -hhost -Pport -uusername -ppassword' #获取最新的binlog文件 logfile=$($conn ...

  6. 07_js走路小游戏

    <html> <head> <!-- 不做了,思路: 按enter键停止,将xs,ys替换为0,再次按,判断xs和ys是否为0,是的话,讲根据fx给xsys赋值. 实现鼠 ...

  7. 在页面中使用js

    JavaScript:用来在页面编写特效的,和HTML\CSS一样当都是由浏览器解析 JavaScript语言 一.JS如何运行(JavaScript,jscript,VbScript,applet ...

  8. HDU 1496 Train Problem I 火车问题1(桟,水)

    题意: 给出两个串,串中的数字i 代表编号为i的火车进入车站的顺序,车站如桟一样,先进后出.第二个串是火车出站的顺序,问若按照第一个串那样进站,是否有可能如第二个串一样的出站顺序?火车顶多9辆,即1- ...

  9. poj 2127 LCIS 带路径输出

    这个题   用一维 为什么错了: 因为 用一维 dp 方程肯定也是一维:但是有没有想,第 i 个字符更新了 j 位置的最优结果,然后 k 字符又一次更新了  j 位置的最优值,然后  我的结果是  i ...

  10. Arduino "Card failed, or not present"(即找不到SD卡)错误解决方案

    http://forum.arduino.cc/index.php?topic=28763.0 Arduino SD自带的例程都是有一个BUG的,必须在pinMode后面加上如下的第二行代码 pinM ...