⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prog_plu.c

📁 一款收款机C源代码!因为是几年前的代码了
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
*   file: prog_PLU.c
*   created by Analy, 2006-09-21
*   
*   used for the PLU program and some other operation about PLU
*
*
*
*
*
****************
Str_PLU_Prog_Menu
*******************************************************************************/
#include "ecrsys.h"
#include "ftype.h"
#include "sysdata.h"
#include "data.h"
#include "keydef.h"
#include "mathes.h"
#include <string.h>
#include "disp.h"
#include "lcd2.h"
#include "PC_Comm.h"
#include "lcd_pop.h"
#include "program.h"
#include "stdio.h"



#define PRG_PLU_MENU_LINE   3


void 	pPLU(void);
void p_Del_PLU(void);
void Pbin2asc(word prg_idx, byte prg_step);
byte Pasc2bin(word prg_idx, byte prg_step);
void Do_Plu_Roll(word key, byte *prg_step);

void PMD_PLU_Menu(void)
{
    byte step_Idx = 0;
    byte Update_Menu_flag = 0;
    byte rsult = NG;

    modi_flag = 0;			/* Clear the flag, indicate the attribute did't modified */
    Last_Prg_Idx = IDX_NULL;
    Last_Prg_Step = STEP_NULL;
    while (TRUE)                       
    {
        if(GetMainMode() != CurrMode)
            return;
        if(Update_Menu_flag == 0)
        {
            Lcd_Send_Text_Buff_Str(BUF_ID_TL_TITLE, 1, Str_ProgMain_Menu[1], ALIGN_MID);
            Lcd_Disp_Text_Buff(BUF_ID_TL_TITLE);
            Lcd_Disp_Str_Btn(BUF_ID_TL_SUB, Str_Prog_Enter);
        }
        
        rsult = Get_Prog_Menu(Str_PLU_Prog_Menu,&step_Idx, PRG_PLU_MENU_LINE, 1, Update_Menu_flag, 0);
        Update_Menu_flag = 1;
        
        if(rsult != OK)
        {
            return;
        }
        switch(step_Idx)
        {
            case    0: Update_Menu_flag = 0; pPLU();           break;//Edit exist PLU
            case    1: Update_Menu_flag = 0; p_Del_PLU();       break;  // Delete a PLU
            case    2: Update_Menu_flag = 0; prn_PLU(0xffff);         break;  //Print PLU parameters
            default: 
                if(numcnt)
                    errorType(ERR_DIGIT_ILLEGAL);
                step_Idx = 0; 
                break;
        }
	}		
}
void p_Del_PLU(void)
{
    int     Prg_Idx  = 0xffff;
    int     posi;
    bool    loop = true;
    byte    Rslt;
    byte    i;
    word    j;
    #ifdef SCANNER           /* Support the scanner function */
    byte    tmp_bar[BAR_BUFF_LEN];
    int     old_posi;
    int     new_posi;
    #endif /* End SCANNER */

    Lcd_Send_Text_Buff_Str(BUF_ID_TL_TITLE, 1, Str_PLU_Prog_Menu[1], ALIGN_MID);
    Lcd_Disp_Text_Buff(BUF_ID_TL_TITLE);
    while(TRUE)
    {
        Rst_Lcd_Text();
        Rst_Tl_Sub();
        Rst_Tl_Input();
        Lcd_Send_Text_Buff_Str(BUF_ID_LCD_TEXT, 1, Str_Plu_Prgram[0], ALIGN_LEFT);
        Lcd_Disp_Text_Buff(BUF_ID_LCD_TEXT);
        Lcd_Send_Text_Buff_Str(BUF_ID_LCD_TEXT, 1, Str_Plu_Prgram[1], ALIGN_LEFT);
        Lcd_Disp_Text_Buff(BUF_ID_LCD_TEXT);
        loop = true;
        
        while(loop)
        {
            Lcd_Disp_Str_Btn(BUF_ID_TL_SUB, Str_PLU_Del_Step[0]);
            ProgBar = 1;
            if ( GetIn() ==   NG )
                continue;
            ProgBar = 0;
            if(GetMainMode() != CurrMode)
                return;
            if(InCmd == KD_CANCEL)
                return;
            if((!BarInFlag)&&(InCmd != SPLU))
                continue;

            if(Judge_Weight_PLU(BCDbuf) == OK)      /* Judge is the weight PLU bar code or not */
            {
                byte    tmp_buf[BAR_BUFF_LEN];
                memcpy(tmp_buf, BCDbuf, BAR_BUFF_LEN);
                Do_Weight_PLU(tmp_buf, BCDbuf);
            }
            posi = SC_SearchIndex(BCDbuf);
            if(posi < 0)
            {
                errorType(ERR_BAR_EXIST); continue;
            }
            Prg_Idx = Sindex[posi];
            if(!Chk_Idle_PLU(Prg_Idx))//不是可用PLU
            {
                errorType(ERR_BAR_EXIST); continue;
            }
            loop = FALSE;
        }
        Last_Prg_Idx = IDX_NULL;
        Last_Prg_Step = STEP_NULL;
        Pbin2asc(Prg_Idx, 0);
        Lcd_Disp_Str_Btn(BUF_ID_TL_INPUT, Str_PLU_Del_Step[1]);
        if(Get_Sure_Done(&Rslt) != OK)
        {
            return;
        }
        if(Rslt != KD_YES)
            continue;

        if((plu[Prg_Idx].quantity != 0) || (plu[Prg_Idx].amount != 0)
        #ifdef  PLU_PTD_RPT
        || (plu[Prg_Idx].PTD_quantity != 0) || (plu[Prg_Idx].PTD_amount != 0)
        #endif
        )
        {
            errorType(ERR_RPT_NOT_EMPTY);
            continue;
        }

        #ifdef SCANNER              /* Support the scanner function */
        memset(&(tmp_bar[3]),0x00,BAR_BUFF_LEN-1-3);
        (tmp_bar)[BAR_BUFF_LEN-1] = 0x01;
        i = (Prg_Idx+1)/10000%100;
        (tmp_bar)[2] = ((i/10)<<4)|(i%10);
        i = (Prg_Idx+1)/100%100;
        (tmp_bar)[1] = ((i/10)<<4)|(i%10);
        i = (Prg_Idx+1)/1%100;
        (tmp_bar)[0] = ((i/10)<<4)|(i%10);

        old_posi = SC_SearchIndex(plu[Prg_Idx].barcode);
        if(old_posi < 0)
            ;/* Reserved */
        else
        {
            new_posi = SC_SearchIndex(tmp_bar);
            if(new_posi >= 0)
            {
                if(Sindex[new_posi] == Prg_Idx)
                    ;
                else
                    bellcnt = 120;/* Reserved */
            }
            else
            {
                new_posi = -new_posi;
                memcpy(plu[Prg_Idx].barcode, tmp_bar, BAR_BUFF_LEN);
                SC_UpdateIndex(old_posi,new_posi-1);        /* Update the index table */
            }
        }
        #endif  /* End SCANNER */

        Set_PLU_Idle(Prg_Idx);

        #ifdef STOCK        /* Support the stock function */
        plu[Prg_Idx].inventory = 0;
        plu[Prg_Idx].saft_Stock = 0;
        #endif /* End STOCK */
        plu[Prg_Idx].plink = 1;
        plu[Prg_Idx].price = 0;
        memset(plu[Prg_Idx].desc, 0x20, MAX_DESC_LEN_EX);
        plu[Prg_Idx].desc[MAX_DESC_LEN_EX] = 0;

        for(j = 0; j <MAX_DPLU_NO; j++)
        {
            if(Dplu_Pluno[j] == Prg_Idx + 1)
            {
                Dplu_Pluno[j] = 0;
                break;
            }
        }
    }
    Last_Prg_Idx = IDX_NULL;
    Last_Prg_Step = STEP_NULL;
    return ;
}


