📄 ygkc_pas.~pas
字号:
unit ygkc_pas;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, StdCtrls, Buttons, ComCtrls, Mask, Grids,
DBGrids, DB,datamd_pas, ADODB;
type
Tygkc_Form = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
DateTimePicker1: TDateTimePicker;
Label4: TLabel;
BitBtn1: TBitBtn;
DBNavigator1: TDBNavigator;
Label11: TLabel;
ComboBox2: TComboBox;
DBGrid1: TDBGrid;
Label5: TLabel;
Label6: TLabel;
BitBtn2: TBitBtn;
ComboBox3: TComboBox;
BitBtn3: TBitBtn;
DataSource1: TDataSource;
DataSource2: TDataSource;
MaskEdit1: TMaskEdit;
MaskEdit2: TMaskEdit;
Label7: TLabel;
DBEdit1: TDBEdit;
DataSource3: TDataSource;
ComboBox1: TComboBox;
ADOTable_kccx: TADOTable;
DataSource4: TDataSource;
ADOTable_kc: TADOTable;
DataSource5: TDataSource;
procedure BitBtn3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
xmid,datestr:string;
tmyear,tmmonth,tmdate,today_gs:integer;
end;
var
ygkc_Form: Tygkc_Form;
implementation
{$R *.dfm}
procedure Tygkc_Form.BitBtn3Click(Sender: TObject);
begin
datamodule1.ADOTable_xm.Active:=false;
datamodule1.ADOTable_xmck.Active:=false;
close();
end;
procedure Tygkc_Form.FormCreate(Sender: TObject);
begin
edit1.Clear;
maskedit1.Clear;
maskedit2.Clear;
datamodule1.ADODataSet1.Close;
datamodule1.ADODataSet1.CommandText:='select convert(varchar(10),getdate(),21) as time';
datamodule1.ADODataSet1.Open;
datestr:=datamodule1.DataSource1.DataSet.fieldbyname('time').AsString;
tmyear:=strtoint(copy(datestr,1,4));tmmonth:=strtoint(copy(datestr,6,2));tmdate:=strtoint(copy(datestr,9,2));
datetimepicker1.Date:=strtodate(datestr);
datamodule1.ADODataSet1.Close;
datamodule1.ADODataSet1.CommandText:='select sum(工时) as zgs from kc where (用户_id='''+datamodule1.user_id+''') and (年='
+inttostr(tmyear)+') and (月='+inttostr(tmmonth)+') and (日='+inttostr(tmdate)+')';
datamodule1.ADODataSet1.Open;
today_gs:=datamodule1.DataSource1.DataSet.fieldbyname('zgs').AsInteger;
Caption:='每日考勤---用户:'+datamodule1.user_name+'今天已登记'+inttostr(today_gs)+'工时';
combobox2change(sender);
activecontrol:=dbgrid1;
end;
procedure Tygkc_Form.ComboBox1Change(Sender: TObject);
begin
if not datamodule1.ADOTable_xm.Active then datamodule1.ADOTable_xm.Active:=true;
datamodule1.ADOTable_xm.locate('项目名称',ComboBox1.Items.strings[combobox1.itemindex],
[loPartialKey]);
xmid:=datamodule1.ADOTable_xm.fieldbyname('项目_id').value;
end;
procedure Tygkc_Form.BitBtn1Click(Sender: TObject);
var inserstring:string;
begin
if (edit1.Text='') or (maskedit2.Text='') then
begin
application.MessageBox('工作内容或预估工时必须输入','操作提示',mb_ok);
exit;
end;
inserstring:='insert into xmck (用户_id,项目_id,工作内容,开始日期,预估工时,是否完成) values ('
+''''+datamodule1.user_id+''','+''''+xmid+''','+''''+edit1.Text+''','+''''
+datetostr(datetimepicker1.date)+''','+trim(maskedit2.Text)+','+'''未完成'')';
datamodule1.ADOCommand1.CommandText:=inserstring;
try
datamodule1.ADOCommand1.Execute;
finally
application.MessageBox('新工作添加成功','操作提示',mb_ok);
end;
datamodule1.ADOTable_xmck.Active:=false;
datamodule1.ADOTable_xmck.Active:=true;
edit1.Clear;
maskedit2.Clear;
end;
procedure Tygkc_Form.ComboBox2Change(Sender: TObject);
begin
datamodule1.ADOTable_xmck.Active:=false;
case combobox2.ItemIndex of
0: begin
datamodule1.ADOTable_xmck.Filtered:=false;
datamodule1.ADOTable_xmck.Filter:='是否完成='+'''未完成''';
datamodule1.ADOTable_xmck.Filtered:=true;
bitbtn2.Enabled:=true;
end;
1: begin
datamodule1.ADOTable_xmck.Filtered:=false;
datamodule1.ADOTable_xmck.Filter:='是否完成='+'''已完成''';
datamodule1.ADOTable_xmck.Filtered:=true;
bitbtn2.Enabled:=false;
end;
else
datamodule1.ADOTable_xmck.Filtered:=false;
end;
datamodule1.ADOTable_xmck.Active:=true;
end;
procedure Tygkc_Form.BitBtn2Click(Sender: TObject);
var i,j,k,xmgs:integer;
sqlstr,xm_id:string;
begin
if ((strtoint(trim(maskedit1.Text))+today_gs)>24) then
begin
application.MessageBox('今天所用工时不合理,请重新输入','操作提示',mb_ok);
exit;
end;
i:=strtoint(trim(maskedit1.Text));
j:=datasource1.DataSet.fieldbyname('已用工时').Value;
k:=datasource1.DataSet.fieldbyname('预估工时').Value;
if ((i+j)<=k) then dbedit1.Clear;
if ((i+j)>k) and (dbedit1.Text='') then
begin
application.MessageBox('当前所用工时超过预估工时,请输入延误原因','操作提示',mb_ok);
exit;
end;
//向kc表中添加数据
xm_id:=datasource1.DataSet.fieldbyname('项目_id').AsString;
adotable_kc.Active:=false;
adotable_kc.Filter:='(用户_id='''+datamodule1.user_id+''') and (项目_id='''+xm_id+''') and (月='+inttostr(tmmonth)+') and (年='+inttostr(tmyear)+') and (日='+inttostr(tmdate)+')';
adotable_kc.Filtered:=true;
adotable_kc.Active:=true;
if datasource5.DataSet.IsEmpty then
sqlstr:='insert into kc (用户_id,项目_id,工时,是否完成) values ('''
+datamodule1.user_id+''','+''''+xm_id+''','+inttostr(i)+','+''''+ComboBox3.Items.strings[combobox3.itemindex]+''')'
else
sqlstr:='update kc set 工时='+inttostr(datasource5.DataSet.fieldbyname('工时').Value+i)+',是否完成='''+ComboBox3.Items.strings[combobox3.itemindex]+''''
+' where (用户_id='''+datamodule1.user_id+''') and (项目_id='''+xm_id+''') and (月='+inttostr(tmmonth)+') and (年='+inttostr(tmyear)+') and (日='+inttostr(tmdate)+')';
datamodule1.ADOCommand1.CommandText:=sqlstr;
datamodule1.ADOCommand1.Execute;
adotable_kc.Active:=false;
adotable_kc.Active:=true;
xmgs:=datasource5.DataSet.fieldbyname('工时').Value;
//向xmck表中登记已用工时
datasource1.DataSet.Edit;
if (ComboBox3.Items.strings[combobox3.itemindex]='已完成')then
begin
datasource1.DataSet.FieldByName('完成日期').Value:=strtodate(datestr);
datasource1.DataSet.FieldByName('是否完成').Value:='已完成';
end;
datasource1.DataSet.FieldByName('已用工时').Value:=i+j;
datasource1.DataSet.Post;
today_gs:=today_gs+i;
Caption:='每日考勤---用户:'+datamodule1.user_name+'今天已登记'+inttostr(today_gs)+'工时';
//向kccx中添加数据
adotable_kccx.Active:=false;
adotable_kccx.Filter:='(用户_id='''+datamodule1.user_id+''') and (项目_id='''+xm_id+''') and (月份='+inttostr(tmmonth)+') and (年度='+inttostr(tmyear)+')';
adotable_kccx.Filtered:=true;
adotable_kccx.Active:=true;
if datasource4.DataSet.IsEmpty then sqlstr:='insert into kccx (用户_id,项目_id,年度,月份,月用工时,['+inttostr(tmdate)+']) values ('''+
datamodule1.user_id+''','''+xm_id+''','+inttostr(tmyear)+','+inttostr(tmmonth)+','+inttostr(i)+','+inttostr(i)+')'
else
begin
sqlstr:='update kccx set ['+inttostr(tmdate)+']='+inttostr(xmgs)+',月用工时='+inttostr(datasource4.DataSet.FieldByName('月用工时').Value+i)
+' where (用户_id='''+datamodule1.user_id+''') and (项目_id='''+xm_id+''') and (月份='+inttostr(tmmonth)+') and (年度='+inttostr(tmyear)+')';
end;
datamodule1.ADOCommand1.CommandText:=sqlstr;
datamodule1.ADOCommand1.Execute;
adotable_kc.Active:=false;
adotable_kccx.Active:=false;
maskedit1.Clear;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -