unit U_TatWBCardInPutOld;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxCheckBox, cxPC,
  Menus, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu,
  dxDateRanges, BtnEdit, U_BaseInput, System.ImageList, Vcl.ImgList, cxContainer,
  cxMaskEdit, cxDropDownEdit, cxRichEdit, cxMemo, dxScrollbarAnnotations,
  dxSkinsCore, dxSkinsDefaultPainters, cxImageList;

type
  TfrmTatWBCardInPutOld = class(TfrmBaseInput)
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    RMDB_1: TRMDBDataSet;
    Panel2: TPanel;
    DS_Card: TDataSource;
    CDS_Card: TClientDataSet;
    GPM_1: TcxGridPopupMenu;
    ADOQueryPrint: TADOQuery;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N3: TMenuItem;
    Panel4: TPanel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    V2Column1: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    TV2Column1: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    ToolButton1: TToolButton;
    ToolButton8: TToolButton;
    ToolButton2: TToolButton;
    TBClose: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    v1Column31: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel1: TPanel;
    Label9: TLabel;
    Label2: TLabel;
    Label15: TLabel;
    Label3: TLabel;
    Label6: TLabel;
    Label4: TLabel;
    GPM_2: TcxGridPopupMenu;
    ToolButton4: TToolButton;
    CDS_1: TClientDataSet;
    DS_1: TDataSource;
    Label7: TLabel;
    TV2Column6: TcxGridDBColumn;
    Label1: TLabel;
    Label10: TLabel;
    TV2Column8: TcxGridDBColumn;
    PM_1: TPopupMenu;
    N1: TMenuItem;
    Label16: TLabel;
    WBType1: TcxButtonEdit;
    WB_MachNo: TcxButtonEdit;
    WB_Macher: TcxButtonEdit;
    WB_YarnLen1: TcxTextEdit;
    edtCardQty1: TcxTextEdit;
    WBCNO: TcxTextEdit;
    WB_Type: TcxComboBox;
    WB_Code: TcxButtonEdit;
    Label5: TLabel;
    WB_Name: TcxTextEdit;
    Label8: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    WB_YarnQty: TcxTextEdit;
    WB_Move: TcxTextEdit;
    WB_ReedNote: TcxTextEdit;
    WB_YarnStripQty: TcxTextEdit;
    WB_Width: TcxTextEdit;
    Label17: TLabel;
    WB_Arg_SDWZ: TcxTextEdit;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    WB_YarnArr: TcxTextEdit;
    WB_YarnStripRemainder: TcxTextEdit;
    WB_ReedNo: TcxTextEdit;
    WB_Arg_PXDS: TcxTextEdit;
    WB_Arg_QJZL: TcxTextEdit;
    WB_YarnArrNote: TcxMemo;
    Note: TcxMemo;
    TV2Column2: TcxGridDBColumn;
    TV2Column5: TcxGridDBColumn;
    TV2Column7: TcxGridDBColumn;
    TV2Column9: TcxGridDBColumn;
    TV2Column10: TcxGridDBColumn;
    TV2Column11: TcxGridDBColumn;
    TV2Column12: TcxGridDBColumn;
    TV2Column13: TcxGridDBColumn;
    TV2Column14: TcxGridDBColumn;
    TV2Column15: TcxGridDBColumn;
    TV2Column16: TcxGridDBColumn;
    TV2Column17: TcxGridDBColumn;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    v1Column18: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    v1SPName: TcxGridDBColumn;
    v1SPSpec: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    DS_3: TDataSource;
    GPM_3: TcxGridPopupMenu;
    CDS_3: TClientDataSet;
    ADO_3: TADOQuery;
    Label21: TLabel;
    WB_ProcessType: TcxComboBox;
    TV2Column18: TcxGridDBColumn;
    Label24: TLabel;
    Label25: TLabel;
    WBType2: TcxButtonEdit;
    edtCardQty2: TcxTextEdit;
    Label26: TLabel;
    Label27: TLabel;
    WBType3: TcxButtonEdit;
    edtCardQty3: TcxTextEdit;
    Label28: TLabel;
    WB_YarnLen2: TcxTextEdit;
    Label29: TLabel;
    WB_YarnLen3: TcxTextEdit;
    Label30: TLabel;
    WBFtyName: TcxButtonEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure WBNoPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure WB_MachNoPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure WB_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure TBSaveClick(Sender: TObject);
    procedure cxButtonEdit1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure WBFtyNameDblClick(Sender: TObject);
  private
    function TestData(): Boolean;
    procedure PrtDate(MWBCID: string);
    procedure InitMain();
    procedure InitCard();
    procedure InitCardGrop();
    procedure KaiKa(MWBType: string; MCardQty: Integer; MWB_YarnLen: Double);
    { Private declarations }
  public
    FWBCNO: string;
    { Public declarations }
  end;

var
  frmTatWBCardInPutOld: TfrmTatWBCardInPutOld;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_WBTatPlanSel, U_WBSpecSel,
  U_WarpBeamInfoSel, U_WBTypeSel, U_CompanySel;

{$R *.dfm}
procedure TfrmTatWBCardInPutOld.InitCardGrop();
begin

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from V_Tat_WB_CardGrop A where A.WBCNO=''' + Trim(FWBCNO) + '''');
    Open;
  end;
  SCSHData(ADOQueryTemp, Panel1, 1);
  WBFtyName.Properties.LookupItems.Text := Trim(ADOQueryTemp.fieldbyname('WBFtyNo').AsString);

end;

function TfrmTatWBCardInPutOld.TestData(): Boolean;
begin
  try

    if Trim(FWBCNO) = '' then
    begin
      if GetLSNo(ADOQueryTemp, FWBCNO, 'QJ', 'Tat_WB_Card', 3, 1) = False then
      begin
        raise Exception.Create('迁经单号失败!');
      end;
      WBCNO.Text := FWBCNO;
    end;

    if trim(WB_Code.Text) = '' then
      raise Exception.Create('经编号不能为空！');
//    if StrToIntDef(edtCardQty.Text, 0) = 0 then
//      raise Exception.Create('排轴数不能为空！');
    if StrToIntDef(WB_YarnQty.Text, 0) = 0 then
      raise Exception.Create('头纹不能为空！');
//    if Trim(WB_YarnArr.Text) = '' then
//      raise Exception.Create('上排不能为空！');
//    if Trim(WB_Len.Text) = '' then
//      raise Exception.Create('轴长不能为空！');
//    if StrToIntDef(WB_YarnLen.Text, 0) = 0 then
//      raise Exception.Create('整经长度不能为空！');
    if Trim(WB_Macher.Text) = '' then
      raise Exception.Create('扦经工位不能为空！');
    if Trim(WB_MachNo.Text) = '' then
      raise Exception.Create('迁经机不能为空！');
//    if StrToIntDef(WB_ClothPiece.Text, 0) = 0 then
//      WB_ClothPiece.Text := '0';
    if Trim(WB_Type.Text) = '' then
      raise Exception.Create('类型不能为空！');
    Result := True;
  except
    Result := false;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmTatWBCardInPutOld.InitMain();
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*  ');
    sql.Add(' from Tat_Plan_Main A inner join Tat_Plan_Sub B on A.Mainid=B.MainId   ');
    sql.Add(' inner join Tat_WB_Card_Link C on B.SubId=C.SubId  ');
    sql.Add(' where C.WBCNO= ' + QuotedStr(Trim(FWBCNO)));
    Open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_1);
  SInitCDSData(ADOQueryTemp, CDS_1);

end;

procedure TfrmTatWBCardInPutOld.InitCard();
begin

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*  ');
    sql.Add('from Tat_WB_Card A   ');
    sql.Add('where isnull(Status,''0'')<>''-1'' and WBCNO=' + quotedstr(Trim(FWBCNO)));
    Open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_Card);
  SInitCDSData(ADOQueryTemp, CDS_Card);
end;

procedure TfrmTatWBCardInPutOld.PrtDate(MWBCID: string);
var
  fPrintFile, FFCYID: string;
  DPS, i, j: Integer;
begin

  ExportFtErpFile('轴卡标签.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\轴卡标签.rmf';

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update Tat_WB_Card set PrtFlag=PrtFlag+1 ');
    sql.Add(' where WBCID=' + quotedstr(MWBCID));
    ExecSQL;
  end;

  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*,D.*  ');
    sql.Add(' from PD_Plan_Main A inner join PD_Plan_Sub B on A.Mainid=B.MainId');
    sql.Add(' inner join  Tat_WB_Card_MS C  on C.Subid=B.Subid  ');
    sql.Add(' inner join  Tat_WB_Card D  on C.WBCID=D.WBCID  ');
    sql.Add(' where D.WBCID=' + quotedstr(MWBCID));
//    ShowMessage(SQL.Text);
    Open;
  end;

//  with ADOQueryTemp do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add('select Y.* from PD_Plan_Yarn Y INNER JOIN Tat_WB_Card_MS M ON M.MainId=Y.MainId where Y.PYType=''经丝'' and M.WBCID=' + Quotedstr(Trim(MWBCID)));
//    Open;
//  end;
//  SCreateCDS(ADOQueryTemp, CDS_PJS);
//  SInitCDSData(ADOQueryTemp, CDS_PJS);
//
//  with ADOQueryTemp do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add('select Y.* from PD_Plan_Yarn Y INNER JOIN Tat_WB_Card_MS M ON M.MainId=Y.MainId where Y.PYType=''纬丝'' and M.WBCID=' + Quotedstr(Trim(MWBCID)));
//    Open;
//  end;
//  SCreateCDS(ADOQueryTemp, CDS_PWS);
//  SInitCDSData(ADOQueryTemp, CDS_PWS);

  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.DefaultCopies := 1;
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
    Exit;
  end;

end;

procedure TfrmTatWBCardInPutOld.WBFtyNameDblClick(Sender: TObject);
begin
  self.WBFtyName.Properties.LookupItems.Text := '';
  self.WBFtyName.Text := '';
end;

procedure TfrmTatWBCardInPutOld.WBNoPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmWBTypeSel := TfrmWBTypeSel.Create(Application);
    with frmWBTypeSel do
    begin
      if ShowModal = 1 then
      begin
        TcxTextEdit(Sender).Text := Trim(frmWBTypeSel.CDS_Main.fieldbyname('WBType').AsString);
      end;
    end;
  finally
    frmWBTypeSel.Free;
  end;
end;

procedure TfrmTatWBCardInPutOld.WB_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmWBSpecSel := TfrmWBSpecSel.Create(Application);
    with frmWBSpecSel do
    begin
      if ShowModal = 1 then
      begin
        Self.WB_Code.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Code').AsString);
        Self.WB_Name.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Name').AsString);
        Self.WB_YarnQty.Text := frmWBSpecSel.CDS_1.fieldbyname('WB_YarnQty').value;
        Self.WB_YarnArr.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_YarnArr').AsString);
        Self.WB_YarnStripQty.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_YarnStripQty').AsString);
        Self.WB_YarnStripRemainder.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_YarnStripRemainder').AsString);
        Self.WB_Width.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Width').AsString);
        Self.WB_ReedNo.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_ReedNo').AsString);
        Self.WB_ReedNote.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_ReedNote').AsString);
        Self.WB_Arg_PXDS.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Arg_PXDS').AsString);
        Self.WB_Arg_SDWZ.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Arg_SDWZ').AsString);
        Self.WB_Arg_QJZL.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Arg_QJZL').AsString);
        Self.WB_Move.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_Move').AsString);
        Self.WB_YarnArrNote.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('WB_YarnArrNote').AsString);
        Self.Note.Text := Trim(frmWBSpecSel.CDS_1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmWBSpecSel.Free;
  end;
end;

procedure TfrmTatWBCardInPutOld.WB_MachNoPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TcxButtonEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
//      MainType := 'SalesCon';
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TcxButtonEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTatWBCardInPutOld.cxButtonEdit1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmCompanySel := TfrmCompanySel.Create(Application);
    with frmCompanySel do
    begin
      FCoType := '供应商';
      if ShowModal = 1 then
      begin
        self.WBFtyName.Properties.LookupItems.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoCode').AsString);
        self.WBFtyName.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoAbbrName').AsString);
      end;
    end;

  finally
    frmCompanySel.Free;
  end;
end;

procedure TfrmTatWBCardInPutOld.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
end;

procedure TfrmTatWBCardInPutOld.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxGrid(Trim(self.Caption) + 'Tv1', Tv1, '坯布轴卡');
  ReadCxGrid(Trim(self.Caption) + 'Tv2', Tv2, '坯布轴卡');
  InitMain();
  InitCard();
  InitCardGrop();
end;

procedure TfrmTatWBCardInPutOld.N1Click(Sender: TObject);
begin
  if not CDS_1.IsEmpty then
    CDS_1.Delete;

end;

procedure TfrmTatWBCardInPutOld.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Card, True);
end;

procedure TfrmTatWBCardInPutOld.N3Click(Sender: TObject);
begin
  SelOKNo(CDS_Card, False);
end;

procedure TfrmTatWBCardInPutOld.TBCloseClick(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmTatWBCardInPutOld.TBSaveClick(Sender: TObject);
begin
  if TestData() = false then
    exit;

  KaiKa(WBType1.Text, StrToIntdef(edtCardQty1.Text, 0), StrToFloatdef(WB_YarnLen1.Text, 0));
  KaiKa(WBType2.Text, StrToIntdef(edtCardQty2.Text, 0), StrToFloatdef(WB_YarnLen2.Text, 0));
  KaiKa(WBType3.Text, StrToIntdef(edtCardQty3.Text, 0), StrToFloatdef(WB_YarnLen3.Text, 0));
end;

procedure TfrmTatWBCardInPutOld.KaiKa(MWBType: string; MCardQty: Integer; MWB_YarnLen: Double);
var
  MWBCID: string;
  i, j: integer;
begin
  if MCardQty = 0 then
    EXIT;
  try
    ADOQueryCmd.Connection.BeginTrans;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      //////////////////            插入轴卡               //////////////////////
      sql.Add(' insert into Tat_WB_Card(WBCNO,WBCID,WBType,WB_ProcessType,WB_Code,WB_Name,WB_YarnQty,WB_YarnArr,WB_YarnLen,WB_Macher,WB_MachNo,WB_Type,Note,FillId,Filler');
      sql.Add(' ,WB_YarnStripQty,WB_YarnStripRemainder,WB_Width,WB_ReedNo,WB_ReedNote,WB_Arg_PXDS,WB_Arg_SDWZ,WB_Arg_QJZL,WB_Move,WB_YarnArrNote,WBFtyNo,WBFtyName  ) values');
      for i := 1 to MCardQty do
      begin
        if GetLSNo(ADOQueryTemp, MWBCID, 'ZK' + trim(WB_MachNo.Text), 'Tat_WB_Card', 3, 1) = False then
        begin
          raise Exception.Create('取布票流水号失败!');
        end;

        if i > 1 then
          sql.Add(',');
        sql.Add(' (' + Quotedstr(Trim(FWBCNO)));
        sql.Add(',' + Quotedstr(Trim(MWBCID)));
        sql.Add(',' + Quotedstr(Trim(MWBType)));
        sql.Add(',' + Quotedstr(Trim(WB_ProcessType.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Code.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Name.Text)));
        sql.Add(',' + (Trim(WB_YarnQty.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_YarnArr.Text)));
        sql.Add(',' + FloatToStr(MWB_YarnLen));
        sql.Add(',' + Quotedstr(Trim(WB_Macher.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_MachNo.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Type.Text)));
        sql.Add(',' + Quotedstr(Trim(Note.Text)));
        sql.Add(',' + Quotedstr(Trim(DCode)));
        sql.Add(',' + Quotedstr(Trim(DName)));

        sql.Add(',' + Quotedstr(Trim(WB_YarnStripQty.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_YarnStripRemainder.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Width.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_ReedNo.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_ReedNote.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Arg_PXDS.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Arg_SDWZ.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Arg_QJZL.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Move.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_YarnArrNote.Text)));
        sql.Add(',' + Quotedstr(Trim(WBFtyName.Properties.LookupItems.Text)));
        sql.Add(',' + Quotedstr(Trim(WBFtyName.Text)));
        sql.Add(' )');
      end;
     //////////////////            插入轴卡               //////////////////////
     ///
     //////////////////            插入轴卡计划单               //////////////////////
      if not CDS_1.IsEmpty then
      begin
        with CDS_1 do
        begin
          First;
          sql.Add(' delete Tat_WB_Card_Link where WBCNO=' + Quotedstr(Trim(FWBCNO)));

          while not Eof do
          begin
            sql.Add(' insert into Tat_WB_Card_Link(MainId,SubID,WBCNO) values');
            sql.Add(' (' + Quotedstr(Trim(CDS_1.FieldByName('MainId').AsString)));
            sql.Add(',' + Quotedstr(Trim(CDS_1.FieldByName('SubID').AsString)));
            sql.Add(',' + Quotedstr(Trim(FWBCNO)));
            sql.Add(' )');
            Next;
          end;
        end;
      end;
      //////////////////            插入轴卡计划单               //////////////////////
      ExecSQL;
    end;
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from V_Tat_WB_CardGrop A where A.WBCNO=''' + Trim(FWBCNO) + '''');
      Open;
    end;
    if ADOQueryTemp.RecordCount > 1 then
      raise Exception.Create('计划单信息不能变更!');

    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
  InitCard();
end;

procedure TfrmTatWBCardInPutOld.ToolButton1Click(Sender: TObject);
var
  WSql: string;
begin

  if CDS_Card.IsEmpty then
    Exit;
  if CDS_Card.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  WSql := '';
  CDS_Card.DisableControls;

  with CDS_Card do
  begin
    First;
    while not Eof do
    begin
      if CDS_Card.fieldbyname('SSel').AsBoolean then
      begin
        if WSql <> '' then
        begin
          WSql := WSql + ',' + QuotedStr(Trim(CDS_Card.fieldbyname('WBCID').AsString));
        end
        else
        begin
          WSql := QuotedStr(Trim(CDS_Card.fieldbyname('WBCID').AsString));
        end;
      end;
      Next;
    end;
  end;

  CDS_Card.Locate('SSel', True, []);
  CDS_Card.EnableControls;

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FPreviewPrint := False;
      FLMType := 'TatWBCard';
      FFiltration1 := WSql;
      if ShowModal = 1 then
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('update Tat_WB_Card         ');
          sql.Add(' set PRTer=' + quotedstr(DName));
          sql.Add(', PRTCount=PRTCount+1');
          sql.Add(', PRTDate=getdate()');
          sql.Add(' where WBCID in (' + WSql + ')');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

procedure TfrmTatWBCardInPutOld.ToolButton2Click(Sender: TObject);
begin
  WriteCxGrid(Trim(self.Caption) + 'Tv1', Tv1, '坯布轴卡');
  WriteCxGrid(Trim(self.Caption) + 'Tv2', Tv2, '坯布轴卡');
end;

procedure TfrmTatWBCardInPutOld.ToolButton4Click(Sender: TObject);
begin
  try
    frmWBTatPlanSel := TfrmWBTatPlanSel.Create(Application);
    with frmWBTatPlanSel do
    begin
      if ShowModal = 1 then
      begin
        frmWBTatPlanSel.CDS_1.DisableControls;
        with frmWBTatPlanSel.CDS_1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean then
            begin
              with Self.CDS_1 do
              begin
                Append;
                FieldByName('ConNo').Value := frmWBTatPlanSel.CDS_1.FieldByName('ConNo').Value;
                FieldByName('OrderNo').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrderNo').Value;
                FieldByName('MainId').Value := frmWBTatPlanSel.CDS_1.FieldByName('MainId').Value;
                FieldByName('SubID').Value := frmWBTatPlanSel.CDS_1.FieldByName('SubID').Value;
                FieldByName('CustName').Value := frmWBTatPlanSel.CDS_1.FieldByName('CustName').Value;
                FieldByName('OrdDate').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrdDate').Value;
                FieldByName('FtyCoName').Value := frmWBTatPlanSel.CDS_1.FieldByName('FtyCoName').Value;
                FieldByName('DlyDate').Value := frmWBTatPlanSel.CDS_1.FieldByName('DlyDate').Value;
                FieldByName('C_Code').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_Code').Value;
                FieldByName('C_Name').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_Name').Value;
                FieldByName('C_Spec').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_Spec').Value;
                FieldByName('C_Width').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_Width').Value;
                FieldByName('C_GramWeight').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_GramWeight').Value;
                FieldByName('OrdPieceLen').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrdPieceLen').Value;
                FieldByName('C_YarnQty').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_YarnQty').Value;
                FieldByName('C_LatitudeSpec').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_LatitudeSpec').Value;
                FieldByName('C_LongitudeSpec').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_LongitudeSpec').Value;
                FieldByName('C_ReedNo').Value := frmWBTatPlanSel.CDS_1.FieldByName('C_ReedNo').Value;
                FieldByName('OrdPiece').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrdPiece').Value;
                FieldByName('OrdQty').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrdQty').Value;
                FieldByName('OrdSNote').Value := frmWBTatPlanSel.CDS_1.FieldByName('OrdSNote').Value;
                Post;
              end;
            end;
            Next;
          end;
        end;
        frmWBTatPlanSel.CDS_1.EnableControls;
      end;
    end;
  finally
    frmWBTatPlanSel.Free;
  end;
end;

procedure TfrmTatWBCardInPutOld.ToolButton8Click(Sender: TObject);
var
  WSql: string;
begin
  if CDS_Card.IsEmpty then
    Exit;
  if CDS_Card.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;

  WSql := '';
  CDS_Card.DisableControls;

  while CDS_Card.Locate('SSel', True, []) do
  begin
    if CDS_Card.fieldbyname('SSel').AsBoolean then
    begin
      if WSql <> '' then
      begin
        WSql := WSql + ',' + (Trim(CDS_Card.fieldbyname('WBCID').AsString));
      end
      else
      begin
        WSql := (Trim(CDS_Card.fieldbyname('WBCID').AsString));
      end;
    end;
    CDS_Card.Delete;
  end;
  CDS_Card.EnableControls;

  try
    ADOQueryCmd.Connection.BeginTrans;
//    with ADOQueryCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add('insert into Knit_Need_Up(UOperation,UType,UDataId) values(''检验'',''检验删除'',' + quotedstr(MCIIDS) + ')  ');
//      ExecSQL;
//    end;
    with ADOQueryCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_TatWB_Card_Del ');
      Sql.Add('@WBCIDS=' + quotedstr(Trim(WSql)));
      Sql.Add(',@DCode=' + Quotedstr(DCode));
      Sql.Add(',@DName=' + Quotedstr(DName));
      Open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    end;
    ADOQueryCmd.Connection.CommitTrans;

    application.MessageBox('删除成功！', '提示信息');
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmTatWBCardInPutOld.TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  with ADO_3 do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.* from Tat_WB_Formula A inner join Tat_WB_Spec B on A.WBSID=B.WBSID ');
    sql.Add(' where WB_Code=''' + Trim(CDS_card.fieldbyname('WB_Code').AsString) + '''');
    Open;
  end;
  SCreateCDS(ADO_3, CDS_3);
  SInitCDSData(ADO_3, CDS_3);
end;

end.

