OPC.UA.DAL/DALBase.cs
(开头部分) 16KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OPC.UA.Model;
using System.Reflection;
using System.Data;
using System.Data.SqlClient;
namespace OPC.UA.DAL
{
public class DALBase<T>where T:ModelBase
{
public static int Insert(T info)
{
//获取info对象实际的类型(不是ModelBase类型,而是传递进来的实体类类型)
Type type = info.GetType();
//表名-->类名
string name = type.Name;
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
//创建参数集合
SqlManager manager = new SqlManager();
PropertyInfo[] pinfos = type.GetProperties();
foreach (PropertyInfo item in pinfos)
{
if (item.GetCustomAttributes(typeof(ColumnAttribute), true).Length == 0)
{
continue;
}
object value = item.GetValue(info, null);
if (value != null)
{
string colName = item.Name;
sb1.Append(colName + ",");
sb2.Append("@" + colName + ",");
manager.Add("@" + colName, value);
}
}
if (manager.Count == 0)
{
throw new Exception("没有数据要添加,无法操作");
}
//删除拼接过程中多产生的一个逗号
sb1.Remove(sb1.Length - 1, 1);
sb2.Remove(sb2.Length - 1, 1);
string sql = string.Format("insert into {0}({1}) values({2})",name,sb1.ToString(),sb2.ToString());
manager.SqlText = sql;
return SqlHelp.CUD(manager);
}
public static int InsertReturnID(T info)
{
//获取info对象实际的类型(不是ModelBase类型,而是传递进来的实体类类型)
Type type = info.GetType();
//表名-->类名
string name = type.Name;
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
//创建参数集合
后面还有 388 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