/*****************************************************************
*  Program the PLU
* !!!NOTE: This function only suit for the max plu number of 65535/5 = 13107(support the SCANNER 
	  function and STOCK function). When the PLU number is larger, must be change the type of 
	  Idx_Step 
*****************************************************************/
void pPLU(void)
{
	byte    i;
    byte    Prg_Step = 0;
    int     Prg_Idx  = 0xffff;
    int     posi;
    word    Key;
   #ifdef SCANNER			/* Support the scanner function */
    byte    tmp_bar[BAR_BUFF_LEN];
    int     old_posi;
   #endif /* End SCANNER */
    byte	desc_len;

	Lcd_Send_Text_Buff_Str(BUF_ID_TL_TITLE, 1, Str_PLU_Prog_Menu[0], ALIGN_MID);
	Lcd_Disp_Text_Buff(BUF_ID_TL_TITLE);
    while(TRUE)
    {
        if(Prg_Step == PLU_SCAN_STEP)
        {
            Rst_Lcd_Text();
            Lcd_Send_Text_Buff_Str(BUF_ID_LCD_TEXT, 1, Str_Plu_Prgram[0], ALIGN_LEFT);
            Lcd_Disp_Text_Buff(BUF_ID_LCD_TEXT);
            Lcd_Send_Text_Buff_Str(BUF_ID_LCD_TEXT, 1, Str_Plu_Prgram[1], ALIGN_LEFT);
            Lcd_Disp_Text_Buff(BUF_ID_LCD_TEXT);
            Lcd_Disp_Str_Btn(BUF_ID_TL_SUB, Str_PLU_Del_Step[0]);
            
            while(Prg_Step == PLU_SCAN_STEP)
            {
                ProgBar = 1;
                if ( GetIn() ==   NG )
                    continue;
                ProgBar = 0;
                if(GetMainMode() != CurrMode)
                    return;
                if(InCmd == KD_CANCEL)
                    return;
                if((!BarInFlag)&&(InCmd != SPLU))
                    continue;
                
                for(i = 0; i < BAR_BUFF_LEN; i ++)
                    {if(BCDbuf[i] != 0)break;}
                    
                if(i == BAR_BUFF_LEN)
                    {errorType(ERR_DIGIT_ILLEGAL); continue;}
                
                if(Judge_Weight_PLU(BCDbuf) == OK)      /* Judge is the weight PLU bar code or not */
                {
                    byte    tmp_buf[BAR_BUFF_LEN];
                    memcpy(tmp_buf, BCDbuf, BAR_BUFF_LEN);
                    Do_Weight_PLU(tmp_buf, BCDbuf);
                }
                posi = SC_SearchIndex(BCDbuf);
                if(posi >= 0)/*输入的条码已经存在,不必更新条码索引表*/
                {
                    Prg_Idx = Sindex[posi];
                    if(!Chk_Idle_PLU(Prg_Idx))
                        Set_PLU_Used(Prg_Idx);
                }
                else/*输入的条码不存在,需要更新条码索引表*/
                {
                    Prg_Idx = Srch_Idle_PLU();
                    if(Prg_Idx >= Max_Plu_No)
                    {
                        Prg_Idx = 0xffff;
                        errorType(ERR_BAR_FULL);
                        continue;
                    }
                    old_posi = SC_SearchIndex(plu[Prg_Idx].barcode);
                    if(old_posi < 0)            /* When not found the bar code, indicate the index table is wrong, not allow this update operation */
                    {
                        bellcnt = 150;
                        return;            /* The new added */
                    }
                    memcpy(plu[Prg_Idx].barcode,BCDbuf,BAR_BUFF_LEN);           /* Update the PLUs bar code */
                    posi = -posi;           /* Get the new position */
                                /* The newCode's value always not 0 */
                    SC_UpdateIndex(old_posi,posi-1);        /* Update the index table */
                    Set_PLU_Used(Prg_Idx);
                }
                Prg_Step++;
            }
            Last_Prg_Idx = IDX_NULL;
            Last_Prg_Step = STEP_NULL;
        }
        
        Pbin2asc(Prg_Idx, Prg_Step);                 /* Display the PLU attribute */
        Key = GetKey();
      
        GetMainMode();    
        if (MainMode != CurrMode)
            return;
		
        switch (Key)
        {
            case KD_ENTER:
                if(Pasc2bin(Prg_Idx, Prg_Step) == NG)
                    continue;
                Prg_Step = ( Prg_Step + 1 ) % MAX_PLU_STEP;       
                break;    

            case KD_PAGE_DOWN:
            case KD_PAGE_UP:
            case KD_DOWN:
            case KD_UP:
                Do_Plu_Roll(Key, &Prg_Step);
                break;
                
            case KD_CANCEL:
                return;

            default:
                break;
        } /* End switch */
   } /* End while */
} /* End pPLU */


