linq2DB lambda
哈雅珺
2023-12-01
//添加数据
public static bool InsertSeries(string SeriesName, string SubSeriesName, string OPIName, string OPICode, string States, string InsideCode, int MinStock, int AddStockNum, string Remarks, string OPI_CODERemarkes, DateTime OPI_Date = default(DateTime))
{
bool result;
string ss = OPIDB.GetConnectionString(DBHelper.ConnConfig);
using (OPIDB sQLNICSDB = new OPIDB(OPIDB.GetConnectionString(DBHelper.ConnConfig)))
{
var user = sQLNICSDB.T_OPI.FirstOrDefault(x => x.OPI_CODE == OPICode && x.SERIES_NAME == SeriesName && x.OPI_NAME == OPIName && x.SUB_NAME == SubSeriesName && x.OPI_INSIDECODE == InsideCode);
if (user == null)
{
result = true;
T_OPI opi = new T_OPI();
if (OPI_Date == default(DateTime))
opi.OPI_DATE = DateTime.Now;
else
opi.OPI_DATE = OPI_Date;
opi.SERIES_NAME = SeriesName;
opi.SUB_NAME = SubSeriesName;
opi.OPI_NAME = OPIName;
opi.OPI_CODE = OPICode;
opi.OPI_STATES = States;
opi.OPI_INSIDECODE = InsideCode;
opi.OPI_MINSTOCK = MinStock;
opi.OPI_ADDSTOCKNUM = AddStockNum;
opi.OPI_REMARKES = Remarks;
opi.OPI_CODERemarkes=OPI_CODERemarkes;
sQLNICSDB.Insert(opi);
}
else
{
result = false;
}
return result;
}
}
//删除数据
public static bool DelSeries(string series_name,int ID)
{
bool result = false;
using (OPIDB sQLNICSDB = new OPIDB(OPIDB.GetConnectionString(DBHelper.ConnConfig)))
{
var name = sQLNICSDB.T_OPI.FirstOrDefault(x => x.OPI_ID == ID);
if (name == null)
{
result = false;
}
else
{
//验证成功,删除
sQLNICSDB.Delete(name);
result = true;
}
}
return result;
}
//修改数据
public static bool UpdateSERIES(string SeriesName, string SubSeriesName, string OPIName, string OPICode, string States, string InsideCode, int MinStock, int AddStockNum, string Remarks, int ID,string OPI_CODERemarkes, DateTime OPI_Date = default(DateTime))
{
bool result = false;
using (OPIDB sQLNICSDB = new OPIDB(OPIDB.GetConnectionString(DBHelper.ConnConfig)))
{
var user = sQLNICSDB.T_OPI.FirstOrDefault(x => x.OPI_ID == ID);
if (user != null)
{
var list1 = sQLNICSDB.T_OPI.FirstOrDefault(x => x.OPI_CODE == OPICode && x.SERIES_NAME == SeriesName && x.OPI_NAME == OPIName && x.SUB_NAME == SubSeriesName && x.OPI_INSIDECODE == InsideCode);
if (list1 != null)
{
result = true;
user.OPI_STATES = States;
user.OPI_MINSTOCK = Convert.ToInt32(MinStock);
user.OPI_ADDSTOCKNUM = AddStockNum;
user.OPI_DATE = OPI_Date;
user.OPI_REMARKES = Remarks;
user.OPI_CODERemarkes = OPI_CODERemarkes;
sQLNICSDB.Update(user);
}
else
{
result = true;
user.SERIES_NAME = SeriesName;
user.SUB_NAME = SubSeriesName;
user.OPI_NAME = OPIName;
user.OPI_CODE = OPICode;
user.OPI_INSIDECODE = InsideCode;
user.OPI_STATES = States;
user.OPI_MINSTOCK = Convert.ToInt32(MinStock);
user.OPI_ADDSTOCKNUM = AddStockNum;
user.OPI_DATE = OPI_Date;
user.OPI_REMARKES = Remarks;
user.OPI_CODERemarkes = OPI_CODERemarkes;
sQLNICSDB.Update(user);
}
}
else
{
result = false;
}
}
return result;
}
//查询所有的数据
public static List<T_OPI> select()
{
using (OPIDB sQLNICSDB = new OPIDB(OPIDB.GetConnectionString(DBHelper.ConnConfig)))
return sQLNICSDB.T_OPI.OrderBy(x => x.SERIES_NAME).ThenBy(x=>x.OPI_INSIDECODE).ToList();//con.表名.ToList(); ToList()--查找所有
}
//tuple
public static List<Tuple<string, string, string, string, string, long, long,Tuple<string,DateTime>>> selectOrNeiBu()
{
using (OPIDB sQLNICSDB = new OPIDB(OPIDB.GetConnectionString(DBHelper.ConnConfig)))
{
//var result2 = sQLNICSDB.T_OPI.Select(s=> Tuple.Create(s.OPI_REMARKES,s.OPI_DATE));
var result3 = sQLNICSDB.T_OPI.Select(s => new Tuple<string, string, string, string,
string, long, long, Tuple<string, DateTime>>(s.SERIES_NAME, s.SUB_NAME, s.OPI_NAME, s.OPI_CODE, s.OPI_STATES, s.OPI_MINSTOCK, s.OPI_ADDSTOCKNUM, Tuple.Create(s.OPI_REMARKES, s.OPI_DATE))).ToList();
return result3;
}
}
//查询去重的系列名称数据
public static List<string> selectDSeriesName()
{
List<string> result = new List<string>();
using (OPIDB sQLNICSDB = new OPIDB(OPIDB.GetConnectionString(DBHelper.ConnConfig)))
{
result = sQLNICSDB.T_OPI.Select(x => x.SERIES_NAME).Distinct().ToList();
}
return result;
}