unit U_PBCKlist;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxButtonEdit, cxDropDownEdit, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, RM_Common,
  RM_Class, RM_e_Xls, RM_GridReport, RM_System, RM_Dataset, cxTextEdit, cxPC,
  cxCheckBox, Menus;

type
  TfrmPBCKlist = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBExport: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1P_CodeName: TcxGridDBColumn;
    v1P_MF: TcxGridDBColumn;
    v1P_KZ: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1CRType: TcxGridDBColumn;
    v1CRTime: TcxGridDBColumn;
    v1CRNO: TcxGridDBColumn;
    v1Filler: TcxGridDBColumn;
    v1FillTime: TcxGridDBColumn;
    Label2: TLabel;
    CRType: TComboBox;
    Label5: TLabel;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1MJXH: TcxGridDBColumn;
    ADOPrint: TADOQuery;
    RMXLSExport1: TRMXLSExport;
    v1P_Code: TcxGridDBColumn;
    v1inoutNO: TcxGridDBColumn;
    CRNO: TEdit;
    Label7: TLabel;
    v1custName: TcxGridDBColumn;
    v1TocustName: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    RMDB_Main: TRMDBDataSet;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyle_fontBlack: TcxStyle;
    cxStyle_fontclFuchsia: TcxStyle;
    cxStyle_fontclPurple: TcxStyle;
    cxStyle_fontclGreen: TcxStyle;
    cxStyle_fontclBlue: TcxStyle;
    cxStyle_fontclTeal: TcxStyle;
    cxStyle_fontclOlive: TcxStyle;
    Label8: TLabel;
    ToFactoryName: TEdit;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    v1Column5: TcxGridDBColumn;
    CodeName: TEdit;
    Label11: TLabel;
    Code: TEdit;
    Label14: TLabel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label9: TLabel;
    Note: TEdit;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    ToolButton1: TToolButton;
    cxGrid2: TcxGrid;
    TvMX: TcxGridDBTableView;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    CDS_MX: TClientDataSet;
    DS_MX: TDataSource;
    v1Column14: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure v1Column6CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
  private
    procedure InitGrid();
    function YSData(ADO: TADOQuery): Boolean;
    function YSData_Other(ADO: TADOQuery; fYFName: string; fmoney: double): Boolean;
    procedure SetStatus();
    procedure InitMXGrid(MCRNO: string);
    { Private declarations }
  public
    fCKName, FZZType: string;
    canshu1, canshu2: string;
    { Public declarations }
  end;

//var
//  frmPBCKlist: TfrmPBCKlist;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp, U_PBCk, U_PBCKMXLR;
{$R *.dfm}

procedure TfrmPBCKlist.InitMXGrid(MCRNO: string);
begin
  with ADOQueryTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_PB_CRMX where CRID=' + quotedstr(Trim(MCRNO)));
    sql.Add(' order by MXID');
    Open;
  end;
  SCreateCDS20(ADOQueryTmp, CDS_MX);
  SInitCDSData20(ADOQueryTmp, CDS_MX);
end;

procedure TfrmPBCKlist.SetStatus();
begin

end;

function TfrmPBCKlist.YSData(ADO: TADOQuery): Boolean;
var
  CRID, YFID, Price, PriceUnit, OrderUnit, FComTaiTou, cust: string;