/* Check the plu refresh or not */
BOOL Chk_Plu_Refresh(long prg_idx)
{
	if (Last_Prg_Idx == IDX_NULL)		/* The first programming */
		return 0xff;
    
	if (prg_idx != Last_Prg_Idx)		/* 显示了不同的PLU */
		return 0xff;
    return Last_Prg_Step;
}

/* Do the PLU roll */
void Do_Plu_Roll(word key, byte *prg_step)
{
	if (key == KD_DOWN) 
    {
        (*prg_step) ++;
	}
	else if (key == KD_UP) 
    {
		*prg_step = *prg_step + MAX_PLU_STEP - 1;
	}
    *prg_step  %= MAX_PLU_STEP;
    
    if ( *prg_step == PLU_SCAN_STEP)
        (*prg_step) ++;
    if(sysflag->PLU_Stock_Flag == 0)
    {
        if( *prg_step == PLU_STOCK_STEP)
            (*prg_step) ++;
        if( *prg_step == PLU_SAFT_STOCK)
            (*prg_step) ++;
    }
    
}



/* Get the barocode character */
void Get_Bar_Char(char *dst, byte *srcbar)
{
	char tmp[20];

	BCDtoAsc(tmp, srcbar, BAR_BUFF_LEN);
	memmove(tmp, tmp+1, 13);
	tmp[13] = '\0';
    xtr_strcpy(dst, tmp);
}

/*****************************************************************/
/*-----------------------------------------------------------------*
*           Display the PLU attribute.
*-----------------------------------------------------------------*/
void Pbin2asc(word prg_idx, byte prg_step)
{
    byte plink;          /* The temporary data store the PLU link department */
    byte len, len1;
    byte mode;
    byte step = 0;

    #ifdef STOCK 			/* Support the PLU stock function */
    if((sysflag->PLU_Stock_Flag == 0) && ((prg_step == PLU_STOCK_STEP)||(prg_step == PLU_SAFT_STOCK)))
    	return;		/* When system flag not support the stock, produce a virtual key */
    #endif /* End STOCK */

    Clr_Dsp_Data();            /* Clear the previous display */
    mode = Chk_Plu_Refresh(prg_idx);

    if (mode == 0xff ) //如果发现需要刷新,  执行以下刷新的函数.
    {
        Rst_Lcd_Text();
        Insert_Full_Text_List(Str_PLU_Prog_Step, MAX_PLU_STEP, 2);
        // 1:display the bar code
        len = strlen(Str_PLU_Prog_Step[step]);
    	Get_Bar_Char(Text_Lcd.text[step]+len, plu[prg_idx].barcode);		/* Get the character barcode */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -