📄 yggzjgtz.pas
字号:
unit yggzjgtz;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, ExtCtrls, StdCtrls, Db, DBTables;
type
Tfrm_yggzjgtz = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label2: TLabel;
Edit2: TEdit;
Label1: TLabel;
Edit1: TEdit;
Panel3: TPanel;
Label3: TLabel;
Label4: TLabel;
Shape1: TShape;
Shape2: TShape;
Bevel1: TBevel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Query1: TQuery;
StringGrid1: TStringGrid;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button4Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Button2Click(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure Edit1Exit(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure StringGrid1Exit(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
private
procedure FormatStr;
{ Private declarations }
public
{ Public declarations }
end;
var
frm_yggzjgtz: Tfrm_yggzjgtz;
implementation
uses cp, dl;
{$R *.DFM}
procedure Tfrm_yggzjgtz.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
action:=cafree;
end;
procedure Tfrm_yggzjgtz.Button4Click(Sender: TObject);
begin
close;
end;
procedure Tfrm_yggzjgtz.Edit1KeyPress(Sender: TObject; var Key: Char);
var sql:string;
begin
if (edit1.text<>'') and (key=#13) then
begin
Sql := 'select xm from ygzlb where ygh='''+Trim(Edit1.Text)+'''';
query1.close;
query1.sql.clear;
query1.SQL.add(sql);
query1.open;
if query1.isempty then
begin
application.MessageBox('无此工号!请核实后重新输入','系统提示',mb_IconInformation+mb_OK);
edit1.SetFocus;
exit;
end;
Edit2.Text := Query1.FieldByName('xm').AsString;
button2.click;
end;
end;
procedure Tfrm_yggzjgtz.Button2Click(Sender: TObject);
var sql,nowdate,curmonth:string;
i:integer;
begin
NowDate := FormatDatetime('YYYYMMDDHHMMSS',Date);
CurMonth := Copy(NowDate,1,6);
sql:='select id,lx,mc,rela from jbcsb where lx=1 order by id';
query1.sql.Clear;
query1.sql.add(sql);
query1.open;
i:=1;
if not Query1.IsEmpty then
StringGrid1.RowCount := Query1.RecordCount + 1;
Query1.First;
while not Query1.Eof do
begin
StringGrid1.Cols[2].Strings[I] := Query1.FieldByName('mc').AsString;
StringGrid1.Cols[0].Strings[I] := Query1.FieldByName('id').AsString;
StringGrid1.Cols[1].Strings[I] := Query1.FieldByName('rela').AsString;
I := I + 1;
Query1.Next;
end;
Sql := 'select xszmid,sm from ygxjjgb where ygh='''
+Trim(Edit1.Text)+''' and yf='''+CurMonth+''' order by xszmid';
Query1.Close;
Query1.Sql.Clear;
Query1.Sql.Add(Sql);
Query1.Open;
Query1.First;
while not Query1.Eof do
begin
for I := 0 to StringGrid1.RowCount - 1 do
begin
if StringGrid1.Cols[0].Strings[i] = Query1.FieldByName('xszmid').AsString then
StringGrid1.Cols[3].Strings[i] := FormatFloat('#####0.00',
Query1.FieldByName('sm').AsFloat);
end;
Query1.Next;
end;
for I := 0 to StringGrid1.RowCount - 1 do
begin
if StringGrid1.Cols[3].Strings[I] = '' then
StringGrid1.Cols[3].Strings[I] := '0.00';
end;
end;
procedure Tfrm_yggzjgtz.StringGrid1SetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
var I,YingFaRow,ShiFaRow: Integer;
ShiFa,YingFa: Real;
begin
for I := 1 to StringGrid1.RowCount - 1 do
begin
if (StringGrid1.Cols[2].Strings[I] = '应发工资') then
YingFaRow := I;
if StringGrid1.Cols[2].Strings[I] = '实发工资' then
ShiFaRow := I;
end;
ShiFa := 0.00;
YingFa := 0.00;
for I := 1 to StringGrid1.RowCount - 1 do
begin
if (StringGrid1.Cols[1].Strings[I] = '1') and (StringGrid1.Cols[3].Strings[I]<>'') then
begin
YingFa := YingFa+StrToFloat(StringGrid1.Cols[3].Strings[I]);
StringGrid1.Cols[3].Strings[YingFaRow] := FormatFloat('#####0.00',YingFa);
ShiFa := YingFa;
end;
end;
for I := 1 to StringGrid1.RowCount - 1 do
begin
if (StringGrid1.Cols[1].Strings[I] = '-1') and (StringGrid1.Cols[3].Strings[I]<>'') then
ShiFa := ShiFa-StrToFloat(StringGrid1.Cols[3].Strings[I]);
end;
StringGrid1.Cols[3].Strings[ShiFaRow] := FormatFloat('#####0.00',ShiFa);
end;
{ ARow: Integer; const Value: String);
var I,YingFaRow,ShiFaRow: Integer;
ShiFa,YingFa: Real;
begin
for I := 1 to StringGrid1.RowCount - 1 do
begin
if (StringGrid1.Cols[2].Strings[I] = '应发工资') then
YingFaRow := I;
if StringGrid1.Cols[2].Strings[I] = '实发工资' then
ShiFaRow := I;
end;
ShiFa := 0.00;
YingFa := 0.00;
for I := 1 to StringGrid1.RowCount - 1 do
begin
if (StringGrid1.Cols[1].Strings[I] = '1') and (StringGrid1.Cols[3].Strings[I]<>'') then
begin
YingFa := YingFa+StrToFloat(StringGrid1.Cols[3].Strings[I]);
StringGrid1.Cols[3].Strings[YingFaRow] := FormatFloat('#####0.00',YingFa);
ShiFa := YingFa;
end;
end;
for I := 1 to StringGrid1.RowCount - 1 do
begin
if (StringGrid1.Cols[1].Strings[I] = '-1') and (StringGrid1.Cols[3].Strings[I]<>'') then
ShiFa := ShiFa-StrToFloat(StringGrid1.Cols[3].Strings[I]);
end;
StringGrid1.Cols[3].Strings[ShiFaRow] := FormatFloat('#####0.00',ShiFa);
exit;
end; }
procedure Tfrm_yggzjgtz.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
if StringGrid1.Cols[1].Strings[ARow] = '0' then
CanSelect := False;
FormatStr;
end;
procedure Tfrm_yggzjgtz.Edit1Exit(Sender: TObject);
begin
if Trim(Edit1.Text) = '' then
Edit1.Text := '';
end;
procedure Tfrm_yggzjgtz.Button1Click(Sender: TObject);
begin
StringGrid1.Cols[0].Clear;
StringGrid1.Cols[1].Clear;
StringGrid1.Cols[2].Clear;
StringGrid1.Cols[3].Clear;
StringGrid1.RowCount := 2;
StringGrid1.Rows[0].Strings[2] := '工资帐目';
StringGrid1.Rows[0].Strings[3] := '工资金额';
StringGrid1.ColWidths[0] := 0;
StringGrid1.ColWidths[1] := 0;
Edit1.Text := ' ';
Edit2.Text := '';
Edit1.SetFocus;
end;
procedure Tfrm_yggzjgtz.FormShow(Sender: TObject);
begin
button1.click;
end;
procedure Tfrm_yggzjgtz.FormatStr;
var i:integer;
begin
for i:= 1 to stringgrid1.rowcount -1 do
begin
if stringgrid1.cols[3].strings[i]='' then
stringgrid1.cols[3].strings[i]:='0.00';
stringgrid1.cols[3].strings[i]:=FormatFloat('#####0.00',strtofloat(stringgrid1.Cols[3].strings[i]));
end;
end;
procedure Tfrm_yggzjgtz.StringGrid1Exit(Sender: TObject);
begin
formatstr;
end;
procedure Tfrm_yggzjgtz.Button3Click(Sender: TObject);
var curdate,sql:string;
i:integer;
begin
curdate:=FormatDatetime('yyyy-mm-dd hh:mm:ss',now);
if button3.caption='确认新增(&A)' then
begin
if Application.MessageBox('确认新增吗?','系统提示',mb_IconInformation+mb_OK+mb_OKCancel)=IDCancel then Exit;
Sql := 'select * from ygxjjgb where yf='''
+Trim(frm_cp.Edit1.Text)+''''
+' and ygh='''+Trim(Edit1.Text)+'''';
Query1.Close;
Query1.Sql.Clear;
Query1.Sql.Add(Sql);
Query1.Open;
if not query1.isempty then
begin
application.messagebox('该月已经存在员工信息,无法完成新增!','系统提示',mb_iconinformation+mb_ok);
button1click(sender);
edit1.setfocus;
exit;
end;
for i:=1 to stringgrid1.rowcount-1 do
begin
sql:=' insert into ygxjjgb(yf,ygh,xszmid,sm,czy,czsj) values('''+trim(frm_cp.edit1.Text)+''','
+''''+trim(edit1.text)+''','+stringgrid1.cols[0].strings[i]+','
+''+stringgrid1.cols[3].strings[i]+','''+dluser+''','''+curdate+''')';
query1.close;
query1.sql.clear;
query1.sql.add(sql);
query1.execsql;
end;
application.messagebox('操作成功!','系统提示',mb_iconinformation+mb_ok);
frm_cp.button5.click;
if Application.MessageBox('是否继续新增?','系统提示',mb_IconInformation+mb_OK+mb_OKCancel)=IDCancel then Exit;
button1click(sender);
edit1.SetFocus;
end;
if button3.caption='确认修改(&S)' then
begin
sql:='select csdm from kjcsb where yf='''+trim(frm_cp.edit1.text)+''' and csmc=''出盘标志''';
query1.close;
query1.sql.clear;
query1.sql.add(sql);
query1.open;
if not Query1.IsEmpty then
begin
if query1.fieldbyname('csdm').asinteger=1 then
begin
application.messagebox('该月工资数据已经出盘,不能修改!','系统提示',mb_iconinformation+mb_ok);
exit;
end;
end;
if application.messagebox('确认修改吗?','系统提示',mb_iconinformation+mb_ok+mb_okcancel)=idcancel then exit;
for i:=1 to stringgrid1.rowcount-1 do
begin
sql:=' update ygxjjgb set sm='+stringgrid1.cols[3].strings[i]
+' where yf='''+trim(frm_cp.edit1.text)+''''
+' and ygh='''+trim(edit1.text)+''''
+'and xszmid='+stringgrid1.cols[0].strings[i]+'';
query1.close;
query1.sql.clear;
query1.sql.add(sql);
query1.execsql;
end;
application.messagebox('操作成功','系统提示',mb_iconinformation+mb_ok);
if frm_cp<> nil then
frm_cp.button5.click;
close;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -