public int SaveComponent(ComponentInfo info, UserInfo userInfo) { if (info.ID == 0) { info.ID = this.componentDao.AddComponent(info); if (info.FaultRates.Count == 0) { info.FaultRates = FaultRateInfo.GetInitList(info.ID, FaultRateInfo.ObjectType.Component); } else { info.FaultRates.ForEach(faultRate => faultRate.ObjectID = info.ID); } this.faultRateDao.AddFaultRates(FaultRateInfo.ConvertFaultRateDataTable(info.FaultRates)); } else { ComponentInfo existingInfo = this.componentDao.GetComponentByID(info.ID); existingInfo.FaultRates = this.faultRateDao.GetFaultRateByObject(existingInfo.ID, FaultRateInfo.ObjectType.Component); info.FujiClass2.Name = this.fujiClassDao.GetFujiClass2ByID(info.FujiClass2.ID).Name; DataTable dtField = existingInfo.GetChangedFields(info); if (dtField.Rows.Count > 0) { this.componentDao.UpdateComponent(info); this.faultRateDao.UpdateFaultRates(FaultRateInfo.ConvertFaultRateDataTable(info.FaultRates)); // 转换故障率信息 if (info.FaultRates.Count != 0 && existingInfo.FaultRates.Count != 0) { dtField.Merge(FaultRateInfo.ConvertAuditDetail(existingInfo.FaultRates, info.FaultRates).ConvertAuditDetailDT(0)); } this.auditManager.AddAuditLog(userInfo.ID, ObjectTypes.Component, info.ID, dtField); } } return(info.ID); }
public int SaveFujiClass2(FujiClassLink info, UserInfo userInfo, bool isUpdate, int copyID = 0) { List <AuditHdrInfo> audits = new List <AuditHdrInfo>(); AuditHdrInfo audit; if (info.FujiClass2.ID == 0) { if (copyID != 0) { FujiClass2Info copyInfo = this.GetFujiClass2ByID(copyID); copyInfo.FujiClass1 = info.FujiClass2.FujiClass1; copyInfo.Name = info.FujiClass2.Name; copyInfo.Description = info.FujiClass2.Description; info.FujiClass2.ID = this.fujiClassDao.AddFujiClass2(copyInfo); this.fujiClassDao.AddFujiClass2EqpType(info); copyInfo.Repairs.ForEach(rate => rate.ObjectID = info.FujiClass2.ID); this.AddFaultRates(copyInfo.Repairs); if (copyInfo.Components.Count > 0) { foreach (ComponentInfo componentInfo in copyInfo.Components) { componentInfo.ID = 0; componentInfo.FujiClass2.ID = info.FujiClass2.ID; this.componentManager.SaveComponent(componentInfo, userInfo); } } if (copyInfo.Consumables.Count > 0) { foreach (ConsumableInfo consumableInfo in copyInfo.Consumables) { consumableInfo.ID = 0; consumableInfo.FujiClass2.ID = info.FujiClass2.ID; this.consumableDao.AddConsumable(consumableInfo); } } } else { this.fujiClassDao.AddFujiClass2(info.FujiClass2); this.fujiClassDao.AddFujiClass2EqpType(info); info.FujiClass2.Repairs = FaultRateInfo.GetInitList(info.FujiClass2.ID, FaultRateInfo.ObjectType.Repair); this.AddFaultRates(info.FujiClass2.Repairs); } audit = info.ConvertAudit(userInfo); if (audit.DetailInfo.Count > 0) { audits.Add(audit); } } else { FujiClassLink existsInfo = this.GetFujiLinkByClass2ID(info.FujiClass2.ID); if (isUpdate) { info.FujiClass2.CheckEquipmentTypeRelatedFields(); this.fujiClassDao.UpdateFujiClass2(info.FujiClass2); this.UpdateFaultRates(info.FujiClass2.Repairs); audit = existsInfo.FujiClass2.ConvertAudit(info.FujiClass2, userInfo); audit.DetailInfo = audit.DetailInfo.Concat(FaultRateInfo.ConvertAuditDetail(existsInfo.FujiClass2.Repairs, info.FujiClass2.Repairs)).ToList(); if (audit.DetailInfo.Count > 0) { audits.Add(audit); } int componentLen = info.FujiClass2.Components.Count; info.FujiClass2.Components.Sort(); existsInfo.FujiClass2.Components.Sort(); info.FujiClass2.Consumables.Sort(); existsInfo.FujiClass2.Consumables.Sort(); for (int i = 0; i < componentLen; i++) { this.componentDao.UpdateComponent(info.FujiClass2.Components[i]); audit = existsInfo.FujiClass2.Components[i].ConvertAudit(info.FujiClass2.Components[i], userInfo); if (audit.DetailInfo.Count > 0) { audits.Add(audit); } } componentLen = info.FujiClass2.Consumables.Count; for (int i = 0; i < componentLen; i++) { this.consumableDao.UpdateConsumable(info.FujiClass2.Consumables[i]); audit = existsInfo.FujiClass2.Consumables[i].ConvertAudit(info.FujiClass2.Consumables[i], userInfo); if (audit.DetailInfo.Count > 0) { audits.Add(audit); } } } else { this.fujiClassDao.AddFujiClass2EqpType(info); audit = info.ConvertAudit(userInfo); if (audit.DetailInfo.Count > 0) { audits.Add(audit); } } } int len = audits.Count; if (len == 0) { return(info.FujiClass2.ID); } DataTable auditDT = audits.ConvertAuditDT(); DataTable auditDetailDT = null; this.auditDao.AddAuditHdr(auditDT); for (int i = 0; i < len; i++) { if (auditDetailDT == null) { auditDetailDT = audits[i].DetailInfo.ConvertAuditDetailDT(SQLUtil.ConvertInt(auditDT.Rows[i]["ID"])); } else { auditDetailDT.Merge(audits[i].DetailInfo.ConvertAuditDetailDT(SQLUtil.ConvertInt(auditDT.Rows[i]["ID"]))); } } this.auditDao.AddAuditDetail(auditDetailDT); return(info.FujiClass2.ID); }