unit U_BPJHList; //

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

type
  TfrmBPJHList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    ToolButton2: TToolButton;
    Panel1: TPanel;
    Label4: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    GDName: TEdit;
    Label2: TLabel;
    FactoryName: TEdit;
    Label3: TLabel;
    BPCode: TEdit;
    Label10: TLabel;
    ToFactoryName: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column1: TcxGridDBColumn;
    v1OrderNo: TcxGridDBColumn;
    v1PSName: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1GDPerson: TcxGridDBColumn;
    v1FactoryName: TcxGridDBColumn;
    v1ToFactoryName: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label5: TLabel;
    BPName: TEdit;
    ToolButton1: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    v1Column24: TcxGridDBColumn;
    v1Column25: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    CheckBox1: TCheckBox;
    v1Column27: TcxGridDBColumn;
    ToolButton7: TToolButton;
    v1Column28: TcxGridDBColumn;
    v1Column29: TcxGridDBColumn;
    v1Column30: TcxGridDBColumn;
    v1Column31: TcxGridDBColumn;
    v1Column32: TcxGridDBColumn;
    v1Column33: TcxGridDBColumn;
    v1Column34: TcxGridDBColumn;
    v1Column35: TcxGridDBColumn;
    v1Column36: TcxGridDBColumn;
    Label6: TLabel;
    BPSpec: TEdit;
    v1Column37: TcxGridDBColumn;
    v1Column38: TcxGridDBColumn;
    v1Column39: TcxGridDBColumn;
    v1Column40: TcxGridDBColumn;
    v1Column43: TcxGridDBColumn;
    v1Column41: TcxGridDBColumn;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2ComeDate: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2MxQty: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2MxNote: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    v2Column21: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2Column13: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column14: TcxGridDBColumn;
    v2Column16: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    v2Column22: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column17: TcxGridDBColumn;
    v2Column18: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    v2Column19: TcxGridDBColumn;
    v2Column20: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource2: TDataSource;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGridPopupMenu3: TcxGridPopupMenu;
    cxSplitter1: TcxSplitter;
    Label7: TLabel;
    GangNoHZ: TEdit;
    v1Column42: TcxGridDBColumn;
    v1Column44: TcxGridDBColumn;
    ToolButton3: TToolButton;
    Panel2: TPanel;
    XM: TComboBox;
    XMStr: TEdit;
    Label8: TLabel;
    Label9: TLabel;
    v1Column45: TcxGridDBColumn;
    Label1: TLabel;
    CPDaiHao: TEdit;
    v1Column46: TcxGridDBColumn;
    Label11: TLabel;
    JHBatchNo: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    procedure FormDestroy(Sender: TObject);
    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 FPNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure FactoryNameKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton7Click(Sender: TObject);
    procedure v1Column24CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure v1Column12CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure cxPageControl1Change(Sender: TObject);
    procedure Tv1StylesGetContentStyle(Sender: TcxCustomGridTableView;
      ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem;
      out AStyle: TcxStyle);
    procedure ToolButton3Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
  private
    FInt,PFInt:Integer;
    canshu1:string;
    procedure InitGrid();
    procedure InitGridWSql(fsj:string);
    procedure InitForm();
    function  DelData():Boolean;
    procedure InitSubGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmBPJHList: TfrmBPJHList;

implementation
uses
  U_DataLink,U_RTFun,U_BPJHInPut,U_ModuleNote,U_ZDYHelp;

{$R *.dfm}

procedure TfrmBPJHList.FormDestroy(Sender: TObject);
begin
  frmBPJHList:=nil;
end;

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

procedure TfrmBPJHList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('计划列表',Tv1,'跟单管理');
  WriteCxGrid('计划列表1',Tv2,'跟单管理');
  WriteCxGrid('计划列表2',Tv3,'跟单管理');
end;

