unit U_ClothGYList;

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, cxPC, Menus,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, cxCheckBox, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, 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, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue;

type
  TfrmClothGYList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label5: TLabel;
    C_CodeName: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RMXLSExport1: TRMXLSExport;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column9: TcxGridDBColumn;
    TBView: TToolButton;
    v1Column21: TcxGridDBColumn;
    Label10: TLabel;
    C_Code: TEdit;
    v1Column20: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label1: TLabel;
    GongYiCode: TEdit;
    tbADD: TToolButton;
    tbEDIT: TToolButton;
    TBDEL: TToolButton;
    v1Column3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    TBQY: TToolButton;
    TBTY: TToolButton;
    Tv1Column3: TcxGridDBColumn;
    TBPrint: TToolButton;
    CDS_PRT: TClientDataSet;
    RMDBPRT: TRMDBDataSet;
    CDS_PZ: TClientDataSet;
    RMDBPZ: TRMDBDataSet;
    CDS_SJ: TClientDataSet;
    RMDBSJ: TRMDBDataSet;
    ClientDataSet1: TClientDataSet;
    RMDBDataSet1: TRMDBDataSet;
    CDS_WJG: TClientDataSet;
    RMDBWJG: TRMDBDataSet;
    RM1: TRMGridReport;
    Label2: TLabel;
    YZConNo: TEdit;
    TBSave: TToolButton;
    v1PriceA: TcxGridDBColumn;
    v1PriceC: TcxGridDBColumn;
    v1PriceD: TcxGridDBColumn;
    v1PriceE: TcxGridDBColumn;
    v1PriceF: TcxGridDBColumn;
    v1PriceG: TcxGridDBColumn;
    v1PriceH: TcxGridDBColumn;
    v1PriceJ: TcxGridDBColumn;
    TBSaveP: TToolButton;
    Panel2: TPanel;
    Tv1Column4: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure tbADDClick(Sender: TObject);
    procedure tbEDITClick(Sender: TObject);
    procedure TBDELClick(Sender: TObject);
    procedure TBQYClick(Sender: TObject);
    procedure TBTYClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TBSavePClick(Sender: TObject);
  private
    FInt, PFInt: Integer;
    procedure InitGrid();
    procedure InitForm();
    procedure InitButton();
    { Private declarations }
  public
    canshu1, FCheJian: string;
    { Public declarations }
  end;

//var
  //frmClothSCList: TfrmClothSCList;

implementation

uses
  U_DataLink, U_ClothGYInPut, U_Fun, U_ZDYHelp, U_SCPerson, U_ClothSCInPutSC,
  U_ClothGongYi, U_RTFun;

{$R *.dfm}

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

procedure TfrmClothGYList.InitButton();
begin
  tbADD.Visible := False;
  tbEDIT.Visible := False;
  tbDEL.Visible := False;
  TBQY.Visible := False;
  TBTY.Visible := False;
  TBPrint.Visible := False;
  TBSave.Visible := False;
  TBSaveP.Visible := False;
  if Self.canshu1 = '低权限' then
  begin

  end;
  if Self.canshu1 = '管理' then
  begin
    tbADD.Visible := True;
    tbEDIT.Visible := True;
    tbDEL.Visible := True;
    TBQY.Visible := True;
    TBTY.Visible := True;
    TBPrint.Visible := True;
  end;
  if Self.canshu1 = '录入' then
  begin
    tbADD.Visible := True;
    tbEDIT.Visible := True;
  end;
  if Self.canshu1 = '打印' then
  begin
    TBPrint.Visible := True;
  end;
  if Self.canshu1 = '工价' then
  begin
    TBSave.Visible := True;
    TBSaveP.Visible := True;
  end;
end;

procedure TfrmClothGYList.TBCloseClick(Sender: TObject);
begin

  if Trim(DName) = 'ADMIN' then
  begin
    WriteCxGridAll(trim(self.Caption), Tv1, ADOQueryCmd, ADOQueryTemp);
  end;
  Close;

end;

