unit U_ZHCPList_Sel;

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, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, cxButtonEdit,
  cxDropDownEdit, cxPC, Buttons, cxTextEdit, cxImage, StrUtils, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu;

type
  TfrmZHCPList_Sel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    Panel11: TPanel;
    v1Column1: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport2: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    v1Column4: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1ZICost: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    TBEdit: TMenuItem;
    TBDel: TMenuItem;
    Panel2: TPanel;
    cxTabControl2: TcxTabControl;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    Panel4: TPanel;
    Label9: TLabel;
    YeHZ: TEdit;
    Label10: TLabel;
    CPHZ: TEdit;
    Label11: TLabel;
    GGHZ: TEdit;
    Label12: TLabel;
    KWView: TMenuItem;
    Panel5: TPanel;
    Label3: TLabel;
    Label4: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Panel1: TPanel;
    Label2: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label1: TLabel;
    Label5: TLabel;
    ZIID: TEdit;
    ZIName: TEdit;
    ZIGY: TEdit;
    Editer: TEdit;
    Filler: TEdit;
    Note: TEdit;
    v1Column14: TcxGridDBColumn;
    Label13: TLabel;
    KHNameHZ: TEdit;
    Panel6: TPanel;
    SpeedButton1: TSpeedButton;
    Image2: TImage;
    SpeedButton2: TSpeedButton;
    Label14: TLabel;
    ZIType: TComboBox;
    v1Column15: TcxGridDBColumn;
    Panel7: TPanel;
    SpeedButton3: TSpeedButton;
    Image1: TImage;
    SpeedButton4: TSpeedButton;
    RM2: TRMGridReport;
    SpeedButton5: TSpeedButton;
    v1Column16: TcxGridDBColumn;
    SpeedButton6: TSpeedButton;
    Tv1Column1: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ZJStatusChange(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure v1Column2PropertiesEditValueChanged(Sender: TObject);
    procedure cxTabControl2Change(Sender: TObject);
    procedure ZIIDKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Image2Click(Sender: TObject);
    procedure ZITypeChange(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private
    canshu1: string;
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure IntTab();
    function GetFiltersGY(TMPanel: TPanel; EquTag, LikeTag: Integer): string;
    function StrFenHang(FStr: string; var FHStr: string): Boolean;
    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmZHCPList_Sel: TfrmZHCPList_Sel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmZHCPList_Sel.FormDestroy(Sender: TObject);
begin
  frmZHCPList_Sel := nil;
end;

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

procedure TfrmZHCPList_Sel.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
  canshu1 := Trim(DParameters1);
end;

procedure TfrmZHCPList_Sel.TBCloseClick(Sender: TObject);
begin
  if Trim(Self.Caption) = '展会产品录入(高)*' then
  begin
    WriteCxGrid('展会产品录入(高)', Tv1, '展会产品管理');
  end
  else if Trim(Self.Caption) = '展会产品录入*' then
  begin
    WriteCxGrid('展会产品录入', Tv1, '展会产品管理');
  end
  else if Trim(Self.Caption) = '展会产品查询*' then
  begin
    WriteCxGrid('展会产品查询', Tv1, '展会产品管理');
  end
  else if Trim(Self.Caption) = '挂钩库存查询*' then
  begin
    WriteCxGrid('挂钩库存查询', Tv1, '展会产品管理');
  end;
  Close;
end;

function TfrmZHCPList_Sel.GetFiltersGY(TMPanel: TPanel; EquTag, LikeTag: Integer): string;
var
  i, j, k: Integer;
  fsj, fsj1: string;
begin
  Result := '';
  with TMPanel do
  begin
    for i := 0 to ControlCount - 1 do
    begin
      if Controls[i] is TLabel then
        Continue;
      if Controls[i] is TEdit then
      begin
        if Trim(TEdit(Controls[i]).Text) <> '' then
        begin
          if Trim(TEdit(Controls[i]).Name) = 'ZIID' then
          begin
            if Copy(Trim(TEdit(Controls[i]).Text), 1, 2) = 'DY' then
            begin
              with ADOQueryTemp do
              begin
                Close;
                sql.Clear;
                sql.Add('select * from ZH_CP_Info_KC where DYID=''' + Trim(TEdit(Controls[i]).Text) + '''');
                Open;
              end;
              TEdit(Controls[i]).Text := Trim(ADOQueryTemp.fieldbyname('ZIID').AsString);
              Controls[i].Tag := 1;
            end
            else
            begin
              Controls[i].Tag := 2;
            end;
          end;
          if Controls[i].Tag = EquTag then
            Result := Result + 'and A.' + Controls[i].Hint + Controls[i].Name + '=' + QuotedStr(Trim(TEdit(Controls[i]).Text))
          else if Controls[i].Tag = LikeTag then
          begin
            j := Pos(' ', Trim(TEdit(Controls[i]).Text));
            if j > 0 then
            begin
              Result := Result + 'and A.' + Controls[i].Hint + Controls[i].Name + ' like ' + QuotedStr('%' + Copy(Trim(TEdit(Controls[i]).Text), 1, j - 1) + '%');
              fsj1 := Copy(Trim(TEdit(Controls[i]).Text), j + 1, Length(Trim(TEdit(Controls[i]).Text)));
              while Trim(fsj1) <> '' do
              begin
                j := Pos(' ', Trim(fsj1));
                if j > 0 then
                begin
                  Result := Result + 'and A.' + Controls[i].Hint + Controls[i].Name + ' like ' + QuotedStr('%' + Copy(Trim(fsj1), 1, j - 1) + '%');
                  fsj1 := Copy(Trim(fsj1), j + 1, Length(Trim(fsj1)));
                end
                else
                begin
                  Result := Result + 'and A.' + Controls[i].Hint + Controls[i].Name + ' like ' + QuotedStr('%' + Trim(fsj1) + '%');
                  fsj1 := '';
                end;
              end;
            end
            else
              Result := Result + 'and A.' + Controls[i].Hint + Controls[i].Name + ' like ' + QuotedStr('%' + Trim(TEdit(Controls[i]).Text) + '%');
          end;
        end;
      end
      else if Controls[i] is TComboBox then
      begin
        if Trim(TComboBox(Controls[i]).Text) <> '' then
          if Controls[i].Tag = EquTag then
            Result := Result + 'and A.' + Controls[i].Hint + Controls[i].Name + '=' + QuotedStr(Trim(TComboBox(Controls[i]).Text))
          else if Controls[i].Tag = LikeTag then
            Result := Result + 'and A.' + Controls[i].Hint + Controls[i].Name + ' like ' + QuotedStr('%' + Trim(TComboBox(Controls[i]).Text) + '%');
      end;
    end;
  end;
  if Trim(Result) <> '' then
    Result := Trim(RightBStr(Result, Length(Result) - 4));
end;

procedure TfrmZHCPList_Sel.InitGrid();
var
  fsj10: string;
begin
  fsj10 := GetFiltersGY(Panel1, 1, 2);
  if Trim(fsj10) <> '' then
  begin
    fsj10 := ' and ' + fsj10;
  end
  else
  begin
    fsj10 := '';
  end;
  Panel2.Visible := True;
  Panel2.Refresh;
  cxTabControl2.Enabled := False;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      if Self.canshu1 = '库存' then
      begin
        sql.Add('Select AA.* From(');
        sql.Add(' select A.*,Cast(ROW_NUMBER() OVER(order by A.ZIID) as int) as RowNum ');
        sql.Add(' ,ImageFileTP=(select Top 1 ImageFile from Image_Info B inner join Image_File C on B.IMID=C.IMID ');
        sql.Add('             where B.WBID=A.ZIID and B.IMNO=''图片'' and B.Valid=''Y'' and C.Valid=''Y'' and C.IFType=''小'' )');
        sql.Add(' ,SCTP=(select Top 1 WBID from Image_Info B inner join Image_File C on B.IMID=C.IMID ');
        sql.Add('             where B.WBID=A.ZIID and B.IMNO=''图片'' and B.Valid=''Y'' and C.Valid=''Y'' and C.IFType=''小'' )');
        sql.Add(' ,ImageFileNR=(select Top 1 ImageFile from Image_Info B inner join Image_File C on B.IMID=C.IMID ');
        sql.Add('             where B.WBID=A.ZIID and B.IMNO=''内容'' and B.Valid=''Y'' and C.Valid=''Y'' and C.IFType=''小'' )');
        sql.Add(',GS=KC.GGQty');
        sql.Add('From(');
        sql.Add(' select ZIID,GGQty=sum(GGQty)  from ZH_CP_Info_KC where isnull(GGQty,0)>0 and Valid=''Y'' Group by ZIID) KC');
        sql.Add(' inner join ZH_CP_Info A  on KC.ZIID=A.ZIID');
        sql.Add(' where A.Valid=''Y''  ');
        sql.Add(fsj10);
        sql.Add(')AA');
        sql.Add(' where RowNum>=' + inttostr(cxTabControl2.TabIndex * 30 + 1));
        sql.Add(' and RowNum<=' + inttostr((cxTabControl2.TabIndex + 1) * 30));
      end
      else
      begin
        sql.Add('Select AA.* From(');
        sql.Add(' select A.*,Cast(ROW_NUMBER() OVER(order by ZIID) as int) as RowNum ');
        sql.Add(' ,ImageFileTP=(select top 1 ImageFile from Image_Info B inner join Image_File C on B.IMID=C.IMID ');
        sql.Add('             where B.WBID=A.ZIID and B.IMNO=''图片'' and B.Valid=''Y'' and C.Valid=''Y'' and C.IFType=''小'' )');
        sql.Add(' ,SCTP=(select Top 1 WBID from Image_Info B inner join Image_File C on B.IMID=C.IMID ');
        sql.Add('             where B.WBID=A.ZIID and B.IMNO=''图片'' and B.Valid=''Y'' and C.Valid=''Y'' and C.IFType=''小'' )');
        sql.Add(' ,ImageFileNR=(select top 1 ImageFile from Image_Info B inner join Image_File C on B.IMID=C.IMID ');
        sql.Add('             where B.WBID=A.ZIID and B.IMNO=''内容'' and B.Valid=''Y'' and C.Valid=''Y'' and C.IFType=''小'' )');
        sql.Add(',GS=(select Sum(GGQty) from ZH_CP_Info_KC KC where KC.ZIID=A.ZIID )');
        sql.Add(' from ZH_CP_Info A  ');
        sql.Add(' where Valid=''Y''  ');
        sql.Add(' and ZIDate>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.Add(' and ZIDate<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
        sql.Add(fsj10);
        sql.Add(')AA');
        sql.Add(' where RowNum>=' + inttostr(cxTabControl2.TabIndex * 30 + 1));
        sql.Add(' and RowNum<=' + inttostr((cxTabControl2.TabIndex + 1) * 30));
      end;

      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add(' select AA=count(*) ');
      sql.Add(' from ZH_CP_Info A  ');
      sql.Add(' where Valid=''Y''  ');
      if Trim(canshu1) <> '库存' then
      begin
        sql.Add(' and ZIDate>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.Add(' and ZIDate<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
      end
      else
      begin
        sql.Add(' and exists(select ZIID from ZH_CP_Info_KC KC where KC.ZIID=A.ZIID and isnull(KC.GGQty,0)>0 and KC.Valid=''Y'' )');
      end;

      sql.Add(fsj10);
      Open;
    end;
    CPHZ.Text := Trim(ADOQueryTemp.fieldbyname('AA').AsString);
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add(' select AA=sum(GGQty) ');
      sql.Add(' from ZH_CP_Info A  ');
      sql.Add(' inner join ZH_CP_Info_KC KC on A.ZIID=KC.ZIID');
      sql.Add(' where A.Valid=''Y'' and KC.Valid=''Y''  ');
      if Trim(canshu1) <> '库存' then
      begin
        sql.Add(' and A.ZIDate>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.Add(' and A.ZIDate<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
      end;
      sql.Add(fsj10);
      Open;
    end;
    GGHZ.Text := Trim(ADOQueryTemp.fieldbyname('AA').AsString);
  finally
    ADOQueryMain.EnableControls;
  end;
  Panel2.Visible := False;
  cxTabControl2.Enabled := True;
end;

procedure TfrmZHCPList_Sel.InitForm();
begin
  BegDate.Date := SGetServerDateMBeg(ADOQueryTemp);
  EndDate.Date := SGetServerDate(ADOQueryTemp);
  if Trim(Self.Caption) = '公司产品录入(高)*' then
  begin
    ReadCxGrid('展会产品录入(高)', Tv1, '展会产品管理');
  end
  else if Trim(Self.Caption) = '公司产品录入*' then
  begin
    ReadCxGrid('展会产品录入', Tv1, '展会产品管理');
    v1ZICost.Visible := False;
    v1ZICost.Hidden := True;
  end
  else if Trim(Self.Caption) = '公司产品查询*' then
  begin
    ReadCxGrid('展会产品查询', Tv1, '展会产品管理');
    v1ZICost.Visible := False;
    v1ZICost.Hidden := True;
  end
  else if Trim(Self.Caption) = '挂钩库存查询*' then
  begin
    ReadCxGrid('挂钩库存查询', Tv1, '展会产品管理');
    v1ZICost.Visible := False;
    v1ZICost.Hidden := True;
    canshu1 := '库存';
    Panel5.Visible := False;
  end;
  //InitGrid();
end;

procedure TfrmZHCPList_Sel.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;

function TfrmZHCPList_Sel.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      //First;
     // while Order_Main.Locate('SSel',True,[]) do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add(' UPdate ZH_CP_Info Set DelTime=getdate(),DelerCode=''' + Trim(DCode) + ''',Deler=''' + Trim(DName) + ''', Valid=''N'' ');
          sql.Add(' where ZIID=''' + Trim(Order_Main.fieldbyname('ZIID').AsString) + '''');
          sql.Add(' delete Image_File where IMID in(select IMID from Image_Info where WBID=''' + Trim(Order_Main.fieldbyname('ZIID').AsString) + ''')');
          sql.Add(' delete Image_Info where  WBID=''' + Trim(Order_Main.fieldbyname('ZIID').AsString) + '''');
          ExecSQL;
        end;
        Order_Main.Delete;
      end;
    end;
    Order_Main.EnableControls;

    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := False;
    Application.MessageBox('数据删除异常！', '提示', 0);
  end;
end;

function TfrmZHCPList_Sel.StrFenHang(FStr: string; var FHStr: string): Boolean;
var
  i, j: Integer;
  LSStr: string;
begin
  Result := False;
  FStr := Trim(FStr);
  FHStr := '';
  j := 1;
  i := Pos(' ', FStr);
  while i > 0 do
  begin
    if j = 1 then
    begin
      LSStr := Copy(FStr, 1, i - 1);  //'1234  5678 456'
      FHStr := '1:' + LSStr;
    end
    else
    begin
      LSStr := Copy(FStr, 1, i - 1);
      if Trim(LSStr) = '' then
      begin
        FStr := Copy(FStr, i + 1, Length(FStr) - i);
      end
      else
        FHStr := FHStr + #13 + #10 + inttostr(j) + ':' + LSStr;
    end;
    if Trim(LSStr) <> '' then
    begin
      j := j + 1;
      FStr := Copy(FStr, i + 1, Length(FStr) - i);
    end;
    i := Pos(' ', FStr);
  end;
  if j = 1 then
  begin
    FHStr := FStr;
  end
  else
  begin
    if Trim(FStr) <> '' then
    begin
      FHStr := FHStr + #13 + #10 + inttostr(j) + ':' + FStr;
    end;
  end;
  Result := True;
end;

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

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

procedure TfrmZHCPList_Sel.IntTab();
var
  JLInt, YeInt, i: Integer;
  fsj, fsj10: string;
begin
  fsj10 := GetFiltersGY(Panel1, 1, 2);
  if Trim(fsj10) <> '' then
  begin
    fsj10 := ' and ' + fsj10;
  end
  else
  begin
    fsj10 := '';
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    if Trim(canshu1) = '库存' then
    begin
      sql.Add('select JLInt=isnull(Count(*),0)  ');
      sql.Add(' from ZH_CP_Info A  ');
      sql.Add(' where Valid=''Y''  ');
      //sql.Add(' and ZIType=''成品'' ');
      sql.Add(' and exists(select ZIID from ZH_CP_Info_KC KC where KC.ZIID=A.ZIID and isnull(KC.GGQty,0)>0 and KC.Valid=''Y'' )');
    end
    else
    begin
      sql.Add(' select JLInt=isnull(Count(*),0) ');
      sql.Add(' from ZH_CP_Info A  ');
      sql.Add(' where Valid=''Y''  ');
      //sql.Add(' and ZIType=''成品'' ');
      sql.Add(' and ZIDate>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
      sql.Add(' and ZIDate<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
    end;
    sql.Add(fsj10);
    Open;
  end;
  JLInt := ADOQueryTemp.fieldbyname('JLInt').AsInteger;
  YeInt := JLInt div 30;
  YeInt := YeInt + 1;
  cxTabControl2.Tabs.Clear;
  for i := 1 to YeInt do
  begin
    fsj := '第' + IntToStr(i) + '页';
    cxTabControl2.Tabs.Add(fsj);
  end;
  YeHZ.Text := IntToStr(YeInt);
end;

procedure TfrmZHCPList_Sel.TBAddClick(Sender: TObject);
begin
  Panel6.Visible := True;
end;

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

procedure TfrmZHCPList_Sel.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmZHCPList_Sel.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmZHCPList_Sel.CustomerNoNameChange(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 TfrmZHCPList_Sel.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from ZH_CP_Info where ZIID like ''' + Trim(Order_Main.fieldbyname('ZIID').AsString) + '-%' + ''' and valid=''Y'' ');
    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;

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

procedure TfrmZHCPList_Sel.ZJStatusChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmZHCPList_Sel.ToolButton4Click(Sender: TObject);
begin
  panel7.Visible := true;
end;

procedure TfrmZHCPList_Sel.v1Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  with Order_Main do
  begin
    Edit;
    if Trim(mvalue) = '' then
    begin
      FieldByName('ZICost').Value := Null;
    end
    else
    begin
      FieldByName('ZICost').Value := mvalue;
    end;
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    if Trim(mvalue) <> '' then
    begin
      sql.Add('Update ZH_CP_Info Set ZICost=' + mvalue);
    end
    else
    begin
      sql.Add('Update ZH_CP_Info Set ZICost=Null');
    end;
    sql.Add(' where ZIID=''' + Trim(Order_Main.fieldbyname('ZIID').AsString) + '''');
    ExecSQL;
  end;
end;

procedure TfrmZHCPList_Sel.cxTabControl2Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmZHCPList_Sel.ZIIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    BegDate.Date := StrToDate('2000-01-01');
    EndDate.Date := StrToDate('2500-01-01');
    IntTab();
    InitGrid();
    if Trim(TEdit(Sender).Name) = 'ZIID' then
    begin
      ZIID.Text := '';
    end;
  end;
end;

procedure TfrmZHCPList_Sel.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
//var
  //fsj:String;
begin
 { StrFenHang(Order_Main.fieldbyname('ZIGY').AsString,fsj);
  if Trim(Order_Main.fieldbyname('ZIGY').AsString)<>fsj then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update ZH_CP_Info Set ZIGY='''+fsj+'''');
      sql.Add(' where ZIID='''+Trim(Order_Main.fieldbyname('ZIID').AsString)+'''');
      ExecSQL;
    end;
  end;
  with Order_Main do
  begin
    Edit;
    FieldByName('ZIGY').Value:=fsj;
    //Post;
  end; }

end;

procedure TfrmZHCPList_Sel.Image2Click(Sender: TObject);
begin
  Panel6.Visible := False;
end;

procedure TfrmZHCPList_Sel.ZITypeChange(Sender: TObject);
begin
  BegDate.Date := StrToDate('2000-01-01');
  EndDate.Date := StrToDate('2500-01-01');
  IntTab();
  InitGrid();
end;

procedure TfrmZHCPList_Sel.Image1Click(Sender: TObject);
begin
  panel7.Visible := false;
end;

procedure TfrmZHCPList_Sel.Tv1DblClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  self.ModalResult := 1;
end;

end.

