Экспертная система Delphi.int.ru

Сообщество программистов
Общение, помощь, обмен опытом

Логин:
Пароль:
Регистрация | Забыли пароль?

Delphi.int.ru Expert

Другие разделы портала

Переход к вопросу:

#   

Статистика за сегодня:  


Лучшие эксперты

Подробнее »



Вопрос # 4 635

/ вопрос открыт /

Здравствуйте, уважаемые эксперты!
Подскажите пожалуйста. У меня есть две формы. На первой форме при нажатии кнопки должны данные из таблицы переноситься как бы в буфер и потом после того как на второй форме все заполнится и при нажатии кнопки Добавить акцию открывается третья форма где уже в таблице будет видно все данные из 1 и 2 формы . Как это сделать подскажите пожалуйста?

К вопросу прикреплён файл. Загрузить » (срок хранения: 60 дней с момента отправки вопроса)

Приложение:
  1.  
  2. unit Unit2;
  3.  
  4. interface
  5.  
  6. uses
  7. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  8. Dialogs, Grids, DBGrids, DBXpress, FMTBcd, DBClient, SimpleDS, DB,
  9. SqlExpr, ExtCtrls, DBCtrls, StdCtrls;
  10.  
  11. type
  12. TForm2 = class(TForm)
  13. SQLConnection2: TSQLConnection;
  14. Q2: TSQLQuery;
  15. StringGrid2: TStringGrid;
  16. ComboBox1: TComboBox;
  17. Label1: TLabel;
  18. Label3: TLabel;
  19. ComboBox3: TComboBox;
  20. Label4: TLabel;
  21. Edit1: TEdit;
  22. Button1: TButton;
  23. RadioGroup1: TRadioGroup;
  24. Button2: TButton;
  25. procedure FormActivate(Sender: TObject);
  26. procedure Button1Click(Sender: TObject);
  27. procedure FormCreate(Sender: TObject);
  28. procedure Button2Click(Sender: TObject);
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. private
  36. { Private declarations }
  37. public
  38. { Public declarations }
  39. end;
  40.  
  41. var
  42. Form2: TForm2;
  43.  
  44. implementation
  45.  
  46. uses Unit4;
  47.  
  48. {$R *.dfm}
  49.  
  50.  
  51. procedure TForm2.FormActivate(Sender: TObject);
  52. var q:integer;
  53.  
  54. begin
  55. try
  56. Q2.Open;
  57. except
  58. on e:exception do showmessage(e.Message)
  59. end;
  60. stringgrid2.Visible:=false;
  61. stringgrid2.RowCount:=2;
  62. q:=1;
  63.  
  64. while not Q2.Eof do
  65. begin
  66. StringGrid2.Cells[0,0]:= 'Ôàìèëèÿ';
  67. StringGrid2.Cells[1,0]:= 'Èìÿ';
  68. StringGrid2.Cells[2,0]:= 'Îò÷åñòâî';
  69. StringGrid2.Cells[3,0]:= 'Äîìàøíèé òåëåôîí';
  70. StringGrid2.Cells[4,0]:= 'Ðàáî÷èé òåëåôîí';
  71. StringGrid2.Cells[5,0]:= 'Ìîáèëüíûé òåëåôîí';
  72. StringGrid2.Cells[6,0]:= 'Ïî÷òà';
  73. StringGrid2.Cells[7,0]:= 'Äàòà ðîæäåíèÿ';
  74. StringGrid2.Cells[8,0]:= 'Ñåìåéíîå ïîëîæåíèå';
  75. StringGrid2.Cells[9,0]:= 'Ñôåðà äåÿòåëüíîñòè';
  76. StringGrid2.Cells[10,0]:= 'Ïîë';
  77.  
  78. stringgrid2.Cells[0,q]:=Q2.fields[0].AsString;
  79. stringgrid2.Cells[1,q]:=Q2.fields[1].AsString;
  80. stringgrid2.Cells[2,q]:=Q2.fields[2].AsString;
  81. stringgrid2.Cells[3,q]:=Q2.fields[3].AsString;
  82. stringgrid2.Cells[4,q]:=Q2.fields[4].AsString;
  83. stringgrid2.Cells[5,q]:=Q2.fields[5].AsString;
  84. stringgrid2.Cells[6,q]:=Q2.fields[6].AsString;
  85. stringgrid2.Cells[7,q]:=Q2.fields[7].AsString;
  86. stringgrid2.Cells[8,q]:=Q2.fields[8].AsString;
  87. stringgrid2.Cells[9,q]:=Q2.fields[9].AsString;
  88. stringgrid2.Cells[10,q]:=Q2.fields[10].AsString;
  89.  
  90.  
  91. Q2.Next;
  92. inc(q);
  93. stringgrid2.RowCount:=q+2;
  94. end;
  95. stringgrid2.Visible:=true;
  96. if Q2.Active then Q2.Close;
  97.  
  98. combobox1.Clear;
  99. Form2.Q2.SQL.Text:='select DISTINCT family_status from owner';
  100. Form2.Q2.Open;
  101. if Form2.Q2.Active then
  102. begin
  103. Form2.Q2.First;
  104. while not q2.Eof do
  105. BEGIN
  106. Form2.ComboBox1.Items.Add(Form2.Q2.FieldByName('family_status').AsString);
  107. Form2.Q2.Next;
  108. END;
  109. q2.Close;
  110. END;
  111.  
  112.  
  113. combobox3.Clear;
  114. Form2.Q2.SQL.Text:='select DISTINCT typeorg from owner';
  115. Form2.Q2.Open;
  116. if Form2.Q2.Active then
  117. begin
  118. Form2.Q2.First;
  119. while not q2.Eof do
  120. BEGIN
  121. Form2.ComboBox3.Items.Add(Form2.Q2.FieldByName('typeorg').AsString);
  122. Form2.Q2.Next;
  123. END;
  124. q2.Close;
  125. end;
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. end;
  133.  
  134.  
  135.  
  136.  
  137.  
  138. procedure TForm2.Button1Click(Sender: TObject);
  139. begin
  140. q2.SQL.Text:='select * from owner where DateDiff(year,date_of_birth,GetDate())='+Edit1.Text+' and family_status ='+char(39)+Combobox1.Text+char(39)+' and TypeOrg = '+char(39)+Combobox3.Text+char(39)+' and sex='+inttostr(RadioGroup1.Itemindex);
  141. q2.Open;
  142. form2.FormActivate(Sender);
  143. q2.Close;
  144. end;
  145.  
  146.  
  147.  
  148. procedure TForm2.FormCreate(Sender: TObject);
  149. var
  150. x, y, w: integer;
  151. s: string;
  152. MaxWidth: integer;
  153. begin
  154. with StringGrid2 do
  155. ClientHeight := DefaultRowHeight * RowCount + 5;
  156. randomize;
  157. with StringGrid2 do begin
  158. for y := 0 to RowCount - 1 do
  159. for x := 0 to ColCount - 1 do begin
  160. s := '';
  161. for w := 0 to random(20) do
  162. s := s + chr(ord('a') + random(26));
  163. Cells[x,y] := s;
  164. end;
  165.  
  166. Canvas.Font := Font;
  167. for x := 0 to ColCount - 1 do begin
  168. MaxWidth := 0;
  169. for y := 0 to RowCount - 1 do begin
  170. w := Canvas.TextWidth(Cells[x,y]);
  171. if w > MaxWidth then MaxWidth := w;
  172. end;
  173. ColWidths[x] := MaxWidth + 5;
  174.  
  175. end;
  176. end;
  177. end;
  178.  
  179.  
  180.  
  181. procedure TForm2.Button2Click(Sender: TObject);
  182. begin
  183. Q2.SQL.Text:='use bonus_dbTest go declare @counts int select @counts = count(distinct field_id) from act_new where active=1 if @counts<4 then begin insert into act_new() values() alter table dbo.spiski add act_4 bit not null constraint df_spiski_act_4 default 0';
  184. Form4:= TForm4.Create(Application);
  185. Form4.Caption:= '&#205;&#238;&#226;&#224;&#255; &#224;&#234;&#246;&#232;&#255;';
  186. Form4.Enabled:=true;
  187. form4.Show;
  188. Form2.Close;
  189. Form4.Button2.Enabled:=true;
  190. q2.Close;
  191. end;
  192. end.
  193.  
  194.  
  195.  
  196. unit Unit4;
  197.  
  198. interface
  199.  
  200. uses
  201. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  202. Dialogs, ComCtrls, StdCtrls, DBXpress, FMTBcd, DB, SqlExpr;
  203.  
  204. type
  205. TForm4 = class(TForm)
  206. Label1: TLabel;
  207. Label2: TLabel;
  208. DateTimePicker1: TDateTimePicker;
  209. Button1: TButton;
  210. Label3: TLabel;
  211. DateTimePicker2: TDateTimePicker;
  212. Label4: TLabel;
  213. Button2: TButton;
  214. Edit3: TEdit;
  215. Label5: TLabel;
  216. SQLConnection1: TSQLConnection;
  217. Q6: TSQLQuery;
  218. Memo1: TMemo;
  219. Memo2: TMemo;
  220. procedure Button1Click(Sender: TObject);
  221. procedure Edit3KeyPress(Sender: TObject; var Key: Char);
  222. procedure Button2Click(Sender: TObject);
  223. procedure DateTimePicker1Change(Sender: TObject);
  224.  
  225. private
  226. { Private declarations }
  227. public
  228. { Public declarations }
  229. end;
  230.  
  231. var
  232. Form4: TForm4;
  233.  
  234. implementation
  235.  
  236. uses Unit2, Unit5, Unit1;
  237.  
  238. {$R *.dfm}
  239.  
  240. procedure TForm4.Button1Click(Sender: TObject);
  241. begin
  242. Form2:= TForm2.Create(Application);
  243. Form2.Caption:= '&#194;&#251;&#225;&#238;&#240; &#243;&#247;&#224;&#241;&#242;&#237;&#232;&#234;&#224;';
  244. form2.Show;
  245. form4.visible:=false;
  246. end;
  247.  
  248. procedure TForm4.Edit3KeyPress(Sender: TObject; var Key: Char);
  249. begin
  250. if (key='.')or(key=',')then key:=decimalseparator;
  251. if not (key in['0'..'9',decimalseparator,#8,#13]) then
  252. begin
  253. key:=#0;
  254. beep;
  255. end;
  256. end;
  257.  
  258.  
  259. procedure TForm4.Button2Click(Sender: TObject);
  260. begin
  261. q6.SQL.Text:='insert into act_new (name, description, date_begin, date_end, amount_bonus) values (:name, :description, :date_begin, :date_end, :amount_bonus)';
  262. q6.Params[0].AsString := Memo2.Text;
  263. q6.Params[1].AsString := Memo1.Text;
  264. q6.Params[2].AsDate := DateTimePicker1.Date;
  265. q6.Params[3].AsDate := DateTimePicker2.Date;
  266. q6.Params[4].AsCurrency := StrToCurr(Edit3.Text);
  267. q6.Prepared := true;
  268. q6.ExecSQL;
  269. end;
  270.  
  271. procedure TForm4.DateTimePicker1Change(Sender: TObject);
  272. begin
  273. q6.SQL.Text:='select date_begin, date_end from act_new convert(datetime, '+char(39)+'2010-10-01 16:20:21.710'+char(39)+' 121) -- yyyy-mm-dd hh:mm:ss.mmm';
  274. end;
  275.  
  276. end.
  277.  
  278.  
  279.  
  280. unit Unit1;
  281.  
  282. interface
  283.  
  284. uses
  285. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  286. Dialogs, FMTBcd, DBXpress, DB, SqlExpr, Grids, DBGrids, StdCtrls,
  287. ExtCtrls, DBCtrls, DBClient, Provider, SimpleDS, Menus;
  288.  
  289. type
  290. TForm1 = class(TForm)
  291. SQLConnection1: TSQLConnection;
  292. Q1: TSQLQuery;
  293. Button1: TButton;
  294. StringGrid1: TStringGrid;
  295. procedure Button1Click(Sender: TObject);
  296. procedure FormActivate(Sender: TObject);
  297. procedure StringGrid1DblClick(Sender: TObject);
  298. procedure Button2Click(Sender: TObject);
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305. private
  306. { Private declarations }
  307. public
  308. { Public declarations }
  309. end;
  310.  
  311. var
  312. Form1: TForm1;
  313.  
  314. implementation
  315.  
  316. uses Unit2, Unit3, Unit4;
  317.  
  318. {$R *.dfm}
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329. procedure TForm1.Button1Click(Sender: TObject);
  330. begin
  331. Form4:= TForm4.Create(Application);
  332. Form4.Caption:= '&#205;&#238;&#226;&#224;&#255; &#224;&#234;&#246;&#232;&#255;';
  333. form4.Show;
  334.  
  335. end;
  336.  
  337. procedure TForm1.FormActivate(Sender: TObject);
  338. var i:integer;
  339. begin
  340. try
  341. Q1.Open;
  342. except
  343. on e: exception do showmessage(e.Message);
  344. end;
  345. stringgrid1.Visible:=false;
  346. i:=1;
  347.  
  348.  
  349.  
  350.  
  351. while not Q1.Eof do
  352. begin
  353.  
  354.  
  355. StringGrid1.Cells[0,0]:= '&#192;&#234;&#246;&#232;&#255;';
  356. StringGrid1.Cells[1,0]:= '&#206;&#239;&#232;&#241;&#224;&#237;&#232;&#229;';
  357. StringGrid1.Cells[2,0]:= '&#196;&#224;&#242;&#224; &#237;&#224;&#247;&#224;&#235;&#224;';
  358. StringGrid1.Cells[3,0]:= '&#196;&#224;&#242;&#224; &#238;&#234;&#238;&#237;&#247;&#224;&#237;&#232;&#255;';
  359. StringGrid1.Cells[4,0]:= '&#202;&#238;&#235;&#232;&#247;&#229;&#241;&#242;&#226;&#238; &#225;&#238;&#237;&#243;&#241;&#238;&#226;';
  360. StringGrid1.Cells[5,0]:= '&#192;&#234;&#242;&#232;&#226;&#237;&#251;&#229;';
  361. StringGrid1.Cells[6,0]:= '&#207;&#240;&#224;&#231;&#228;&#237;&#232;&#247;&#237;&#251;&#229;';
  362.  
  363.  
  364.  
  365. stringgrid1.Cells[0,i]:=q1.Fields[0].AsString;
  366. stringgrid1.Cells[1,i]:=q1.Fields[1].AsString;
  367. stringgrid1.Cells[2,i]:=q1.Fields[2].AsString;
  368. stringgrid1.Cells[3,i]:=q1.Fields[3].AsString;
  369. stringgrid1.Cells[4,i]:=q1.Fields[4].AsString;
  370. stringgrid1.Cells[5,i]:=q1.Fields[5].AsString;
  371. stringgrid1.Cells[6,i]:=q1.Fields[6].AsString;
  372.  
  373. q1.Next;
  374. inc(i);
  375. stringgrid1.RowCount:=i+1;
  376. end;
  377. stringgrid1.Visible:=true;
  378. if q1.Active then q1.Close;
  379.  
  380. end;
  381.  
  382.  
  383.  
  384.  
  385.  
  386. procedure TForm1.StringGrid1DblClick(Sender: TObject);
  387. begin
  388. Form3:= TForm3.Create(Application);
  389. Form3.Caption:= '&#205;&#238;&#226;&#224;&#255; &#224;&#234;&#246;&#232;&#255;';
  390. form3.Show;
  391. end;
  392.  
  393. procedure TForm1.Button2Click(Sender: TObject);
  394. begin
  395. Form2:= TForm2.Create(Application);
  396. Form2.Caption:= '&#194;&#251;&#225;&#238;&#240;';
  397. form2.Show;
  398. end;
  399. end.
  400.  
  401.  
  402.  


slai Вопрос ожидает решения (принимаются ответы, доступен мини-форум)

Вопрос задал: slai (статус: Посетитель)
Вопрос отправлен: 4 октября 2010, 06:50
Состояние вопроса: открыт, ответов: 0.


Мини-форум вопроса

Мини-форум пуст.

Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.

Версия движка: 2.6+ (26.01.2011)
Текущее время: 22 февраля 2025, 11:43
Выполнено за 0.02 сек.