You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

360 lines
10 KiB
Plaintext

11 months ago
unit u_op_seae_word;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
dxExEdtr, DB, dxTL, dxDBCtrl, dxDBGrid, dxCntner, StdCtrls, Mask,
wwdbedit, Wwdotdot, Wwdbcomb, bsSkinCtrls, Dialogs, Excel, ADODB,
BusinessSkinForm, DBCtrls, OleServer, Word2000;
type
Tfrm_op_seae_word = class(TForm)
bsBusinessSkinForm1: TbsBusinessSkinForm;
t_excel_bill: TADOQuery;
t_excel_bill1: TDataSource;
bsSkinPanel1: TbsSkinPanel;
t_excel_bill_bill: TADOQuery;
t_excel_bill_bill1: TDataSource;
bsSkinPanel8: TbsSkinPanel;
bsSkinButton10: TbsSkinButton;
bsSkinButton11: TbsSkinButton;
bsSkinButton12: TbsSkinButton;
t_op_ctn: TADOQuery;
bsSkinOpenDialog1: TOpenDialog;
SaveDialog: TSaveDialog;
bsSkinGroupBox2: TbsSkinGroupBox;
bsSkinPanel6: TbsSkinPanel;
bsSkinPanel7: TbsSkinPanel;
bsSkinButton7: TbsSkinButton;
bsSkinButton8: TbsSkinButton;
bsSkinButton9: TbsSkinButton;
t_excel_billEX_ID: TAutoIncField;
t_excel_billDSDesigner: TStringField;
t_excel_billDSDesigner2: TBlobField;
dxDBGrid2: TdxDBGrid;
dxDBGrid2Column1: TdxDBGridMaskColumn;
dxDBGrid2Y: TdxDBGridMaskColumn;
bsSkinPanel9: TbsSkinPanel;
wwDBComboBox2: TwwDBComboBox;
DBEdit1: TDBEdit;
dxDBGrid2Column4: TdxDBGridColumn;
DBEdit5: TDBEdit;
bsSkinButton1: TbsSkinButton;
bsSkinButton2: TbsSkinButton;
bsSkinButton4: TbsSkinButton;
bsSkinGroupBox3: TbsSkinGroupBox;
bsSkinPanel2: TbsSkinPanel;
dxDBGrid1: TdxDBGrid;
dxDBGrid1Column1: TdxDBGridMaskColumn;
Memo1: TMemo;
bsSkinButton13: TbsSkinButton;
wordApp: TWordApplication;
lbl1: TLabel;
procedure FormShow(Sender: TObject);
procedure bsSkinButton1Click(Sender: TObject);
procedure bsSkinButton2Click(Sender: TObject);
procedure bsSkinButton4Click(Sender: TObject);
procedure t_excel_billPostError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
procedure t_excel_bill_billPostError(DataSet: TDataSet;
E: EDatabaseError; var Action: TDataAction);
procedure t_excel_billBeforeDelete(DataSet: TDataSet);
procedure bsSkinButton7Click(Sender: TObject);
procedure bsSkinButton8Click(Sender: TObject);
procedure bsSkinButton9Click(Sender: TObject);
procedure t_excel_bill_ctnBeforeInsert(DataSet: TDataSet);
procedure t_excel_bill_billBeforePost(DataSet: TDataSet);
procedure t_excel_bill_billAfterInsert(DataSet: TDataSet);
procedure bsSkinButton11Click(Sender: TObject);
procedure bsSkinButton12Click(Sender: TObject);
procedure bsSkinButton10Click(Sender: TObject);
procedure bsSkinButton13Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_op_seae_word: Tfrm_op_seae_word;
implementation
uses u_main, my_sys_function, u_op_seae;
{$R *.dfm}
procedure Tfrm_op_seae_word.FormShow(Sender: TObject);
begin
t_excel_bill.open;
t_excel_bill_bill.open;
end;
procedure Tfrm_op_seae_word.bsSkinButton1Click(Sender: TObject);
begin
if employee<>'<27>¹<EFBFBD><C2B9><EFBFBD>' then
begin
showmessage('<27><><EFBFBD><EFBFBD>ϵϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>Ա');
Exit;
end;
t_excel_bill.insert;
end;
procedure Tfrm_op_seae_word.bsSkinButton2Click(Sender: TObject);
begin
if employee<>'<27>¹<EFBFBD><C2B9><EFBFBD>' then
begin
showmessage('<27><><EFBFBD><EFBFBD>ϵϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>Ա');
Exit;
end;
table_post(t_excel_bill);
end;
procedure Tfrm_op_seae_word.bsSkinButton4Click(Sender: TObject);
begin
if employee<>'<27>¹<EFBFBD><C2B9><EFBFBD>' then
begin
showmessage('<27><><EFBFBD><EFBFBD>ϵϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>Ա');
Exit;
end;
table_delete(t_excel_bill);
end;
procedure Tfrm_op_seae_word.t_excel_billPostError(DataSet: TDataSet;
E: EDatabaseError; var Action: TDataAction);
begin
showmessage('<27><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>');
end;
procedure Tfrm_op_seae_word.t_excel_bill_billPostError(DataSet: TDataSet;
E: EDatabaseError; var Action: TDataAction);
begin
showmessage('<27>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>');
end;
procedure Tfrm_op_seae_word.t_excel_billBeforeDelete(DataSet: TDataSet);
begin
table_before_delete(t_excel_bill_bill,'<27>ӱ<EFBFBD>');
end;
procedure Tfrm_op_seae_word.bsSkinButton7Click(Sender: TObject);
begin
t_excel_bill_bill.insert;
end;
procedure Tfrm_op_seae_word.bsSkinButton8Click(Sender: TObject);
begin
table_post(t_excel_bill_bill);
end;
procedure Tfrm_op_seae_word.bsSkinButton9Click(Sender: TObject);
begin
table_delete(t_excel_bill_bill);
end;
procedure Tfrm_op_seae_word.t_excel_bill_ctnBeforeInsert(
DataSet: TDataSet);
begin
table_before_insert(t_excel_bill);
end;
procedure Tfrm_op_seae_word.t_excel_bill_billBeforePost(
DataSet: TDataSet);
begin
table_before_post(t_excel_bill_bill,'<27>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>');
table_before_post(t_excel_bill_bill,'<27><>ǩ<EFBFBD><C7A9>');
end;
procedure Tfrm_op_seae_word.t_excel_bill_billAfterInsert(
DataSet: TDataSet);
begin
t_excel_bill_bill['EX_ID']:=t_excel_bill['EX_ID'];
end;
procedure Tfrm_op_seae_word.bsSkinButton11Click(Sender: TObject);
begin
close;
end;
procedure Tfrm_op_seae_word.bsSkinButton12Click(Sender: TObject);
begin
if employee<>'<27>¹<EFBFBD><C2B9><EFBFBD>' then
begin
showmessage('<27><><EFBFBD><EFBFBD>ϵϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>Ա');
Exit;
end;
if t_excel_bill.IsEmpty then
exit;
if (t_excel_bill.state=dsinsert)or(t_excel_bill.state=dsedit)then
t_excel_bill.Post;
if bsSkinOpenDialog1.Execute then
begin
t_excel_bill.EDIT;
t_excel_billDSDesigner2.LoadFromFile(bsSkinOpenDialog1.FileName);
t_excel_bill.post;
end;
end;
procedure Tfrm_op_seae_word.bsSkinButton10Click(Sender: TObject);
var
str:Tstringlist;
wide_str,tempstr:widestring;
i:integer;
Y:INTEGER;
templateName: OleVariant;
newTemplate: OleVariant;
ItemIndex: OleVariant;
vSelection: Selection;
vBookMark: BookMark;
vTable: Table;
WD: WordDocument;
function WriteWordBookMark(WD: WordDocument;BookMarkName,BookMarkValue: String): Boolean;//<2F><>ֵд<D6B5><D0B4>word<72>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ǩ<EFBFBD><C7A9>
var
BMName: OleVariant;
begin
Result := False;
if WD.Bookmarks.Exists(BookMarkName) then
begin
BMName := BookMarkName;
WD.Bookmarks.Item(BMName).Select;
wordApp.Selection.Text := BookMarkValue;
end;
end;
begin
if t_excel_bill.IsEmpty then
exit;
t_excel_billDSDesigner2.SaveToFile(ExtractFilePath(ParamStr(0))+t_excel_bill.fieldbyname('EX_ID').asstring+'.doc');
templateName :=ExtractFilePath(ParamStr(0))+t_excel_bill.fieldbyname('EX_ID').asstring+'.doc';
str:=Tstringlist.Create;
str.Clear;
newTemplate := False;
try
wordApp.Connect();
except
MessageDlg('<27><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>δ<EFBFBD><CEB4>װMicrosoft Office Word97<39><37><EFBFBD><EFBFBD><EFBFBD>ߵİ汾<C4B0><E6B1BE>', mtError, [mbOK], 0);
Abort;
end;
{
WordApp:TWordApplication;
Template:String;//ģ<><C4A3><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>(ȫ·<C8AB><C2B7>)
BookMarkName:String;//ģ<><C4A3><EFBFBD>ļ<EFBFBD><C4BC>е<EFBFBD><D0B5><EFBFBD>ǩ<EFBFBD><C7A9>
BookMarkValue:String;//<2F><>Ҫ<EFBFBD>ڱ<EFBFBD>ǩλ<C7A9><CEBB><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
visibleTemp:boolean;//wordӦ<64>ó<EFBFBD><C3B3><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɼ<EFBFBD>
WD:= WordApp.Documents.Add(Template, EmptyParam, EmptyParam, visibleTemp);
WriteWordBookMark(WordApp, WD,BookMarkName,BookMarkValue);
//****************************************************//
}
wd:=wordApp.Documents.AddOld(templateName, newTemplate);
t_excel_bill_bill.First;
while not t_excel_bill_bill.eof do
begin
if t_excel_bill_bill.fieldbyname('<27>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>').asstring<>'<27><>װ<EFBFBD><D7B0>111'then
begin
if trim(t_excel_bill_bill.fieldbyname('<27>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>').asstring)<>'<27>̶<EFBFBD>ֵ'then
begin
if trim(t_excel_bill_bill.fieldbyname('<27>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>').asstring)='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' then begin
Memo1.Text:=frm_op_seae.t_op_seae2.DataSet.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring+' '+frm_op_seae.t_op_seae2.DataSet.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring;
for i:=0 to Memo1.Lines.Count-1 do
begin
if i=0 then
tempstr:=Memo1.Lines[i]
else
tempstr:=tempstr+#13#10+Memo1.Lines[i];
end;
end else begin
Memo1.Text:=frm_op_seae.t_op_seae2.DataSet.fieldbyname(t_excel_bill_bill.fieldbyname('<27>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>').asstring).asstring;
for i:=0 to Memo1.Lines.Count-1 do
begin
if i=0 then
tempstr:=Memo1.Lines[i]
else
tempstr:=tempstr+#13#10+Memo1.Lines[i];
end;
end;
WriteWordBookMark(WD,t_excel_bill_bill.fieldbyname('<27><>ǩ<EFBFBD><C7A9>').asstring,tempstr);
end
else
begin
WriteWordBookMark(WD,t_excel_bill_bill.fieldbyname('<27><>ǩ<EFBFBD><C7A9>').asstring,t_excel_bill_bill.fieldbyname('<27>̶<EFBFBD>ֵ').asstring);
end;
end
else
begin
t_op_ctn.close;
t_op_ctn.Parameters[0].value:=frm_op_seae.t_op_seae2.DataSet.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring;
t_op_ctn.open;
// Y:=t_excel_bill_bill.fieldbyname('<27><><EFBFBD><EFBFBD>Y').asinteger;
t_op_ctn.first;
while not t_op_ctn.eof do
begin
wide_str:=t_op_ctn.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring
+copy(' ',1,20-length(t_op_ctn.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring))
+t_op_ctn.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring;
tempstr:=wide_str;
wide_str:=t_op_ctn.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring+'X'
+t_op_ctn.fieldbyname('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ').asstring+' '
+t_op_ctn.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring
+t_op_ctn.fieldbyname('<27><>װ').asstring;
tempstr:=tempstr+#13#10+wide_str;
wide_str:=t_op_ctn.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring+'KGS';
tempstr:=tempstr+#13#10+wide_str;
wide_str:=t_op_ctn.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring+'CBM';
tempstr:=tempstr+#13#10+wide_str;
t_op_ctn.next;
end;
wide_str:=frm_op_seae.t_op_seae2.DataSet.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring
+frm_op_seae.t_op_seae2.DataSet.fieldbyname('<27><>װ').asstring;
tempstr:=tempstr+#13#10+wide_str;
wide_str:=frm_op_seae.t_op_seae2.DataSet.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring+'KGS';
tempstr:=tempstr+#13#10+wide_str;
wide_str:=frm_op_seae.t_op_seae2.DataSet.fieldbyname('<27><><EFBFBD><EFBFBD>').asstring+'CBM';
tempstr:=tempstr+#13#10+wide_str;
WriteWordBookMark(WD,t_excel_bill_bill.fieldbyname('<27><>ǩ<EFBFBD><C7A9>').asstring,tempstr);
end;
t_excel_bill_bill.next;
end;
wordApp.Visible := true;
//<2F><><EFBFBD><EFBFBD>С<EFBFBD><D0A1>
// wordApp.WindowState := 2;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
wordApp.WindowState := 1;
wordApp.Disconnect();
end;
procedure Tfrm_op_seae_word.bsSkinButton13Click(Sender: TObject);
begin
if t_excel_bill.IsEmpty then
exit;
if employee<>'<27>¹<EFBFBD><C2B9><EFBFBD>' then
begin
showmessage('<27><><EFBFBD><EFBFBD>ϵϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>Ա');
Exit;
end;
end;
end.