| | |
| | | { |
| | | public MesItems GetItemQcPrint(WarehouseQuery query) |
| | | { |
| | | return Db.Queryable<MesItems>() |
| | | .Where(c => c.Factory == query.Factory |
| | | && c.Company == query.Company |
| | | && c.ItemNo == query.ItemNo).First(); |
| | | return Db.Queryable<MesItems>().Where(c => c.Factory == query.Factory && c.Company == query.Company && c.ItemNo == query.ItemNo).First(); |
| | | } |
| | | |
| | | |
| | |
| | | return 1; |
| | | break; |
| | | case "3": |
| | | if (DeleteItem(db, entity.Id)) |
| | | if (UpdateItemStatus(db, entity.Id, "B")) |
| | | return 1; |
| | | break; |
| | | case "4": |
| | |
| | | return 1; |
| | | break; |
| | | default: |
| | | throw new ArgumentNullException( |
| | | $"type没有{item.Type}这个类型的参数"); |
| | | throw new ArgumentNullException($"type没有{item.Type}这个类型的参数"); |
| | | } |
| | | |
| | | throw new NotImplementedException("操作失败"); |
| | |
| | | public bool SaveList(List<ErpItems> items) |
| | | { |
| | | var list = items.Select(GetMesItems).ToList(); |
| | | var groupBy = list.GroupBy(s => s.Type) |
| | | .ToDictionary(g => g.Key, g => g.ToList()); |
| | | var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList()); |
| | | |
| | | return UseTransaction(db => |
| | | { |
| | |
| | | throw new NotImplementedException("插入失败"); |
| | | break; |
| | | case "3": |
| | | if (!DeleteItemBatch(db, itemGroup.Value)) |
| | | if (!UpdateItemStatusBatch(db, itemGroup.Value, "B")) |
| | | throw new NotImplementedException("删除失败"); |
| | | break; |
| | | case "4": |
| | |
| | | throw new NotImplementedException("同步失败"); |
| | | break; |
| | | default: |
| | | throw new ArgumentNullException( |
| | | $"type没有{itemGroup.Key}这个类型的参数"); |
| | | throw new ArgumentNullException($"type没有{itemGroup.Key}这个类型的参数"); |
| | | } |
| | | |
| | | return 1; |
| | | }) > 0; |
| | | } |
| | | |
| | | private bool UpdateItemStatus(SqlSugarScope db, decimal itemId, |
| | | string status) |
| | | private bool UpdateItemStatus(SqlSugarScope db, decimal itemId,string status) |
| | | { |
| | | var result = db.Updateable<MesItems>() |
| | | .SetColumns(s => s.Fforbidstatus == status) |
| | | .Where(s => s.Id == itemId).ExecuteCommand(); |
| | | |
| | | if (result > 0) |
| | | return true; |
| | | |
| | | throw new NotImplementedException(status == "A" ? "启用失败" : "禁用失败"); |
| | | var result = db.Updateable<MesItems>().SetColumns(s => s.Fforbidstatus == status).Where(s => s.Id == itemId).ExecuteCommand(); |
| | | return true; |
| | | } |
| | | |
| | | private bool InsertItem(SqlSugarScope db, MesItems entity) |
| | | { |
| | | var insert = db.Insertable(entity).ExecuteCommand(); |
| | | if (insert > 0) |
| | | var exists = db.Queryable<MesItems>().Any(e => e.Id == entity.Id); |
| | | if (exists) |
| | | { |
| | | var result = db.Updateable<MesItems>().ExecuteCommand(); |
| | | return true; |
| | | |
| | | throw new NotImplementedException("插入失败"); |
| | | } |
| | | else |
| | | { |
| | | var insert = db.Insertable(entity).ExecuteCommand(); |
| | | if (insert > 0) |
| | | { |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | throw new NotImplementedException("插入失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private bool DeleteItem(SqlSugarScope db, decimal itemId) |
| | | private bool InsertOrUpdate(SqlSugarScope db, MesItems entity) |
| | | { |
| | | var deleteById = db.Deleteable<MesItems>().In(itemId).ExecuteCommand(); |
| | | if (deleteById > 0) |
| | | var exists = db.Queryable<Organize>().Any(e => e.Id == entity.Id); |
| | | if (exists) |
| | | { |
| | | var update = db.Updateable(entity).ExecuteCommand(); |
| | | return true; |
| | | |
| | | throw new NotImplementedException("删除失败"); |
| | | } |
| | | else |
| | | { |
| | | var insert = db.Insertable(entity).ExecuteCommand(); |
| | | if (insert > 0) |
| | | { |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private MesItems GetMesItems(ErpItems item) |
| | |
| | | }; |
| | | } |
| | | |
| | | private bool UpdateItemStatusBatch(SqlSugarScope db, |
| | | List<MesItems> itemList, string status) |
| | | private bool UpdateItemStatusBatch(SqlSugarScope db,List<MesItems> itemList, string status) |
| | | { |
| | | var ids = itemList.Select(it => it.Id).ToArray(); |
| | | var result = db.Updateable<MesItems>() |
| | | .SetColumns(s => s.Fforbidstatus == status) |
| | | .Where(s => ids.Contains(s.Id)).ExecuteCommand(); |
| | | |
| | | if (result > 0) |
| | | return true; |
| | | |
| | | throw new NotImplementedException(status == "A" ? "启用失败" : "禁用失败"); |
| | | var result = db.Updateable<MesItems>().SetColumns(s => s.Fforbidstatus == status).Where(s => ids.Contains(s.Id)).ExecuteCommand(); |
| | | return true; |
| | | } |
| | | |
| | | private bool InsertItemBatch(SqlSugarScope db, List<MesItems> itemList) |
| | | { |
| | | var insertRange = db.Insertable(itemList).ExecuteCommand(); |
| | | if (insertRange > 0) |
| | | return true; |
| | | |
| | | throw new NotImplementedException("插入失败"); |
| | | } |
| | | |
| | | private bool DeleteItemBatch(SqlSugarScope db, List<MesItems> itemList) |
| | | { |
| | | var ids = itemList.Select(it => it.Id).ToArray(); |
| | | var deleteByIds = db.Deleteable<MesItems>().In(ids).ExecuteCommand(); |
| | | if (deleteByIds > 0) |
| | | return true; |
| | | |
| | | throw new NotImplementedException("删除失败"); |
| | | } |
| | | |
| | | private bool InsertOrUpdate(SqlSugarScope db, MesItems entity) |
| | | { |
| | | var exists = db.Queryable<MesItems>().Any(e => e.Id == entity.Id); |
| | | if (exists) |
| | | foreach (var entity in itemList) |
| | | { |
| | | var update = db.Updateable(entity).ExecuteCommand(); |
| | | if (update > 0) |
| | | return true; |
| | | if (!InsertItem(db, entity)) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var insert = db.Insertable(entity).ExecuteCommand(); |
| | | if (insert > 0) |
| | | return true; |
| | | } |
| | | |
| | | return false; |
| | | return true; |
| | | } |
| | | |
| | | private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesItems> itemList) |
| | | { |
| | | foreach (var entity in itemList) |
| | | { |
| | | if (!InsertOrUpdate(db, entity)) |
| | | { |
| | | return false; |
| | | |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | } |