unit U_ShuttleClothSCList;

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,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmShuttleClothSCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    ConNo: TEdit;
    Label5: TLabel;
    C_CodeName: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    RMDBPRT: TRMDBDataSet;
    TBCopy: TToolButton;
    TBView: TToolButton;
    v1Column19: TcxGridDBColumn;
    RMDBPZ: TRMDBDataSet;
    CDS_PZ: TClientDataSet;
    CDS_SJ: TClientDataSet;
    RMDBSJ: TRMDBDataSet;
    v1Column21: TcxGridDBColumn;
    Label10: TLabel;
    C_Code: TEdit;
    v1Column22: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    RMDBDataSet1: TRMDBDataSet;
    ClientDataSet1: TClientDataSet;
    Label6: TLabel;
    BatchNoHZ: TEdit;
    v1Column31: TcxGridDBColumn;
    v1Column30: TcxGridDBColumn;
    ComboBox1: TComboBox;
    v1Column34: TcxGridDBColumn;
    KHNAME: TEdit;
    Label7: TLabel;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure conPress(Sender: TObject; var Key: Char);
    procedure TBViewClick(Sender: TObject);
    procedure TBCopyClick(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
  private
    FInt, PFInt: Integer;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitButton();
    { Private declarations }
  public
    canshu1, FCheJian: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ShuttleClothSCInPut;

{$R *.dfm}

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

procedure TfrmShuttleClothSCList.InitButton();
begin

  if Trim(canshu1) = '查询' then
  begin
    TBAdd.Visible := False;
    TBCopy.Visible := False;
    TBEdit.Visible := False;
    TBDel.Visible := False;
  end;

end;

procedure TfrmShuttleClothSCList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('坯布生产计划单', Tv1, '坯布生产管理');
end;

procedure TfrmShuttleClothSCList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*  ');
      sql.Add(' ,DDZT=(case when BegFlag=0 then ''待开始'' else (case when EndFlag=0 then ''已开始'' else ''已结束'' end ) end) ');
      sql.Add(' from Cloth_Main A inner join CLoth_Sub B on A.Mainid=B.MainId');
      sql.Add(' where A.FillTIme>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and A.FillTIme<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''');
      if Trim(canshu1) = '录入' then
        sql.Add(' and A.Filler=' + quotedstr(DName));
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmShuttleClothSCList.InitForm();
begin
  InitButton();
  ReadCxGrid('坯布生产计划单', Tv1, '坯布生产管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 30;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  InitGrid();
end;

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

procedure TfrmShuttleClothSCList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmClothSCInPut := TfrmClothSCInPut.Create(Application);
    with frmClothSCInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FSubId := Trim(Self.Order_Main.fieldbyname('SubId').AsString);
      if ShowModal = 1 then
      begin
        InitGrid();
        Self.Order_Main.Locate('MainId', frmClothSCInPut.FMainId, []);
      end;
    end;
  finally
    frmClothSCInPut.Free;
  end;
end;

procedure TfrmShuttleClothSCList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*');
    sql.Add('from Cloth_AnPai A');
    sql.Add(' where A.SubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
    sql.Add(' and A.MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    //ShowMessage(SQL.Text);
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Application.MessageBox('已产生安排数据不能删除!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin
    Order_Main.Delete;
  end;
end;

function TfrmShuttleClothSCList.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Cloth_Sub where SubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
      sql.Add('delete Cloth_JiTai where SubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
      ExecSQL;
    end;

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Cloth_Sub where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      Open;
    end;
    if ADOQueryTemp.IsEmpty then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('delete Cloth_Main where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
        ExecSQL;
      end;
    end;
    if Trim(Order_Main.fieldbyname('SubId').AsString) = '' then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('delete Cloth_Main where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
        ExecSQL;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Cloth_PaiZhen where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Cloth_YCL_PB where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := False;
    Application.MessageBox('数据删除异常！', '提示', 0);
  end;
end;

procedure TfrmShuttleClothSCList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel('坯布生产单', cxGrid1);
end;

procedure TfrmShuttleClothSCList.TBPrintClick(Sender: TObject);
var
  fPrintFile, FWeiZhi: string;
  i, j, k: integer;
begin
  if Order_Main.IsEmpty then
    Exit;
  ExportFtErpFile(trim(ComboBox1.Text) + '.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + trim(ComboBox1.Text) + '.rmf';

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select  PZNote1=PZNote,WeiZhi1=WeiZhi,SPZ1=PZ1,SPZ2=PZ2,SPZ3=PZ3,SPZ4=PZ4,SPZ5=PZ5,SPZ6=PZ6,SPZ7=PZ7,SPZ8=PZ8,SPZ9=PZ9,SPZ10=PZ10 ');
    sql.Add(' ,SPZ11=PZ11,SPZ12=PZ12,SPZ13=PZ13,SPZ14=PZ14,SPZ15=PZ15,SPZ16=PZ16,SPZ17=PZ17,SPZ18=PZ18,SPZ19=PZ19,SPZ20=PZ20 ');
    sql.Add(' ,SPZ21=PZ21,SPZ22=PZ22,SPZ23=PZ23,SPZ24=PZ24,SPZ25=PZ25,SPZ26=PZ26,SPZ27=PZ27,SPZ28=PZ28,SPZ29=PZ29,SPZ30=PZ30 ');
    sql.Add(' ,SPZ31=PZ31,SPZ32=PZ32,SPZ33=PZ33,SPZ34=PZ34,SPZ35=PZ35,SPZ36=PZ36,SPZ37=PZ37, SPZ38=PZ38, SPZ39=PZ39, SPZ40=PZ40 ');
    sql.Add(' ,SPZ41=PZ41, SPZ42=PZ42, SPZ43=PZ43, SPZ44=PZ44, SPZ45=PZ45, SPZ46=PZ46, SPZ47=PZ47, SPZ48=PZ48, SPZ49=PZ49, SPZ50=PZ50 ');
    sql.Add(' ,SPZ51=PZ51, SPZ52=PZ52, SPZ53=PZ53, SPZ54=PZ54, SPZ55=PZ55, SPZ56=PZ56, SPZ57=PZ57, SPZ58=PZ58, SPZ59=PZ59, SPZ60=PZ60');
    sql.Add(' ,SPZ61=PZ61, SPZ62=PZ62, SPZ63=PZ63, SPZ64=PZ64, SPZ65=PZ65, SPZ66=PZ66, SPZ67=PZ67, SPZ68=PZ68, SPZ69=PZ69, SPZ70=PZ70');
    sql.Add(' ,SPZ71=PZ71, SPZ72=PZ72, SPZ73=PZ73, SPZ74=PZ74, SPZ75=PZ75, SPZ76=PZ76, SPZ77=PZ77, SPZ78=PZ78, SPZ79=PZ79, SPZ80=PZ80');
    sql.Add(' ,SPZ81=PZ81, SPZ82=PZ82, SPZ83=PZ83, SPZ84=PZ84, SPZ85=PZ85, SPZ86=PZ86, SPZ87=PZ87, SPZ88=PZ88, SPZ89=PZ89, SPZ90=PZ90');
    sql.Add(' ,SPZ91=PZ91, SPZ92=PZ92, SPZ93=PZ93, SPZ94=PZ94, SPZ95=PZ95, SPZ96=PZ96, SPZ97=PZ97, SPZ98=PZ98, SPZ99=PZ99, SPZ100=PZ100');
    sql.Add(' ,SPZ101=PZ101, SPZ102=PZ102, SPZ103=PZ103, SPZ104=PZ104, SPZ105=PZ105, SPZ106=PZ106, SPZ107=PZ107, SPZ108=PZ108 ,SPZ109=PZ109 ,SPZ110=PZ110');
    sql.Add(',SPZ111=PZ111 ,SPZ112=PZ112 ,SPZ113=PZ113 ,SPZ114=PZ114 ,SPZ115=PZ115 ,SPZ116=PZ116 ,SPZ117=PZ117 ,SPZ118=PZ118 ,SPZ119=PZ119 ,SPZ120=PZ120');
    sql.Add(',SPZ121=PZ121 ,SPZ122=PZ122 ,SPZ123=PZ123 ,SPZ124=PZ124 ,SPZ125=PZ125 ,SPZ126=PZ126 ,SPZ127=PZ127 ,SPZ128=PZ128 ,SPZ129=PZ129 ,SPZ130=PZ130');
    sql.Add(',SPZ131=PZ131 ,SPZ132=PZ132 ,SPZ133=PZ133 ,SPZ134=PZ134 ,SPZ135=PZ135 ,SPZ136=PZ136 ,SPZ137=PZ137 ,SPZ138=PZ138 ,SPZ139=PZ139 ,SPZ140=PZ140');
    sql.Add(',SPZ141=PZ141 ,SPZ142=PZ142 ,SPZ143=PZ143 ,SPZ144=PZ144    ');
    sql.Add(' from Cloth_PaiZhen where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    sql.Add(' and RTrim(PZType)=''排针'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PZ);
  SInitCDSData20(ADOQueryTemp, CDS_PZ);
  if CDS_PZ.IsEmpty then
  begin
    CDS_PZ.Append;
    CDS_PZ.Post;
  end;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Cloth_PaiZhen where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    sql.Add(' and RTrim(PZType)=''三角'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_SJ);
//  SInitCDSData20(ADOQueryTemp, CDS_SJ);

  j := 0;
  k := 1;

  ADOQueryTemp.First;
  FWeiZhi := ADOQueryTemp.FieldByName('WeiZhi').AsString;
  while not ADOQueryTemp.Eof do
  begin
    if Trim(ADOQueryTemp.FieldByName('WeiZhi').AsString) <> FWeiZhi then
    begin
      with CDS_SJ do
      begin
        Append;
        Post;
      end;
    end;
    FWeiZhi := ADOQueryTemp.FieldByName('WeiZhi').AsString;
    with CDS_SJ do
    begin
      Append;
      for i := 0 to ADOQueryTemp.FieldCount - 1 do
      begin
        fields[i].value := ADOQueryTemp.Fields[i].Value;
      end;
      fieldByName('Sflag').AsString := '1';
      fieldByName('Sindex').value := k;
      fieldByName('Ssel').value := false;
      fieldByName('SDefNote').value := '';
      inc(k);
      Post;
    end;

    ADOQueryTemp.Next;
    j := j + 1;
  end;

  if CDS_SJ.IsEmpty then
  begin
    CDS_SJ.Append;
    CDS_SJ.Post;
  end;

  with ADOQueryTemp do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add('Select A.* ');
    sql.Add(',YLQty=Cast(C_Qty*PBQty*0.01*(1+isnull(ZPSH,0)*0.01) as decimal(18,1))');
    sql.Add(' from Cloth_YCL_PB A');
    sql.Add(' inner join Cloth_Sub B on A.SubId=B.SubId');
    sql.Add(' where A.SubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PRT);
  SInitCDSData20(ADOQueryTemp, CDS_PRT);

  if CDS_PRT.IsEmpty then
  begin
    CDS_PRT.Append;
    CDS_PRT.Post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Cloth_Sub where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, ClientDataSet1);
  SInitCDSData20(ADOQueryTemp, ClientDataSet1);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RMVariables['ZSCPS'] := ClientDataSet1.fieldbyname('ZSCPS').Value;
    RMVariables['ZSCQty'] := ClientDataSet1.fieldbyname('ZSCQty').Value;
    RMVariables['WFJHPSHZ'] := ClientDataSet1.fieldbyname('WFJHPSHZ').Value;
    RMVariables['WFJHQtyHZ'] := ClientDataSet1.fieldbyname('WFJHQtyHZ').Value;
    RMVariables['C_Code'] := Order_Main.fieldbyname('C_Code').Value;
    RMVariables['ConNo'] := Order_Main.fieldbyname('ConNo').Value;
    RMVariables['C_CodeName'] := Order_Main.fieldbyname('C_CodeName').Value;
    RMVariables['DayQty'] := Order_Main.fieldbyname('DayQty').Value;
    RMVariables['CarType'] := Order_Main.fieldbyname('CarType').Value;
    RMVariables['ChouZhen'] := Order_Main.fieldbyname('ChouZhen').Value;
    RMVariables['KZQty'] := Order_Main.fieldbyname('KZQty').Value;
    RMVariables['MFQty'] := Order_Main.fieldbyname('MFQty').Value;
    RMVariables['KZ'] := Order_Main.fieldbyname('KZ').Value;
    RMVariables['MF'] := Order_Main.fieldbyname('MF').Value;
    RMVariables['PiKgQty'] := Order_Main.fieldbyname('PiKgQty').Value;
    RMVariables['ZhuanQty'] := Order_Main.fieldbyname('ZhuanQty').Value;
    RMVariables['PiQty'] := Order_Main.fieldbyname('PiQty').Value;
    RMVariables['C_Qty'] := Order_Main.fieldbyname('C_Qty').Value;
    RMVariables['QDTime'] := Order_Main.fieldbyname('QDTime').Value;
    RMVariables['JHChejian'] := Order_Main.fieldbyname('JHChejian').Value;
    RMVariables['DeliveryDate'] := Order_Main.fieldbyname('DeliveryDate').Value;
    RMVariables['ShaChang1'] := Order_Main.fieldbyname('ShaChang').Value;
    RMVariables['SJCarNO'] := Order_Main.fieldbyname('SJCarNO').Value;
    RMVariables['C_Spec'] := Order_Main.fieldbyname('C_Spec').Value;
    RMVariables['C_Color'] := Order_Main.fieldbyname('C_Color').Value;
    RMVariables['C_Note'] := Order_Main.fieldbyname('C_Note').Value;
    RMVariables['SJCarNO'] := Order_Main.fieldbyname('SJCarNO').Value;
    RMVariables['ChouZhen'] := Order_Main.fieldbyname('ChouZhen').Value;
    RMVariables['PiKgQtyFD'] := Order_Main.fieldbyname('PiKgQtyFD').Value;
    RMVariables['BatchNoHZ'] := Order_Main.fieldbyname('BatchNoHZ').Value;
    RMVariables['ConPayment'] := Order_Main.fieldbyname('ConPayment').Value;
    RMVariables['ConPRTPrice'] := Order_Main.fieldbyname('ConPRTPrice').Value;
    RMVariables['ConDYMoney'] := Order_Main.fieldbyname('ConDYMoney').Value;
    RMVariables['ZdyNameZ'] := Order_Main.fieldbyname('ZdyNameZ').Value;
    RMVariables['Zdr'] := Order_Main.fieldbyname('Filler').Value;
    RMVariables['WzPrice'] := Order_Main.fieldbyname('WzPrice').Value;
    RMVariables['BZNote'] := Order_Main.fieldbyname('BZNote').Value;
    RMVariables['ZZYQ'] := Order_Main.fieldbyname('ZZYQ').Value;
    RMVariables['ZZSH'] := Order_Main.fieldbyname('ZZSH').Value;
    RMVariables['MFZZS'] := Order_Main.fieldbyname('MFZZS').Value;
    RMVariables['ALBL'] := Order_Main.fieldbyname('ALBL').Value;
    RMVariables['gongyi'] := Order_Main.fieldbyname('gongyi').Value;
    RMVariables['ZongJieNote'] := Order_Main.fieldbyname('ZongJieNote').Value;
    RMVariables['ZhenCun'] := Order_Main.fieldbyname('ZhenCun').Value;
    RMVariables['Filler'] := Order_Main.fieldbyname('Filler').Value;
    RMVariables['JHChejian'] := Order_Main.fieldbyname('JHChejian').Value;
    RMVariables['HTSYRName'] := Order_Main.fieldbyname('HTSYRName').Value;
    RMVariables['YWY'] := Order_Main.fieldbyname('YWY').Value;
    RMVariables['KJTS'] := Order_Main.fieldbyname('KJTS').Value;
    RMVariables['PBMF'] := Order_Main.fieldbyname('PBMF').Value;
    RMVariables['PBKZ'] := Order_Main.fieldbyname('PBKZ').Value;
    RMVariables['ZongZhenQty'] := Order_Main.fieldbyname('ZongZhenQty').Value;
    RMVariables['KHName'] := Order_Main.fieldbyname('KHName').Value;
    RMVariables['HZPaiSha'] := Order_Main.fieldbyname('HZPaiSha').Value;
    RMVariables['KHConNo'] := Order_Main.fieldbyname('KHConNo').Value;
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
  end;
end;

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

procedure TfrmShuttleClothSCList.TBAddClick(Sender: TObject);
begin

  try
    frmClothSCInPut := TfrmClothSCInPut.Create(Application);
    with frmClothSCInPut do
    begin
      PState := 0;
      FMainId := '';
      FSubId := '';
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmClothSCInPut.Free;
  end;
end;

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

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

procedure TfrmShuttleClothSCList.conPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(Trim(ConNo.Text)) < 4 then
      Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        sql.Clear;
        //sql.Add('exec Cloth_QryList :MainId,:WSql');
       // Parameters.ParamByName('WSql').Value:=' and OM.conNo like '''+'%'+Trim(ConNoM.Text)+'%'+''''
                                             // +' and ConType=''生产'' ';
        sql.Add('select * from Cloth_Main A inner join CLoth_Sub B on A.Mainid=B.MainId');
        sql.Add(' where A.ConNo like ''' + '%' + Trim(ConNo.Text) + '%' + '''');

        Open;
      end;
      SCreateCDS20(ADOQueryMain, Order_Main);
      SInitCDSData20(ADOQueryMain, Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmShuttleClothSCList.TBViewClick(Sender: TObject);
begin
  try
    frmClothSCInPut := TfrmClothSCInPut.Create(Application);
    with frmClothSCInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FSubId := Trim(Self.Order_Main.fieldbyname('SubId').AsString);
      FConNo := Trim(Self.Order_Main.fieldbyname('ConNo').AsString);
      TBSave.Visible := False;
      ToolBar3.Visible := False;
      ScrollBox1.Enabled := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClothSCInPut.Free;
  end;
end;

procedure TfrmShuttleClothSCList.TBCopyClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmClothSCInPut := TfrmClothSCInPut.Create(Application);
    with frmClothSCInPut do
    begin
      PState := 1;
      FCopyInt := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FConNo := Trim(Self.Order_Main.fieldbyname('ConNo').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClothSCInPut.Free;
  end;
end;

procedure TfrmShuttleClothSCList.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  FDDZT: string;
begin

  if AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('DDZT').Index] = null then
    Exit;

  FDDZT := AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('DDZT').Index];

  if FDDZT = '已开始' then
    ACanvas.Font.Color := $FF0000;
  if FDDZT = '已结束' then
    ACanvas.Font.Color := $0000FF;

end;

end.

