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 { 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 ContactName { get; set; } public string ContactPhone { get; set; } public string StackingPosition { get; set; } public int? State { get; set; } public string ReceiveMan { get; set; } public string ReceiveDate { get; set; } public string PlanStartDate { get; set; } public string Code { get; set; } } public static Model.SGGLDB db = Funs.DB; /// /// 未到场 /// public static int state_0 = 0; /// /// 已发货 /// public static int state_1 = 1; /// /// 已到场 /// 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; } #region 获取列表 /// /// 记录数 /// public static int count { get; set; } /// 获取分页列表 /// /// 页码 /// 每页数量 /// public static IEnumerable getListData(string name, Grid Grid1) { IQueryable q1 = (from x in db.HJGL_PackagingManage join y in db.HJGL_Pipeline_Component on x.PipelineComponentId equals y.PipelineComponentId join z in db.HJGL_Pipeline on y.PipelineId equals z.PipelineId select x ); if (!string.IsNullOrEmpty(name)) { q1 = q1.Where(e => e.PackagingManageId.Contains(name)); } count = q1.Count(); if (count == 0) { return null; } q1 = SortConditionHelper.SortingAndPaging(q1, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize); return from x in q1 select new { x.PackagingManageId, x.PackagingCode, x.ProjectId, x.PipelineComponentId, x.StackingPosition, x.State, x.ContactName, x.ContactPhone, x.Remark, }; } #endregion 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); 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 GetPackagingManageList(string projectId, string PackagingCode) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var q = (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() where x.ProjectId == projectId && (string.IsNullOrEmpty(PackagingCode) || x.PackagingCode.Contains(PackagingCode)) select new PackagingManageItem { PackagingManageId = x.PackagingManageId, PackagingCode = x.PackagingCode, ProjectName = n.ProjectName, ContactName = x.ContactName, ContactPhone = x.ContactPhone, StackingPosition = x.StackingPosition, State = x.State, ReceiveMan = t.PersonName, ReceiveDate = x.ReceiveDate.HasValue ? string.Format("{0:g}", x.ReceiveDate) : "", PlanStartDate = GetMinPlanStartDate(x.PackagingManageId), Code = x.PackagingCode.Substring(0, x.PackagingCode.LastIndexOf("-")).Substring(x.PackagingCode.Substring(0, x.PackagingCode.LastIndexOf("-")).LastIndexOf("-") + 1), }).Distinct(); return q.OrderByDescending(x => x.Code).ToList(); } } /// /// 形成出库单 /// /// public static void PutOutOrder(string PackagingManageId) { var model = GetHJGL_PackagingManageById(PackagingManageId); if (model.State == state_0) { model.State = state_1; UpdateHJGL_PackagingManage(model); } } /// /// 根据主键获取装箱明细 /// /// /// 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 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 listStr = new List(); 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; } /// /// 根据项目号获取包装编号历史记录 /// /// /// public static List 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 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, }; db.HJGL_PackagingManage.InsertOnSubmit(table); db.SubmitChanges(); } public static void UpdateHJGL_PackagingManage(Model.HJGL_PackagingManage newtable) { Model.HJGL_PackagingManage table = db.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; db.SubmitChanges(); } } public static void DeleteHJGL_PackagingManageById(string PackagingManageId) { Model.HJGL_PackagingManage table = db.HJGL_PackagingManage.FirstOrDefault(x => x.PackagingManageId == PackagingManageId); if (table != null) { db.HJGL_PackagingManage.DeleteOnSubmit(table); db.SubmitChanges(); } } /// /// 管线下拉框 /// /// 下拉框名字 /// 是否显示请选择 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); } } } }