//20170209 add by liwei1 for P001-170203001 ===end=== private void InsertMR(DateTime report_datetime, string category, string recommendedOperations, DependencyObjectCollection resultColl, object docId) //20170209 modi by liwei1 for P001-170124001 增加参数:docId { DataTable dt = QueryForMoReceiptReq(report_datetime, category, recommendedOperations, docId); //20170209 modi by liwei1 for P001-170124001 增加参数:docId ValidateParaFilDoc(dt); //20161213 add by shenbao for B001-161213006 DataTable dt_d = QueryForMoReceipt_D(category, report_datetime, recommendedOperations); if (dt.Rows.Count > 0) { IQueryService qrySrv = GetService <IQueryService>();//20170405 add by wangrm for P001-170328001 ICreateService createSrv = GetService <ICreateService>("MO_RECEIPT_REQUISTION"); DependencyObject entity = createSrv.Create() as DependencyObject; ISaveService saveService = this.GetService <ISaveService>("MO_RECEIPT_REQUISTION"); List <IGrouping <object, DataRow> > groupDt = dt_d.AsEnumerable().GroupBy(a => (a.Field <object>("MO_RECEIPT_REQUISTION_ID"))).ToList(); IEFNETStatusStatusService efnetSrv = this.GetService <IEFNETStatusStatusService>(); IDocumentNumberGenerateService docNumberService = this.GetService <IDocumentNumberGenerateService>("MO_RECEIPT_REQUISTION"); foreach (DataRow dr in dt.Rows) { DependencyObject newEntity = new DependencyObject(entity.DependencyObjectType); DependencyObjectCollection newEntityDColl = newEntity["MO_RECEIPT_REQUISTION_D"] as DependencyObjectCollection; AddToEntity(newEntity, dr, dt.Columns, false); newEntity["DOC_NO"] = docNumberService.NextNumber(dr["DOC_ID"], dr["DOC_DATE"].ToDate().Date); List <IGrouping <object, DataRow> > entityDColl = groupDt.Where(c => c.Key.Equals(dr["MO_RECEIPT_REQUISTION_ID"])).ToList(); foreach (IGrouping <object, DataRow> groupDColl in entityDColl) { foreach (DataRow dr_d in groupDColl) { DependencyObject newEntityD = new DependencyObject(newEntityDColl.ItemDependencyObjectType); AddToEntity(newEntityD, dr_d, dt_d.Columns, true); newEntityDColl.Add(newEntityD); } } //20170428 add by wangyq for P001-170427001 ============begin========== DependencyObject resultObj = resultColl.AddNew(); resultObj["doc_no"] = newEntity["DOC_NO"]; //20170428 add by wangyq for P001-170427001 ============end========== //20170628 modi by zhangcn for P001-170327001 ===begin=== try { SetIgnoreWarningTag(); //忽略警告 saveService.Save(newEntity); //希望触发保存校验 } finally { ResetIgnoreWarningTag();// 重置警告 } //20170628 modi by zhangcn for P001-170327001 ===end=== //7.3自动签核 efnetSrv.GetFormFlow("MO_RECEIPT_REQUISTION.I01", dr["DOC_ID"], dr["Owner_Org_ROid"], new List <object>() { dr["MO_RECEIPT_REQUISTION_ID"] }); } } }
/// <summary> /// 获取下一个单号 /// </summary> /// <param name="documentNumberGenSrv">单号生成服务</param> /// <param name="docNo">当前单号,如果传入单号为空,则会调用单号生成服务获取单号</param> /// <param name="docID">单据类型</param> /// <param name="sequenceDigit">单据类型流水号位数</param> /// <param name="date">单据日期</param> /// <returns></returns> public static string NextNumber(IDocumentNumberGenerateService documentNumberGenSrv, string docNo , object docID, int sequenceDigit, DateTime date) { if (docNo == string.Empty) { docNo = documentNumberGenSrv.NextNumber(docID, date); } else { if (docNo.Length > sequenceDigit) { docNo = docNo.Substring(0, docNo.Length - sequenceDigit) + (docNo.Substring(docNo.Length - sequenceDigit, sequenceDigit).ToInt32() + 1).ToStringExtension().PadLeft(sequenceDigit, '0'); } } return(docNo); }
private string InsertPoArrivalInspection(string receiptNo, DependencyObjectCollection receiptList, List <int> paiSequenceNumber, Dictionary <int, object> docIdDt) { //获取生成到货检验单基础数据 DataTable poArrivalInspection = GetInsertPoArrivalInspection(receiptNo, paiSequenceNumber); //把查询数据以序号为Key,存入字典中。方便后期直接根据序号拿数据 Dictionary <int, DataRow> poArrivalDictionary = new Dictionary <int, DataRow>(); foreach (DataRow item in poArrivalInspection.Rows) { if (!poArrivalDictionary.ContainsKey(item["SequenceNumber"].ToInt32())) { poArrivalDictionary.Add(item["SequenceNumber"].ToInt32(), item); } } //创建生成采购到货检验单缓存临时表 DataTable poArrivalInspectionInfo = poArrivalInspection.Clone(); //复制表结构 poArrivalInspectionInfo.TableName = "PO_ARRIVAL_INSPECTION"; //创建生成采购到货检验单计数单身缓存临时表 DataTable poArrivalInspectionDInfo = CreatePoArrivalInspectionDInfo(); //创建生成采购到货检验单计量单身缓存临时表 DataTable poArrivalInspectionD1Info = CreatePoArrivalInspectionD1Info(); //创建计数品质检验不良原因缓存临时表 DataTable defectiveReasonsAiId = CreateDefectiveReasonsAiIdInfo(); IPrimaryKeyService keyService = GetService <IPrimaryKeyService>(TypeKey); //生成主键服务 IDocumentNumberGenerateService docNumService = GetService <IDocumentNumberGenerateService>("PO_ARRIVAL_INSPECTION"); //自动编号服务 ICreateInspectionService createInspectionService = GetService <ICreateInspectionService>("PO_ARRIVAL_INSPECTION"); //顺序检查服务 IGenerateOrDeletePurchaseArivalQCResultService generatePurchaseArivalQc = GetService <IGenerateOrDeletePurchaseArivalQCResultService>("PO_QC_RESULT"); //生成/删除采购质检业务信息服务 IItemQtyConversionService itemQtyConversionService = GetService <IItemQtyConversionService>(TypeKey); ILogOnService loginService = GetService <ILogOnService>(); List <DocmentInfo> listDocuments = new List <DocmentInfo>(); Dictionary <string, string> salesReturnDocNo = new Dictionary <string, string>(); //记录产生的单号用于批量生成的时候防止重复单号 const decimal defaultDecimal = 0m; string resutQcNo = string.Empty; //返回结果单号 //循环入参数据,分别给到货检验单、货检验单计数单身、货检验单计量单身身临时表插入数据 foreach (DependencyObject receiptListItem in receiptList) { object poArrivalInspectionId = keyService.CreateId(); //主键 if (poArrivalDictionary.ContainsKey(receiptListItem["seq"].ToInt32())) { #region 到货检验单临时表插入数据 //获取生单基础数据 DataRow dr = poArrivalDictionary[receiptListItem["seq"].ToInt32()]; //获取单据性质 object docId = Maths.GuidDefaultValue(); if (docIdDt.ContainsKey(dr["SequenceNumber"].ToInt32())) { docId = docIdDt[dr["SequenceNumber"].ToInt32()]; } if (dr["PURCHASE_TYPE"].ToStringExtension() == "1" || dr["PURCHASE_TYPE"].ToStringExtension() == "5") { dr["CATEGORY"] = "Q1"; } else if (dr["PURCHASE_TYPE"].ToStringExtension() == "2" || dr["PURCHASE_TYPE"].ToStringExtension() == "3") { dr["CATEGORY"] = "Q2"; } //计算列赋值 dr["PO_ARRIVAL_INSPECTION_ID"] = poArrivalInspectionId; //主键 dr["DOC_ID"] = docId; //单据类型 dr["DOC_DATE"] = DateTime.Now.Date; //单据日期 dr["DOC_NO"] = docNumService.NextNumber(dr["DOC_ID"], dr["DOC_DATE"].ToDate()); //单号 if (!salesReturnDocNo.ContainsKey(dr["DOC_NO"].ToString())) { salesReturnDocNo.Add(dr["DOC_NO"].ToString(), dr["DOC_NO"].ToString()); } else { string oldDocNo = salesReturnDocNo[dr["DOC_NO"].ToString()]; //取得字典中存储的最大单号 string docNo = NewDocNo(oldDocNo); //产生新单号 salesReturnDocNo[dr["DOC_NO"].ToString()] = docNo; //更新字段中单号 dr["DOC_NO"] = docNo; //当前笔单号重新赋值 } object[] createInspection = createInspectionService.GetInspectionId(dr["ITEM_ID"], dr["Owner_Org_ROid"], dr["ITEM_FEATURE_ID"], dr["OPERATION_ID"]); if (!Maths.IsEmpty(createInspection)) { dr["INSPECTION_PLAN_ID"] = createInspection[0]; //质检方案ID dr["INSPECTION_TIMES"] = createInspection[1]; //最大抽样次数 } dr["INSPECTION_QTY"] = receiptListItem["receipt_qty"]; //送检数量 dr["INSPECTION_DUE_DATE"] = Maths.AddTimeValue(dr["ARRIVAL_DATE"].ToDate(), 1, dr["INSPECT_DAYS"].ToInt32()); //检验期限 dr["INVENTORY_QTY"] = itemQtyConversionService.GetConvertedQty(dr["ITEM_ID"], dr["INSPECTION_UNIT_ID"], dr["INSPECTION_QTY"].ToDecimal(), dr["STOCK_UNIT_ID"]); //库存单位数量 dr["SECOND_QTY"] = itemQtyConversionService.GetConvertedQty(dr["ITEM_ID"], dr["INSPECTION_UNIT_ID"], dr["INSPECTION_QTY"].ToDecimal(), dr["SECOND_UNIT_ID"]); //库存单位数量 dr["ACCEPTABLE_QTY"] = receiptListItem["ok_qty"]; //送检数量 dr["UNQUALIFIED_QTY"] = receiptListItem["unqualified_qty"]; //不合格数量 dr["DESTROYED_QTY"] = receiptListItem["checkdestroy_qty"]; //破坏数量 //判定结果 if (receiptListItem["result_type"].ToStringExtension() == "Y") { dr["DECISION"] = "1"; } else { dr["DECISION"] = "2"; } //后道工序 if (!Maths.IsEmpty(dr["MO_ROUTING_D_ID"])) { DependencyObject moRouting = GetMoRouting(dr["MO_ROUTING_D_ID"]); dr["TO_MO_ROUTING_D_ID"] = moRouting["MO_ROUTING_D_ID"]; dr["TO_OPERATION_ID"] = moRouting["OPERATION_ID"]; } dr["Owner_Emp"] = GetEmployeeInfo(loginService.CurrentUserId); dr["Owner_Dept"] = GetAdminUnitInfo(dr["Owner_Emp"]); //系统管理字段 AddManagementData(dr, loginService); poArrivalInspectionInfo.Rows.Add(dr.ItemArray); #endregion #region 到货检验单计数单身临时表插入数据 DependencyObjectCollection qcList = receiptListItem["qc_list"] as DependencyObjectCollection; if (qcList == null) { continue; //不存在qc_list集合数据跳出循环 } foreach (var qcListItem in qcList) { if (qcListItem["qc_seq"].ToInt32() == 0) { continue; //序号为0的数据是默认数据只是为了json结构完整插入的,虚无插入E10系统 } DataRow qcListDr = poArrivalInspectionDInfo.NewRow(); qcListDr["PO_ARRIVAL_INSPECTION_D_ID"] = keyService.CreateId(); //主键 qcListDr["ParentId"] = poArrivalInspectionId; //父主键 qcListDr["SEQUENCE"] = qcListItem["qc_seq"]; qcListDr["DEFECT_CLASS"] = qcListItem["defect_level"]; qcListDr["INSPECTION_QTY"] = qcListItem["test_qty"]; qcListDr["INSPECTION_QQ"] = qcListItem["return_qty"]; qcListDr["INSPECTION_ITEM_ID"] = GetInspectionItem(qcListItem["test_no"], dr["Owner_Org_ROid"]); qcListDr["INSPECTION_AC"] = qcListItem["acceptable_qty"]; qcListDr["INSPECTION_RE"] = qcListItem["rejected_qty"]; if (receiptListItem["result_type"].ToStringExtension() == "Y") { qcListDr["DECISION"] = true; } else { qcListDr["DECISION"] = false; } qcListDr["IMPACT_RESULT"] = true; qcListDr["REMARK"] = string.Empty; qcListDr["DEFECTIVE_REASONS_ID"] = Maths.GuidDefaultValue(); //系统管理字段 AddManagementData(qcListDr, loginService); DependencyObjectCollection reasonlist = qcListItem["reason_list"] as DependencyObjectCollection; if (reasonlist == null) { continue; } //defect_qty为0且reason_no为空的数据是默认数据只是为了json结构完整插入的,不需要插入E10系统 if (reasonlist.Count == 1 && (!Maths.IsEmpty(reasonlist[0]["reason_no"]) || reasonlist[0]["defect_qty"].ToInt32() != 0)) { qcListDr["DEFECTIVE_REASONS_ID"] = GetDefectiveReasonsId(reasonlist[0]["reason_no"].ToStringExtension()); } else { //defect_qty为0且reason_no为空的数据是默认数据只是为了json结构完整插入的,不需要插入E10系统 if (!Maths.IsEmpty(reasonlist[0]["reason_no"]) || reasonlist[0]["defect_qty"].ToInt32() != 0) { foreach (DependencyObject reasonlistItem in reasonlist) { DataRow reasonlistDr = defectiveReasonsAiId.NewRow(); reasonlistDr["DEFECTIVE_REASONS_AI_ID"] = keyService.CreateId(); //主键 reasonlistDr["ParentId"] = qcListDr["PO_ARRIVAL_INSPECTION_D_ID"]; //父主键 reasonlistDr["DEFECTS"] = reasonlistItem["defect_qty"]; reasonlistDr["REMARK"] = string.Empty; reasonlistDr["DEFECTIVE_REASONS_ID"] = GetDefectiveReasonsId(reasonlistItem["reason_no"].ToStringExtension()); //系统管理字段 AddManagementData(reasonlistDr, loginService); defectiveReasonsAiId.Rows.Add(reasonlistDr.ItemArray); //子单身第一笔时把不良原因主键赋值给单身不良原因 if (reasonlist.IndexOf(reasonlistItem) == 0) { qcListDr["DEFECTIVE_REASONS_ID"] = reasonlistDr["DEFECTIVE_REASONS_ID"]; } } } } //把对应数据添加至预生单缓存中 poArrivalInspectionDInfo.Rows.Add(qcListDr.ItemArray); } #endregion #region 到货检验单计量单身临时表插入数据 DependencyObjectCollection collection = createInspectionService.CreateInspection(dr["INSPECTION_PLAN_ID"], dr["OPERATION_ID"]); foreach (DependencyObject item in collection) { if (item["INSPECTION_TYPE"].Equals("VI")) //collection.检验类型=‘VI’ { DataRow itemDr = poArrivalInspectionD1Info.NewRow(); itemDr["PO_ARRIVAL_INSPECTION_D1_ID"] = keyService.CreateId(); itemDr["ParentId"] = poArrivalInspectionId; itemDr["SEQUENCE"] = item["SEQUENCE"]; //检验顺序 DependencyObject inspectionPlantD = GetInspectionPlantD(dr["INSPECTION_PLAN_ID"], item["INSPECTION_ITEM_ID"]); itemDr["DEFECT_CLASS"] = inspectionPlantD["DEFECT_CLASS"]; itemDr["INSPECTION_QTY"] = defaultDecimal; itemDr["INSPECTION_QQ"] = defaultDecimal; itemDr["DECISION"] = false; itemDr["IMPACT_RESULT"] = inspectionPlantD["IMPACT_RESULT"]; itemDr["REMARK"] = string.Empty; itemDr["INSPECTION_ITEM_ID"] = item["INSPECTION_ITEM_ID"]; //检验项目 itemDr["DEFECTIVE_REASONS_ID"] = Maths.GuidDefaultValue(); itemDr["ACCEPTANCE_CONSTANT"] = defaultDecimal; itemDr["SS"] = defaultDecimal; itemDr["XX"] = defaultDecimal; //系统管理字段 AddManagementData(itemDr, loginService); poArrivalInspectionD1Info.Rows.Add(itemDr.ItemArray); } } #endregion //记录单据信息 DocmentInfo docmentInfo = new DocmentInfo(); docmentInfo.Id = dr["PO_ARRIVAL_INSPECTION_ID"]; docmentInfo.OwnerOrgId = dr["Owner_Org_ROid"]; docmentInfo.DocId = dr["DOC_ID"]; docmentInfo.DocNo = dr["DOC_NO"].ToStringExtension(); listDocuments.Add(docmentInfo); if (Maths.IsEmpty(resutQcNo)) { resutQcNo = dr["DOC_NO"].ToStringExtension(); } else { resutQcNo += "," + dr["DOC_NO"].ToStringExtension(); } } } #region 将数据统一插入数据库中 using (ITransactionService trans = GetService <ITransactionService>()) { IQueryService querySrv = GetService <IQueryService>(); //生成采购到货检验单 if (poArrivalInspectionInfo.Rows.Count > 0) { poArrivalInspectionInfo.Columns.Remove("SequenceNumber"); poArrivalInspectionInfo.Columns.Remove("ARRIVAL_DATE"); poArrivalInspectionInfo.Columns.Remove("INSPECT_DAYS"); poArrivalInspectionInfo.Columns.Remove("STOCK_UNIT_ID"); poArrivalInspectionInfo.Columns.Remove("SECOND_UNIT_ID"); poArrivalInspectionInfo.Columns.Remove("PURCHASE_TYPE"); BulkCopyAll(poArrivalInspectionInfo, querySrv); } //生成采购到货检验单计数单身 if (poArrivalInspectionDInfo.Rows.Count > 0) { BulkCopyAll(poArrivalInspectionDInfo, querySrv); } //生成采购到货检验单计量单身 if (poArrivalInspectionD1Info.Rows.Count > 0) { BulkCopyAll(poArrivalInspectionD1Info, querySrv); } //生成计数品质检验不良原因 if (defectiveReasonsAiId.Rows.Count > 0) { BulkCopyAll(defectiveReasonsAiId, querySrv); } //EFNET签核 var infos = listDocuments.GroupBy(c => new { DOC_ID = c.DocId, OwnerOrgID = c.OwnerOrgId }); foreach (var item in infos) { IEFNETStatusStatusService efnetSrv = GetService <IEFNETStatusStatusService>(); efnetSrv.GetFormFlow("PO_ARRIVAL_INSPECTION.I01", item.Key.DOC_ID, item.Key.OwnerOrgID, item.Select(c => c.Id).ToArray()); } //保存单据 IReadService readSrv = GetService <IReadService>("PO_ARRIVAL_INSPECTION"); object[] entities = readSrv.Read(listDocuments.Select(c => c.Id).Distinct().ToArray()); if (entities != null && entities.Length > 0) { ISaveService saveSrv = GetService <ISaveService>("PO_ARRIVAL_INSPECTION"); saveSrv.Save(entities); } trans.Complete(); } #endregion return(resutQcNo); }