test_edit_src.pas
来自「一个仓库管理中的子系统--采购子系统」· PAS 代码 · 共 617 行 · 第 1/2 页
PAS
617 行
beforeheight := 0;
For count2 := 0 to count1 - 1 Do
beforeheight := beforeheight + canvas.textheight (strings[count2]);
length := Canvas.TextWidth (strings[count1]);
canvas.textrect(rect(x1,y1,x2,y2),x1+width - textxdirectionspace - length,y1+round ((height - 2 * textydirectionspace - textheight) / 2 +textydirectionspace+beforeheight), strings[count1]);
End;
1: For count1 := 0 to strings.Count - 1 Do
Begin
beforeheight := 0;
For count2 := 0 to count1 - 1 Do
beforeheight := beforeheight + canvas.textheight (strings[count2]);
length := Canvas.TextWidth (strings[count1]);
canvas.textrect(rect(x1,y1,x2,y2),x1+round (textxdirectionspace + (width - 2* textxdirectionspace - length) / 2),y1+textydirectionspace+round ((height - 2 *textydirectionspace - textheight) / 2)+beforeheight,strings[count1]);
End;
End
//end case
End
finally
canvas.Unlock;
end;
End;
Procedure TForm2.DisplayComponent(TheObject:TWinControl);
begin
TheObject.Visible:=True;
with StringGrid1 do
begin
if (GoEditing in Options) then
Options:=Options-[GoEditing];
end;
end;
procedure TForm2.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var text:string;
begin
if arow=0 then
begin
stringgrid1.Canvas.Brush.Color:=grid_headcolor;
stringgrid1.Canvas.FillRect(rect);
writetext(stringgrid1.canvas,rect.left,rect.top,rect.right,rect.bottom,4,1,stringgrid1.cells[acol,arow],font,1,true);
exit;
end;
text:=stringgrid1.cells[acol,arow];
if (arow mod 2) =0 then stringgrid1.Canvas.Brush.Color:=grid_highcolor
else stringgrid1.Canvas.Brush.Color:=grid_lowcolor;
if gdSelected in state then stringgrid1.Canvas.Brush.Color:=grid_selectedcolor;
stringgrid1.Canvas.FillRect(rect);
writetext(stringgrid1.canvas,rect.left,rect.top,rect.right,rect.bottom,1,1,text,font,2,true);
if (dhsm_field_Index=0) and (bz_field_index=0) then //如果用户没有选择“到货说明”则本函数退出
exit;
with Sender as TStringGrid do
begin
if gdFocused in State then
begin
if (ACol=dhsm_field_Index) and (dhsm_field_Index<>0) then
begin
DateTimePicker1.SetBounds(
Rect.Left+StringGrid1.left+1,
Rect.Top+StringGrid1.Top+1,
Rect.Right-Rect.Left+1,
StringGrid1.DefaultRowHeight);
Canvas.DrawFocusRect(Rect);
end
else
if (ACol=bz_field_Index) and (bz_field_Index<>0) then
begin
Combobox1.SetBounds(
Rect.Left+StringGrid1.left+1,
Rect.Top+StringGrid1.Top+1,
Rect.Right-Rect.Left+1,
StringGrid1.DefaultRowHeight);
Canvas.DrawFocusRect(Rect);
end;
end;
end;
end;
procedure TForm2.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
if (dhsm_field_Index=0) and (bz_field_index=0) then
exit;
myrowcount:=Arow;
with stringgrid1 do
if (Acol<>1) and (gorowselect in Options) then
options:=options-[gorowselect]
else if (Acol=1) and not (goRowselect in Options) then
options:=options+[gorowselect];
if (ACol=dhsm_field_Index) and (dhsm_field_Index<>0) then
begin
DisplayComponent(datetimepicker1);
ComboBox1.Visible:=false;
end
else
if (Acol=bz_field_index) and (bz_field_index<>0) then
begin
DisplayComponent(ComboBox1);
datetimepicker1.Visible:=False;
end
else
begin
Combobox1.Visible:=false;
datetimepicker1.Visible:=False;
with StringGrid1 do
begin
if (GoEditing in Options) then
Options:=Options-[GoEditing];
end;
end;
end;
procedure TForm2.FormActivate(Sender: TObject);
var I,J,Next_start,col:integer;
begin
//J:=1;
dhsm_field_Index:=0;
bz_field_index:=0;
sqbid_field_index:=0;
cpbh_field_index:=0;
next_start:=0;
datetimepicker1.DateTime:=date;
with datamodule1.publicquery2 do //对“备注“-Combobox1中的items属性进行初始化
begin
sql.Clear;
sql.Add('select distinct bz from dbo.a_cghzglb');
prepare;
open;
Combobox1.Items.Clear;
while not eof do
begin
if fieldbyname('bz').asstring<>'' then
combobox1.Items.Add(FieldByName('bz').asstring);
next;
end;
close;
end;
with datamodule1.publicquery2 do
begin
sql.Clear;
sql.Text:=select_condition;
prepare;
open;
for I:=0 to datamodule1.publicquery2.Fields.Count-1 do
if visible_flag_array[I]=1 then
datamodule1.publicquery2.Fields[I].Visible:=false;
for I:=0 to fields_count-1 do
if datamodule1.publicquery2.Fields[I].Visible then
visible_fields_count:=visible_fields_count+1;
stringgrid1.RowHeights[0]:=36;
stringgrid1.ColCount:=visible_fields_count+1;
stringGrid1.RowCount:=datamodule1.publicquery2.RecordCount+1;
for I:=1 to stringgrid1.ColCount-1 do
for J:=next_start to fields_count-1 do
begin
if datamodule1.publicquery2.Fields[J].Visible then
begin
stringgrid1.Cells[I,0]:=datamodule1.publicquery2.Fields[J].FieldName;
next_start:=J+1;
break;
end;
end;
for I:=1 to stringgrid1.ColCount-1 do //判断字段“到货说明”所在的位置
if stringgrid1.Cells[I,0]='到货说明' then
begin
dhsm_field_index:=I;
break;
end;
for I:=1 to stringgrid1.ColCount-1 do
if stringgrid1.Cells[I,0]='备注' then
begin
bz_field_index:=I;
break;
end;
for I:=1 to stringgrid1.ColCount-1 do
if stringgrid1.Cells[I,0]='申请表单号' then
begin
sqbid_field_index:=I;
break;
end;
for I:=1 to stringgrid1.ColCount-1 do
if stringgrid1.Cells[I,0]='产品编号' then
begin
cpbh_field_index:=I;
break;
end;
j:=1;
while not eof do
begin
col:=1;
for I:=0 to fields.Count-1 do
if visible_flag_array[I]=0 then
begin
if (col=dhsm_field_Index) and (fields[I].asstring<>'') then
stringgrid1.cells[col,J]:=showmedate(fields[I].asstring)
else
stringgrid1.cells[col,J]:=fields[I].asstring;
col:=col+1;
end;
next;
J:=J+1;
end;
close;
end;
end;
procedure TForm2.FormResize(Sender: TObject);
begin
stringgrid1.Height:=(form2.Height*8) div 10;
stringgrid1.Width:=form2.Width-10;
bitbtn2.left:=(form2.Width*8) div 10;
bitbtn2.top:=(form2.Height*10) div 12;
bitbtn1.Top:=bitbtn2.top;
bitbtn1.left:=bitbtn2.left-(form2.Width*7) div 10;
end;
procedure TForm2.ComboBox1Change(Sender: TObject);
begin
stringGrid1.cells[bz_field_index,MyRowCount]:=Combobox1.Text;
end;
procedure TForm2.DateTimePicker1CloseUp(Sender: TObject);
begin
stringGrid1.cells[dhsm_field_index,MyRowCount]:=ShowMeDate(DateTo709str(DateTimepicker1.date));
//stringGrid1.cells[dhsm_field_index,MyRowCount]:=sqinputForm.ShowMeDate(sqinputForm.DateTo709str(DateTimepicker1.date));
end;
procedure TForm2.DateTimePicker1Click(Sender: TObject);
begin
DateTimepicker1.datetime:=Date;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
var I:integer;
sqbidstr,cpbhstr,dhsmstr,bzstr:string;
//right_posted:boolean;
begin
//right_posted:=false;
if (dhsm_Field_index=0) or (bz_field_index=0) then
exit;
for I:=1 to stringgrid1.rowCount-1 do
begin
sqbidstr:=stringgrid1.Cells[sqbid_field_index,I];
cpbhstr:=stringgrid1.Cells[cpbh_field_index,I];
dhsmstr:=GetDate709(stringgrid1.Cells[dhsm_field_index,I]);
bzstr:=stringgrid1.Cells[bz_field_index,I];
{if sqbidstr='' then
if I<>stringgrid
break;}
with datamodule1.query3 do
begin
requestlive:=true;
sql.Clear;
sql.Add('select * from dbo.a_cghzglb');
//sql.Add('where sqbid='+''''+sqbidstr+''''+' and '+'cpbh='+''''+cpbhstr+'''');
sql.Add('where sqbid='+''''+sqbidstr+''''+' and cpbh='+''''+cpbhstr+'''');
prepare;
open;
edit;
fieldByname('qt').asstring:=dhsmstr;
fieldByName('bz').asstring:=bzstr;
post;
close;
end;
end;
datamodule1.Query3.RequestLive:=false;
showmessage('您的修改数据已经成功写入数据库产品编号!');
end;
procedure TForm2.DateTimePicker1UserInput(Sender: TObject;
const UserString: String; var DateAndTime: TDateTime;
var AllowChange: Boolean);
begin
stringGrid1.cells[dhsm_field_index,MyRowCount]:=showmedate(userstring);
DateTimepicker1.datetime:=Date;
end;
procedure TForm2.DateTimePicker1Exit(Sender: TObject);
begin
DateTimepicker1.datetime:=Date;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?