procedure TFsettle.FormCreate(Sender: TObject);
begin
querylist := tquery.create(self);
querylist.DatabaseName := 'book';
querylist.SQL.Add('select departcurrency.dept,department_kc_change.dept from departcurrency, department_kc_change');
querylist.SQL.Add('where (departcurrency."date" =:_date) and (department_kc_change."date" =:_date)');
querylist.ParamByName('_date').AsDate := date;
querylist.Open;
button2.Enabled := (querylist.Fields[0].AsString = '');
button3.Enabled := not button2.Enabled;
button5.Enabled := button2.Enabled;
button6.Enabled := button2.Enabled;
querylist.Close;
querylist.SQL.Clear;
label1.Caption := formatdatetime('yyyy"Äê"mm"ÔÂ"dd"ÈÕ"½áÕË', date);
sellgrid.cells[0, 0] := 'Àà±ð';
sellgrid.cells[1, 0] := 'ÂëÑó';
sellgrid.cells[2, 0] := 'ʵÑó';
sellgrid.cells[3, 0] := '³É±¾';
sellgrid.cells[4, 0] := 'ÀûÈó';
sellgrid.cells[5, 0] := '±¸×¢';
sellgrid.cells[6, 0] := '״̬';
sellgrid.ColWidths[7] := -1;
sellgrid.ColWidths[8] := -1;
sellgrid.ColWidths[9] := -1;
inoutgrid.Cells[0, 0] := 'Àà±ð';
inoutgrid.Cells[1, 0] := 'µ¥ºÅ';
inoutgrid.Cells[2, 0] := 'µ¥Î»';
inoutgrid.Cells[3, 0] := '²Ù×÷Ô±';
inoutgrid.Cells[4, 0] := 'ÂëÑó';
inoutgrid.Cells[5, 0] := 'ʵÑó';
inoutgrid.Cells[6, 0] := 'ÊýÁ¿';
inoutgrid.Cells[7, 0] := 'ÕÛ¿Û';
inoutgrid.ColWidths[8] := -1;
formmain.out_excel := CreateOleObject('Excel.Application');//生成excel对象
end;
procedure TFsettle.Button7Click(Sender: TObject);
var
queryout: tquery;
temp_i, temp_j: integer;
begin
formmain.out_workbooks := formmain.out_excel.workbooks.add(-4167);//+各工作簿
queryout := tquery.Create(self);
queryout.DatabaseName := 'book';
queryout.SQL.Add('SELECT Sl, Bookname, Xlh, Dj, sell."date", Num, Zk, Ghdw');
queryout.SQL.Add('FROM Sell');
queryout.SQL.Add('WHERE (Bookname <> "&AElig;&Uacute;&iquest;&macr;")');
queryout.SQL.Add(' AND (Bookname <> "&Ograve;&ocirc;&Iuml;&ntilde;")');
queryout.SQL.Add(' AND (Bookname <> "&Iacute;&aelig;&frac34;&szlig;")');
queryout.SQL.Add(' AND (Bookname <> "&Icirc;&Auml;&raquo;&macr;&Oacute;&Atilde;&AElig;·")');
queryout.SQL.Add(' AND (sell."date" =:_date)');
queryout.parambyname('_date').asdate := date;
queryout.Open;
if (queryout.Fields[1].AsString <> '') then
begin
with formmain do
begin
out_worksheets := out_excel.worksheets.add;
out_worksheets.name := 'UPsell';
out_worksheets.Cells.Select;
out_excel.Selection.NumberFormatLocal := '@';
try
gauge1.MaxValue := queryout.RecordCount;
gauge1.ForeColor := clRed;
for temp_i := 1 to queryout.RecordCount do
begin
out_worksheets.cells[temp_i, 1] := queryout.Fields[0].AsString;
out_worksheets.cells[temp_i, 2] := queryout.Fields[1].AsString;
out_worksheets.cells[temp_i, 3] := queryout.Fields[2].AsString;
out_worksheets.cells[temp_i, 4] := queryout.Fields[3].AsString;
out_worksheets.cells[temp_i, 5] := dbbook.TablecompanyDeptId.Value;
out_worksheets.cells[temp_i, 6] := queryout.Fields[4].AsString;
out_worksheets.cells[temp_i, 7] := queryout.Fields[5].AsString;
out_worksheets.cells[temp_i, 8] := queryout.Fields[6].AsString;
out_worksheets.cells[temp_i, 9] := queryout.Fields[7].AsString;
out_worksheets.cells[temp_i, 10] := '&Iuml;ú&Ecirc;&Ucirc;&iquest;&Iacute;&raquo;§';
queryout.Next;
gauge1.Progress := temp_i;
end;
except
end;
end;
end;
//====================================================
queryout.sql.Clear;
queryout.SQL.Add('SELECT Buybook.Sl, Buybook.Bookname, Buybook.xlh, Buybook.Dj, buybook.rkrq, buybook.rkd, buybook.rkzk, buybook.ghdw');
queryout.SQL.Add('From buybook');
queryout.SQL.Add('inner join buybookinfo');
queryout.SQL.Add(' on (buybook.rkd = buybookinfo.rkd)');
queryout.SQL.Add('where buybook.rkrq =:_date');
queryout.SQL.Add(' and (buybookinfo.posted = true)');
queryout.ParamByName('_date').asdate := date;
queryout.Close;
queryout.Open;
if (queryout.Fields[1].AsString <> '') then
begin
with formmain do
begin
out_worksheets := out_excel.worksheets.add;
out_worksheets.name := 'UPbuybook';
out_worksheets.Cells.Select;
out_excel.Selection.NumberFormatLocal := '@';
try
gauge1.MaxValue := queryout.RecordCount;
gauge1.ForeColor := clYellow;
for temp_i := 1 to queryout.RecordCount do
begin
out_worksheets.cells[temp_i, 1] := queryout.Fields[0].AsString;
out_worksheets.cells[temp_i, 2] := queryout.Fields[1].AsString;
out_worksheets.cells[temp_i, 3] := queryout.Fields[2].AsString;
out_worksheets.cells[temp_i, 4] := queryout.Fields[3].AsString;
out_worksheets.cells[temp_i, 5] := dbbook.TablecompanyDeptId.Value;
out_worksheets.cells[temp_i, 6] := queryout.Fields[4].AsString;
out_worksheets.cells[temp_i, 7] := queryout.Fields[5].AsString;
out_worksheets.cells[temp_i, 8] := queryout.Fields[6].AsString;
out_worksheets.cells[temp_i, 9] := queryout.Fields[7].AsString;
out_worksheets.cells[temp_i, 10] := queryout.Fields[7].Asstring;
queryout.Next;
gauge1.Progress := temp_i;
end;
except
end;
end;
end;
//====================================================
queryout.SQL.Clear;
queryout.SQL.Add('SELECT Move.Sl, Move.NAME, Move.Xlh, Move.Dj, Move."Date", Move.Ykd, Move.Bag_num, Move.Zk, Move.Ghdw, Move.Place');
queryout.SQL.Add('FROM Move');
queryout.SQL.Add('INNER JOIN Move_bag');
queryout.SQL.Add(' ON (Move.Bag_num = Move_bag.Bag_num)');
queryout.SQL.Add('WHERE (Move."Date" =:_date)');
queryout.SQL.Add(' AND (Move_bag.Posted = TRUE)');
queryout.parambyname('_date').asdate := date;
queryout.Close;
queryout.Open;
if (queryout.Fields[1].AsString <> '') then
begin
with formmain do
begin
out_worksheets := out_excel.worksheets.add;
out_worksheets.name := 'UPmove';
out_worksheets.Cells.Select;
out_excel.Selection.NumberFormatLocal := '@';
try
gauge1.MaxValue := queryout.RecordCount;
gauge1.ForeColor := clYellow;
for temp_i := 1 to queryout.RecordCount do
begin
out_worksheets.cells[temp_i, 1] := queryout.Fields[0].AsString;
out_worksheets.cells[temp_i, 2] := queryout.Fields[1].AsString;
out_worksheets.cells[temp_i, 3] := queryout.Fields[2].AsString;
out_worksheets.cells[temp_i, 4] := queryout.Fields[3].AsString;
out_worksheets.cells[temp_i, 5] := dbbook.TablecompanyDeptId.Value;
out_worksheets.cells[temp_i, 6] := queryout.Fields[4].AsString;
out_worksheets.cells[temp_i, 7] := queryout.Fields[5].AsString + '_' + queryout.Fields[6].AsString;
out_worksheets.cells[temp_i, 8] := queryout.Fields[7].AsString;
out_worksheets.cells[temp_i, 9] := queryout.Fields[8].AsString;
out_worksheets.cells[temp_i, 10] := queryout.Fields[9].Asstring;
queryout.Next;
gauge1.Progress := temp_i;
end;
except
end;
end;
end;
//======================================================
queryout.SQL.Clear;
queryout.SQL.Add('SELECT Bigsell.Sl , Bigsell.Bookname, Bigsell.Xlh, Bigsell.Price, bigsell."date", Bigsell.number, Bigsell.pfzk, bigsell.ghdw,Bigsell.pfdw');
queryout.SQL.Add('FROM Bigsell');
queryout.SQL.Add(' INNER JOIN Bigsellinfo');
queryout.SQL.Add(' ON (Bigsell.Number = Bigsellinfo.Number)');
queryout.SQL.Add('WHERE (Bigsell."Date" =:_date)');
queryout.SQL.Add(' AND (Bigsellinfo.Posted = TRUE)');
queryout.ParamByName('_date').AsDate := date;
queryout.Close;
queryout.Open;
if (queryout.Fields[1].AsString <> '') then
begin
with formmain do
begin
out_worksheets := out_excel.worksheets.add;
out_worksheets.name := 'UPbigsell';
out_worksheets.Cells.Select;
out_excel.Selection.NumberFormatLocal := '@';
try
gauge1.MaxValue := queryout.RecordCount;
gauge1.ForeColor := clGreen;
for temp_i := 1 to queryout.RecordCount do
begin
out_worksheets.cells[temp_i, 1] := queryout.Fields[0].AsString;
out_worksheets.cells[temp_i, 2] := queryout.Fields[1].AsString;
out_worksheets.cells[temp_i, 3] := queryout.Fields[2].AsString;
out_worksheets.cells[temp_i, 4] := queryout.Fields[3].AsString;
out_worksheets.cells[temp_i, 5] := dbbook.TablecompanyDeptId.Value;
out_worksheets.cells[temp_i, 6] := queryout.Fields[4].AsString;
out_worksheets.cells[temp_i, 7] := queryout.Fields[5].AsString;
out_worksheets.cells[temp_i, 8] := queryout.Fields[6].AsString;
out_worksheets.cells[temp_i, 9] := queryout.Fields[7].AsString;
out_worksheets.cells[temp_i, 10] := queryout.Fields[8].AsString;
queryout.Next;
gauge1.Progress := temp_i;
end;
except
end;
end;
end;
//=========================================================================
queryout.SQL.Clear;
queryout.SQL.Add('SELECT ID, Name, Sex, Age, Birth, Address, Phone, Start_date, Last_time_use, Total_TMoney, Total_FMoney, Sum_number, Remark, Shopping_num, Day_changeF, Day_changeT, Deptid, Uactive');
queryout.SQL.Add('FROM "User.db"');
queryout.SQL.Add('WHERE (Day_changeF > 0) OR (Uactive = False)');
queryout.Close;
queryout.Open;
if not queryout.IsEmpty then
begin
formmain.out_worksheets := formmain.out_excel.worksheets.add;
formmain.out_worksheets.name := 'UPdata';
formmain.out_worksheets.Cells.Select;
formmain.out_excel.Selection.NumberFormatLocal := '@';
try
gauge1.MaxValue := queryout.RecordCount;
gauge1.ForeColor := clWhite;
for temp_i := 1 to queryout.RecordCount do
begin
for temp_j := 1 to queryout.FieldCount do
if (queryout.Fields[temp_j - 1].asstring <> '') then
formmain.out_worksheets.cells[temp_i, temp_j] := queryout.Fields[temp_j - 1].asstring
else
formmain.out_worksheets.cells[temp_i, temp_j] := '&Icirc;&acute;&Igrave;&icirc;&ETH;&acute;';
queryout.Next;
gauge1.Progress := temp_i;
end;
except
end;
end;
formmain.out_excel.DisplayAlerts := False;
formmain.out_excel.worksheets['Sheet1'].Delete;
formmain.out_excel.DisplayAlerts := True;
formmain.out_workbooks.saveas(Filename := dbbook.Tablecompanydept.Value + '&frac12;á&Otilde;&Euml;' + datetostr(date));
formmain.out_workbooks.close;//关闭。。。。。。。。。。。
formmain.out_excel.quit;///退出
queryout.Free;
showmessage(dbbook.Tablecompanydept.Value + '&frac12;á&Otilde;&Euml;' + datetostr(date) + ' &Ograve;&Ntilde;&frac34;&shy;&micro;&frac14;&sup3;&ouml;&micro;&frac12;&Icirc;&Ograve;&micro;&Auml;&Icirc;&Auml;&micro;&micro;&Auml;&iquest;&Acirc;&frac14;');
gauge1.Progress := 0;
end;
procedure TFsettle.FormClose(Sender: TObject; var Action: TCloseAction);
begin
formmain.out_excel :=Unassigned;///释放
querylist.Free;
Action := cafree;
end;
另外,这个问题,都是在98下面出的,我自己调试的时候,都能够杀掉,我实在想不到这样有什么异常。