FmsStockManager.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using DbCommon.BusinessCore.DbCore;
  2. using DbCommon.Enties.DbModels;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace DbCommon.BusinessCore.BaseCore
  9. {
  10. public class FmsStockManager : FmsDbContext<FmsStock>
  11. {
  12. public void Init()
  13. {
  14. //If no exist create datebase
  15. //Db.DbMaintenance.CreateDatabase();
  16. if (!Db.DbMaintenance.IsAnyTable("barcodesforagv"))
  17. {
  18. //Create tables
  19. Db.CodeFirst.InitTables(typeof(FmsStock));
  20. }
  21. }
  22. public int CountMaterial(string material)
  23. {
  24. return Db.Queryable<FmsStock>()
  25. .Where(d => d.StockCode == material && d.Flag == 0)
  26. .Select(f => f.StockCode)
  27. .Count();
  28. }
  29. public bool UpdateFlag(string material)
  30. {
  31. return CurrentDb.Update(
  32. d => new FmsStock()
  33. {
  34. Flag = 1,
  35. },
  36. d => d.StockCode == material && d.Flag == 0);
  37. }
  38. public bool UpdateFlag(string[] materialArray)
  39. {
  40. return CurrentDb.Update(
  41. d => new FmsStock()
  42. {
  43. Flag = 1,
  44. },
  45. d => materialArray.Contains(d.StockCode) && d.Flag == 0);
  46. }
  47. public bool UpdateAllFlag()
  48. {
  49. return CurrentDb.Update(
  50. d => new FmsStock()
  51. {
  52. Flag = 1,
  53. },
  54. d => d.Flag == 0);
  55. }
  56. }
  57. }