【Wonder原创】NHibernate调用存储过程
调用:
代码
1 public static bool IsPassPack(string lotno,ref string msg)
2 {
3 bool flag = false;
4 try
5 {
6 using (ISession s = NHibernateHelper.GetSession("MES"))
7 {
8 IDbCommand cmd = s.Connection.CreateCommand();
9 cmd.CommandText = "MES_Material.judgeHappened";
10 cmd.CommandType = System.Data.CommandType.StoredProcedure;
11
12 #region para
13 IDbDataParameter para1 = cmd.CreateParameter();
14 para1.ParameterName = "p_lotno";
15 para1.DbType = DbType.String;
16 para1.Value = lotno;
17 cmd.Parameters.Add(para1);
18
19 IDbDataParameter para2 = cmd.CreateParameter();
20 para2.Direction = ParameterDirection.Output;
21 para2.ParameterName = "p_result";
22 para2.DbType = DbType.String;
23 para2.Size = 10;
24 cmd.Parameters.Add(para2);
25
26 IDbDataParameter para3 = cmd.CreateParameter();
27 para3.Direction = ParameterDirection.Output;
28 para3.ParameterName = "p_msg";
29 para3.DbType = DbType.String;
30 para3.Size = 100;
31 cmd.Parameters.Add(para3);
32 #endregion
33
34 cmd.ExecuteNonQuery();
35 if (para2.Value.Equals("0"))
36 flag = true;
37 else
38 flag = false;
39 msg = para3.Value.ToString();
40 }
41
42 }
43 catch (Exception ex)
44 {
45 flag = false;
46 msg = ex.Message;
47 CB_Utility.LogError(msg);
48 }
49 return flag;
读取配置文件 MES.cfg.xml:
代码
1 public static ISession GetSession(string name)
2 {
3 string CurrentFolder = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("file:///", "");
4 string curFolder = CurrentFolder.Substring(0, CurrentFolder.LastIndexOf('/'));
5 string filename = curFolder + "/" + name + ".cfg.xml";
6
7 ISessionFactory _sessionFactory = (new Configuration()).Configure(filename).BuildSessionFactory();
8 return _sessionFactory.OpenSession();
9 }