?? ggjs.pas
字號:
unit ggjs;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, Db, Grids, DBGrids, AppEvnts, Menus;
type
Tggjsb = class(TForm)
Panel1: TPanel;
Label1: TLabel;
UpDown1: TUpDown;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
UpDown2: TUpDown;
Button1: TButton;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button2Click(Sender: TObject);
procedure DBGrid1CellClick(Column: TColumn);
procedure DBGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure UpDown1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure UpDown2MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
ii1,ii:integer;//用來獲得當(dāng)前記錄的值以區(qū)別是否把焦點(diǎn)放到別的記錄上
iiii: boolean; //判斷是否是第一次單擊網(wǎng)格表
aa_str,a_str:string//取單元格里面的值
end;
var
ggjsb: Tggjsb;
implementation
uses datamodule, gzgn;
{$R *.DFM}
procedure Tggjsb.Button2Click(Sender: TObject);
var
anumber:set of '0'..'9';
myset:set of 'a'..'t';
mychar:char;
bb_str,str:string; //接受輸入的公式
a_iiii,a_i:integer;//取字符串長度控制循環(huán)次數(shù)
aa_ii,a_ii:integer;//從1開始取和循環(huán)
begin
str:=trim(a_str);
bb_str:=trim(aa_str);
anumber:=['0'..'9'];
aa_ii:=length(bb_str);
a_iiii:=1;
if str<>'' then
begin
myset:=['a'..'t'];
a_i:=length(str);
if (not (str[a_i] in myset)) and (not (bb_str[aa_ii] in anumber)) then
begin
showmessage('最后一個不能為計算符號');
a_ii:=101;
end
else
begin
a_ii:=1; //從1開始取和循環(huán)
mychar:=str[a_ii];
if mychar in myset then //開頭有寫對的情況
begin
while a_ii<=a_i do
begin
mychar:=str[a_ii];
if not odd(a_ii) then //為偶數(shù)
begin
if ((str[a_ii]<>'+') and (str[a_ii]<>'-')) and ((str[a_ii]<>'*') and (str[a_ii]<>'/')) then //錯的
begin //偶數(shù)不為公式符號的情況
a_ii:=100;
end;
end
else //奇數(shù)的情況
begin
//if not (mychar in myset) then //為奇數(shù)
//ii:=20;
end;
a_ii:=a_ii+1;
end; //上面while的
end
else
a_ii:=101;//上面第一個if的
end;
if a_ii=101 then //判斷不為全數(shù)字的錯的情況
begin
bb_str:=trim(aa_str);
anumber:=['0'..'9'];
aa_ii:=length(bb_str);
a_iiii:=1;
while a_iiii<=aa_ii do
begin
if bb_str[a_iiii] in anumber then //是數(shù)字的情況
a_iiii:=a_iiii+1
else//真的出錯
begin
dbgrid1.DataSource.DataSet.First;
dbgrid1.datasource.dataset.MoveBy(ii1-1);
showmessage(dbgrid1.Columns[0].field.asstring+'公式出錯,請重新設(shè)定,謝謝!');
datamodule1.ggjs.edit;
a_iiii:=1055;
end;
end;
end;
end;//上面判斷是空字符串的情況
//end;//判斷上面最后一個不能為空的情況 ;
end;
procedure Tggjsb.DBGrid1CellClick(Column: TColumn);
var
str:string;
begin
if datamodule1.ggjss.fieldbyname('a_gzcm').asstring='押金' then
begin
showmessage('對不起,押金項(xiàng)目不能修改,請用別的項(xiàng)修改');
Dbgrid1.DataSource.DataSet.first;
Dbgrid1.DataSource.DataSet.Moveby(2);
end
else
begin
ii:=Tstringgrid(dbgrid1).row; // 取當(dāng)前行數(shù)
if iiii=true then //第一次單擊的情況
begin
datamodule1.ggjs.edit;
iiii:=false;
end
else //不是第一次單擊的情況
begin
if datamodule1.ggjs.Modified then //判斷表是否在修改狀態(tài)中
datamodule1.ggjs.Post;
datamodule1.ggjs.edit;
dbgrid1.datasource.DataSet.First;
dbgrid1.DataSource.DataSet.MoveBy(ii1-1);
a_str:=dbgrid1.Columns[2].field.asstring;//取更改當(dāng)前記錄前的值用以頭判斷公式是否正確
aa_str:=a_str;
dbgrid1.datasource.dataset.first;
dbgrid1.datasource.dataset.MoveBy(ii-1);
if ii<>ii1 then //判斷記錄指針是否有移動(這是有移動的情況)
begin
datamodule1.ggjs.edit;
button2.Click;
end;
end;
ii1:=ii;
datamodule1.ggjs.edit;
end;//押金項(xiàng)不能修改的情況
end;
//end;
procedure Tggjsb.DBGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if inttostr(key)='13' then
begin
if datamodule1.ggjs.modified then
datamodule1.ggjs.Post;
end;
end;
procedure Tggjsb.FormShow(Sender: TObject);
var
str:string;
begin
iiii:=true;
button4.visible:=false;
button3.visible:=false;
button2.visible:=false;
str:='select a_date from ggjs order by a_date desc';
with datamodule1.ggjss do
begin
close;
sql.clear;
sql.add(str);
prepare;
open;
end;
edit1.text:=formatdatetime('yyyy',datamodule1.ggjss.fieldbyname('a_date').asdatetime);
edit2.text:=formatdatetime('mm',datamodule1.ggjss.fieldbyname('a_date').asdatetime);
str:='select *from ggjs where extract(year from a_date)='+edit1.text;
str:=str+' and extract(month from a_date)='+edit2.text;
with datamodule1.ggjss do
begin
close;
sql.clear;
sql.add(str);
prepare;
open;
end;
//button2.visible:=false;
//button4.visible:=false;
end;
procedure Tggjsb.Button1Click(Sender: TObject);
var
myset:set of 'a'..'t';
anumber:set of '0'..'9';
mychar:char;
str,aa_hjs,aa_hjs1,a_hjs,hjs:string; //接受輸入的公式
a_i:integer;//取字符串長度控制循環(huán)次數(shù)
aa_ii,a_iiii,a_ii:integer;//從1開始取和循環(huán)
a_row:integer;// 判斷出錯在第幾行
begin
a_row:=0;
str:='select *from ggjs where extract(year from a_date)='+edit1.text;
str:=str+' and extract(month from a_date)='+edit2.text;
with datamodule1.ggjss do
begin
close;
sql.clear;
sql.add(str);
prepare;
open;
end;
while not datamodule1.ggjss.Eof do
begin
a_row:=a_row+1;
aa_hjs:=datamodule1.ggjss.fieldbyname('a_jsgs').asstring;
anumber:=['0'..'9'];
aa_hjs1:=trim(aa_hjs);
aa_ii:=length(aa_hjs1);
a_iiii:=1;
a_hjs:=datamodule1.ggjss.fieldbyname('a_jsgs').asstring;
if a_hjs<>'' then // 判斷公式是否空字符串
begin
myset:=['a'..'t'];
hjs:=trim(a_hjs);
a_i:=length(hjs);
if (not (hjs[a_i] in myset)) and (not (aa_hjs1[aa_ii] in anumber)) then
begin
showmessage('最后一個不能為計算符號');
a_ii:=101;
end
else
begin
a_ii:=1; //從1開始取和循環(huán)
mychar:=hjs[a_ii];
if mychar in myset then //開頭有寫對的情況
begin
while a_ii<=a_i do
begin
mychar:=hjs[a_ii];
if not odd(a_ii) then //為偶數(shù)
begin
if ((hjs[a_ii]<>'+') and (hjs[a_ii]<>'-')) and ((hjs[a_ii]<>'*') and (hjs[a_ii]<>'/')) then //錯的
begin //偶數(shù)不為公式符號的情況
a_ii:=100;
end;
end
else //奇數(shù)的情況
begin
//if not (mychar in myset) then //為奇數(shù)
//ii:=20;
end;
a_ii:=a_ii+1;
end; //上面while的
end
else
a_ii:=101;//上面第一個if的
end;//判斷上面最后一個不能為空的情況
if a_ii=101 then //錯的情況
begin
aa_hjs1:=trim(aa_hjs);
anumber:=['0'..'9'];
aa_ii:=length(aa_hjs1);
a_iiii:=1;
while a_iiii<=aa_ii do
begin
if aa_hjs1[a_iiii] in anumber then //是數(shù)字的情況
a_iiii:=a_iiii+1
else//真的出錯
begin
datamodule1.ggjss.Last;
a_iiii:=1055;
end;
end;
end;
end;//上面判斷是空字符串的情況
datamodule1.ggjss.Next;
end;//循環(huán)各條記錄
if (a_row<>20) or (aa_ii=a_iiii+1) then
begin
dbgrid1.SetFocus;
DBGrid1.DataSource.dataset.first;
DataSource1.dataset.moveby(a_row-1);
showmessage(dbgrid1.Columns[0].field.asstring+'公式出錯,請重新設(shè)定,謝謝!');
end;
end;
procedure Tggjsb.UpDown1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
str:string;
a_month:string;
i_record:integer;
begin
i_record:=20;
if strtoint(edit2.text)=0 then
a_month:='12'
else
a_month:=inttostr(strtoint(edit2.text)-1);
button3.click;
str:='select *from ggjs where Extract(year from a_date)=';
str:=str+edit1.text+' and extract(month from a_date)=';
str:=str+edit2.text;
with datamodule1.ggjss do
begin
close;
sql.clear;
sql.add(str);
prepare;
open;
end;
if datamodule1.ggjss.eof then //還沒有錄入公式
begin
if application.messagebox('本月還未輸入公式要輸入公式嗎?','程序執(zhí)行確認(rèn)',mb_yesno+mb_defbutton2+mb_iconstop+mb_applmodal)=idyes then
begin
if application.messagebox('要重新輸入公式嗎?','程序執(zhí)行確認(rèn)',mb_yesno+mb_defbutton2+mb_iconstop+mb_applmodal)<>idyes then
begin// 不重新輸入公式
//找上月數(shù)據(jù)
str:='select *from ggjs where Extract(year from a_date)=';
str:=str+edit1.text+' and extract(month from a_date)=';
str:=str+a_month;
with datamodule1.ggjss do
begin
close;
sql.clear;
sql.add(str);
prepare;
open;
end;
if datamodule1.ggjss.eof then //如果沒有上月數(shù)據(jù)
begin //根據(jù)最新看過的數(shù)據(jù)進(jìn)行
button3.click;
if datamodule1.ggjsn.state in [dsinsert,dsedit] then
datamodule1.ggjsn.post;
datamodule1.ggjsn.close;
datamodule1.ggjsn.open;
while not datamodule1.ggjsn.eof do
begin
with datamodule1.ggjss do //開始復(fù)制
begin
append;
fieldbyname('a_gzcm').asstring:=datamodule1.ggjsn.fieldbyname('a_gzcm').asstring;
fieldbyname('a_smdm').asstring:=datamodule1.ggjsn.fieldbyname('a_smdm').asstring;
fieldbyname('a_date').asdatetime:=strtodate(edit1.text+'-'+edit2.text+'-'+'15');
fieldbyname('a_jsgs').asstring:=datamodule1.ggjsn.fieldbyname('a_jsgs').asstring;
post;
end;
datamodule1.ggjsn.next;
end;
end
else //有上月數(shù)據(jù)
begin
while i_record>0 do
begin
datamodule1.ggjs.close;
datamodule1.ggjs.open;
with datamodule1.ggjs do //開始復(fù)制上月數(shù)據(jù)
begin
append;
fieldbyname('a_gzcm').asstring:=datamodule1.ggjss.fieldbyname('a_gzcm').asstring;
fieldbyname('a_smdm').asstring:=datamodule1.ggjss.fieldbyname('a_smdm').asstring;
fieldbyname('a_date').asdatetime:=strtodate(edit1.text+'-'+edit2.text+'-'+'15');
fieldbyname('a_jsgs').asstring:=datamodule1.ggjss.fieldbyname('a_jsgs').asstring;
post;
end;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -