unit U_ClothSCDCGAnPai;

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,
  BtnEdit, RM_BarCode, cxPC, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxSkinsCore, 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, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmClothSCDCGAnPai = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    Label3: TLabel;
    ConNo: TEdit;
    CDS_PRT: TClientDataSet;
    RM2: TRMGridReport;
    RMDBPRT: TRMDBDataSet;
    ADOQueryPrint: TADOQuery;
    DSAnPai: TDataSource;
    CDS_AnPai: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    ZhuanQty: TEdit;
    Label9: TLabel;
    Panel2: TPanel;
    CarNo: TEdit;
    Label1: TLabel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    v3Column1: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    Label2: TLabel;
    C_CodeName: TEdit;
    Label6: TLabel;
    PS: TEdit;
    Label7: TLabel;
    JXPerson: TBtnEditA;
    Button2: TButton;
    Button1: TButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column2: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource3: TDataSource;
    ClientDataSet3: TClientDataSet;
    v3Column3: TcxGridDBColumn;
    v3Column4: TcxGridDBColumn;
    v3Column5: TcxGridDBColumn;
    Label4: TLabel;
    C_Code: TEdit;
    v3Column6: TcxGridDBColumn;
    Label5: TLabel;
    Label8: TLabel;
    APPS: TEdit;
    PSSX: TEdit;
    Label10: TLabel;
    v2Column3: TcxGridDBColumn;
    v3Column7: TcxGridDBColumn;
    Button3: TButton;
    v3Column8: TcxGridDBColumn;
    v3Column9: TcxGridDBColumn;
    Label11: TLabel;
    ChouZhen: TEdit;
    v3Column10: TcxGridDBColumn;
    v3Column11: TcxGridDBColumn;
    Label12: TLabel;
    CheJian: TComboBox;
    v3Column12: TcxGridDBColumn;
    v3Column13: TcxGridDBColumn;
    v3Column14: TcxGridDBColumn;
    v3Column15: TcxGridDBColumn;
    v3Column16: TcxGridDBColumn;
    v3Column17: TcxGridDBColumn;
    Label13: TLabel;
    v3Column18: TcxGridDBColumn;
    v3Column19: TcxGridDBColumn;
    Label14: TLabel;
    APBatchNo: TEdit;
    v2Column5: TcxGridDBColumn;
    v3Column20: TcxGridDBColumn;
    v3Column21: TcxGridDBColumn;
    Button4: TButton;
    cv3Column22: TcxGridDBColumn;
    Label15: TLabel;
    DCG: TBtnEditA;
    Tv2Column1: TcxGridDBColumn;
    Tv3Column1: TcxGridDBColumn;
    Tv3Column2: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure JXPersonBtnClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv3CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure Button3Click(Sender: TObject);
    procedure v3Column8PropertiesEditValueChanged(Sender: TObject);
    procedure PSKeyPress(Sender: TObject; var Key: Char);
    procedure Button4Click(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure C_CodeNameKeyPress(Sender: TObject; var Key: Char);
    procedure DCGBtnClick(Sender: TObject);
    procedure Tv3CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
  private
    FInt, PFInt: Integer;
    FFMainID, BPFlag: string;
    procedure InitGrid();
    procedure InitForm();
    function SaveDataAP(): Boolean;
    { Private declarations }
  public
    canshu1: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}

procedure TfrmClothSCDCGAnPai.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
  WriteCxGrid('DCG13', Tv3, '坯布生产2');
end;

procedure TfrmClothSCDCGAnPai.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('DCG12', Tv2, '坯布生产');
  WriteCxGrid('DCG13', Tv3, '坯布生产');
end;