procedure TfrmBPJHList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from XH_Cloth_JH A ');
      sql.Add(' where 1=1 ');
      if Trim(canshu1)<>'高权限' then
      begin
        sql.Add(' and A.FillerCode='''+Trim(DCode)+'''');
      end;
      sql.Add(' and A.JHDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''');
      sql.Add(' and A.JHDate<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime+1))+'''');
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and BegFlag=0 and EndFlag=0');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and BegFlag=1 and EndFlag=0');
      end  else
      if cxTabControl1.TabIndex=2 then
      begin
        sql.Add('  and EndFlag=1');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;

end;

procedure TfrmBPJHList.InitGridWSql(fsj:string);
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' select A.* ');
      sql.Add(' from XH_Cloth_JH A ');
      sql.Add(' where 1=1 ');
      if Trim(canshu1)<>'高权限' then
      begin
        sql.Add(' and A.FillerCode='''+Trim(DCode)+'''');
      end;
      if cxTabControl1.TabIndex>1 then
      begin
        if CheckBox1.Checked then
        begin
          sql.Add(' and A.JHDate>='''+Trim(FormatDateTime('yyyy-MM-dd',BegDate.DateTime))+'''');
          sql.Add(' and A.JHDate<'''+Trim(FormatDateTime('yyyy-MM-dd',EndDate.DateTime+1))+'''');
        end;
      end;
      if cxTabControl1.TabIndex=0 then
      begin
        sql.Add(' and BegFlag=0 and EndFlag=0');
      end else
      if cxTabControl1.TabIndex=1 then
      begin
        sql.Add(' and BegFlag=1 and EndFlag=0');
      end  else
      if cxTabControl1.TabIndex=2 then
      begin
        sql.Add('  and EndFlag=1');
      end;
      sql.Add(fsj);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;

end;

procedure TfrmBPJHList.InitForm();
begin
  ReadCxGrid('计划列表',Tv1,'跟单管理');
  ReadCxGrid('计划列表1',Tv2,'跟单管理');
  ReadCxGrid('计划列表2',Tv3,'跟单管理');
  EndDate.DateTime:=SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime:=SGetServerDateMBeg(ADOQueryTemp);
end;

procedure TfrmBPJHList.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 TfrmBPJHList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  {with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from GD_JinDu_Main where GMID='''+Trim(Order_Main.fieldbyname('GMId').AsString)+'''');
    sql.Add(' and isnull(GMStatus,'''')=''已完成'' ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False then
  begin
    Application.MessageBox('已完成不能修改数据！','提示',0);
    Exit;
  end;}
  try
    frmBPJHInPut:=TfrmBPJHInPut.Create(Application);
    with frmBPJHInPut do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('JHID').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmBPJHInPut.Free;
  end;
end;