procedure TfrmClothGYList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select B.* ');
//      sql.Add('  ,YZConNo=cast((select distinct '' ''+ X.ConNo from Cloth_Main X inner join Cloth_Sub Y on X.MainId=Y.MainId ');
//      sql.Add('  where DATEDIFF(MONTH,X.Filltime,getdate())<7 and Y.GongYiCode=B.GongYiCode for xml path('''')) as varchar(600))');

      sql.Add('  ,YZConNo=cast((select  '' ''+ X.ConNo from Cloth_Main X inner join Cloth_Sub Y on X.MainId=Y.MainId ');
      sql.Add('  where Y.GongYiCode=B.GongYiCode order by X.filltime desc for xml path('''')) as varchar(6000))');     // DATEDIFF(MONTH,X.Filltime,getdate())<7 and

      sql.Add(' from CLoth_GY B');
      sql.Add(' where Valid=''Y'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmClothGYList.InitForm();
begin
  InitButton();
  ReadCxGridAll(trim(self.Caption), Tv1);
  InitGrid();
end;

procedure TfrmClothGYList.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 TfrmClothGYList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel('坯布生产单', cxGrid1);
end;

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

procedure TfrmClothGYList.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 TfrmClothGYList.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmClothGYList.TBViewClick(Sender: TObject);
begin
  try
    frmClothGYInPut := TfrmClothGYInPut.Create(Application);
    with frmClothGYInPut do
    begin
      TBSave.Visible := False;
      ToolBar3.Visible := False;
      if canshu1 = '查询' then
      begin
        cxPageControl1.Visible := False;
        ToolBar1.Visible := False;
      end;
      PState := 1;
      FSubId := Trim(Self.Order_Main.fieldbyname('GYId').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClothGYInPut.Free;
  end;
end;

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

procedure TfrmClothGYList.tbADDClick(Sender: TObject);
begin
  try
    frmClothGYInPut := TfrmClothGYInPut.Create(Application);
    with frmClothGYInPut do
    begin
      PState := 0;
      FMainId := '';
      FSubId := '';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClothGYInPut.Free;
  end;
end;

procedure TfrmClothGYList.tbEDITClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Trim(FormatDateTime('yyyy-MM-dd', Order_Main.FieldByName('FillTime').AsDateTime)) < '2022-03-14' then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from Cloth_GY A  where ');
    sql.Add(' A.GYID=' + quotedstr(trim(Order_Main.fieldbyname('GYID').AsString)));
    sql.Add(' and DATEDIFF(DD,A.Filltime,GETDATE()) >30 ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Application.MessageBox('数据已锁定无法修改!', '提示', 0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.* from Cloth_GY A  where ');
    sql.Add(' GYID=' + quotedstr(trim(Order_Main.fieldbyname('GYID').AsString)));
    sql.Add(' and QYFlag=1 ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Application.MessageBox('工艺已启用无法修改!', '提示', 0);
    Exit;
  end;

  with Self.ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    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(Order_Main.fieldbyname('GYId').AsString)));
    sql.Add(',' + quotedstr(trim('成功')));
    sql.Add(')');
    execsql;
  end;
  try
    frmClothGYInPut := TfrmClothGYInPut.Create(Application);
    with frmClothGYInPut do
    begin
      PState := 1;
      FSubId := Trim(Self.Order_Main.fieldbyname('GYId').AsString);
      if ShowModal = 1 then
      begin
        InitGrid();
        Self.Order_Main.Locate('MainId', frmClothGYInPut.FMainId, []);
      end;
    end;
  finally
    frmClothGYInPut.Free;
  end;
end;

procedure TfrmClothGYList.TBDELClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  if Application.MessageBox('确定要删除此工艺吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Cloth_GY SET QYFlag=0, Valid=''N'' ,DelPerson=''' + trim(DName) + ''',DelTime=getdate() ');
      sql.Add('where GYID=' + quotedstr(trim(Order_Main.fieldbyname('GYID').AsString)));
      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(Order_Main.FieldByName('GongYiCode').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('工艺删除成功！', '提示信息');
    Order_Main.Delete;
  except
    application.MessageBox('工艺删除失败！', '提示信息', 0);
  end;

end;

procedure TfrmClothGYList.TBQYClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  if Application.MessageBox('确定要启用吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Cloth_GY SET QYFlag=1,QYPerson=''' + trim(DName) + ''',QYTime=getdate() ');
      sql.Add('where GYID=' + quotedstr(trim(Order_Main.fieldbyname('GYID').AsString)));
      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(Order_Main.FieldByName('GongYiCode').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('工艺启用成功！', '提示信息');
    with Order_Main do
    begin
      Edit;
      FieldByName('QYFlag').Value := True;
      Post;
    end;
  except
    application.MessageBox('工艺启用失败！', '提示信息', 0);
  end;
end;

procedure TfrmClothGYList.TBTYClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  if Application.MessageBox('确定要停用吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Cloth_GY SET QYFlag=0,QYPerson=''' + trim(DName) + ''',QYTime=getdate() ');
      sql.Add('where GYID=' + quotedstr(trim(Order_Main.fieldbyname('GYID').AsString)));
      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(Order_Main.FieldByName('GongYiCode').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('工艺停用成功！', '提示信息');
    with Order_Main do
    begin
      Edit;
      FieldByName('QYFlag').Value := False;
      Post;
    end;
  except
    application.MessageBox('工艺停用失败！', '提示信息', 0);
  end;
end;

procedure TfrmClothGYList.TBPrintClick(Sender: TObject);
var
  fPrintFile: string;
  i, j, k: integer;
begin
  if Order_Main.IsEmpty then
    Exit;
  ExportFtErpFile('坯布工艺单.rmf', ADOQueryTemp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\坯布工艺单.rmf';

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select  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 ');
    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);

  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['C_Code'] := Order_Main.fieldbyname('C_Code').Value;
    RMVariables['C_CodeName'] := Order_Main.fieldbyname('C_CodeName').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['JHChejian'] := Order_Main.fieldbyname('JHChejian').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['Zdr'] := Order_Main.fieldbyname('Filler').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['ZhenCun'] := Order_Main.fieldbyname('ZhenCun').Value;
    RMVariables['FillTime'] := Order_Main.fieldbyname('FillTime').Value;
    RMVariables['ZongZhenQty'] := Order_Main.fieldbyname('ZongZhenQty').Value;
    RMVariables['PSNote'] := Order_Main.fieldbyname('PSNote').Value;
    RMVariables['SJNote'] := Order_Main.fieldbyname('SJNote').Value;
    RMVariables['ISYT'] := Order_Main.fieldbyname('ISYT').Value;
    RMVariables['ISKF'] := Order_Main.fieldbyname('ISKF').Value;
    RMVariables['ISCZ'] := Order_Main.fieldbyname('ISCZ').Value;
    RMVariables['PBFactoryNoName'] := Order_Main.fieldbyname('PBFactoryNoName').Value;
    RMVariables['YGPS'] := Order_Main.fieldbyname('YGPS').Value;
    RMVariables['YGQty'] := Order_Main.fieldbyname('YGQty').Value;
    RMVariables['GongYiCode'] := Order_Main.fieldbyname('GongYiCode').Value;
    RMVariables['YZConNo'] := Order_Main.fieldbyname('YZConNo').Value;
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
  end;
end;

procedure TfrmClothGYList.TBSaveClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  C_Code.SetFocus;
  if Application.MessageBox('确定要保存当前选中的数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CLoth_GY where GYID=''' + Trim(Order_Main.fieldbyname('GYID').AsString) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Edit;
      RTSetSaveDataCDS(ADOQueryCmd, Tv1, Order_Main, 'CLoth_GY', 7);
      FieldByName('Editer').Value := Trim(DName);
      FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTemp);
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('保存成功!', '提示', 0);
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败!', '提示', 0);
  end;
end;

procedure TfrmClothGYList.TBSavePClick(Sender: TObject);
var
  FDate: TDateTime;
begin
  if Order_Main.IsEmpty then
    Exit;
  C_Code.SetFocus;
  if Application.MessageBox('批量保存时间会比较长，要等待一段时间，确定要批量保存当前页面的数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  FDate := SGetServerDateTime(ADOQueryTemp);
  Panel2.Visible := True;
  Panel2.Refresh;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CLoth_GY where GYID=''' + Trim(Order_Main.fieldbyname('GYID').AsString) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin                                   
          Edit;
          RTSetSaveDataCDS(ADOQueryCmd, Tv1, Order_Main, 'CLoth_GY', 7);
          FieldByName('Editer').Value := Trim(DName);
          FieldByName('EditTime').Value := FDate;
          Post;
        end;
        next;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Panel2.Visible := False;
    Application.MessageBox('保存成功!', '提示', 0);
  except
    Panel2.Visible := False;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败!', '提示', 0);
  end;
end;

end.

