IDHelper.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Common.Model;
  2. using Common.Wechat;
  3. using CoreEntity.DAL;
  4. using CoreEntity.Entity;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Text;
  10. using ZcPeng.PublicLibrary;
  11. namespace CoreEntity.BAL
  12. {
  13. class IDHelper
  14. {
  15. /// <summary>
  16. /// 订单汇总里面关键的几个字段
  17. ///一个是billno在智友的syscode表中prefix = 'F'的即为最大编号,
  18. ///一个是billcode在智友的billcode表中,需要对应的是采购订单的RULEID(固定5x80rrxrb24q2ktt),
  19. ///从billcode表中取到recnum,billcode的生成规则:PDD+机构标识+8位长度的流水码(recnum,不足补零)例如PDD+Y30+00000058
  20. ///订单明细中没有BILLCODE,但是有billsn,即明细的序号
  21. /// </summary>
  22. /// <returns></returns>
  23. public static long GetRecNo()
  24. {
  25. long id = 0;
  26. #region 查id
  27. string commandTextUser = "Select RecNum From "
  28. + "SysCode Where Prefix=@Prefix";
  29. string resultUser;
  30. DataTable dt = new DataTable();
  31. List<SqlParameter> parametersUser = new List<SqlParameter>();
  32. parametersUser.Add(new SqlParameter("Prefix", 'F'));
  33. //DataAccess.GetValues(commandTextUser, ref dt, parametersUser.ToArray(), out resultUser);
  34. //List<SysCode> users = new List<SysCode>();
  35. //users = (List<SysCode>)ModelConvertHelper<SysCode>.ConvertToModel(dt);
  36. //SysCode user = users.ToArray()[0];
  37. //id = user.RECNUM;
  38. SqlConnection conn = null;
  39. SqlTransaction tran = null;
  40. bool successUser = DataAccess.GetOneValue(commandTextUser, parametersUser.ToArray(), out var v, out resultUser, out conn, out tran, true);
  41. id = long.Parse(v.ToString());
  42. string commandText = "Update " + "SysCode set RecNum = @id +1 " +
  43. " Where Prefix=@Prefix ;" + commandTextUser;
  44. string result;
  45. List<SqlParameter> parameters = new List<SqlParameter>();
  46. parameters.Add(new SqlParameter( "id", id));
  47. parameters.Add(new SqlParameter( "Prefix", 'F'));
  48. List<DataAccessCommand> list = new List<DataAccessCommand>();
  49. list.Add(new DataAccessCommand(commandText, parameters, CommandType.Text, true));
  50. bool success = DataAccess.ExecuteBatchCommands(list, out result,conn,tran);
  51. //bool success = DataAccess.GetOneValue(commandText,parameters, out var v, out result);
  52. //id = (long)v;
  53. #endregion
  54. if (success)
  55. return id + 1;
  56. return 0;
  57. }
  58. public static void Main(string[] args)
  59. {
  60. var id = IDHelper.GetRecNo();
  61. string orderNo = id.ToString();
  62. StringBuilder sb = new StringBuilder("");
  63. if (orderNo.Length < 8)
  64. {
  65. for (int ik = 0; ik < (8 - orderNo.Length); ik++)
  66. {
  67. sb.Append('0');
  68. }
  69. sb.Append(orderNo);
  70. }
  71. //string orgno = OrgDAL.GetOrgNo("","");//PurOrderDAL.ORGID
  72. //String OrderCode = "PJH" + orgno//机构标识
  73. // + sb.ToString();
  74. Console.Write("文本-:"+id);
  75. }
  76. }
  77. }