begin
  Result := False;
  with ADOQueryTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from YF_Money_KC where FactoryName=''' + Trim(ADO.fieldbyname('custName').asstring) + ''' and YFDefFlag1=0 ');
    Open;
  end;

  if not ADOQueryTmp.IsEmpty then
  begin
    CRID := ADOQueryTmp.fieldbyname('CRID').AsString;
  end
  else
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YF_Money_CRID set CRID=CRID+1');
      sql.Add('select * from YF_Money_CRID ');
      Open;
    end;
    CRID := ADOQueryCmd.fieldbyname('CRID').AsString;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YF_Money_KC where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('CRID').Value := StrToInt(CRID);
      FieldByName('FactoryName').Value := Trim(ADO.fieldbyname('custName').asstring);
      FieldByName('ZdyStr1').Value := '应收收';
      Post;
    end;
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete  from YF_Money_CR ');
    sql.Add(' where MainID=''' + Trim(ADO.fieldbyname('CRNO').AsString) + '''');
    sql.Add(' and subID=''' + Trim(ADO.fieldbyname('CRID').AsString) + '''');
    sql.Add(' and YFName=''产品销售'' ');
    execsql;
  end;

  with ADOQueryTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YF_Money_CR ');
    sql.Add(' where MainID=''' + Trim(ADO.fieldbyname('CRNO').AsString) + '''');
    sql.Add(' and subID=''' + Trim(ADO.fieldbyname('CRID').AsString) + '''');
    sql.Add(' and YFName=''产品销售'' ');
    Open;
  end;

  if ADOQueryTmp.IsEmpty then
  begin
    if GetLSNo(ADOQueryCmd, YFID, 'CS', 'YF_Money_CR', 4, 1) = False then
    begin
      Application.MessageBox('取应收最大号失败!', '提示', 0);
      Exit;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YF_Money_CR where 1<>1');
      Open;
    end;

    with ADOQueryCmd do
    begin
      Append;
      FieldByName('YFID').Value := Trim(YFID);
      FieldByName('YFTypeId').Value := Trim(ADO.fieldbyname('CRNO').AsString);
      FieldByName('CRID').Value := StrToInt(CRID);
      FieldByName('Filler').Value := Trim(DName);
      FieldByName('CRType').Value := '应收款登记';
      FieldByName('CRFlag').Value := '应收收';
      FieldByName('QtyFlag').Value := 1;
      FieldByName('FactoryName').Value := Trim(ADO.fieldbyname('custName').asstring);
      FieldByName('CRTime').Value := Trim(FormatDateTime('yyyy-MM-dd', ADO.fieldbyname('CRTime').AsDateTime));
      FieldByName('YFType').Value := '自动生成';
      FieldByName('ps').Value := ADO.fieldbyname('RollNum').AsFloat;
      FieldByName('Qty').Value := ADO.fieldbyname('Qty').AsFloat;
      FieldByName('Price').Value := ADO.fieldbyname('Price').AsFloat;
      FieldByName('Money').Value := ADO.fieldbyname('Money').AsFloat;
      FieldByName('BBMoney').Value := ADO.fieldbyname('Money').AsFloat;
      FieldByName('HuiLv').Value := 1;
      FieldByName('BZType').Value := '人民币';
      FieldByName('QtyUnit').Value := Trim(ADO.fieldbyname('QtyUnit').AsString);
      FieldByName('ComTaiTou').Value := Trim(cust);
      FieldByName('YFName').Value := '产品销售';
      FieldByName('MainId').Value := Trim(ADO.fieldbyname('CRNO').AsString);
      FieldByName('subID').Value := Trim(ADO.fieldbyname('CRID').AsString);
      FieldByName('status').Value := '0';
      Post;
    end;
  end
  else
  begin
    YFID := Trim(ADOQueryTmp.fieldbyname('YFID').AsString);
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update YF_Money_KC Set KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
    sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
    sql.Add(' where CRID=' + CRID);
    ExecSQL;
  end;

  Result := True;
end;

function TfrmPBCKlist.YSData_Other(ADO: TADOQuery; fYFName: string; fmoney: double): Boolean;
var
  CRID, YFID, Price, PriceUnit, OrderUnit, FComTaiTou, cust: string;
begin
  Result := False;
  with ADOQueryTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from YF_Money_KC where FactoryName=''' + Trim(ADO.fieldbyname('custName').asstring) + ''' and YFDefFlag1=0 ');
    Open;
  end;

  if not ADOQueryTmp.IsEmpty then
  begin
    CRID := ADOQueryTmp.fieldbyname('CRID').AsString;
  end
  else
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YF_Money_CRID set CRID=CRID+1');
      sql.Add('select * from YF_Money_CRID ');
      Open;
    end;
    CRID := ADOQueryCmd.fieldbyname('CRID').AsString;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YF_Money_KC where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('CRID').Value := StrToInt(CRID);
      FieldByName('FactoryName').Value := Trim(ADO.fieldbyname('custName').asstring);
      FieldByName('ZdyStr1').Value := '应收收';
      Post;
    end;
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete  from YF_Money_CR ');
    sql.Add(' where MainID=''' + Trim(ADO.fieldbyname('CRNO').AsString) + '''');
    sql.Add(' and subID=''' + Trim(ADO.fieldbyname('CRID').AsString) + '''');
    sql.Add(' and YFName=''' + trim(fYFName) + ''' ');
    execsql;
  end;

  with ADOQueryTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YF_Money_CR ');
    sql.Add(' where MainID=''' + Trim(ADO.fieldbyname('CRNO').AsString) + '''');
    sql.Add(' and subID=''' + Trim(ADO.fieldbyname('CRID').AsString) + '''');
    sql.Add(' and YFName=''' + trim(fYFName) + ''' ');
    Open;
  end;

  if ADOQueryTmp.IsEmpty then
  begin
    if GetLSNo(ADOQueryCmd, YFID, 'CS', 'YF_Money_CR', 4, 1) = False then
    begin
      Application.MessageBox('取应收最大号失败!', '提示', 0);
      Exit;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YF_Money_CR where 1<>1');
      Open;
    end;

    with ADOQueryCmd do
    begin
      Append;
      FieldByName('YFID').Value := Trim(YFID);
      FieldByName('YFTypeId').Value := Trim(ADO.fieldbyname('CRNO').AsString);
      FieldByName('CRID').Value := StrToInt(CRID);
      FieldByName('Filler').Value := Trim(DName);
      FieldByName('CRType').Value := '应收款登记';
      FieldByName('CRFlag').Value := '应收收';
      FieldByName('QtyFlag').Value := 1;
      FieldByName('FactoryName').Value := Trim(ADO.fieldbyname('custName').asstring);
      FieldByName('CRTime').Value := Trim(FormatDateTime('yyyy-MM-dd', ADO.fieldbyname('CRTIme').AsDateTime));
      FieldByName('YFType').Value := '自动生成';
      FieldByName('Qty').Value := 1;
      FieldByName('Price').Value := fmoney;
      FieldByName('Money').Value := fmoney;
      FieldByName('BBMoney').Value := fmoney;
      FieldByName('HuiLv').Value := 1;
      FieldByName('BZType').Value := '人民币';
      FieldByName('QtyUnit').Value := '个';
      FieldByName('ComTaiTou').Value := Trim(cust);
      FieldByName('YFName').Value := fYFName;
      FieldByName('MainId').Value := Trim(ADO.fieldbyname('CRNO').AsString);
      FieldByName('subID').Value := Trim(ADO.fieldbyname('CRID').AsString);
      FieldByName('status').Value := '0';
      Post;
    end;
  end
  else
  begin
    YFID := Trim(ADOQueryTmp.fieldbyname('YFID').AsString);
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update YF_Money_KC Set KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
    sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
    sql.Add(' where CRID=' + CRID);
    ExecSQL;
  end;

  Result := True;
end;

procedure TfrmPBCKlist.InitGrid();
begin
  try
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      sql.Add('select A.* ');
      SQL.Add(' from CK_PB_CR A ');
      sql.Add('where CRTime>=''' + formatdateTime('yyyy-MM-dd', begdate.Date) + ''' ');
      sql.Add('and CRTime<''' + formatdateTime('yyyy-MM-dd', enddate.Date + 1) + ''' ');
      sql.Add('and CRFlag=''出库'' and A.valid=''Y'' and CKName=''坯布仓库'' ');
      if trim(FZZType) <> '全部' then
        sql.Add(' and ZZType=' + quotedstr(trim(FZZType)));
      if canshu1 = '录入' then
      begin
        Sql.Add(' and Filler=' + quotedstr(Trim(DName)));
      end;
      sql.Add('order by A.CRNO,A.Code ');

      open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
  end;
end;

procedure TfrmPBCKlist.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := cafree;
end;

procedure TfrmPBCKlist.FormDestroy(Sender: TObject);
begin
//  frmPBCKlist:=nil;
end;

procedure TfrmPBCKlist.TBAddClick(Sender: TObject);
begin
  frmPBCk := TfrmPBCk.create(self);
  with frmPBCk do
  begin
    fkeyNo := '';
    fType := 0;
    FZZType := self.FZZType;
    if showmodal = 1 then
    begin
      TBRafresh.Click;
      self.CDS_Main.Locate('crNo', trim(fkeyNo), []);
    end;
    free;
  end;
end;

procedure TfrmPBCKlist.OrderNoChange(Sender: TObject);
begin
  if ADOQuerymain.Active = False then
    Exit;
  SDofilter(ADOQuerymain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQuerymain, CDS_Main);
  SInitCDSData20(ADOQuerymain, CDS_Main);
end;

procedure TfrmPBCKlist.FormShow(Sender: TObject);
var
  fsj: string;
begin
  readCxGrid(self.Caption, Tv1, '面料仓库1');
  fsj := 'select distinct(CRType) name from CK_PB_CR where CRFlag=''出库''   ';
  SInitComBoxBySql(ADOQueryCmd, CRType, False, fsj);
  SetStatus();
  InitGrid();
end;

procedure TfrmPBCKlist.FormCreate(Sender: TObject);
begin
  EndDate.Date := SGetServerDate10(ADOQueryTmp);
  BegDate.Date := EndDate.Date - 7;
  cxGrid1.Align := alclient;

end;

procedure TfrmPBCKlist.TBCloseClick(Sender: TObject);
begin
  writeCxGrid(self.Caption, Tv1, '面料仓库1');
  close;
end;

procedure TfrmPBCKlist.TBEditClick(Sender: TObject);
begin
  if cds_main.IsEmpty then
    exit;
  with ADOQueryTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YF_Money_CR_Sub where YFPZNO=''' + Trim(CDS_Main.fieldbyname('CRID').AsString) + '''');
    Open;
  end;
  if ADOQueryTmp.IsEmpty = False then
  begin
    Application.MessageBox('已经生成财务数据不能操作!', '提示', 0);
    Exit;
  end;
  if (cds_main.fieldbyname('Filler').AsString <> trim(DName)) and (trim(canshu2) <> '高权限') then
  begin
    application.MessageBox('操作员不正确，不能修改！', '提示信息', MB_ICONERROR);
    exit;
  end;

  frmPBCk := TfrmPBCk.create(self);
  with frmPBCk do
  begin
    fkeyNo := self.cds_main.fieldbyname('CRID').AsString;
    fType := 1;
    fckName := self.fckName;
    FZZType := self.FZZType;
    CRNO.Enabled := false;
    if showmodal = 1 then
    begin
      TBRafresh.Click;
      self.CDS_Main.Locate('CRNO', trim(fkeyNo), []);
    end;
    free;
  end;
end;

procedure TfrmPBCKlist.TBDelClick(Sender: TObject);
var
  YFID, CRID, note: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  with ADOQueryTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YF_Money_CR_Sub where YFPZNO=''' + Trim(CDS_Main.fieldbyname('CRID').AsString) + '''');
    Open;
  end;
  if ADOQueryTmp.IsEmpty = False then
  begin
    Application.MessageBox('已经生成财务数据不能操作!', '提示', 0);
    Exit;
  end;
  if Trim(CDS_Main.fieldbyname('Filler').AsString) <> Trim(DName) then
  begin
    Application.MessageBox('不能操作他人数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    if Trim(CDS_Main.FieldByName('CRNO').AsString) <> '' then
    begin
      ADOQueryCmd.Connection.BeginTrans;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('update CK_PB_CR set Valid=''N''  where CRID=' + quotedstr(Trim(CDS_Main.FieldByName('CRID').AsString)));
        ExecSQL;
      end;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        SQL.Add('exec P_Up_PBKc ' + quotedstr(Trim(CDS_Main.FieldByName('CRID').AsString)));
        Open;
      end;
      if Trim(ADOQueryCmd.FieldByName('Msg').AsString) = '操作失败' then
      begin
        CDS_Main.EnableControls;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('出库数量超出库存数量!', '提示', 0);
        Exit;
      end;
      ADOQueryCmd.Connection.CommitTrans;
      CDS_Main.Delete;
    end;
  except
    Application.MessageBox('数据删除失败！', '提示信息', 0);
  end;
end;

procedure TfrmPBCKlist.TBRafreshClick(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmPBCKlist.TBPrintClick(Sender: TObject);
var
  filepath: string;
  Porderno, PRTCodeName, funit: string;
  i, j: Integer;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if CDS_Main.IsEmpty then
    exit;
  with AdoPrint do
  begin
    close;
    sql.Clear;
    sql.Add('exec P_Print_MlCK  @inoutNO=' + quotedstr(trim(CDS_Main.fieldbyname('crno').AsString)));
    open;
  end;

  try
    filepath := ExtractFilePath(Application.ExeName) + 'report\面料出库码单.rmf';
    if not FileExists(Pchar(filepath)) then
    begin
      application.MessageBox(pchar('文件[' + filepath + ']不存在！'), '提示信息', MB_IConError);
      exit;
    end;
    RMVariables['dtxz'] := FormatDateTime('yyyy-mm-dd', date());
    RMVariables['zdr'] := trim(DName);
    RMVariables['Filler'] := trim(CDS_Main.fieldbyname('Filler').AsString);
    RM1.LoadFromFile(filepath);
    RM1.ShowReport;
  finally

  end;

end;

procedure TfrmPBCKlist.TBExportClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmPBCKlist.v1Column6CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
var
  colIdx0, colIdx1: integer;
begin
  colIdx0 := tv1.GetColumnByFieldName('CRNO').Index;
  if (ARow1.Values[colIdx0] = ARow2.Values[colIdx0]) then
    AAreEqual := True
  else
    AAreEqual := False;

end;

procedure TfrmPBCKlist.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmPBCKlist.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmPBCKlist.ToolButton1Click(Sender: TObject);
begin
  frmPBCKMXLR := TfrmPBCKMXLR.create(self);
  with frmPBCKMXLR do
  begin
    fkeyNo := self.cds_main.fieldbyname('CRID').AsString;
    fType := 0;
    if showmodal = 1 then
    begin

      self.InitGrid();
      self.CDS_Main.Locate('CRID', fkeyNo, [])
    end;
    free;
  end;
end;

procedure TfrmPBCKlist.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  InitMXGrid(Trim(CDS_Main.fieldbyname('CRID').AsString));
end;

end.

