packinfo.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "packinfo.h"
  2. #include "globalinfo.h"
  3. #include <QDateTime>
  4. int PackInfo::lastMin = 0;
  5. int PackInfo::lastNum = 1;
  6. PackInfo::PackInfo(const ProjectInfo & info) : _info(info)
  7. {
  8. code_single = buildPackId();
  9. goods_id = info.goods_id;
  10. }
  11. BoxInfo::BoxInfo(QSharedPointer<PackInfo> pack,QString code):case_number(code),parent(pack)
  12. {}
  13. QString PackInfo::buildPackId()
  14. {
  15. QDateTime now = QDateTime::currentDateTime();
  16. int min = now.time().minute();
  17. if(min != lastMin) lastNum = 1;
  18. else lastNum ++;
  19. QString packId = GlobalInfo::this_()->packNum() + now.toString("yyMMddhhmmss") + QString::asprintf("%03d",lastNum);
  20. if(lastNum > 999) return QString();
  21. return packId;
  22. }
  23. QString PackInfo::buildBoxId()
  24. {
  25. int nowNum = boxes().size() + 1;
  26. QDateTime now = QDateTime::currentDateTime();
  27. QString id = now.toString("yyMMddhhmmss") + /*GlobalInfo::this_()->packNum() +*/ QString::asprintf("%03d",nowNum);
  28. return id;
  29. }
  30. int PackInfo::tube_number()
  31. {
  32. int ret = 0;
  33. for(int i = 0; i < _boxes.size();++i){
  34. ret += _boxes.at(i)->tube_number;
  35. }
  36. return ret;
  37. }
  38. int PackInfo::gross_weight()
  39. {
  40. int ret = 0;
  41. for(int i = 0; i < _boxes.size();++i){
  42. ret += _boxes.at(i)->gross_weight;
  43. }
  44. return ret;
  45. }
  46. int PackInfo::net_weight()
  47. {
  48. int ret = 0;
  49. for(int i = 0; i < _boxes.size();++i){
  50. ret += _boxes.at(i)->net_weight;
  51. }
  52. return ret;
  53. }
  54. QSharedPointer<BoxInfo> PackInfo::addBoxInfo()
  55. {
  56. QSharedPointer<BoxInfo> ret(new BoxInfo(sharedFromThis(),buildBoxId()));
  57. return ret;
  58. }
  59. void PackInfo::addBoxInfoList(QSharedPointer<BoxInfo> boxes)
  60. {
  61. _boxes.append(boxes);
  62. }
  63. void PackInfo::delBoxInfoAt(int num)
  64. {
  65. qDebug()<<"size"<<_boxes.size();
  66. qDebug()<<"num"<<num;
  67. _boxes.removeAt(num);
  68. }
  69. QSharedPointer<BoxInfo> PackInfo::boxInfoAt(int num)
  70. {
  71. return _boxes.at(num);
  72. }
  73. int PackInfo::boxInfoSize()
  74. {
  75. return _boxes.size();
  76. }