unit U_DyePlanInPut; 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, cxCalendar, StrUtils, cxCurrencyEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, cxDropDownEdit, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu, cxPC; type TfrmDyePlanInPut = class(TForm) ToolBar1: TToolBar; TBSave: TToolButton; TBClose: TToolButton; ScrollBox1: TScrollBox; Label1: TLabel; OrderNo: TEdit; ADOTemp: TADOQuery; ADOCmd: TADOQuery; DS_1: TDataSource; CDS_1: TClientDataSet; Label10: TLabel; ConNo: TEdit; Label3: TLabel; Label14: TLabel; Label12: TLabel; Label13: TLabel; OrdDate: TDateTimePicker; CustName: TBtnEditC; C_Width: TBtnEditC; C_GramWeight: TBtnEditC; Label2: TLabel; C_Name: TBtnEditC; Label19: TLabel; Label25: TLabel; DLYDate: TDateTimePicker; Label42: TLabel; Label43: TLabel; Saleser: TBtnEditC; Need_Packing: TMemo; Need_Production: TMemo; Need_Other: TMemo; Label23: TLabel; Label4: TLabel; Label7: TLabel; Workshop: TEdit; OrdType: TComboBox; GPM_1: TcxGridPopupMenu; Label21: TLabel; Label27: TLabel; GC_Piece: TBtnEditC; GC_BatchNo: TEdit; Label66: TLabel; GC_Position: TEdit; Label67: TLabel; GC_PieceWeight: TEdit; ToolButton4: TToolButton; Label5: TLabel; C_Spec: TBtnEditC; cxPageControl1: TcxPageControl; ToolBar2: TToolBar; ToolButton1: TToolButton; ToolButton2: TToolButton; ToolButton3: TToolButton; cxGrid1: TcxGrid; Tv1: TcxGridDBTableView; Tv1Column1: TcxGridDBColumn; v1SOrddefstr1: TcxGridDBColumn; v1PRTColor: TcxGridDBColumn; v1PRTORDQTY: TcxGridDBColumn; v1OrderUnit: TcxGridDBColumn; v1Column2: TcxGridDBColumn; v1Column3: TcxGridDBColumn; Tv1Column3: TcxGridDBColumn; v1Column5: TcxGridDBColumn; v1Column1: TcxGridDBColumn; cxGrid1Level1: TcxGridLevel; Label6: TLabel; GC_STKID: TEdit; Label8: TLabel; GC_TotalPiece: TEdit; procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBSaveClick(Sender: TObject); procedure v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure ToolButton1Click(Sender: TObject); procedure ToolButton2Click(Sender: TObject); procedure CustNameBtnUpClick(Sender: TObject); procedure CustNameBtnDnClick(Sender: TObject); procedure C_NameBtnUpClick(Sender: TObject); procedure v1OrderUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure ToolButton3Click(Sender: TObject); procedure Need_ProductionDblClick(Sender: TObject); procedure GC_PieceBtnUpClick(Sender: TObject); procedure GC_BatchNoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure ToolButton4Click(Sender: TObject); private procedure InitData(); procedure ZDYHelp(FButn: TcxButtonEdit; LType: string); function SaveData(): Boolean; { Private declarations } public PState, CopyInt, PriceFlag: Integer; FMainId, FFMainId, FOrderNo: string; FXS: Integer; canshu1, canshu2, FWorkshop: string; fFlileFlag: string; { Public declarations } end; var frmDyePlanInPut: TfrmDyePlanInPut; newh: hwnd; implementation uses U_DataLink, U_ZDYHelp, U_RTFun, U_DyeGreyClothOutSel, U_CompanySel, U_ZDYHelpSel, U_DyeGreyClothStkSel; {$R *.dfm} procedure TfrmDyePlanInPut.TBCloseClick(Sender: TObject); begin Close; end; procedure TfrmDyePlanInPut.InitData(); begin with ADOTemp do begin Close; sql.Clear; sql.Add('select * from Dye_Plan_Main where MainId=''' + Trim(FMainId) + ''''); Open; end; SCSHData(ADOTemp, ScrollBox1, 2); CustName.TxtCode := ADOTemp.FieldByName('CustNo').asstring; with ADOTemp do begin Close; SQL.Clear; sql.Add('select * '); sql.Add('from Dye_Plan_Sub A where 1=1 '); sql.Add(' and MainId=''' + Trim(FMainId) + ''''); Open; end; SCreateCDS(ADOTemp, CDS_1); SInitCDSData(ADOTemp, CDS_1); if CopyInt = 99 then begin PState := 0; FMainId := ''; OrderNo.Text := '自动生成'; GC_Piece.Text := ''; GC_BatchNo.Text := ''; GC_Position.Text := ''; GC_STKID.Text := ''; OrdDate.DateTime := SGetServerDateTime(ADOTemp); DlyDate.DateTime := OrdDate.DateTime; with CDS_1 do begin First; while not Eof do begin Edit; FieldByName('MainId').Value := ''; FieldByName('SubId').Value := ''; FieldByName('carNum').Value := 0; Post; Next; end; end; end; end; procedure TfrmDyePlanInPut.ZDYHelp(FButn: TcxButtonEdit; LType: string); var FType, ZDYName, FText: string; begin end; procedure TfrmDyePlanInPut.FormShow(Sender: TObject); var forderNo: string; begin readCxGrid(Trim(Self.Caption), Tv1, '染整计划管理'); OrdDate.DateTime := SGetServerDateTime(ADOTemp); DlyDate.DateTime := OrdDate.DateTime; Workshop.text := trim(FWorkshop); fFlileFlag := UserDataFlag + 'HX'; InitData(); end; function TfrmDyePlanInPut.SaveData(): Boolean; var maxno, forderNo: string; begin try ADOCmd.Connection.BeginTrans; /////////////// 保存主表 /////////////// if Trim(FMainId) = '' then begin if not GetLSNo(ADOCmd, maxno, 'JM', 'Dye_Plan_Main', 3, 1) then raise Exception.Create('取最大号失败!'); if GetLSNo(ADOCmd, forderNo, 'JH', 'Dye_Plan_Main', 3, 1) = False then raise Exception.Create('取计划单号失败!'); OrderNo.Text := trim(forderNo); end else begin maxno := Trim(FMainId); end; with ADOCmd do begin Close; sql.Clear; SQL.Add('select * from Dye_Plan_Main where MainId=''' + Trim(FMainId) + ''''); Open; end; with ADOCmd do begin if ADOCmd.IsEmpty then begin Append; FieldByName('Fillid').Value := Trim(dcode); FieldByName('Filler').Value := Trim(DName); end else begin Edit; FieldByName('Editid').Value := Trim(dcode); FieldByName('Editer').Value := Trim(DName); FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp); end; RTSetsavedata(ADOCmd, 'Dye_Plan_Main', ScrollBox1, 2); FieldByName('MainId').Value := Trim(maxno); FieldByName('CustNo').Value := CustName.TxtCode; Post; end; with ADOCmd do begin Close; sql.Clear; sql.Add('select * from Dye_Plan_Main where orderno=''' + Trim(OrderNo.Text) + ''''); Open; end; if ADOCmd.RecordCount > 1 then raise Exception.Create('计划单号重复!'); FMainId := Trim(maxno); /////////////// 保存主表 /////////////// /// /////////////// 保存子表 /////////////// with CDS_1 do begin First; while not Eof do begin if Trim(CDS_1.fieldbyname('SubId').AsString) = '' then begin if not GetLSNo(ADOCmd, maxno, 'JS', 'Dye_Plan_Sub', 4, 1) then raise Exception.Create('计划单号重复!'); end else begin maxno := Trim(CDS_1.fieldbyname('SubId').AsString); end; with ADOCmd do begin Close; SQL.Clear; sql.Add('select * from Dye_Plan_Sub A '); sql.Add(' where MainId=''' + Trim(FMainId) + ''''); sql.Add(' and SubId=''' + Trim(maxno) + ''''); Open; end; with ADOCmd do begin if ADOCmd.IsEmpty then begin Append; end else Edit; RTSetSaveDataCDS(ADOCmd, Tv1, CDS_1, 'Dye_Plan_Sub', 0); FieldByName('MainId').Value := Trim(FMainId); FieldByName('SubId').Value := Trim(maxno); Post; end; CDS_1.Edit; CDS_1.FieldByName('SubId').Value := Trim(maxno); Next; end; end; /////////////// 保存子表 /////////////// ADOCmd.Connection.CommitTrans; Result := True; except ADOCmd.Connection.RollbackTrans; Result := False; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); end; end; procedure TfrmDyePlanInPut.TBSaveClick(Sender: TObject); begin OrdDate.SetFocus; try // if Trim(OrderNo.Text) = '' then // raise Exception.Create('计划单号不能为空!'); if Trim(OrdType.Text) = '' then raise Exception.Create('订单类型不能为空!'); if Trim(CustName.Text) = '' then raise Exception.Create('客户不能为空!'); if Trim(C_Name.Text) = '' then raise Exception.Create('产品名称不能为空!'); if CDS_1.IsEmpty then raise Exception.Create('明细不能为空!'); except application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); exit; end; // // if PState = 1 then // begin // if Trim(OrderNo.Text) <> Trim(forderNo) then // begin // with ADOTemp do // begin // Close; // sql.Clear; // sql.Add('select * from YF_Money_CR where MainId=''' + Trim(FMainId) + ''''); // Open; // end; // if ADOTemp.IsEmpty = False then // begin // Application.MessageBox('已产生数据,不能更改订单号!', '提示', 0); // Exit; // end; // end; // end; if SaveData() then begin Application.MessageBox('保存成功!', '提示', 0); TBClose.Click(); end; end; procedure TfrmDyePlanInPut.v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'C_Color'; flagname := '颜色'; V1Name.Caption := '中文名称'; // V1Note.Caption := '英文名称'; // fnote := True; if ShowModal = 1 then begin Self.CDS_1.Edit; Self.CDS_1.FieldByName('C_Color').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); // Self.CDS_1.FieldByName('ORDNOTE').Value := Trim(ClientDataSet1.fieldbyname('ORDNOTE').AsString); end; end; finally frmZDYHelp.Free; end; end; procedure TfrmDyePlanInPut.ToolButton1Click(Sender: TObject); var i: Integer; begin // if Trim(OrderNo.Text) = '' then // begin // Application.MessageBox('计划单号不能为空!', '提示', 0); // Exit; // end; i := CDS_1.RecordCount; i := i + 1; CDS_1.Last; CopyAddRow(Tv1, CDS_1); with CDS_1 do begin Edit; FieldByName('SerialNo').Value := IntToStr(i); FieldByName('OrdQty').Value := 0; FieldByName('AntcpPiece').Value := 0; FieldByName('AntcpQty').Value := 0; FieldByName('OrdUnit').Value := 'KG'; FieldByName('AntcpUnit').Value := '匹'; Post; end; end; procedure TfrmDyePlanInPut.ToolButton2Click(Sender: TObject); begin if CDS_1.IsEmpty then Exit; with ADOTemp do begin Close; sql.Clear; sql.Add('select * from Dye_Plan_Card where SubId=''' + Trim(CDS_1.fieldbyname('SubId').AsString) + ''''); Open; end; if ADOTemp.IsEmpty = False then begin Application.MessageBox('已开卡不能删除数据!', '提示', 0); Exit; end; if Trim(CDS_1.fieldbyname('SubId').AsString) <> '' then begin if Application.MessageBox('确定要删除数据吗?', '提示', 32 + 4) <> IDYES then Exit; with ADOCmd do begin Close; sql.Clear; sql.Add('delete Dye_Plan_Sub where SubId=''' + Trim(CDS_1.fieldbyname('SubId').AsString) + ''''); ExecSQL; end; end; CDS_1.Delete; end; procedure TfrmDyePlanInPut.CustNameBtnUpClick(Sender: TObject); begin try frmCompanySel := TfrmCompanySel.Create(Application); with frmCompanySel do begin FCoType := '客户'; if ShowModal = 1 then begin CustName.Text := Trim(CDS_1.fieldbyname('CoName').AsString); CustName.TxtCode := Trim(CDS_1.fieldbyname('CoCode').AsString); Self.Saleser.Text := Trim(CDS_1.fieldbyname('Saleser').AsString); end; end; finally frmCompanySel.Free; end; end; procedure TfrmDyePlanInPut.CustNameBtnDnClick(Sender: TObject); begin TBtnEditC(Sender).Text := ''; TBtnEditC(Sender).TxtCode := ''; end; procedure TfrmDyePlanInPut.C_NameBtnUpClick(Sender: TObject); var fsj: string; FWZ: Integer; begin fsj := Trim(TEdit(Sender).Hint); FWZ := Pos('/', fsj); try frmZDYHelpSel := TfrmZDYHelpSel.Create(Application); with frmZDYHelpSel do begin flag := Copy(fsj, 1, FWZ - 1); flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ); MainType := 'DyePlan'; if ShowModal = 1 then begin TEdit(Sender).Text := ReturnStr; end; end; finally frmZDYHelpSel.Free; end; end; procedure TfrmDyePlanInPut.v1OrderUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); var mvalues: string; begin mvalues := tv1.Columns[tv1.Controller.FocusedColumn.index].DataBinding.FieldName; try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'OrderUnit'; flagname := '数量单位'; if ShowModal = 1 then begin Self.CDS_1.Edit; Self.CDS_1.FieldByName(mvalues).Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); end; end; finally frmZDYHelp.Free; end; end; procedure TfrmDyePlanInPut.v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'PriceUnit'; flagname := '价格单位'; if Trim(DParameters1) <> '高权限' then begin TBAdd.Visible := False; TBEdit.Visible := False; TBDel.Visible := False; end; if ShowModal = 1 then begin Self.CDS_1.Edit; Self.CDS_1.FieldByName('PriceUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); end; end; finally frmZDYHelp.Free; end; end; procedure TfrmDyePlanInPut.ToolButton3Click(Sender: TObject); begin if CDS_1.IsEmpty then Exit; OneKeyPost(Tv1, CDS_1); end; procedure TfrmDyePlanInPut.ToolButton4Click(Sender: TObject); begin WriteCxGrid(Trim(Self.Caption), Tv1, '染整计划管理'); end; procedure TfrmDyePlanInPut.Need_ProductionDblClick(Sender: TObject); var fsj: string; FWZ: Integer; i: integer; begin fsj := Trim(TMemo(Sender).Hint); FWZ := Pos('/', fsj); i := 0; try frmZDYHelpSel := TfrmZDYHelpSel.Create(Application); with frmZDYHelpSel do begin flag := Copy(fsj, 1, FWZ - 1); flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ); if ShowModal = 1 then begin TMemo(Sender).Lines.Clear; with ClientDataSet1 do begin First; while not Eof do begin if FieldByName('SSel').AsBoolean = True then begin i := i + 1; TMemo(Sender).Lines.Add(inttostr(i) + '.' + FieldByName('ZDYName').AsString) end; Next; end; end; end; end; finally frmZDYHelpSel.Free; end; end; procedure TfrmDyePlanInPut.GC_BatchNoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin Application.Hint := TEdit(Sender).Name; end; procedure TfrmDyePlanInPut.GC_PieceBtnUpClick(Sender: TObject); var fRollNum: integer; MGC_BatchNo, MGC_Piece, MGC_STKID, MGC_Position: string; begin MGC_BatchNo := ''; MGC_Piece := ''; MGC_STKID := ''; MGC_Position := ''; fRollNum := 0; if trim(CustName.Text) = '' then begin Application.MessageBox('客户不能为空!', '提示', 0); Exit; end; frmDyeGreyClothStkSel := TfrmDyeGreyClothStkSel.create(self); with frmDyeGreyClothStkSel do begin FromCoNo.Text := trim(self.CustName.TxtCode); FromCoNo.Enabled := False; if showmodal = 1 then begin CDS_Main.DisableControls; CDS_Main.First; while not CDS_Main.eof do begin if CDS_Main.FieldByName('ssel').AsBoolean then begin MGC_BatchNo := MGC_BatchNo + trim(CDS_Main.FieldByName('BatchNo').AsString) + '+'; fRollNum := fRollNum + CDS_Main.FieldByName('STKPIECE').AsInteger; MGC_Piece := MGC_Piece + trim(CDS_Main.FieldByName('STKPIECE').AsString) + ','; MGC_STKID := MGC_STKID + trim(CDS_Main.FieldByName('STKID').AsString) + ';'; MGC_Position := MGC_Position + trim(CDS_Main.FieldByName('StkPosition').AsString) + ';'; Self.C_Name.Text := trim(CDS_Main.FieldByName('C_Name').AsString); Self.C_Spec.Text := trim(CDS_Main.FieldByName('C_spec').AsString); CustName.TxtCode := trim(CDS_Main.FieldByName('FromCoNo').AsString); CustName.Text := trim(CDS_Main.FieldByName('FromCoName').AsString); Self.C_Width.Text := trim(CDS_Main.FieldByName('C_Width').AsString); Self.C_GramWeight.Text := trim(CDS_Main.FieldByName('C_GramWeight').AsString); Self.Saleser.Text := trim(CDS_Main.FieldByName('Saleser').AsString); end; CDS_Main.Next; end; CDS_Main.EnableControls; end; free; end; if length(MGC_BatchNo) > 0 then begin MGC_BatchNo := copy(MGC_BatchNo, 1, Length(MGC_BatchNo) - 1); MGC_Piece := copy(MGC_Piece, 1, Length(MGC_Piece) - 1); MGC_STKID := copy(MGC_STKID, 1, Length(MGC_STKID) - 1); MGC_Position := copy(MGC_Position, 1, Length(MGC_Position) - 1); GC_TotalPiece.text := inttostr(fRollNum); GC_BatchNo.Text := MGC_BatchNo; GC_Piece.Text := MGC_Piece; GC_STKID.Text := MGC_STKID; GC_Position.Text := MGC_Position; end; end; end.