SGGL_SHJ/SGGL/BLL/HJGL/WeldingManage/WeldingDailyService.cs

872 lines
42 KiB
C#

using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace BLL
{
public partial class WeldingDailyService
{
/// <summary>
///获取焊接日报信息
/// </summary>
/// <returns></returns>
public static Model.HJGL_WeldingDaily GetPipeline_WeldingDailyByWeldingDailyId(string WeldingDailyId)
{
return Funs.DB.HJGL_WeldingDaily.FirstOrDefault(e => e.WeldingDailyId == WeldingDailyId);
}
/// <summary>
/// 根据焊接日报主键获取焊接日报信息
/// </summary>
/// <param name="weldReportNo">焊接日报编号</param>
/// <returns>焊接日报信息</returns>
public static bool IsExistWeldingDailyCode(string weldingDailyCode, string weldingDailyId, string projectId)
{
var q = Funs.DB.HJGL_WeldingDaily.FirstOrDefault(x => x.WeldingDailyCode == weldingDailyCode && x.ProjectId == projectId && x.WeldingDailyId != weldingDailyId);
if (q != null)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 根据焊接日报Id获取焊接日报明细信息
/// </summary>
/// <param name="ManagerTotalId"></param>
/// <returns></returns>
public static List<Model.SpWeldingDailyItem> GetWeldingDailyItem(string weldingDailyId)
{
List<Model.SpWeldingDailyItem> returnViewMatch = new List<Model.SpWeldingDailyItem>();
var weldlineLists = (from x in Funs.DB.View_HJGL_WeldJoint
where x.WeldingDailyId == weldingDailyId
select new SpWeldingDailyItem
{
WeldJointId = x.WeldJointId,
WeldJointCode = x.WeldJointCode,
PipelineCode = x.PipelineCode,
CoverWelderCode = x.CoverWelderCode,
CoverWelderId = x.CoverWelderId,
BackingWelderCode = x.BackingWelderCode,
BackingWelderId = x.BackingWelderId,
WeldTypeId = x.WeldTypeCode,
JointArea = x.JointArea,
WeldingLocationId = x.WeldingLocationId,
WeldingLocationCode = x.WeldingLocationCode,
JointAttribute = x.JointAttribute,
Size = x.Size,
Dia = x.Dia,
Thickness = x.Thickness,
WeldingMethodCode = x.WeldingMethodCode,
WeldingWireCode = x.WeldingWireCode,
WeldingRodCode = x.WeldingRodCode
}).ToList();
returnViewMatch = weldlineLists;
//if (weldlineLists.Count() > 0)
//{
// foreach (var item in weldlineLists)
// {
// Model.SpWeldingDailyItem newWeldReportItem = new Model.SpWeldingDailyItem();
// newWeldReportItem.WeldJointId = item.WeldJointId;
// newWeldReportItem.WeldJointCode = item.WeldJointCode;
// newWeldReportItem.PipelineCode = item.PipelineCode;
// newWeldReportItem.CoverWelderCode = item.CoverWelderCode;
// newWeldReportItem.CoverWelderId = item.CoverWelderId;
// newWeldReportItem.BackingWelderCode = item.BackingWelderCode;
// newWeldReportItem.BackingWelderId = item.BackingWelderId;
// //newWeldReportItem.WeldTypeId = item.WeldTypeCode;
// newWeldReportItem.JointArea = item.JointArea;
// newWeldReportItem.WeldingLocationId = item.WeldingLocationId;
// newWeldReportItem.WeldingLocationCode = item.WeldingLocationCode;
// newWeldReportItem.JointAttribute = item.JointAttribute;
// newWeldReportItem.Size = item.Size;
// newWeldReportItem.Dia = item.Dia;
// newWeldReportItem.Thickness = item.Thickness;
// newWeldReportItem.WeldingMethodCode = item.WeldingMethodCode;
// newWeldReportItem.WeldingWireCode = item.WeldingWireCode;
// newWeldReportItem.WeldingRodCode = item.WeldingRodCode;
// returnViewMatch.Add(newWeldReportItem);
// }
//}
return returnViewMatch;
}
/// <summary>
/// 查找后返回集合增加到列表集团中
/// </summary>
/// <param name="hdItemsString"></param>
/// <returns></returns>
public static List<Model.SpWeldingDailyItem> GetWeldReportAddItem(string hdString)
{
List<Model.SpWeldingDailyItem> returnViewMatch = new List<Model.SpWeldingDailyItem>(); //= getWeldReportItem;
if (!string.IsNullOrEmpty(hdString))
{
List<string> totallist = Funs.GetStrListByStr(hdString, '@');
foreach (var hdItemsString in totallist)
{
List<string> list = Funs.GetStrListByStr(hdItemsString, '#');
if (list.Count() == 4)
{
string CoverWelderCode = string.Empty; //盖面焊工号
string BackingWelderCode = string.Empty; //打底焊工号
string welderLists = list[0];
List<string> welderIds = Funs.GetStrListByStr(welderLists, '|');
if (welderIds.Count() == 2)
{
var welderCell = BLL.SitePerson_PersonService.GetSitePersonById(welderIds[0]);
if (welderCell != null)
{
CoverWelderCode = welderCell.WelderCode;
}
var welderFloor = BLL.SitePerson_PersonService.GetSitePersonById(welderIds[1]);
if (welderFloor != null)
{
BackingWelderCode = welderFloor.WelderCode;
}
}
string weldingLocationCode = string.Empty;
string weldingLocationId = list[1];
var loc = BLL.Base_WeldingLocationServie.GetWeldingLocationById(weldingLocationId);
if (loc != null)
{
weldingLocationCode = loc.WeldingLocationCode;
}
string jointAttribute = list[2];
string weldlineIdLists = list[3];
List<string> weldlineIds = Funs.GetStrListByStr(weldlineIdLists, '|');
foreach (var weldlineItem in weldlineIds)
{
//if (returnViewMatch.FirstOrDefault(x => x.JOT_ID == jotItem) == null)
//{
var jot = Funs.DB.View_HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == weldlineItem);
//var weldline = BLL.Pipeline_WeldJointService.GetViewWeldJointById(weldlineItem);
if (jot != null)
{
Model.SpWeldingDailyItem newWeldReportItem = new Model.SpWeldingDailyItem();
newWeldReportItem.WeldJointId = jot.WeldJointId;
newWeldReportItem.WeldJointCode = jot.WeldJointCode;
newWeldReportItem.PipelineCode = jot.PipelineCode;
newWeldReportItem.CoverWelderCode = CoverWelderCode;
newWeldReportItem.CoverWelderId = welderIds[0];
newWeldReportItem.BackingWelderCode = BackingWelderCode;
newWeldReportItem.BackingWelderId = welderIds[1];
newWeldReportItem.WeldTypeCode = jot.WeldTypeCode;
newWeldReportItem.JointArea = jot.JointArea;
newWeldReportItem.WeldingLocationId = weldingLocationId;
newWeldReportItem.WeldingLocationCode = weldingLocationCode;
newWeldReportItem.JointAttribute = jointAttribute;
newWeldReportItem.Size = jot.Size;
newWeldReportItem.Dia = jot.Dia;
newWeldReportItem.Thickness = jot.Thickness;
newWeldReportItem.WeldingMethodCode = jot.WeldingMethodCode;
// 如存在日报,默认还是原日报焊工
if (!string.IsNullOrEmpty(jot.WeldingDailyId))
{
newWeldReportItem.CoverWelderId = jot.CoverWelderId;
newWeldReportItem.BackingWelderId = jot.BackingWelderId;
var welderCover = SitePerson_PersonService.GetSitePersonById(jot.CoverWelderId);
if (welderCover != null)
{
newWeldReportItem.CoverWelderCode = welderCover.WelderCode;
}
var welderBacking = SitePerson_PersonService.GetSitePersonById(jot.BackingWelderId);
if (welderBacking != null)
{
newWeldReportItem.BackingWelderCode = welderBacking.WelderCode;
}
newWeldReportItem.JointAttribute = jot.JointAttribute;
newWeldReportItem.WeldingLocationId = jot.WeldingLocationId;
var location = BLL.Base_WeldingLocationServie.GetWeldingLocationById(jot.WeldingLocationId);
if (location != null)
{
newWeldReportItem.WeldingLocationCode = location.WeldingLocationCode;
}
}
returnViewMatch.Add(newWeldReportItem);
}
}
}
}
}
return returnViewMatch;
}
/// <summary>
/// 获取未焊接焊口信息
/// </summary>
/// <param name="ManagerTotalId"></param>
/// <returns></returns>
public static List<Model.SpWeldingDailyItem> GetWeldReportItemFind(string weldingDailyId, string pipelineId)
{
List<Model.SpWeldingDailyItem> returnViewMatch = new List<Model.SpWeldingDailyItem>();
var weldlineLists = from x in Funs.DB.View_HJGL_NoWeldJointFind
where x.PipelineId == pipelineId &&
(x.WeldingDailyId == null || x.WeldingDailyId == weldingDailyId)
select x;
if (weldlineLists.Count() > 0)
{
foreach (var item in weldlineLists)
{
Model.SpWeldingDailyItem newWeldReportItem = new Model.SpWeldingDailyItem();
newWeldReportItem.WeldJointId = item.WeldJointId;
newWeldReportItem.WeldJointCode = item.WeldJointCode;
newWeldReportItem.Dia = item.Dia;
newWeldReportItem.Thickness = item.Thickness;
newWeldReportItem.WeldingMethodCode = item.WeldingMethodCode;
newWeldReportItem.WeldTypeCode = item.WeldTypeCode;
returnViewMatch.Add(newWeldReportItem);
}
}
return returnViewMatch;
}
/// <summary>
/// 增加焊接日报信息
/// </summary>
/// <param name="WeldingDaily"></param>
public static void AddWeldingDaily(Model.HJGL_WeldingDaily WeldingDaily)
{
Model.SGGLDB db = Funs.DB;
Model.HJGL_WeldingDaily newWeldingDaily = new HJGL_WeldingDaily
{
WeldingDailyId = WeldingDaily.WeldingDailyId,
WeldingDailyCode = WeldingDaily.WeldingDailyCode,
ProjectId = WeldingDaily.ProjectId,
UnitId = WeldingDaily.UnitId,
UnitWorkId = WeldingDaily.UnitWorkId,
WeldingDate = WeldingDaily.WeldingDate,
Tabler = WeldingDaily.Tabler,
TableDate = WeldingDaily.TableDate,
Remark = WeldingDaily.Remark,
};
db.HJGL_WeldingDaily.InsertOnSubmit(newWeldingDaily);
db.SubmitChanges();
}
/// <summary>
/// 修改焊接日报信息
/// </summary>
/// <param name="WeldingDaily"></param>
public static void UpdateWeldingDaily(Model.HJGL_WeldingDaily WeldingDaily)
{
Model.SGGLDB db = Funs.DB;
Model.HJGL_WeldingDaily newWeldingDaily = db.HJGL_WeldingDaily.FirstOrDefault(e => e.WeldingDailyId == WeldingDaily.WeldingDailyId);
if (newWeldingDaily != null)
{
newWeldingDaily.WeldingDailyCode = WeldingDaily.WeldingDailyCode;
newWeldingDaily.UnitId = WeldingDaily.UnitId;
newWeldingDaily.UnitWorkId = WeldingDaily.UnitWorkId;
newWeldingDaily.WeldingDate = WeldingDaily.WeldingDate;
newWeldingDaily.Tabler = WeldingDaily.Tabler;
newWeldingDaily.TableDate = WeldingDaily.TableDate;
newWeldingDaily.Remark = WeldingDaily.Remark;
db.SubmitChanges();
}
}
/// <summary>
/// 根据焊接日报Id删除一个焊接日报信息
/// </summary>
/// <param name="WeldingDailyId"></param>
public static void DeleteWeldingDaily(string WeldingDailyId)
{
Model.SGGLDB db = Funs.DB;
Model.HJGL_WeldingDaily delWeldingDaily = db.HJGL_WeldingDaily.FirstOrDefault(e => e.WeldingDailyId == WeldingDailyId);
if (delWeldingDaily != null)
{
db.HJGL_WeldingDaily.DeleteOnSubmit(delWeldingDaily);
db.SubmitChanges();
}
}
#region
/// <summary>
/// 移动端按焊口保存焊接日报待审核明细
/// </summary>
/// <param name="weldJointId">焊口ID</param>
/// <param name="personId">提交焊工ID</param>
/// <param name="time">焊接日期</param>
/// <param name="weldingLocationId">焊接位置ID</param>
/// <param name="welderType">焊工类型 0 全部 1 打底 2 盖面</param>
/// <returns>错误信息</returns>
public static string SaveWeldingDailyTempDetailByMobile(string weldJointId, string personId, string time, string weldingLocationId, int welderType)
{
string res = string.Empty;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
try
{
DateTime weldingDate;
if (!DateTime.TryParse(time, out weldingDate))
{
return "焊接日期不正确";
}
weldingDate = weldingDate.Date;
var person = db.Person_Persons.FirstOrDefault(x => x.PersonId == personId);
if (person == null)
{
return "人员不存在";
}
var joint = db.View_HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == weldJointId);
string err = CheckWeldingDailyTempJoint(db, joint, weldingLocationId);
if (!string.IsNullOrEmpty(err))
{
return err;
}
var weldTask = db.HJGL_WeldTask.FirstOrDefault(x => x.WeldJointId == joint.WeldJointId);
var weldJoint = db.HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == joint.WeldJointId);
var pending = GetPendingTempDetail(db, weldJointId, weldingDate);
string coverWelderId = pending != null ? pending.CoverWelderId : weldJoint.CoverWelderId;
string backingWelderId = pending != null ? pending.BackingWelderId : weldJoint.BackingWelderId;
if (welderType == 0)
{
coverWelderId = personId;
backingWelderId = personId;
}
else if (welderType == 1)
{
backingWelderId = personId;
}
else if (welderType == 2)
{
coverWelderId = personId;
}
else
{
return "焊工类型不正确";
}
SaveWeldingDailyTempDetail(db, joint, weldTask, weldingDate, personId, coverWelderId, backingWelderId,
joint.JointAttribute, weldingLocationId, joint.ProjectId, null, null, joint.WeldingMode);
db.SubmitChanges();
}
catch (Exception ex)
{
APICommonService.SaveSysAPILog("erro", ex.ToString(), "-1");
res = ex.Message;
}
}
return res;
}
/// <summary>
/// Web端保存焊接日报待审核明细
/// </summary>
/// <param name="weldJointId">焊口ID</param>
/// <param name="submitPersonId">提交人ID</param>
/// <param name="weldingDate">焊接日期</param>
/// <param name="coverWelderId">盖面焊工ID</param>
/// <param name="backingWelderId">打底焊工ID</param>
/// <param name="jointAttribute">焊口属性</param>
/// <param name="weldingLocationId">焊接位置ID</param>
/// <param name="projectId">项目ID</param>
/// <param name="unitId">单位ID</param>
/// <param name="unitWorkId">单位工程ID</param>
/// <param name="weldingMode">焊接模式</param>
/// <returns>错误信息</returns>
public static string SaveWeldingDailyTempDetailByWeb(string weldJointId, string submitPersonId, DateTime weldingDate, string coverWelderId,
string backingWelderId, string jointAttribute, string weldingLocationId, string projectId, string unitId, string unitWorkId, string weldingMode)
{
string res = string.Empty;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
try
{
weldingDate = weldingDate.Date;
weldingLocationId = NormalizeNullValue(weldingLocationId);
unitId = NormalizeNullValue(unitId);
unitWorkId = NormalizeNullValue(unitWorkId);
if (string.IsNullOrEmpty(weldJointId))
{
return "焊口不能为空";
}
if (string.IsNullOrEmpty(coverWelderId) || string.IsNullOrEmpty(backingWelderId))
{
return "未选择完整焊工";
}
var joint = db.View_HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == weldJointId);
string err = CheckWeldingDailyTempJoint(db, joint, weldingLocationId);
if (!string.IsNullOrEmpty(err))
{
return err;
}
var coverWelder = db.SitePerson_Person.FirstOrDefault(x => x.ProjectId == projectId && x.PersonId == coverWelderId);
if (coverWelder == null)
{
return "盖面焊工不存在";
}
var backingWelder = db.SitePerson_Person.FirstOrDefault(x => x.ProjectId == projectId && x.PersonId == backingWelderId);
if (backingWelder == null)
{
return "打底焊工不存在";
}
var weldTask = db.HJGL_WeldTask.FirstOrDefault(x => x.WeldJointId == weldJointId);
SaveWeldingDailyTempDetail(db, joint, weldTask, weldingDate, submitPersonId, coverWelderId, backingWelderId,
jointAttribute, weldingLocationId, projectId, unitId, unitWorkId, weldingMode);
db.SubmitChanges();
}
catch (Exception ex)
{
APICommonService.SaveSysAPILog("erro", ex.ToString(), "-1");
res = ex.Message;
}
}
return res;
}
/// <summary>
/// 审核通过焊接日报待审核明细
/// </summary>
/// <param name="tempDetailIds">待审核明细ID集合</param>
/// <param name="auditMan">审核人</param>
/// <returns>错误信息</returns>
public static string AuditWeldingDailyTempDetails(string[] tempDetailIds, string auditMan)
{
string errlog = string.Empty;
if (tempDetailIds == null || tempDetailIds.Length == 0)
{
return "请选择要审核的记录";
}
foreach (string tempDetailId in tempDetailIds.Where(x => !string.IsNullOrEmpty(x)).Distinct())
{
var tempDetail = Funs.DB.HJGL_WeldingDailyTempDetail.FirstOrDefault(x => x.TempDetailId == tempDetailId);
if (tempDetail == null)
{
errlog += "待审核记录不存在;";
continue;
}
if (tempDetail.AuditState != 0)
{
errlog += "焊口待审核记录已审核;";
continue;
}
if (string.IsNullOrEmpty(tempDetail.CoverWelderId) || string.IsNullOrEmpty(tempDetail.BackingWelderId))
{
errlog += "焊口待审核记录未选择完整焊工;";
continue;
}
var weldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(tempDetail.WeldJointId);
if (weldJoint == null)
{
errlog += "焊口不存在;";
continue;
}
if (!string.IsNullOrEmpty(weldJoint.WeldingDailyId))
{
errlog += "焊口【" + weldJoint.WeldJointCode + "】已生成焊接日报;";
continue;
}
var batchC = BLL.Project_SysSetService.GetSysSetBySetId("5", tempDetail.ProjectId);
if (batchC == null)
{
errlog += "请设置项目的组批条件;";
continue;
}
var weldingDaily = GetOrCreateWeldingDailyByTempDetail(tempDetail);
string itemErr = InsertWeldingDailyItem(tempDetail.WeldJointId, tempDetail.CoverWelderId, tempDetail.BackingWelderId,
tempDetail.JointAttribute, weldingDaily.WeldingDate, batchC.SetValue, true, weldingDaily.WeldingDailyId,
tempDetail.ProjectId, tempDetail.WeldingLocationId);
if (!string.IsNullOrEmpty(itemErr))
{
errlog += itemErr;
continue;
}
BLL.HJGL_PipelineComponentjointService.UpdateStateByWeldJointId(tempDetail.WeldJointId, (DateTime)weldingDaily.WeldingDate);//更改预制口实际时间和状态
PipelineService.UpdataDateByWeldJointId(tempDetail.WeldJointId);//更改安装口时间和状态
tempDetail.AuditState = 1;
tempDetail.AuditMan = auditMan;
tempDetail.AuditDate = DateTime.Now;
Funs.DB.SubmitChanges();
}
return errlog;
}
/// <summary>
/// 删除未审核的焊接日报待审核明细
/// </summary>
/// <param name="tempDetailIds">待审核明细ID集合</param>
/// <returns>错误信息</returns>
public static string DeleteWeldingDailyTempDetails(string[] tempDetailIds)
{
if (tempDetailIds == null || tempDetailIds.Length == 0)
{
return "请选择要删除的记录";
}
string errlog = string.Empty;
foreach (string tempDetailId in tempDetailIds.Where(x => !string.IsNullOrEmpty(x)).Distinct())
{
var tempDetail = Funs.DB.HJGL_WeldingDailyTempDetail.FirstOrDefault(x => x.TempDetailId == tempDetailId);
if (tempDetail == null)
{
continue;
}
if (tempDetail.AuditState != 0)
{
errlog += "已审核记录不能删除;";
continue;
}
Funs.DB.HJGL_WeldingDailyTempDetail.DeleteOnSubmit(tempDetail);
}
Funs.DB.SubmitChanges();
return errlog;
}
private static string CheckWeldingDailyTempJoint(Model.SGGLDB db, Model.View_HJGL_WeldJoint joint, string weldingLocationId)
{
if (joint == null)
{
return "焊口不存在";
}
if (!string.IsNullOrEmpty(joint.WeldingDailyId))
{
return "焊口【" + joint.WeldJointCode + "】已生成焊接日报,不能提交待审核";
}
if (!string.IsNullOrEmpty(weldingLocationId))
{
var weldingLocationModel = db.Base_WeldingLocation.FirstOrDefault(x => x.WeldingLocationId == weldingLocationId);
if (weldingLocationModel == null)
{
return "焊口位置不存在";
}
}
return string.Empty;
}
private static Model.HJGL_WeldingDailyTempDetail GetPendingTempDetail(Model.SGGLDB db, string weldJointId, DateTime weldingDate)
{
return db.HJGL_WeldingDailyTempDetail.FirstOrDefault(x => x.WeldJointId == weldJointId
&& x.WeldingDate >= weldingDate.Date
&& x.WeldingDate < weldingDate.Date.AddDays(1)
&& x.AuditState == 0);
}
private static void SaveWeldingDailyTempDetail(Model.SGGLDB db, Model.View_HJGL_WeldJoint joint, Model.HJGL_WeldTask weldTask,
DateTime weldingDate, string submitPersonId, string coverWelderId, string backingWelderId, string jointAttribute,
string weldingLocationId, string projectId, string unitId, string unitWorkId, string weldingMode)
{
var pending = GetPendingTempDetail(db, joint.WeldJointId, weldingDate);
if (pending == null)
{
pending = new Model.HJGL_WeldingDailyTempDetail
{
TempDetailId = Guid.NewGuid().ToString(),
WeldJointId = joint.WeldJointId,
WeldingDate = weldingDate.Date,
AuditState = 0,
SubmitDate = DateTime.Now
};
db.HJGL_WeldingDailyTempDetail.InsertOnSubmit(pending);
}
pending.ProjectId = !string.IsNullOrEmpty(projectId) ? projectId : joint.ProjectId;
pending.UnitId = !string.IsNullOrEmpty(unitId) ? unitId : (weldTask != null && !string.IsNullOrEmpty(weldTask.UnitId) ? weldTask.UnitId : joint.UnitId);
pending.UnitWorkId = !string.IsNullOrEmpty(unitWorkId) ? unitWorkId : joint.UnitWorkId;
pending.CoverWelderId = coverWelderId;
pending.BackingWelderId = backingWelderId;
pending.JointAttribute = !string.IsNullOrEmpty(jointAttribute) ? jointAttribute : joint.JointAttribute;
pending.WeldingLocationId = !string.IsNullOrEmpty(weldingLocationId) ? weldingLocationId : joint.WeldingLocationId;
pending.WeldingMode = !string.IsNullOrEmpty(weldingMode) ? weldingMode : joint.WeldingMode;
pending.SubmitPersonId = submitPersonId;
pending.SubmitDate = DateTime.Now;
}
private static Model.HJGL_WeldingDaily GetOrCreateWeldingDailyByTempDetail(Model.HJGL_WeldingDailyTempDetail tempDetail)
{
var weldingDaily = Funs.DB.HJGL_WeldingDaily.FirstOrDefault(x => x.UnitWorkId == tempDetail.UnitWorkId
&& x.WeldingDate >= tempDetail.WeldingDate.Date
&& x.WeldingDate < tempDetail.WeldingDate.Date.AddDays(1));
if (weldingDaily != null)
{
return weldingDaily;
}
var submitPerson = Funs.DB.Person_Persons.FirstOrDefault(x => x.PersonId == tempDetail.SubmitPersonId);
string personName = submitPerson != null ? submitPerson.PersonName : string.Empty;
string perfix = string.Format("{0:yyyyMMdd}", tempDetail.WeldingDate) + "-" + personName + "-";
weldingDaily = new Model.HJGL_WeldingDaily
{
WeldingDailyId = Guid.NewGuid().ToString(),
WeldingDailyCode = BLL.SQLHelper.RunProcNewId("SpGetThreeNumber", "dbo.HJGL_WeldingDaily", "WeldingDailyCode", tempDetail.ProjectId, perfix),
WeldingDate = tempDetail.WeldingDate.Date,
ProjectId = tempDetail.ProjectId,
UnitWorkId = tempDetail.UnitWorkId,
UnitId = tempDetail.UnitId,
Tabler = tempDetail.SubmitPersonId,
TableDate = tempDetail.WeldingDate.Date,
Remark = "焊接日报待审核通过"
};
BLL.WeldingDailyService.AddWeldingDaily(weldingDaily);
return weldingDaily;
}
private static string NormalizeNullValue(string value)
{
return value == Const._Null ? null : value;
}
/// <summary>
/// 日报明细插入(更新焊口信息),组批等
/// </summary>
/// <param name="weldJointId">焊口ID</param>
/// <param name="coverWelderId">盖面焊工ID</param>
/// <param name="backingWelderId">打底焊工ID</param>
/// <param name="jointAttribute">焊口属性</param>
/// <param name="weldingDate">焊接日期</param>
/// <param name="batchCondition">组批条件</param>
/// <param name="isSave">是否保存</param>
/// <param name="weldingDailyId">日报ID</param>
/// <param name="projectId">项目ID</param>
/// <param name="weldingLocationId">焊接位置ID</param>
/// <returns>错误信息</returns>
private static string InsertWeldingDailyItem(string weldJointId, string coverWelderId, string backingWelderId, string jointAttribute, DateTime? weldingDate, string batchCondition, bool isSave, string weldingDailyId, string projectId, string weldingLocationId)
{
string errlog = string.Empty;
var newWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(weldJointId);
if (newWeldJoint == null)
{
return "焊口不存在;";
}
var pipeline = BLL.PipelineService.GetPipelineByPipelineId(newWeldJoint.PipelineId);
var weldingDaily = BLL.WeldingDailyService.GetPipeline_WeldingDailyByWeldingDailyId(weldingDailyId);
if (pipeline == null || weldingDaily == null)
{
return "焊口关联管线或日报不存在;";
}
if (!string.IsNullOrEmpty(coverWelderId) && !string.IsNullOrEmpty(backingWelderId))
{
if (isSave)
{
newWeldJoint.WeldingDailyId = weldingDailyId;
newWeldJoint.WeldingDailyCode = weldingDaily.WeldingDailyCode;
newWeldJoint.CoverWelderId = coverWelderId;
newWeldJoint.BackingWelderId = backingWelderId;
newWeldJoint.CoverWelderTeamGroupId = SitePerson_PersonService.GetSitePersonByProjectIdPersonId(pipeline.ProjectId, coverWelderId).TeamGroupId;
newWeldJoint.BackingWelderTeamGroupId = SitePerson_PersonService.GetSitePersonByProjectIdPersonId(pipeline.ProjectId, backingWelderId).TeamGroupId;
if (!string.IsNullOrEmpty(weldingLocationId))
{
newWeldJoint.WeldingLocationId = weldingLocationId;
}
newWeldJoint.JointAttribute = jointAttribute;
BLL.WeldJointService.UpdateWeldJoint(newWeldJoint);
// 更新焊口号 修改固定焊口号后 +G
BLL.WeldJointService.UpdateWeldJointAddG(newWeldJoint.WeldJointId, newWeldJoint.JointAttribute, Const.BtnAdd);
errlog = PointBatchService.AddBatchByWeldJointId(weldJointId, weldingDate, batchCondition);//自动组批
}
}
else
{
errlog = "焊口" + "【" + newWeldJoint.WeldJointCode + "】" + "未选择焊工";
}
return errlog;
}
#endregion
/// <summary>
/// 日报明细删除
/// </summary>
/// <param name="weldJointId"></param>
/// <returns></returns>
public static string DeleteWeldingDailyItemByweldJointId(string weldJointId)
{
string errlog = string.Empty;
var newWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(weldJointId);
var pipeline = BLL.PipelineService.GetPipelineByPipelineId(newWeldJoint.PipelineId);
if (newWeldJoint != null && !string.IsNullOrEmpty(newWeldJoint.WeldingDailyId))
{
var isTrust = from x in Funs.DB.HJGL_Batch_BatchTrustItem
where x.WeldJointId == weldJointId
select x; ;
if (isTrust.Count() == 0)
{
var updateWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(weldJointId);
if (updateWeldJoint != null)
{
updateWeldJoint.WeldingDailyId = null;
updateWeldJoint.WeldingDailyCode = null;
updateWeldJoint.CoverWelderId = null;
updateWeldJoint.BackingWelderId = null;
BLL.WeldJointService.UpdateWeldJoint(updateWeldJoint);
var weldTask = BLL.WeldTaskService.GetWeldTaskByWeldJointId(weldJointId);
if (weldTask != null)
{
weldTask.CoverWelderId = null;
weldTask.BackingWelderId = null;
BLL.WeldTaskService.UpdateWeldTask(weldTask);
}
var pointBatchItems = from x in Funs.DB.HJGL_Batch_PointBatchItem where x.WeldJointId == weldJointId select x;
string pointBatchId = pointBatchItems.FirstOrDefault().PointBatchId;
// 删除焊口所在批明细信息
BLL.PointBatchDetailService.DeleteBatchDetail(weldJointId);
// 删除批信息
var batch = from x in Funs.DB.HJGL_Batch_PointBatchItem where x.PointBatchId == pointBatchId select x;
if (pointBatchId != null && batch.Count() == 0)
{
BLL.PointBatchService.DeleteBatch(pointBatchId);
}
}
}
else
{
errlog += "焊口【" + newWeldJoint.WeldJointCode + "】已进委托单了,不能删除。";
}
}
return errlog;
}
/// <summary>
/// 按类型获取焊接日报项
/// </summary>
/// <param name="WeldingDailyType"></param>
/// <returns></returns>
public static List<Model.HJGL_WeldingDaily> GetPipeline_WeldingDailyList(string unitId)
{
var list = (from x in Funs.DB.HJGL_WeldingDaily
where x.UnitId == unitId
orderby x.WeldingDailyCode
select x).ToList();
return list;
}
public static List<Model.HJGL_WeldingDaily> GetPipelineDailyListByUnitWorkId(string UnitWorkId)
{
var list = (from x in Funs.DB.HJGL_WeldingDaily
where x.UnitWorkId == UnitWorkId
orderby x.WeldingDailyCode
select x).ToList();
return list;
}
public static Dictionary<string, object> GetFileOutValueById(string WeldingDailyId)
{
var value = new Dictionary<string, object>();
string strSql = @" SELECT
PipelineCode as '管线号',
(case when charindex('/',WeldJointCode)>0
then RIGHT(WeldJointCode,CHARINDEX('/',REVERSE(WeldJointCode))-1)
else WeldJointCode end) as '焊口序号',
WeldJointCode as '焊口号',
BackingWelderCode as '打底焊工',
BackingWelderTeamGroupName as '打底焊工班组',
CoverWelderCode as '盖面焊工',
CoverWelderTeamGroupName as '盖面焊工班组',
Material1Code as '材质1' ,
Material2Code as '材质2' ,
Dia as '外径' ,
DNDia as 'DN公称直径',
Thickness as '壁厚' ,
WeldTypeCode as '焊缝类型' ,
WeldingMethodCode as '焊接方法' ,
WeldingWireCode as '焊丝' ,
WeldingMode as '焊口机动化程度' ,
WeldingRodCode as '焊条' ,
Size as '达因'
FROM dbo.View_HJGL_WeldJoint
WHERE WeldingDailyId=@WeldingDailyId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@WeldingDailyId", WeldingDailyId));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
var WeldingDailyCode = (from x in Funs.DB.HJGL_WeldingDaily
where x.WeldingDailyId == WeldingDailyId
select x.WeldingDailyCode).FirstOrDefault();
if (!string.IsNullOrEmpty(WeldingDailyCode))
{
value.Add(WeldingDailyCode, tb);
}
return value;
}
public static Dictionary<string, object> GetFileOutValueByUnitWorkId(string UnitWorkId, string Month)
{
var value = new Dictionary<string, object>();
var p = from x in Funs.DB.HJGL_WeldingDaily
where x.UnitWorkId == UnitWorkId
&& x.WeldingDate < Convert.ToDateTime(Month + "-01").AddMonths(1)
&& x.WeldingDate >= Convert.ToDateTime(Month + "-01")
orderby x.WeldingDailyCode descending
select x;
if (p.Count() > 0)
{
foreach (var item in p)
{
var detail = GetFileOutValueById(item.WeldingDailyId);
value.Add(detail.Keys.First(), detail.Values.First());
}
}
return value;
}
#region
/// <summary>
/// 焊接日报下拉项
/// </summary>
/// <param name="dropName">下拉框名称</param>
/// <param name="isShowPlease">是否显示请选择</param>
/// <param name="WeldingDailyType">耗材类型</param>
public static void InitDropDownListByUnitId(FineUIPro.DropDownList dropName, bool isShowPlease, string unitId)
{
dropName.DataValueField = "WeldingDailyId";
dropName.DataTextField = "WeldingDailyCode";
dropName.DataSource = GetPipeline_WeldingDailyList(unitId);
dropName.DataBind();
if (isShowPlease)
{
Funs.FineUIPleaseSelect(dropName);
}
}
public static void InitDownListByUnitWortId(FineUIPro.DropDownList dropName, bool isShowPlease, string UnitWortId)
{
dropName.DataValueField = "WeldingDailyId";
dropName.DataTextField = "WeldingDailyCode";
dropName.DataSource = GetPipelineDailyListByUnitWorkId(UnitWortId);
dropName.DataBind();
if (isShowPlease)
{
Funs.FineUIPleaseSelect(dropName);
}
}
#endregion
}
}