条形码扫描示例程序

来源:互联网 发布:网络对学生的坏处 编辑:程序博客网 时间:2024/05/06 06:25
  1. /*
  2. 适用8300版本
  3. M/D : 2007.5.14 
  4. KNL : 8300K-3.23 
  5. LIB : 8300L-2.21 
  6. */
  7. #include <8300lib.h>
  8. #include <ucos.h>
  9. #include <stdlib.h>
  10. #define  BYTE      unsigned char
  11. #define  BOOL      unsigned char
  12. #define  ULONG     unsigned long
  13. #define  TRUE      1
  14. #define  FALSE     0
  15. #define  CANCEL    2
  16. #define  Ymax    5
  17. #define  Xmax    20
  18. static char *ACK = "ACK/r";
  19. static char *NAK = "NAK/r";
  20. int    beep1[4] = {16, 5, 0, 0};
  21. int    beep2[8] = {30, 10, 0, 5, 30, 10, 0, 0};
  22. int    beep3[8] = {30, 50, 0, 5, 30, 50, 0, 0};
  23. int    beep4[4] = {30, 150, 0, 0};
  24. //************************VAR***********************************#define  NULL      0x00*******//
  25. //void flip_page(char page[][Xmax], int rowcount);  //将page中的内容显示出来,按UP、DOWN键上、下翻动
  26. int InputData(char* databuf, int maxbit, int x, int y); //数据采集
  27. int InputData2(char* databuf, int maxbit, int x, int y);
  28. void backlight();   //设置背光
  29. int bklt_flag = 0;
  30. static BOOL ConnectingPage (void);  //联接等待界面
  31. //BOOL DownloadLookup (char* filename, int record_len, int key_offset, int key_len);
  32. //          //数据下载到filename中,记录长度为record_len,索引开始位置为key_offset,长度为key_len
  33. BOOL UploadDBF (int fDbf);      //数据上传
  34. void record_save(char* record, char* filename);
  35. void shangchuan(void);
  36. void ntos(char ns[], long n, unsigned count);
  37. char date[11]; 
  38. char time[11]; 
  39. /*-----------函数声明--------------------*/
  40. void Login(void);   //登陆界面
  41. void MainMenu(void);    //主菜单
  42. void getDatetime(void); //登陆界面显示的时间
  43. void SetClock(void);    //设置时间
  44. void scan_barcode(void);//扫描条码
  45. void transmit(void);    //传输
  46. void del_data(void);    //清除
  47. void caiji(void);
  48. int caiji2(void);
  49. void chaxun(void);//查询删除
  50. void chaxun2(void);
  51. void xiugai(void);//修改
  52. /*-----------变量------------------------*/
  53. char riqi[9];//日期
  54. char chehao[5];//车号
  55. char zuhao[5];//组号
  56. char xuhao[4];//序号
  57. char kunhao[17];//捆号
  58. char zhongliang[11];//重量
  59. char all[46];
  60. int connect_port =0;
  61. /*******************************************************************/
  62. void main()
  63. {
  64.     //SetFont(FONT_6X8);
  65.     SetFont(FONT_6X12);
  66.     SetVideoMode(0);
  67.     SetCursor(0);
  68.     
  69.         while(1)
  70.         {
  71.             Login();          /*登录界面*/       
  72.             MainMenu();   /*应用功能菜单*/
  73.         }
  74. }
  75. void  Login(void)
  76. {
  77.     while(1)
  78.     { 
  79.         clr_scr();
  80.         gotoxy(0,1);
  81.         printf("铝锭条码离线扫描系统");
  82.         gotoxy(0,3);
  83.         printf("      版本V1.0.0    ");
  84.         gotoxy(0,4);
  85.         getDatetime();
  86.         printf("      %s",date);
  87.         OSTimeDly (300);
  88.         on_beeper (beep4);
  89.         return;
  90.     }
  91. }
  92. void  MainMenu(void)
  93. {
  94.     int ret,f_hd;
  95.     char key;
  96.     
  97.     if (!access("DATA"))
  98.     {
  99.         f_hd = create_DBF ("DATA", 45);     
  100.         create_index (f_hd, 1, 0, 12);      
  101.         create_index (f_hd, 2, 0, 16);
  102.         create_index (f_hd, 3, 0, 19);
  103.         close_DBF(f_hd);    
  104.     }
  105.     
  106.     while(1)
  107.     {
  108.         clr_scr();
  109.         gotoxy(0,1);
  110.         printf("     1 数据采集     ");
  111.         gotoxy(0,2);
  112.         printf("     2 删除修改     ");
  113.         gotoxy(0,3);
  114.         printf("     3 资料上传     ");
  115.         for (;!kbhit(););
  116.         switch (key = getchar())
  117.         {
  118.             case KEY_F7: backlight();break;
  119.             case '1': caiji();break;    
  120.             case '2': chaxun();break;
  121.             //case '3': xiugai();break; 
  122.             case '3': shangchuan();break;
  123.             case KEY_ESC: return;
  124.         }   
  125.     } 
  126. }
  127. void chaxun(void)
  128. {
  129.     int ret1,ret2,ret3,ret4,i;
  130.     char riqi1[9],chehao1[5],zuhao1[5];
  131.     while(1)
  132.     {
  133.         memset(riqi,' ',9);
  134.         riqi[8] = 0;
  135.         memset(chehao,' ',5);
  136.         chehao[4] = 0;
  137.         memset(zuhao,' ',5);
  138.         zuhao[4] = 0;
  139.         clr_scr();
  140.         gotoxy(0,0);
  141.         printf("请输入:");
  142.         gotoxy(0,1);
  143.         printf("日期:%s",riqi);
  144.         gotoxy(0,2);
  145.         printf("车号:%s",chehao);
  146.         gotoxy(0,3);
  147.         printf("组号:%s",zuhao);
  148.         for(;;)
  149.         {
  150.             memset(riqi1,0x00,9);
  151.             memset(chehao1,0x00,5);
  152.             memset(zuhao1,0x00,5);
  153.             clr_scr();
  154.             gotoxy(0,0);
  155.             printf("请输入:");
  156.             gotoxy(0,1);
  157.             printf("日期:%s",riqi);
  158.             gotoxy(0,2);
  159.             printf("车号:%s",chehao);
  160.             gotoxy(0,3);
  161.             printf("组号:%s",zuhao);
  162.             ret1 = InputData2(riqi1, 8, 5, 1);
  163.             if (ret1 == 0)//没输入就按回车
  164.             {
  165.                 memset(riqi1,' ',9);
  166.                 riqi1[8] = 0;
  167.                 continue;
  168.             }
  169.             if (ret1 == 1)//按ESC
  170.             {
  171.                 return;
  172.             }
  173.             if (ret1 == 2)//正常
  174.             {
  175.                 for(i=0;i<strlen(riqi1);i++)
  176.                 {
  177.                     riqi[i] = riqi1[i];
  178.                 }
  179.                 for(;;)
  180.                 {
  181.                     clr_scr();
  182.                     gotoxy(0,0);
  183.                     printf("请输入:");
  184.                     gotoxy(0,1);
  185.                     printf("日期:%s",riqi);
  186.                     gotoxy(0,2);
  187.                     printf("车号:%s",chehao);
  188.                     gotoxy(0,3);
  189.                     printf("组号:%s",zuhao);
  190.                     ret2 = InputData2(chehao1, 4, 5, 2);
  191.                     if (ret2 == 0)//没输入就按回车
  192.                     {
  193.                         memset(chehao1,' ',5);
  194.                         chehao1[4] = 0;
  195.                         continue;
  196.                     }
  197.                     if (ret2 == 1)//按ESC
  198.                     {
  199.                         return;
  200.                     }
  201.                     if (ret2 == 2)//正常
  202.                     {
  203.                         for(i=0;i<strlen(chehao1);i++)
  204.                         {
  205.                             chehao[i] = chehao1[i];
  206.                         }
  207.                         for(;;)
  208.                         {
  209.                             clr_scr();
  210.                             gotoxy(0,0);
  211.                             printf("请输入:");
  212.                             gotoxy(0,1);
  213.                             printf("日期:%s",riqi);
  214.                             gotoxy(0,2);
  215.                             printf("车号:%s",chehao);
  216.                             gotoxy(0,3);
  217.                             printf("组号:%s",zuhao);
  218.                             ret3 = InputData2(zuhao1, 4, 5, 3);
  219.                             if (ret3 == 0)//没输入就按回车
  220.                             {
  221.                                 memset(zuhao1,' ',5);
  222.                                 zuhao1[4] = 0;
  223.                                 continue;
  224.                             }
  225.                             if (ret3 == 1)//按ESC
  226.                             {
  227.                                 return;
  228.                             }
  229.                             if (ret3 == 2)//正常
  230.                             {
  231.                                 for(i=0;i<strlen(zuhao1);i++)
  232.                                 {
  233.                                     zuhao[i] = zuhao1[i];
  234.                                 }
  235.                                 
  236.                                     chaxun2();
  237.                                     return;
  238.                                     
  239.                             }
  240.                         }
  241.                     }
  242.                 }
  243.             }
  244.         }
  245.     } 
  246. }
  247. void chaxun2(void)
  248. {
  249.     char rcz[17],buf[46],buf2[46];
  250.     char xianshixuhao[4],xianshishuliang[4],xianshikunhao[17],xianshizhongliang[11];
  251.     int zukunshu;
  252.     int guangbiao;
  253.     int i,n,j;
  254.     int f_hd;
  255.     char key;
  256.     int temp1,temp2;
  257.     int ret1,ret;
  258.     char input1[17],input2[11],disinput1[17],disinput2[11];
  259.     char temp3[4],temp4[4];
  260.     
  261.         memset(rcz,0x00,17);
  262.         strcat(rcz,riqi);
  263.         strcat(rcz,chehao);
  264.         strcat(rcz,zuhao);
  265.         
  266. /*-----------------初始化光标位置-------------------------*/   
  267.     f_hd = open_DBF((char *)"DATA");
  268.         n = member_in_DBF (f_hd);
  269.         for(i=0;i<n;i++)
  270.         {
  271.             memset(buf,0x00,46);
  272.             lseek_DBF(f_hd, 2, i, 1);
  273.             get_member(f_hd,2,(char*)buf);
  274.             if(strncmp(buf,rcz,16) == 0)
  275.             {
  276.                 guangbiao = i;
  277.                 break;
  278.             }
  279.         }
  280.         close_DBF(f_hd);
  281. /*------------------------------- -------------------------*/           
  282.         
  283.     for(;;)
  284.     {
  285.         
  286.         /*--------------检测是否有数据---------------------------*/
  287.         f_hd = open_DBF((char *)"DATA");
  288.         if(has_member(f_hd,2,(char*)rcz) == 1)
  289.         {
  290.             close_DBF(f_hd);
  291.         }
  292.         else
  293.         {
  294.             close_DBF(f_hd);
  295.             clr_scr();
  296.             gotoxy(0,2);
  297.             printf("  无当前组号记录! ");
  298.             OSTimeDly (300);
  299.             return;
  300.         }
  301.         
  302.         /*------------求相同组数量-----------------*/
  303.         zukunshu = 0;
  304.         memset(buf,0x00,46);
  305.         f_hd = open_DBF((char *)"DATA");
  306.         n = member_in_DBF (f_hd);
  307.         for(i=0;i<n;i++)
  308.         {
  309.             memset(buf,0x00,46);
  310.             lseek_DBF(f_hd, 2, i, 1);
  311.             get_member(f_hd,2,(char*)buf);
  312.             if(strncmp(buf,rcz,16) == 0)
  313.             {
  314.                 zukunshu = zukunshu+1;
  315.             }
  316.         }
  317.         close_DBF(f_hd);
  318.         /*-----------移动到光标位置,取数据------------------*/
  319.         f_hd = open_DBF((char *)"DATA");
  320.         lseek_DBF(f_hd, 2, guangbiao, 1);
  321.         memset(buf,0x00,46);
  322.         get_member(f_hd,2,(char*)buf);
  323.         memset(xianshixuhao,0x00,4);
  324.         memset(xianshikunhao,0x00,17);
  325.         memset(xianshizhongliang,0x00,11);
  326.         for(i = 16;i<19;i++)
  327.         {
  328.             xianshixuhao[i-16] = buf[i];
  329.         }
  330.         for(i = 19;i<34;i++)
  331.         {
  332.             xianshikunhao[i-19] = buf[i];
  333.         }
  334.         for(i = 35;i<44;i++)
  335.         {
  336.             xianshizhongliang[i-35] = buf[i];
  337.         }
  338.         close_DBF(f_hd);
  339.         
  340.         clr_scr();
  341.         gotoxy(0,0);
  342.         printf("序号/组数量          ");
  343.         gotoxy(13,0);
  344.         printf("%s",xianshixuhao);
  345.         gotoxy(16,0);
  346.         printf("/%d",zukunshu);
  347.         gotoxy(0,1);
  348.         printf("%s",riqi);
  349.         gotoxy(9,1);
  350.         printf("%s",chehao);
  351.         gotoxy(13,1);
  352.         printf("%s",zuhao);
  353.         gotoxy(0,2);
  354.         printf("捆号:%s",xianshikunhao);
  355.         gotoxy(0,3);
  356.         printf("重量:%s",xianshizhongliang);
  357.         gotoxy(0,4);
  358.         printf("F1:删除      F3:修改");
  359.         
  360.         for (;!kbhit(););
  361.         switch (key = getchar())
  362.         {   
  363.             case KEY_F7: backlight();continue;
  364.             case KEY_DOWN: 
  365.                 {
  366.                     f_hd = open_DBF((char *)"DATA");
  367.                     n = member_in_DBF (f_hd);
  368.                     if (guangbiao<n)
  369.                     {
  370.                         lseek_DBF(f_hd, 2, guangbiao+1, 1);
  371.                         memset(buf,0x00,46);
  372.                         get_member(f_hd,2,(char*)buf);
  373.                         if(strncmp(buf,rcz,16) == 0)
  374.                         {
  375.                             guangbiao++;
  376.                         }
  377.                     }
  378.                     else
  379.                     {
  380.                     }
  381.                     close_DBF(f_hd);
  382.                     break;
  383.                 }
  384.             case KEY_UP: 
  385.                 {
  386.                     f_hd = open_DBF((char *)"DATA");
  387.                     n = member_in_DBF (f_hd);
  388.                     if (guangbiao>0)
  389.                     {
  390.                         lseek_DBF(f_hd, 2, guangbiao-1, 1);
  391.                         memset(buf,0x00,46);
  392.                         get_member(f_hd,2,(char*)buf);
  393.                         if(strncmp(buf,rcz,16) == 0)
  394.                         {
  395.                             guangbiao--;
  396.                         }
  397.                     }
  398.                     else
  399.                     {
  400.                     }
  401.                     close_DBF(f_hd);
  402.                     break;
  403.                 }
  404.             case KEY_F1: 
  405.                 {
  406.                     clr_scr();
  407.                     gotoxy(0,1);
  408.                     printf("  是否删除当前数据? ");
  409.                     gotoxy(0,3);
  410.                     printf("    1是     2否    ");
  411.                     for (;!kbhit(););
  412.                     switch (key = getchar())
  413.                     {   
  414.                         case KEY_F7: backlight();continue;
  415.                         case '1':   //1111
  416.                             {
  417.                             
  418.                                 f_hd = open_DBF((char *)"DATA");
  419.                                 lseek_DBF(f_hd, 2, guangbiao, 1);
  420.                                 delete_member(f_hd,2);
  421.                                 n = member_in_DBF (f_hd);
  422.                                 for(i=0;i<n;i++)
  423.                                 {
  424.                                     lseek_DBF(f_hd, 2, i, 1);
  425.                                     memset(buf,0x00,46);
  426.                                     get_member(f_hd,2,(char*)buf);
  427.                                     if(strncmp(buf,rcz,16) == 0)
  428.                                     {
  429.                                         memset(temp3,0x00,4);
  430.                                         temp3[0] = buf[16];
  431.                                         temp3[1] = buf[17];
  432.                                         temp3[2] = buf[18];
  433.                                         temp1 = atoi(temp3);
  434.                                         temp2 = atoi(xianshixuhao);
  435.                                         if(temp1>temp2)
  436.                                         {
  437.                                             temp1--;
  438.                                             memset(temp3,0x00,4);
  439.                                             itoa(temp1,(char*)temp3,10);
  440.                                             memset(temp4,' ',4);
  441.                                             temp4[3] = 0;
  442.                                             for(j = 0;j<strlen(temp3);j++)
  443.                                             {
  444.                                                 temp4[j] = temp3[j];
  445.                                             }
  446.                                             buf[16] = temp4[0];
  447.                                             buf[17] = temp4[1];
  448.                                             buf[18] = temp4[2];
  449.                                             update_member(f_hd,2,(char*)buf);
  450.                                         }
  451.                                     }
  452.                                 }
  453.                                 close_DBF(f_hd);
  454.                                 continue;
  455.                             }//case 1111
  456.                         case '2':continue;
  457.                     }
  458.                 }//case F_1
  459.             case KEY_F3:
  460.                 {
  461.                     memset(disinput1,0x00,17);
  462.                     memset(disinput2,0x00,11);
  463.                     for(;;)
  464.                     {
  465.                         
  466.                     clr_scr();
  467.                     gotoxy(0,0);
  468.                     printf("%s",riqi);
  469.                     gotoxy(9,0);
  470.                     printf("%s",chehao);
  471.                     gotoxy(13,0);
  472.                     printf("%s",zuhao);
  473.                     gotoxy(0,2);
  474.                     printf("捆号:%s",disinput1);
  475.                     gotoxy(0,3);
  476.                     printf("重量:%s",disinput2);
  477.                     memset(input1,0x00,17);
  478.                     ret = InputData(input1, 16, 5, 2);
  479.                     if(ret == 1)
  480.                     {
  481.                         memset(disinput1,' ',17);
  482.                         disinput1[16] = 0;
  483.                         for (i = 0;i<strlen(input1);i++)
  484.                         {
  485.                             disinput1 [i] = input1 [i];
  486.                         }
  487.                         gotoxy(0,2);
  488.                         printf("                    ");
  489.                         gotoxy(0,2);
  490.                         printf("捆号:%s",disinput1);
  491.                         memset(input2,0x00,11);
  492.                         ret1 =InputData2(input2, 10, 5, 3);
  493.                         if(ret1 == 2)
  494.                         {
  495.                             memset(disinput2,' ',11);
  496.                             disinput2[10] = 0;
  497.                             for(i=0;i<strlen(input2);i++)
  498.                             {
  499.                                 disinput2[i] = input2[i];
  500.                             }
  501.                             memset(buf,0x00,46);
  502.                             strcat(buf,riqi);
  503.                             strcat(buf,chehao);
  504.                             strcat(buf,zuhao);
  505.                             
  506.                             f_hd = open_DBF((char *)"DATA");
  507.                             lseek_DBF(f_hd, 2, guangbiao, 1);
  508.                             memset(buf2,0x00,46);
  509.                             get_member(f_hd,2,(char*)buf2);
  510.                             xuhao[0] = buf2[16];
  511.                             xuhao[1] = buf2[17];
  512.                             xuhao[2] = buf2[18];
  513.                             close_DBF(f_hd);
  514.                             
  515.                             strcat(buf,xuhao);
  516.                             strcat(buf,disinput1);
  517.                             strcat(buf,disinput2);
  518.                             f_hd = open_DBF((char *)"DATA");
  519.                             lseek_DBF(f_hd, 2, guangbiao, 1);
  520.                             update_member(f_hd,2,(char*)buf);
  521.                             close_DBF(f_hd);
  522.                             break;
  523.                         }
  524.                         else if(ret1 == 1)
  525.                         {
  526.                             break;
  527.                         }
  528.                     }
  529.                     else if(ret == 0)
  530.                     {
  531.                         break;
  532.                     }
  533.                     }
  534.                     continue;
  535.                 }
  536.             case KEY_ESC:return;
  537.         }
  538.     }
  539. }
  540. void shangchuan(void)
  541. {
  542.     int f_hd,uploadflag;
  543.     char key1,key2,key;
  544.     
  545.     while(1)
  546.     {
  547.         clr_scr ();
  548.         gotoxy(0,0);
  549.         printf("===请选择上传方式===");
  550.         gotoxy(0,2);
  551.         printf("    1.数据线连接    ");
  552.         gotoxy(0,3);
  553.         printf("    2.通讯座连接    ");
  554.         gotoxy(0,4);
  555.         printf("ESC返回             ");
  556.         
  557.         for (;!kbhit(););
  558.         switch (key = getchar())
  559.         {   
  560.             case KEY_F7: backlight();continue;
  561.             case '1'
  562.                 {
  563.                     connect_port = 0;
  564.                     f_hd = open_DBF((char *)"DATA");
  565.                     uploadflag = UploadDBF (f_hd);
  566.                     close_DBF(f_hd);
  567.                     if (uploadflag == TRUE)
  568.                     {
  569.                         clr_scr();
  570.                         gotoxy(0,1);
  571.                         printf("%s",(char *)"  是否删除所有  ");
  572.                         gotoxy(0,2);
  573.                         printf("%s",(char *)"    采集数据    ");
  574.                         gotoxy(0,3);
  575.                         printf("%s",(char *)"   1是    2否   ");
  576.                         for (;!kbhit(););
  577.                         switch (key2 = getchar())
  578.                         {   
  579.                             case KEY_F7: backlight();break;
  580.                             case '1'
  581.                                 {
  582.                                     if(remove((char*)"DATA")==1)
  583.                                     {
  584.                                         on_beeper (beep1);
  585.                                         clr_scr();
  586.                                         gotoxy(0,2);
  587.                                         printf("%s",(char *)"    删除成功    ");
  588.                                         if (!access("DATA"))
  589.                                         {
  590.                                             f_hd = create_DBF ("DATA", 45);     
  591.                                             create_index (f_hd, 1, 0, 12);      
  592.                                             create_index (f_hd, 2, 0, 16);
  593.                                             create_index (f_hd, 3, 0, 19);
  594.                                             close_DBF(f_hd);    
  595.                                         }
  596.                                         OSTimeDly (300);
  597.                                     }
  598.                                     else
  599.                                     {
  600.                                         on_beeper (beep3);
  601.                                         clr_scr();
  602.                                         gotoxy(0,2);
  603.                                         printf("%s",(char *)"    删除失败    ");
  604.                                         OSTimeDly (300);
  605.                                     }
  606.                                     break;
  607.                                 }
  608.                             case '2'break;
  609.                         }
  610.                     }
  611.                     break;
  612.                 }
  613.             case '2'
  614.                 {
  615.                     connect_port = 2;
  616.                     f_hd = open_DBF((char *)"DATA");
  617.                     uploadflag = UploadDBF (f_hd);
  618.                     close_DBF(f_hd);
  619.                     if (uploadflag == TRUE)
  620.                     {
  621.                         clr_scr();
  622.                         gotoxy(0,1);
  623.                         printf("%s",(char *)"  是否删除所有  ");
  624.                         gotoxy(0,2);
  625.                         printf("%s",(char *)"    采集数据    ");
  626.                         gotoxy(0,3);
  627.                         printf("%s",(char *)"   1是    2否   ");
  628.                         for (;!kbhit(););
  629.                         switch (key2 = getchar())
  630.                         {   
  631.                             case KEY_F7: backlight();break;
  632.                             case '1'
  633.                                 {
  634.                                     if(remove((char*)"DATA")==1)
  635.                                     {
  636.                                         on_beeper (beep1);
  637.                                         clr_scr();
  638.                                         gotoxy(0,2);
  639.                                         printf("%s",(char *)"    删除成功    ");
  640.                                         if (!access("DATA"))
  641.                                         {
  642.                                             f_hd = create_DBF ("DATA", 45);     
  643.                                             create_index (f_hd, 1, 0, 12);      
  644.                                             create_index (f_hd, 2, 0, 16);
  645.                                             create_index (f_hd, 3, 0, 19);
  646.                                             close_DBF(f_hd);    
  647.                                         }
  648.                                         OSTimeDly (300);
  649.                                     }
  650.                                     else
  651.                                     {
  652.                                         on_beeper (beep3);
  653.                                         clr_scr();
  654.                                         gotoxy(0,2);
  655.                                         printf("%s",(char *)"    删除失败    ");
  656.                                         OSTimeDly (300);
  657.                                     }
  658.                                     break;
  659.                                 }
  660.                             case '2'break;
  661.                         }
  662.                     }
  663.                     break;
  664.                 }
  665.             case KEY_ESC:return;
  666.         }
  667.     }
  668.                     /*f_hd = open_DBF((char *)"DATA");
  669.                     uploadflag = UploadDBF (f_hd);
  670.                     close_DBF(f_hd);
  671.                     if (uploadflag == TRUE)
  672.                     {
  673.                         clr_scr();
  674.                         gotoxy(0,0);
  675.                         printf("%s",(char *)"  是否删除所有  ");
  676.                         gotoxy(0,1);
  677.                         printf("%s",(char *)"    采集数据    ");
  678.                         gotoxy(0,3);
  679.                         printf("%s",(char *)"   1是    2否   ");
  680.                         for (;!kbhit(););
  681.                         switch (key2 = getchar())
  682.                         {   
  683.                             case KEY_F7: backlight();break;
  684.                             case '1': 
  685.                                 {
  686.                                     if(remove((char*)"shoujian")==1)
  687.                                     {
  688.                                         on_beeper (beep1);
  689.                                         clr_scr();
  690.                                         gotoxy(0,2);
  691.                                         printf("%s",(char *)"    删除成功    ");
  692.                                         if (!access("shoujian"))
  693.                                         {
  694.                                             f_hd = create_DBF ("shoujian", 92);     
  695.                                             create_index (f_hd, 1, 32, 16); 
  696.                                             create_index (f_hd, 2, 0, 16);
  697.                                             close_DBF(f_hd);    
  698.                                         }
  699.                                         OSTimeDly (300);
  700.                                     }
  701.                                     else
  702.                                     {
  703.                                         on_beeper (beep3);
  704.                                         clr_scr();
  705.                                         gotoxy(0,2);
  706.                                         printf("%s",(char *)"    删除失败    ");
  707.                                         OSTimeDly (300);
  708.                                     }
  709.                                     break;
  710.                                 }
  711.                             case '2': break;
  712.                         }
  713.                     }*/
  714. }
  715. void caiji(void)
  716. {
  717.     int ret1,ret2,ret3,ret4,i;
  718.     char riqi1[9],chehao1[5],zuhao1[5];
  719.     while(1)
  720.     {
  721.         memset(riqi,' ',9);
  722.         riqi[8] = 0;
  723.         memset(chehao,' ',5);
  724.         chehao[4] = 0;
  725.         memset(zuhao,' ',5);
  726.         zuhao[4] = 0;
  727.         clr_scr();
  728.         gotoxy(0,0);
  729.         printf("请输入:");
  730.         gotoxy(0,1);
  731.         printf("日期:%s",riqi);
  732.         gotoxy(0,2);
  733.         printf("车号:%s",chehao);
  734.         gotoxy(0,3);
  735.         printf("组号:%s",zuhao);
  736.         for(;;)
  737.         {
  738.             memset(riqi1,0x00,9);
  739.             memset(chehao1,0x00,5);
  740.             memset(zuhao1,0x00,5);
  741.             clr_scr();
  742.             gotoxy(0,0);
  743.             printf("请输入:");
  744.             gotoxy(0,1);
  745.             printf("日期:%s",riqi);
  746.             gotoxy(0,2);
  747.             printf("车号:%s",chehao);
  748.             gotoxy(0,3);
  749.             printf("组号:%s",zuhao);
  750.             ret1 = InputData2(riqi1, 8, 5, 1);
  751.             if (ret1 == 0)//没输入就按回车
  752.             {
  753.                 memset(riqi1,' ',9);
  754.                 riqi1[8] = 0;
  755.                 continue;
  756.             }
  757.             if (ret1 == 1)//按ESC
  758.             {
  759.                 return;
  760.             }
  761.             if (ret1 == 2)//正常
  762.             {
  763.                 for(i=0;i<strlen(riqi1);i++)
  764.                 {
  765.                     riqi[i] = riqi1[i];
  766.                 }
  767.                 for(;;)
  768.                 {
  769.                     clr_scr();
  770.                     gotoxy(0,0);
  771.                     printf("请输入:");
  772.                     gotoxy(0,1);
  773.                     printf("日期:%s",riqi);
  774.                     gotoxy(0,2);
  775.                     printf("车号:%s",chehao);
  776.                     gotoxy(0,3);
  777.                     printf("组号:%s",zuhao);
  778.                     ret2 = InputData2(chehao1, 4, 5, 2);
  779.                     if (ret2 == 0)//没输入就按回车
  780.                     {
  781.                         memset(chehao1,' ',5);
  782.                         chehao1[4] = 0;
  783.                         continue;
  784.                     }
  785.                     if (ret2 == 1)//按ESC
  786.                     {
  787.                         return;
  788.                     }
  789.                     if (ret2 == 2)//正常
  790.                     {
  791.                         for(i=0;i<strlen(chehao1);i++)
  792.                         {
  793.                             chehao[i] = chehao1[i];
  794.                         }
  795.                         for(;;)
  796.                         {
  797.                             clr_scr();
  798.                             gotoxy(0,0);
  799.                             printf("请输入:");
  800.                             gotoxy(0,1);
  801.                             printf("日期:%s",riqi);
  802.                             gotoxy(0,2);
  803.                             printf("车号:%s",chehao);
  804.                             gotoxy(0,3);
  805.                             printf("组号:%s",zuhao);
  806.                             ret3 = InputData2(zuhao1, 4, 5, 3);
  807.                             if (ret3 == 0)//没输入就按回车
  808.                             {
  809.                                 memset(zuhao1,' ',5);
  810.                                 zuhao1[4] = 0;
  811.                                 continue;
  812.                             }
  813.                             if (ret3 == 1)//按ESC
  814.                             {
  815.                                 return;
  816.                             }
  817.                             if (ret3 == 2)//正常
  818.                             {
  819.                                 for(i=0;i<strlen(zuhao1);i++)
  820.                                 {
  821.                                     zuhao[i] = zuhao1[i];
  822.                                 }
  823.                                 for(;;)
  824.                                 {
  825.                                     ret4 = caiji2();
  826.                                     if (ret4 == 0)//没输入就按回车
  827.                                     {
  828.                                     }
  829.                                     if (ret4 == 1)//按ESC
  830.                                     {
  831.                                         return;
  832.                                     }
  833.                                     if (ret4 == 2)//正常
  834.                                     {
  835.                                     }
  836.                                 }
  837.                             }
  838.                         }
  839.                     }
  840.                 }
  841.             }
  842.         }
  843.     } 
  844. }
  845. int caiji2(void)
  846. {
  847.     /*atof
  848. 【功能】将一个字符串转换成浮点数。
  849. 【原型】double atof(const char *s)
  850. 【位置】math.h
  851. */
  852.     char input1[17],input2[11];
  853.     char temp1[13],temp2[17],buf1[46],buf2[13],buf3[17],buf4[11];
  854.     char temptj[11];
  855.     int f_hd,n,i,j;
  856.     int zukunshu= 0,chekunshu= 0;
  857.     double zuzhongliang1,zuzhongliang2,chezhongliang1,chezhongliang2;
  858.     int ret,ret1;
  859.     int xuhaoshu;
  860.     char xhshu[4];
  861.     for(;;)
  862.     {
  863.         chezhongliang1 = 0;
  864.         zuzhongliang1 = 0;
  865.         zukunshu = 0;
  866.         chekunshu = 0;
  867.         memset(temp2,0x00,17);
  868.         memset(temp1,0x00,13);
  869.         strcat(temp2,riqi);
  870.         strcat(temp2,chehao);
  871.         strcat(temp2,zuhao);
  872.         strcat(temp1,riqi);
  873.         strcat(temp1,chehao);
  874.         f_hd = open_DBF((char *)"DATA");
  875.         n = member_in_DBF (f_hd);
  876.         for(i=0;i<n;i++)
  877.         {
  878.             memset(buf1,0x00,46);
  879.             lseek_DBF(f_hd, 2, i, 1);
  880.             get_member(f_hd,2,(char*)buf1);
  881.             if(strncmp(buf1,temp2,16) == 0)
  882.             {
  883.                 zukunshu = zukunshu+1;
  884.             }
  885.         }
  886.         close_DBF(f_hd);
  887.         f_hd = open_DBF((char *)"DATA");
  888.         n = member_in_DBF (f_hd);
  889.         for(i=0;i<n;i++)
  890.         {
  891.             memset(buf1,0x00,46);
  892.             lseek_DBF(f_hd, 1, i, 1);
  893.             get_member(f_hd,1,(char*)buf1);
  894.             if(strncmp(buf1,temp1,12) == 0)
  895.             {
  896.                 chekunshu = chekunshu+1;
  897.             }
  898.         }
  899.         close_DBF(f_hd);
  900. /*--------------------------------------------------------*/
  901.         f_hd = open_DBF((char *)"DATA");
  902.         n = member_in_DBF (f_hd);
  903.         for(i=0;i<n;i++)
  904.         {
  905.             memset(buf1,0x00,46);
  906.             lseek_DBF(f_hd, 1, i, 1);
  907.             get_member(f_hd,1,(char*)buf1);
  908.             if(strncmp(buf1,temp1,12) == 0)
  909.             {
  910.                 memset(temptj,0x00,11);
  911.                 chezhongliang2 = 0;
  912.                 for(j = 35;j<45;j++)
  913.                 {
  914.                     temptj[j-35] = buf1[j];
  915.                 }
  916.                 chezhongliang2 = atof((char*)temptj);
  917.                 chezhongliang1 = chezhongliang1 + chezhongliang2; 
  918.             }
  919.         }
  920.         close_DBF(f_hd);
  921.         
  922.         f_hd = open_DBF((char *)"DATA");
  923.         n = member_in_DBF (f_hd);
  924.         for(i=0;i<n;i++)
  925.         {
  926.             memset(buf1,0x00,46);
  927.             lseek_DBF(f_hd, 2, i, 1);
  928.             get_member(f_hd,2,(char*)buf1);
  929.             if(strncmp(buf1,temp2,16) == 0)
  930.             {
  931.                 memset(temptj,0x00,11);
  932.                 zuzhongliang2 = 0;
  933.                 for(j = 35;j<45;j++)
  934.                 {
  935.                     temptj[j-35] = buf1[j];
  936.                 }
  937.                 zuzhongliang2 = atof((char*)temptj);
  938.                 zuzhongliang1 = zuzhongliang1 + zuzhongliang2; 
  939.             }
  940.         }
  941.         close_DBF(f_hd);
  942.         
  943. /*-----------------------------------------------------------------*/
  944.         
  945.         clr_scr();
  946.         gotoxy(0,0);
  947.         printf("%s",riqi);
  948.         gotoxy(9,0);
  949.         printf("%s",chehao);
  950.         gotoxy(13,0);
  951.         printf("%s",zuhao);
  952.         gotoxy(0,1);
  953.         printf("捆号:");
  954.         gotoxy(0,2);
  955.         printf("重量:");
  956.         gotoxy(0,3);
  957.         printf("zu:%d",zukunshu);
  958.         gotoxy(0,4);
  959.         printf("che:%d",chekunshu);
  960.         gotoxy(7,3);
  961.         printf("%-7.2f",zuzhongliang1);
  962.         gotoxy(7,4);
  963.         printf("%-7.2f",chezhongliang1);
  964.         
  965.         memset(input1,0x00,17);
  966.         ret = InputData(input1, 16, 5, 1);
  967.         if(ret == 1)
  968.         {
  969.             memset(kunhao,' ',17);
  970.             kunhao[16] = 0;
  971.             for (i = 0;i<strlen(input1);i++)
  972.             {
  973.                 kunhao [i] = input1 [i];
  974.             }
  975.             gotoxy(0,1);
  976.             printf("                    ");
  977.             gotoxy(0,1);
  978.             printf("捆号:%s",kunhao);
  979.             memset(input2,0x00,11);
  980.             ret1 =InputData2(input2, 10, 5, 2);
  981.             if(ret1 == 2)
  982.             {
  983.                 memset(zhongliang,' ',11);
  984.                 zhongliang[10] = 0;
  985.                 for(i=0;i<strlen(input2);i++)
  986.                 {
  987.                     zhongliang[i] = input2[i];
  988.                 }
  989.         /*-----------------------------------*/
  990.                 xuhaoshu = zukunshu +1;
  991.                 memset(xhshu,0x00,4);
  992.                 itoa (xuhaoshu, (char*)xhshu, 10);
  993.                 memset(xuhao,' ',4);
  994.                 xuhao[3] = 0;
  995.                 for(i=0;i<strlen(xhshu);i++)
  996.                 {
  997.                     xuhao[i] = xhshu[i];
  998.                 }
  999.         /*-----------------------------------*/
  1000.                 memset(all,0x00,46);
  1001.                 strcat(all,riqi);
  1002.                 strcat(all,chehao);
  1003.                 strcat(all,zuhao);
  1004.                 
  1005.                 strcat(all,xuhao);
  1006.                 strcat(all,kunhao);
  1007.                 strcat(all,zhongliang);
  1008.                 record_save((char*)all, (char*)"DATA");
  1009.             }
  1010.             else if(ret1 == 1)
  1011.             {
  1012.                 return 1;
  1013.             }
  1014.         }
  1015.         else if(ret == 0)
  1016.         {
  1017.             return 1;
  1018.         }
  1019.     }
  1020. }
  1021. void record_save(char* record, char* filename)
  1022. {
  1023.     int f_hd;
  1024.     f_hd=open_DBF((char *)filename);
  1025.     
  1026.     if(add_member(f_hd,(char *)record) == 1)
  1027.     {
  1028.         on_beeper (beep1);
  1029.     }
  1030.     else
  1031.     {
  1032.         on_beeper (beep3);//OSTimeDly (300);
  1033.         clr_scr ();
  1034.         gotoxy(0,2);
  1035.         printf("    保存失败    ");
  1036.         OSTimeDly (300);
  1037.     }
  1038.     close_DBF(f_hd);
  1039. }
  1040. void  getDatetime(void)
  1041. {
  1042.     char cur_time[16];
  1043.     char tmpdate[11],tmptime[9];
  1044.     char year[6],month[4],day[4],hour[4],minute[4],second[4];
  1045.     memset(date,0x00,sizeof(date));
  1046.     memset(tmpdate,0x00,sizeof(tmpdate));
  1047.     memset(time,0x00,sizeof(time));
  1048.     memset(tmptime,0x00,sizeof(tmptime));
  1049.     memset(year,0x00,sizeof(date));
  1050.     memset(month,0x00,sizeof(date));
  1051.     memset(day,0x00,sizeof(date));
  1052.     memset(hour,0x00,sizeof(date));
  1053.     memset(minute,0x00,sizeof(date));
  1054.     memset(second,0x00,sizeof(date));
  1055.     
  1056.     
  1057.     get_time(cur_time);
  1058.     /*获取时间*/
  1059.     memcpy(year,cur_time,4);
  1060.     memcpy(month,cur_time+4,2);
  1061.     memcpy(day,cur_time+6,2);
  1062.     /*获取时间*/
  1063.     memcpy(hour,cur_time+8,2);
  1064.     memcpy(minute,cur_time+10,2);
  1065.     memcpy(second,cur_time+12,2);
  1066.     sprintf(date,"%04d-%02d-%02d/x00",atoi(year),atoi(month),atoi(day));
  1067.     sprintf(time,"%02d:%02d:%02d/x00",atoi(hour),atoi(minute),atoi(second));
  1068.     
  1069. }
  1070. static BOOL ConnectingPage (void)
  1071. {
  1072.     clr_scr ();
  1073.     gotoxy(0,0);
  1074.     printf("连接中. ");
  1075.     gotoxy(0,3);
  1076.     printf(" ");
  1077.     gotoxy(0,4);
  1078.     printf("按 ESC 退出");
  1079. //    DispString (0, 1, (char*)"连接中. ", 0, 1);
  1080.  //   DispString (0, 3, (char*)" ", 0, 1);
  1081.   //  DispString (0, 5, (char*)"按 ESC 退出", 0, 1);
  1082.     return TRUE;
  1083. }
  1084. BOOL UploadDBF (int fDbf)
  1085.     {
  1086.     int       i, j, k, n,nPort,p;
  1087.     char szbuf1[100];
  1088.     unsigned  sum;
  1089.     BYTE      Header [2];
  1090.     BYTE      c;
  1091.     BYTE      szData [256];
  1092.     BYTE      szBuf[256];
  1093.     ConnectingPage ();
  1094.         SetCommType (1, connect_port);                   // IR
  1095.                 nPort = 1;                            // must use COM2
  1096.                 c = 0x08;            // 115200,N,8,1        
  1097.                 open_com (nPort, c);
  1098. ReTry:
  1099.     i = 0;
  1100.     while (i < 10)
  1101.     {
  1102.         if (read_com (nPort, (char *)&c))     // if successful reading
  1103.             szData [i++] = c;
  1104.         if (c == '/r')
  1105.             break;
  1106.         if ((c = getchar()) == KEY_ESC)
  1107.         {
  1108.             close_com (nPort);
  1109.             clr_scr ();
  1110.             return FALSE;
  1111.         }
  1112.         else if (c == KEY_F7)
  1113.             backlight();
  1114.     }
  1115.     szData [i] = 0;
  1116.     if (!strcmp (szData, "READ/r"))
  1117.     {
  1118.         write_com (nPort, ACK);
  1119.         while (!com_eot (nPort));
  1120.         gotoxy(0,0);
  1121.         printf("上传中");
  1122.         gotoxy(0,3);
  1123.         printf("状态:");
  1124.        // DispString (0, 1, (char*)"上传中", 0, 1);      // Sending data...
  1125.        // DispString (0, 3, (char*)"状态:", 0, 1);      // Transfered:
  1126.     }
  1127.     else
  1128.     {
  1129.         write_com (nPort, NAK);
  1130.         while (!com_eot (nPort));
  1131.         goto ReTry;
  1132.     }
  1133.     n = member_in_DBF (fDbf);
  1134.     lseek_DBF (fDbf, 1, 0, SEEK_SET); //SEEK_SET=1(from 8000lib.h)
  1135.     k = 0;
  1136.     while (k < n)
  1137.     {
  1138.         get_member (fDbf, 1, (char *)szData);
  1139.         lseek_DBF (fDbf, 1, 1, SEEK_CUR);
  1140.         
  1141.         
  1142.     ////////////////////////////////////////    
  1143.         //p = strlen (szData);
  1144.         //for (i=6;i<p;i++)
  1145.         //  szbuf1[i-6] = szData[i];
  1146.         //memset(szData,0x00,strlen(szData));
  1147.         //for (i=6;i<p;i++)
  1148.         //  szData[i-6] = szbuf1[i-6];
  1149.     /////////////////////////////////////// 
  1150.         j = strlen (szData);
  1151.         if (j < 1)/**************************************************************************************************/
  1152.         {
  1153.             k++;
  1154.             continue;
  1155.         }
  1156.         sum = Header [0] = k++ % 10;    // rotate from 0 to 9
  1157.         for (i=0; i<j; i++)//i=0
  1158.             sum += szData [i];
  1159.         szData [j] = sum & 0xFF;
  1160.         if (szData [j] == '/r')         // make sure the checksum isn't '/r'
  1161.             szData [j]++;
  1162.         j++;
  1163.         szData [j] = sum >> 8;
  1164.         if (szData [j] == '/r')         // make sure the checksum isn't '/r'
  1165.             szData [j]++;
  1166.         szData [++j] = '/r';
  1167.         szData [++j] = 0;
  1168.         itoa (k, (char*)szBuf, 10);
  1169.         gotoxy(11,3);
  1170.         printf("%s",szBuf);
  1171.      //   DispString (11, 3, (char*)szBuf, 0, 1);   // show data transfered
  1172. ReSend:
  1173.         nwrite_com (nPort, (char *)Header, 1);
  1174.         while (com_eot(nPort) == 0x00);
  1175.         nwrite_com (nPort, (char *)szData, j);
  1176.         while (!com_eot (nPort));
  1177. ReDo:
  1178.         i = 0;
  1179.         while (i < 10)
  1180.         {
  1181.             if (read_com (nPort, (char *)&c))
  1182.                 szBuf [i++] = c;
  1183.             if (c == '/r')
  1184.                 break;
  1185.             if ((c = getchar()) == KEY_ESC)
  1186.             {
  1187.                 close_com (nPort);
  1188.                 clr_scr ();
  1189.                 return FALSE;
  1190.             }
  1191.             else if (c == KEY_F7)
  1192.                 backlight();
  1193.         }
  1194.         szBuf [i] = 0;
  1195.         if (!strcmp (szBuf, NAK))
  1196.             goto ReSend;
  1197.         else if (strcmp (szBuf, ACK))
  1198.             goto ReDo;
  1199.     }
  1200.     write_com (nPort, "OVER/r");
  1201.     while (!com_eot (nPort));
  1202.     write_com (nPort, "OVER/r");
  1203.     while (!com_eot (nPort));
  1204.     on_beeper (beep2);
  1205.     gotoxy(11,3);
  1206.     printf("完成");
  1207.     //DispString (11, 3, (char*)"完成", 0, 1);    // Done
  1208.     //DispString (0, 5, (char*)" ", 0);
  1209.     
  1210.     //DispString (0, 7, (char*)" ", 0, 1);
  1211.     close_com (nPort);
  1212.     OSTimeDly (200);
  1213.     return TRUE;
  1214.     }
  1215. //--------------------------------------------------------//
  1216. int InputData2 (char* databuf, int maxbit, int CurX, int CurY)
  1217. {
  1218.     char    key,c_space[100];
  1219.     int     flag,count;
  1220.     
  1221.     for (count=0;count<maxbit;count++)
  1222.         c_space[count] = ' ';
  1223.     c_space[count] = 0;              //设定maxbit个字节的空格,用来清空输入区
  1224.     memset(databuf,0x00,strlen(databuf));
  1225.     databuf[strlen(databuf)-1] = 0;
  1226.     gotoxy(CurX,CurY);
  1227.     SetCursor (1);
  1228.     
  1229.     en_alpha (ALPHA_FIXED); //ALPHA_FIXED 只允许字母输入
  1230.     
  1231.     flag = 0;
  1232.     count = 0;
  1233.     for (;;)
  1234.     {               
  1235.         if (kbhit())
  1236.         {
  1237.             key = getchar();
  1238.             if (key == KEY_CR)
  1239.             {
  1240.                 clr_kb();
  1241.                 if (count == 0)
  1242.                 {
  1243.                     SetCursor (0);
  1244.                     return 0;
  1245.                 }
  1246.                 else if (count > 0)
  1247.                 {
  1248.                     on_beeper (beep2);
  1249.                     break;
  1250.                 }
  1251.             }
  1252.             else if (key == KEY_BS)
  1253.             {
  1254.                 if (count>0 && count<=maxbit)
  1255.                 {
  1256.                     if ((CurX+count)<=Xmax)
  1257.                     {
  1258.                         count--;
  1259.                         databuf[count] = 0;
  1260.                         gotoxy(CurX+count,CurY);
  1261.                         putchar(' ');
  1262.                         gotoxy(CurX+count,CurY);
  1263.                     }
  1264.                     else
  1265.                     {
  1266.                         count--;
  1267.                         databuf[count] = 0;
  1268.                         gotoxy(CurX+count-Xmax,CurY+1);
  1269.                         putchar(' ');
  1270.                         gotoxy(CurX+count-Xmax,CurY+1);
  1271.                     }
  1272.                 }
  1273.             }
  1274.             else if (key == KEY_F7)
  1275.             {
  1276.                 backlight();
  1277.             }
  1278.             else if (key == KEY_ESC)
  1279.             {
  1280.                     count = 0;
  1281.                     dis_alpha ();
  1282.                     SetCursor (0);
  1283.                     return 1;   
  1284.             }
  1285.             else
  1286.             if ( (key>='0'&&key<='9')||(key>='A'&&key<='Z')||(key>='a'&&key<='z')||(key=='.')||(key=='-'))
  1287.             {
  1288.                 if(count == 0)
  1289.                 {
  1290.                     gotoxy(CurX,CurY);
  1291.                     printf("%s",(char *)c_space);
  1292.                     gotoxy(CurX,CurY);
  1293.                     databuf[count]=key;
  1294.                     gotoxy(CurX+count,CurY);
  1295.                     putchar(databuf[count]);
  1296.                     count++;
  1297.                     clr_kb();
  1298.                 }
  1299.                 else if (count < maxbit)
  1300.                 {
  1301.                     databuf[count]=key;
  1302.                     if ((CurX+count)<Xmax)
  1303.                     {
  1304.                         gotoxy(CurX+count,CurY);
  1305.                     }
  1306.                     else
  1307.                     {
  1308.                         gotoxy(CurX+count-Xmax,CurY+1);
  1309.                     }
  1310.                     putchar(databuf[count]);
  1311.                     count++;
  1312.                     clr_kb();
  1313.                 }
  1314.             }
  1315.         }
  1316.     }
  1317.     dis_alpha ();
  1318.     SetCursor (0);
  1319.     return 2;       
  1320. }
  1321. int InputData (char* databuf, int maxbit, int CurX, int CurY)
  1322. {
  1323.     char    key,c_space[100];
  1324.     int     flag,count;
  1325.     
  1326.     for (count=0;count<maxbit;count++)
  1327.         c_space[count] = ' ';
  1328.     c_space[count] = 0;              //设定maxbit个字节的空格,用来清空输入区
  1329.     gotoxy(CurX,CurY);
  1330.     SetCursor (1);
  1331.     en_alpha (ALPHA_FIXED); //ALPHA_FIXED 只允许字母输入
  1332.     InitScanner1();
  1333.     flag = 0;
  1334.     count = 0;
  1335.     for (;;)
  1336.     {
  1337.         if (Decode ())
  1338.         {
  1339.             on_beeper (beep2);
  1340.             HaltScanner1();
  1341.             flag=1;
  1342.             break;
  1343.         }                   //扫描条码成功后退出循环
  1344.         else if (kbhit())
  1345.         {
  1346.             key = getchar();
  1347.             if (key == KEY_CR)
  1348.             {
  1349.                 clr_kb();
  1350.                 if (count == 0)
  1351.                 {
  1352.                     count = 0;
  1353.                     gotoxy(CurX,CurY);
  1354.                 }
  1355.                 else if (count > 0)
  1356.                 {
  1357.                     databuf[count]=0x00;
  1358.                     on_beeper (beep2);
  1359.                     HaltScanner1();
  1360.                     break;
  1361.                 }           //数据输入完成后退出循环
  1362.             }
  1363.             else if (key == KEY_BS)
  1364.             {
  1365.                 if (count>0 && count<=maxbit)
  1366.                 {
  1367.                     if ((CurX+count)<=Xmax)
  1368.                     {
  1369.                         count--;
  1370.                         databuf[count] = 0;
  1371.                         gotoxy(CurX+count,CurY);
  1372.                         putchar(' ');
  1373.                         gotoxy(CurX+count,CurY);
  1374.                     }
  1375.                     else
  1376.                     {
  1377.                         count--;
  1378.                         databuf[count] = 0;
  1379.                         gotoxy(CurX+count-Xmax,CurY+1);
  1380.                         putchar(' ');
  1381.                         gotoxy(CurX+count-Xmax,CurY+1);
  1382.                     }
  1383.                 }
  1384.             }
  1385.             else if (key == KEY_F7)
  1386.             {
  1387.                 backlight();
  1388.             }
  1389.             else if (key == KEY_ESC)
  1390.             {
  1391.                     count = 0;
  1392.                     HaltScanner1();
  1393.                     dis_alpha ();
  1394.                     SetCursor (0);
  1395.                     return 0;       //返回上一级菜单
  1396.                 
  1397.             }
  1398.             else
  1399.             if ( (key>='0'&&key<='9')||(key>='A'&&key<='Z')||(key>='a'&&key<='z')||(key=='.')||(key=='-') )
  1400.             {
  1401.                 if(count == 0)
  1402.                 {
  1403.                     gotoxy(CurX,CurY);
  1404.                     printf("                ");
  1405.                     gotoxy(CurX,CurY);
  1406.                     databuf[count]=key;
  1407.                     gotoxy(CurX+count,CurY);
  1408.                     putchar(databuf[count]);
  1409.                     count++;
  1410.                     clr_kb();
  1411.                 }
  1412.                 else if (count < maxbit)
  1413.                 {
  1414.                     databuf[count]=key;
  1415.                     if ((CurX+count)<Xmax)
  1416.                     {
  1417.                         gotoxy(CurX+count,CurY);
  1418.                     }
  1419.                     else
  1420.                     {
  1421.                         gotoxy(CurX+count-Xmax,CurY+1);
  1422.                     }
  1423.                     putchar(databuf[count]);
  1424.                     count++;
  1425.                     clr_kb();
  1426.                 }
  1427.             }
  1428.         }
  1429.     }
  1430.     if (flag == 1)
  1431.     {
  1432.         for (count=0;count<CodeLen && count<maxbit;count++)
  1433.         {
  1434.             databuf[count]=CodeBuf[count];
  1435.         }
  1436.         databuf[count]=0x00;
  1437.     }
  1438.     dis_alpha ();
  1439.     SetCursor (0);
  1440.     return 1;//继续下一步操作
  1441. }
  1442. //--------------------------------------------------------//
  1443. /*//--------------------------------------------------------//
  1444. //--------------------------------------------------------//*/
  1445. void backlight()
  1446. {
  1447.     if (bklt_flag == 0) bklt_flag = 1;
  1448.     else bklt_flag = 0;
  1449.     lcd_backlit (bklt_flag);
  1450. }
 
原创粉丝点击