procedure TfrmBPJHList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from XH_Cloth_DH where JHID='''+Trim(Order_Main.fieldbyname('JHID').AsString)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False then
  begin
    Application.MessageBox('已有到货数据不能删除数据！','提示',0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from XH_Cloth_TP where JHID='''+Trim(Order_Main.fieldbyname('JHID').AsString)+'''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False then
  begin
    Application.MessageBox('已有投坯数据不能删除数据！','提示',0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete XH_Cloth_JH where JHID='''+Trim(Order_Main.fieldbyname('JHID').AsString)+'''');
    ExecSQL;
  end;
  Order_Main.Delete;
end;

function TfrmBPJHList.DelData():Boolean;
begin

end;

procedure TfrmBPJHList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel(Self.Caption,cxGrid1);
end;

procedure TfrmBPJHList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  TBFind.Click;
end;

procedure TfrmBPJHList.TBAddClick(Sender: TObject);
begin
  try
    frmBPJHInPut:=TfrmBPJHInPut.Create(Application);
    with frmBPJHInPut do
    begin
      PState:=0;
      FMainId:='';

      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmBPJHInPut.Free;
  end;
end;

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

procedure TfrmBPJHList.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  try
    frmBPJHInPut:=TfrmBPJHInPut.Create(Application);
    with frmBPJHInPut do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('JHId').AsString);
      TBSave.Visible:=False;
      ToolButton1.Visible:=False;
      ToolButton2.Visible:=False;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmBPJHInPut.Free;
  end;
end;

procedure TfrmBPJHList.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

procedure TfrmBPJHList.OrderNoKeyPress(Sender: TObject;
  var Key: Char);
var
  fsj:string;
begin
  if Key=#13 then
  begin
    if Length(Trim(BPCode.Text))<3 then Exit;
    fsj:=' and A.BPCode like '''+'%'+Trim(BPCode.Text)+'%'+'''';
    InitGridWSql(fsj);
  end;
end;

procedure TfrmBPJHList.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
  TBFind.Click;
end;

procedure TfrmBPJHList.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' UPdate XH_Cloth_JH Set BegFlag=1,BegDate=getdate(),BegPerson='''+Trim(DName)+'''');
    sql.Add(' where JHId='''+Trim(Order_Main.fieldbyname('JHId').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('BegFlag').Value:=True;
    Post;
  end;
  if cxTabControl1.TabIndex=0 then
  begin
    Order_Main.Delete;
  end;
end;

procedure TfrmBPJHList.ToolButton4Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' UPdate XH_Cloth_JH Set BegFlag=0,BegCXDate=getdate(),BegPerson='''+Trim(DName)+'''');
    sql.Add(' where JHId='''+Trim(Order_Main.fieldbyname('JHId').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('BegFlag').Value:=False;
    Post;
  end;
  if cxTabControl1.TabIndex=1 then
  begin
    Order_Main.Delete;
  end;
end;

procedure TfrmBPJHList.ToolButton5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' UPdate XH_Cloth_JH Set EndFlag=1,EndDate=getdate(),EndPerson='''+Trim(DName)+'''');
    sql.Add(' where JHId='''+Trim(Order_Main.fieldbyname('JHId').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('EndFlag').Value:=True;
    Post;
  end;
  if cxTabControl1.TabIndex<2 then
  begin
    Order_Main.Delete;
  end;
end;

procedure TfrmBPJHList.ToolButton6Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then Exit;
  if Application.MessageBox('确定要执行此操作吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add(' UPdate XH_Cloth_JH Set EndFlag=0,EndCXDate=getdate(),EndPerson='''+Trim(DName)+'''');
    sql.Add(' where JHId='''+Trim(Order_Main.fieldbyname('JHId').AsString)+'''');
    ExecSQL;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('EndFlag').Value:=False;
    Post;
  end;
  if cxTabControl1.TabIndex=2 then
  begin
    Order_Main.Delete;
  end;
end;

procedure TfrmBPJHList.FactoryNameKeyPress(Sender: TObject; var Key: Char);
var
  fsj:string;
  FName:string;
begin
  if Key=#13 then
  begin
    if Trim(TEdit(Sender).Text)='' then Exit;
    FName:=TEdit(Sender).Hint;
    fsj:=' and '+FName+' like '''+'%'+Trim(TEdit(Sender).Text)+'%'+'''';
    InitGridWSql(fsj);
    TBFind.Click;
  end;
end;

procedure TfrmBPJHList.ToolButton7Click(Sender: TObject);
begin
   try
     frmZDYHelp:=TfrmZDYHelp.Create(Application);
     with frmZDYHelp do
     begin
       flag:='GDGSTT';
       flagname:='抬头';
       if ShowModal=1 then
       begin

       end;
     end;
   finally
     frmZDYHelp.Free;
   end;
end;

procedure TfrmBPJHList.v1Column24CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  Id:Integer;
begin

  Id:=TV1.GetColumnByFieldName('JGSHQty').Index;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[id]=Null then Exit;
  if AViewInfo.GridRecord.Values[id]<0 then
  begin
    ACanvas.Brush.Color:=clRed;
  end;
end;

procedure TfrmBPJHList.v1Column12CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  Id:Integer;
begin
  Id:=TV1.GetColumnByFieldName('KCPSHZ').Index;
  if Id<0 then Exit;
  if AViewInfo.GridRecord.Values[id]=Null then Exit;
  if AViewInfo.GridRecord.Values[id]=0 then
  begin
    ACanvas.Brush.Color:=$0040FF00;  //clGreen
  end;
end;

procedure TfrmBPJHList.Tv1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Order_Main.IsEmpty then Exit;
  InitSubGrid();
end;
procedure TfrmBPJHList.InitSubGrid();
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    if cxPageControl1.ActivePageIndex=0 then
    begin
      sql.Add('select * from XH_Cloth_DH where JHID='''+Trim(Order_Main.fieldbyname('JHID').AsString)+'''');
    end else
    begin
      sql.Add('select * from XH_Cloth_TP where JHID='''+Trim(Order_Main.fieldbyname('JHID').AsString)+'''');
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet2);
  SInitCDSData20(ADOQueryTemp,ClientDataSet2);
end;

procedure TfrmBPJHList.cxPageControl1Change(Sender: TObject);
begin
  InitSubGrid();
end;

procedure TfrmBPJHList.Tv1StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
var
  id,id10,id20:Integer;
begin
  try
    if Tv1.GroupedItemCount=0 then
    begin
      Id:=Tv1.GetColumnByFieldName('KCPSHZ').Index;
      Id10:=Tv1.GetColumnByFieldName('KCPSHZCP').Index;
      Id20:=Tv1.GetColumnByFieldName('KCPSHZSC').Index;

      if (ARecord.Values[id]=0) and (ARecord.Values[Id10]=0) and (ARecord.Values[Id20]=Null)  then
      begin
        AStyle:=DataLink_OrderAndGD.SkyBlue;
      end;
    end else
    begin

    end;
  except
  end;
end;

procedure TfrmBPJHList.ToolButton3Click(Sender: TObject);
var
  FName:string;
begin
  if Order_Main.IsEmpty  then Exit;
  if Trim(XM.Text)='' then
  begin
    Application.MessageBox('没有选择项目!','提示',0);
    Exit;
  end;
  if Trim(XMStr.Text)='' then
  begin
    Application.MessageBox('项目值不能为空!','提示',0);
    Exit;
  end;
  if Order_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  if Application.MessageBox(PChar('确定要把所选数据的《'+Trim(XM.Text)+'》更改为：'+Trim(XMStr.Text)+'  吗？'),'',32+4)<>IDYES then Exit;
  if Trim(XM.Text)='供应商' then FName:='FactoryName';
  if Trim(XM.Text)='抬头' then FName:='TaiTou';
  if Trim(XM.Text)='存放工厂' then FName:='ToFactoryName';
  if Trim(XM.Text)='品名' then FName:='BPName';
  if Trim(XM.Text)='门幅' then FName:='BPMF';
  if Trim(XM.Text)='克重' then FName:='BPKZ';
  if Trim(XM.Text)='成品代号' then FName:='CPDaiHao';

  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      First;
      while not Eof do
      begin
        if Order_Main.FieldByName('SSel').AsBoolean=True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPdate XH_Cloth_JH Set '+FName+'='''+Trim(XMStr.Text)+'''');
            sql.Add(' where JHID='''+Trim(Order_Main.fieldbyname('JHID').AsString)+'''');
            ExecSQL;
          end;
          if Trim(FName)='FactoryName' then
          begin
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('UPdate XH_Cloth_DH Set FromFactoryName='''+Trim(XMStr.Text)+'''');
              sql.Add(' where JHID='''+Trim(Order_Main.fieldbyname('JHID').AsString)+'''');
              ExecSQL;
            end;
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('UPdate XH_Cloth_TP Set FromFactoryName='''+Trim(XMStr.Text)+'''');
              sql.Add(' where JHID='''+Trim(Order_Main.fieldbyname('JHID').AsString)+'''');
              ExecSQL;
            end;
          end;
          if Trim(FName)='ToFactoryName' then
          begin
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('UPdate XH_Cloth_DH Set DQFactoryName='''+Trim(XMStr.Text)+'''');
              sql.Add(' where JHID='''+Trim(Order_Main.fieldbyname('JHID').AsString)+'''');
              ExecSQL;
            end;
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('UPdate XH_Cloth_TP Set DQFactoryName='''+Trim(XMStr.Text)+'''');
              sql.Add(' where JHID='''+Trim(Order_Main.fieldbyname('JHID').AsString)+'''');
              ExecSQL;
            end;
          end;
          Edit;
          FieldByName(FName).Value:=Trim(XMStr.Text);
        end;
        Next;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('批量修改成功!','提示',0);
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('批量修改异常!','提示',0);
    Exit;
  end;
end;

procedure TfrmBPJHList.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main,True);  
end;

procedure TfrmBPJHList.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main,False); 
end;

end.
