/// <summary> /// 导入生产计划 /// </summary> /// <param name="productionPlanList"></param> /// <returns></returns> public bool ImportProductionPlan(List <ExtractInventoryTool_ProductionPlan> productionPlanList, bool isCover, out string errorMessage) { lock (lockObj) { try { errorMessage = string.Empty; if (productionPlanList == null || productionPlanList.Count == 0) { errorMessage = "生产计划为空"; return(false); } //先查询出所有的生产计划唯一码 DataTable allMaterial = GetAllUniqueCode("ProductionPlan"); List <ExtractInventoryTool_ProductionPlan> allProductionPlanList = new List <ExtractInventoryTool_ProductionPlan>(); foreach (DataRow row in allMaterial.Rows) { allProductionPlanList.Add(new ExtractInventoryTool_ProductionPlan() { Oid = Int32.Parse(row["Oid"].ToString()), UniqueCode = row["UniqueCode"].ToString() }); } StringBuilder insertStrbd = new StringBuilder(); StringBuilder updateStrbd = new StringBuilder(); List <SQLiteParameter[]> insertParamList = new List <SQLiteParameter[]>(); List <SQLiteParameter[]> updateParamList = new List <SQLiteParameter[]>(); foreach (var productionPlan in productionPlanList) { ExtractInventoryTool_ProductionPlan exitsPP = allProductionPlanList.FirstOrDefault(m => m.UniqueCode.Trim().Equals(productionPlan.UniqueCode.Trim())); if (exitsPP != null && exitsPP.Oid != 0)//导入数据如果表里有就更新,没有就新建 { if (!isCover) { errorMessage = "存在重复数据,是否覆盖?"; return(true); } productionPlan.Oid = exitsPP.Oid; } SQLiteParameter[] parameter = { SQLiteHelper.MakeSQLiteParameter("@Oid", DbType.Int32, productionPlan.Oid), SQLiteHelper.MakeSQLiteParameter("@VehicleModelCode", DbType.String, productionPlan.VehicleModelCode), SQLiteHelper.MakeSQLiteParameter("@ProductionDate", DbType.Date, productionPlan.ProductionDate), SQLiteHelper.MakeSQLiteParameter("@UnitNum", DbType.Int32, productionPlan.UnitNum), SQLiteHelper.MakeSQLiteParameter("@UpdateTime", DbType.DateTime, productionPlan.UpdateTime), SQLiteHelper.MakeSQLiteParameter("@Client", DbType.Int32, productionPlan.Client), SQLiteHelper.MakeSQLiteParameter("@UniqueCode", DbType.String, productionPlan.UniqueCode) }; if (exitsPP != null && exitsPP.Oid != 0) { updateParamList.Add(parameter); } else { insertParamList.Add(parameter); } } //添加新数据 insertStrbd.Append(@"Insert into ProductionPlan (VehicleModelCode,ProductionDate,UnitNum,UpdateTime,Client,UniqueCode) ") .Append(@"values ( ") .Append(@"@VehicleModelCode,@ProductionDate,@UnitNum,@UpdateTime,@Client,@UniqueCode ") .Append(@")"); new SQLiteHelper().ExecuteNonQueryBatch(insertStrbd.ToString(), insertParamList); updateStrbd.Append(@"Update ProductionPlan set VehicleModelCode=@VehicleModelCode,ProductionDate=@ProductionDate,UnitNum=@UnitNum,UpdateTime=@UpdateTime,Client=@Client,UniqueCode=@UniqueCode ") .Append(@" WHERE Oid=@Oid"); new SQLiteHelper().ExecuteNonQueryBatch(updateStrbd.ToString(), updateParamList); return(true); } catch (Exception ex) { throw ex; } } }
public bool ImportInventory(List <ExtractInventoryTool_Inventory> inventoryList, bool isCover, out string errorMessage) { lock (lockObj) { try { errorMessage = string.Empty; if (inventoryList == null || inventoryList.Count == 0) { errorMessage = "库存信息为空"; return(false); } //先查询出所有的BOM唯一码 DataTable allInventory = GetAllUniqueCode("Inventory", "Material"); List <ExtractInventoryTool_Inventory> allBOMList = new List <ExtractInventoryTool_Inventory>(); foreach (DataRow row in allInventory.Rows) { allBOMList.Add(new ExtractInventoryTool_Inventory() { Oid = Int32.Parse(row["Oid"].ToString()), Material = Int32.Parse(row["Material"].ToString()) }); } StringBuilder insertStrbd = new StringBuilder(); StringBuilder updateStrbd = new StringBuilder(); List <SQLiteParameter[]> insertParamList = new List <SQLiteParameter[]>(); List <SQLiteParameter[]> updateParamList = new List <SQLiteParameter[]>(); foreach (var inventory in inventoryList) { ExtractInventoryTool_Inventory exitsInventory = allBOMList.FirstOrDefault(m => m.Material == inventory.Material); if (exitsInventory != null && exitsInventory.Oid != 0)//导入数据如果表里有就更新,没有就新建 { if (!isCover) { errorMessage = "存在重复数据,是否覆盖?"; return(true); } inventory.Oid = exitsInventory.Oid; } SQLiteParameter[] parameter = { SQLiteHelper.MakeSQLiteParameter("@Oid", DbType.Int32, inventory.Oid), SQLiteHelper.MakeSQLiteParameter("@Material", DbType.Int32, inventory.Material), SQLiteHelper.MakeSQLiteParameter("@SysInventory", DbType.Int32, inventory.SysInventory), SQLiteHelper.MakeSQLiteParameter("@Min", DbType.Int32, inventory.Min), SQLiteHelper.MakeSQLiteParameter("@Max", DbType.Int32, inventory.Max), SQLiteHelper.MakeSQLiteParameter("@HUB", DbType.Int32, inventory.HUB), SQLiteHelper.MakeSQLiteParameter("@InTransit", DbType.Int32, inventory.InTransit), SQLiteHelper.MakeSQLiteParameter("@Total", DbType.Int32, inventory.Total) }; if (exitsInventory != null && exitsInventory.Oid != 0) { updateParamList.Add(parameter); } else { insertParamList.Add(parameter); } } //添加新数据 insertStrbd.Append(@"Insert into Inventory (Material,SysInventory,Min,Max,HUB,InTransit,Total) ") .Append(@"values ( ") .Append(@"@Material,@SysInventory,@Min,@Max,@HUB,@InTransit,@Total ") .Append(@")"); new SQLiteHelper().ExecuteNonQueryBatch(insertStrbd.ToString(), insertParamList); updateStrbd.Append(@"Update Inventory set Material=@Material,SysInventory=@SysInventory,Min=@Min,Max=@Max,HUB=@HUB,InTransit=@InTransit,Total=@Total ") .Append(@" WHERE Oid=@Oid"); new SQLiteHelper().ExecuteNonQueryBatch(updateStrbd.ToString(), updateParamList); return(true); } catch (Exception ex) { throw ex; } } }
/// <summary> /// 导入物料备案 /// </summary> /// <param name="materialList">物料信息</param> /// <param name="isCover">是否覆盖已有数据</param> /// <param name="errorMessage">报错信息</param> /// <returns></returns> /// <remarks> /// Meritar_Jeffrey 2021/04/14 16:31:13 /// 功能 : /// </remarks> public bool ImportMaterial(List <ExtractInventoryTool_Material> materialList, bool isCover, out string errorMessage) { lock (lockObj) { try { errorMessage = string.Empty; if (materialList == null || materialList.Count == 0) { errorMessage = "物料信息为空"; return(false); } //先查询出所有的物料唯一码 DataTable allMaterial = GetAllUniqueCode("Material"); List <ExtractInventoryTool_Material> allMaterialList = new List <ExtractInventoryTool_Material>(); foreach (DataRow row in allMaterial.Rows) { allMaterialList.Add(new ExtractInventoryTool_Material() { Oid = Int32.Parse(row["Oid"].ToString()), UniqueCode = row["UniqueCode"].ToString() }); } StringBuilder insertStrbd = new StringBuilder(); StringBuilder updateStrbd = new StringBuilder(); List <SQLiteParameter[]> insertParamList = new List <SQLiteParameter[]>(); List <SQLiteParameter[]> updateParamList = new List <SQLiteParameter[]>(); foreach (var material in materialList) { ExtractInventoryTool_Material exitsMaterial = allMaterialList.FirstOrDefault(m => m.UniqueCode.Trim().Equals(material.UniqueCode.Trim())); if (exitsMaterial != null && exitsMaterial.Oid != 0)//导入数据如果表里有就更新,没有就新建 { if (!isCover) { errorMessage = "存在重复数据,是否覆盖?"; return(true); } material.Oid = exitsMaterial.Oid; } SQLiteParameter[] parameter = { SQLiteHelper.MakeSQLiteParameter("@Oid", DbType.Int32, material.Oid), SQLiteHelper.MakeSQLiteParameter("@Client", DbType.Int32, material.Client), SQLiteHelper.MakeSQLiteParameter("@Name", DbType.String, material.Name), SQLiteHelper.MakeSQLiteParameter("@Code", DbType.String, material.Code), SQLiteHelper.MakeSQLiteParameter("@Supplier", DbType.String, material.Supplier), SQLiteHelper.MakeSQLiteParameter("@SupplierCode", DbType.String, material.SupplierCode), SQLiteHelper.MakeSQLiteParameter("@UniqueCode", DbType.String, material.UniqueCode) }; if (exitsMaterial != null && exitsMaterial.Oid != 0) { updateParamList.Add(parameter); } else { insertParamList.Add(parameter); } } //添加新数据 insertStrbd.Append(@"Insert into Material (Client,Name,Code,Supplier,SupplierCode,UniqueCode) ") .Append(@"values ( ") .Append(@"@Client,@Name,@Code,@Supplier,@SupplierCode,@UniqueCode ") .Append(@")"); new SQLiteHelper().ExecuteNonQueryBatch(insertStrbd.ToString(), insertParamList); updateStrbd.Append(@"Update Material set Client=@Client,Name=@Name,Code=@Code,Supplier=@Supplier,SupplierCode=@SupplierCode,UniqueCode=@UniqueCode ") .Append(@" WHERE Oid=@Oid"); new SQLiteHelper().ExecuteNonQueryBatch(updateStrbd.ToString(), updateParamList); return(true); } catch (Exception ex) { //唯一码重复,须提示 //debug(); throw ex; } } }