写这样的代码是不是很烂啊。。 能否走得出去?(女程序员想换个工作了) (100分)

L

leisure

Unregistered / Unconfirmed
GUEST, unregistred user!
<大伙留个意见吧~~~我这样敢不敢出去~~>
当然还会懂一些其它的东西。。

从串口采集数据处理后送数据库.
根据不同的客户测试方法不同
//=======================================
unit DataToDBThread;
{数据存数据库单元}
interface
uses
Classes,ADODB,ActiveX,Dialogs;
type
TDataToDBThread = class(TThread)
private
{ Private declarations }
Str:AnsiString;
ADOQUERY1:TADOQuery;
protected
procedure Execute;override;
destructor destroy;
public
constructor Create(Suspended:boolean;SQLSTR:AnsiString);
end;
implementation
uses Glo_FuncProc;
constructor TDataToDBThread.Create(suspended:boolean;SQLSTR:AnsiString);
begin
inherited create(suspended);
Str:=SQLSTR;
end;
destructor TDataToDBThread.destroy;
begin
inherited;
end;
procedure TDataToDBThread.Execute;
begin
{ Place thread code here }
CoInitialize(Nil);
if (not Assigned(ADOQUERY1)) then
ADOQUERY1:=TADOQUERY.Create(nil);
try
try
with ADOQUERY1do
begin
Close;
ConnectionString :=SetConnectionString;
SQL.Clear ;
SQL.Add(Str);
ExecSQL ;
Close;
end;
except
showmessage('网络不通,请检查!') //*****************不能用哦。。。
end;
finally
FreeAndNil(ADOQUERY1);
//经指点将ADOQUERY1.Free改正后
end;
CoUnInitialize;
end;
end.
//=======================================
unit Glo_FuncProc;
{共享函数及过程单元}
interface
uses GloVariant,TypInfo,Classes,ADODB,Dialogs,Graphics,spcomm,Types,ExtCtrls,SysUtils;
function GetCustomerType(const customer: string): integer;
function GetCustomerFromDB:TStringList;
function SetConnectionString:WideString;
procedure CommIni(C:TComponent;SCom:string);
procedure PaintImg(I:TComponent;ImgPos:integer;const BgColor:TColor;const Str:string='');
procedure TextImg(I:TComponent;ImgPos:integer;const BgColor:TColor;Text:string);
implementation
function GetCustomerType(const customer: string): integer;
{Return: -1表示此客户未定义属于哪一类型,0表示是DELL类客户,1表示是HP类客户}
var
THpP,TDellP: PTypeInfo;
Hpi,Delli: Integer;
begin
Result:=-1;
THpP:=TypeInfo(TEnumHP);
TDellP:=TypeInfo(TEnumDell);
Hpi:=GetEnumValue(THpP,customer);
Delli:=GetEnumValue(TDellP,customer);
if (Delli=-1) and (Hpi=-1) then
Result:=-1
else
begin
if (Hpi=-1) then
Result:=0;
if (Delli=-1) then
Result:=1;
end;
end;

function SetConnectionString:WideString;
{设置连接数据库字符串}
begin
Result:='Provider=SQLOLEDB.1;Password=cpk;Persist Security Info=True;User ID=cpk;';
Result:=Result+'Initial Catalog=Ictdb;Data Source='+Server;
end;

function GetCustomerFromDB:TStringList;
{从数据库得到所有的客户}
var
ADOQry:TADOQuery;
i:integer;
begin
GetCustomerFromDB:=TStringList.Create ;
ADOQry:=TADOQuery.Create(nil);
try
ADOQry.ConnectionString:=SetConnectionString;
ADOQry.Active:=false;
ADOQry.SQL.Clear ;
ADOQry.SQL.Add('Select Customer from CustomerTb');
ADOQry.Open;
i:=0;
while (not ADOQry.Eof) do
begin
GetCustomerFromDB.Insert(i,ADOQry.FieldByName('customer').asstring);
ADOQry.next;
Inc(i,1);
end;
ADOQry.Close ;
finally
ADOQry.Free ;
end;
end;

procedure CommIni(C:TComponent;SCom:string);
{串口初始化}
begin
try
with TComm(C)do
begin
StopComm;
CommName:=SCom;
BaudRate :=9600;
ByteSize :=_7;
StopBits:=_2;
Parity:=Even;
StartComm;
end;
except
ShowMessage('打开串口出错');
exit;
end;
end;

procedure PaintImg(I:TComponent;ImgPos:integer;const BgColor:TColor;const Str:string='');
{画背景提示图案}
var
R,ImgR:TRect;
TpLeft,BmRight:TPoint;
begin
with TImage(I)do
begin
ImgR.TopLeft:=Point(0,0);
ImgR.BottomRight:=Point(Width,Height);
Canvas.Brush.Color:=BgColor;
Canvas.FillRect(ImgR);
case ImgPos of
1:
begin
TpLeft:=Point(0,0);
BmRight:=Point(50,50);
end;
2:
begin
TpLeft:=Point(Width-50,0);
BmRight:=Point(Width,50);
end;
3,6:
begin
TpLeft:=Point(Width div 2 - 25 ,Height div 2 - 25);
BmRight:=Point(Width div 2 + 25 ,Height div 2 + 25);
end;
4:
begin
TpLeft:=Point(0,Height-50);
BmRight:=Point(50,Height);
end;
5:
begin
TpLeft:=Point(Width-50,Height-50);
BmRight:=Point(Width,Height);
end;
end;
R.TopLeft:=TpLeft;
R.BottomRight:=BmRight;
Canvas.Font.Color :=clMaroon;
Canvas.Brush.Color:=clblue;
if ImgPos<>6 then
Canvas.Ellipse(R)
else
begin
Canvas.Brush.Color :=BgColor;
Canvas.TextOut(10,10,Str);
Canvas.Brush.Color :=clblue;
Canvas.Rectangle(R);
end;
Canvas.Font.Size :=25;
Canvas.TextOut(TpLeft.X+15,TpLeft.Y+6,IntToStr(ImgPos));
end;
end;

