sqbinput.pas
来自「一个仓库管理中的子系统--采购子系统」· PAS 代码 · 共 1,776 行 · 第 1/4 页
PAS
1,776 行
unit sqbinput;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ComCtrls, ExtCtrls, Grids, DBGrids, Db, DBTables;
var MyRowCount,oldCol,oldRow:Integer;
Gridcellstr,if_reused:string;
type
TsqinputForm = class(TForm)
TabControl1: TTabControl;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
yxnxLabel: TLabel;
Label4: TLabel;
Label6: TLabel;
Label7: TLabel;
sqrqDate: TDateTimePicker;
Label8: TLabel;
Label9: TLabel;
sqbidPanel: TPanel;
Panel3: TPanel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
jldwCombo: TComboBox;
Label13: TLabel;
sbslEdit: TEdit;
Label14: TLabel;
gjjeEdit: TEdit;
Label15: TLabel;
sccjCombo: TComboBox;
Label16: TLabel;
yyhrwEdit: TEdit;
Label17: TLabel;
sjyqEdit: TEdit;
Label18: TLabel;
bzEdit: TEdit;
Panel2: TPanel;
Label5: TLabel;
Label3: TLabel;
Label19: TLabel;
xqfzrCombo: TComboBox;
bzrCombo: TComboBox;
shrCombo: TComboBox;
xqrqDate: TDateTimePicker;
bzrqDate: TDateTimePicker;
shrqDate: TDateTimePicker;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Timer1: TTimer;
lshEdit: TEdit;
Label23: TLabel;
pzrCombo: TComboBox;
pzrqDate: TDateTimePicker;
Label24: TLabel;
Label25: TLabel;
sqrqEdit: TEdit;
bzrqEdit: TEdit;
xqrqEdit: TEdit;
shrqEdit: TEdit;
pzrqEdit: TEdit;
sqdwCombo: TComboBox;
cpbhEdit: TEdit;
Label26: TLabel;
jhyCombo: TComboBox;
cpmcEdit: TEdit;
xhggEdit: TEdit;
StringGrid1: TStringGrid;
GsccjCombo: TComboBox;
GjldwCombo: TComboBox;
StatusBar1: TStatusBar;
AppendBtnG: TBitBtn;
PostBtnG: TBitBtn;
NewBtnG: TBitBtn;
ExitBtnR: TBitBtn;
PostBtnR: TBitBtn;
AppendBtnR: TBitBtn;
NewBtnR: TBitBtn;
GjhyCombo: TComboBox;
rwmcEdit: TEdit;
Label27: TLabel;
zdCount: TLabel;
Label28: TLabel;
zfsqbCombo: TComboBox;
procedure TabControl1Change(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure AppendBtnRClick(Sender: TObject);
procedure PostBtnRClick(Sender: TObject);
procedure NewBtnRClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure cpbhComboExit(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure sqrqDateCloseUp(Sender: TObject);
procedure bzrqDateCloseUp(Sender: TObject);
procedure xqrqDateCloseUp(Sender: TObject);
procedure shrqDateCloseUp(Sender: TObject);
procedure pzrqDateCloseUp(Sender: TObject);
procedure sqrqEditExit(Sender: TObject);
procedure bzrqEditExit(Sender: TObject);
procedure xqrqEditExit(Sender: TObject);
procedure shrqEditExit(Sender: TObject);
procedure pzrqEditExit(Sender: TObject);
procedure GjhyComboChange(Sender: TObject);
procedure GjldwComboChange(Sender: TObject);
procedure GsccjComboChange(Sender: TObject);
procedure AppendBtnGClick(Sender: TObject);
procedure PostBtnGClick(Sender: TObject);
procedure NewBtnGClick(Sender: TObject);
procedure sccjComboExit(Sender: TObject);
procedure GsccjComboExit(Sender: TObject);
procedure cpbhEditKeyPress(Sender: TObject; var Key: Char);
procedure sccjComboKeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
procedure GsccjComboKeyPress(Sender: TObject; var Key: Char);
procedure sbslEditKeyPress(Sender: TObject; var Key: Char);
procedure sbslEditExit(Sender: TObject);
procedure gjjeEditExit(Sender: TObject);
procedure gjjeEditKeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1Click(Sender: TObject);
procedure cpbhEditDblClick(Sender: TObject);
procedure StringGrid1DblClick(Sender: TObject);
procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure cpmcEditKeyPress(Sender: TObject; var Key: Char);
procedure xhggEditKeyPress(Sender: TObject; var Key: Char);
procedure sqrqDateClick(Sender: TObject);
private
{ Private declarations }
public
//Function sub0Fromstr(datestr:string):string;
Function GetDate709(datestr:String):string;
Function ShowMeDate(Date709str:string):string;
Procedure CheckDateEdit(Datestr:string);
Function PostTosqxb:boolean;
Function PostTosqzb:Boolean;
Function DateTo709Str(date709:Tdate):string;
Procedure InitsqxbInput;
Function GetsqBdid:string;
Function GetYear:word;
procedure InitInputfrm;
Function IntToStrPad0(N:Longint;Len:Integer):String;
Procedure DisplayComponent(TheObject:TWinControl);
Function BeforePostsqzb:integer;
Function PostFromGrid:Boolean;
procedure InitstringGrid;
function checkFloatdata(checkText:string):string;
procedure check_the_reused_id(reused_id:string);
{ Public declarations }
end;
var
sqinputForm: TsqinputForm;
implementation
uses Datamodule,sccgssb, wzsz, cpxxcxsz;
{$R *.DFM}
procedure TsqinputForm.check_the_reused_id(reused_id:string);
var reused:boolean;
begin
reused:=false;
with datamodule1.PublicQuery1 do
begin
Requestlive:=True;
sql.Clear;
sql.Add('select * From dbo.a_zfsqbjl');
sql.Add('where zfsqbid='+''''+reused_id+'''');
prepare;
open;
if recordcount<>0 then
begin
reused:=true;
delete;
end;
Requestlive:=True;
close;
end;
if reused then
begin
with datamodule1.PublicQuery1 do
begin
sql.Clear;
sql.Add('select * From dbo.a_zfsqbjl');
prepare;
open;
zfsqbCombo.Items.Clear;
while not eof do
begin
zfsqbCombo.Items.Add(FieldByname('zfsqbid').asstring);
next;
end;
close;
end;
end;
end;
function TsqinputForm.checkFloatdata(checkText:string):string;
var Tempstr:string;
position,len:integer;
begin
len:=length(checkText);
position:=ansipos('.',checkText);
if position=0 then
checkText:=checkText+'.00'
else
begin
Tempstr:=copy(checkText,position,(len-position+1));
if length(Tempstr)>=3 then
begin
Tempstr:=copy(tempstr,1,3);
checktext:=copy(checktext,1,position-1);
checkText:=checkText+Tempstr;
end
else
begin
Tempstr:=Tempstr+'0';
checktext:=copy(checktext,1,position-1);
checkText:=checkText+Tempstr;
end;
end;
result:=checkText;
end;
procedure TsqInputForm.InitstringGrid;
var I,J:Integer;
begin
For I:=0 to stringGrid1.ColCount-1 do
For J:=1 to stringGrid1.RowCount-1 do
if (I=6) or (I=7) then
stringGrid1.Cells[I,J]:='0.0'
else
if I=0 then
stringGrid1.Cells[I,J]:=inttostr(J)
else
StringGrid1.Cells[I,J]:='';
end;
function TsqinputForm.PostFromGrid:Boolean;
var I:integer;
begin
For I:=1 to stringGrid1.RowCount-1 do
begin
with stringGrid1 do
if (cells[1,I]='') and (Cells[2,I]='') and (Cells[3,I]='') and (cells[4,I]='') and (Cells[5,I]='') and (Cells[6,I]='0.0') then
begin
result:=true;
exit;
end;
with datamodule1.cgsqxbTable do
begin
open;
try
append;
FieldByName('jhy').asstring:=stringGrid1.Cells[1,I];
FieldByName('sqbid').asstring:=sqbidPanel.caption;
FieldByName('cpbh').asstring:=stringGrid1.Cells[2,I];
FieldByName('cpmc').asstring:=stringGrid1.Cells[3,I];
FieldByName('xhgg').asstring:=stringGrid1.Cells[4,I];
FieldByName('jldw').asstring:=stringGrid1.Cells[5,I];
FieldByName('sbsl').asFloat:=strToFloat(stringGrid1.Cells[6,I]);
FieldByName('gjje').asFloat:=strToFloat(stringGrid1.Cells[7,I]);
FieldByName('yyhrw').asstring:=stringGrid1.Cells[9,I];
FieldByName('sccj').asstring:=stringGrid1.Cells[8,I];
FieldByName('sjyq').asstring:=stringGrid1.Cells[10,I];
FieldByName('bz').asstring:=stringGrid1.Cells[11,I];
post;
except
on EDBEngineError do
begin
messageDlg('您输入的数据可能不符合规范,请检查后重新输入!',mtInformation,[mbOK],0);
Result:=False;
exit;
end;
end;
end;
with dataModule1 do
begin
hzglTable.Open;
try
hzglTable.Append;
hzglTablejhy.AsString:=stringGrid1.Cells[1,I];
hzglTablesqbid.asstring:=sqbidpanel.Caption;
hzglTablecpbh.asstring:=stringGrid1.Cells[2,I];
hzgltablecpmc.asstring:=stringGrid1.Cells[3,I];
hzgltablexhgg.asstring:=stringGrid1.Cells[4,I];
hzglTablesldw.asstring:=stringGrid1.Cells[5,I];
hzgltablesbsl.asFloat:=Strtofloat(stringGrid1.Cells[6,I]);
hzgltablegjje.asFloat:=Strtofloat(stringGrid1.Cells[7,I]);
hzgltablesccj.asstring:=stringGrid1.Cells[8,I];
hzgltablesjyq.asstring:=stringGrid1.Cells[9,I];
hzglTablelsh.asstring:=lshedit.Text;
hzglTablerwmc.asstring:=rwmcEdit.Text;
hzglTableyxnx.asstring:=yxnxLabel.Caption;
hzglTablexqdw.asstring:=sqdwCombo.Text;
hzglTablesbrq.asstring:=GetDate709(sqrqedit.Text);
hzglTablebzr.asstring:=bzrCombo.Text;
hzglTableshr.asstring:=shrCombo.Text;
hzglTablebzrq.asstring:=GetDate709(bzrqedit.Text);
hzglTableshrq.asstring:=GetDate709(shrqedit.Text);
hzglTablepzr.asstring:=pzrCombo.Text;
hzglTablepzrq.asstring:=GetDate709(pzrqedit.Text);
hzglTable.Post;
except
on EDBEngineError do
begin
messageDlg('您输入的数据可能不符合规范,请检查后重新输入!',mtInformation,[mbOK],0);
Result:=False;
exit;
end;
end;
end;
end;
InitstringGrid;
result:=True;
end;
function TsqinputForm.BeforePostsqzb:integer;
begin
with datamodule1.PublicQuery1 do
begin
//close;
sql.Clear;
sql.Add('select * from dbo.a_cgsqzb');
sql.add('where sqbid='+''''+sqbidPanel.Caption+'''');
open;
Result:=RecordCount;
close;
end;
end;
procedure TsqinputForm.TabControl1Change(Sender: TObject); //切换TabControl控件
begin
with TabControl1 do
begin
if TabIndex=1 then
begin
//设置按钮的可见状态
AppendbtnG.Visible:=True;
PostBtnG.Visible:=True;
NewBtnG.Visible:=True;
AppendbtnR.Visible:=False;
PostBtnR.Visible:=False;
NewBtnR.Visible:=False;
//设置StringGrid1的显示性质
with StringGrid1 do
begin
Visible:=True;
Height:=panel3.Height;
Width:=panel3.Width;
Left:=Panel3.Left;
top:=0;
cells[1,0]:='计划员';
Cells[2,0]:='产品编号';
cells[3,0]:='产品名称';
cells[4,0]:='型号规格';
cells[5,0]:='计量单位';
cells[6,0]:='申请数量';
cells[7,0]:='估计金额';
cells[8,0]:='生产厂家';
cells[9,0]:='用于何任务';
cells[10,0]:='时间要求';
cells[11,0]:='备注';
end;
GjhyCombo.Text:='';
GjldwCombo.Text:='';
GsccjCombo.Text:='';
with datamodule1.PublicQuery1 do
begin
close;
sql.clear;
sql.add('select gysmc from dbo.e_fczfzb');
open;
first;
GsccjCombo.Items.Clear;
while not eof do
begin
GsccjCombo.Items.Add(FieldByName('gysmc').asstring);
next;
end;
close;
sql.clear;
sql.add('select jhyid from dbo.p_jhyb');
open;
first;
GjhyCombo.Items.Clear;
while not eof do
begin
GjhyCombo.Items.Add(FieldByName('jhyid').asstring);
next;
end;
close;
end;
end
else
begin
StringGrid1.Visible:=False;
GjldwCombo.Visible:=False;
GsccjCombo.Visible:=False;
GjhyCombo.Visible:=false;
AppendbtnR.Visible:=True;
PostBtnR.Visible:=True;
NewBtnR.Visible:=True;
AppendbtnG.Visible:=False;
PostBtnG.Visible:=False;
NewBtnG.Visible:=False;
end;
end;
end;
procedure TsqinputForm.Timer1Timer(Sender: TObject); //在状态条上显示系统时间
begin
with statusbar1.Panels.Items[3] do
begin
Text:='20'+DateTimeToStr(Now);
end;
end;
Procedure TsqinputForm.DisplayComponent(TheObject:TWinControl);
begin
TheObject.Visible:=True;
with StringGrid1 do
begin
if (GoEditing in Options) then
Options:=Options-[GoEditing];
end;
end;
Function TsqinputForm.IntToStrPad0(N:LongInt;Len:Integer):string; //定制字符串的长度,不够的加零补齐
begin
FmtStr(Result,'%d',[N]);
while Length(Result)<len do
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?