putproducet.pas
上传用户:bjkrmsxy
上传日期:2010-01-31
资源大小:9004k
文件大小:6k
源码类别:

百货/超市行业

开发平台:

Delphi

  1. unit putproducet;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, DBCtrls, ExtCtrls, Grids, DBGrids, DB, ADODB;
  6. type
  7.   TPut_Form = class(TForm)
  8.     Panel1: TPanel;
  9.     Panel2: TPanel;
  10.     Label1: TLabel;
  11.     Label2: TLabel;
  12.     DBGrid1: TDBGrid;
  13.     GroupBox1: TGroupBox;
  14.     Label8: TLabel;
  15.     Label9: TLabel;
  16.     Edit6: TEdit;
  17.     Edit7: TEdit;
  18.     Button3: TButton;
  19.     GroupBox2: TGroupBox;
  20.     Button4: TButton;
  21.     Button5: TButton;
  22.     Button6: TButton;
  23.     Panel3: TPanel;
  24.     Label3: TLabel;
  25.     Label4: TLabel;
  26.     Label5: TLabel;
  27.     Label6: TLabel;
  28.     Label7: TLabel;
  29.     Edit1: TEdit;
  30.     Edit2: TEdit;
  31.     Edit3: TEdit;
  32.     Edit4: TEdit;
  33.     Edit5: TEdit;
  34.     Button1: TButton;
  35.     Button2: TButton;
  36.     DataSource1: TDataSource;
  37.     ADOTable1: TADOTable;
  38.     Label10: TLabel;
  39.     DataSource2: TDataSource;
  40.     Button7: TButton;
  41.     Button8: TButton;
  42.     Button9: TButton;
  43.     dbcombobox2: TComboBox;
  44.     dbcombobox1: TComboBox;
  45.     ADOQuery1: TADOQuery;
  46.     procedure Button4Click(Sender: TObject);
  47.     procedure Button1Click(Sender: TObject);
  48.     procedure FormActivate(Sender: TObject);
  49.     procedure DBComboBox2Change(Sender: TObject);
  50.     procedure DBComboBox1Change(Sender: TObject);
  51.     procedure Button8Click(Sender: TObject);
  52.     procedure Button2Click(Sender: TObject);
  53.     procedure Button6Click(Sender: TObject);
  54.     procedure Button5Click(Sender: TObject);
  55.     procedure Button7Click(Sender: TObject);
  56.     procedure Button9Click(Sender: TObject);
  57.     procedure Button3Click(Sender: TObject);
  58.   private
  59.     { Private declarations }
  60.   public
  61.     { Public declarations }
  62.   end;
  63. var
  64.   Put_Form: TPut_Form;
  65. implementation
  66. uses datamodule;
  67. {$R *.dfm}
  68. procedure TPut_Form.Button4Click(Sender: TObject);
  69. begin
  70. dbgrid1.readonly:=true;
  71. Panel3.visible:=true;
  72. end;
  73. procedure TPut_Form.Button1Click(Sender: TObject);
  74. begin
  75.   if ((edit1.text='') or (edit2.text='') or (edit3.text='') or (edit4.text='') or (edit5.text='')) then
  76.   showmessage('信息或数据不完整,添加失败!!')
  77.   else
  78.   begin
  79.   try
  80.     with adoquery1 do
  81.       begin
  82.         insert;
  83.         fields.fields[1].asinteger:=strtoint(edit1.text);
  84.         fields.fields[2].asstring:=edit2.text;
  85.         fields.fields[3].AsVariant:=strtofloat(edit5.text);
  86.         fields.fields[4].asstring:=edit4.text;
  87.         fields.fields[5].asinteger:=strtoint(DBComboBox2.text);
  88.         fields.fields[6].asinteger:=strtoint(edit3.text);
  89.         fields.fields[7].AsDateTime:=date;
  90.         fields.fields[8].asinteger:=0;
  91.         post;
  92.       end;
  93.     Panel3.visible:=false;
  94.   except on exception do
  95.      begin
  96.        showmessage('商品已存在或者是数据类型不合适,请修改后再提交');
  97.        adoquery1.cancel;
  98.      end;
  99.   end;
  100.  end;
  101. end;
  102. procedure TPut_Form.FormActivate(Sender: TObject);
  103. begin
  104.     with adotable1 do
  105.       begin
  106.          tablename:='produce_type_t';
  107.          if not active then
  108.          active:=true;
  109.          first;
  110.           dbcombobox2.Items.Clear;
  111.          dbcombobox1.Items.Clear;
  112.       end;
  113.          while not adotable1.Eof do
  114.            begin
  115.            dbcombobox2.Items.add(adotable1.Fields.fields[0].asstring);
  116.            dbcombobox1.Items.add(adotable1.Fields.fields[1].asstring);
  117.            adotable1.next;
  118.            end;
  119.     dbcombobox2.ItemIndex:=0;
  120.     dbcombobox1.ItemIndex:=0;
  121. end;
  122. procedure TPut_Form.DBComboBox2Change(Sender: TObject);
  123. var
  124. sqls:string;
  125. begin
  126.    dbcombobox1.ItemIndex:=dbcombobox2.ItemIndex;
  127.    if not panel2.enabled then
  128.    panel2.enabled:=true;
  129.    begin
  130.     with adoquery1 do
  131.       begin
  132.       close;
  133.       sql.clear;
  134.       sqls:='select * from produce_t where p_type=:i';
  135.       sql.add(sqls);
  136.       parameters.ParamValues['i']:=strtoint(dbcombobox2.text);
  137.       open;
  138.       end;
  139.     end;
  140. end;
  141. procedure TPut_Form.DBComboBox1Change(Sender: TObject);
  142. var
  143. sqls:string;
  144. begin
  145. dbcombobox2.ItemIndex:=dbcombobox1.ItemIndex;
  146.  if not panel2.enabled then
  147.  panel2.enabled:=true;
  148.    begin
  149.     with adoquery1 do
  150.       begin
  151.       close;
  152.       sql.clear;
  153.       sqls:='select * from produce_t where p_type=:i';
  154.       sql.add(sqls);
  155.       parameters.ParamValues['i']:=strtoint(dbcombobox2.text);
  156.       open;
  157.       end;
  158.     end;
  159. end;
  160. procedure TPut_Form.Button8Click(Sender: TObject);
  161. begin
  162. if adoquery1.active then
  163.    adoquery1.close;
  164. if adotable1.active then
  165.    adotable1.close;
  166. close;
  167. end;
  168. procedure TPut_Form.Button2Click(Sender: TObject);
  169. begin
  170. Panel3.visible:=false;
  171. end;
  172. procedure TPut_Form.Button6Click(Sender: TObject);
  173. begin
  174. dbgrid1.readonly:=true;
  175. adoquery1.delete;
  176. end;
  177. procedure TPut_Form.Button5Click(Sender: TObject);
  178. begin
  179. if dbgrid1.readonly then
  180. dbgrid1.readonly:=false;
  181. adoquery1.edit;
  182. end;
  183. procedure TPut_Form.Button7Click(Sender: TObject);
  184. begin
  185. adoquery1.prior;
  186. end;
  187. procedure TPut_Form.Button9Click(Sender: TObject);
  188. begin
  189. adoquery1.next;
  190. end;
  191. procedure TPut_Form.Button3Click(Sender: TObject);
  192. var
  193. sqls:string;
  194. Parami:tparameter;
  195. begin
  196.   if (edit7.Text='') and (edit6.Text='') then
  197.   showmessage('请输入要查询的关键字')
  198.   else
  199.   begin
  200.    with adoquery1 do
  201.    begin
  202.     close;
  203.     sql.Clear;
  204.     sqls:='select * from produce_t where 1=1';
  205.     if edit7.Text<>'' then
  206.       sqls:=sqls+'and p_name='''+edit7.Text+'''';
  207.     if edit6.Text<>'' then
  208.       begin
  209.        sqls:=sqls+'and p_id=:id';
  210.        Parameters.Clear;
  211.        Parami:=Parameters.ADDParameter; //创建参数1
  212.        Parami.Name:='id';
  213.        Parami.Value:=strtoint(edit6.text);
  214.       end;
  215.      sql.add(sqls);
  216.      Prepared;
  217.      open;
  218.     if  recordcount=0 then
  219.       showmessage('对不起,该商品不在');
  220.     end;
  221.   end;
  222. end;
  223. end.