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

📄 main.cpp

📁 一个用VC写的超市管理系统
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#include"math.h"
#pragma hdrstop

#include <stdio.h>
#include "main.h"
#include "data.h"
#include "name_gl.h"
#include "jinhuo_gl.h"
#include "lingshou.h"
#include "kucen.h"
#include "xiaoshou.h"
#include "passwd.h"
#include "check.h"
#include "xiaopiao.h"
#include "qingli.h"
#include "xiaoshoumx.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
Tfm_main *fm_main;
//-----------------------------------------------------
int danjuhao,row;;
//---------------------------------------------------------------------------
__fastcall Tfm_main::Tfm_main(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::bt_nameClick(TObject *Sender)
{
    fm_name_gl->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::bt_jinhuoClick(TObject *Sender)
{
    fm_jinhuo_gl->ShowModal();    
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::FormShow(TObject *Sender)
{
    //计算单据号
    dm_data->ds_guest->Close();
    dm_data->ds_guest->CommandText="select top 1 * from xiaoshou order by danjuhao desc";
    dm_data->ds_guest->Open();
    if(dm_data->ds_guest->RecordCount<1 && (shuliang->Focused()==true || shoujia->Focused()==true || dazhe->Focused()==true))
        danjuhao=1;
    else
        danjuhao=dm_data->ds_guest->FieldByName("danjuhao")->AsInteger+1;
        dm_data->ds_guest->Close();
    row=0;
    lb->RowCount=1;
    lb->ColCount=8;
    lb->ColWidths[3]=30;
    lb->ColWidths[7]=150;
    lb->Cells[0][0]="序号";
    lb->Cells[1][0]="货号";
    lb->Cells[2][0]="货名";
    lb->Cells[3][0]="数量";
    lb->Cells[4][0]="定价";
    lb->Cells[5][0]="优惠价";
    lb->Cells[6][0]="金额";
    lb->Cells[7][0]="时间";

    danjuhaos->Text=danjuhao;
    shuliang_hj->Text="0";
    jine_hj->Text="0";
    xianfu->Text="0";
    
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::codeKeyPress(TObject *Sender, char &Key)
{
    if(Key==VK_RETURN)
        PostMessage(Handle,WM_KEYDOWN,VK_TAB,0);
}
//---------------------------------------------------------------------------


void __fastcall Tfm_main::shuliangKeyPress(TObject *Sender, char &Key)
{
    if(Key==VK_RETURN)
        PostMessage(Handle,WM_KEYDOWN,VK_TAB,0);
    
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::shoujiaKeyPress(TObject *Sender, char &Key)
{
    if(Key==VK_RETURN)
        PostMessage(Handle,WM_KEYDOWN,VK_TAB,0);

}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::dazheKeyPress(TObject *Sender, char &Key)
{
    if(Key==VK_RETURN)
        PostMessage(Handle,WM_KEYDOWN,VK_TAB,0);
    
}
//---------------------------------------------------------------------------


void __fastcall Tfm_main::codeExit(TObject *Sender)
{
    dm_data->ds_guest->Close();
    dm_data->ds_guest->CommandText="select jinhuo.*,name.name from jinhuo,name where jinhuo.code='"+code->Text+"' and name.code=jinhuo.code order by id desc";
    dm_data->ds_guest->Open();
    if(dm_data->ds_guest->RecordCount<1 && (shuliang->Focused()==true || shoujia->Focused()==true || dazhe->Focused()==true || chuhuo->Focused()==true))
    {
        Application->MessageBoxA("该货物可能没有进货,请重新输入","提示",MB_OK);
        code->SetFocus();
    }
    else
    {
        int sn=0;
        shoujia->Text=dm_data->ds_guest->FieldByName("shoujia")->AsString;
        dingjia->Text=shoujia->Text;
        name->Text=dm_data->ds_guest->FieldByName("name")->AsString;
        shuliang->Text="1";
        while(!dm_data->ds_guest->Eof)
        {
            sn=sn+dm_data->ds_guest->FieldByName("shuliang")->AsInteger;
            dm_data->ds_guest->Next();
        }
        shuliang0->Text=IntToStr(sn);
    }
    dm_data->ds_guest->Close();
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::shoujiaChange(TObject *Sender)
{
    float shoujian,dazhen,shoujia0n;

    if((shoujia->Text.Trim()!="") && (dazhe->Text.Trim()!=""))
    {
        shoujian=StrToFloat(shoujia->Text);
        dazhen=StrToFloat(dazhe->Text);
        shoujia0n=shoujian*dazhen/10;
        shoujia0->Text=FormatFloat("0.00",shoujia0n);
    }
}
//---------------------------------------------------------------------------


void __fastcall Tfm_main::shoujiaxgClick(TObject *Sender)
{
    if(shoujiaxg->Checked==true)
        shoujia->Enabled=true;
    else
        shoujia->Enabled=false;
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::dazhexgClick(TObject *Sender)
{
    if(dazhexg->Checked==true)
        dazhe->Enabled=true;
    else
        dazhe->Enabled=false;

}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::chuhuoClick(TObject *Sender)
{
    dm_data->ds_guest->Close();
    dm_data->ds_guest->CommandText="select jinhuo.*,name.name from jinhuo,name where jinhuo.code='"+code->Text+"' and name.code=jinhuo.code order by id desc";
    dm_data->ds_guest->Open();
    if(dm_data->ds_guest->RecordCount<1)
    {
        Application->MessageBoxA("该货物可能没有进货,请重新输入","提示",MB_OK);
        code->SetFocus();
        dm_data->ds_guest->Close();
        return;
    }

    row=row+1;
    lb->RowCount=row+1;
    lb->Cells[0][row]=row;
    lb->Cells[1][row]=code->Text;
    lb->Cells[2][row]=name->Text;
    lb->Cells[3][row]=shuliang->Text;
    lb->Cells[4][row]=FormatFloat("0.00",StrToFloat(dingjia->Text));
    lb->Cells[5][row]=shoujia0->Text;
    lb->Cells[6][row]=FormatFloat("0.00",StrToFloat(shoujia0->Text)*StrToInt(shuliang->Text));
    lb->Cells[7][row]=Now();

    shuliang_hj->Text=StrToInt(shuliang_hj->Text)+StrToInt(shuliang->Text);
    jine_hj->Text=FormatFloat("0.00",StrToFloat(jine_hj->Text)+StrToFloat(lb->Cells[6][row]));
    code->SetFocus();
}
//---------------------------------------------------------------------------






void __fastcall Tfm_main::xianfuKeyPress(TObject *Sender, char &Key)
{
    if(Key==VK_RETURN)
        PostMessage(Handle,WM_KEYDOWN,VK_TAB,0);

}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::xianfuExit(TObject *Sender)
{
    zhaoling->Text=FloatToStr(StrToFloat(xianfu->Text)-StrToFloat(jine_hj->Text));
}
//---------------------------------------------------------------------------


void __fastcall Tfm_main::jiezhangClick(TObject *Sender)
{
    AnsiString price;
    TDateTime dd;
//
   if(row<1)
   {
        Application->MessageBoxA("没有货物可供结帐,请输入货物代码","提示",MB_OK);
        code->SetFocus();
        return;
    }
    //打印
    if(dy->Checked==true)
    {
        FILE *fp;
        AnsiString str="";
        if((fp=fopen("Lpt1","wb"))==NULL)
        {
            Application->MessageBoxA("打印机出错","警告",MB_OK);
            return;
        }
        if(huiyuan->Checked==true)
            price="会员价";
        else
            price="定价";

        dm_data->ds_guest->Close();
        dm_data->ds_guest->CommandText="select * from code where id>=20000 and id<30000 order by id";
        dm_data->ds_guest->Open();
        dm_data->ds_guest->First();

        str=str.cat_sprintf("%s\n",dm_data->ds_guest->FieldByName("content")->AsString);
        str=str.cat_sprintf("流水号: %d\n",danjuhao);
        str=str.cat_sprintf("时  间: %s\n",Now().FormatString("yyyy-mm-dd hh:nn:ss"));
        str=str.cat_sprintf("%s\n","--------------------------------");
        str=str.cat_sprintf("%-14s%4s %6s %6s\n","货名","数量",price,"金额");
        for(int i=1;i<=row;i++)
            str=str.cat_sprintf("%-14s%4s %6s %6s\n",lb->Cells[2][i],lb->Cells[3][i],lb->Cells[5][i],lb->Cells[6][i]);
        str=str.cat_sprintf("%s\n","--------------------------------");
        str=str.cat_sprintf("%-14s%4s %13s\n","合计",shuliang_hj->Text,jine_hj->Text);

        dm_data->ds_guest->Next();
        while(!dm_data->ds_guest->Eof)
        {
            str=str.cat_sprintf("%s\n",dm_data->ds_guest->FieldByName("content")->AsString);
            dm_data->ds_guest->Next();
        }
        str=str.cat_sprintf("%s\n","\n\n\n\n\n\n");

        fputs(str.c_str(),fp);
        fclose(fp);
        dm_data->ds_guest->Close();
    }
    //保存数据
    dm_data->ds_guest->Close();
    dm_data->ds_guest->CommandText="select * from xiaoshou where danjuhao<1";
    dm_data->ds_guest->Open();

    for(int i=1;i<=row;i++)
    {
        dm_data->ds_guest->Append();
        dm_data->ds_guest->FieldValues["danjuhao"]=danjuhao;
        dm_data->ds_guest->FieldValues["code"]=lb->Cells[1][i];
        dm_data->ds_guest->FieldValues["shuliang"]=lb->Cells[3][i];
        dm_data->ds_guest->FieldValues["shoujia"]=lb->Cells[5][i];
        dm_data->ds_guest->FieldValues["jine"]=lb->Cells[6][i];
        dm_data->ds_guest->FieldValues["dt"]=lb->Cells[7][i];
        dd=lb->Cells[7][i];
        dm_data->ds_guest->FieldValues["dtd"]=dd.DateString();
    }
    dm_data->ds_guest->Post();
    dm_data->ds_guest->Close();

    //计算单据号 初始化
    danjuhao=danjuhao+1;
    row=0;
    lb->RowCount=1;

    danjuhaos->Text=danjuhao;
    shuliang_hj->Text="0";
    jine_hj->Text="0";
    xianfu->Text="0";
    code->SetFocus();
}
//---------------------------------------------------------------------------



void __fastcall Tfm_main::FormShortCut(TWMKey &Msg, bool &Handled)
{
    switch(Msg.CharCode)
    {
        case VK_F1:
            code->SetFocus();
            break;
        case VK_F2:
            shuliang->SetFocus();
            break;
        case VK_F3:
            shoujia->SetFocus();
            break;
        case VK_F4:
            dazhe->SetFocus();
            break;
        case VK_F5:
            chuhuo->SetFocus();
            PostMessage(Handle,WM_KEYDOWN,VK_RETURN,0);
            break;
        case VK_F6:
            qingchu->SetFocus();
            PostMessage(Handle,WM_KEYDOWN,VK_RETURN,0);
            break;
        case VK_F7:
            xianfu->SetFocus();
            break;
        case VK_F8:
            jiezhang->SetFocus();
            PostMessage(Handle,WM_KEYDOWN,VK_RETURN,0);
            break;
    }
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::qingchuClick(TObject *Sender)
{
    row=0;
    lb->RowCount=1;

    shuliang_hj->Text="0";
    jine_hj->Text="0";
    xianfu->Text="0";
    code->SetFocus();

}
//---------------------------------------------------------------------------


void __fastcall Tfm_main::bt_lingshouClick(TObject *Sender)
{
    fm_lingshou_gl->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::bt_kucenClick(TObject *Sender)
{
    fm_kucen->ShowModal();    
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::bt_xiaoshouClick(TObject *Sender)
{
    fm_xiaoshou->ShowModal();    
}
//---------------------------------------------------------------------------




void __fastcall Tfm_main::touserClick(TObject *Sender)
{
    if(touser->ItemIndex==0)
    {
        Panel1->Visible=false;
        return;
    }
    fm_check->ShowModal();
    dm_data->ds_passwd->Close();
    dm_data->ds_passwd->Open();
    if(passwd==dm_data->ds_passwd->FieldByName("code")->AsString)
        Panel1->Visible=true;
    else
    {
        Panel1->Visible=false;
        touser->ItemIndex=0;
    }
    dm_data->ds_passwd->Close();
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::bt_sysClick(TObject *Sender)
{
    fm_passwd->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::bt_xiaopiaoClick(TObject *Sender)
{
    fm_xiaopiao->ShowModal();  
}
//---------------------------------------------------------------------------


void __fastcall Tfm_main::bt_dataClick(TObject *Sender)
{
    fm_qingli->ShowModal();    
}
//---------------------------------------------------------------------------



void __fastcall Tfm_main::Button1Click(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------

void __fastcall Tfm_main::Button2Click(TObject *Sender)
{
    fm_xiaoshoumx->Show();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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