NHibernate - HQL - 添加和更改
添加:
/// <summary>
/// 等待乙方做出回应 A
/// </summary>
private void button2_Click_1(object sender, EventArgs e)
{
//使用NHibernate,进行存储
Chinfo c = new Chinfo(); c.CtinfoId = ID;
c.Goodsinfo = "白玉手镯";
c.Buyersinfo = "甲方";
c.Sellerinfo = "乙方";
c.Infocreatetime = DateTime.Now;//字段Infocreatetime是DateTime类型,所以此处不能ToString.
c.Currentgoodsstate = "A";
c.Goodsflow = "";
c.Goodsflownowtime = DateTime.Now.ToString();
c.CourierId = ""; try
{
NHelper.Session().Save(c);
NHelper.Trans().Commit();
MessageBox.Show("保存成功!", "提示");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示");
} this.btn_A.Enabled = false;//禁用A
this.btn_B.Enabled = true;//开启B
this.btn_C.Enabled = true;//开启C
}
修改:
/// <summary>
/// 乙方已同意请求 等待公司做出回应 B 1100000
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
try
{
IQuery query = NHelper.Session().CreateQuery("from Chinfo c where c.CtinfoId = ?"); query.SetParameter(, ID); IList<Chinfo> list = query.List<Chinfo>(); list[].Currentgoodsstate = "B";
list[].Goodsflow = "";
list[].Goodsflownowtime = list[].Goodsflownowtime + "-" + DateTime.Now.ToString(); NHelper.Session().Update(list[]); NHelper.Trans().Commit(); MessageBox.Show("修改成功!", "提示");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示");
} this.btn_B.Enabled = false;//禁用B
this.btn_C.Enabled = false;//禁用C
this.btn_D.Enabled = true;//开启D
this.btn_E.Enabled = true;//开启E
}
NHelper.cs代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;
using NHibernate.Cfg; namespace Changing
{
public static class NHelper
{
//变量声明
static ISession session = null;
static ISessionFactory factory = null;
static ITransaction trans = null; //读取配置文件
static Configuration cfg = new Configuration().Configure(@"Config/NHibernate.cfg.xml"); /// <summary>
/// 创建Session工厂
/// </summary>
/// <returns></returns>
public static ISessionFactory Factory()
{
return factory = cfg.BuildSessionFactory();
} /// <summary>
/// 创建Session
/// </summary>
/// <returns></returns>
public static ISession Session()
{
return session = Factory().OpenSession();
} /// <summary>
/// 创建事务
/// </summary>
/// <returns></returns>
public static ITransaction Trans()
{
trans = session.BeginTransaction(); return trans;
}
}
}
NHibernate - HQL - 添加和更改的更多相关文章
- hibernate HQL添加语句
1.Hibernate HQL添加语句 save();方法使用HQL语句来完成插入操作是不能实现的,不管你使用insert into....values...还是insert into.....sel ...
- [NHibernate]HQL查询
目录 写在前面 文档与系列文章 查询的几种方式 HQL查询 一个例子 总结 写在前面 上篇文章介绍了nhibernate在项目中的基本配置,包括数据库连接字符串的设置,映射文件的配置及需注意的地方,这 ...
- Hibernate之HQL添加过滤器查询的用法
HQL查询过程中支持添加过滤器.使用步骤是这样的: 首先在要查询的实体对象的映射中使用<filter-def>标签配置过滤器,并在相对应的<class>标签中添加对应的< ...
- 动态添加和更改F7编辑器(div和editGrid列)
//更改列编辑器 waf("#editGrid").wafGrid("setColumnConfig", "settlementType", ...
- NHibernate -- HQL
使用NHibernate中的HQL来查询数据. 代码: /// <summary> /// 查找事件 /// </summary> private void btn_Selec ...
- Nhibernate HQL 匿名类(严格说是map的使用以及构造函数的使用
1.map的使用 var hql=string.Format(@"select new map( tc.LimitIndexType as LimitIndexType, tc.LimitS ...
- [NHibernate]一对多关系(级联删除,级联添加)
目录 写在前面 文档与系列文章 一对多关系 一个例子 级联删除 级联保存 总结 写在前面 在前面的文章中,我们只使用了一个Customer类进行举例,而在客户.订单.产品中它们的关系,咱们并没有涉及, ...
- NHibernate系列文章二十二:NHibernate查询之HQL查询(附程序下载)
摘要 NHibernate提供了多种查询方式,最早的HQL语言查询.Criteria查询和SQL Query,到NHibernate 3.0的Linq NHibernate,NHIbernate 4. ...
- [NHibernate]并发控制
目录 写在前面 文档与系列文章 并发控制 乐观并发控制(Optimistic Concurrency) 一个例子 悲观并发控制(Pessimistic Concurrency) 总结 写在前面 上篇文 ...
随机推荐
- BZOJ 1087
var f:..,..,..] of int64; a:Array[..] of longint; count:..] of longint; ans:int64; n,m:longint; proc ...
- ArcGIS Engine 改变线IPolyline的方向
有时候需要改变一下线的方向来组成要要的图形,可以按一下方法来变换一下. 如果看官有好的方法的话,请不吝贴上为谢! private IPolyline ChangeDirection(IPolyline ...
- android -- 蓝牙 bluetooth (二) 打开蓝牙
4.2的蓝牙打开流程这一部分还是有些变化的,从界面上看蓝牙开关就是设置settings里那个switch开关,widget开关当然也可以,起点不同而已,后续的流程是一样的.先来看systemServe ...
- 【Hibernate】HQL new map
HQL 查询如果需要带出对象(比如:OneToOne子对象)的一两个属性,而不是全部带出.可以使用 select new map的方法带出. 1.lazy还是设置为false /**关联属性对象*/ ...
- 【Eclipse】Failed to load JavaHL Library
1.选择window--->preferences->Team->SVN->SVN接口 2.选择SVNKit (Pure Java) xxxxxx 如下图所示 : 选择之后, ...
- Jquery UI accordion手风琴菜单
最近学习jQuery,总结了一些心得. 1.引用 <script type="text/javascript" src=jquery.js></script> ...
- Mybatis3 框架理解
最近工作比较闲,维护一个政府机关的短信发送平台,大部分业务逻辑都在Oracle数据库上,但自己明明应聘的是Java开发啊!!!整天写存储过程的我还是有一颗写高级语言的心啊!!!好吧!!!先找个数据库方 ...
- location.href使用方法总结
javascript中的location.href有非常多种使用方法,主要例如以下. self.location.href="/url" 当前页面打开URL页面 location. ...
- PHP - 防止 XSS(跨站脚本攻击)
<?PHP /** * @blog http://www.phpddt.com * @param $string * @param $low 安全别级低 */ function clean_xs ...
- RadioButtonList控件
在这里只写,绑定数据库数据的RadioButtonList控件: 一: 首先,先在数据库中建立一张表: 1 CREATE TABLE KK 2 ( 3 id INT, 4 [name] VARCHAR ...