UpdateBarCodeNew.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UFSoft.UBF.PL.Engine.Cache;
  7. using UFSoft.UBF.Util.DataAccess;
  8. using UFSoft.UBF.Util.Log;
  9. namespace UFIDA.U9.Cust.KuSi.zhangky.BPSVPlug
  10. {
  11. internal class UpdateBarCodeNew
  12. {
  13. public static void Update(long id, string entityType, string barcode, long binid, string binCode, string binName, long whid, string whCode, string whName)
  14. {
  15. string strTmp;
  16. ILogger logger = LoggerManager.GetLogger("BPSVPlug_UpdateBarCodeNew------");
  17. if (string.IsNullOrEmpty(barcode))
  18. {
  19. strTmp = "UseDocLine.EntityID=@ID and UseDocLine.EntityType=@EntityType order by CreatedOn desc";
  20. }
  21. else
  22. {
  23. strTmp = "UseDocLine.EntityID=@ID and UseDocLine.EntityType=@EntityType and BarCode='" + barcode + "' order by CreatedOn desc";
  24. }
  25. if (entityType.Contains("TransferFormL") || entityType.Contains("TransferFormSL") || entityType.Contains("TransInSubLine") || entityType.Contains("MiscRcvTransBin"))
  26. {
  27. strTmp = strTmp.Replace("UseDocLine", "CreateEntity");
  28. }
  29. logger.Error(string.Format("-------1开始找条码使用档 {0},{1}", id.ToString(),entityType));
  30. UFIDA.U9.BC.BaseData.BarCodeUsed.EntityList tmp = UFIDA.U9.BC.BaseData.BarCodeUsed.Finder.FindAll(strTmp
  31. , new UFSoft.UBF.PL.OqlParam[]
  32. {
  33. new UFSoft.UBF.PL.OqlParam(id),
  34. new UFSoft.UBF.PL.OqlParam(entityType)
  35. });
  36. if (tmp != null && tmp.Count > 0)
  37. {
  38. logger.Error(string.Format("-------2找到条码使用档 {0},{1}", id.ToString(), entityType));
  39. List<UFIDA.U9.BC.BaseData.BarCodeUsed> list = Distinct(tmp);
  40. logger.Error(string.Format("-------3去重 {0},{1}", id.ToString(), entityType));
  41. foreach (var barCodeUsed in list)
  42. {
  43. StringBuilder sql = new StringBuilder();
  44. sql.Append(string.Format
  45. ("if not exists(select 1 from BC_BarCodeUsed_Trl with (nolock) where id={0} and SysMLFlag='zh-CN') begin insert into BC_BarCodeUsed_Trl(ID, SysMLFlag) values({1}, 'zh-CN') end if not exists(select 1 from BC_BarCode_Trl with (nolock) where id={2} and SysMLFlag='zh-CN') begin insert into BC_BarCode_Trl(ID,SysMLFlag) values({3},'zh-CN') end ", barCodeUsed.ID, barCodeUsed.ID, barCodeUsed.BarCodeMaster.ID, barCodeUsed.BarCodeMaster.ID));
  46. DataAccessor.RunSQL(DataAccessor.GetConn(), sql.ToString(), null);
  47. barCodeUsed.SetValue("Cust4Binid", binid);
  48. barCodeUsed.SetValue("Cust4Bincode", binCode);
  49. barCodeUsed.SetValue("Cust4Binname", binName);
  50. barCodeUsed.BarCodeMaster.SetValue("Cust4Binid", binid);
  51. barCodeUsed.BarCodeMaster.SetValue("Cust4Bincode", binCode);
  52. barCodeUsed.BarCodeMaster.SetValue("Cust4Binname", binName);
  53. if (whid != 0)
  54. {
  55. barCodeUsed.SetValue("Cust4Whid", whid);
  56. barCodeUsed.SetValue("Cust4Whcode", whCode);
  57. barCodeUsed.SetValue("Cust4Whname", whName);
  58. barCodeUsed.BarCodeMaster.SetValue("Cust4Whid", whid);
  59. barCodeUsed.BarCodeMaster.SetValue("Cust4Whcode", whCode);
  60. barCodeUsed.BarCodeMaster.SetValue("Cust4Whname", whName);
  61. }
  62. logger.Error(string.Format("-------4更新库位 {0},{1},{2},{3}", barCodeUsed.ID, barCodeUsed.BarCode, binCode, whCode));
  63. }
  64. }
  65. }
  66. private static List<UFIDA.U9.BC.BaseData.BarCodeUsed> Distinct(UFIDA.U9.BC.BaseData.BarCodeUsed.EntityList list)
  67. {
  68. Dictionary<string, UFIDA.U9.BC.BaseData.BarCodeUsed> dic = new Dictionary<string, UFIDA.U9.BC.BaseData.BarCodeUsed>();
  69. foreach (var barCodeUsed in list)
  70. {
  71. if (!dic.ContainsKey(barCodeUsed.BarCode))
  72. {
  73. dic.Add(barCodeUsed.BarCode, barCodeUsed);
  74. }
  75. }
  76. return new List<UFIDA.U9.BC.BaseData.BarCodeUsed>(dic.Values);
  77. }
  78. }
  79. }