-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit1.cpp
145 lines (124 loc) · 3.86 KB
/
Unit1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#include <string.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
float TForm1::strToFloat(AnsiString text)
{
float ret = 0.0;
AnsiString str = Trim(text);
/*
try
{
ret = StrToFloat(str);
}
catch(...)
{
}
*/
ret = atof(str.c_str());
return ret;
}
void TForm1::ShowPrice()
{
float price = 0.0;
float rate = 0.0;
float fright = 0.0;
float profit = 0.0;
float freeFright, weight, no = 0.0;
price = strToFloat(txtPrice->Text);
rate = strToFloat(txtRate->Text);
fright = strToFloat(txtFright->Text);
profit = strToFloat(txtProfit->Text);
freeFright = strToFloat(txtFreeProfit->Text);
weight = strToFloat(txtWeight->Text);
if(chkNo->Checked)
{
no = strToFloat(txtNo->Text); // 挂号费
}
if(price<0.1)
{
//Application->MessageBox("请输入正确的价格!","注意", MB_ICONWARNING);
lbPrice->Caption = "请输入正确的价格!";
return;
}
float cost , sellPrice, packetFright;
cost = (price + fright)/rate;
packetFright = (weight*freeFright+no)/rate;
sellPrice = (cost + cost*profit/100 + packetFright)/0.95;
char tip[512]={0};
sprintf(tip, "成本:$%.2f \t(%.2f元)\n\
运费:$%.2f \t(%.2f元)\n\
售价:$%.2f \t(%.2f元)\n\
利润:$%.2f \t(%.2f元)",
cost, cost*rate,
packetFright, packetFright*rate,
sellPrice, sellPrice*rate,
cost*profit/100, cost*profit*rate/100
);
lbPrice->Caption = tip;
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//Bordercons->biMaximize=false;
//BorderStyle=bsSingle;
//lbPrice->Caption = "";
char title[128];
sprintf(title, "速卖通价格试算%s", APP_VER);
this->Caption = title;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
txtPrice->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::txtPriceEnter(TObject *Sender)
{
ShowPrice();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::txtProfitChange(TObject *Sender)
{
ShowPrice();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::txtFrightChange(TObject *Sender)
{
ShowPrice();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::txtPriceChange(TObject *Sender)
{
ShowPrice();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::chkNoClick(TObject *Sender)
{
ShowPrice();
if(chkNo->Checked)
{
//chkNo->Checked = false;
txtNo->Enabled = true;
return;
}
//chkNo->Checked = true;
txtNo->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::txtNoChange(TObject *Sender)
{
ShowPrice();
}
//---------------------------------------------------------------------------