unit U_ClothContractList;

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, cxDropDownEdit;

type
  TfrmClothContractList = 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_CodeNameM: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    Label4: TLabel;
    C_Spec: TEdit;
    ScrollBox1: TScrollBox;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1FactoryNo1Name: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ClientDataSet3: TClientDataSet;
    DataSource2: TDataSource;
    DataSource3: TDataSource;
    ClientDataSet2: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    CDS_PRT: TClientDataSet;
    cxTabControl1: TcxTabControl;
    Tchk: TToolButton;
    TNochk: TToolButton;
    FactoryNoName: TEdit;
    Label6: TLabel;
    v1Column1: TcxGridDBColumn;
    ToolButton1: TToolButton;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    v1ClothQty: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    v1ClothUnit: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxSplitter1: TcxSplitter;
    ADOQuerySub: TADOQuery;
    DSsub: TDataSource;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    SQNO: TEdit;
    Label7: TLabel;
    Panel4: TPanel;
    Label14: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    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 Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure Tv2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Tv3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Tv2CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton5Click(Sender: TObject);
    procedure v2Column3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure conPress(Sender: TObject; var Key: Char);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TchkClick(Sender: TObject);
    procedure TNochkClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Image2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure SQNOKeyPress(Sender: TObject; var Key: Char);
  private
    FInt,PFInt:Integer;
    procedure InitGrid();
    procedure InitForm();
    function  DelData():Boolean;
    procedure SetStatus();
    procedure InitSub();
    { Private declarations }
  public
    FType:string;
    { Public declarations }
  end;

var
  frmClothContractList: TfrmClothContractList;

implementation
uses
  U_DataLink,U_ClothContractInPutPB,U_Fun,U_ProductOrderList,U_ZDYHelp,
  U_FjList_RZ;

{$R *.dfm}
procedure TfrmClothContractList.InitSub();
begin
  ADOQuerySub.Close;
  IF Order_Main.IsEmpty then exit;
  with ADOQuerySub do
  begin
    close;
    sql.Clear;
    sql.Add('select * from Contract_Sub ');
    sql.Add('where mainID ='+quotedstr((Order_Main.fieldbyname('mainID').AsString)));
    open;
  end;
end;

procedure TfrmClothContractList.SetStatus();
begin
  TBAdd.Visible:=false;
  tchk.Visible:=false;
  tnochk.Visible:=false;
  tbedit.Visible:=false;
  tbdel.Visible:=false;
  IF FType=''then
  begin
    case cxTabControl1.TabIndex of
    0:begin
   //    tchk.Visible:=true;
       tbedit.Visible:=true;
       tbdel.Visible:=true;
       TBAdd.Visible:=true;
      end;
    1:begin
     //   tnochk.Visible:=true;
      end;
    2:begin

      end;
    end;
  end;
  IF FType='查询' then
  begin
    Tbadd.Visible:=false;
    TBPrint.Visible:=false;
    //v1Price.Visible:=false;
   // v1PriceUnit.Visible:=false;
  //  v1Money.Visible:=false;

  //  v1Price.Hidden:=true;
  //  v1PriceUnit.Hidden:=true;
  //  v1Money.Hidden:=true;
    cxTabControl1.TabIndex:=2;
    cxTabControl1.Visible:=false;
  end;
end;

procedure TfrmClothContractList.FormDestroy(Sender: TObject);
begin
  frmClothContractList:=nil;
end;

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

procedure TfrmClothContractList.FormCreate(Sender: TObject);
begin
  ScrollBox1.Align:=alClient;
end;

procedure TfrmClothContractList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(self.Caption+tv1.Name+'1',Tv1,'指示单管理');
  WriteCxGrid(self.Caption+tv2.Name,Tv2,'指示单管理');
end;

procedure TfrmClothContractList.InitGrid();
var strwhere: string;
begin
  strwhere:=' where QDTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''''
              +' and QDTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime+1))+''''
              +' and HTType=''采购合同''';
  IF cxTabControl1.TabIndex=0 then
  strwhere:=strwhere+' and isnull(C_status,''0'')=''0'' ';
  IF cxTabControl1.TabIndex=1 then
  strwhere:=strwhere+' and isnull(C_status,''0'')=''1'' ';
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.*     ');
      sql.Add(' from Contract_Main A');
      sql.Add(' where QDTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''' ');
      sql.Add(' and QDTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime+1))+''' ');
      sql.Add(' and HTType=''采购合同'' ');
     // IF cxTabControl1.TabIndex=0 then
    //  sql.Add(' and isnull(C_status,''0'')=''0''  ');
    //  IF cxTabControl1.TabIndex=1 then
    //  sql.Add(' and isnull(C_status,''0'')=''1''  ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
    TBFind.Click;
  end;
end;

procedure TfrmClothContractList.InitForm();
begin
  ReadCxGrid(self.Caption+tv1.Name+'1',Tv1,'指示单管理');
  ReadCxGrid(self.Caption+tv2.Name,Tv2,'指示单管理');
  cxTabControl1.TabIndex:=0;
  if Trim(DParameters1)='1' then
  begin
    TBPrint.Visible:=False;
  end else
  begin
 //   v1Column1.Visible:=True;
 //   v1Column1.Hidden:=False;
 //   v1PRTUnit.Visible:=True;
 //   v1PRTUnit.Hidden:=False;
  //  v1PRTQty.Visible:=True;
  //  v1PRTQty.Hidden:=False;
    TBPrint.Visible:=True;
  end;
  BegDate.DateTime:=SGetServerDate10(ADOQueryTemp)-7;
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  InitGrid();
end;

procedure TfrmClothContractList.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 TfrmClothContractList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    frmClothContractInPutPB:=TfrmClothContractInPutPB.Create(Application);
    with frmClothContractInPutPB do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FConNo:=Trim(Self.Order_Main.fieldbyname('ConNo').AsString);
      if ShowModal=1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmClothContractInPutPB.Free;
  end;
end;

procedure TfrmClothContractList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if ClientDataSet2.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 TfrmClothContractList.DelData():Boolean;
begin
  try
    Result:=false;
    ADOQueryCmd.Connection.BeginTrans;

    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('delete from Contract_Sub where MainId='''+Trim(Order_Main.fieldbyname('MainId').AsString)+'''');
      sql.Add('delete Contract_Main 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 TfrmClothContractList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel('坯布合同订单列表',cxGrid1);
end;

procedure TfrmClothContractList.TBPrintClick(Sender: TObject);
var
   fPrintFile,FConNoM:string;

begin
  if Order_Main.IsEmpty then Exit;

  Panel4.Left:=(self.Width - Panel4.Width ) div 2;
  Panel4.Visible:=true;

 { fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\坯布订购合同.rmf' ;
  with ADOQueryTemp do
  begin
    Filtered:=False;
    Close;
    sql.Clear;
    sql.Add('exec ClothContract_QryList :MainId,:WSql');
    Parameters.ParamByName('WSql').Value:=' and FillTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''''
                                         +' and FillTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime+1))+'''';
    Parameters.ParamByName('MainId').Value:=Trim(Order_Main.fieldbyname('MainId').AsString);
    Parameters.ParamByName('WSql').Value:='';
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_PRT);
  SInitCDSData20(ADOQueryTemp,CDS_PRT);
  FConNoM:=Trim(CDS_PRT.fieldbyname('ConNoM').AsString);
  if FileExists(fPrintFile) then
  begin
    //RMVariables['begindate']:=begindate.DateTime;
    //RMVariables['enddate']:=enddate.DateTime;
    //RMVariables['printtime']:=Now;
    //RMVariables['printer']:=Trim(gUserName);
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\坯布订购合同.rmf'),'提示',0);
  end; }
end;

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

procedure TfrmClothContractList.TBAddClick(Sender: TObject);
begin
  try
    frmClothContractInPutPB:=TfrmClothContractInPutPB.Create(Application);
    with frmClothContractInPutPB do
    begin
      PState:=0;
      FMainId:='';
      if ShowModal=1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmClothContractInPutPB.Free;
  end;
end;

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

procedure TfrmClothContractList.Tv1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
 { with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*,KCSL=A.MXQty-(select isnull(Sum(TPQty),0) from Contract_Sub_Mxto B where B.MXID=A.MXID),');
    sql.Add(' KCPS=A.Qty1-(select isnull(Sum(Qty1),0) from Contract_Sub_Mxto B where B.MXID=A.MXID)');
    sql.Add('from Contract_Sub_Mx A');
    sql.Add(' where A.SubId='''+Trim(Order_Main.fieldbyname('SubId').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet2);
  SInitCDSData20(ADOQueryTemp,ClientDataSet2);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*,C.MPRTSpec,B.PRTColor,C.MPRTCodeName,C.OrderNo ,');
    sql.Add('C_Unit=(select Top 1 C_Unit from Contract_Sub AA,Contract_Sub_Mx BB where AA.SubId=BB.SubId and BB.MXid=A.Mxid)');
    SQL.Add('from Contract_Sub_MxTo A inner join JYOrder_Sub B on A.OrdSubId=B.SubId');
    SQL.Add(' inner join JYOrder_Main C on C.MainId=B.MainId ');
    sql.Add('where A.MxId='''+Trim(ClientDataSet2.fieldbyname('MxId').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet3);
  SInitCDSData20(ADOQueryTemp,ClientDataSet3);  }
end;

procedure TfrmClothContractList.Tv2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FInt:=2;
end;

procedure TfrmClothContractList.Tv1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FInt:=1;
end;

procedure TfrmClothContractList.Tv3MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FInt:=3;
end;

procedure TfrmClothContractList.Tv2CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*,C.MPRTSpec,B.PRTColor,C.MPRTCodeName,C.OrderNo ,');
    sql.Add('C_Unit=(select Top 1 C_Unit from Contract_Sub AA,Contract_Sub_Mx BB where AA.SubId=BB.SubId and BB.MXid=A.Mxid)');
    SQL.Add(' from Contract_Sub_MxTo A inner join JYOrder_Sub B on A.OrdSubId=B.SubId ');
    SQL.Add(' inner join JYOrder_Main C on C.MainId=B.MainId ');
    sql.Add('where A.MxId='''+Trim(ClientDataSet2.fieldbyname('MxId').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet3);
  SInitCDSData20(ADOQueryTemp,ClientDataSet3);
end;

procedure TfrmClothContractList.ToolButton5Click(Sender: TObject);
var
  maxno:string;
begin

end;

procedure TfrmClothContractList.v2Column3PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='RKPlace';
      flagname:='入库地点';
      if ShowModal=1 then
      begin
        with ClientDataSet2 do
        begin
          Edit;
          FieldByName('RKPlace').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmClothContractList.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 ClothContract_QryList :MainId,:WSql');
        Parameters.ParamByName('WSql').Value:=' and OM.conNo like '''+'%'+Trim(ConNo.Text)+'%'+''''
                                             +' and HTType=''采购合同''';
        Open;
      end;
      SCreateCDS20(ADOQueryMain,Order_Main);
      SInitCDSData20(ADOQueryMain,Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;  }
end;

procedure TfrmClothContractList.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin

  If Order_Main.IsEmpty then Exit;
  try
    frmClothContractInPutPB:=TfrmClothContractInPutPB.Create(Application);
    with frmClothContractInPutPB do
    begin
      PState:=1;
      ToolBar1.Enabled:=false;
      ToolBar2.Enabled:=false;
      Tv1.OptionsData.Editing:=false;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FConNo:=Trim(Self.Order_Main.fieldbyname('ConNoM').AsString);
      if ShowModal=1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmClothContractInPutPB.Free;
  end; 
end;

procedure TfrmClothContractList.TchkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Contract_Sub SET C_status=''1'' ');
      sql.Add('where subID='+quotedstr(trim(Order_Main.fieldbyname('subID').AsString)));
      execsql;
    end;
    application.MessageBox('采购完成！','提示信息');
    TBRafresh.Click;
  except
   application.MessageBox('采购失败！','提示信息',0);
  end;
end;

procedure TfrmClothContractList.TNochkClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Contract_Sub SET C_status=''0'' ');
      sql.Add('where subID='+quotedstr(trim(Order_Main.fieldbyname('subID').AsString)));
      execsql;
    end;
    application.MessageBox('撤销成功！','提示信息');
    TBRafresh.Click;
  except
   application.MessageBox('撤销失败！','提示信息',0);
  end;
end;

procedure TfrmClothContractList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  TBRafresh.Click;
end;

procedure TfrmClothContractList.Tv1CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
 { if cxTabControl1.TabIndex=0 then
  begin
    with Order_Main do
    begin
      if (AViewInfo.GridRecord.Values[v1MXQty.Index]<
         AViewInfo.GridRecord.Values[v1C_Qty.Index]*0.97) or
         (AViewInfo.GridRecord.Values[v1MXQty.Index]>
         AViewInfo.GridRecord.Values[v1C_Qty.Index]*1.03) then
      begin
        ACanvas.Font.Color:=clRed;
      end;
      if AViewInfo.GridRecord.Values[v1DHQty.Index]<
         AViewInfo.GridRecord.Values[v1Qty1.Index] then
      begin
        ACanvas.Font.Color:=clRed;
      end;
    end;
  end;  }
end;

procedure TfrmClothContractList.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    frmFjList_RZ:=TfrmFjList_RZ.Create(Application);
    with frmFjList_RZ do
    begin
    //  PState:=1;
   //   if Trim(canshu1)<>'高权限'  then cxButton1.Visible:=false; 
      fkeyNO:=Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      fType:='布匹采购';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmFjList_RZ.Free;
  end;
end;

procedure TfrmClothContractList.Tv1CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
    InitSub();
end;

procedure TfrmClothContractList.Image2Click(Sender: TObject);
begin
  Panel4.Visible:=false;
end;

procedure TfrmClothContractList.Button1Click(Sender: TObject);
var
   fPrintFile,FConNoM:string;

begin
  if Order_Main.IsEmpty then Exit;
 // fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\坯布订购合同.rmf' ;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\'+Trim(RadioGroup1.Items.Strings[RadioGroup1.ItemIndex])+'.rmf' ;
  with ADOQueryTemp do
  begin
    Close;
    Filtered:=False;
    sql.Clear;
    sql.Add('exec ClothContract_QryList :MainId,:WSql');
    Parameters.ParamByName('WSql').Value:=' and FillTime>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+''''
                                         +' and FillTime<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime+1))+'''';
    Parameters.ParamByName('MainId').Value:=Trim(Order_Main.fieldbyname('MainId').AsString);
    Parameters.ParamByName('WSql').Value:='';
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_PRT);
  SInitCDSData20(ADOQueryTemp,CDS_PRT);
  FConNoM:=Trim(CDS_PRT.fieldbyname('ConNoM').AsString);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end else
  begin
    Application.MessageBox(PChar('没有找到'+trim(fPrintFile)),'提示',0);
  end;

end;

procedure TfrmClothContractList.SQNOKeyPress(Sender: TObject;
  var Key: Char);
begin

  IF key=#13 then
  begin
    IF trim(SQNo.Text)='' then exit;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.*     ');
      sql.Add(' from Contract_Main A');
      sql.Add(' where SQNO like ''%'+trim(SQNo.Text)+'%'' ');
      sql.Add(' and HTType=''采购合同'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  end;
end;

end.
