Delphi - guardar datos y continuar en el mismo form en delphi

   
Vista:

guardar datos y continuar en el mismo form en delphi

Publicado por Francisco Aparicio (2 intervenciones) el 30/04/2015 20:17:25
como puedo hacer para que al guardar los datos capturados pueda regresar al mismo form para seguir con la captura de otro producto, este es mi codigo. Gracias

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
unit Pcaptent;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Data.DB, Bde.DBTables,
  Vcl.ComCtrls, Vcl.StdCtrls, Vcl.Mask, Vcl.DBCtrls, Vcl.Buttons, Vcl.DBLookup,
  Vcl.Grids, Vcl.DBGrids;
type
  TForm7 = class(TForm)
    DataSource1: TDataSource;
    Query1: TQuery;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Query1Fec_ent: TDateField;
    Query1Pedido: TFloatField;
    Query1Proveedor: TStringField;
    Query1Cveart: TFloatField;
    Query1Descripc: TStringField;
    Query1Marca: TStringField;
    Query1Presen: TStringField;
    Query1Precuni: TFloatField;
    Query1Importe: TFloatField;
    Query1Observ: TMemoField;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    DateTimePicker1: TDateTimePicker;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Query2: TQuery;
    DataSource2: TDataSource;
    Query1Cantreq: TStringField;
    Query1Fcha_emision: TDateField;
    Query1Fcha_entrega: TDateField;
    Query1Folio: TStringField;
    DBGrid1: TDBGrid;
    Query3: TQuery;
    DataSource3: TDataSource;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    ComboBox1: TComboBox;
    Edit6: TEdit;
 
    procedure FormShow(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Edit1Exit(Sender: TObject);
    procedure Edit2Exit(Sender: TObject);
    procedure Edit4Exit(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { Public declarations }
  public
    { Public declarations }
  end;
 
var
  Form7: TForm7;
 
implementation
 
{$R *.dfm}
 
uses SegCapt;
 
procedure TForm7.BitBtn1Click(Sender: TObject);
var
   Exant,Entra,Salida,Dev,Existe,temp1,temp2,temp3:Real;
   dd,mm,aaaa:Word;
   ffecha,fpedido,fproveedor : string;
   buttonSelected : Integer;
begin
   DecodeDate(DateTimePicker1.Date,aaaa,mm,dd);
 
   Query1.Active;
   Query1.Insert;
   Query1.FieldByName('Fec_ent').AsDateTime := DateTimePicker1.Date;
   Query1.FieldByName('Pedido').AsString := Edit4.Text;
   Query1.FieldByName('Proveedor').AsString := Edit5.Text;
   Query1.FieldByName('Cveart').AsString := Edit6.Text;
   Query1.FieldByName('Descripc').AsString := ComboBox1.Text;
   Query1.FieldByName('Marca').AsString := Edit8.Text;
   Query1.FieldByName('Presen').AsString := Edit9.Text;
   Query1.FieldByName('Precuni').AsString := Edit2.Text;
   Query1.FieldByName('Cantreq').AsString := Edit1.Text;
   Query1.FieldByName('Importe').AsString := Edit3.Text;
////   Form7.Query1.FieldByName('Observ').AsString :=  Memo1.Text;
   Query1.Post;
 
   Query3.Active;
   Query3.Locate('Clave',Edit6.Text,[]);
   Query3.Edit;
   Exant := Query3['Existencia'];
   Entra := StrToFloat(Query3['Entradas']) + StrToFloat(Edit1.Text);
   Existe:= StrToFloat(Query3['Existencia']) + StrToFloat(Edit1.Text);
 
   Query3.FieldByName('Exanterior').AsString := FloatToStr(Exant);
   Query3.FieldByName('Entradas').AsString := FloatToStr(Entra);
   Query3.FieldByName('Existencia').AsString := FloatToStr(Existe);
   Query3.Post;
 
   Query2.Active := True;
   Query2.Insert;
   Query2.FieldByName('Fecha').AsDateTime := DateTimePicker1.Date;
   Query2.FieldByName('Clave').AsString := Edit6.Text;
   Query2.FieldByName('Producto').AsString := ComboBox1.Text;
   Query2.FieldByName('Unidad').AsString := Edit9.Text;
   Query2.FieldByName('Precio').AsString := Edit2.Text;
   Query2.FieldByName('Tipo_mov').AsString := 'EA';
   Query2.FieldByName('Entrada').AsString  := Edit1.Text;
   Query2.FieldByName('Salida').Value  := 0;
   Query2.FieldByName('Existencia').AsString  := FloatToStr(Existe);
   Query2.FieldByName('Importe').AsString  := Edit3.Text;
   Query2.FieldByName('Concepto').AsString := 'ENTRADA DE ALMACEN';
   Query2.Post;
 
   Query2.Close;
   Query1.Refresh;
 
   buttonSelected := MessageDlg('Desea Continuar con la Misma Factura',mtCustom,[mbOK,mbCancel], 0);
   if buttonSelected = mrOK    then
      begin
         temp1:=0;
         Edit6.Text := ' ';
         Edit8.Text := ' ';
         Edit9.Text := ' ';
         Edit1.Text:=FormatFloat('##0.000',temp1);
         Edit2.Text := ' ';
         Form7.ComboBox1.SetFocus;
         ShowMessage('Continuar Factura');
      end;
   if buttonSelected = mrCancel then
      begin
         ShowMessage('Factura Terminada');
         Query3.Close;
         Query2.Close;
         Query1.Close;
         Form7.Close;
      end;
end;
 
procedure TForm7.BitBtn2Click(Sender: TObject);
begin
   Query1.Close;
   Query2.Close;
   Query3.Close;
   Form7.Close;
end;
 
procedure TForm7.ComboBox1Change(Sender: TObject);
var
   Codigo: Integer;
   Temp2 : Real;
begin
   if ComboBox1.ItemIndex > -1 then
    Codigo:= Integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
    Edit6.Text := IntToStr(Codigo);
 
    If (Query3.Locate('Clave',Edit6.Text,[])) Then
       Begin
          Edit8.Text := Query3.FieldByName('Marca').AsString;
          Edit9.Text := Query3.FieldByName('Unidad').AsString;
          Temp2 := Query3['Precio'];
          Edit2.Text := Format('%0:2f',[temp2]);
          Edit1.SetFocus();
       end;
end;
 
procedure TForm7.Edit1Exit(Sender: TObject);
var
   temp1,temp2,temp3: Real;
begin
   if Edit1.Text = ' ' then
      begin
         temp1:=0;
      end
   else
      begin
         temp1 := StrToFloat(Edit1.Text);
      end;
   Edit1.Text:=FormatFloat('##0.000',temp1);
 
   temp2 := StrToFloat(Edit2.Text);
   Edit2.Text := Format('%0:2f',[temp2]);
 
   temp3 := StrToFloat(Edit2.Text) * StrToFloat(Edit1.Text);
   Edit3.Text := Format('%0:2f',[temp3]);
end;
 
procedure TForm7.Edit2Exit(Sender: TObject);
var
   temp1,temp2,temp4: Real;
begin
   temp1 := StrToFloat(Edit1.Text);
   Edit1.Text:=FormatFloat('##0.000',temp1);
 
   temp2 := StrToFloat(Edit2.Text);
   Edit2.Text := Format('%0:2f',[temp2]);
 
   temp4 := StrToFloat(Edit2.Text) * StrToFloat(Edit1.Text);
   Edit3.Text := Format('%0:2f',[temp4]);
end;
 
procedure TForm7.Edit4Exit(Sender: TObject);
begin
   Query1.Active := True;
   Query1.Edit;
   Query1.Filtered := False;
   Query1.Filter := 'Pedido=' + Edit4.Text;
   Query1.Filtered := True;
end;
 
procedure TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   Query1.Close;
   Query2.Close;
   Query3.Close;
   Form7.Close;
   Action := cafree;
end;
 
procedure TForm7.FormCreate(Sender: TObject);
begin
   while not Query3.Eof do
   begin
     ComboBox1.Items.AddObject(Query3.FieldByName('Producto').AsString, TObject(Query3.FieldByName('Clave').AsInteger));
     Query3.Next;
   end;
   ComboBox1.Text := 'Elija su opción';
end;
 
procedure TForm7.FormShow(Sender: TObject);
var
   temp1,temp2,temp3:Real;
begin
   temp1:=0;
 
   Form7.Query1.Active := False;
   Form7.DateTimePicker1.Date := now;
 
   Edit1.Text := FloatToStr(Temp1);
   Edit1.Text:=FormatFloat('##0.000',temp1);
 
   temp2 := Query3['Precio'];
   Edit2.Text := Format('%0:2f',[temp2]);
 
   temp3 := temp1;
   Edit3.Text := Format('%0:2f',[temp3]);
end;
 
end.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder