unit U_YarnElasticityOrderInPut; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo, cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit, StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxDropDownEdit, StrUtils, cxPC, ShellAPI, cxCalendar, Math, Menus, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges; type TfrmShuttleLSSCInPut = class(TForm) ToolBar1: TToolBar; TBSave: TToolButton; TBClose: TToolButton; ScrollBox1: TScrollBox; ADOQueryTemp: TADOQuery; ADOQueryCmd: TADOQuery; CDS_Sanjiao: TClientDataSet; DS_Sanjiao: TDataSource; Label4: TLabel; BatchNo: TEdit; Label6: TLabel; Y_Spec: TEdit; FtyName: TBtnEditC; Label8: TLabel; Label9: TLabel; Label3: TLabel; YarnTubeWeight: TEdit; Label11: TLabel; PaperBoxWeight: TEdit; Label1: TLabel; BoxCount: TEdit; Label5: TLabel; YarnRackCount: TEdit; Label2: TLabel; Tv1: TcxGridDBTableView; cxGrid1Level1: TcxGridLevel; cxGrid1: TcxGrid; Tv1Column1: TcxGridDBColumn; cxGrid2: TcxGrid; Tv2: TcxGridDBTableView; cxGridDBColumn1: TcxGridDBColumn; cxGridLevel1: TcxGridLevel; DataSource1: TDataSource; ClientDataSet1: TClientDataSet; DataSource2: TDataSource; ClientDataSet2: TClientDataSet; Label7: TLabel; Y_Color: TEdit; Y_Name: TBtnEditC; YE_Name: TBtnEditC; Label10: TLabel; OrdQty: TEdit; procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBSaveClick(Sender: TObject); procedure FtyNameBtnUpClick(Sender: TObject); procedure FtyNameBtnDnClick(Sender: TObject); procedure Y_NameBtnDnClick(Sender: TObject); procedure Y_NameBtnUpClick(Sender: TObject); procedure YE_NameBtnDnClick(Sender: TObject); procedure YE_NameBtnUpClick(Sender: TObject); private FXS, Fint: Integer; procedure InitData(); function SaveData(): Boolean; { Private declarations } public PState, FCopyInt, fpd: Integer; FMainId, FConNo, PType, FSubId: string; { Public declarations } end; var frmShuttleLSSCInPut: TfrmShuttleLSSCInPut; newh: hwnd; implementation uses U_DataLink, U_ZDYHelp, U_RTFun, U_CompanySel, U_YarnInfoSel; {$R *.dfm} procedure TfrmShuttleLSSCInPut.TBCloseClick(Sender: TObject); begin ModalResult := 1; end; procedure TfrmShuttleLSSCInPut.InitData(); var PBNO, PBFlag, fsj: string; i: Integer; begin if fpd <> 1 then begin /////////////////刷新产品信息///////////////////////// with ADOQueryTemp do begin Close; SQL.Clear; sql.Add(' select A.* from YE_Plan_Main A'); if PState = 1 then begin sql.Add(' where A.MainId=' + Quotedstr(Trim(FMainId))); end; if PState = 0 then begin sql.Add(' where 1<>1 '); end; Open; end; SCSHData(ADOQueryTemp, ScrollBox1, 0); Y_Name.TxtCode := ADOQueryTemp.FieldByName('Y_Code').AsString; YE_Name.TxtCode := ADOQueryTemp.FieldByName('YE_Code').AsString; FtyName.TxtCode := ADOQueryTemp.FieldByName('FtyNo').AsString; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from YE_Plan_Rule where Mainid=''' + Trim(FMainId) + ''' and RType=''颜色'' '); Open; end; SCreateCDS(ADOQueryTemp, ClientDataSet1); SInitCDSData(ADOQueryTemp, ClientDataSet1); fsj := 'select Name=ColorName,Code=ColorName from YE_YarnTube_Color '; SInitCxGridComboBoxBySql(ADOQueryTemp, Tv1Column1, fsj, 1, true, ''); with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from YE_Plan_Rule where Mainid=''' + Trim(FMainId) + ''' and RType=''机台'' '); Open; end; SCreateCDS(ADOQueryTemp, ClientDataSet2); SInitCDSData(ADOQueryTemp, ClientDataSet2); if ClientDataSet1.IsEmpty then begin for i := 1 to 10 do begin with ClientDataSet1 do begin Append; Post; end; end; end; if ClientDataSet2.IsEmpty then begin for i := 1 to 10 do begin with ClientDataSet2 do begin Append; Post; end; end; end; if PState = 0 then begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select Top 1 * from YE_Plan_Main order by FillTime desc'); Open; end; YarnTubeWeight.Text := Trim(ADOQueryTemp.fieldbyname('YarnTubeWeight').AsString); PaperBoxWeight.Text := Trim(ADOQueryTemp.fieldbyname('PaperBoxWeight').AsString); BoxCount.Text := Trim(ADOQueryTemp.fieldbyname('BoxCount').AsString); YarnRackCount.Text := Trim(ADOQueryTemp.fieldbyname('YarnRackCount').AsString); end; if FCopyInt = 1 then begin FMainId := ''; end; end; procedure TfrmShuttleLSSCInPut.FormShow(Sender: TObject); begin InitData(); end; function TfrmShuttleLSSCInPut.SaveData(): Boolean; var maxno: string; begin try ADOQueryCmd.Connection.BeginTrans; if Trim(FMainId) = '' then begin if GetLSNo(ADOQueryCmd, maxno, 'YEM', 'YE_Plan_Main', 4, 1) = False then begin ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('生成流水号异常!', '提示', 0); exit; end; end else begin maxno := Trim(FMainId); end; with ADOQueryCmd do begin Close; sql.Clear; SQL.Add('select * from YE_Plan_Main where MainId=''' + Trim(maxno) + ''''); Open; end; with ADOQueryCmd do begin if Trim(FMainId) = '' then begin Append; FieldByName('Filler').Value := Trim(DName); FieldByName('FillTime').Value := SGetServerDateTime(ADOQueryTemp); FieldByName('Status').Value := '0'; FieldByName('Y_Code').Value := Y_Name.TxtCode; FieldByName('YE_Code').Value := YE_Name.TxtCode; FieldByName('FtyNo').Value := FtyName.TxtCode; end else begin Edit; FieldByName('Editer').Value := Trim(DName); FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTemp); end; FieldByName('MainId').Value := Trim(maxno); FieldByName('OrderNo').Value := Trim(maxno); RTSetsavedata(ADOQueryCmd, 'YE_Plan_Main', ScrollBox1, 0); Post; end; // with ADOQueryCmd do // begin // Close; // sql.Clear; // sql.Add('select * from YE_Plan_Main where isnull(BatchNo,'''')=''' + Trim(BatchNo.Text) + ''''); // Open; // end; // if ADOQueryCmd.RecordCount > 1 then // begin // ADOQueryCmd.Connection.RollbackTrans; // Application.MessageBox('批号不能重复!', '提示', 0); // Result := False; // Exit; // end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('delete YE_Plan_Rule where MainId=''' + Trim(maxno) + ''''); ExecSQL; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from YE_Plan_Rule where 1=2'); Open; end; ClientDataSet1.DisableControls; with ClientDataSet1 do begin First; while not Eof do begin with ADOQueryCmd do begin ADOQueryCmd.Append; ADOQueryCmd.FieldByName('MainId').Value := Trim(maxno); ADOQueryCmd.FieldByName('RType').Value := Trim('颜色'); ADOQueryCmd.FieldByName('RName').Value := Trim(ClientDataSet1.fieldbyname('RName').AsString); ADOQueryCmd.Post; end; Next; end; end; ClientDataSet1.EnableControls; ClientDataSet2.DisableControls; with ClientDataSet2 do begin First; while not Eof do begin with ADOQueryCmd do begin ADOQueryCmd.Append; ADOQueryCmd.FieldByName('MainId').Value := Trim(maxno); ADOQueryCmd.FieldByName('RType').Value := Trim('机台'); ADOQueryCmd.FieldByName('RName').Value := Trim(ClientDataSet2.fieldbyname('RName').AsString); ADOQueryCmd.Post; end; Next; end; end; ClientDataSet2.EnableControls; ADOQueryCmd.Connection.CommitTrans; FMainId := Trim(maxno); Result := True; except Result := False; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('保存失败!', '提示', 0); end; end; procedure TfrmShuttleLSSCInPut.TBSaveClick(Sender: TObject); var FReal: Double; maxConNo: string; begin FtyName.SetFocus; if trim(FtyName.Text) = '' then begin Application.MessageBox('厂家不能为空!', '提示', 0); Exit; end; if StrTofloatDef(OrdQty.Text, 0) = 0 then begin Application.MessageBox('计划数量不能为空!', '提示', 0); Exit; end; if SaveData() then begin Application.MessageBox('保存成功!', '提示', 0); ModalResult := 1; end; end; procedure TfrmShuttleLSSCInPut.FtyNameBtnUpClick(Sender: TObject); begin try frmCompanySel := TfrmCompanySel.Create(Application); with frmCompanySel do begin FCoType := '供应商'; if ShowModal = 1 then begin FtyName.TxtCode := Trim(CDS_1.fieldbyname('CoCode').AsString); FtyName.Text := Trim(CDS_1.fieldbyname('CoName').AsString); end; end; finally frmCompanySel.Free; end; end; procedure TfrmShuttleLSSCInPut.FtyNameBtnDnClick(Sender: TObject); begin FtyName.Text := ''; end; procedure TfrmShuttleLSSCInPut.Y_NameBtnDnClick(Sender: TObject); begin Self.Y_Name.TxtCode := ''; Self.Y_Name.Text := ''; Self.Y_Spec.Text := ''; Self.Y_Color.Text := ''; end; procedure TfrmShuttleLSSCInPut.Y_NameBtnUpClick(Sender: TObject); begin try frmYarnInfoSel := TfrmYarnInfoSel.Create(Application); with frmYarnInfoSel do begin if ShowModal = 1 then begin Self.Y_Name.TxtCode := Trim(CDS_1.fieldbyname('Y_Code').AsString); Self.Y_Name.Text := Trim(CDS_1.fieldbyname('Y_Name').AsString); Self.Y_Spec.Text := Trim(CDS_1.fieldbyname('Y_Spec').AsString); Self.Y_Color.Text := Trim(CDS_1.fieldbyname('Y_Color').AsString); end; end; finally frmYarnInfoSel.Free; end; end; procedure TfrmShuttleLSSCInPut.YE_NameBtnDnClick(Sender: TObject); begin YE_Name.TxtCode := ''; YE_Name.Text := ''; end; procedure TfrmShuttleLSSCInPut.YE_NameBtnUpClick(Sender: TObject); begin try frmYarnInfoSel := TfrmYarnInfoSel.Create(Application); with frmYarnInfoSel do begin if ShowModal = 1 then begin YE_Name.TxtCode := Trim(CDS_1.fieldbyname('Y_Code').AsString); YE_Name.Text := Trim(CDS_1.fieldbyname('Y_Name').AsString); end; end; finally frmYarnInfoSel.Free; end; end; end.