315 lines
13 KiB
C#
315 lines
13 KiB
C#
using FineUIPro;
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace BLL
|
|
{
|
|
/// <summary>
|
|
/// 包装管理服务类
|
|
/// </summary>
|
|
public static class HJGL_PackagingmanageService
|
|
{
|
|
public class PackagingManageItem
|
|
{
|
|
public string PackagingManageId { get; set; }
|
|
public string PackagingCode { get; set; }
|
|
public string ProjectId { get; set; }
|
|
public string ProjectName { get; set; }
|
|
public string DriverName { get; set; }
|
|
public string DriverPhone { get; set; }
|
|
public string LicensePlateNumber { get; set; }
|
|
public string ContactName { get; set; }
|
|
public string ContactPhone { get; set; }
|
|
public string StackingPosition { get; set; }
|
|
public int? State { get; set; }
|
|
public int? TypeInt { get; set; }
|
|
public string TypeString { get; set; }
|
|
|
|
public string ReceiveMan { get; set; }
|
|
public string ReceiveDate { get; set; }
|
|
public string PlanStartDate { get; set; }
|
|
|
|
public string Code { get; set; }
|
|
public string TrainNumber { get; set; }
|
|
public string TrainNumberOld { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 未到场
|
|
/// </summary>
|
|
public static int state_0 = 0;
|
|
|
|
/// <summary>
|
|
/// 已发货
|
|
/// </summary>
|
|
public static int state_1 = 1;
|
|
|
|
/// <summary>
|
|
/// 已到场
|
|
/// </summary>
|
|
public static int state_2 = 2;
|
|
|
|
public static ListItem[] GetState()
|
|
{
|
|
ListItem[] list = new ListItem[3];
|
|
list[0] = new ListItem("预出库", state_0.ToString());
|
|
list[1] = new ListItem("已出库", state_1.ToString());
|
|
list[2] = new ListItem("已到场", state_2.ToString());
|
|
return list;
|
|
}
|
|
|
|
public enum TypeInt : int
|
|
{
|
|
预制组件 = 10,
|
|
预制散件 = 20,
|
|
其他材料 = 30,
|
|
}
|
|
|
|
public static Dictionary<string, int> TypeIntMap = new Dictionary<string, int>
|
|
{
|
|
{ "预制组件" ,(int)TypeInt.预制组件},
|
|
{ "预制散件" ,(int)TypeInt.预制散件},
|
|
{ "其他材料" ,(int)TypeInt.其他材料},
|
|
};
|
|
|
|
public static string GetTypeString(int? TypeInt)
|
|
{
|
|
return TypeIntMap.FirstOrDefault(c => c.Value == TypeInt).Key;
|
|
}
|
|
|
|
public static Model.HJGL_PackagingManage GetHJGL_PackagingManageById(string PackagingManageId)
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
return db.HJGL_PackagingManage.FirstOrDefault(x => x.PackagingManageId == PackagingManageId);
|
|
}
|
|
}
|
|
|
|
public static string GetMinPlanStartDate(string PackagingManageId)
|
|
{
|
|
string PlanStartDate = "";
|
|
DataTable tb = BLL.HJGL_PackagingmanageService.GetPackagingDetailById(PackagingManageId);
|
|
if (tb == null || tb.Rows.Count == 0)
|
|
{
|
|
return PlanStartDate;
|
|
}
|
|
var dtTable = tb.AsEnumerable().OrderBy(o => o["PlanStartDate"]).CopyToDataTable();
|
|
if (dtTable.Rows != null && dtTable.Rows.Count > 0)
|
|
{
|
|
PlanStartDate = dtTable.Rows[0]["PlanStartDate"].ToString();
|
|
}
|
|
return PlanStartDate;
|
|
}
|
|
|
|
public static (List<PackagingManageItem> Data, int Total) GetPackagingManageList(string projectId, string PackagingCode, int pageIndex = 0, int pageSize = 20)
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
var baseQuery = (from x in db.HJGL_PackagingManage
|
|
join n in db.Base_Project on x.ProjectId equals n.ProjectId
|
|
join m in db.Person_Persons on x.ReceiveMan equals m.PersonId into tt
|
|
from t in tt.DefaultIfEmpty()
|
|
join train in db.HJGL_TrainNumberManage on x.TrainNumberId equals train.Id into trains
|
|
from train in trains.DefaultIfEmpty()
|
|
where x.ProjectId == projectId
|
|
&& (string.IsNullOrEmpty(PackagingCode) || x.PackagingCode.Contains(PackagingCode))
|
|
select new PackagingManageItem
|
|
{
|
|
PackagingManageId = x.PackagingManageId,
|
|
PackagingCode = x.PackagingCode,
|
|
ProjectName = n.ProjectName,
|
|
ContactName = train.ContactName,
|
|
ContactPhone = train.ContactPhone,
|
|
DriverName = train.DriverName,
|
|
DriverPhone = train.DriverPhone,
|
|
LicensePlateNumber = train.LicensePlateNumber,
|
|
StackingPosition = x.StackingPosition,
|
|
State = x.State,
|
|
TypeInt = x.TypeInt,
|
|
TypeString = GetTypeString(x.TypeInt),
|
|
ReceiveMan = train.ContactName,//t.PersonName,
|
|
ReceiveDate = x.ReceiveDate.HasValue ? string.Format("{0:g}", x.ReceiveDate) : "",
|
|
PlanStartDate = GetMinPlanStartDate(x.PackagingManageId),
|
|
TrainNumberOld = x.TrainNumber,
|
|
TrainNumber = train.TrainNumber,
|
|
Code = x.PackagingCode.Substring(0, x.PackagingCode.LastIndexOf("-")).Substring(x.PackagingCode.Substring(0, x.PackagingCode.LastIndexOf("-")).LastIndexOf("-") + 1),
|
|
}).Distinct();
|
|
|
|
var pagedData = baseQuery
|
|
.OrderByDescending(x => x.Code)
|
|
.Skip((pageIndex) * pageSize)
|
|
.Take(pageSize)
|
|
.ToList();
|
|
|
|
// 获取总记录数(延迟计数优化)
|
|
var totalCount = baseQuery.Count();
|
|
return (pagedData, totalCount);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 形成出库单
|
|
/// </summary>
|
|
/// <param name="PackagingManageId"></param>
|
|
public static void PutOutOrder(string PackagingManageId)
|
|
{
|
|
var model = GetHJGL_PackagingManageById(PackagingManageId);
|
|
if (model.State == state_0)
|
|
{
|
|
model.State = state_1;
|
|
UpdateHJGL_PackagingManage(model);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据主键获取装箱明细
|
|
/// </summary>
|
|
/// <param name="PackagingManageId"></param>
|
|
/// <returns></returns>
|
|
public static DataTable GetPackagingDetailById(string PackagingManageId)
|
|
{
|
|
DataTable tb = new DataTable();
|
|
var model = GetHJGL_PackagingManageById(PackagingManageId);
|
|
if (!string.IsNullOrEmpty(model.PipelineComponentId))
|
|
{
|
|
var PipelineComponentIds = model.PipelineComponentId.Split(',');
|
|
string strSql = @"select com.PipelineComponentId, com.PipelineComponentCode,isnull(pipe.PlanStartDate,getdate()) as PlanStartDate,unitwork.UnitWorkName,'1' as num ,'个' as CU,pipe.FlowingSection
|
|
from HJGL_Pipeline_Component com
|
|
left join HJGL_Pipeline pipe on com.PipelineId=pipe.PipelineId
|
|
left join WBS_UnitWork unitwork on pipe.UnitWorkId=unitwork.UnitWorkId
|
|
";
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
strSql += string.Format("where com.PipelineComponentId in ( {0}) ", "'" + string.Join("','", PipelineComponentIds) + "'");
|
|
strSql += " order by com.PipelineComponentCode";
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
}
|
|
return tb;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据项目号获取包装编号历史记录
|
|
/// </summary>
|
|
/// <param name="projectid"></param>
|
|
/// <returns></returns>
|
|
public static List<string> GetPackagingCode(string projectid)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
var q = (from x in db.HJGL_PackagingManage
|
|
where x.ProjectId.Contains(projectid)
|
|
select x.PackagingCode).Distinct().ToList();
|
|
return q;
|
|
}
|
|
public static List<Model.HJGL_PackagingManage> GetPackagingManage(string trainNumberId)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
var q = (from x in db.HJGL_PackagingManage
|
|
where x.TrainNumberId==trainNumberId
|
|
select x).Distinct().ToList();
|
|
return q;
|
|
}
|
|
public static string GetNewPackagingCode(string projectid)
|
|
{
|
|
string code = ProjectService.GetProjectCodeByProjectId(projectid) + "-" + string.Format("{0:yyyyMMdd}", DateTime.Now) + "-";
|
|
|
|
var q = GetPackagingManageList(projectid, code);
|
|
if (q.Total > 0)
|
|
{
|
|
code = code + (q.Total + 1).ToString().PadLeft(3, '0');
|
|
}
|
|
else
|
|
{
|
|
code = code + "001";
|
|
}
|
|
return code;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增实体
|
|
/// </summary>
|
|
/// <param name="newtable"></param>
|
|
public static void AddHJGL_PackagingManage(Model.HJGL_PackagingManage newtable)
|
|
{
|
|
Model.HJGL_PackagingManage table = new Model.HJGL_PackagingManage
|
|
{
|
|
PackagingManageId = newtable.PackagingManageId,
|
|
PackagingCode = newtable.PackagingCode,
|
|
ProjectId = newtable.ProjectId,
|
|
PipelineComponentId = newtable.PipelineComponentId,
|
|
StackingPosition = newtable.StackingPosition,
|
|
State = newtable.State,
|
|
ContactName = newtable.ContactName,
|
|
ContactPhone = newtable.ContactPhone,
|
|
Remark = newtable.Remark,
|
|
ReceiveDate = newtable.ReceiveDate,
|
|
ReceiveMan = newtable.ReceiveMan,
|
|
TrainNumber = newtable.TrainNumber,
|
|
TrainNumberId = newtable.TrainNumberId,
|
|
TypeInt = newtable.TypeInt,
|
|
CompileMan=newtable.CompileMan,
|
|
CompileDate = newtable.CompileDate
|
|
};
|
|
var db1 = Funs.DB;
|
|
db1.HJGL_PackagingManage.InsertOnSubmit(table);
|
|
db1.SubmitChanges();
|
|
}
|
|
|
|
public static void UpdateHJGL_PackagingManage(Model.HJGL_PackagingManage newtable)
|
|
{
|
|
var db1 = Funs.DB;
|
|
Model.HJGL_PackagingManage table = db1.HJGL_PackagingManage.FirstOrDefault(x => x.PackagingManageId == newtable.PackagingManageId);
|
|
if (table != null)
|
|
{
|
|
table.PackagingManageId = newtable.PackagingManageId;
|
|
table.PackagingCode = newtable.PackagingCode;
|
|
table.ProjectId = newtable.ProjectId;
|
|
table.PipelineComponentId = newtable.PipelineComponentId;
|
|
table.StackingPosition = newtable.StackingPosition;
|
|
table.State = newtable.State;
|
|
table.ContactName = newtable.ContactName;
|
|
table.ContactPhone = newtable.ContactPhone;
|
|
table.Remark = newtable.Remark;
|
|
table.ReceiveMan = newtable.ReceiveMan;
|
|
table.ReceiveDate = newtable.ReceiveDate;
|
|
table.TrainNumber = newtable.TrainNumber;
|
|
table.TrainNumberId = newtable.TrainNumberId;
|
|
table.TypeInt = newtable.TypeInt;
|
|
db1.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
public static void DeleteHJGL_PackagingManageById(string PackagingManageId)
|
|
{
|
|
var db1 = Funs.DB;
|
|
Model.HJGL_PackagingManage table = db1.HJGL_PackagingManage.FirstOrDefault(x => x.PackagingManageId == PackagingManageId);
|
|
if (table != null)
|
|
{
|
|
db1.HJGL_PackagingManage.DeleteOnSubmit(table);
|
|
db1.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 管线下拉框
|
|
/// </summary>
|
|
/// <param name="dropName">下拉框名字</param>
|
|
/// <param name="isShowPlease">是否显示请选择</param>
|
|
public static void InitPipelineDownList(FineUIPro.DropDownList dropName, string projectid, bool isShowPlease)
|
|
{
|
|
dropName.DataValueField = "string";
|
|
dropName.DataTextField = "string";
|
|
dropName.DataSource = GetPackagingCode(projectid);
|
|
dropName.DataBind();
|
|
if (isShowPlease)
|
|
{
|
|
Funs.FineUIPleaseSelect(dropName);
|
|
}
|
|
}
|
|
}
|
|
} |