procedure TextImg(I:TComponent;ImgPos:integer;const BgColor:TColor;Text:string);
{画提示字符}
var
Row,x:integer;
TxWidth,TxHeight:integer;
ImgR:TRect;
begin
with TImage(I)do
begin
ImgR.TopLeft:=Point(0,0);
ImgR.BottomRight:=Point(Width,Height);
Canvas.Font.Color :=clMaroon;
Canvas.Brush.Color:=BgColor;
Canvas.FillRect(ImgR);
Canvas.Font.Size :=25;
TxWidth:=Canvas.TextWidth(Text);
row:=1;
if TxWidth>Width-ImgPos then
begin
if (TxWidth/(Width-ImgPos))<>(TxWidth div (Width-ImgPos)) then
Row:=TxWidth div Width +1;
end;

TxHeight:=Canvas.TextHeight(Text);
for x:=1 to rowdo
begin
Canvas.TextOut(ImgPos,x*TxHeight+6,copy(Text,(Length(Text) div row )*(x-1)
,Length(Text) div row ));
end;
end;
end;
end.
//==========================================================================
unit Glo_VarConst;
{全程常量及变量单元}
interface
const
ProjCap:array [1..9] of String=('BU/WU','色纯(Red)','色纯(Green)','Cutoff Raster',
'全白亮度','窗口亮度','Raster','白平衡(9300)','白平衡(6500)');
ComputeNum:array [0..1] of integer=(50,36);
//DELL=50,HP=36
type
TEnumDELL=(DELL);
TEnumHP=(HP,SNI,COMPAQ,IIYAMA,VISONIC);
TBuWuRG=record
x:integer;
y:integer;
dy:single;
end;

TMyBuWuRG=array [0..5] of TBuWuRG;
{0:根据1-5计算出来的值 1-5:是五点的当前值}
TData = record
BuWuRG:array [1..3] of TMyBuWuRG;
{ 1.BuWu 2.色纯(R)3.色纯(G)}
dy:array [4..7] of single;
{4-8是CutOff Raster- 白平衡6500的值}
BalanceW:array [8..9] of array [0..1] of integer;
end;

TTimPat=record
Timing:string;
Pattern:string;
end;

TSingleMaxMinLimit=record
Max:single;
Min:single;
end;

TIntMaxMinLimit=record
Max:integer;
Min:integer;
end;

TBuWuMaxMinLimit=record
x:TIntMaxMinLimit;
y:TIntMaxMinLimit;
dy:TSingleMaxMinLimit;
end;

TRGWBALAMaxMinLimit=record
x:TIntMaxMinLimit;
y:TIntMaxMinLimit;
end;

TMaxMinLimit=record
BuWu:array [1..1] of TBuWuMaxMinLimit ;
RG: array [2..3] of TRGWBALAMaxMinLimit;
Dy: array [4..7] of TSingleMaxMinLimit;
WBalance: array [8..9,0..1] of TIntMaxMinLimit;
end;

var
TimPat:array [1..9] of TTimPat;
MaxMinLimit:TMaxMinLimit;
Server:String;
implementation
end.
//======================================
unit CacuDataCls;
{计算数据类}
interface
uses
Classes,Graphics,Types,ExtCtrls,SysUtils,Dialogs,Variants;
type
MaxMin=array [0..1] of String;
TCacuData=class(TObject)
private
FMax:variant;
FMin:variant;
protected
procedure SetMax(value:variant);
procedure SetMin(value:variant);
public
constructor Create;
destructor destroy;override;
function MaxMin(Data:variant):MaxMin;
function AddZeroToStr(Data:variant):string;
function MaxSubMin:string;
function MinDivMax:string;
procedure IniMaxMinZero;
published
property Max:variant read FMax write SetMax ;
property Min:variant read FMin write SetMin ;
end;

implementation
{ TCacuMaxMin }
constructor TCacuData.Create;
begin
FMax:=0;
FMin:=0;
end;

destructor TCacuData.destroy;
begin
inherited;
end;

procedure TCacuData.IniMaxMinZero;
begin
FMax:=0;
FMin:=0;
end;

function TCacuData.MinDivMax: String;
{小数除以大数,以百分几返回}
begin
if FMax=0 then
MinDivMax:='0'
else
MinDivMax:=AddZeroToStr((FMin/FMax)*100);
end;

function TCacuData.MaxMin(Data:variant): MaxMin;
{求出最大数及最小数}
begin
if (Data>FMax) or (FMax=0) then
FMax:=Data;
if (Data<FMin) or (FMin=0) then
FMin:=Data;
MaxMin[0]:=AddZeroToStr(FMax);
MaxMin[1]:=AddZeroToStr(FMin);
end;

function TCacuData.MaxSubMin: String;
{求出最大数与最小数之差}
begin
MaxSubMin:=AddZeroToStr(FMax-FMin);
end;

function TCacuData.AddZeroToStr(Data: Variant): String;
{前端置0}
begin
if (Pos('.',Data)=1) and (Data<1) then
AddZeroToStr:=Trim(Copy('0'+VarToStr(Data),1,4))
else
AddZeroToStr:=Trim(Copy(VarToStr(Data),1,4));
end;

procedure TCacuData.SetMax(Value:Variant);
begin
if FMax<>Value then
begin
FMax:=Value;
end;
end;

procedure TCacuData.SetMin(Value:Variant);
begin
if FMin<>Value then
begin
FMin:=Value;
end;
end;
end.

