179 lines
6.5 KiB
C#
179 lines
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace BLL
|
|
{
|
|
public static class TrainNumberManageService
|
|
{
|
|
public enum StateInt
|
|
{
|
|
未发货 = 0, // 未发货
|
|
已发货 = 1, // 已发货,未验收
|
|
已验收 = 2, // 已验收
|
|
|
|
}
|
|
|
|
private static IQueryable<Model.HJGL_TrainNumberManage> GetByQueryModle(Model.HJGL_TrainNumberManage table)
|
|
{
|
|
var q = from x in Funs.DB.HJGL_TrainNumberManage select x;
|
|
if (table == null)
|
|
{
|
|
return q;
|
|
}
|
|
if (!string.IsNullOrEmpty(table.Id))
|
|
{
|
|
q = q.Where(x => x.Id.Contains(table.Id));
|
|
}
|
|
if (!string.IsNullOrEmpty(table.TrainNumber))
|
|
{
|
|
q = q.Where(x => x.TrainNumber.Contains(table.TrainNumber));
|
|
}
|
|
if (!string.IsNullOrEmpty(table.ProjectId))
|
|
{
|
|
q = q.Where(x => x.ProjectId.Contains(table.ProjectId));
|
|
}
|
|
if (table.State != null)
|
|
{
|
|
q = q.Where(x => x.State == table.State);
|
|
}
|
|
if (!string.IsNullOrEmpty(table.DriverName))
|
|
{
|
|
q = q.Where(x => x.DriverName.Contains(table.DriverName));
|
|
}
|
|
if (!string.IsNullOrEmpty(table.DriverPhone))
|
|
{
|
|
q = q.Where(x => x.DriverPhone.Contains(table.DriverPhone));
|
|
}
|
|
if (!string.IsNullOrEmpty(table.LicensePlateNumber))
|
|
{
|
|
q = q.Where(x => x.LicensePlateNumber.Contains(table.LicensePlateNumber));
|
|
}
|
|
if (!string.IsNullOrEmpty(table.ContactName))
|
|
{
|
|
q = q.Where(x => x.ContactName.Contains(table.ContactName));
|
|
}
|
|
if (!string.IsNullOrEmpty(table.ContactPhone))
|
|
{
|
|
q = q.Where(x => x.ContactPhone.Contains(table.ContactPhone));
|
|
}
|
|
if (!string.IsNullOrEmpty(table.Remark))
|
|
{
|
|
q = q.Where(x => x.Remark.Contains(table.Remark));
|
|
}
|
|
q = q.OrderByDescending(x => x.TrainNumber);
|
|
|
|
return q;
|
|
}
|
|
|
|
public static List<Model.HJGL_TrainNumberManage> GetListByQueryModle(Model.HJGL_TrainNumberManage table)
|
|
{
|
|
return GetByQueryModle(table).ToList();
|
|
}
|
|
|
|
public static (List<Model.HJGL_TrainNumberManage> Data, int Total) GetListByQueryModle(Model.HJGL_TrainNumberManage table, int pageIndex = 1, int pageSize = 20)
|
|
{
|
|
var baseQuery = GetByQueryModle(table);
|
|
var pagedData = baseQuery
|
|
.Skip((pageIndex-1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToList();
|
|
|
|
// 获取总记录数(延迟计数优化)
|
|
var totalCount = baseQuery.Count();
|
|
|
|
return (pagedData, totalCount);
|
|
}
|
|
|
|
public static Model.HJGL_TrainNumberManage GetModelById(string Id)
|
|
{
|
|
return Funs.DB.HJGL_TrainNumberManage.FirstOrDefault(x => x.Id == Id);
|
|
}
|
|
|
|
//根据projectid 获取最新车次号
|
|
public static string GetNewTrainNumber(string ProjectId)
|
|
{
|
|
var q = from x in Funs.DB.HJGL_TrainNumberManage
|
|
where x.ProjectId == ProjectId
|
|
select x.TrainNumber;
|
|
var max = q.Count();
|
|
var NewTrainNumber = string.Format("{0:yyyyMMdd}", DateTime.Now)+"-"+(max + 1).ToString().PadLeft(3, '0');
|
|
return NewTrainNumber;
|
|
|
|
}
|
|
|
|
public static void Add(Model.HJGL_TrainNumberManage newtable)
|
|
{
|
|
Model.HJGL_TrainNumberManage table = new Model.HJGL_TrainNumberManage
|
|
{
|
|
Id = newtable.Id,
|
|
TrainNumber = newtable.TrainNumber,
|
|
ProjectId = newtable.ProjectId,
|
|
State = newtable.State,
|
|
DriverName = newtable.DriverName,
|
|
DriverPhone = newtable.DriverPhone,
|
|
LicensePlateNumber = newtable.LicensePlateNumber,
|
|
ContactName = newtable.ContactName,
|
|
ContactPhone = newtable.ContactPhone,
|
|
Remark = newtable.Remark,
|
|
ReceiveDate = newtable.ReceiveDate,
|
|
};
|
|
Funs.DB.HJGL_TrainNumberManage.InsertOnSubmit(table);
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
|
|
public static void Update(Model.HJGL_TrainNumberManage newtable)
|
|
{
|
|
Model.HJGL_TrainNumberManage table = Funs.DB.HJGL_TrainNumberManage.FirstOrDefault(x => x.Id == newtable.Id);
|
|
if (table != null)
|
|
{
|
|
table.Id = newtable.Id;
|
|
table.TrainNumber = newtable.TrainNumber;
|
|
table.ProjectId = newtable.ProjectId;
|
|
table.State = newtable.State;
|
|
table.DriverName = newtable.DriverName;
|
|
table.DriverPhone = newtable.DriverPhone;
|
|
table.LicensePlateNumber = newtable.LicensePlateNumber;
|
|
table.ContactName = newtable.ContactName;
|
|
table.ContactPhone = newtable.ContactPhone;
|
|
table.Remark = newtable.Remark;
|
|
table.ReceiveDate = newtable.ReceiveDate;
|
|
Funs.DB.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
public static void DeleteById(string Id)
|
|
{
|
|
var db = Funs.DB;
|
|
Model.HJGL_TrainNumberManage table = db.HJGL_TrainNumberManage.FirstOrDefault(x => x.Id == Id);
|
|
if (table != null)
|
|
{
|
|
var packagingList = db.HJGL_PackagingManage.Where(x => x.TrainNumberId == Id).ToList();
|
|
foreach (var item in packagingList)
|
|
{
|
|
item.TrainNumberId = null;
|
|
item.TrainNumber = null;
|
|
}
|
|
|
|
db.HJGL_TrainNumberManage.DeleteOnSubmit(table);
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
public static void InitDownListOfTrainNumber(FineUIPro.DropDownList dropName, string projectId, bool isShowPlease)
|
|
{
|
|
Model.HJGL_TrainNumberManage table = new Model.HJGL_TrainNumberManage();
|
|
table.ProjectId = projectId;
|
|
|
|
dropName.DataValueField = "Id";
|
|
dropName.DataTextField = "TrainNumber";
|
|
dropName.DataSource = GetListByQueryModle(table);
|
|
dropName.DataBind();
|
|
if (isShowPlease)
|
|
{
|
|
Funs.FineUIPleaseSelect(dropName);
|
|
}
|
|
}
|
|
}
|
|
}
|