unit U_YarnOutInput1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit, cxSpinEdit, StdCtrls, ExtCtrls, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, dxSkinsDefaultPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu, U_BaseInput, System.ImageList, Vcl.ImgList, dxSkinWXI, dxScrollbarAnnotations, cxContainer, dxCore, cxDateUtils, cxMaskEdit, dxSkinBasic, dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkroom, dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray, dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinOffice2016Colorful, dxSkinOffice2016Dark, dxSkinOffice2019Black, dxSkinOffice2019Colorful, dxSkinOffice2019DarkGray, dxSkinOffice2019White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringtime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinTheBezier, dxSkinValentine, dxSkinVisualStudio2013Blue, dxSkinVisualStudio2013Dark, dxSkinVisualStudio2013Light, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, cxPC; type TfrmYarnOutInput1 = class(TfrmBaseInput) ToolBar1: TToolBar; TBDel: TToolButton; TBSave: TToolButton; TBClose: TToolButton; DS_1: TDataSource; CDS_1: TClientDataSet; ADOQueryCmd: TADOQuery; ADO_1: TADOQuery; ADOQueryTemp: TADOQuery; GPM_1: TcxGridPopupMenu; ToolButton1: TToolButton; cxGrid1: TcxGrid; TV1: TcxGridDBTableView; cxGridDBColumn1: TcxGridDBColumn; cxGridDBColumn2: TcxGridDBColumn; cxGridDBColumn3: TcxGridDBColumn; cxGridDBColumn4: TcxGridDBColumn; cxGridDBColumn5: TcxGridDBColumn; cxGridDBColumn6: TcxGridDBColumn; cxGridDBColumn7: TcxGridDBColumn; cxGridDBColumn8: TcxGridDBColumn; cxGridDBColumn9: TcxGridDBColumn; cxGridDBColumn10: TcxGridDBColumn; cxGridDBColumn11: TcxGridDBColumn; cxGridDBColumn12: TcxGridDBColumn; cxGridDBColumn13: TcxGridDBColumn; cxGridDBColumn14: TcxGridDBColumn; cxGridDBColumn15: TcxGridDBColumn; cxGridDBColumn16: TcxGridDBColumn; cxGridDBColumn17: TcxGridDBColumn; cxGridDBColumn18: TcxGridDBColumn; cxGridDBColumn19: TcxGridDBColumn; cxGridDBColumn20: TcxGridDBColumn; cxGridLevel1: TcxGridLevel; Panel1: TPanel; cxGrid3: TcxGrid; TV3: TcxGridDBTableView; cxGrid3Level1: TcxGridLevel; ADO_2: TADOQuery; GPM_2: TcxGridPopupMenu; CDS_2: TClientDataSet; DS_2: TDataSource; DS_3: TDataSource; CDS_3: TClientDataSet; GPM_3: TcxGridPopupMenu; ADO_3: TADOQuery; Panel2: TPanel; cxGrid2: TcxGrid; TV2: TcxGridDBTableView; cxGridDBColumn21: TcxGridDBColumn; cxGridDBColumn23: TcxGridDBColumn; cxGridDBColumn24: TcxGridDBColumn; cxGridDBColumn25: TcxGridDBColumn; cxGridDBColumn26: TcxGridDBColumn; cxGridDBColumn27: TcxGridDBColumn; cxGridDBColumn28: TcxGridDBColumn; cxGridLevel2: TcxGridLevel; TV3Column1: TcxGridDBColumn; TV3Column2: TcxGridDBColumn; TV3Column3: TcxGridDBColumn; TV3Column4: TcxGridDBColumn; TV3Column5: TcxGridDBColumn; Panel3: TPanel; lbl1: TLabel; lbl2: TLabel; IOTime: TcxDateEdit; ToCoName: TcxButtonEdit; TV2Column1: TcxGridDBColumn; TV3Column6: TcxGridDBColumn; TV1Column1: TcxGridDBColumn; TV1Column2: TcxGridDBColumn; TV3Column7: TcxGridDBColumn; cxTabControl1: TcxTabControl; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBDelClick(Sender: TObject); procedure TBSaveClick(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure Tv1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure TV3CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); procedure ToCoNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure cxTabControl1Change(Sender: TObject); procedure TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean); private { Private declarations } procedure InitGrid1; procedure InitGrid2; procedure InitGrid3; function SaveCKData(): Boolean; public { Public declarations } FBCId, FStkName, FKHName: string; end; var frmYarnOutInput1: TfrmYarnOutInput1; implementation uses U_DataLink, U_RTFun, U_ZDYHelp, U_YarnStkSel, U_CompanySel; {$R *.dfm} procedure TfrmYarnOutInput1.InitGrid1; begin with ADO_1 do begin Close; sql.Clear; sql.Add(' select A.* '); sql.Add(' from BS_Yarn_IO A'); sql.Add(' where BYIOID=''' + Trim(FBCId) + ''''); Open; end; SCreateCDS(ADO_1, CDS_1); SInitCDSData(ADO_1, CDS_1); end; procedure TfrmYarnOutInput1.InitGrid2; begin with ADO_2 do begin Close; sql.Clear; sql.Add(' select * from ( '); sql.Add(' select A.WBCID,A.WB_Code,A.WB_Name,WB_YarnLen= ROUND((sum(A.WB_YarnLen*C.Y_Ratio)/10000),2),Y_Code,C.Y_Name,C.Y_Spec,Y_Color '); sql.Add(' ,YarnMeter=(select ROUND((sum(case when isnull(TestDenier,0)>0 then X.Qty*1000/(X.TestDenier/9000)/10000 else 0 end)),2) from BS_Yarn_IO X '); sql.Add(' where X.IOFlag=''出库'' and X.WBCID =A.WBCID and X.Y_Code =C.Y_Code )'); sql.Add(' from Tat_WB_Card A '); sql.Add(' inner join Tat_WB_Spec B on A.WB_Code=B.WB_Code '); sql.Add(' inner join Tat_WB_Formula C on B.WBSID=C.WBSID'); sql.Add(' group by A.WBCID,A.WB_Code,A.WB_Name,Y_Code,C.Y_Name,C.Y_Spec,Y_Color '); case cxTabControl1.TabIndex of 0: begin sql.Add(' ) AA where ISNULL(AA.YarnMeter,0)-AA.WB_YarnLen <-0.1 '); end; 1: begin sql.Add(' ) AA where ISNULL(AA.YarnMeter,0)-AA.WB_YarnLen >=-0.1 '); end; end; Open; end; SCreateCDS(ADO_2, CDS_2); SInitCDSData(ADO_2, CDS_2); end; procedure TfrmYarnOutInput1.InitGrid3; begin with ADO_3 do begin Close; sql.Clear; sql.Add(' select A.* '); sql.Add(',YarnMeter=ROUND((case when isnull(TestDenier,0)>0 then StkQty*1000/(TestDenier/9000)/10000 else 0 end),2) '); sql.Add(' from BS_Yarn_IO A where A.IOFlag=''入库'' and isnull(STkQty,0)>0 '); sql.Add(' and isnull(stkName,'''')=''' + Trim(FstkName) + ''''); sql.Add(' and Y_Code=''' + Trim(CDS_2.fieldbyname('Y_Code').AsString) + ''''); Open; end; SCreateCDS(ADO_3, CDS_3); SInitCDSData(ADO_3, CDS_3); end; procedure TfrmYarnOutInput1.cxTabControl1Change(Sender: TObject); begin InitGrid2; end; procedure TfrmYarnOutInput1.FormClose(Sender: TObject; var Action: TCloseAction); begin inherited; Action := caFree; end; function TfrmYarnOutInput1.SaveCKData(): Boolean; var MBYIOID, Maxno: string; begin try ADOQueryCmd.Connection.BeginTrans; CDS_1.DisableControls; with CDS_1 do begin First; while not eof do begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from BS_Yarn_IO where BYIOID=''' + Trim(CDS_1.fieldbyname('BYIOID').AsString) + ''''); Open; end; MBYIOID := Trim(ADOQueryTemp.fieldbyname('BYIOID').AsString); if Trim(MBYIOID) = '' then begin if not GetLSNo(ADOQueryCmd, Maxno, 'YC', 'BS_Yarn_IO', 3, 1) then raise Exception.Create('取染色坯布出库编号失败!'); end else begin Maxno := Trim(MBYIOID); end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from BS_Yarn_IO where BYIOID=''' + Trim(Maxno) + ''''); Open; end; with ADOQueryCmd do begin if Trim(MBYIOID) = '' then begin Append; FieldByName('Filler').Value := Trim(DName) end else begin Edit; FieldByName('Editer').Value := Trim(DName); FieldByName('EditTime').Value := SGetServerDate(ADOQueryTemp); end; RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_1, 'BS_Yarn_IO', 0); FieldByName('STKName').Value := FSTKName; FieldByName('BYIOID').Value := Trim(Maxno); FieldByName('IOFlag').Value := '出库'; FieldByName('IOQtyFlag').Value := -1; FieldByName('STKID').Value := CDS_1.fieldbyname('STKID').Value; FieldByName('FromCoNo').Value := CDS_1.fieldbyname('FromCoNo').Value; FieldByName('FromCoName').Value := CDS_1.fieldbyname('FromCoName').Value; FieldByName('StkCoNo').Value := CDS_1.fieldbyname('StkCoNo').Value; FieldByName('ToCoNo').Value := CDS_1.fieldbyname('ToCoNo').Value; FieldByName('Supplier').Value := CDS_1.fieldbyname('Supplier').Value; Post; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('Update BS_Yarn_IO Set StkPiece=(select Sum(isnull(Piece,0)*IOQtyFlag) from BS_Yarn_IO A where A.STKID=BS_Yarn_IO.BYIOID)'); sql.Add(',STKQty=(select Sum(isnull(Qty,0)*IOQtyFlag) from BS_Yarn_IO A where A.STKID=BS_Yarn_IO.BYIOID )'); sql.Add('where BYIOID=''' + Trim(CDS_1.fieldbyname('STKID').AsString) + ''''); ExecSQL; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from BS_Yarn_IO where BYIOID=''' + Trim(CDS_1.fieldbyname('STKID').AsString) + ''''); Open; end; if ADOQueryTemp.FieldByName('StkPiece').Value < 0 then raise Exception.Create('出库数量大于入库数量不能保存!'); if ADOQueryTemp.FieldByName('StkPiece').Value < 0 then raise Exception.Create('出库箱/件数大于入库箱/件数不能保存!'); with ADOQueryCmd do begin Close; Sql.Clear; Sql.Add('exec P_BS_Yarn_Move '); Sql.Add(' @BYIOID=' + quotedstr(Trim(Maxno))); Open; end; if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString))); with ADOQueryCmd do begin Close; sql.Clear; sql.Add('insert into Finance_Need_Up(UType,UDataId,UOperation,UOperator,UModule,UDetails) '); sql.Add('values(''纱线出库'' '); sql.Add(',' + quotedstr(Maxno)); sql.Add(',''保存'' '); sql.Add(',' + quotedstr(DName)); sql.Add(',' + quotedstr(trim(self.Caption))); sql.Add(',' + quotedstr(Maxno)); sql.Add(') '); ExecSQL; end; Edit; FieldByName('BYIOID').Value := Trim(Maxno); Post; Next; end; end; CDS_1.EnableControls; ADOQueryCmd.Connection.CommitTrans; Result := True; except Result := False; ADOQueryCmd.Connection.RollbackTrans; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); end; end; procedure TfrmYarnOutInput1.TBCloseClick(Sender: TObject); begin Close; end; procedure TfrmYarnOutInput1.FormShow(Sender: TObject); var fsj: string; begin inherited; IOTime.Date := SGetServerDateTime(ADOQueryTemp); ReadCxGrid(fSTKName + '出库登记Tv1', Tv1, '纱线仓库'); ReadCxGrid(fSTKName + '出库登记Tv2', Tv2, '纱线仓库'); ReadCxGrid(fSTKName + '出库登记Tv3', Tv3, '纱线仓库'); InitGrid1(); InitGrid2(); InitGrid3(); end; procedure TfrmYarnOutInput1.TBDelClick(Sender: TObject); begin if CDS_1.IsEmpty then Exit; if Trim(CDS_1.fieldbyname('BYIOID').AsString) <> '' then begin if Application.MessageBox('确定要删除数据吗?', '提示', 32 + 4) <> IDYES then Exit; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('exec P_Fin_Flow_Judge '); Sql.Add(' @FFIDS=' + quotedstr(Trim(CDS_1.fieldbyname('BYIOID').AsString))); Sql.Add(',@DCode=' + quotedstr(Trim(DCode))); Sql.Add(',@DName=' + quotedstr(Trim(DName))); Open; end; if ADOQueryTemp.FieldByName('intReturn').AsInteger = -1 then begin Application.MessageBox(PChar(ADOQueryTemp.fieldbyname('ShowMsg').AsString), '提示', 0); exit; end; try ADOQueryCmd.Connection.BeginTrans; with ADOQueryCmd do begin Close; Sql.Clear; sql.Add('insert into Finance_Need_Up(UType,UDataId,UOperation,UOperator,UModule,UDetails) '); sql.Add('values(''纱线出库'' '); sql.Add(',' + quotedstr(Trim(CDS_1.fieldbyname('BYIOID').AsString))); sql.Add(',''删除'' '); sql.Add(',' + quotedstr(DName)); sql.Add(',' + quotedstr(trim(self.Caption))); sql.Add(',' + quotedstr(Trim(CDS_1.fieldbyname('BYIOID').AsString))); sql.Add(') '); Sql.Add('exec P_BS_Yarn_Out_Del '); Sql.Add(' @BYIOIDS=' + quotedstr(Trim(CDS_1.fieldbyname('BYIOID').AsString))); Sql.Add(',@DCode=' + quotedstr(Trim(DCode))); Sql.Add(',@DName=' + quotedstr(Trim(DName))); Open; end; if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString))); ADOQueryCmd.Connection.CommitTrans; CDS_1.Delete; except ADOQueryCmd.Connection.RollbackTrans; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); end; end else CDS_1.Delete; end; procedure TfrmYarnOutInput1.TBSaveClick(Sender: TObject); begin if CDS_1.IsEmpty then Exit; if CDS_1.Locate('IOTime', null, []) = True then begin Application.MessageBox('出库时间不能为空!', '提示', 0); Exit; end; if CDS_1.Locate('IOType', null, []) = True then begin Application.MessageBox('出库类型不能为空!', '提示', 0); Exit; end; if CDS_1.Locate('Qty', null, []) = True then begin Application.MessageBox('数量不能为空!', '提示', 0); Exit; end; if SaveCKData() then begin Application.MessageBox('保存成功!', '提示', 0); //ModalResult:=1; InitGrid2(); InitGrid3(); end; end; procedure TfrmYarnOutInput1.ToCoNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmCompanySel := TfrmCompanySel.Create(Application); with frmCompanySel do begin FCoType := '供应商'; if ShowModal = 1 then begin self.ToCoName.Properties.LookupItems.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoCode').AsString); self.ToCoName.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoAbbrName').AsString); end; end; finally frmCompanySel.Free; end; end; procedure TfrmYarnOutInput1.ToolButton1Click(Sender: TObject); begin WriteCxGrid(fSTKName + '出库登记Tv1', Tv1, '纱线仓库'); WriteCxGrid(fSTKName + '出库登记Tv2', Tv2, '纱线仓库'); WriteCxGrid(fSTKName + '出库登记Tv3', Tv3, '纱线仓库'); end; procedure TfrmYarnOutInput1.Tv1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmCompanySel := TfrmCompanySel.Create(Application); with frmCompanySel do begin FCoType := '供应商'; if ShowModal = 1 then begin with Self.CDS_1 do begin Edit; FieldByName('ToCoNo').Value := Trim(CDS_1.fieldbyname('CoCode').AsString); FieldByName('ToCoName').Value := Trim(CDS_1.fieldbyname('CoAbbrName').AsString); end; end; end; finally frmCompanySel.Free; end; end; procedure TfrmYarnOutInput1.TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean); begin InitGrid3(); end; procedure TfrmYarnOutInput1.TV3CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); begin if Trim(ToCoName.Text) = '' then begin Application.MessageBox('出到单位不能为空!', '提示', 0); Exit; end; with Self.CDS_1 do begin Append; FieldByName('IOTime').Value := IOTime.Date; FieldByName('STKID').Value := CDS_3.fieldbyname('BYIOID').Value; FieldByName('IOType').Value := '车间领用'; FieldByName('FromCoNo').Value := CDS_3.fieldbyname('FromCoNo').Value; //来自单位 FieldByName('FromCoName').Value := CDS_3.fieldbyname('FromCoName').Value; FieldByName('StkCoNo').Value := CDS_3.fieldbyname('StkCoNo').Value; //存放单位 FieldByName('StkCoName').Value := CDS_3.fieldbyname('StkCoName').Value; FieldByName('ToCoNo').Value := self.ToCoName.Properties.LookupItems.Text; //出到单位 FieldByName('ToCoName').Value := Self.ToCoName.Text; FieldByName('Brand').Value := CDS_3.fieldbyname('Brand').Value; FieldByName('Y_Code').Value := CDS_3.fieldbyname('Y_Code').Value; FieldByName('Y_Name').Value := CDS_3.fieldbyname('Y_Name').Value; FieldByName('Y_Spec').Value := CDS_3.fieldbyname('Y_Spec').Value; FieldByName('Y_Composition').Value := CDS_3.fieldbyname('Y_Composition').Value; FieldByName('Y_Color').Value := CDS_3.fieldbyname('Y_Color').Value; FieldByName('Denier').Value := CDS_3.fieldbyname('Denier').Value; FieldByName('BatchNo').Value := CDS_3.fieldbyname('BatchNo').Value; FieldByName('QtyUnit').Value := CDS_3.fieldbyname('QtyUnit').Value; FieldByName('StkPosition').Value := CDS_3.fieldbyname('StkPosition').Value; FieldByName('Supplier').Value := CDS_3.fieldbyname('Supplier').Value; FieldByName('WBCID').Value := CDS_2.fieldbyname('WBCID').Value; FieldByName('TestDenier').Value := CDS_3.fieldbyname('TestDenier').Value; FieldByName('Y_Type').Value := CDS_3.fieldbyname('Y_Type').Value; FieldByName('Y_ColorNo').Value := CDS_3.fieldbyname('Y_ColorNo').Value; FieldByName('Piece').Value := 0; if CDS_3.fieldbyname('YarnMeter').AsFloat > 0 then FieldByName('Qty').Value := RoundFloat((CDS_3.fieldbyname('STKQTY').AsFloat / CDS_3.fieldbyname('YarnMeter').AsFloat * (CDS_2.fieldbyname('WB_YarnLen').AsFloat - CDS_2.fieldbyname('YarnMeter').AsFloat)), 2); end; end; end.