public bool Add(string billNo, string wareCode) { Guid empanyid = new Guid("d9f369dd-d793-41f5-a191-815503766e94"); var check = new CheckBillMaster(); check.BillNo = "12070001CK"; check.BillDate = DateTime.Now; check.BillTypeCode = "1"; check.WarehouseCode = "CK001"; check.OperatePersonID = empanyid; check.VerifyDate = DateTime.Now; check.Status = "1"; check.IsActive = "1"; check.UpdateTime = DateTime.Now; CheckBillMasterRepository.Add(check); CheckBillMasterRepository.SaveChanges(); return(true); }
/// <summary> /// 根据参数生成并保存盘点数据 --异动生成 /// </summary> /// <param name="beginDate">开始时间</param> /// <param name="endDate">结束时间</param> /// <param name="UserName">登陆用户</param> /// <returns></returns> public bool ChangedAdd(string beginDate, string endDate, string UserName, string billType, out string info) { bool result = false; info = string.Empty; IQueryable <Warehouse> wareQuery = WarehouseRepository.GetQueryable(); IQueryable <Storage> storageQuery = StorageRepository.GetQueryable(); IQueryable <InBillAllot> inAllotQuery = InBillAllotRepository.GetQueryable(); IQueryable <OutBillAllot> outAllotQuery = OutBillAllotRepository.GetQueryable(); IQueryable <MoveBillDetail> moveBillQuery = MoveBillDetailRepository.GetQueryable(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.UserName == UserName); if (employee != null) { if (beginDate == string.Empty || beginDate == null) { beginDate = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd"); } if (endDate == string.Empty || endDate == null) { endDate = DateTime.Now.ToString("yyyy-MM-dd"); } DateTime begin = Convert.ToDateTime(beginDate); DateTime end = Convert.ToDateTime(endDate); try { using (var scope = new TransactionScope()) { Console.WriteLine("start"); var sw = new Stopwatch(); sw.Start(); #region 循环所有仓库的订单,一个仓库一个盘点单据 var warehouses = wareQuery.OrderBy(w => w.WarehouseCode); foreach (var item in warehouses.ToArray()) { var inCells = inAllotQuery.Where(i => i.FinishTime >= begin && i.FinishTime <= end && i.Cell.WarehouseCode == item.WarehouseCode).OrderBy(i => i.CellCode).Select(i => i.CellCode); var outCells = outAllotQuery.Where(o => o.FinishTime >= begin && o.FinishTime <= end && o.Cell.WarehouseCode == item.WarehouseCode).OrderBy(o => o.CellCode).Select(o => o.CellCode); var moveInCells = moveBillQuery.Where(m => m.FinishTime >= begin && m.FinishTime <= end && m.InCell.WarehouseCode == item.WarehouseCode).OrderBy(m => m.InCell.CellCode).Select(m => m.InCell.CellCode); var moveOutCells = moveBillQuery.Where(m => m.FinishTime >= begin && m.FinishTime <= end && m.OutCell.WarehouseCode == item.WarehouseCode).OrderBy(m => m.OutCell.CellCode).Select(m => m.OutCell.CellCode); var storages = storageQuery.Where(s => s.Quantity > 0 && s.IsLock == "0" && (inCells.Any(i => i == s.CellCode) || outCells.Any(o => o == s.CellCode) || moveInCells.Any(mi => mi == s.CellCode) || moveOutCells.Any(mo => mo == s.CellCode))) .OrderBy(s => s.ProductCode) .Select(s => s).ToArray(); if (storages.Any()) { string billNo = GetCheckBillNo().ToString(); var check = new CheckBillMaster(); check.BillNo = billNo; check.BillDate = DateTime.Now; check.BillTypeCode = billType; check.WarehouseCode = item.WarehouseCode; check.OperatePersonID = employee.ID; check.Status = "1"; check.IsActive = "1"; check.UpdateTime = DateTime.Now; CheckBillMasterRepository.Add(check); storages.AsParallel().ForAll(stor => { var checkDetail = new CheckBillDetail(); checkDetail.CellCode = stor.CellCode; checkDetail.StorageCode = stor.StorageCode; checkDetail.ProductCode = stor.ProductCode; checkDetail.UnitCode = stor.Product.UnitCode; checkDetail.Quantity = stor.Quantity; checkDetail.RealProductCode = stor.ProductCode; checkDetail.RealUnitCode = stor.Product.UnitCode; checkDetail.RealQuantity = stor.Quantity; checkDetail.Status = "0"; lock (check.CheckBillDetails) { check.CheckBillDetails.Add(checkDetail); } stor.IsLock = "1"; }); result = true; } else { info = "所选择查询的时间无数据!"; } } CheckBillMasterRepository.SaveChanges(); #endregion sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); sw.Restart(); CheckBillMasterRepository.SaveChanges(); sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); scope.Complete(); } } catch (Exception e) { result = false; info = e.Message; } } return(result); }
/// <summary> /// 根据参数生成并保存盘点数据 --产品生成 /// </summary> /// <param name="products">产品数据</param> /// <param name="UserName">登陆用户</param> /// <returns></returns> public bool ProductAdd(string products, string UserName, string billType, out string info) { bool result = false; info = string.Empty; IQueryable <Warehouse> wareQuery = WarehouseRepository.GetQueryable(); IQueryable <Storage> storageQuery = StorageRepository.GetQueryable(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.UserName == UserName); if (employee != null) { if (products != null && products != string.Empty) { products = products.Substring(0, products.Length - 1); try { using (var scope = new TransactionScope()) { Console.WriteLine("start"); var sw = new Stopwatch(); sw.Start(); #region products 这个有值,就把这个值里面所有的卷烟信息所在的仓库的货位的储存信息生成盘点单,一个仓库一个盘点单据 var warehouses = wareQuery.OrderBy(w => w.WarehouseCode); foreach (var item in warehouses.ToArray()) { var storages = storageQuery.Where(s => s.Product != null && products.Contains(s.ProductCode) && s.Cell.WarehouseCode == item.WarehouseCode && s.Quantity > 0 && s.IsLock == "0") .OrderBy(s => s.StorageCode) .Select(s => s).ToArray(); if (storages.Any()) { string billNo = GetCheckBillNo().ToString(); var check = new CheckBillMaster(); check.BillNo = billNo; check.BillDate = DateTime.Now; check.BillTypeCode = billType; check.WarehouseCode = item.WarehouseCode; check.OperatePersonID = employee.ID; check.Status = "1"; check.IsActive = "1"; check.UpdateTime = DateTime.Now; CheckBillMasterRepository.Add(check); storages.AsParallel().ForAll(stor => { var checkDetail = new CheckBillDetail(); checkDetail.CellCode = stor.CellCode; checkDetail.StorageCode = stor.StorageCode; checkDetail.ProductCode = stor.ProductCode; checkDetail.UnitCode = stor.Product.UnitCode; checkDetail.Quantity = stor.Quantity; checkDetail.RealProductCode = stor.ProductCode; checkDetail.RealUnitCode = stor.Product.UnitCode; checkDetail.RealQuantity = stor.Quantity; checkDetail.Status = "0"; lock (check.CheckBillDetails) { check.CheckBillDetails.Add(checkDetail); } stor.IsLock = "1"; }); result = true; } else { info = "所选择的产品无数据!"; } } #endregion sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); sw.Restart(); CheckBillMasterRepository.SaveChanges(); sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); scope.Complete(); } } catch (Exception e) { result = false; info = e.Message; } } else { info = "产品信息为空!无法生成!"; } } else { info = "当前登陆用户为空!请重新登陆!"; } return(result); }
/// <summary> /// 根据参数生成并保存盘点数据 --货位生成 /// </summary> /// <param name="ware">仓库</param> /// <param name="area">库区</param> /// <param name="shelf">货架</param> /// <param name="cell">货位</param> /// <param name="UserName">登陆用户</param> /// <returns></returns> public bool CellAdd(string ware, string area, string shelf, string cell, string UserName, string billType, out string info) { bool result = false; info = string.Empty; IQueryable <Warehouse> wareQuery = WarehouseRepository.GetQueryable(); IQueryable <Storage> storageQuery = StorageRepository.GetQueryable(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.UserName == UserName); if (employee != null) { try { using (var scope = new TransactionScope()) { Console.WriteLine("start"); var sw = new Stopwatch(); sw.Start(); #region ware 这个有值,就把这个值里面所有的仓库的货位的储存信息生成盘点单,一个仓库一个盘点单据 if (ware != null && ware != string.Empty) { ware = ware.Substring(0, ware.Length - 1); var wares = wareQuery.Where(w => ware.Contains(w.WarehouseCode)).ToArray(); foreach (var item in wares) { var storages = storageQuery.Where(s => s.Cell.WarehouseCode == item.WarehouseCode && s.Quantity > 0 && s.IsLock == "0") .OrderBy(s => s.StorageCode) .Select(s => s).ToArray(); if (storages.Any()) { string billNo = GetCheckBillNo().ToString(); var check = new CheckBillMaster(); check.BillNo = billNo; check.BillDate = DateTime.Now; check.BillTypeCode = billType; check.WarehouseCode = item.WarehouseCode; check.OperatePersonID = employee.ID; check.Status = "1"; check.IsActive = "1"; check.UpdateTime = DateTime.Now; CheckBillMasterRepository.Add(check); storages.AsParallel().ForAll(stor => { var checkDetail = new CheckBillDetail(); checkDetail.CellCode = stor.CellCode; checkDetail.StorageCode = stor.StorageCode; checkDetail.ProductCode = stor.ProductCode; checkDetail.UnitCode = stor.Product.UnitCode; checkDetail.Quantity = stor.Quantity; checkDetail.RealProductCode = stor.ProductCode; checkDetail.RealUnitCode = stor.Product.UnitCode; checkDetail.RealQuantity = stor.Quantity; checkDetail.Status = "0"; lock (check.CheckBillDetails) { check.CheckBillDetails.Add(checkDetail); } stor.IsLock = "1"; }); result = true; } else { info = "所选择的货位无数据!"; } } } #endregion #region ware 这个无值,把全部仓库里面包含area,shelf,cell的数据生成盘点单,一个仓库一个盘点单据 if (area != null && area != string.Empty || shelf != null && shelf != string.Empty || cell != null && cell != string.Empty) { if (area != string.Empty) { area = area.Substring(0, area.Length - 1); } if (shelf != string.Empty) { shelf = shelf.Substring(0, shelf.Length - 1); } if (cell != string.Empty) { cell = cell.Substring(0, cell.Length - 1); } var warehouses = wareQuery.OrderBy(w => w.WarehouseCode); foreach (var item in warehouses.ToArray()) { var storages = storageQuery.Where(s => s.Cell.WarehouseCode == item.WarehouseCode && (area.Contains(s.Cell.Shelf.Area.AreaCode) || shelf.Contains(s.Cell.Shelf.ShelfCode) || cell.Contains(s.Cell.CellCode)) && s.Quantity > 0 && s.IsLock == "0") .OrderBy(s => s.StorageCode) .Select(s => s).ToArray(); if (storages.Any()) { string billNo = GetCheckBillNo().ToString(); var check = new CheckBillMaster(); check.BillNo = billNo; check.BillDate = DateTime.Now; check.BillTypeCode = billType; check.WarehouseCode = item.WarehouseCode; check.OperatePersonID = employee.ID; check.Status = "1"; check.IsActive = "1"; check.UpdateTime = DateTime.Now; CheckBillMasterRepository.Add(check); storages.AsParallel().ForAll(stor => { var checkDetail = new CheckBillDetail(); checkDetail.CellCode = stor.CellCode; checkDetail.StorageCode = stor.StorageCode; checkDetail.ProductCode = stor.ProductCode; checkDetail.UnitCode = stor.Product.UnitCode; checkDetail.Quantity = stor.Quantity; checkDetail.RealProductCode = stor.ProductCode; checkDetail.RealUnitCode = stor.Product.UnitCode; checkDetail.RealQuantity = stor.Quantity; checkDetail.Status = "0"; lock (check.CheckBillDetails) { check.CheckBillDetails.Add(checkDetail); } stor.IsLock = "1"; }); result = true; } } } #endregion sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); sw.Restart(); CheckBillMasterRepository.SaveChanges(); sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); scope.Complete(); } } catch (Exception e) { result = false; info = e.Message; } } else { info = "当前登陆用户为空!请重新登陆!"; } return(result); }
/// <summary> /// 根据参数生成并保存盘点数据 --产品生成 /// </summary> /// <param name="products">产品数据</param> /// <param name="UserName">登陆用户</param> /// <returns></returns> public bool ProductAdd(string products, string UserName, string billType, out string info) { bool result = false; info = string.Empty; IQueryable <Warehouse> wareQuery = WarehouseRepository.GetQueryable(); IQueryable <Storage> storageQuery = StorageRepository.GetQueryable(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.UserName == UserName); if (employee != null) { if (products != null && products != string.Empty) { products = products.Substring(0, products.Length - 1); try { using (var scope = new TransactionScope()) { #region products 这个有值,就把这个值里面所有的卷烟信息所在的仓库的货位的储存信息生成盘点单,一个仓库一个盘点单据 var warehouses = wareQuery.OrderBy(w => w.WarehouseCode); foreach (var item in warehouses.ToArray()) { var storages = storageQuery.Where(s => s.ProductCode != null && products.Contains(s.ProductCode) && s.Cell.Shelf.Area.Warehouse.WarehouseCode == item.WarehouseCode && s.Quantity > 0 && s.IsLock == "0") .OrderBy(s => s.StorageCode).AsEnumerable() .Select(s => new { s.StorageCode, s.Cell.CellCode, s.Cell.CellName, s.Product.ProductCode, s.Product.ProductName, s.Product.Unit.UnitCode, s.Product.Unit.UnitName, Quantity = s.Quantity / s.Product.Unit.Count, s.Product.Unit.Count, IsActive = s.IsActive == "1" ? "可用" : "不可用", StorageTime = s.StorageTime.ToString("yyyy-MM-dd"), UpdateTime = s.UpdateTime.ToString("yyyy-MM-dd") }); if (storages.Count() > 0) { string billNo = GetCheckBillNo().ToString(); var check = new CheckBillMaster(); check.BillNo = billNo; check.BillDate = DateTime.Now; check.BillTypeCode = billType; check.WarehouseCode = item.WarehouseCode; check.OperatePersonID = employee.ID; check.Status = "1"; check.IsActive = "1"; check.UpdateTime = DateTime.Now; CheckBillMasterRepository.Add(check); CheckBillMasterRepository.SaveChanges(); foreach (var stor in storages.ToArray()) { var checkDetail = new CheckBillDetail(); checkDetail.BillNo = billNo; checkDetail.CellCode = stor.CellCode; checkDetail.StorageCode = stor.StorageCode; checkDetail.ProductCode = stor.ProductCode; checkDetail.UnitCode = stor.UnitCode; checkDetail.Quantity = stor.Quantity * stor.Count; checkDetail.RealProductCode = stor.ProductCode; checkDetail.RealUnitCode = stor.UnitCode; checkDetail.RealQuantity = stor.Quantity * stor.Count; checkDetail.Status = "1"; CheckBillDetailRepository.Add(checkDetail); CheckBillDetailRepository.SaveChanges(); var storage = storageQuery.FirstOrDefault(s => s.StorageCode == stor.StorageCode); storage.IsLock = "1"; StorageRepository.SaveChanges(); } result = true; } else { info = "所选择的产品无数据!"; } } #endregion scope.Complete(); } } catch (Exception e) { info = e.Message; } } else { info = "产品信息为空!无法生成!"; } } else { info = "当前登陆用户为空!请重新登陆!"; } return(result); }
/// <summary> /// 根据参数生成并保存盘点数据 --货位生成 /// </summary> /// <param name="ware">仓库</param> /// <param name="area">库区</param> /// <param name="shelf">货架</param> /// <param name="cell">货位</param> /// <param name="UserName">登陆用户</param> /// <returns></returns> public bool CellAdd(string ware, string area, string shelf, string cell, string UserName, string billType, out string info) { bool result = false; info = string.Empty; IQueryable <Warehouse> wareQuery = WarehouseRepository.GetQueryable(); IQueryable <Storage> storageQuery = StorageRepository.GetQueryable(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.UserName == UserName); if (employee != null) { try { using (var scope = new TransactionScope()) { #region ware 这个有值,就把这个值里面所有的仓库的货位的储存信息生成盘点单,一个仓库一个盘点单据 if (ware != null && ware != string.Empty) { ware = ware.Substring(0, ware.Length - 1); var wares = wareQuery.Where(w => ware.Contains(w.WarehouseCode)); foreach (var item in wares.ToArray()) { var storages = storageQuery.Where(s => s.Cell.Shelf.Area.Warehouse.WarehouseCode == item.WarehouseCode && s.Quantity > 0 && s.IsLock == "0") .OrderBy(s => s.StorageCode).AsEnumerable() .Select(s => new { s.StorageCode, s.Cell.CellCode, s.Cell.CellName, s.IsLock, s.Product.ProductCode, s.Product.ProductName, s.Product.Unit.UnitCode, s.Product.Unit.UnitName, Quantity = s.Quantity / s.Product.Unit.Count, s.Product.Unit.Count, IsActive = s.IsActive == "1" ? "可用" : "不可用", StorageTime = s.StorageTime.ToString("yyyy-MM-dd"), UpdateTime = s.UpdateTime.ToString("yyyy-MM-dd") }); if (storages.Count() > 0) { string billNo = GetCheckBillNo().ToString(); var check = new CheckBillMaster(); check.BillNo = billNo; check.BillDate = DateTime.Now; check.BillTypeCode = billType; check.WarehouseCode = item.WarehouseCode; check.OperatePersonID = employee.ID; check.Status = "1"; check.IsActive = "1"; check.UpdateTime = DateTime.Now; CheckBillMasterRepository.Add(check); CheckBillMasterRepository.SaveChanges(); foreach (var stor in storages.ToArray()) { var checkDetail = new CheckBillDetail(); checkDetail.BillNo = billNo; checkDetail.CellCode = stor.CellCode; checkDetail.StorageCode = stor.StorageCode; checkDetail.ProductCode = stor.ProductCode; checkDetail.UnitCode = stor.UnitCode; checkDetail.Quantity = stor.Quantity * stor.Count; checkDetail.RealProductCode = stor.ProductCode; checkDetail.RealUnitCode = stor.UnitCode; checkDetail.RealQuantity = stor.Quantity * stor.Count; checkDetail.Status = "1"; CheckBillDetailRepository.Add(checkDetail); CheckBillDetailRepository.SaveChanges(); var storage = storageQuery.FirstOrDefault(s => s.StorageCode == stor.StorageCode); storage.IsLock = "1"; StorageRepository.SaveChanges(); scope.Complete(); } result = true; } else { info = "所选择的货位无数据!"; } } } #endregion #region ware 这个无值,把全部仓库里面包含area,shelf,cell的数据生成盘点单,一个仓库一个盘点单据 if (area != null && area != string.Empty || shelf != null && shelf != string.Empty || cell != null && cell != string.Empty) { if (area != string.Empty) { area = area.Substring(0, area.Length - 1); } if (shelf != string.Empty) { shelf = shelf.Substring(0, shelf.Length - 1); } if (cell != string.Empty) { cell = cell.Substring(0, cell.Length - 1); } var warehouses = wareQuery.OrderBy(w => w.WarehouseCode); foreach (var item in warehouses.ToArray()) { var storages = storageQuery.ToList().Where(s => s.Cell.Shelf.Area.Warehouse.WarehouseCode == item.WarehouseCode && (area.Contains(s.Cell.Shelf.Area.AreaCode) || shelf.Contains(s.Cell.Shelf.ShelfCode) || cell.Contains(s.Cell.CellCode)) && s.Quantity > 0 && s.IsLock == "0") .OrderBy(s => s.StorageCode).AsEnumerable() .Select(s => new { s.StorageCode, s.Cell.CellCode, s.Cell.CellName, s.Product.ProductCode, s.Product.ProductName, s.Product.Unit.UnitCode, s.Product.Unit.UnitName, Quantity = s.Quantity / s.Product.Unit.Count, s.Product.Unit.Count, IsActive = s.IsActive == "1" ? "可用" : "不可用", StorageTime = s.StorageTime.ToString("yyyy-MM-dd"), UpdateTime = s.UpdateTime.ToString("yyyy-MM-dd") }); if (storages.Count() > 0) { string billNo = GetCheckBillNo().ToString(); var check = new CheckBillMaster(); check.BillNo = billNo; check.BillDate = DateTime.Now; check.BillTypeCode = billType; check.WarehouseCode = item.WarehouseCode; check.OperatePersonID = employee.ID; check.Status = "1"; check.IsActive = "1"; check.UpdateTime = DateTime.Now; CheckBillMasterRepository.Add(check); CheckBillMasterRepository.SaveChanges(); foreach (var stor in storages.ToArray()) { var checkDetail = new CheckBillDetail(); checkDetail.BillNo = billNo; checkDetail.CellCode = stor.CellCode; checkDetail.StorageCode = stor.StorageCode; checkDetail.ProductCode = stor.ProductCode; checkDetail.UnitCode = stor.UnitCode; checkDetail.Quantity = stor.Quantity * stor.Count; checkDetail.RealProductCode = stor.ProductCode; checkDetail.RealUnitCode = stor.UnitCode; checkDetail.RealQuantity = stor.Quantity * stor.Count; checkDetail.Status = "1"; CheckBillDetailRepository.Add(checkDetail); CheckBillDetailRepository.SaveChanges(); var storage = storageQuery.FirstOrDefault(s => s.StorageCode == stor.StorageCode); storage.IsLock = "1"; StorageRepository.SaveChanges(); scope.Complete(); } result = true; } } } #endregion scope.Complete(); } } catch (Exception e) { info = e.Message; } } else { info = "当前登陆用户为空!请重新登陆!"; } return(result); }