📄 jin.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdlib.h>
#include <stdio.h>
#include "jin.h"
#include "main.h"
#include "thread.h"
#include "global.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
Tform_jin *form_jin;
extern TDonThread *donThread;
//---------------------------------------------------------------------------
__fastcall Tform_jin::Tform_jin(TComponent* Owner)
: TForm(Owner)
{
xuhao=0;
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::exit_bClick(TObject *Sender)
{
next_bClick(NULL);
form_main->Show();
Hide();
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::FormCreate(TObject *Sender)
{
Caption=bd.name;
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key==F3_KEY) enter_bClick(NULL);
else if(Key==F1_KEY) clear_bClick(NULL);
//else if(Key==F8_KEY) print_bClick(NULL);
else if(Key==F5_KEY) next_bClick(NULL);
else if(Key==Esc_KEY) exit_bClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::Timer1Timer(TObject *Sender)
{
long now_ad_j1,now_ad_z1,now_ad_j2,now_ad_z2;
char str[30];
get_ad_jin(&now_ad_j1,&now_ad_j2,&now_ad_z1,&now_ad_z2);
switch(bd.hq_mode){
case HQ_DG:
if(bd.fx==1 && bd.pb_mode==PB_WAVE)//wave判别方向需2个重力通道
now_ad=(now_ad_z1+now_ad_z2)/2-zero_jin;
else
now_ad=now_ad_z1-zero_jin;
break;
case HQ_BDG:
if(bd.fx==1 && bd.pb_mode==PB_WAVE)//wave判别方向需2个重力通道
now_ad=now_ad_j1*bd.k_j_z +(now_ad_z1+now_ad_z2)/2-zero_jin;
else
now_ad=now_ad_j1*bd.k_j_z +now_ad_z1-zero_jin;
break;
case HQ_CPZ:
default:
now_ad=((now_ad_j1+now_ad_j2)*bd.k_j_z+now_ad_z1+now_ad_z2)/2-zero_jin;
break;
}
// now_ad 被 TDonThread::Execute() 使用
if(now_ad<3 && now_ad> -3 && bd.use_status==USE_ZC){ // 零点跟踪
zero_jin+=now_ad;
now_wei=0;
}else
now_wei=ad_to_wei_jin(now_ad);
long static ad_wd[2];
ad_wd[0]=ad_wd[1];
ad_wd[1]=now_ad;
if(abs(ad_wd[0]-ad_wd[1])<5) flag_wd=TRUE;
else flag_wd=FALSE;
if(flag_wd==TRUE) Label1->Font->Color=clBlue;
else Label1->Font->Color=clRed;
sprintf(str,"%5.2f",(float)now_wei/1000.0);
Label1->Caption=str;
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::FormHide(TObject *Sender)
{
Timer1->Enabled=false;
if(table1->Active==true){
table1->Refresh();
table1->Close();
}
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::FormShow(TObject *Sender)
{
Timer1->Enabled=true;
table1->EmptyTable();
if(table1->Exists==true) table1->Open();
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::clear_bClick(TObject *Sender)
{
if(flag_wd==true) zero_jin=now_ad+zero_jin;
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::enter_bClick(TObject *Sender)
{
if(flag_wd==true){
table1->Append();
table1No->Value=++xuhao;
table1Mao->Value=(double)now_wei/1000.00;
table1Pi->Value=0.00;
table1Spd->Value=0;
table1->Post();
table1->Close();
table1->Open();
table1->Last();
}
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::table1PiChange(TField *Sender)
{
table1Jin->Value=table1Mao->Value - table1Pi->Value;
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::create_dbname()
{
LPSYSTEMTIME lpst=new SYSTEMTIME;
if(lpst){
GetLocalTime(lpst);
sprintf(tm,"%04d%02d%02d_%02d%02d%02d",lpst->wYear,
lpst->wMonth,lpst->wDay,lpst->wHour,lpst->wMinute,lpst->wSecond);
sprintf(dbname,"%s%s.db",DB_PATH,tm);
}
}
void __fastcall Tform_jin::next_bClick(TObject *Sender)
{
if(xuhao>0){
create_dbname();
donThread->set_tm_cecnt(tm,xuhao);
donThread->refresh_dir();
print_bClick(NULL); //print it
if(table1->Active==true){
table1->Refresh();
table1->Close();
}
char from_dbname[100]; // refresh data
sprintf(from_dbname,"%s%s",DB_PATH,"data.db");
CopyFile(from_dbname,dbname,false);
table1->EmptyTable();
table1->Open();
xuhao=0;
}
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::print_bClick(TObject *Sender)
{
FILE *prn ;
char title[100];
double total_mao=0,total_jin=0;
if(xuhao>0 && table1->Active==TRUE){
/*
// save
create_dbname();
donThread->set_tm_cecnt(tm,xuhao);
donThread->refresh_dir();*/
// print
strcpy(title,bd.name);
strcat(title,"轨道衡过衡报告单");
if((prn=fopen("PRN","wb"))!=NULL){
fprintf(prn,"%60s\n\n",title);
fprintf(prn," 日期_时间:%s 单位:吨\n",tm);
fprintf(prn,"----------------------------------------------------------------------------------------\n");
fprintf(prn,"%4s%10s%8s%8s%8s%12s%16s%16s%6s\n","序号","车号",
"毛重","皮重","净重","货名","收货单位","发货单位","速度");
fprintf(prn,"----------------------------------------------------------------------------------------\n");
for(table1->First();table1->Eof!=TRUE;table1->Next()){
fprintf(prn,"%4s%10s%8.02f%8.02f%8.02f%12s%16s%16s%6d\n",
table1->FindField("No")->AsString.c_str(),
table1->FindField("Cehao")->AsString.c_str(),
table1->FindField("Mao")->AsFloat,
table1->FindField("Pi")->AsFloat,
table1->FindField("Jin")->AsFloat,
table1->FindField("Name")->AsString.c_str(),
table1->FindField("Rec")->AsString.c_str(),
table1->FindField("Send")->AsString.c_str(),
table1->FindField("Spd")->AsInteger );//dataSpd->AsString.c_str()
total_mao+=(double)(table1->FindField("Mao")->AsFloat) ;
total_jin+=(double)(table1->FindField("Jin")->AsFloat) ;
fprintf(prn,"----------------------------------------------------------------------------------------\n");
}
fprintf(prn," 毛重合计:%-8.2f 净重合计:%-8.2f 操作员:\n", total_mao,total_jin);
fprintf(prn,"\n\n\n");
fclose(prn);
}
/*
// ready for next_ce
if(table1->Active==true){
table1->Refresh();
table1->Close();
}
char from_dbname[100];
sprintf(from_dbname,"%s%s",DB_PATH,"data.db");
CopyFile(from_dbname,dbname,false);
table1->EmptyTable();
table1->Open();
xuhao=0;*/
}//if
}
//---------------------------------------------------------------------------
void __fastcall Tform_jin::DBGrid1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if( (Key==Insert_KEY) ||
(Key==Delete_KEY && Shift.Contains(ssCtrl)) ||
(Key==DOWN_KEY) ||
(Key==Tab_KEY) ) // 防止加减记录
DBGrid1->ReadOnly=TRUE;
else
DBGrid1->ReadOnly=FALSE;
if( Key==Enter_KEY ) table1->Next();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -