unit U_TatWBCardInPut;

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,
  dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, BtnEdit, U_BaseInput,
  System.ImageList, Vcl.ImgList, dxScrollbarAnnotations, cxImageList;

type
  TfrmTatWBCardInPut = class(TfrmBaseInput)
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    RMDB_1: TRMDBDataSet;
    Panel2: TPanel;
    DS_Card: TDataSource;
    CDS_Card: TClientDataSet;
    ADOQueryPrint: TADOQuery;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N3: TMenuItem;
    Panel4: TPanel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    V2Column1: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    TV2Column4: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    TV2Column1: TcxGridDBColumn;
    TV2Column2: TcxGridDBColumn;
    TV2Column3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    ToolButton1: TToolButton;
    ToolButton8: TToolButton;
    ToolButton2: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label8: TLabel;
    Label9: TLabel;
    Label11: TLabel;
    Label2: TLabel;
    Label15: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label4: TLabel;
    WB_YarnQty: TEdit;
    edtCardQty: TEdit;
    WB_Spec: TEdit;
    WB_Type: TComboBox;
    WB_ClothPiece: TEdit;
    WB_MachNo: TBtnEditC;
    WB_Macher: TBtnEditC;
    WB_YarnLen: TEdit;
    Note: TRichEdit;
    GPM_2: TcxGridPopupMenu;
    TV2Column5: TcxGridDBColumn;
    Label7: TLabel;
    WBData: TDateTimePicker;
    Label10: TLabel;
    FtyCoName: TBtnEditC;
    Label13: TLabel;
    WB_BatchNo: TEdit;
    Label14: TLabel;
    WB_ClothNameL: TBtnEditC;
    Label16: TLabel;
    WB_YarnWidth: TEdit;
    TV2Column6: TcxGridDBColumn;
    Label17: TLabel;
    WB_YarnBatchNo: TBtnEditC;
    Label18: TLabel;
    WBCNOL: TEdit;
    TV2Column8: TcxGridDBColumn;
    TV2Column9: TcxGridDBColumn;
    Label19: TLabel;
    WB_Code: TBtnEditC;
    Label1: TLabel;
    WB_YarnArrQty: TEdit;
    ToolButton3: TToolButton;
    TV2Column10: TcxGridDBColumn;
    TV2Column7: TcxGridDBColumn;
    WB_Len: TBtnEditC;
    WB_Clothcode: TEdit;
    TV2Column11: TcxGridDBColumn;
    Panel3: TPanel;
    Label12: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    ConNo: TEdit;
    Edit1: TEdit;
    WB_ClothName: TEdit;
    OrderNos: TEdit;
    BatchNo: TEdit;
    WBCID: TEdit;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    TBRafresh: TToolButton;
    Label27: TLabel;
    ConNoL: TEdit;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    TV2Column12: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
//    procedure FormShow(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure WB_MachNoBtnDnClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure FtyCoNameBtnUpClick(Sender: TObject);
    procedure FtyCoNameBtnDnClick(Sender: TObject);
    procedure WB_ClothNameLBtnUpClick(Sender: TObject);
    procedure WB_ClothNameLBtnDnClick(Sender: TObject);
    procedure WB_CodeBtnUpClick(Sender: TObject);
    procedure WB_CodeBtnDnClick(Sender: TObject);
//    procedure ToolButton3Click(Sender: TObject);
    procedure WB_MachNoBtnUpClick(Sender: TObject);
    procedure WB_YarnBatchNoBtnUpClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
   // procedure WB_YarnBatchNo1Change(Sender: TObject);
  private
    function TestData(): Boolean;
    procedure PrtDate(MWBCID: string);

    procedure InitCard();
    { Private declarations }
  public
    FWBCNO: string;
    WBOrderNo: string;
    WBC_Name: string;
    { Public declarations }
  end;

var
  frmTatWBCardInPut: TfrmTatWBCardInPut;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_TatPlanSel, U_CompanySel,
  U_TatClothInfoSel, U_YarnInfoSel, U_WBSpecEditSel, U_YarnStkSel,
  U_SalesContractSel;

{$R *.dfm}

function TfrmTatWBCardInPut.TestData(): Boolean;
begin
  try

//    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_YarnBatchNo.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
    begin
      WB_ClothPiece.Text := '0';
    end;
//    if Trim(WB_Type.Text) = '' then
//      raise Exception.Create('类型不能为空！');
    Result := True;
  except
    Result := false;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmTatWBCardInPut.InitCard();
var
  WhereStr: string;
  i: Integer;
  Ctrl: TControl;
  EditCtrl: TEdit;
  CtrlText: string;
  DBField: string; // 数据库字段名（直接使用控件Name）
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    SQL.ADD('select A.*');
    SQL.ADD('from Tat_WB_Card A');

    // 基础固定条件
    WhereStr := 'where isnull(Status,''0'')<>''-1'' and WBCNO=' + quotedstr(Trim(WBOrderNo)) + ' and A.WBData>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''' + ' and A.WBData<''' + Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''';

    // 遍历Panel3中的所有TEdit控件（搜索条件框）
    for i := 0 to Panel3.ControlCount - 1 do
    begin
      Ctrl := Panel3.Controls[i];
      if Ctrl is TEdit then // 只处理编辑框
      begin
        EditCtrl := TEdit(Ctrl);
        CtrlText := Trim(EditCtrl.Text);
        if CtrlText = '' then
          Continue; // 空值不参与搜索

        // 直接用控件Name作为数据库字段名（因为Name与字段名完全一致）
        DBField := 'A.' + EditCtrl.Name; // 拼接表别名A.，如A.WB_ClothName

        // 根据Tag属性判断查询方式（Tag=1：模糊；Tag=0：精确）
        if EditCtrl.Tag = 1 then
          WhereStr := WhereStr + ' and ' + DBField + ' like ' + quotedstr('%' + CtrlText + '%')
        else
          WhereStr := WhereStr + ' and ' + DBField + ' = ' + quotedstr(CtrlText);
      end;
    end;

    // 添加完整条件
    SQL.Add(WhereStr);
    Open;

    // 原有赋值逻辑
    WBData.Date := Date;
    BegDate.DateTime := Date - 6;
    enddate.DateTime := Date;
  end;

  SCreateCDS(ADOQueryTemp, CDS_Card);
  SInitCDSData(ADOQueryTemp, CDS_Card);
end;

procedure TfrmTatWBCardInPut.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 TfrmTatWBCardInPut.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
end;

//procedure TfrmTatWBCardInPut.FormShow(Sender: TObject);
//begin
//  inherited;
//  ReadCxGrid(Trim(self.Caption) + 'Tv2', Tv2, '坯布轴卡');
//  WBData.DateTime := SGetServerDate(ADOQueryTemp);
//  if Trim(FWBCNO) = '' then
//  begin
//    if GetLSNo(ADOQueryTemp, FWBCNO, 'QJ', 'Tat_WB_Card', 3, 1) = False then
//    begin
//      raise Exception.Create('迁经单号失败!');
//    end;
//  end;
//  WBCNO.Text := FWBCNO;
//  InitCard();
//end;

procedure TfrmTatWBCardInPut.FormShow(Sender: TObject);
begin
//  inherited;
  InitCard();
end;

procedure TfrmTatWBCardInPut.FtyCoNameBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).TxtCode := '';
  TBtnEditC(Sender).Text := '';
end;

procedure TfrmTatWBCardInPut.FtyCoNameBtnUpClick(Sender: TObject);
begin
  try
    frmCompanySel := TfrmCompanySel.Create(Application);
    with frmCompanySel do
    begin
      FCoType := '供应商';
      if ShowModal = 1 then
      begin
        FtyCoName.TxtCode := Trim(CDS_1.fieldbyname('CoCode').AsString);
        FtyCoName.Text := Trim(CDS_1.fieldbyname('CoAbbrName').AsString);
      end;
    end;
  finally
    frmCompanySel.Free;
  end;
end;

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

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

procedure TfrmTatWBCardInPut.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmTatWBCardInPut.TBRafreshClick(Sender: TObject);
begin
  InitCard();
end;

procedure TfrmTatWBCardInPut.TBSaveClick(Sender: TObject);
var
  MWBCID: string;
  i, j: integer;
begin
  if TestData() = false then
    exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
//////////////////            插入轴卡               //////////////////////
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' insert into Tat_WB_Card(WBCID, WBCNO,WB_YarnBatchNo,WB_Clothcode,WB_Code,WB_Spec,WB_YarnQty,WB_YarnArrQty,WB_Len,WB_YarnLen,WB_Macher ');
      sql.Add(' ,WBData,FtyCoNo,FtyCoName,WB_YarnWidth,WB_ClothName,WB_BatchNo');
      sql.Add(' ,WB_MachNo,WB_ClothPiece,WB_Type,Note,FillId,Filler,ConNo) values');
      //ShowMessage(SQL.TEXT);

      for i := 1 to StrToIntdef(edtCardQty.Text, 1) do
      begin
        if GetLSNo(ADOQueryTemp, MWBCID, 'ZK', 'Tat_WB_Card', 3, 1) = False then
        begin
          raise Exception.Create('取布票流水号失败!');
        end;
        if i > 1 then
          sql.Add(',');
        sql.Add(' (' + Quotedstr(Trim(MWBCID)));
        sql.Add(',' + Quotedstr(Trim(WBCNOL.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_YarnBatchNo.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Clothcode.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Code.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Spec.Text)));
        sql.Add(',' + (Trim(WB_YarnQty.Text)));
        sql.Add(',' + Quotedstr(WB_YarnArrQty.Text));
        sql.Add(',' + Quotedstr(Trim(WB_Len.Text)));
        sql.Add(',' + (Trim(WB_YarnLen.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_Macher.Text)));
        sql.Add(',' + Quotedstr(Trim(FormatDateTime('yyyy-MM-dd', WBData.DateTime))));
        sql.Add(',' + Quotedstr(Trim(FtyCoName.TxtCode)));
        sql.Add(',' + Quotedstr(Trim(FtyCoName.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_YarnWidth.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_ClothNameL.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_BatchNo.Text)));
        sql.Add(',' + Quotedstr(Trim(WB_MachNo.Text)));
        sql.Add(',' + (Trim(WB_ClothPiece.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(ConNoL.Text)));
        sql.Add(' )');
        //ShowMessage(SQL.TEXT);
      end;

      ExecSQL;
    end;

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

procedure TfrmTatWBCardInPut.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;
          //ShowMessage(SQL.TEXT);
        end;
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

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

procedure TfrmTatWBCardInPut.ToolButton4Click(Sender: TObject);
begin
  try
    frmSalesContractSel := TfrmSalesContractSel.Create(Application);
    with frmSalesContractSel do
    begin
      if ShowModal = 1 then
      begin
        self.ConNoL.Text := frmSalesContractSel.CDS_1.fieldbyname('ConNo').AsString; //合同号
//        self.Custname.Text := frmSalesContractSel.CDS_1.fieldbyname('BuyName').AsString; //客户
//        self.OurCoName.Text := frmSalesContractSel.CDS_1.fieldbyname('SellName').AsString;
        self.WB_Clothcode.Text := frmSalesContractSel.CDS_1.fieldbyname('C_Code').AsString; //编号
        self.WB_ClothNameL.Text := frmSalesContractSel.CDS_1.fieldbyname('C_Name').AsString; //品名
//        self.OrdQty.Text := frmSalesContractSel.CDS_1.fieldbyname('ConQty').AsString;  //总数量

      end;
    end;
  finally
    frmSalesContractSel.Free;
  end;

end;

procedure TfrmTatWBCardInPut.ToolButton5Click(Sender: TObject);
begin
  try
    frmTatPlanSel := TfrmTatPlanSel.Create(Application);
    with frmTatPlanSel do
    begin
      if ShowModal = 1 then
      begin
        Self.WB_ClothNameL.Text := frmTatPlanSel.CDS_1.fieldbyname('C_Name').AsString;
        Self.WB_YarnWidth.Text := frmTatPlanSel.CDS_1.fieldbyname('C_Width').AsString;
        Self.WB_Clothcode.Text := frmTatPlanSel.CDS_1.fieldbyname('C_Code').AsString;
      end;
    end;
  finally
    frmTatPlanSel.Free;
  end;
end;

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

procedure TfrmTatWBCardInPut.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 TfrmTatWBCardInPut.WB_ClothNameLBtnDnClick(Sender: TObject);
begin
  Self.WB_ClothName.Text := '';
  Self.WB_YarnWidth.Text := '';
end;

procedure TfrmTatWBCardInPut.WB_ClothNameLBtnUpClick(Sender: TObject);
begin
  try
    frmTatClothInfoSel := TfrmTatClothInfoSel.Create(Application);
    with frmTatClothInfoSel do
    begin
      if ShowModal = 1 then
      begin
        Self.ConNoL.Text := '';
      end;
      begin
        Self.WB_ClothNameL.Text := frmTatClothInfoSel.CDS_1.fieldbyname('C_Name').AsString;
        Self.WB_YarnWidth.Text := frmTatClothInfoSel.CDS_1.fieldbyname('C_Width').AsString;
        Self.WB_Clothcode.Text := frmTatClothInfoSel.CDS_1.fieldbyname('C_Code').AsString;
      end;
    end;
  finally
    frmTatClothInfoSel.Free;
  end;
end;

procedure TfrmTatWBCardInPut.WB_CodeBtnDnClick(Sender: TObject);
begin
//  TBtnEditC(Sender).Text := '';
//  TBtnEditC(Sender).TxtCode := '';

end;

procedure TfrmTatWBCardInPut.WB_CodeBtnUpClick(Sender: TObject);
begin
//  try
//    frmWBSpecEditSel := TfrmWBSpecEditSel.Create(Application);
//    with frmWBSpecEditSel do
//    begin
//      if ShowModal = 1 then
//      begin
//        Self.WB_Code.Text := CDS_Main.FieldByName('WB_Code').AsString;
//        Self.WB_Spec.Text := CDS_Main.FieldByName('WB_Spec').AsString;
//        Self.WB_YarnQty.Text := CDS_Main.FieldByName('WB_YarnQty').AsString;
//
//      end;
//    end;
//  finally
//    frmWBSpecEditSel.Free;
//  end;
end;

procedure TfrmTatWBCardInPut.WB_MachNoBtnDnClick(Sender: TObject);
begin
//  TBtnEditC(Sender).Text := '';
//  TBtnEditC(Sender).TxtCode := '';
end;

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

end;

procedure TfrmTatWBCardInPut.WB_YarnBatchNoBtnUpClick(Sender: TObject);
begin
//  try
//    frmYarnStkSel := TfrmYarnStkSel.Create(Application);
//    with frmYarnStkSel do
//    begin
//      FstkName := '纱线';
//      if ShowModal = 1 then
//      begin
//        Self.WB_YarnBatchNo.Text := rtvalues[0];
//      end;
//    end;
//  finally
//    frmYarnStkSel.Free;
//  end;
end;

end.

