unit ExpVouItemsu; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGridEh, ExtCtrls, Buttons, StdCtrls, DB, kbmMemTable, SlDateu, DBTables; type TfrmExpVou = class(TForm) Panel1: TPanel; Bevel1: TBevel; SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; Panel2: TPanel; SpeedButton3: TSpeedButton; SpeedButton4: TSpeedButton; BitBtn1: TBitBtn; memTblVouitems: TkbmMemTable; dsrVouitems: TDataSource; SlDate: TSlDate; DataSource1: TDataSource; Query1: TQuery; CheckBox1: TCheckBox; DBGridCarriageSum: TDBGridEh; SaveDialog1: TSaveDialog; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure FormCreate(Sender: TObject); procedure SlDateDateChanged(Sender: TObject; FromDate, ToDate: TDateTime; sFromDate, sToDate: String; MonthDay: TMonthDay); procedure SpeedButton3Click(Sender: TObject); procedure SpeedButton4Click(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure CheckBox1Click(Sender: TObject); private procedure GetVouitems; procedure CreateMemTbl; procedure SetCarriageSum(Sel : Boolean); { Private declarations } public { Public declarations } end; var frmExpVou: TfrmExpVou; implementation uses NetConstu, DSMainfrmu; {$R *.dfm} procedure TfrmExpVou.CreateMemTbl; begin memTblVouitems.Close; memTblVouitems.Fields.Clear; with memTblVouitems.FieldDefs do begin Clear; Add('Selected', ftsmallint, 0, false); Add('VOUDATE', ftDate, 0, false); Add('AccMonth', ftsmallint, 0, false); Add('VKNO', ftsmallint, 0, false); Add('ORDNO', ftinteger, 0, false); Add('LineNO', ftinteger, 0, false); Add('ExPlan', ftString, 60, false); Add('ACCID',ftString,16,false); Add('ACCNAME',ftString,30,false); Add('MBLNO',ftString,20,false); Add('CorpID',ftString,20,false); Add('FCY',ftString,2,false); Add('FCYEXRATE', ftFloat, 0, false); Add('DC',ftString,2,false); Add('FCYDR', ftFloat, 0, false); Add('FCYCR', ftFloat, 0, false); Add('AMTDR', ftFloat, 0, false); Add('AMTCR', ftFloat, 0, false); Add('PREPARED', ftString,10, false); memTblVouitems.CreateTable; end; end; procedure TfrmExpVou.SetCarriageSum(Sel : Boolean); var BK : TBookmark; NoteNoTag : SmallInt; begin if not memTblVouitems.Active then exit; if Sel then NoteNoTag:=1 else NoteNoTag:=0; BK:=memTblVouitems.getbookmark; with memTblVouitems do try DisableControls; First; while not Eof do begin if FieldByName('Selected').AsInteger<>NoteNoTag then begin Edit; FieldByName('Selected').AsInteger:=NoteNoTag; Post; end; Next; end; finally GotoBookmark(BK); FreeBookmark(BK); EnableControls; end; end; procedure TfrmExpVou.FormClose(Sender: TObject; var Action: TCloseAction); begin action:=cafree; end; procedure TfrmExpVou.FormShow(Sender: TObject); begin CreateMemTbl; slDate.Today:=LoginInfo.LoginDate; slDate.BeginChange; end; procedure TfrmExpVou.GetVouitems; var aQuery:TQuery; s:String; begin if SlDate.DateKind<>dkAll then begin S:=Format(' and (v.VouDate>=''%s'' and v.VouDate<=''%s'')',[SlDate.FromDateAsString,SlDate.ToDateAsString]); end else S:=''; aQuery:=CreateQuery; try with aQuery do begin Close;SQL.Clear; SQL.Add('Select 0 selected,V.* from V_Vouitems V where 1=1 '); if not CheckBox1.Checked then SQL.Add(' AND V.STATUS=0'); if S<>'' then SQL.Add(S); Open; end; memTblVouitems.LoadFromDataSet(aQuery,[]); finally freeAndNil(aQuery); end; end; procedure TfrmExpVou.FormCreate(Sender: TObject); begin // CreateMemTbl; end; procedure TfrmExpVou.SlDateDateChanged(Sender: TObject; FromDate, ToDate: TDateTime; sFromDate, sToDate: String; MonthDay: TMonthDay); begin GetVouitems; end; procedure TfrmExpVou.SpeedButton3Click(Sender: TObject); begin SetCarriageSum(true); end; procedure TfrmExpVou.SpeedButton4Click(Sender: TObject); begin SetCarriageSum(false); end; procedure TfrmExpVou.SpeedButton2Click(Sender: TObject); var aQuery:TQuery; SL:TStrings; S:String; begin if not memtblVouitems.Active then exit; // DatabaseVouitems.Connected:=true; // tblVouitems.Active:=true; memtblVouitems.First; aQuery:=CreateQuery; aQuery.SQL.Add('Update Vouitems set Status=1 where ordno=:OrdNo and lineNo=:lineNo'); sl:=TStringList.Create; sl.Add('ÌîÖÆƾ֤,V800'); try while not memtblVouitems.Eof do begin if memtblVouitems.FieldByName('Selected').AsInteger=1 then begin S:=''; S:=S+FormatDateTime('YY-MM-DD',memTblVouitems.FieldByName('VouDate').AsDateTime)+','; if memTblVouitems.FieldByName('VKNO').AsInteger=1 then S:=S+'ת,'; S:=S+memTblVouitems.fieldByName('ORDNO').AsString+','; S:=S+'1'+','; S:=S+memTblVouitems.fieldByName('Explan').AsString+','; S:=S+memTblVouitems.fieldByName('ACCID').AsString+','; S:=S+memTblVouitems.fieldByName('AMTDR').AsString+','; S:=S+memTblVouitems.fieldByName('AMTCR').AsString+',,'; S:=S+FloattoStr(memTblVouitems.fieldByName('FCYDR').AsFloat+memTblVouitems.fieldByName('FCYCR').AsFloat)+','; S:=S+memTblVouitems.fieldByName('FCYExRate').AsString+',,,,,,,'; S:=S+memTblVouitems.fieldByName('CORPID').AsString+',,'; SL.Add(S); end; memTblVouitems.Next; end; if sl.Count<>1 then begin if SaveDialog1.Execute then begin sl.SaveToFile(SaveDialog1.FileName); end; end; finally FreeAndNil(aQuery); FreeAndNil(Sl); end; end; procedure TfrmExpVou.SpeedButton1Click(Sender: TObject); begin GetVouitems; end; procedure TfrmExpVou.CheckBox1Click(Sender: TObject); begin GetVouitems; end; end.