unit U_YEInspEdit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxTextEdit, DBClient, ADODB, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxButtonEdit, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges; type TfrmYEInspEdit = class(TForm) ToolBar1: TToolBar; ToolButton2: TToolButton; TBClose: TToolButton; Panel1: TPanel; Label1: TLabel; CIID: TEdit; ADOTmp: TADOQuery; ADOQueryMain: TADOQuery; ADOCmd: TADOQuery; DataSource1: TDataSource; Order_MJ: TClientDataSet; ToolButton1: TToolButton; ToolButton3: TToolButton; Label2: TLabel; GrossWeight: TEdit; Label4: TLabel; Label6: TLabel; Meter: TEdit; RadioGroup1: TRadioGroup; Ma: TLabel; Label7: TLabel; MJQty1: TEdit; Label5: TLabel; Label10: TLabel; Label12: TLabel; Label14: TLabel; NetWeight: TEdit; PieceNo: TEdit; Label15: TLabel; Label11: TLabel; Yardage: TEdit; ToolButton4: TToolButton; cxGrid1: TcxGrid; TV1: TcxGridDBTableView; cxGridDBColumn2: TcxGridDBColumn; cxGridDBColumn3: TcxGridDBColumn; cxGridDBColumn4: TcxGridDBColumn; cxGridDBColumn5: TcxGridDBColumn; cxGridDBColumn6: TcxGridDBColumn; cxGridDBColumn7: TcxGridDBColumn; cxGridDBColumn8: TcxGridDBColumn; cxGridDBColumn9: TcxGridDBColumn; cxGridLevel3: TcxGridLevel; TV1Column1: TcxGridDBColumn; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormDestroy(Sender: TObject); procedure tv2CDWZPropertiesEditValueChanged(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure ToolButton3Click(Sender: TObject); procedure ToolButton2Click(Sender: TObject); procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure ToolButton4Click(Sender: TObject); procedure cxGridDBColumn3PropertiesEditValueChanged(Sender: TObject); procedure TV1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); private { Private declarations } function SaveData(): Boolean; procedure GetJYXK(FJYIP: string); public { Public declarations } end; var frmYEInspEdit: TfrmYEInspEdit; implementation uses U_RTFun, U_ZDYHelp, U_DataLink; {$R *.dfm} procedure TfrmYEInspEdit.GetJYXK(FJYIP: string); begin with ADOTmp do begin Close; sql.Clear; SQL.Add('select A.* from Dye_Cloth_Inspect A '); sql.Add(' where A.CIID=''' + Trim(FJYIP) + ''''); Open; end; if ADOTmp.IsEmpty then begin CIID.Text := ''; Label2.Caption := ''; Label2.Visible := False; Application.MessageBox('条码错误!', '提示', 0); Exit; end; PieceNo.Text := Trim(ADOTmp.fieldbyname('PieceNo').AsString); GrossWeight.Text := Trim(ADOTmp.fieldbyname('GrossWeight').AsString); NetWeight.Text := Trim(ADOTmp.fieldbyname('NetWeight').AsString); Meter.Text := Trim(ADOTmp.fieldbyname('Meter').AsString); Yardage.Text := Trim(ADOTmp.fieldbyname('Yardage').AsString); if Trim(Trim(ADOTmp.fieldbyname('Grade').AsString)) = '正品' then begin RadioGroup1.ItemIndex := 0 end else if Trim(Trim(ADOTmp.fieldbyname('Grade').AsString)) = '次品' then begin RadioGroup1.ItemIndex := 1; end; with ADOTmp do begin Close; sql.Clear; SQL.Add('select * from Dye_Cloth_Inspect_Flaw A where A.CIID=''' + Trim(CIID.Text) + ''''); Open; end; Label2.Caption := Trim(CIID.Text); Label2.Visible := True; CIID.Text := ''; SCreateCDS(ADOTmp, Order_MJ); SInitCDSData(ADOTmp, Order_MJ); end; procedure TfrmYEInspEdit.cxGridDBColumn3PropertiesEditValueChanged(Sender: TObject); var mvalue, CIFbeg, CIFEnd: string; FFReal: Double; begin mvalue := TcxTextEdit(Sender).EditingText; with Order_MJ do begin Edit; FieldByName('CIFEnd').Value := mvalue; Post; end; CIFbeg := Trim(Order_MJ.fieldbyname('CIFbeg').AsString); CIFEnd := Trim(Order_MJ.fieldbyname('CIFEnd').AsString); if (Trim(CIFbeg) <> '') and (Trim(CIFEnd) <> '') then begin if TryStrToFloat(CIFbeg, FFReal) and TryStrToFloat(CIFbeg, FFReal) then begin if StrToFloat(CIFEnd) < StrToFloat(CIFbeg) then begin Application.MessageBox('终止位置小于起始位置!', '提示', 0); Exit; end; with Order_MJ do begin Edit; FieldByName('CDQty').Value := StrToFloat(CIFEnd) - StrToFloat(CIFbeg); Post; end; end else begin Application.MessageBox('非法数字!', '提示', 0); Exit; end; end; end; procedure TfrmYEInspEdit.FormClose(Sender: TObject; var Action: TCloseAction); begin Action := caFree; end; procedure TfrmYEInspEdit.FormDestroy(Sender: TObject); begin frmYEInspEdit := nil; end; procedure TfrmYEInspEdit.tv2CDWZPropertiesEditValueChanged(Sender: TObject); var mvalue, CIFbeg, CIFEnd: string; FFReal: Double; begin mvalue := TcxTextEdit(Sender).EditingText; with Order_MJ do begin Edit; FieldByName('CIFbeg').Value := mvalue; Post; end; CIFbeg := Trim(Order_MJ.fieldbyname('CIFbeg').AsString); CIFEnd := Trim(Order_MJ.fieldbyname('CIFEnd').AsString); if (Trim(CIFbeg) <> '') and (Trim(CIFEnd) <> '') then begin if TryStrToFloat(CIFbeg, FFReal) and TryStrToFloat(CIFbeg, FFReal) then begin if StrToFloat(CIFEnd) < StrToFloat(CIFbeg) then begin Application.MessageBox('终止位置小于起始位置!', '提示', 0); Exit; end; with Order_MJ do begin Edit; FieldByName('CIFQty').Value := StrToFloat(CIFEnd) - StrToFloat(CIFbeg); Post; end; end else begin Application.MessageBox('非法数字!', '提示', 0); Exit; end; end; end; procedure TfrmYEInspEdit.ToolButton1Click(Sender: TObject); begin if Trim(Label2.Caption) = '' then Exit; Order_MJ.Append; Order_MJ.Post; end; procedure TfrmYEInspEdit.ToolButton3Click(Sender: TObject); begin if Trim(Label2.Caption) = '' then Exit; if Order_MJ.IsEmpty then Exit; if Trim(Order_MJ.fieldbyname('CIFID').AsString) <> '' then begin if Application.MessageBox('确定要删除数据吗?', '提示', 32 + 4) <> IDYES then Exit; with ADOCmd do begin Close; sql.Clear; sql.Add('delete Dye_Cloth_Inspect_Flaw where CIFID=''' + Trim(Order_MJ.fieldbyname('CIFID').AsString) + ''''); ExecSQL; end; end; Order_MJ.Delete; end; procedure TfrmYEInspEdit.ToolButton4Click(Sender: TObject); begin WriteCxGrid(trim(Self.Caption), Tv1, '印染检验管理'); end; procedure TfrmYEInspEdit.TV1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'WFBCD'; flagname := '疵点'; if ShowModal = 1 then begin Self.Order_MJ.Edit; Self.Order_MJ.FieldByName('CIFName').value := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString); end; end; finally frmZDYHelp.Free; end; end; function TfrmYEInspEdit.SaveData(): Boolean; var maxno: string; FFreal: Double; begin try ADOCmd.Connection.BeginTrans; ///保存疵点表 with Order_MJ do begin First; while not Eof do begin if trim(Order_MJ.FieldByName('CIFName').AsString) = '' then raise Exception.Create(pchar('疵点名称不能为空!')); if Trim(Order_MJ.fieldbyname('CIFID').AsString) = '' then begin if GetLSNo(ADOTmp, maxno, 'JC', 'Dye_Cloth_Inspect_Flaw', 5, 1) = False then raise Exception.Create(pchar('取子流水号失败!')); end else begin maxno := Trim(Order_MJ.fieldbyname('CIFID').AsString); end; with ADOCmd do begin Close; SQL.Clear; sql.Add(' select * from Dye_Cloth_Inspect_Flaw '); sql.Add(' where CIFID=''' + Trim(maxno) + ''' '); Open; end; with ADOCmd do begin if Trim(Order_MJ.fieldbyname('CIFID').AsString) = '' then Append else Edit; FieldByName('CIID').Value := Trim(Label2.Caption); FieldByName('CIFID').Value := Trim(maxno); RTSetSaveDataCDS(ADOCmd, Tv1, Order_MJ, 'Dye_Cloth_Inspect_Flaw', 0); Post; end; Order_MJ.Edit; Order_MJ.FieldByName('CIFID').Value := Trim(maxno); Order_MJ.FieldByName('CIID').Value := Trim(Label2.Caption); Next; end; end; with ADOCmd do begin Close; sql.Clear; sql.Add(' UPdate Dye_Cloth_Inspect Set '); sql.Add(' PieceNo=''' + Trim(PieceNo.Text) + ''' '); sql.Add(',GrossWeight=' + FloatToStr(Strtofloatdef(GrossWeight.Text, 0))); sql.Add(',NetWeight=' + FloatToStr(Strtofloatdef(NetWeight.Text, 0))); sql.Add(',Meter=' + FloatToStr(Strtofloatdef(Meter.Text, 0))); sql.Add(',Yardage=' + FloatToStr(Strtofloatdef(Yardage.Text, 0))); if RadioGroup1.ItemIndex = 0 then begin sql.Add(',Grade=''正品'' '); end else if RadioGroup1.ItemIndex = 1 then begin sql.Add(',Grade=''次品'' '); end; sql.Add(' where CIID=''' + Trim(Label2.Caption) + ''''); ExecSQL; end; ////////////////// 更新卷号疵点信息 ////////////////// with ADOCmd do begin Close; sql.Clear; sql.Add('exec P_Dye_Insp_Up @CIID=''' + Trim(Label2.Caption) + ''''); sql.Add(',@InspType=' + QuotedStr('单卷修改')); execsql; end; ////////////////// 更新卷号疵点信息 ////////////////// /// ////////////////// 出入库及库存 ////////////////// with ADOCmd do begin Close; sql.Clear; sql.Add('exec P_Dye_Insp_In_Stk @CIID=''' + Trim(Label2.Caption) + ''''); execsql; end; ////////////////// 出入库及库存 ////////////////// /// ////////////////// 更新进度 ////////////////// with ADOCmd do begin Close; sql.Clear; sql.Add('insert into Dye_Need_Up(UOperation,UType,UDataId) values(''检验'',''检验编辑'',' + quotedstr(Trim(Label2.Caption)) + ') '); execsql; end; ////////////////// 更新进度 ////////////////// /// ADOCmd.Connection.CommitTrans; Result := True; except Result := False; ADOCmd.Connection.RollbackTrans; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); end; end; procedure TfrmYEInspEdit.ToolButton2Click(Sender: TObject); begin if Trim(Label2.Caption) = '' then Exit; if SaveData() then begin Application.MessageBox('保存成功!', '提示', 0); Exit; end; end; procedure TfrmYEInspEdit.TBCloseClick(Sender: TObject); begin Close; end; procedure TfrmYEInspEdit.FormShow(Sender: TObject); begin ReadCxGrid(trim(Self.Caption), Tv1, '印染检验管理'); if CIID.Text <> '' then begin GetJYXK(CIID.Text); end; end; end.