procedure TfrmClothSCDCGAnPai.InitGrid();
begin
  FFMainID := '';
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
//      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.*,C_Note,B.ConNo,C.gongyi,B.GCCode,C.C_CodeName,C.ZhenCun,C_Qty=C.ZSCQty,C.C_Code,PiQty=C.ZSCPS ');
      sql.Add(',C.pikgqty,B.LabName,C.BatchNoHZ,C.ChouZhen,C.CarType,C.C_Spec,C.C_Color');
      sql.Add(',CPName=( select TOP 1 CPName from CP_YDang X inner join CP_Type Y on X.CYType=Y.CPID where X.CYName=C.C_CodeName )');
      sql.Add(',APPS=(select count(*) from JYCon_Sub_AnPai JSA where JSA.MainId=A.MainId and JSA.CarNo=A.CarNo )');
      sql.Add(',APPSHZ=(select count(*) from JYCon_Sub_AnPai JSA where JSA.MainId=A.MainId  )');
      sql.Add(',WJYPS=isnull((select count(*) from JYCon_Sub_AnPai JSA where JSA.MainId=A.MainId and JSA.CarNo=A.CarNo ),0) - isnull((select Count(*) from WFB_MJJY_PB CR where CR.MainId=A.MainId and CR.CarNo=A.CarNo ),0) ');
      sql.Add(',JYPS=isnull((select Count(*) from WFB_MJJY_PB CR where CR.MainId=A.MainId and CR.CarNo=A.CarNo ),0) ');
      sql.Add(',JXPerson10=(select Top 1 JXPerson from JYCon_Sub_AnPai AP ');
      sql.Add(' where AP.MainId=B.MainId and AP.CarNo=A.CarNo and isnull(AP.JXPerson,'''')<>'''' Order by AP.FillTime Desc)');
      if BPFlag = 'BS' then
        sql.Add(' , CustomerNoName=(select TOP 1 X.CoHRName from Company X where X.CoName=B.KHNAME and CoType=''客户'') ')
      else
        sql.Add(' ,B.KHNAME CustomerNoName ');
      sql.Add(' from Cloth_JiTai A');
      sql.Add(' inner join Cloth_Main B on A.MainId=B.MainId');
      sql.Add(' inner join Cloth_Sub C on A.SubId=C.SubId');
      sql.Add(' where A.StopFlag=0  and B.EndFlag=0 ');
      sql.Add(' order by [dbo].[getNum](CarNo) ');
//      ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet3);
    SInitCDSData20(ADOQueryMain, ClientDataSet3);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmClothSCDCGAnPai.InitForm();
var
  fsj: string;
begin

  BPFlag := Trim(DParameters1);

  ReadCxGrid('DCG12', Tv2, '坯布生产');
  ReadCxGrid('DCG13', Tv3, '坯布生产2');
  fsj := 'select distinct Code=Null,Name=MCCJ from Machine Group by MCCJ ';
  SInitComBoxBySql(ADOQueryTemp, CheJian, False, fsj);
  InitGrid();
end;

procedure TfrmClothSCDCGAnPai.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmClothSCDCGAnPai.ConNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, ClientDataSet3);
  SInitCDSData20(ADOQueryMain, ClientDataSet3);
end;

procedure TfrmClothSCDCGAnPai.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmClothSCDCGAnPai.JXPersonBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'JXPerson';
      flagname := '机修';
      if ShowModal = 1 then
      begin
        JXPerson.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothSCDCGAnPai.Button2Click(Sender: TObject);
var
  FFDS: Integer;
  FGYCarNo: string;
begin
  if ClientDataSet3.IsEmpty then
    Exit;
  if ClientDataSet3.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end
  else
  begin
    Label10.Caption := Trim(ClientDataSet3.fieldbyname('ConNo').AsString);
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      SQL.Add(' select APPSHZ =(select count(*) from JYCon_Sub_AnPai JSA where JSA.MainId=A.MainId ) from Cloth_JiTai A ');
      sql.Add(' where A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + '''');
      sql.Add(' and A.mainID=''' + Trim(ClientDataSet3.fieldbyname('mainID').AsString) + '''');
//      ShowMessage(sql.text);
      Open;
    end;

    APPS.Text := Trim(ADOQueryTemp.fieldbyname('APPSHZ').AsString);
    PSSX.Text := Trim(ClientDataSet3.fieldbyname('PiQty').AsString);
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      SQL.Add(' select A.*');
      sql.Add(' from JYCon_Sub_AnPai A');
      sql.Add(' where A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + '''');
      sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + '''');
      sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + '''');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_AnPai);
    SInitCDSData20(ADOQueryTemp, CDS_AnPai);
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      SQL.Add(' select COUNT(JYFlag) wjps');
      sql.Add(' from JYCon_Sub_AnPai A');
      sql.Add(' where A.JYFlag=0 and A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + '''');
      sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + '''');
      sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + '''');
      Open;
    end;
    Label13.caption := '未检验匹数：' + trim(inttostr(ADOQueryTemp.fieldbyname('wjps').asinteger));
    CDS_AnPai.Last;
  end;
  if Trim(PS.Text) = '' then
  begin
    Application.MessageBox('匹数不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToInt(Trim(PS.Text), FFDS) = False then
  begin
    Application.MessageBox('匹数非法', '提示', 0);
    Exit;
  end;
  if Trim(JXPerson.Text) = '' then
  begin
    Application.MessageBox('调试机修不能为空!', '提示', 0);
    Exit;
  end;

  FFDS := 0;
  FGYCarNo := Trim(ClientDataSet3.fieldbyname('CarNo').AsString);
  ClientDataSet3.DisableControls;
  with ClientDataSet3 do
  begin
    First;
    while not Eof do
    begin
      if ClientDataSet3.FieldByName('SSel').AsBoolean = True then
      begin
        FFDS := FFDS + 1;
      end;
      ClientDataSet3.Next;
    end;
  end;
  ClientDataSet3.EnableControls;
  ClientDataSet3.Locate('CarNo', FGYCarNo, []);
  if FFDS * strtoint(PS.Text) + strtoint(APPS.Text) > StrToInt(PSSX.Text) then
  begin
    Application.MessageBox('安排匹数过多，不允许保存!', '提示', 0);
    Exit;
  end;
  Panel2.Enabled := False;
  if SaveDataAP() then
  begin
    InitGrid();
  end;
  Panel2.Enabled := true;
  CDS_AnPai.Last;
end;

function TfrmClothSCDCGAnPai.SaveDataAP(): Boolean;
var
  maxno, fPrintFile: string;
  i: Integer;
  FDate: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
  GYMainId, GYSubId, GYCarNo, GYC_Code, GYC_CodeName: string;
  GYConNo, GYXHInt, GYLabName, GYCheJian, GYBatchNOHZ: string;
  GYChouZhen, GYCarType, GYC_Spec, GYC_CPName, GYC_ZhenCun: string;
  GYC_Custom, GYC_gongyi, GYC_PiKgQty, GYapBatchNo, GC_Note: string;
begin
  cxGrid3.Enabled := False;
  FDate := FormatDateTime('yyyy-MM-dd', SGetServerDate(ADOQueryTemp));
  with ClientDataSet3 do
  begin
    First;
    while Locate('SSel', True, []) do
    begin
      GYMainId := Trim(ClientDataSet3.fieldbyname('Mainid').AsString);
      GYSubId := Trim(ClientDataSet3.fieldbyname('SubId').AsString);
      GYCarNo := Trim(ClientDataSet3.fieldbyname('CarNo').AsString);
      GYC_Code := Trim(ClientDataSet3.fieldbyname('C_Code').AsString);
      GYC_CodeName := Trim(ClientDataSet3.fieldbyname('C_CodeName').AsString);
      GYConNo := Trim(ClientDataSet3.fieldbyname('ConNo').AsString);
      GYLabName := Trim(ClientDataSet3.fieldbyname('LabName').AsString);
      GYCheJian := Trim(ClientDataSet3.fieldbyname('CheJian').AsString);
      GYBatchNOHZ := Trim(ClientDataSet3.fieldbyname('BatchNOHZ').AsString);

      GYChouZhen := Trim(ClientDataSet3.fieldbyname('ChouZhen').AsString);
      GYCarType := Trim(ClientDataSet3.fieldbyname('CarType').AsString);
      GYC_Spec := Trim(ClientDataSet3.fieldbyname('C_Spec').AsString);
      GYC_Custom := Trim(ClientDataSet3.fieldbyname('CustomerNoName').AsString);
      GYC_gongyi := Trim(ClientDataSet3.fieldbyname('gongyi').AsString);
      GYC_CPName := Trim(ClientDataSet3.fieldbyname('CPName').AsString);
      GYC_ZhenCun := Trim(ClientDataSet3.fieldbyname('ZhenCun').AsString);
      GYC_PiKgQty := Trim(ClientDataSet3.fieldbyname('PiKgQty').AsString);

      GC_Note := Trim(ClientDataSet3.fieldbyname('C_Note').AsString);
      for i := 1 to StrToInt(PS.Text) do
      begin
        try
          ADOQueryCmd.Connection.BeginTrans;
          if GetLSNo(ADOQueryCmd, maxno, BPFlag, 'JYCon_Sub_AnPai', 4, 1) = False then
          begin
            cxGrid3.Enabled := True;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('生成坯布安排流水号异常！', '提示', 0);
            exit;
          end;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            SQL.Add('select * from JYCon_Sub_AnPai where 1=2');
            Open;
          end;
          with ADOQueryCmd do
          begin
            Append;
            FieldByName('MainId').Value := Trim(GYMainId);
            FieldByName('SubId').Value := Trim(GYSubId);
            FieldByName('APId').Value := Trim(maxno);
            FieldByName('JXPerson').Value := Trim(JXPerson.Text);
            FieldByName('DCG').Value := Trim(DCG.Text);
            FieldByName('APBatchNo').Value := Trim(APBatchNo.Text);
            FieldByName('CarNo').Value := Trim(GYCarNo);
            FieldByName('CheJian').Value := Trim(GYCheJian);
            FieldByName('PRTCount').Value := 1;
            FieldByName('APDate').Value := FDate;
            FieldByName('Filler').Value := Trim(DName);
            Post;
          end;

          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' Update JYCon_Sub_AnPai Set XHInt=isnull((select Max(XHInt) from JYCon_Sub_AnPai A where A.MainId=JYCon_Sub_AnPai.MainId and A.CarNo=JYCon_Sub_AnPai.CarNo ),0)+1');
            sql.Add(' ,QDTime=(select DoTime from Cloth_JiTai JT where JT.MainId=''' + Trim(GYMainId) + ''' and CarNo=''' + Trim(GYCarNo) + '''');
            sql.Add('          and StopFlag=0 )');
            sql.Add(' where APId=''' + Trim(maxno) + '''');
            ExecSQL;
          end;
          with ADOQueryTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select XHInt from JYCon_Sub_AnPai A where A.APId=''' + Trim(maxno) + '''');
            Open;
          end;
          GYXHInt := Trim(ADOQueryTemp.fieldbyname('XHInt').AsString);
          with CDS_AnPai do
          begin
            Append;
            FieldByName('MainId').Value := Trim(GYMainId);
            FieldByName('SubId').Value := Trim(GYSubId);
            FieldByName('APId').Value := Trim(maxno);
            FieldByName('JXPerson').Value := Trim(JXPerson.Text);
            FieldByName('DCG').Value := Trim(DCG.Text);
            FieldByName('APBatchNo').Value := Trim(APBatchNo.Text);
//            FieldByName('APBatchNo').Value := ADOQueryTemp.fieldbyname('APBatchNo').Value;
            FieldByName('CarNo').Value := Trim(GYCarNo);
            FieldByName('XHInt').Value := ADOQueryTemp.fieldbyname('XHInt').Value;
            FieldByName('APDate').Value := FDate;
            FieldByName('PRTCount').Value := 1;
            Post;
          end;
          with ADOQueryTemp do
          begin
            Close;
            sql.Clear;
            SQL.Add('select * from JYCon_Sub_AnPai where APID=''' + Trim(maxno) + '''');
            sql.Add(' and CarNo=''' + Trim(GYCarNo) + '''');
            sql.Add(' and JXPerson=''' + Trim(JXPerson.Text) + '''');
            sql.Add(' and DCG=''' + Trim(DCG.Text) + '''');
            sql.Add(' and MainId=''' + Trim(GYMainId) + '''');
            sql.Add(' and SubId=''' + Trim(GYSubId) + '''');
            Open;
          end;
          if ADOQueryTemp.IsEmpty then
          begin
            cxGrid3.Enabled := True;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('打印异常，请重新选择打印，已打印出的标签有效!', '提示', 0);
            Exit;
          end;
          ADOQueryCmd.Connection.CommitTrans;
        except
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('打印异常！', '提示', 0);
          Exit;
        end;
        fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
        if FileExists(fImagePath) then
          DeleteFile(fImagePath);

        try
          if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
            CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
          if FileExists(fImagePath) then
            DeleteFile(fImagePath);
          Moudle := LoadLibrary('MakeQRBarcode.dll');
          @Makebar := GetProcAddress(Moudle, 'Make');
          @Mixtext := GetProcAddress(Moudle, 'MixText');
          Txt := Trim(maxno);
          Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
        except
          cxGrid3.Enabled := True;
          application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
          exit;
        end;
        Sleep(300);
        if Trim(GYLabName) = '有抬头标签' then
        begin
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\有抬头标签.rmf';

        end
        else if Trim(GYLabName) = '无抬头标签' then
        begin
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\无抬头标签.rmf';
        end
        else
          fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf';

        if FileExists(fPrintFile) then
        begin
          RM2.LoadFromFile(fPrintFile);
          RMVariables['QRBARCODE'] := fImagePath;
          RMVariables['PRTCS'] := '';
          RMVariables['ConNo'] := Trim(GYConNo);
          RMVariables['APID'] := Trim(maxno);
          RMVariables['C_Code'] := Trim(GYC_Code);
          RMVariables['C_CodeName'] := Trim(GYC_CodeName);
          RMVariables['JXPerson'] := Trim(JXPerson.Text);
          RMVariables['DCG'] := Trim(DCG.Text);
          RMVariables['APBatchNo'] := Trim(apbatchno.text);
          RMVariables['CarNo'] := Trim(GYCarNo);
          RMVariables['CheJian'] := Trim(GYCheJian);
          RMVariables['XHInt'] := Trim(GYXHInt);
          RMVariables['BatchNoHZ'] := Trim(GYBatchNOHZ);
          RMVariables['ChouZhen'] := Trim(GYChouZhen);
          RMVariables['CarType'] := Trim(GYCarType);
          RMVariables['C_Spec'] := Trim(GYC_Spec);
          RMVariables['CustomerNoName'] := Trim(GYC_Custom);
          RMVariables['gongyi'] := Trim(GYC_gongyi);
          RMVariables['CPName'] := Trim(GYC_CPName);
          RMVariables['ZhenCun'] := Trim(GYC_ZhenCun);
          RMVariables['PiKgQty'] := Trim(GYC_PiKgQty);
          RMVariables['C_Note'] := Trim(GC_Note);
          RM2.PrintReport;
        end
        else
        begin
          cxGrid3.Enabled := True;
          Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf'), '提示', 0);
          Exit;
        end;
      end;
      ClientDataSet3.Delete;
    end;
  end;

  FFMainID := '';
  cxGrid3.Enabled := True;
  Result := True;

end;

procedure TfrmClothSCDCGAnPai.Button1Click(Sender: TObject);
begin
  if CDS_AnPai.IsEmpty then
    Exit;
  if CDS_AnPai.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if CDS_AnPai.Locate('SSel;JYFlag', VarArrayOf([True, True]), []) then
  begin
    Application.MessageBox('已检验不能作废!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要作废数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_AnPai.DisableControls;
    with CDS_AnPai do
    begin
      while CDS_AnPai.FieldByName('SSel').AsBoolean = True do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('delete JYCon_Sub_AnPai  ');
          sql.Add(' where APId=''' + Trim(CDS_AnPai.fieldbyname('APID').AsString) + '''');
          sql.Add(' and not exists(select * from WFB_MJJY_PB A where A.MJID=JYCon_Sub_AnPai.APID)');

          sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
          sql.Add(' ' + quotedstr(trim(DName)));
          sql.Add(',getdate() ');
          sql.Add(',' + quotedstr(trim(self.Caption)));
          sql.Add(',' + quotedstr(trim('作废布票')));
          sql.Add(',' + quotedstr(trim('卷号:' + trim(CDS_AnPai.FieldByName('apid').AsString) + ' 车号:' + trim(CDS_AnPai.FieldByName('carno').AsString) + '   批号:' + trim(CDS_AnPai.FieldByName('APBatchNo').AsString) + '  MAINID:' + trim(CDS_AnPai.FieldByName('mainid').AsString))));
          sql.Add(',' + quotedstr(trim('成功')));
          sql.Add(')');
          ExecSQL;
        end;
        CDS_AnPai.Delete;
      end;
    end;
    CDS_AnPai.EnableControls;

    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    CDS_AnPai.EnableControls;
    Application.MessageBox('作废失败!', '提示', 0);
    Exit;
  end;
end;

procedure TfrmClothSCDCGAnPai.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmClothSCDCGAnPai.Tv3CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  Label10.Caption := Trim(ClientDataSet3.fieldbyname('ConNo').AsString);
  APPS.Text := Trim(ClientDataSet3.fieldbyname('APPSHZ').AsString);
  PSSX.Text := Trim(ClientDataSet3.fieldbyname('PiQty').AsString);
//  APBatchNo.Text := Trim(ClientDataSet3.fieldbyname('BatchNoHZ').AsString);
//  APBatchNo.Text := Trim(ClientDataSet3.fieldbyname('C_Code').AsString);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add(' select A.*');
    sql.Add(' from JYCon_Sub_AnPai A');
    sql.Add(' where A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + '''');
    sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + '''');
    sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_AnPai);
  SInitCDSData20(ADOQueryTemp, CDS_AnPai);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add(' select COUNT(JYFlag) wjps');
    sql.Add(' from JYCon_Sub_AnPai A');
    sql.Add(' where A.JYFlag=0 and A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + '''');
    sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + '''');
    sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + '''');
    Open;
  end;
  Label13.caption := '未检验匹数：' + trim(inttostr(ADOQueryTemp.fieldbyname('wjps').asinteger));

//  v2Column3.SortOrder := soDescending;

end;

procedure TfrmClothSCDCGAnPai.Button3Click(Sender: TObject);
var
  fPrintFile: string;
  i: Integer;
  FDate: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
  GYLabName: string;
begin
  if ClientDataSet3.IsEmpty then
    Exit;
  if CDS_AnPai.IsEmpty then
    Exit;
  if CDS_AnPai.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if CDS_AnPai.Locate('SSel;JYFlag', VarArrayOf([True, True]), []) then
  begin
    Application.MessageBox('已检验不能重打!', '提示', 0);
    Exit;
  end;

  with CDS_AnPai do
  begin
    while CDS_AnPai.Locate('SSel', true, []) do
    begin
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from Cloth_Main where Mainid=''' + Trim(CDS_AnPai.fieldbyname('MainId').AsString) + '''');
        Open;
      end;
      GYLabName := Trim(ADOQueryTemp.fieldbyname('LabName').AsString);
      CDS_AnPai.Edit;
      CDS_AnPai.FieldByName('PRTFlag').Value := 1;
      CDS_AnPai.FieldByName('PRTCount').Value := 2;
      CDS_AnPai.Post;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('UPdate JYCon_Sub_AnPai Set PRTFlag=1,PRTCount=2 ');
        sql.Add(' where APId=''' + Trim(CDS_AnPai.fieldbyname('APID').AsString) + '''');
        ExecSQL;
      end;
      try
        Moudle := LoadLibrary('MakeQRBarcode.dll');
        @Makebar := GetProcAddress(Moudle, 'Make');
        @Mixtext := GetProcAddress(Moudle, 'MixText');
        Txt := Trim(CDS_AnPai.fieldbyname('APId').AsString);
        fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
        if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
          CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
        if FileExists(fImagePath) then
          DeleteFile(fImagePath);
        Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
      except
        application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
        exit;
      end;

      if Trim(GYLabName) = '有抬头标签' then
      begin
        fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\有抬头标签.rmf';
      end
      else if Trim(GYLabName) = '无抬头标签' then
      begin
        fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\无抬头标签.rmf';
      end
      else
        fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf';

      if FileExists(fPrintFile) then
      begin
        with ADOQueryPrint do
        begin
          Close;
          sql.Clear;
          sql.Add('select CustomerNoName=B.KHName,A.*,B.*, ');
          sql.Add(' AA.APID,A.ZhuanQty,AA.SCPerson,AA.CarNo,AA.CheJian ,AA.XHInt,AA.JXPerson,AA.APBatchNo,AA.DCG');
          sql.Add(',CPName=( select TOP 1 CPName from CP_YDang X inner join CP_Type Y on X.CYType=Y.CPID where X.CYName=A.C_CodeName )');
          sql.Add(' from JYCon_Sub_AnPai AA');
          sql.Add(' inner join Cloth_Sub A on AA.SubId=A.SubId and AA.Mainid=A.MainId');
          sql.Add(' inner join Cloth_Main B on AA.MainId=B.MainId ');
          sql.Add(' where AA.APId=''' + Trim(CDS_AnPai.fieldbyname('APID').AsString) + '''');
//          ShowMessage(sql.text);
          Open;
        end;
        RM2.LoadFromFile(fPrintFile);
        RMVariables['QRBARCODE'] := fImagePath;
        RMVariables['PRTCS'] := '2';
        RMVariables['ConNo'] := Trim(ADOQueryPrint.fieldbyname('ConNo').AsString);
        RMVariables['APID'] := Trim(ADOQueryPrint.fieldbyname('APID').AsString);
        RMVariables['C_Code'] := Trim(ADOQueryPrint.fieldbyname('C_Code').AsString);
        RMVariables['C_CodeName'] := Trim(ADOQueryPrint.fieldbyname('C_CodeName').AsString);
        RMVariables['CustomerNoName'] := Trim(ADOQueryPrint.fieldbyname('CustomerNoName').AsString);
        RMVariables['JXPerson'] := Trim(ADOQueryPrint.fieldbyname('JXPerson').AsString);
        RMVariables['DCG'] := Trim(ADOQueryPrint.fieldbyname('DCG').AsString);
        RMVariables['CarNo'] := Trim(ADOQueryPrint.fieldbyname('CarNo').AsString);
        RMVariables['CheJian'] := Trim(ADOQueryPrint.fieldbyname('CheJian').AsString);
        RMVariables['XHInt'] := Trim(ADOQueryPrint.fieldbyname('XHInt').AsString);
        RMVariables['BatchNoHZ'] := Trim(ADOQueryPrint.fieldbyname('BatchNoHZ').AsString);
        RMVariables['ChouZhen'] := Trim(ADOQueryPrint.fieldbyname('ChouZhen').AsString);
        RMVariables['CarType'] := Trim(ADOQueryPrint.fieldbyname('CarType').AsString);
        RMVariables['C_Spec'] := Trim(ADOQueryPrint.fieldbyname('C_Spec').AsString);
        RMVariables['C_Color'] := Trim(ADOQueryPrint.fieldbyname('C_Color').AsString);
        RMVariables['gongyi'] := Trim(ADOQueryPrint.fieldbyname('gongyi').AsString);
        RMVariables['APBatchNo'] := Trim(ADOQueryPrint.fieldbyname('APBatchNo').AsString);
        RMVariables['CPName'] := Trim(ADOQueryPrint.fieldbyname('CPName').AsString);
        RMVariables['ZhenCun'] := Trim(ADOQueryPrint.fieldbyname('ZhenCun').AsString);
        RMVariables['PiKgQty'] := Trim(ADOQueryPrint.fieldbyname('PiKgQty').AsString);
        RMVariables['C_Note'] := Trim(ADOQueryPrint.fieldbyname('C_Note').AsString);
        RM2.PrintReport;
      end
      else
      begin
        Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf'), '提示', 0);
        Exit;
      end;
      CDS_AnPai.Edit;
      CDS_AnPai.FieldByName('SSel').Value := false;

    end;
  end;
end;

procedure TfrmClothSCDCGAnPai.v3Column8PropertiesEditValueChanged(Sender: TObject);
var
  mvale: Boolean;
  fsj: string;
begin
  mvale := TcxCheckBox(Sender).EditingValue;
  if mvale = True then
  begin
//    APBatchNo.Text := Trim(ClientDataSet3.fieldbyname('C_Code').AsString);
    if Trim(FFMainID) = '' then
    begin
      FFMainID := Trim(ClientDataSet3.fieldbyname('Mainid').AsString)
    end
    else
    begin
      if Trim(FFMainID) <> Trim(ClientDataSet3.fieldbyname('Mainid').AsString) then
      begin
        with ClientDataSet3 do
        begin
          Edit;
          FieldByName('SSel').Value := False;
        end;
        Application.MessageBox('不能选择不同的订单号!', '提示', 0);
        Exit;
      end;
    end;
    Label10.Caption := Trim(ClientDataSet3.fieldbyname('ConNo').AsString);
    APPS.Text := Trim(ClientDataSet3.fieldbyname('APPSHZ').AsString);
    PSSX.Text := Trim(ClientDataSet3.fieldbyname('PiQty').AsString);
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      SQL.Add(' select A.*');
      sql.Add(' from JYCon_Sub_AnPai A');
      sql.Add(' where A.SubId=''' + Trim(ClientDataSet3.fieldbyname('SubId').AsString) + '''');
      sql.Add(' and A.MainId=''' + Trim(ClientDataSet3.fieldbyname('MainId').AsString) + '''');
      sql.Add(' and A.CarNo=''' + Trim(ClientDataSet3.fieldbyname('CarNo').AsString) + '''');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_AnPai);
    SInitCDSData20(ADOQueryTemp, CDS_AnPai);
  end;
  fsj := Trim(ClientDataSet3.fieldbyname('JTID').AsString);
  with ClientDataSet3 do
  begin
    Edit;
    FieldByName('SSel').Value := mvale;
  end;
  if mvale = True then
  begin
    JXPerson.Text := Trim(ClientDataSet3.fieldbyname('JXPerson10').AsString);
  end
  else
  begin
    ClientDataSet3.Locate('SSel', True, []);
    JXPerson.Text := Trim(ClientDataSet3.fieldbyname('JXPerson10').AsString);
  end;
  if ClientDataSet3.Locate('SSel', True, []) = False then
  begin
    JXPerson.Text := '';
    FFMainID := '';
  end;
  ClientDataSet3.Locate('JTID', fsj, []);
end;

procedure TfrmClothSCDCGAnPai.PSKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Button2.Click;
  end;
end;

procedure TfrmClothSCDCGAnPai.Button4Click(Sender: TObject);
var
  fPrintFile: string;
  i: Integer;
  FDate: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
  GYLabName: string;
begin
  if ClientDataSet3.IsEmpty then
    Exit;
  if CDS_AnPai.IsEmpty then
    Exit;
  if CDS_AnPai.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if CDS_AnPai.Locate('SSel;JYFlag', VarArrayOf([True, True]), []) then
  begin
    Application.MessageBox('已检验不能重打!', '提示', 0);
    Exit;
  end;

  with CDS_AnPai do
  begin
    while CDS_AnPai.Locate('SSel', true, []) do
    begin
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from Cloth_Main where Mainid=''' + Trim(CDS_AnPai.fieldbyname('MainId').AsString) + '''');
        Open;
      end;
      GYLabName := Trim(ADOQueryTemp.fieldbyname('LabName').AsString);
      CDS_AnPai.Edit;
      CDS_AnPai.FieldByName('PRTFlag').Value := 1;
      CDS_AnPai.FieldByName('PRTCount').Value := 2;
      CDS_AnPai.Post;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('UPdate JYCon_Sub_AnPai Set PRTFlag=1,PRTCount=2 ');
        sql.Add(',APBatchNo =' + quotedstr(Trim(APBatchNo.Text)));
        sql.Add(' where APId=''' + Trim(CDS_AnPai.fieldbyname('APID').AsString) + '''');
        ExecSQL;
      end;
      try
        Moudle := LoadLibrary('MakeQRBarcode.dll');
        @Makebar := GetProcAddress(Moudle, 'Make');
        @Mixtext := GetProcAddress(Moudle, 'MixText');
        Txt := Trim(CDS_AnPai.fieldbyname('APId').AsString);
        fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
        if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
          CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
        if FileExists(fImagePath) then
          DeleteFile(fImagePath);
        Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
      except
        application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
        exit;
      end;

      if Trim(GYLabName) = '有抬头标签' then
      begin
        fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\有抬头标签.rmf';
      end
      else if Trim(GYLabName) = '无抬头标签' then
      begin
        fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\无抬头标签.rmf';
      end
      else
        fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf';

      if FileExists(fPrintFile) then
      begin
        with ADOQueryPrint do
        begin
          Close;
          sql.Clear;
          sql.Add('select A.*,B.*, ');
          sql.Add(' AA.APID,A.ZhuanQty,AA.SCPerson,AA.CarNo,AA.CheJian ,AA.XHInt,AA.JXPerson,AA.APBatchNo,AA.DCG');
          sql.Add(',CPName=( select TOP 1 CPName from CP_YDang X inner join CP_Type Y on X.CYType=Y.CPID where X.CYName=A.C_CodeName )');
          sql.Add(' ,CustomerNoName=(select top 1 CustomerNoName  from JYOrderCon_Main_PB X where X.MainId=B.ConMainId) ');
          sql.Add(' from JYCon_Sub_AnPai AA');
          sql.Add(' inner join Cloth_Sub A on AA.SubId=A.SubId and AA.Mainid=A.MainId');
          sql.Add(' inner join Cloth_Main B on AA.MainId=B.MainId ');
          sql.Add(' where AA.APId=''' + Trim(CDS_AnPai.fieldbyname('APID').AsString) + '''');
          Open;
        end;
        RM2.LoadFromFile(fPrintFile);
        RMVariables['QRBARCODE'] := fImagePath;
        RMVariables['PRTCS'] := '2';
        RMVariables['ConNo'] := Trim(ADOQueryPrint.fieldbyname('ConNo').AsString);
        RMVariables['APID'] := Trim(ADOQueryPrint.fieldbyname('APID').AsString);
        RMVariables['C_Code'] := Trim(ADOQueryPrint.fieldbyname('C_Code').AsString);
        RMVariables['C_CodeName'] := Trim(ADOQueryPrint.fieldbyname('C_CodeName').AsString);
        RMVariables['CustomerNoName'] := Trim(ADOQueryPrint.fieldbyname('CustomerNoName').AsString);
        RMVariables['JXPerson'] := Trim(ADOQueryPrint.fieldbyname('JXPerson').AsString);
        RMVariables['DCG'] := Trim(ADOQueryPrint.fieldbyname('DCG').AsString);
        RMVariables['CarNo'] := Trim(ADOQueryPrint.fieldbyname('CarNo').AsString);
        RMVariables['CheJian'] := Trim(ADOQueryPrint.fieldbyname('CheJian').AsString);
        RMVariables['XHInt'] := Trim(ADOQueryPrint.fieldbyname('XHInt').AsString);
        RMVariables['BatchNoHZ'] := Trim(ADOQueryPrint.fieldbyname('BatchNoHZ').AsString);
        RMVariables['ChouZhen'] := Trim(ADOQueryPrint.fieldbyname('ChouZhen').AsString);
        RMVariables['CarType'] := Trim(ADOQueryPrint.fieldbyname('CarType').AsString);
        RMVariables['C_Spec'] := Trim(ADOQueryPrint.fieldbyname('C_Spec').AsString);
        RMVariables['C_Color'] := Trim(ADOQueryPrint.fieldbyname('C_Color').AsString);
        RMVariables['gongyi'] := Trim(ADOQueryPrint.fieldbyname('gongyi').AsString);
        RMVariables['APBatchNo'] := Trim(ADOQueryPrint.fieldbyname('APBatchNo').AsString);
        RMVariables['CPName'] := Trim(ADOQueryPrint.fieldbyname('CPName').AsString);
        RMVariables['ZhenCun'] := Trim(ADOQueryPrint.fieldbyname('ZhenCun').AsString);
        RMVariables['PiKgQty'] := Trim(ADOQueryPrint.fieldbyname('PiKgQty').AsString);
//        RM2.PrintReport;
      end
      else
      begin
        Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\坯布标签AP.rmf'), '提示', 0);
        Exit;
      end;
      CDS_AnPai.Edit;
      CDS_AnPai.FieldByName('SSel').Value := false;
      CDS_AnPai.FieldByName('APBatchNo').Value := Trim(APBatchNo.Text);
    end;
  end;
end;

procedure TfrmClothSCDCGAnPai.ConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    TBRafresh.Click();
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, ClientDataSet3);
  SInitCDSData20(ADOQueryMain, ClientDataSet3);
end;

procedure TfrmClothSCDCGAnPai.C_CodeNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    TBRafresh.Click();
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, ClientDataSet3);
  SInitCDSData20(ADOQueryMain, ClientDataSet3);
end;

procedure TfrmClothSCDCGAnPai.DCGBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'SCPerson';
      flagname := '挡车工';
      if ShowModal = 1 then
      begin
        DCG.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothSCDCGAnPai.Tv3CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  if AViewInfo.GridRecord.Values[Tv3Column1.Index] < 20 then
    ACanvas.Brush.Color := $DAEDFF;
end;

end.

