📄 rtrtrtrtrtrtdlg.cpp
字号:
// rtrtrtrtrtrtDlg.cpp : implementation file
//
#include "stdafx.h"
#include "rtrtrtrtrtrt.h"
#include "rtrtrtrtrtrtDlg.h"
#include "iostream.h"
#include "fstream.h"
#include "string.h"
#include "malloc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CString filename;
struct goods a[100];
struct sale b[100];
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRtrtrtrtrtrtDlg dialog
CRtrtrtrtrtrtDlg::CRtrtrtrtrtrtDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRtrtrtrtrtrtDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRtrtrtrtrtrtDlg)
m_zhao = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CRtrtrtrtrtrtDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRtrtrtrtrtrtDlg)
DDX_Control(pDX, IDC_XIAOYILIST, m_jiaoyilist);
DDX_Control(pDX, IDC_FINDLIST, m_seeklist);
DDX_Control(pDX, IDC_SALELIST, m_salelist);
DDX_Control(pDX, IDC_GOODSLIST, m_goodslist);
DDX_Text(pDX, IDC_ZHAO, m_zhao);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRtrtrtrtrtrtDlg, CDialog)
//{{AFX_MSG_MAP(CRtrtrtrtrtrtDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_Open, OnOpen)
ON_BN_CLICKED(IDC_PAILIE, OnPailie)
ON_BN_CLICKED(IDC_SEEK, OnSeek)
ON_EN_CHANGE(IDC_ZHAO, OnChangeZhao)
ON_BN_CLICKED(IDC_JIAOYI, OnJiaoyi)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRtrtrtrtrtrtDlg message handlers
BOOL CRtrtrtrtrtrtDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
DataInit();
GetDlgItem(IDC_Open)->EnableWindow(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CRtrtrtrtrtrtDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CRtrtrtrtrtrtDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CRtrtrtrtrtrtDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CRtrtrtrtrtrtDlg::DataInit()//初始化
{
bFileEmpty=FALSE;
bNewFile=FALSE;
bFileModified=FALSE;//初始化文件属性
ifstream infile(filename,ios::in|ios::nocreate);//打开文件,失败返回错误信息
if(!infile)
{
bNewFile=TRUE;
bFileEmpty=TRUE;
iCount=0;
}
if(bFileEmpty==FALSE)//如果文件已存在,则从文件中读取数据建立链表
{
char temp[3];
infile>>temp;
iCount=atoi(temp);
for(int i=0;i<95;i++)//将所得信息放入结构体数组中
{ if(i<iCount)//商品信息的读入
{
infile>>a[i].num; //从文件中读取商品序号
infile>>a[i].amount; //数量
infile>>a[i].price; //价格
infile.ignore(2); //忽略而个空格
infile.getline(a[i].name,50,'\n'); //商品名
m_goodslist.InsertString(i*5,a[i].num); //向商品信息显示框输入信息
m_goodslist.InsertString(i*5+1,a[i].amount);
m_goodslist.InsertString(i*5+2,a[i].price);
m_goodslist.InsertString(i*5+3,a[i].name);
m_goodslist.InsertString(i*5+4," ");
}
else //交易信息的读入
{
infile>>b[i-33].code; //交易代码
infile>>b[i-33].num; //交易商品序号
infile>>b[i-33].sales; //买进卖出代码
infile>>b[i-33].amount; //买进卖出数量
m_salelist.InsertString((i-33)*5,b[i-33].code);
m_salelist.InsertString((i-33)*5+1,b[i-33].num);
m_salelist.InsertString((i-33)*5+2,b[i-33].sales);
m_salelist.InsertString((i-33)*5+3,b[i-33].amount);
m_salelist.InsertString((i-33)*5+4," ");
}
}
}
GetDlgItem(IDC_PAILIE)->EnableWindow(FALSE);//使其它几个按钮在读入文件前无法使用
GetDlgItem(IDC_JIAOYI)->EnableWindow(FALSE);
GetDlgItem(IDC_SEEK)->EnableWindow(FALSE);
}
void CRtrtrtrtrtrtDlg::OnOpen()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE,"txt");
char cFliter[]="Adress List File (*.txt)\0*.txt\0\0";
//规定能打开的的文件的后缀名为txt.
dlg.m_ofn.lpstrFilter=cFliter;
dlg.m_ofn.lpstrTitle="请输入要创建/打开的文件名...";
int iResult;
iResult = dlg.DoModal();
if(iResult == IDOK)
{
filename=dlg.GetFileName();//filename是全局变量用来存放文件名
}
DataInit(); //对读入的文件进行初始化
GetDlgItem(IDC_PAILIE)->EnableWindow(TRUE);//使排序按钮可用
GetDlgItem(IDC_JIAOYI)->EnableWindow(TRUE);//同上
}
void CRtrtrtrtrtrtDlg::OnPailie() //按序号升序尽心排序
{
// TODO: Add your control notification handler code here
m_goodslist.ResetContent();//将商品信息显示框重置
int i;
char t[50];//定义交换数组
for(int x=0;x<iCount;x++)//冒泡法
{ for( i=x;i<iCount;i++)
{
if ((atoi(a[x].num))>(atoi(a[i].num)))
{
strcpy(t,a[x].num);
strcpy(a[x].num,a[i].num);
strcpy(a[i].num,t);
strcpy(t,a[x].amount);
strcpy(a[x].amount,a[i].amount);
strcpy(a[i].amount,t);
strcpy(t,a[x].price);
strcpy(a[x].price,a[i].price);
strcpy(a[i].price,t);
strcpy(t,a[x].name);
strcpy(a[x].name,a[i].name);
strcpy(a[i].name,t);
}
}
}
for(i=0;i<iCount;i++)//输出排序完成后的商品信息
{
m_goodslist.InsertString(i*5,a[i].num);
m_goodslist.InsertString(i*5+1,a[i].amount);
m_goodslist.InsertString(i*5+2,a[i].price);
m_goodslist.InsertString(i*5+3,a[i].name);
m_goodslist.InsertString(i*5+4," ");
}
GetDlgItem(IDC_SEEK)->EnableWindow(TRUE);//使查找处于可用状态
}
void CRtrtrtrtrtrtDlg::OnSeek() //对商品进行查找(用二分法,须在排序之后使用)
{
// TODO: Add your control notification handler code here
m_seeklist.ResetContent();//更新查找商品信息显示框
int b,as,i;
b=iCount;
as=0;
for(i=b/2;;)//运用二分法进行查找
{
if (atoi(a[i].num)<m_zhao){as=i; i=(i+b)/2;}
else if(atoi(a[i].num)>m_zhao){i=(as+i)/2;}
if (atoi(a[i].num)==m_zhao||i==as){break;}
}
if(atoi(a[i].num)==m_zhao)//如有则输出对应商品信息
{
m_seeklist.InsertString(0,a[i].num);
m_seeklist.InsertString(1,a[i].amount);
m_seeklist.InsertString(2,a[i].price);
m_seeklist.InsertString(3,a[i].name);
}
else m_seeklist.InsertString(0,"无此商品");//没有则输出无此商品
}
void CRtrtrtrtrtrtDlg::OnChangeZhao()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
UpdateData(TRUE);
// TODO: Add your control notification handler code here
}
void CRtrtrtrtrtrtDlg::OnJiaoyi() //对商品进行交易
{
// TODO: Add your control notification handler code here
int x,y,n; //定义插入行数x和商品的循环y
x=0;
int i;
int z;
//char t[2];
for(i=0;i<62;i++)
{
m_jiaoyilist.InsertString(x++,b[i].code);
if(strcmp(b[i].sales,"S")&&strcmp(b[i].sales,"R"))//如买进卖出代码不是S或R则输出买卖代码错误
{
m_jiaoyilist.InsertString(x++,"买卖代码错误!");
}
if(atoi(b[i].amount)<0)//如果数量小于0则输出交易数量错误
{
m_jiaoyilist.InsertString(x++,"交易数量错误!");
}
if(atoi(b[i].amount)<0||(strcmp(b[i].sales,"S")&&strcmp(b[i].sales,"R")))
{
m_jiaoyilist.InsertString(x++," ");
continue;
}
else
for(y=0;y<iCount;y++)
{
n=0;
if(!strcmp(a[y].num,b[i].num))//匹配成功则对商品数量进行相应的加减
{ n=1 ;
if(!strcmp(b[i].sales,"S"))
{
z=atoi(a[y].amount)-atoi(b[i].amount);
a[y].amount[1]=z%10+48;
a[y].amount[0]=z/10+48;
if(a[y].amount[1]<48)
{a[y].amount[1]=48;
m_jiaoyilist.InsertString(x++,"商品数量不够");}
}
else
{
z=atoi(a[y].amount)+atoi(b[i].amount);
a[y].amount[1]=z%10+48;
a[y].amount[0]=z/10+48;
}
break;
}
}
if(n)
{m_jiaoyilist.InsertString(x++,"交易成功!");}
else//不成功则显示无私商品
{m_jiaoyilist.InsertString(x++,"库中无此商品");}
m_jiaoyilist.InsertString(x++," ");
}
m_goodslist.ResetContent();//更新商品信息显示框
for(i=0;i<iCount;i++)//输出经过交易后的商品信息
{
m_goodslist.InsertString(i*5,a[i].num);
m_goodslist.InsertString(i*5+1,a[i].amount);
m_goodslist.InsertString(i*5+2,a[i].price);
m_goodslist.InsertString(i*5+3,a[i].name);
m_goodslist.InsertString(i*5+4," ");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -