unit u_op_Air_Goods; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid, ADODB, bsSkinCtrls, cxCalc, cxNavigator, cxDBNavigator, cxLabel, cxContainer, cxTextEdit, cxMaskEdit, cxDropDownEdit; type Tfrm_op_Air_Goods = class(TForm) cxGrid1DBTableView1: TcxGridDBTableView; cxGrid1Level1: TcxGridLevel; cxGrid1: TcxGrid; t_op_Air_Goods1: TDataSource; t_op_Air_Goods: TADOQuery; cxGrid1DBTableView1DBColumn1: TcxGridDBColumn; cxGrid1DBTableView1DBColumn2: TcxGridDBColumn; cxGrid1DBTableView1DBColumn3: TcxGridDBColumn; cxGrid1DBTableView1DBColumn4: TcxGridDBColumn; bsSkinButton1: TbsSkinButton; cxDBNavigator1: TcxDBNavigator; cxCalcEdit1: TcxCalcEdit; cxLabel1: TcxLabel; procedure FormShow(Sender: TObject); procedure t_op_Air_GoodsAfterInsert(DataSet: TDataSet); procedure bsSkinButton1Click(Sender: TObject); procedure t_op_Air_GoodsBeforePost(DataSet: TDataSet); private { Private declarations } public { Public declarations } end; var frm_op_Air_Goods: Tfrm_op_Air_Goods; implementation uses u_main,my_sys_function; {$R *.dfm} procedure Tfrm_op_Air_Goods.FormShow(Sender: TObject); begin t_op_Air_Goods.Open; end; procedure Tfrm_op_Air_Goods.t_op_Air_GoodsAfterInsert(DataSet: TDataSet); begin t_op_Air_Goods['编号']:=t_op_Air_Goods.DataSource.DataSet['编号']; end; procedure Tfrm_op_Air_Goods.bsSkinButton1Click(Sender: TObject); var aAdoQuery:TAdoQuery; d_Weight,cmb:Double; qty:Integer; begin // d_Weight:=0; cmb:=0; qty:=0; if cxCalcEdit1.Value=0 then begin ShowMessage('计算基数不能0'); exit; end; aAdoQuery:=CreateAdoQuery; with aAdoQuery do try Close;SQL.Clear; sql.Add('Select * from t_op_Air_Goods'); sql.Add('where 编号=:编号'); Parameters.ParamByName('编号').Value:=t_op_Air_Goods.DataSource.DataSet['编号']; Open;First; while not Eof do begin qty:=qty+FieldByName('件数').AsInteger; cmb:=cmb+FieldByName('长').Value*FieldByName('宽').Value*FieldByName('高').Value*FieldByName('件数').Value; d_Weight:=d_Weight+FieldByName('长').Value*FieldByName('宽').Value*FieldByName('高').Value*FieldByName('件数').Value; Next; end; t_op_Air_Goods.DataSource.DataSet.Edit; t_op_Air_Goods.DataSource.DataSet['件数']:=qty; t_op_Air_Goods.DataSource.DataSet['重量']:=d_Weight/cxCalcEdit1.Value; t_op_Air_Goods.DataSource.DataSet['计价重量']:=d_Weight/cxCalcEdit1.Value; t_op_Air_Goods.DataSource.DataSet['尺码']:=cmb/1000000; t_op_Air_Goods.DataSource.DataSet.Post; { Close;SQL.Clear; sql.Add('update t_op_Aire set 重量=:重量'); sql.Add('where 编号=:编号'); Parameters.ParamByName('编号').Value:=t_op_Air_Goods.DataSource.DataSet['编号']; Parameters.ParamByName('重量').Value:=d_Weight/cxCalcEdit1.Value; ExecSQL; } finally Free; end; Close; end; procedure Tfrm_op_Air_Goods.t_op_Air_GoodsBeforePost(DataSet: TDataSet); begin if DataSet.FieldByName('长').Value=0 then begin showmessage('长不能为0,不能保存!'); abort; end; if DataSet.FieldByName('宽').Value=0 then begin showmessage('宽不能为0,不能保存!'); abort; end; if DataSet.FieldByName('高').Value=0 then begin showmessage('高不能为0,不能保存!'); abort; end; if DataSet.FieldByName('件数').Value=0 then begin showmessage('件数不能为0,不能保存!'); abort; end; end; end.