📄 sale.c
字号:
/* ** $Id: edit.c,v 1.23 2006/05/26 01:41:35 sunlei Exp $**** Listing 22.1**** edit.c: Sample program for MiniGUI Programming Guide** Usage of EDIT control.**** Copyright (C) 2004 ~ 2006 Feynman Software.**** License: GPL*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include "message.h"#include <sys/ipc.h>#include "tryttys1.c"//#include "client5.c"#include "infonet.c"#include "clientfork.c"void prompt (HWND hDlg);void promtno (HWND hDlg);#define MSG_CHANG_FOCUS_TO_NUM (MSG_USER + 1) //用来改变窗口的焦点信号,从id到数量#define MSG_CHANG_FOCUS_TO_ID (MSG_USER + 2) ////int mainhaha(void);//int clientfork();//extern key_t clientmesqidkey;typedef struct InformTobacco{ //用来 描述烟的一个数据结构 char id[12]; char *name; unsigned int number; unsigned int price; unsigned int totle; int adddata; char *exadd;}INFOTOBA;//#define _LANG_ZHCN 1/* 定义对 话框 模板 */static DLGTEMPLATE DlgBoxInputNum ={ 0,//WS_BORDER | WS_CAPTION, WS_EX_NONE, 0,0,640,480, " CHIP COMPANY", 0,0,0,0};/* * 该对话框一共有11个控 件,分 别是机器标识,条码:条码编辑,名称:名称显示,数量:数量编辑,单价:单价显示,金额:金额显示 系统状态栏。 */#define IDC_NUM_MM 100#define IDC_SIZE_INCH 110#define IDC_NAME_MM 120#define IDC_ID_MM 130#define IDC_PRICE_MM 140#define IDC_TOTLE_MM 150#define IDC_NET_INFO 160#define IDC_SEND_INFO 170#define IDC_READ_INFO 180#define IDC_CTRL1 20#define IDC_CTRL2 30#define IDC_STATIC_NAME 31static CTRLDATA CtrlInputNum [] ={ { CTRL_STATIC, /*----------机器标识--------*/ WS_VISIBLE | SS_SIMPLE, 200,30,300,30, IDC_STATIC, " 烟 草 POS 机", 0 }, { CTRL_STATIC, /*----------条码--------*/ WS_VISIBLE | SS_SIMPLE, 160,110,100,30, IDC_STATIC, "条码:", 0 }, { CTRL_EDIT, /*----------条码编辑--------*/ WS_VISIBLE | WS_TABSTOP | WS_BORDER, 280, 100, 120, 30, IDC_ID_MM, NULL, 0 }, { CTRL_STATIC, /*----------烟草名称--------*/ WS_VISIBLE | SS_SIMPLE, 160,180,100,30, IDC_STATIC, "品名 :", 0 }, { CTRL_STATIC, /*----------名称显示--------*/ WS_VISIBLE /*| WS_TABSTOP */| WS_BORDER, 280, 170, 200, 30, IDC_NAME_MM, NULL, 0 }, { CTRL_STATIC, /*----------数量--------*/ WS_VISIBLE | SS_SIMPLE, 160,250,100,30, IDC_STATIC, "数量 :", 0 }, { CTRL_EDIT, /*----------数量编辑--------*/ WS_VISIBLE | WS_TABSTOP | WS_BORDER, 280, 240, 40, 30, IDC_NUM_MM, NULL, 0 }, { CTRL_STATIC, /*----------单价--------*/ WS_VISIBLE | SS_SIMPLE, 160,320,100,30, IDC_STATIC, "单价:", 0 }, { CTRL_STATIC, /*----------单价显示--------*/ WS_VISIBLE /*| WS_TABSTOP */| WS_BORDER, 280, 310, 200, 30, IDC_PRICE_MM, NULL, 0 }, { CTRL_STATIC, /*----------金额--------*/ WS_VISIBLE | SS_SIMPLE, 160,390,100,30, IDC_STATIC, "小计 :", 0 }, { CTRL_STATIC, /*----------金额显示--------*/ WS_VISIBLE /*| WS_TABSTOP*/ | WS_BORDER, 280, 380, 200, 30, IDC_TOTLE_MM, NULL, 0 }, { CTRL_STATIC, /*----------网络服务标识--------*/ WS_VISIBLE | SS_SIMPLE, 160,450,100,30, IDC_STATIC, "网络服务 :", 0 }, { CTRL_STATIC, /*----------网络状态链接成功了码--------*/ WS_VISIBLE | WS_BORDER, 280,440,200,30, IDC_NET_INFO, NULL, 0 },/* { CTRL_STATIC, WS_VISIBLE | WS_BORDER, 250,440,100,30, IDC_SEND_INFO, NULL, 0 }, { CTRL_STATIC, WS_VISIBLE | WS_BORDER, 430,440,100,30, IDC_READ_INFO, NULL, 0 }, */};//查找烟草的名称,反回0为没有找到 只是验证了前11位,static int littledata(char *p){ char data[4][13] ={ { /*43,*/ 54, 57, 48, 49, 48, 50, 56, 49, 57, 49, 48, 50, 57,}, //白沙 { /*43,*/54, 57, 48, 49, 48, 50, 56, 48, 55, 54, 51, 57, 53,}, //牡丹 { /*43,*/54, 57, 48, 49, 48, 50, 56, 48, 51, 55, 50, 55, 51,}, //黄果树 { /*43,*/ 54, 57, 48, 49, 48, 50, 56, 48, 53, 50, 56, 57, 52,}, //国宾 }; int i,j; printf ("now in littledata"); for (i=0;i<4;i++){ for(j=0;j<13;j++){ printf ("%d=%d",*(p+j),data[i][j]); if(*(p+j) != data[i][j]) break; if(j >= 12 ) return i+1; } printf ("\n"); } return 0;} static unsigned int totle; //用来记录小计的金额,//static unsigned char tabacoonum; //记录产品数量static unsigned int relnum; //记录产品数量static char pernum[2]; //pers函数内用来统计数量的数组,static char linshijiage = 0; //临时的一个烟草的价格,这么作不合理,只是临时的static int dataok = 0; //记录条码是否合理static char idbuf14[14]; //用来传递给SOCKET通讯的ID标识,static char *sockethead = "begin,td,00000001,";//static char *sockettail = "+1+1+2007,end"; //时间暂时设置成2007,以后在说static char *sockettail = "+2007,end"; //时间暂时设置成2007,以后在说//用来处理ID和产品数量控件的过程函数,static void my_notif_proc (HWND hwnd, int id, int nc, DWORD add_data){ if (id == IDC_ID_MM && nc == EN_CHANGE) { char buff [14]; int len ,i; len = GetWindowText (hwnd, buff, 14); if(len >= 13){ printf("buff is "); for(i=0;i<len;i++){ idbuf14[i] = buff[i]; printf("%d. ",buff[i]); } //idbuf14[14] = '/0'; printf("\n"); switch(littledata(buff)){ case 1: sprintf (buff, "白沙"); SetDlgItemText (GetParent (hwnd), IDC_NAME_MM, buff); sprintf (buff, "5.00"); linshijiage = 5; dataok = 1; SetDlgItemText (GetParent (hwnd), IDC_PRICE_MM, buff); break; case 2: sprintf (buff, "牡丹"); SetDlgItemText (GetParent (hwnd), IDC_NAME_MM, buff); sprintf (buff, "4.00"); linshijiage = 4; dataok = 1; SetDlgItemText (GetParent (hwnd), IDC_PRICE_MM, buff); break; case 3: sprintf (buff, "黄果树"); SetDlgItemText (GetParent (hwnd), IDC_NAME_MM, buff); sprintf (buff, "3.00"); linshijiage = 3; dataok = 1; SetDlgItemText (GetParent (hwnd), IDC_PRICE_MM, buff); break; case 4: sprintf (buff, "国宾"); SetDlgItemText (GetParent (hwnd), IDC_NAME_MM, buff); sprintf (buff, "9.00"); linshijiage = 9; dataok = 1; SetDlgItemText (GetParent (hwnd), IDC_PRICE_MM, buff); break; default: sprintf (buff,"无记录"); SetDlgItemText (GetParent (hwnd), IDC_NAME_MM, buff); sprintf (buff, "0"); linshijiage = 0; dataok = 1; SetDlgItemText (GetParent (hwnd), IDC_PRICE_MM, buff); } HideCaret(hwnd); SendMessage(GetParent (hwnd),MSG_CHANG_FOCUS_TO_NUM,0,0); sprintf (buff, "%d",linshijiage); //prompt (hDlg); SetDlgItemText (GetParent (hwnd), IDC_TOTLE_MM, buff); } } if (id == IDC_NUM_MM && nc == EN_CHANGE){ int i,ltotle; //unsigned int relnum; char num[2]; char buff[10]; i = GetWindowText(hwnd,num,2); pernum[1] = num[1]; pernum[0] = num[0]; num[0] -= 0x30; num[1] -= 0x30; printf("\n\nthe num is %d, %d",num[0],num[1]); //relnum = num; relnum = num[0]*10+num[1]; if(num[1] == 208){ relnum = num[0]; pernum[1] = '0'; if(num[0] == 208){ pernum[0] = '1'; relnum = 1; } } //tabacoonum = relnum; ltotle = linshijiage*relnum; totle = ltotle; printf ("\n\nlishijiange = %d num = %d totle = %d\n",linshijiage,relnum,totle); //linshijiage = 0; sprintf (buff, "%d",totle); SetDlgItemText (GetParent (hwnd), IDC_TOTLE_MM, buff); //SendMessage(GetParent (hwnd),MSG_CHANG_FOCUS_TO_ID,0,0); }}static char socketline[60];static void persINPstr (void){ //char x = "x"; char lshujia[6]; lshujia[0] = '+'; lshujia[1] = pernum[1]; lshujia[2] = pernum[0]; lshujia[3] = '+'; lshujia[4] = linshijiage+0x30; lshujia[5] = '\0'; printf ("\n\nlinshishujia is %s",lshujia); //printf("expect the sting is %s",idbuf14); strcpy(socketline,sockethead); strcat(socketline,idbuf14); strcat(socketline,lshujia); strcat(socketline,sockettail); printf("\n\nexpect the socketline is %s\n\n",socketline); if(write(client_sendpipe[1],socketline,50) < 0){ printf("ttys write err\n"); } else{ printf("client_sendpipe[1] write okok \n"); }}//对话框的主过程函数,static int InputNumDialogBoxProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam){ char buff[20]; switch (message) { case MSG_INITDIALOG: SetNotificationCallback (GetDlgItem (hDlg, IDC_ID_MM), my_notif_proc); SendMessage(GetDlgItem (hDlg, IDC_ID_MM),EM_GETLINECOUNT,12,0); SetNotificationCallback (GetDlgItem (hDlg, IDC_NUM_MM), my_notif_proc); return 1; case MSG_COMMAND: printf("in MSG_COMMAND wParam = %d lparam = %d\n",(int) wParam,(int) lParam); switch (wParam){ case 2: sprintf (buff, "网络已经链接成功"); SetDlgItemText (hDlg, IDC_NET_INFO, buff); //DestroyMainWindowIndirect (hDlg); //printf("now Updatewindow is it \n"); break; case 3: sprintf (buff, "信息已经发送"); SetDlgItemText (hDlg, IDC_NET_INFO, buff); //DestroyMainWindowIndirect (hDlg); //printf("now Updatewindow is it \n"); break; case 4: sprintf (buff, "接受到服务器信息"); SetDlgItemText (hDlg, IDC_NET_INFO, buff); //DestroyMainWindowIndirect (hDlg); //printf("now Updatewindow is it \n"); break; case 5: sprintf (buff, "没有网络连接请求"); SetDlgItemText (hDlg, IDC_NET_INFO, buff); //DestroyMainWindowIndirect (hDlg); //printf("now Updatewindow is it \n"); break; case 6: sprintf (buff, "网络连接失败"); SetDlgItemText (hDlg, IDC_NET_INFO, buff); //DestroyMainWindowIndirect (hDlg); //printf("now Updatewindow is it \n"); break; case 7: sprintf (buff, "没有ipconfig文件"); SetDlgItemText (hDlg, IDC_NET_INFO, buff); //DestroyMainWindowIndirect (hDlg); //printf("now Updatewindow is it \n"); break; } break; case MSG_KEYDOWN: printf("in MSG_KEYDOWN wParam = %d lparam = %d\n",(int)wParam,(int)lParam); switch (wParam){ case 28: //enter if(dataok == 1) { prompt (hDlg); persINPstr (); dataok = 0;} else promtno(hDlg); sprintf (buff, ""); SetDlgItemText (hDlg, IDC_ID_MM, buff); SetDlgItemText (hDlg, IDC_NAME_MM, buff); SetDlgItemText (hDlg, IDC_NUM_MM, buff); SetDlgItemText (hDlg, IDC_TOTLE_MM, buff); SetDlgItemText (hDlg, IDC_PRICE_MM, buff); SendMessage(hDlg,MSG_CHANG_FOCUS_TO_ID,0,0); //persINPstr (); linshijiage = 0; SendMessage(hDlg,MSG_CHANG_FOCUS_TO_ID,0,0); //"begin,td,00001,12345678+20+14.5+2007-05-12 10:35:01,end" //sprintf (buff, "%d",totle); //SetDlgItemText (hDlg, IDC_TOTLE_MM, buff); //mainhaha(); //SendMessage(hDlg,MSG_KEYDOWN,78,131200); break; case 98: //quit /key //UpdateWindow (hDlg,TRUE); EndDialog (hDlg, wParam); //printf("now Updatewindow is it \n"); break; case 78: //continue input new tobacco +++ //sprintf (buff, "%d",totle); //SetDlgItemText (hDlg, IDC_TOTLE_MM, buff); //mainhaha(); //SendMessage(hDlg,MSG_KEYDOWN,78,131200); break; } break; case MSG_CHANG_FOCUS_TO_NUM: //printf("now in MSG_CHANG_FOCUS haha \n"); SetFocusChild(GetDlgItem (hDlg, IDC_NUM_MM)); break; case MSG_CHANG_FOCUS_TO_ID: //printf("now in MSG_CHANG_FOCUS_TO_ID HAHA\n"); SetFocusChild(GetDlgItem (hDlg, IDC_ID_MM)); break; } return DefaultDialogProc (hDlg, message, wParam, lParam);}static int Iniclienmes(void){ if((clientmesqid = msgget(clientmesqidkey, IPC_CREAT | 0666)) < 0){ printf("clientmesqid creat erro\n"); return 1; } else{ printf("clientmesqid message queue ok \n"); printf ("message queue id = %d\n",clientmesqid); } return 0; }int MiniGUIMain (int argc, const char* argv[]){ //double length = 0; HWND hwnd; MSG Msg; //int initdlg = 0; #ifdef _MGRM_PROCESSES JoinLayer(NAME_DEF_LAYER , "input" , 0 , 0); #endif Iniclienmes(); DlgBoxInputNum.controls = CtrlInputNum; DlgBoxInputNum.controlnr = 13; //11个控件 hwnd = CreateMainWindowIndirect(&DlgBoxInputNum,HWND_DESKTOP,InputNumDialogBoxProc); if (hwnd == HWND_INVALID){ printf("\n"); printf("i'm quit wuwu\n"); printf("\n"); return -1; } if(pipe(client_sendpipe) == -1){ //打开主进程与SOCKET进程发送数据管 printf("open client_sendpipe pipe error\n"); return -1; } clientfork(); while ( GetMessage (&Msg, hwnd) ){ char msgbuf[15]; //printf("now i am in self main while\n"); /* if(Msg.wParam == 98 ){ printf ("\nin main while recieve quit hehe\n"); SendMessage(hwnd,MSG_COMMAND,2,0); continue; }*/ if(msgrcv(clientmesqid, msgbuf,1,0,MSG_NOERROR | IPC_NOWAIT) == -1){ //printf("reciev message error kuba\n"); }else{ printf("reciev ok haha"); printf("the buf is %c\n",msgbuf[0]); if(msgbuf[0] == 'c'){ SendMessage(hwnd,MSG_COMMAND,2,0); } if(msgbuf[0] == 's'){ SendMessage(hwnd,MSG_COMMAND,3,0); } if(msgbuf[0] == 'r'){ SendMessage(hwnd,MSG_COMMAND,4,0); } if(msgbuf[0] == 'x'){ SendMessage(hwnd,MSG_COMMAND,5,0); } if(msgbuf[0] == 'n'){ SendMessage(hwnd,MSG_COMMAND,6,0); } if(msgbuf[0] == 'f'){ SendMessage(hwnd,MSG_COMMAND,7,0); } } TranslateMessage (&Msg); DispatchMessage (&Msg); } //DialogBoxIndirectParam (&DlgBoxInputNum, HWND_DESKTOP, InputNumDialogBoxProc, (LPARAM)length); return 0;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -