📄 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;//用来获得当前记录的值以区别是否把焦点放到别的记录上
iiii: boolean; //判断是否是第一次单击网格表
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;//取字符串长度控制循环次数
aa_ii,a_ii:integer;//从1开始取和循环
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开始取和循环
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 //为偶数
begin
if ((str[a_ii]<>'+') and (str[a_ii]<>'-')) and ((str[a_ii]<>'*') and (str[a_ii]<>'/')) then //错的
begin //偶数不为公式符号的情况
a_ii:=100;
end;
end
else //奇数的情况
begin
//if not (mychar in myset) then //为奇数
//ii:=20;
end;
a_ii:=a_ii+1;
end; //上面while的
end
else
a_ii:=101;//上面第一个if的
end;
if a_ii=101 then //判断不为全数字的错的情况
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 //是数字的情况
a_iiii:=a_iiii+1
else//真的出错
begin
dbgrid1.DataSource.DataSet.First;
dbgrid1.datasource.dataset.MoveBy(ii1-1);
showmessage(dbgrid1.Columns[0].field.asstring+'公式出错,请重新设定,谢谢!');
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('对不起,押金项目不能修改,请用别的项修改');
Dbgrid1.DataSource.DataSet.first;
Dbgrid1.DataSource.DataSet.Moveby(2);
end
else
begin
ii:=Tstringgrid(dbgrid1).row; // 取当前行数
if iiii=true then //第一次单击的情况
begin
datamodule1.ggjs.edit;
iiii:=false;
end
else //不是第一次单击的情况
begin
if datamodule1.ggjs.Modified then //判断表是否在修改状态中
datamodule1.ggjs.Post;
datamodule1.ggjs.edit;
dbgrid1.datasource.DataSet.First;
dbgrid1.DataSource.DataSet.MoveBy(ii1-1);
a_str:=dbgrid1.Columns[2].field.asstring;//取更改当前记录前的值用以头判断公式是否正确
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;//押金项不能修改的情况
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;//取字符串长度控制循环次数
aa_ii,a_iiii,a_ii:integer;//从1开始取和循环
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开始取和循环
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 //为偶数
begin
if ((hjs[a_ii]<>'+') and (hjs[a_ii]<>'-')) and ((hjs[a_ii]<>'*') and (hjs[a_ii]<>'/')) then //错的
begin //偶数不为公式符号的情况
a_ii:=100;
end;
end
else //奇数的情况
begin
//if not (mychar in myset) then //为奇数
//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 //是数字的情况
a_iiii:=a_iiii+1
else//真的出错
begin
datamodule1.ggjss.Last;
a_iiii:=1055;
end;
end;
end;
end;//上面判断是空字符串的情况
datamodule1.ggjss.Next;
end;//循环各条记录
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+'公式出错,请重新设定,谢谢!');
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('本月还未输入公式要输入公式吗?','程序执行确认',mb_yesno+mb_defbutton2+mb_iconstop+mb_applmodal)=idyes then
begin
if application.messagebox('要重新输入公式吗?','程序执行确认',mb_yesno+mb_defbutton2+mb_iconstop+mb_applmodal)<>idyes then
begin// 不重新输入公式
//找上月数据
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 //如果没有上月数据
begin //根据最新看过的数据进行
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 //开始复制
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 //有上月数据
begin
while i_record>0 do
begin
datamodule1.ggjs.close;
datamodule1.ggjs.open;
with datamodule1.ggjs do //开始复制上月数据
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -