/// <summary> /// 批量导入数据 /// </summary> /// <param name="listRecord">数据集</param> public void BatchInportInfo(List <ZL_Database_Record> listRecord) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; BillNumberControl billNoControl = new BillNumberControl(CE_BillTypeEnum.质量数据库.ToString(), this); try { foreach (ZL_Database_Record record in listRecord) { string billNo = billNoControl.GetNewBillNo(); InsertFile(record.BillNo, billNo); record.BillNo = billNo; ctx.ZL_Database_Record.InsertOnSubmit(record); ctx.SubmitChanges(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void InsertInfoExcel(string billNo, DataTable infoTable) { IMaterialRequisitionServer billServer = ServerModuleFactory.GetServerModule <IMaterialRequisitionServer>(); BillNumberControl billNoControl = new BillNumberControl("领料单", billServer); DepotManagementDataContext ctx = CommentParameter.DepotDataContext; ctx.Connection.Open(); ctx.Transaction = ctx.Connection.BeginTransaction(); IStoreServer storeService = ServerModuleFactory.GetServerModule <IStoreServer>(); try { List <string> lstStorage = new List <string>(); if (infoTable.Columns.Contains("库房")) { lstStorage = DataSetHelper.ColumnsToList_Distinct(infoTable, "库房"); foreach (string storage in lstStorage) { string temp = UniversalFunction.GetStorageID(storage); if (temp.Trim().Length == 0) { throw new Exception("【库房名称】:" + storage + "有误, 无法匹配到库房ID"); } } } if (!infoTable.Columns.Contains("物品ID")) { infoTable.Columns.Add("物品ID"); foreach (DataRow dr in infoTable.Rows) { int goodsID = UniversalFunction.GetGoodsID(dr["图号型号"] == null ? "" : dr["图号型号"].ToString(), dr["物品名称"] == null ? "" : dr["物品名称"].ToString(), dr["规格"] == null ? "" : dr["规格"].ToString()); if (goodsID == 0) { throw new Exception(string.Format("【图号型号】:{0} 【物品名称】:{1} 【规格】:{2}有误," + " 无法匹配到物品ID", dr["图号型号"], dr["物品名称"], dr["规格"])); } dr["物品ID"] = goodsID; } } var varData = from a in ctx.S_MaterialRequisition where a.Bill_ID == billNo select a; if (varData.Count() != 1) { throw new Exception("无法获取【单据号】: " + billNo + " 的基本信息"); } S_MaterialRequisition requisition = varData.Single(); if (BillIsFinish(ctx, requisition.Bill_ID)) { throw new Exception("单据已完成,无法进行操作"); } if (lstStorage.Count == 0) { lstStorage.Add(UniversalFunction.GetStorageName(requisition.StorageID)); } foreach (string storage in lstStorage) { DataTable tempTable = infoTable; if (lstStorage.Count > 1) { tempTable = DataSetHelper.SiftDataTable(infoTable, "库房 = '" + storage + "'"); } string tempBillNo = ""; string storageID = UniversalFunction.GetStorageID(storage); if (requisition.StorageID != storageID) { S_MaterialRequisition tempRequisition = new S_MaterialRequisition(); tempBillNo = billNoControl.GetNewBillNo(ctx); tempRequisition.Bill_ID = tempBillNo; tempRequisition.AssociatedBillNo = requisition.AssociatedBillNo; tempRequisition.AssociatedBillType = requisition.AssociatedBillType; tempRequisition.AuthorizeDate = requisition.AuthorizeDate; tempRequisition.AuthorizePersonnel = requisition.AuthorizePersonnel; tempRequisition.Bill_Time = requisition.Bill_Time; tempRequisition.BillStatus = requisition.BillStatus; tempRequisition.Department = requisition.Department; tempRequisition.DepartmentDirector = requisition.DepartmentDirector; tempRequisition.DepotManager = requisition.DepotManager; tempRequisition.FetchCount = requisition.FetchCount; tempRequisition.FetchType = requisition.FetchType; tempRequisition.FillInPersonnel = requisition.FillInPersonnel; tempRequisition.FillInPersonnelCode = requisition.FillInPersonnelCode; tempRequisition.OutDepotDate = requisition.OutDepotDate; tempRequisition.ProductType = requisition.ProductType; tempRequisition.PurposeCode = requisition.PurposeCode; tempRequisition.Remark = requisition.Remark; tempRequisition.StorageID = storageID; tempRequisition.TechnologistDate = requisition.TechnologistDate; tempRequisition.TechnologistPersonnel = requisition.TechnologistPersonnel; ctx.S_MaterialRequisition.InsertOnSubmit(tempRequisition); ctx.SubmitChanges(); } else { tempBillNo = billNo; } foreach (DataRow dr in tempTable.Rows) { S_MaterialRequisitionGoods goodsInfo = new S_MaterialRequisitionGoods(); goodsInfo.RequestCount = dr["数量"] == null ? 0 : Convert.ToDecimal(dr["数量"]); goodsInfo.BatchNo = dr["批次号"] == null ? "" : dr["批次号"].ToString(); if (dr["物品ID"] == null || Convert.ToInt32(dr["物品ID"]) == 0) { throw new Exception("【物品ID】无效"); } goodsInfo.GoodsID = Convert.ToInt32(dr["物品ID"]); goodsInfo.Bill_ID = tempBillNo; StoreQueryCondition condition = new StoreQueryCondition(); condition.BatchNo = goodsInfo.BatchNo; condition.GoodsID = goodsInfo.GoodsID; condition.StorageID = storageID; S_Stock stockInfo = storeService.GetStockInfo(condition); if (stockInfo == null) { throw new Exception(string.Format("【物品ID】:{0} 【批次号】:{1} 【库房】:{2} 未找到匹配的库存记录", goodsInfo.GoodsID, goodsInfo.BatchNo, storage)); } goodsInfo.ProviderCode = stockInfo.Provider; goodsInfo.BasicCount = 0; goodsInfo.Remark = "由Excel导入"; goodsInfo.RepairStatus = null; goodsInfo.RealCount = goodsInfo.RequestCount; goodsInfo.ShowPosition = 1; ctx.S_MaterialRequisitionGoods.InsertOnSubmit(goodsInfo); ctx.SubmitChanges(); } } ctx.SubmitChanges(); ctx.Transaction.Commit(); } catch (Exception ex) { ctx.Transaction.Rollback(); throw new Exception(ex.Message); } }