unit U_ClothSCYWYList;

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,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu,
  dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmClothSCYWYList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: 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;
    v1Column5: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    RMDBPRT: TRMDBDataSet;
    v1Column12: TcxGridDBColumn;
    TBView: TToolButton;
    v1Column19: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    Label10: TLabel;
    C_Code: TEdit;
    v1Column10: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    Label6: TLabel;
    GongYiCode: TEdit;
    v1Column31: TcxGridDBColumn;
    v1Column32: TcxGridDBColumn;
    ToolButton2: TToolButton;
    cxTabControl1: TcxTabControl;
    tchk: TToolButton;
    tnochk: TToolButton;
    v1Column1: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Label4: TLabel;
    C_NDXS: TComboBox;
    v1PBJGPrice: TcxGridDBColumn;
    v1JGTiaoJia: TcxGridDBColumn;
    v1JGHSPrice: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    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 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 ToolButton2Click(Sender: TObject);
    procedure tchkClick(Sender: TObject);
    procedure tnochkClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1Column2PropertiesEditValueChanged(Sender: TObject);
  private
    FInt, PFInt: Integer;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitButton();
    { Private declarations }
  public
    canshu1, FCheJian: string;
    { Public declarations }
  end;

//var
  //frmClothSCList: TfrmClothSCList;

implementation

uses
  U_DataLink, U_ClothSCInPut, U_Fun, U_ZDYHelp, U_SCPerson, U_ClothSCInPutSC,
  U_ClothSCYWYInPut, U_RTFun;

{$R *.dfm}

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

procedure TfrmClothSCYWYList.InitButton();
begin
  tchk.Visible := false;
  tnochk.Visible := false;
  tbedit.Visible := false;
  tbdel.Visible := false;
  TBAdd.Visible := false;
  v1PBJGPrice.Visible := False;
  v1PBJGPrice.Hidden := True;
  v1JGTiaoJia.Visible := False;
  v1JGTiaoJia.Hidden := True;
  v1JGHSPrice.Visible := False;
  v1JGHSPrice.Hidden := True;
  if Trim(canshu1) = '审核' then
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          tchk.Visible := true;
        end;
      1:
        begin
          tnochk.Visible := true;
        end;
      2:
        begin

        end;
    end;
  end;

  if Trim(canshu1) = '录入' then
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          TBAdd.Visible := true;
          tbedit.Visible := true;
          tbdel.Visible := true;
        end;
      1:
        begin

        end;
      2:
        begin

        end;
    end;
  end;

  if Trim(canshu1) = '调价' then
  begin
    tchk.Visible := false;
    tnochk.Visible := false;
    tbedit.Visible := false;
    tbdel.Visible := false;
    TBAdd.Visible := false;
    cxTabControl1.TabIndex := 3;
    Tv1.OptionsSelection.CellSelect := True;
    v1PBJGPrice.Visible := True;
    v1PBJGPrice.Hidden := False;
    v1JGTiaoJia.Visible := True;
    v1JGTiaoJia.Hidden := False;
    v1JGHSPrice.Visible := True;
    v1JGHSPrice.Hidden := False;
  end;

end;

procedure TfrmClothSCYWYList.TBCloseClick(Sender: TObject);
begin
  if Trim(DName) = 'ADMIN' then
  begin
    WriteCxGridAll(trim(self.Caption), Tv1, ADOQueryCmd, ADOQueryTemp);
  end;

  Close;
end;

procedure TfrmClothSCYWYList.InitGrid();
begin
  BegDate.SetFocus;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*,C_CodeNameND=RTrim(C_CodeName)+isnull(C_NDXS,'''') ,C.PBJGPrice,B.JGTiaoJia,JGHSPrice=isnull(C.PBJGPrice,0)+isnull(B.JGTiaoJia,0) ');
      sql.Add(',OrderDetail=(select Top 1 OrderDetail  from PBOrder_Main BB where BB.OrderNo=A.ConNo and BB.Valid=''Y'')');
      sql.Add(' from Cloth_Main A inner join CLoth_Sub B on A.Mainid=B.MainId');
      sql.Add(' left join CP_Info C on B.C_CodeName=C.SPName and C.ISQY=1 ');
      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 canshu1 = '录入' then
        sql.Add(' and A.Filler=' + QuotedStr(Trim(DName)));

      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add('and  isnull(A.status,''0'')=''0''');
          end;
        1:
          begin
            sql.Add('and  isnull(A.status,''0'')=''1''');
          end;
        2:
          begin
            sql.Add('and  isnull(A.status,''0'')=''2''');
          end;
        3:
          begin
            sql.Add('and  isnull(A.status,''0'') in (''0'',''1'',''2'')');
          end;
      end;
//      ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmClothSCYWYList.InitForm();
begin
  ReadCxGridAll(trim(self.Caption), Tv1);
  InitButton();
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 7;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  InitGrid();
end;

procedure TfrmClothSCYWYList.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 TfrmClothSCYWYList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.* from Cloth_Sub A  where IsGongYi=1');
    sql.Add(' and mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
    sql.Add(' and exists(select * from Cloth_Main B where A.MainId=B.MainId and DATEDIFF(DD,B.Filltime,GETDATE()) >30)  ');
    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('SubId').AsString)));
    sql.Add(',' + quotedstr(trim('成功')));
    sql.Add(')');
    execsql;
  end;
  try
    frmClothSCYWYInPut := TfrmClothSCYWYInPut.Create(Application);
    with frmClothSCYWYInPut 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', frmClothSCYWYInPut.FMainId, []);
      end;
    end;
  finally
    frmClothSCYWYInPut.Free;
  end;
end;

procedure TfrmClothSCYWYList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.* from Cloth_Sub A  where IsGongYi=1');
    sql.Add(' and mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
    sql.Add(' and exists(select * from Cloth_Main B where A.MainId=B.MainId and DATEDIFF(DD,B.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.*');
    sql.Add('from JYCon_Sub_AnPai A');
    sql.Add(' where A.SubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
    sql.Add(' and A.MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    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
    //TBRafresh.Click;
    //TBFind.Click;
    Order_Main.Delete;
  end;
end;

function TfrmClothSCYWYList.DelData(): Boolean;
begin

  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('SubId').AsString)));
    sql.Add(',' + quotedstr(trim('成功')));
    sql.Add(')');
    execsql;
  end;
  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) + '''');
      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 TfrmClothSCYWYList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel('坯布生产单', cxGrid1);
end;

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

procedure TfrmClothSCYWYList.TBAddClick(Sender: TObject);
begin

  try
    frmClothSCYWYInPut := TfrmClothSCYWYInPut.Create(Application);
    with frmClothSCYWYInPut do
    begin
      PState := 0;
      FMainId := '';
      FSubId := '';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClothSCYWYInPut.Free;
  end;
end;

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

procedure TfrmClothSCYWYList.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('select * from Cloth_Main A inner join CLoth_Sub B on A.Mainid=B.MainId');
        sql.Add(' where A.ConNo like ''' + '%' + Trim(ConNo.Text) + '%' + '''');
        case cxTabControl1.TabIndex of
          0:
            begin
              sql.Add('and  isnull(A.status,''0'')=''0''');
            end;
          1:
            begin
              sql.Add('and  isnull(A.status,''0'')=''1''');
            end;
          2:
            begin
              sql.Add('and  isnull(A.status,''0'')=''2''');
            end;
          3:
            begin
              sql.Add('and  isnull(A.status,''0'') in (''0'',''1'',''2'')');
            end;
        end;
        Open;
      end;
      SCreateCDS20(ADOQueryMain, Order_Main);
      SInitCDSData20(ADOQueryMain, Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmClothSCYWYList.TBViewClick(Sender: TObject);
begin
  try
    frmClothSCYWYInPut := TfrmClothSCYWYInPut.Create(Application);
    with frmClothSCYWYInPut 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;
      ScrollBox1.Enabled := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClothSCYWYInPut.Free;
  end;
end;

procedure TfrmClothSCYWYList.ToolButton2Click(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 A.*,B.* ');

    sql.Add(',FILLTIME1=(select TOP 1 FILLTIME from Cloth_Main X inner join CLoth_Sub Y on X.Mainid=Y.MainId   ');
    sql.Add(' where Y.IsGongYi=1 and Y.GongYiCode= B.TJGongYiCode) ');

    SQL.Add(',OrderDetail=(select Top 1 OrderDetail  from PBOrder_Main B where B.OrderNo=A.ConNo and B.Valid=''Y'')');
    sql.Add(' from Cloth_Main A inner join CLoth_Sub B on A.Mainid=B.MainId');
    sql.Add(' where A.MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PRT);
  SInitCDSData20(ADOQueryTemp, CDS_PRT);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\坯布生产计划单.rmf'), '提示', 0);
  end;
end;

procedure TfrmClothSCYWYList.tchkClick(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_Main SET status=''1'',chker=''' + trim(DName) + ''',Chktime=getdate() ');
      sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').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('ConNO').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('订单审核成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('订单审核失败！', '提示信息', 0);
  end;
end;

procedure TfrmClothSCYWYList.tnochkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.* from Cloth_Sub A  where IsGongYi=1');
    sql.Add(' and mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').AsString)));
    sql.Add(' and exists(select * from Cloth_Main B where A.MainId=B.MainId and DATEDIFF(DD,B.Filltime,GETDATE()) >30)  ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Application.MessageBox('数据已锁定无法修改!', '提示', 0);
    Exit;
  end;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Cloth_Main SET status=''0'',chker=null,Chktime=null ');
      sql.Add('where mainID=' + quotedstr(trim(Order_Main.fieldbyname('mainID').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('orderNO').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('订单撤销审核成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('订单撤销审核失败！', '提示信息', 0);
  end;
end;

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

procedure TfrmClothSCYWYList.ToolButton1Click(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 A.*,B.* ');
    SQL.Add(',OrderDetail=(select Top 1 OrderDetail  from PBOrder_Main B where B.OrderNo=A.ConNo and B.Valid=''Y'')');
    sql.Add(' from Cloth_Main A inner join CLoth_Sub B on A.Mainid=B.MainId');
    sql.Add(' where A.MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PRT);
  SInitCDSData20(ADOQueryTemp, CDS_PRT);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\坯布匹样生产计划单.rmf'), '提示', 0);
  end;
end;

procedure TfrmClothSCYWYList.Tv1Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FJGPrice, FJGTJ, FHSPrice: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    FJGTJ := '0';
  end
  else
  begin
    FJGTJ := mvalue;
  end;
  FJGPrice := Trim(Order_Main.fieldbyname('PBJGPrice').AsString);
  if Trim(FJGPrice) = '' then
    FJGPrice := '0';
  with Order_Main do
  begin
    Edit;
    if Trim(FJGTJ) = '0' then
    begin
      FieldByName('JGTiaoJia').Value := null;
    end
    else
    begin
      FieldByName('JGTiaoJia').Value := FJGTJ;
    end;
    FieldByName('JGHSPrice').Value := StrToFloat(FJGTJ) + StrToFloat(FJGPrice);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    if Trim(FJGTJ) = '0' then
      sql.Add('Update Cloth_Sub Set JGTiaoJia=Null ')
    else
      sql.Add('Update Cloth_Sub Set JGTiaoJia=' + FJGTJ);
    sql.Add('where Subid=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
    ExecSQL;
  end;
end;

end.

