using WcsMain.Common;
using WcsMain.DataBase.TableEntity;
using WcsMain.WcsAttribute.AutoFacAttribute;
namespace WcsMain.DataBase.Dao;
///
/// tbl_app_db 表的增删改查
///
[Component]
public class AppDBDao
{
///
/// 插入数据
///
///
///
public int Insert(AppDB appDB)
{
try
{
int insertResult = CommonTool.DbServe.Insertable(appDB).ExecuteCommand();
return insertResult;
}
catch (Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 更新数据,以主键为条件,主键 : DBName
///
///
///
public int Update(AppDB appDB)
{
try
{
var sqlFuc = CommonTool.DbServe.Updateable(appDB).IgnoreColumns(ignoreAllNullColumns: true);
return sqlFuc.ExecuteCommand();
}
catch (Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 删除数据,以主键为条件
///
///
///
public int Delete(AppDB appDB)
{
try
{
var sqlFuc = CommonTool.DbServe.Deleteable(appDB);
return sqlFuc.ExecuteCommand();
}
catch (Exception ex)
{
_ = ex;
return 0;
}
}
///
/// 查找数据
///
///
///
public List? Select(AppDB appDB)
{
try
{
var sqlFuc = CommonTool.DbServe.Queryable();
if (appDB.DBName != null)
{
sqlFuc = sqlFuc.Where(w => w.DBName == appDB.DBName);
}
if (appDB.DBAddress != null)
{
sqlFuc = sqlFuc.Where(w => w.DBAddress == appDB.DBAddress);
}
if (appDB.IsSystem != null)
{
sqlFuc = sqlFuc.Where(w => w.IsSystem == appDB.IsSystem);
}
if (appDB.Remark != null)
{
sqlFuc = sqlFuc.Where(w => w.Remark == appDB.Remark);
}
return sqlFuc.OrderBy(o => new { o.PlcId, o.DBName }).ToList();
}
catch (Exception ex)
{
_ = ex;
return default;
}
}
///
/// 查找所有数据
///
///
public List? Select() => Select(new AppDB());
}