//=======================================
unit MainUnit;
{主单元}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,SPComm, StdCtrls, Menus,IniFiles,unit3, ExtCtrls, Buttons,
ComCtrls,Math,GloVariant,ADODB,StrUtils, DB,DataToDBThread;
type
TForm1 = class(TForm)
Comm1: TComm;
MainMenu1: TMainMenu;
N1: TMenuItem;
Comm2: TComm;
GroupBox1: TGroupBox;
Label1: TLabel;
line: TComboBox;
Label2: TLabel;
model: TComboBox;
Label3: TLabel;
customer: TComboBox;
Label4: TLabel;
crt: TComboBox;
Label5: TLabel;
sum: TEdit;
GroupBox2: TGroupBox;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
CheckBox6: TCheckBox;
CheckBox7: TCheckBox;
CheckBox8: TCheckBox;
CheckBox9: TCheckBox;
SumToZero: TBitBtn;
BitBtn2: TBitBtn;
ChangeModel: TBitBtn;
Panel1: TPanel;
Panel2: TPanel;
GroupBox4: TGroupBox;
GroupBox5: TGroupBox;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
bu: TLabel;
SubX: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
xMinlab: TLabel;
yMinlab: TLabel;
dyMinlab: TLabel;
SubY: TLabel;
Label23: TLabel;
Label24: TLabel;
xMaxlab: TLabel;
yMaxlab: TLabel;
dyMaxlab: TLabel;
Image1: TImage;
TestTy: TRadioGroup;
N3: TMenuItem;
Label12: TLabel;
N2: TMenuItem;
ADOStoredProc1: TADOStoredProc;
Station: TComboBox;
StatusBar1: TStatusBar;
GroupBox3: TGroupBox;
xlab: TLabel;
ylab: TLabel;
dylab: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
procedure Comm1ReceiveData(Sender: TObject;
Buffer: Pointer;
BufferLength: Word);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure lineExit(Sender: TObject);
procedure modelExit(Sender: TObject);
procedure customerExit(Sender: TObject);
procedure crtExit(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure CheckBox3Click(Sender: TObject);
procedure CheckBox4Click(Sender: TObject);
procedure CheckBox5Click(Sender: TObject);
procedure CheckBox6Click(Sender: TObject);
procedure CheckBox7Click(Sender: TObject);
procedure CheckBox8Click(Sender: TObject);
procedure CheckBox9Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure SumToZeroClick(Sender: TObject);
procedure ChangeModelClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure N2Click(Sender: TObject);
procedure customerChange(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure modelChange(Sender: TObject);
procedure StationChange(Sender: TObject);
function ShiftBsg:Boolean;
procedure StationKeyPress(Sender: TObject;
var Key: Char);
procedure customerKeyPress(Sender: TObject;
var Key: Char);
procedure modelKeyPress(Sender: TObject;
var Key: Char);
procedure crtKeyPress(Sender: TObject;
var Key: Char);
procedure sumKeyPress(Sender: TObject;
var Key: Char);
procedure lineKeyPress(Sender: TObject;
var Key: Char);
procedure crtChange(Sender: TObject);
procedure IniToZero;
private
{ Private declarations }
procedure GetFromInifile;
procedure WriteToInifile;
procedure DisableModel;
function CheckProject:Boolean;
procedure TestFiveDot(const Key:WORD);
procedure TestMove(const Key:WORD);
function PressVKSPACE:Boolean;
procedure SendDataToDB(Const Data:TData;TestTy:Integer);
procedure ExcuteADOSP;
procedure SendToBsg(Const Timing:string;Const Pattern:string);
procedure GetFromIniModel(Const Customer:string);
procedure GetFromIniMaxMin(Const Cust_Model:string);
function CaluData(Const Key:Word):Boolean;
function DataLimitCheck(Const LocProjNum:integer;Data:array of variant):Boolean;
public
{ Public declarations }
procedure GetFromIniTiming(FirstCreateForm:Boolean=false);
procedure WriteToIniTiming;
end;

var
Form1: TForm1;
xCacu:TCacuData;
yCacu:TCacuData;
dyCacu:TCacuData;
xMaxMin,yMaxMin,dyMaxMin:MaxMin;
ProjCk:array [0..9] of Boolean;
ProjNum:integer=1;
GloNum:integer=1;
KeyFlag:String;
WdKey:integer=VK_SPACE;
ProjRec:TDATA;
//测试的数据
MyThread:TDataToDBThread;
Boolbegin
Test:Boolean;
StrProjCheck:string;
//格式是'101101110' 有测试的项目为1否则是0
implementation
uses Glo_FuncProc, TimingSet;
{$R *.dfm}
procedure TForm1.Comm1ReceiveData(Sender: TObject;
Buffer: Pointer;
BufferLength: Word);
{处理串口接收来的数据,并根据测试模式及按键计算数据}
var
PS:pChar;
S:string;
x,y,i:integer;
DY:single;
begin
PS:=Buffer;
S:=String(PS);
if UpperCase(COPY(S,1,2))<>'P1' then
exit;
try
i:=Pos(';',S);
xlab.Caption:=trim(Copy(S,4,i-4));
S:=trim(Copy(S,i+1,Length(S)));
i:=Pos(';',S);
ylab.Caption:=trim(Copy(S,1,i-1));
S:=trim(Copy(S,i+1,Length(S)));
S:=Trim(Copy(S,1,4));
dylab.Caption:=S;
if ((TestTy.ItemIndex=0) and (ProjNum<4) and (KeyFlag='#2')) then
begin
x:=StrToInt(xlab.caption);
y:=StrToInt(ylab.caption);
dy:=StrToFloat(dylab.Caption);
xMaxMin:=xCacu.MaxMin(x);
xMaxlab.Caption:=xMaxMin[0];
xMinlab.Caption:=xMaxMin[1];
Subx.Caption:=xCacu.MaxSubMin;
yMaxMin:=yCacu.MaxMin(y);
yMaxlab.Caption:=yMaxMin[0];
yMinlab.Caption:=yMaxMin[1];
Suby.Caption:=yCacu.MaxSubMin;
dyMaxMin:=dyCacu.MaxMin(dy);
dyMaxlab.Caption:=dyMaxMin[0];
dyMinlab.Caption:=dyMaxMin[1];
bu.Caption:=dyCacu.MinDivMax+'%';
end;
except
exit;
end;
end;

function TForm1.CaluData(Const Key:Word):Boolean;
{根据不同按键将数据存储在不同的存储区并设置下一按键}
var
i:integer;
STemp:string;
begin
ReSult:=true;
case ProjNum of
1,2,3:
begin
case TestTy.ItemIndex of
0:
begin
if (Key=VK_NUMPAD1) then
begin
with ProjRecdo
begin
KeyFlag:='#1';
BuWuRG[ProjNum][0].x :=StrToInt(SubX.caption);
BuWuRG[ProjNum][0].y :=StrToInt(SubY.caption);
STemp:=Copy(bu.caption,0,Length(bu.caption)-1);
BuWuRG[ProjNum][0].dy :=StrToFloat(STemp);
Result:=DataLimitCheck(ProjNum,[BuWuRG[ProjNum][0].x,
BuWuRG[ProjNum][0].y,BuWuRG[ProjNum][0].dy]);
end;
end;
if (Key=VK_NUMPAD2) then
KeyFlag:='#2';
end;
1:
begin
if (Key in [VK_NUMPAD1..VK_NUMPAD5]) then
begin
With ProjRecdo
begin
BuWuRG[ProjNum][Key-VK_NUMPAD0].x :=StrToInt(xlab.caption);
BuWuRG[ProjNum][Key-VK_NUMPAD0].y :=StrToInt(ylab.caption);
BuWuRG[ProjNum][Key-VK_NUMPAD0].dy :=StrToFloat(dylab.caption);
if (Key=VK_NUMPAD5) then
begin
xCacu.IniMaxMinZero;
yCacu.IniMaxMinZero;
dyCacu.IniMaxMinZero;
for i:=1 to 5 do
begin
xMaxMin:=xCacu.MaxMin(ABS(BuWuRG[ProjNum].x-BuWuRG[ProjNum][3].x));
yMaxMin:=yCacu.MaxMin(ABS(BuWuRG[ProjNum].y-BuWuRG[ProjNum][3].y));
dyMaxMin:=dyCacu.MaxMin(BuWuRG[ProjNum].dy);
end;
BuWuRG[ProjNum][0].x :=StrToInt(xMaxMin[0]);
BuWuRG[ProjNum][0].y :=StrToInt(yMaxMin[0]);
BuWuRG[ProjNum][0].dy :=StrToFloat(dyCacu.MinDivMax);
Result:=DataLimitCheck(ProjNum,[BuWuRG[ProjNum][0].x,BuWuRG[ProjNum][0].y,BuWuRG[ProjNum][0].dy]);
Subx.Caption :=xMaxMin[0];
Suby.Caption :=yMaxMin[0];
Str(BuWuRG[ProjNum][0].dy:4:2,STemp);
bu.Caption :=STemp+'%';
for i:=1 to 5 do
begin
xMaxMin:=xCacu.MaxMin(BuWuRG[ProjNum].x);
yMaxMin:=yCacu.MaxMin(BuWuRG[ProjNum].y);
end;
xMaxlab.Caption:=xMaxMin[0];
xMinlab.Caption:=xMaxMin[1];
yMaxlab.Caption:=yMaxMin[0];
yMinlab.Caption:=yMaxMin[1];
dyMaxlab.Caption:=dyMaxMin[0];
dyMinlab.Caption:=dyMaxMin[1];
end;
end;
end;
end;
end;
end;
4,5,6,7:
begin
if (Key=VK_NUMPAD6) then
begin
IniToZero;
with ProjRecdo
begin
dy[ProjNum]:=StrToFloat(dylab.Caption);
Result:=DataLimitCheck(ProjNum,[dy[ProjNum]]);
end;
end;
end;
8,9:
begin
if (Key=VK_NUMPAD6) then
begin
with ProjRec,MaxMinLimitdo
begin
BalanceW[ProjNum,0]:=StrToInt(xlab.Caption);
BalanceW[ProjNum,1]:=StrToInt(ylab.Caption);
Result:=DataLimitCheck(ProjNum,[BalanceW[ProjNum,0],BalanceW[ProjNum,1]]);
end;
end;
end;
end;
end;


procedure TForm1.GetFromInifile;
{从spec.ini文件中获取数据}
var
Sdir:String;
inif:TiniFile;
i:integer;
begin
Sdir:=ExtractFilePath(Application.ExeName)+'spec.ini';
inif:=Tinifile.Create(Sdir);
try
inif.ReadSection('Line',Line.Items);
inif.ReadSection('Crt',Crt.Items);
inif.ReadSection('Station',Station.Items);
inif.ReadSection('Customer',Customer.Items);
Line.Text:=inif.ReadString ('IniPara','line', '');
Crt.Text:=inif.ReadString ('IniPara','CRT', '');
Customer.Text:=inif.ReadString ('IniPara','Customer', 'DELL');
SetTiming.Customer.Caption:=Customer.Text;
Model.Text:=inif.ReadString ('IniPara','Model', '');
SetTiming.Model.Caption:=Model.Text;
Sum.Text:=inif.ReadString ('IniPara','sum', '0');
Station.Text:=inif.ReadString ('IniPara','Station', 'aaa');
Server:=inif.ReadString ('IniPara','Server', 'mfg_server1');
GetFromIniModel(Customer.Text);
for i:=1 to 9do
TCheckBox(FindComponent('CheckBox'+IntToStr(i))).Checked :=inif.ReadBool('ProjCheck','Check'+IntToStr(i),False);
finally
inif.Free;
end;
end;

procedure TForm1.WriteToInifile;
{将数据写入spec.ini文件}
var
inif:TiniFile;
CurDir:String;
i:integer;
begin
CurDir:=ExtractFilePath(Application.ExeName)+'spec.ini';
inif:=Tinifile.Create(CurDir);
try
inif.WriteString ('IniPara','line',Line.Text);
inif.WriteString ('IniPara','CRT',Crt.Text);
inif.WriteString ('IniPara','customer',Customer.Text);
inif.WriteString ('IniPara','model',model.Text);
inif.WriteString ('IniPara','sum',sum.Text);
inif.WriteString ('IniPara','Station',Station.Text);
for i:=1 to 9do
inif.WriteBool('ProjCheck','Check'+IntToStr(i)
,TCheckBox(FindComponent('CheckBox'+IntToStr(i))).Checked);
finally
inif.Free;
end;
end;

procedure TForm1.GetFromIniModel(Const Customer:string);
{从Model.ini文件中获取数据}
var
Sdir:String;
inif:TiniFile;
begin
Sdir:=ExtractFilePath(Application.ExeName)+'Model.ini';
inif:=Tinifile.Create(Sdir);
if (not inif.SectionExists(Customer)) then
begin
ShowMessage('请在MODEL.INI中建立此客户的MODEL');
exit;
end;
try
inif.ReadSection(Customer,Form1.Model.Items);
finally
inif.Free;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
Pcstr:pChar;
begin
Boolbegin
Test:=false;
CommIni(Comm1,'COM1');
CommIni(Comm2,'COM2');
SetTiming:=TSetTiming.Create(Application);
GetFromInifile;

GetFromIniTiming(true);
xCacu:=TCacuData.Create ;
yCacu:=TCacuData.Create ;
dyCacu:=TCacuData.Create ;
TextImg(Image1,30,clWhite,'按空格键初始化');
Pcstr:='F1'+Chr(VK_RETURN)+Chr(10);
Comm1.WriteCommData(Pcstr,Length(Pcstr));
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
Pcstr:pChar;
begin
Pcstr:='F0'+Chr(VK_RETURN)+Chr(10);
Comm1.WriteCommData(Pcstr,Length(Pcstr));
Comm1.StopComm ;
Comm2.StopComm ;
xCacu.Free ;
yCacu.Free ;
dyCacu.Free ;
WriteToInifile;
end;


function TForm1.PressVKSPACE:Boolean;
{按空格键初始化所有参数}
begin
GetFromIniMaxMin(Customer.Text+'_'+Model.Text);
PressVKSPACE:=true;
if (not CheckProject) or (TestTy.ItemIndex =-1) then
begin
ShowMessage('请检查是否选择了测试项目及测试方式!');
PressVKSPACE:=false;
exit;
end;
DisableModel;
ProjNum:=1;
while (not ProjCk[ProjNum]) and (ProjNum<9)do
begin
Inc(ProjNum,1);
end;

if (ProjCk[ProjNum]) then
SendToBsg(TimPat[ProjNum].Timing,TimPat[ProjNum].Pattern);
if ProjNum>=4 then
WdKey:=VK_NUMPAD6
else
begin
case TestTY.ItemIndex of
0: WdKey:=VK_NUMPAD2;
1: WdKey:=VK_NUMPAD1;
end;
end;
end;



function TForm1.CheckProject:Boolean;
{检查是否有测试的项目,并设置StrProjCheck参数}
var
i:integer;
begin
CheckProject:=false;
StrProjCheck:='';
for i:=1 to 9do
begin
ProjCK:=TCheckBox(FindComponent('CheckBox'+IntToStr(i))).Checked=true;
if ProjCK then
begin
CheckProject:=true;
StrProjCheck:=StrProjCheck+'1';
end
else
StrProjCheck:=StrProjCheck+'0';
end;
end;

procedure TForm1.SendDataToDB(const Data: TData;
TestTy: Integer);
{数据存数据库}
var
IntSum,i:integer;
SQLStr:Ansistring;
CustomerType,FieldI:integer;
{CustomerType: 0:DELL TYPE 1:HP TYPE}
STable,SBuWu,SRed,SGreen:string;
IntTemp:Cardinal;
begin
IntSum:=StrToInt(sum.text);
Inc(IntSum,1);
sum.text:=IntToStr(IntSum);
CustomerType:=GetCustomerType(Customer.text);
case CustomerType of
0:
begin
STable:='DellType';
SBuWu:='wx1,wy1,BY1,wx2,wy2,BY2,wx3,wy3,BY3,wx4,wy4,BY4,wx5,wy5,BY5,';
SRed:='RedX1,RedY1,RedX2,RedY2,RedX3,RedY3,RedX4,RedY4,RedX5,RedY5,';
SGreen:='GreenX1,GreenY1,GreenX2,GreenY2,GreenX3,GreenY3,GreenX4,GreenY4,GreenX5,GreenY5,';
FieldI:=5;
end;
1:
begin
STable:='HpType';
SBuWu:='';
SRed:='';
SGreen:='';
FieldI:=0;
end
else
begin
ShowMessage('请确认此客户属于DELL类还是HP类?');
exit;
end;
end;
SQLStr:='Insert Into '+STable;
SQLStr:=SQLStr+'(riqi,Line,Model,Crt,Customer,Station,CurSum,';
SQLStr:=SQLStr+'wx,wy,Bu,'+SBuWu;
SQLStr:=SQLStr+'RedX,RedY,'+SRed;
SQLStr:=SQLStr+'GreenX,GreenY,';
SQLStr:=SQLStr+SGreen;
SQLStr:=SQLStr+'CutoffBY,WhiteBY,WindowBY,' ;
SQLStr:=SQLStr+'RasterBY,WBalance93x,WBalance93y,WBalance65x,WBalance65y)' ;
SQLStr:=SQLStr+' Values(';
for i:=0 to 5do
SQLStr:=SQLStr+'''%s''' + ',';
//至Station
SQLStr:=SQLStr+'''%d''' + ',';
//至CurSum
for i:=0 to FieldI do
SQLStr:=SQLStr+ '''%d''' + ',' + '''%d''' + ','+'''%4.1f''' + ',';
//wx--BY5
for i:=0 to FieldIdo
SQLStr:=SQLStr+ '''%d''' + ',' + '''%d''' + ',';
////RedX-至REDY5
for i:=0 to FieldIdo
SQLStr:=SQLStr+ '''%d''' + ',' + '''%d''' + ',';
////GreenX-至GreenY5
for i:=0 to 3do
SQLStr:=SQLStr+ '''%4.1f''' + ',';
//CutoffBY--Raster
for i:=0 to 1do
SQLStr:=SQLStr+ '''%d''' + ',' +'''%d''' + ',';
//WBalance93x--WBalance65y
SQLStr:=StuffString(SQLStr,Length(SQLStr),1,')');
try
case CustomerType of
0: {DELL}
SQLStr:=Format(SQLStr,['20'+DateTimeToStr(Now),Line.Text,Model.Text,Crt.text,
Customer.text,Station.text,StrToInt(sum.text)
,Data.BuWuRG[1][0].x,Data.BuWuRG[1][0].y,Data.BuWuRG[1][0].dy
,Data.BuWuRG[1][1].x,Data.BuWuRG[1][1].y,Data.BuWuRG[1][1].dy
,Data.BuWuRG[1][2].x,Data.BuWuRG[1][2].y,Data.BuWuRG[1][2].dy
,Data.BuWuRG[1][3].x,Data.BuWuRG[1][3].y,Data.BuWuRG[1][3].dy
,Data.BuWuRG[1][4].x,Data.BuWuRG[1][4].y,Data.BuWuRG[1][4].dy
,Data.BuWuRG[1][5].x,Data.BuWuRG[1][5].y,Data.BuWuRG[1][5].dy //BuWu
,Data.BuWuRG[2][0].x,Data.BuWuRG[2][0].y
,Data.BuWuRG[2][1].x,Data.BuWuRG[2][1].y
,Data.BuWuRG[2][2].x,Data.BuWuRG[2][2].y
,Data.BuWuRG[2][3].x,Data.BuWuRG[2][3].y
,Data.BuWuRG[2][4].x,Data.BuWuRG[2][4].y
,Data.BuWuRG[2][5].x,Data.BuWuRG[2][5].y //RED
,Data.BuWuRG[3][0].x,Data.BuWuRG[3][0].y
,Data.BuWuRG[3][1].x,Data.BuWuRG[3][1].y
,Data.BuWuRG[3][2].x,Data.BuWuRG[3][2].y
,Data.BuWuRG[3][3].x,Data.BuWuRG[3][3].y
,Data.BuWuRG[3][4].x,Data.BuWuRG[3][4].y
,Data.BuWuRG[3][5].x,Data.BuWuRG[3][5].y //GREEN
,Data.dy[4],Data.dy[5],Data.dy[6],Data.dy[7]
,Data.BalanceW[8,0],Data.BalanceW[8,1],Data.BalanceW[9,0],Data.BalanceW[9,1]
]);
1: {HP}
SQLStr:=Format(SQLStr,['20'+DateTimeToStr(Now),Line.Text,Model.Text,Crt.text,
Customer.text,Station.text,StrToInt(sum.text)
,Data.BuWuRG[1][0].x,Data.BuWuRG[1][0].y,Data.BuWuRG[1][0].dy //BuWu
,Data.BuWuRG[2][0].x,Data.BuWuRG[2][0].y //RED
,Data.BuWuRG[3][0].x,Data.BuWuRG[3][0].y //GREEN
,Data.dy[4],Data.dy[5],Data.dy[6],Data.dy[7]
,Data.BalanceW[8,0],Data.BalanceW[8,1],Data.BalanceW[9,0],Data.BalanceW[9,1]
])
else
exit;
end;
MyThread:=TDataToDBThread.Create(false,SQLStr);
MyThread.WaitFor ;
MyThread.Free;
if StrToInt(sum.Text)>=ComputeNum[CustomerType] then
begin
StatusBar1.Panels[3].Text :='开始计算CP/CPK的值!';
update;
IntTemp:=GetTickCount;
ExcuteADOSP;
StatusBar1.Panels[3].Text := '耗用时间:'+FloatToStr((GetTickCount-IntTemp)/1000)+'秒';
sum.Text:='0';
end;
except
ShowMessage('ERROR');
end;
end;

procedure TForm1.ExcuteADOSP;
var
CustomerType:integer;
begin
try
try
CustomerType:=GetCustomerType(Customer.Text);
with ADOStoredProc1do
begin
ConnectionString :=SetConnectionString;
Parameters.ParamValues['@Line;@Model;@Crt;@Station;@Customer;@CustomerType;@ProjCheck']
:=VarArrayOf([TRIM(Line.Text),TRIM(Model.Text),TRIM(Crt.Text),TRIM(Station.Text),TRIM(Customer.Text),CustomerType,StrProjCheck]);
ExecProc ;
end;
except
ShowMessage('网络不通,请检查!');
end
finally
ADOStoredProc1.Close;
end;
end;

procedure TForm1.GetFromIniMaxMin(const Cust_Model: string);
{从文件MaxMin.ini读数据要设置的最大最小值}
const
BuWuCap:array [1..1] of array [1..6] of string=(('WuX_Min','WuX_Max','WuY_Min','WuY_Max','Bu_Min','Bu_Max'));
RGCap:array [2..3] of array [1..4] of string=(('GreenX_Min','GreenX_Max','GreenY_Min','GreenY_Max'),('RedX_Min',
'RedX_Max','RedY_Min','RedY_Max'));
DyCap:array [4..7] of array [1..2] of string=(('CutRasterY_Min','CutRasterY_Max'),('WhiteY_Min',
'WhiteY_Max'),('WindowY_Min','WindowY_Max'),('RasterY_Min','RasterY_Max'));
WBala:array [8..9] of array [1..4] of string=(('WBala93X_Min','WBala93X_Max','WBala93Y_Min','WBala93Y_Max'),
('WBala65X_Min','WBala65X_Max','WBala65Y_Min','WBala65Y_Max'));
var
Sdir:String;
inif:TiniFile;
begin
Sdir:=ExtractFilePath(Application.ExeName)+'MaxMin.ini';
inif:=Tinifile.Create(Sdir);
try
try
with MaxMinLimit,inifdo
begin
BuWu[1].x.Min :=ReadInteger(Cust_Model,BuWuCap[1][1],0);
BuWu[1].x.Max:=ReadInteger(Cust_Model,BuWuCap[1][2],600);
BuWU[1].y.Min:=ReadInteger(Cust_Model,BuWuCap[1][3],0);
BuWU[1].y.Max:=ReadInteger(Cust_Model,BuWuCap[1][4],600);
BuWU[1].Dy.Min:=ReadFloat(Cust_Model,BuWuCap[1][5],0);
BuWU[1].Dy.Max:=ReadFloat(Cust_Model,BuWuCap[1][6],600);
RG[2].x.Min:=ReadInteger(Cust_Model,RGCap[2][1],0);
RG[2].x.Max:=ReadInteger(Cust_Model,RGCap[2][2],600);
RG[2].y.Min:=ReadInteger(Cust_Model,RGCap[2][3],0);
RG[2].y.Max:=ReadInteger(Cust_Model,RGCap[2][4],600);
RG[3].x.Min:=ReadInteger(Cust_Model,RGCap[3][1],0);
RG[3].x.Max:=ReadInteger(Cust_Model,RGCap[3][2],600);
RG[3].y.Min:=ReadInteger(Cust_Model,RGCap[3][3],0);
RG[3].y.Max:=ReadInteger(Cust_Model,RGCap[3][4],600);
DY[4].Min :=ReadFloat(Cust_Model,DyCap[4][1],0);
DY[4].Max :=ReadFloat(Cust_Model,DyCap[4][2],600);
DY[5].Min :=ReadFloat(Cust_Model,DyCap[5][1],0);
DY[5].Max :=ReadFloat(Cust_Model,DyCap[5][2],600);
DY[6].Min :=ReadFloat(Cust_Model,DyCap[6][1],0);
DY[6].Max :=ReadFloat(Cust_Model,DyCap[6][2],600);
DY[7].Min :=ReadFloat(Cust_Model,DyCap[7][1],0);
DY[7].Max :=ReadFloat(Cust_Model,DyCap[7][2],600);
WBalance[8,0].Min:=ReadInteger(Cust_Model,WBala[8][1],0);
WBalance[8,0].Max:=ReadInteger(Cust_Model,WBala[8][2],600);
WBalance[8,1].Min:=ReadInteger(Cust_Model,WBala[8][3],0);
WBalance[8,1].Max:=ReadInteger(Cust_Model,WBala[8][4],600);
WBalance[9,0].Min:=ReadInteger(Cust_Model,WBala[9][1],0);
WBalance[9,0].Max:=ReadInteger(Cust_Model,WBala[9][2],600);
WBalance[9,1].Min:=ReadInteger(Cust_Model,WBala[9][3],0);
WBalance[9,1].Max:=ReadInteger(Cust_Model,WBala[9][4],600);
end;
except
ShowMessage('MaxMin.ini文件中的数据格式出错');
end;
finally
inif.Free ;
end;
end;

function TForm1.DataLimitCheck(const LocProjNum: integer;
Data: array of Variant):Boolean;
{检查数据是否达标}
begin
Result:=true;
with MaxMinLimitdo
begin
case LocProjNum of
1:
begin
if (Data[low(Data)] >= BuWu[ProjNum].x.Min )
and (Data[low(Data)]<= BuWu[ProjNum].x.Max)
and (Data[low(Data)+1]>= BuWu[ProjNum].y.Min)
and (Data[low(Data)+1]<= BuWu[ProjNum].y.Max)
and (Data[low(Data)+2]>= BuWu[ProjNum].dy.Min)
and (Data[low(Data)+2]<= BuWu[ProjNum].dy.Max) then
begin
exit;
end;
end;
2,3:
begin
if (Data[low(Data)]>= RG[ProjNum].x.Min )
and (Data[low(Data)]<= RG[ProjNum].x.Max)
and (Data[low(Data)+1]>= RG[ProjNum].y.Min)
and (Data[low(Data)+1]<= RG[ProjNum].y.Max) then
begin
exit;
end;
end;
4,5,6,7:
begin
if (Data[low(Data)]>= dy[ProjNum].Min )
and (Data[low(Data)]<= dy[ProjNum].Max ) then
exit;
end;
8,9:
begin
if (Data[low(Data)]>= WBalance[ProjNum,0].Min )
and (Data[low(Data)]<= WBalance[ProjNum,0].Max)
and (Data[low(Data)+1]>= WBalance[ProjNum,1].Min)
and (Data[low(Data)+1]<= WBalance[ProjNum,1].Max) then
begin
exit;
end;
end
end;
end;
Result:=false;
ShowMessage('数据未达标!请重新测试!');
end;


procedure TForm1.SendToBsg(Const Timing:string;Const Pattern:string);
{发送数据到BSG}
var
Pcstr:string;
begin
Pcstr:='RUN timing '+ Timing+' pattern '+Pattern+';';
Comm2.WriteCommData(PChar(Pcstr),Length(Pcstr));
end;

function TForm1.ShiftBsg:Boolean;
{切换BSG的模式}
begin
Result:=False;
while (not ProjCk[ProjNum]) and (ProjNum<9)do
begin
Inc(ProjNum,1);
Result:=true;
end;
if (ProjCk[ProjNum]) then
SendToBsg(TimPat[ProjNum].Timing,TimPat[ProjNum].Pattern);
end;

procedure TForm1.IniToZero;
{将参数初始化为0}
begin
xCacu.IniMaxMinZero;
yCacu.IniMaxMinZero;
dyCacu.IniMaxMinZero;
Subx.Caption:='0';
Suby.Caption:='0';
bu.Caption:='100%';
xMaxLab.Caption:='0';
yMaxLab.Caption:='0';
dyMaxLab.Caption:='0';
xMinLab.Caption:='0';
yMinLab.Caption:='0';
dyMinLab.Caption:='0';
end;


procedure TForm1.StationKeyPress(Sender: TObject;
var Key: Char);
begin
if Key=Chr(VK_SPACE) then
Key:=Chr(VK_BACK);
end;

//----------------
总结:
1.用TFORM 及ADOQUERY1。。。这样不好。
2.缺少注释。
3.好多bug.....
哎.........


 
希望大家能给评论一下。。。
是不是很差呀。。
 
没有兴趣看这么长的没有注释的程序。至少,不应该用Form1做单元的名字。
 
不知道你说的好是什么标准呀。。。。
就像楼上说的,没有注释就不是好的编码习惯。。。。
 
没时间看,收藏先慢慢再看。
 
的确很烂,编程习惯不好是一方面!还错误百出!
粗略看了前面一段,多线程的代码,AdoQuery1动态产生然后Free,
下次再用时Assigned(AdoQuery1)是没有用的,Free时请用FreeAndNil(AdoQuery1).
还有怎么可以在线程里ShowMessage呢?

 
嘿嘿,我写上几千行代码也不写注释,他上面的函数还有说明是做什么的,如果看我的,
一个也没有。[:D]
风格一般般,不是太好,但也不太差,还有ShowMessage是垃圾,没听过吗?
像你那种ShowMessage,应该使用 raise EMyException.Create('error')
 
谢谢..
我当时也想到不能用SHOWMESSAGE,但是不知该用什么?
raise EMyException.Create('error') 这下知道了,得抛出一个异常。。。
 
用MessageBox
 
线程里如果是致命错误就引发异常, 否则就写一个Log过程记下一些事, 不好用模态对话框
 
Too Long Codes!
 
用MessageBox应该是跟SHOWMESSAGE一样不好吧~~
 
嗨,太长,没什么建议,学习一下吧~
顺便问一下,为什么需要将:ADOQUERY1.Free,
换为FreeAndNil(ADOQUERY1);
(回答详细者,给50分!!!)
 
ADOQUERY1.Free
虽然有释放内存但并不会使ADOQUERY1=nil
Assigned()而这个是要判断是否为NIL
Assigned
tests for a nil (unassigned) pointer or procedural variable.
 
还不错,看得出你用Delphi有一段时间了,代码风格也不错。
 
resourcestring
SOKCANCEL = 'Confirm';
SReceiveFile = 'Receive the file: %s from %s?(Timeout: %d seconds)';
const
MAX_TITLE = 50;

type
PData = ^TData;
TData = record
hwnd: THandle;
Title: array [0..MAX_TITLE - 1] of Char;
end;

function EnumFunc(hwnd: THandle;
lpParam: Integer): Boolean;
stdcall;
var
Buffer: array [0..MAX_TITLE - 1] of Char;
begin
Result := True;
FillChar(Buffer, SizeOf(Buffer), 0);
if GetWindowText(hwnd, Buffer, SizeOf(Buffer)) > 0 then
if PData(lpParam)^.Title = Buffer then
begin
PData(lpParam)^.hwnd := hwnd;
Result := False;
end;
end;

procedure TimerFunc(hwnd: THandle;
uMsg, idEvent: UINT;
dwTime: Cardinal);
stdcall;
function GetTitleHandle(Title: string): THandle;
var
Data: TData;
begin
FillChar(Data, SizeOf(Data), 0);
Move(Title[1], Data.Title, Length(Title));
EnumWindows(@EnumFunc, Integer(@Data));
Result := Data.hwnd;
end;

var
Child: THandle;
begin
Child := GetTitleHandle(SOKCANCEL);
if Child <> 0 then
PostMessage(Child, WM_CLOSE, 0, 0);
end;

function MyMessageBox(Handle: THandle;
Text: string;
Timeout: Integer): Integer;
begin
SetTimer(Handle, 2, Timeout, @TimerFunc);
Result := MessageBox(Handle, PChar(Text), PChar(SOKCANCEL),
MB_OKCANCEL or MB_ICONQUESTION);
{ MB_OKCANCELdo
not localize !! }
KillTimer(Handle, 2);
end;
 
[blue]哇,MM啊。一下子贴这么多。搞得我的MyIE都任了半天。[:D][/blue]
 
to leisure,首先感谢回答,我知道FREE后并没有nil,但我有一点不明白!
呵呵,是我记错了,我记得有些控件自身有FreeAndNIL方法,原来没有,哈哈~
freeandnil API,是不是等效于先FREE,然后等NIL?(我记得是,哈哈~)
回答后,即给分!
 
你得学会看Delphi的源代码阿,freeandnil不是api,只是Delphi提供的库函数而已。
procedure FreeAndNil(var Obj);
var
Temp: TObject;
begin
Temp := TObject(Obj);
Pointer(Obj) := nil;
Temp.Free;
end;

 
真长见识。
 

Similar threads

I
回复
0
查看
617
import
I
I
回复
0
查看
632
import
I
I
回复
0
查看
487
import
I
顶部