unit U_SXKCCK220314;

interface

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

type
  TfrmSXKCCK220314 = class(TForm)
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_MainSel: TDataSource;
    cxGridPopupMenu4: TcxGridPopupMenu;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    CDS_YanSe: TClientDataSet;
    RMXLSExport1: TRMXLSExport;
    RMDBMX: TRMDBDataSet;
    RM1: TRMGridReport;
    DS_YanSe: TDataSource;
    Panel1: TPanel;
    Panel3: TPanel;
    Label5: TLabel;
    CKOrdNo: TEdit;
    cxGrid5: TcxGrid;
    TV5: TcxGridDBTableView;
    v1Column12: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    cxGrid5Level1: TcxGridLevel;
    Button2: TButton;
    Button1: TButton;
    KHName: TEdit;
    Label9: TLabel;
    Panel2: TPanel;
    Button3: TButton;
    Button4: TButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridLevel2: TcxGridLevel;
    Panel4: TPanel;
    V1Column15: TcxGridDBColumn;
    V1Column17: TcxGridDBColumn;
    V1Column19: TcxGridDBColumn;
    V1Column20: TcxGridDBColumn;
    V1Column21: TcxGridDBColumn;
    V1Column22: TcxGridDBColumn;
    V1Column23: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    Panel6: TPanel;
    Panel5: TPanel;
    Panel7: TPanel;
    Edit1: TEdit;
    Label1: TLabel;
    Edit2: TEdit;
    Label2: TLabel;
    Edit3: TEdit;
    Label3: TLabel;
    Edit4: TEdit;
    Label4: TLabel;
    Label6: TLabel;
    Edit6: TEdit;
    Label7: TLabel;
    Edit7: TEdit;
    Label8: TLabel;
    Edit8: TEdit;
    Label10: TLabel;
    Edit9: TEdit;
    Label11: TLabel;
    Edit10: TEdit;
    Label12: TLabel;
    Edit11: TEdit;
    Label13: TLabel;
    Edit12: TEdit;
    Label14: TLabel;
    CPType: TComboBox;
    Edit5: TEdit;
    Label15: TLabel;
    Edit13: TEdit;
    Label16: TLabel;
    Button5: TButton;
    btnCX: TButton;
    Panel8: TPanel;
    Label17: TLabel;
    CDS_MainSel: TClientDataSet;
    CDS_GangHao: TClientDataSet;
    CDS_TuoTuan: TClientDataSet;
    DS_GangHao: TDataSource;
    DS_TuoTuan: TDataSource;
    V1Column10: TcxGridDBColumn;
    V2Column2: TcxGridDBColumn;
    V3Column1: TcxGridDBColumn;
    V3Column2: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    V2Column7: TcxGridDBColumn;
    V1Column11: TcxGridDBColumn;
    V2Column8: TcxGridDBColumn;
    V3Column3: TcxGridDBColumn;
    CDS_YanSeSel: TClientDataSet;
    CDS_GangHaoSel: TClientDataSet;
    CDS_TuoTuanSel: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGridPopupMenu3: TcxGridPopupMenu;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure btnCXClick(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure V1Column10PropertiesEditValueChanged(Sender: TObject);
    procedure V2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure V3Column1PropertiesEditValueChanged(Sender: TObject);
  private
    { Private declarations }
    fsjYS,fsjGH,fsjTP:String;
    procedure InitKC();
    procedure initMXKC();
  public
    { Public declarations }
  end;

var
  frmSXKCCK220314: TfrmSXKCCK220314;

implementation

uses
  U_DataLink, U_Fun, U_RTFun, MMSystem, U_FHSQListSel, U_CKProductBCPKCListSel;

{$R *.dfm}

procedure TfrmSXKCCK220314.InitKC();
var
  fwhere, Pwhere: string;
begin

  Pwhere := SGetFilters(Panel1, 1, 2);
  if trim(Pwhere) <> '' then
    fwhere := fwhere + ' where ' + trim(Pwhere);

  with ADOQueryTemp do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add(' Select AA.* ');
    sql.Add(' ,B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ ');
    sql.Add('  ,C.PRTColor,C.PRTEColor,C.PRTHX,C.PrtKuanNo,C.PRTColorNo ');
    sql.Add('  from(select A.MainId,A.Subid,QtyY=sum(Cast(A.Qty*1.0936 as decimal(18,1))),QtyM=sum(Qty),QtyKg=Sum(KgQty),PS=Count(*) ');
    sql.Add('  from  CK_BanCP_CR A inner join CK_BanCP_KC D on A.MJID=D.MJID ');
    sql.Add('  where A.CRFlag=''入库'' and D.KCValid=''Y''  ');
    sql.Add('  and exists(select SubId from FHSQ_Sub X where X.SubId=A.SubId and X.FSId=' + QUOTEDSTR(CKOrdNo.Text) + ')  ');
    sql.Add('  Group by A.MainId,A.Subid) AA ');
    sql.Add('  inner join JYOrder_Main B on AA.MainId=B.MainId  ');
    sql.Add('  inner join JYOrder_Sub C on AA.SubId=C.SubId  ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_YanSe);
  SInitCDSData20(ADOQueryTemp, CDS_YanSe);
  SelOKNo(CDS_YanSe,True);

  with ADOQueryTemp do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add(' Select AA.* ');
    sql.Add(' ,B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ ');
    sql.Add('  ,C.PRTColor,C.PRTEColor,C.PRTHX,C.PrtKuanNo,C.PRTColorNo ');
    sql.Add('  from(select A.MainId,A.Subid,A.APID,A.GangHao,QtyY=sum(Cast(A.Qty*1.0936 as decimal(18,1))),QtyM=sum(Qty),QtyKg=Sum(KgQty),PS=Count(*) ');
    sql.Add('  from  CK_BanCP_CR A inner join CK_BanCP_KC D on A.MJID=D.MJID ');
    sql.Add('  where A.CRFlag=''入库'' and D.KCValid=''Y''  ');
    sql.Add('  and exists(select SubId from FHSQ_Sub X where X.SubId=A.SubId and X.FSId=' + QUOTEDSTR(CKOrdNo.Text) + ')  ');
    sql.Add('  Group by A.MainId,A.Subid,A.APID,A.GangHao) AA ');
    sql.Add('  inner join JYOrder_Main B on AA.MainId=B.MainId  ');
    sql.Add('  inner join JYOrder_Sub C on AA.SubId=C.SubId  ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_GangHao);
  SInitCDSData20(ADOQueryTemp, CDS_GangHao);
  SelOKNo(CDS_GangHao,True);

  with ADOQueryTemp do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add(' Select AA.* ');
    sql.Add(' ,B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ ');
    sql.Add('  from(select A.MainId,A.RKOrdID,QtyY=sum(Cast(A.Qty*1.0936 as decimal(18,1))),QtyM=sum(Qty),QtyKg=Sum(KgQty),PS=Count(*) ');
    sql.Add('  from  CK_BanCP_CR A inner join CK_BanCP_KC D on A.MJID=D.MJID ');
    sql.Add('  where A.CRFlag=''入库'' and D.KCValid=''Y''  ');
    sql.Add('  and exists(select SubId from FHSQ_Sub X where X.SubId=A.SubId and X.FSId=' + QUOTEDSTR(CKOrdNo.Text) + ')  ');
    sql.Add('  Group by A.MainId,A.RKOrdID) AA ');
    sql.Add('  inner join JYOrder_Main B on AA.MainId=B.MainId  ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_TuoTuan);
  SInitCDSData20(ADOQueryTemp, CDS_TuoTuan);
  SelOKNo(CDS_TuoTuan,True);

  with ADOQueryTemp do
  begin
    Filtered := False;
    Close;
    sql.Clear;

    sql.Add('  select A.*,QtyY=Cast(A.Qty*1.0936 as decimal(18,1)) ');
    sql.Add(' ,B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ ');
    sql.Add('  ,C.PRTColor,C.PRTEColor,C.PRTHX,C.PrtKuanNo ');
    sql.Add('  from  CK_BanCP_CR A inner join CK_BanCP_KC D on A.MJID=D.MJID ');
    sql.Add('  inner join JYOrder_Main B on A.MainId=B.MainId  ');
    sql.Add('   inner join JYOrder_Sub C on A.SubId=C.SubId  ');
    sql.Add('   where A.CRFlag=''入库'' and D.KCValid=''Y''  ');
    sql.Add('   and exists(select SubId from FHSQ_Sub X where X.SubId=A.SubId and X.FSId=' + QUOTEDSTR(CKOrdNo.Text) + ')  ');

    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_MainSel);
  SInitCDSData20(ADOQueryTemp, CDS_MainSel);
  SelOKNo(CDS_MainSel,True);

end;
procedure TfrmSXKCCK220314.initMXKC();
var
  fsj:string;
begin
  fsj:='';
  with CDS_YanSeSel do
  begin
    First;
    while not eof do
    begin
      if Trim(fsj)='' then
      begin
        fsj:=fsj+''''+Trim(fieldbyname('SubId').AsString)+'''';
      end else
        fsj:=fsj+','+''''+Trim(fieldbyname('SubId').AsString)+'''';
      Next;
    end;
  end;
  fsjYS:=fsj;

  fsj:='';
  with CDS_GangHaoSel do
  begin
    First;
    while not eof do
    begin
      if Trim(fsj)='' then
      begin
        fsj:=fsj+''''+Trim(fieldbyname('APId').AsString)+'''';
      end else
        fsj:=fsj+','+''''+Trim(fieldbyname('APId').AsString)+'''';
      Next;
    end;
  end;
  fsjGH:=fsj;

  fsj:='';
  with CDS_TuoTuanSel do
  begin
    First;
    while not eof do
    begin
      if Trim(fsj)='' then
      begin
        fsj:=fsj+''''+Trim(fieldbyname('RKOrdID').AsString)+'''';
      end else
        fsj:=fsj+','+''''+Trim(fieldbyname('RKOrdID').AsString)+'''';
      Next;
    end;
  end;
  fsjTP:=fsj;
  
  with ADOQueryTemp do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add('  select A.*,QtyY=Cast(A.Qty*1.0936 as decimal(18,1)) ');
    sql.Add(' ,B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ ');
    sql.Add('  ,C.PRTColor,C.PRTEColor,C.PRTHX,C.PrtKuanNo ');
    sql.Add('  from  CK_BanCP_CR A inner join CK_BanCP_KC D on A.MJID=D.MJID ');
    sql.Add('  inner join JYOrder_Main B on A.MainId=B.MainId  ');
    sql.Add('   inner join JYOrder_Sub C on A.SubId=C.SubId  ');
    sql.Add('   where A.CRFlag=''入库'' and D.KCValid=''Y''  ');
    sql.Add('   and exists(select SubId from FHSQ_Sub X where X.SubId=A.SubId and X.FSId=' + QUOTEDSTR(CKOrdNo.Text) + ')  ');
    if Trim(fsjYS)<>'' then
    begin
      sql.Add('  and A.Subid in('+Trim(fsjYS)+')');
    end;
    if Trim(fsjGH)<>'' then
    begin
      sql.Add('  and A.APid in('+Trim(fsjGH)+')');
    end;
    if Trim(fsjTP)<>'' then
    begin
      sql.Add('  and A.RKOrdID in('+Trim(fsjTP)+')');
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_MainSel);
  SInitCDSData20(ADOQueryTemp, CDS_MainSel);
  SelOKNo(CDS_MainSel,True);
end;
procedure TfrmSXKCCK220314.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmSXKCCK220314.FormDestroy(Sender: TObject);
begin
  frmSXKCCK220314 := nil;
end;

procedure TfrmSXKCCK220314.FormShow(Sender: TObject);
begin

  ReadCxGrid('扫描出库1', Tv1, '成品仓库');
  ReadCxGrid('扫描出库2', Tv2, '成品仓库');
  ReadCxGrid('扫描出库3', Tv3, '成品仓库');
  ReadCxGrid('扫描出库5', Tv5, '成品仓库');
end;

procedure TfrmSXKCCK220314.Button2Click(Sender: TObject);
begin
  Close;
  WriteCxGrid('扫描出库1', Tv1, '成品仓库');
  WriteCxGrid('扫描出库2', Tv2, '成品仓库');
  WriteCxGrid('扫描出库3', Tv3, '成品仓库');
  WriteCxGrid('扫描出库5', Tv5, '成品仓库');
end;

procedure TfrmSXKCCK220314.Button1Click(Sender: TObject);
var
  MKey: Char;
begin

  try
    frmFHSQListSel := TfrmFHSQListSel.Create(self);
    with frmFHSQListSel do
    begin
      if ShowModal = 1 then
      begin
        self.CKOrdNo.Text := Trim(Order_Main.fieldbyname('FSID').AsString);

      end;
    end;
  finally
    frmFHSQListSel.Free;
  end;
  btnCX.Click;
end;

procedure TfrmSXKCCK220314.btnCXClick(Sender: TObject);
begin
  if Trim(CKOrdNo.Text) = '' then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select SubId from FHSQ_Sub where FSId=' + QUOTEDSTR(CKOrdNo.Text));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_YanSeSel);
  SInitCDSData20(ADOQueryTemp,CDS_YanSeSel);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select APId from CK_BanCP_CR A inner join CK_BanCP_KC D on A.MJID=D.MJID  ');
    sql.Add('  where A.CRFlag=''入库'' and D.KCValid=''Y''  ');
    sql.Add('  and exists(select SubId from FHSQ_Sub X where X.SubId=A.SubId and X.FSId=' + QUOTEDSTR(CKOrdNo.Text) + ')  ');
    sql.Add(' Group by APID ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_GangHaoSel);
  SInitCDSData20(ADOQueryTemp,CDS_GangHaoSel);

  with ADOQueryTemp do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add(' select A.RKOrdID ');
    sql.Add('  from  CK_BanCP_CR A inner join CK_BanCP_KC D on A.MJID=D.MJID ');
    sql.Add('  where A.CRFlag=''入库'' and D.KCValid=''Y''  ');
    sql.Add('  and exists(select SubId from FHSQ_Sub X where X.SubId=A.SubId and X.FSId=' + QUOTEDSTR(CKOrdNo.Text) + ')  ');
    sql.Add('  Group by A.RKOrdID ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_TuoTuanSel);
  SInitCDSData20(ADOQueryTemp, CDS_TuoTuanSel);
  InitKC();
end;

procedure TfrmSXKCCK220314.Button5Click(Sender: TObject);
var
  SqlMJID: string;
begin
  CDS_MainSel.DisableControls;
  with CDS_MainSel do
  begin
    First;
    SqlMJID := '';
    while not Eof do
    begin
      if Trim(SqlMJID) = '' then
        SqlMJID := QuotedStr(Trim(CDS_MainSel.fieldbyname('MJID').AsString))
      else
        SqlMJID := SqlMJID + ',' + QuotedStr(Trim(CDS_MainSel.fieldbyname('MJID').AsString));
      Next;
    end;
    SqlMJID := 'MJID IN (' + SqlMJID + ')'
  end;
  CDS_MainSel.EnableControls;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE CK_BanCP_CR Set  ');
      sql.add(' CRTime=getdate(),CRType=''扫描出库'',CRFlag=''出库''  ');
      sql.add(',CKOrdNo=' + quotedstr(Trim(CKOrdNo.Text)));
      sql.add(',filler=' + quotedstr(DName));
      sql.Add(' where ' + SqlMJID);
      sql.Add('and CK_BanCP_CR.CRFlag=''待出库''  ');
      ExecSQL;
    end;
    //更新kcvalid状态
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE CK_BanCP_KC Set  ');
      sql.add(' KCValid=''N''  ');
      sql.Add(' where ' + SqlMJID);
      ExecSQL;
    end;
    //更新出入库状态
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE WFB_MJJY Set  MJStr2=''已出库''  ');
      sql.Add(' where ' + SqlMJID);
      SQL.Add(' and WFB_MJJY.MJStr2=''已入库'' ');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_Do_FHSQ ''' + Trim(CKOrdNo.Text) + '''');
    ExecSQL;
  end;
end;

procedure TfrmSXKCCK220314.V1Column10PropertiesEditValueChanged(Sender: TObject);
var
  mvalue:Boolean;
  fsj:string;
begin
  mvalue:=TcxCheckBox(Sender).EditingValue;
  with CDS_YanSe do
  begin
    Edit;
    FieldByName('SSel').Value:=mvalue;
  end;
  if mvalue=True then
  begin
    with CDS_YanSeSel do
    begin
      Append;
      FieldByName('SubId').Value:=Trim(CDS_YanSe.fieldbyname('SubId').AsString);
      Post;
    end;
  end else
  begin
    CDS_YanSeSel.Locate('SubId',Trim(CDS_YanSe.fieldbyname('SubId').AsString),[]);
    CDS_YanSeSel.Delete;
  end;
  fsj:='';
  with CDS_YanSeSel do
  begin
    First;
    while not eof do
    begin
      if Trim(fsj)='' then
      begin
        fsj:=fsj+''''+Trim(fieldbyname('SubId').AsString)+'''';
      end else
        fsj:=fsj+','+''''+Trim(fieldbyname('SubId').AsString)+'''';
      Next;
    end;
  end;
  with ADOQueryTemp do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add(' Select AA.* ');
    sql.Add(' ,B.OrderNo,B.MPRTCode,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ ');
    sql.Add('  ,C.PRTColor,C.PRTEColor,C.PRTHX,C.PrtKuanNo,C.PRTColorNo ');
    sql.Add('  from(select A.MainId,A.Subid,A.GangHao,A.APID,QtyY=sum(Cast(A.Qty*1.0936 as decimal(18,1))),QtyM=sum(Qty),QtyKg=Sum(KgQty),PS=Count(*) ');
    sql.Add('  from  CK_BanCP_CR A inner join CK_BanCP_KC D on A.MJID=D.MJID ');
    sql.Add('  where A.CRFlag=''入库'' and D.KCValid=''Y''  ');
    sql.Add('  and exists(select SubId from FHSQ_Sub X where X.SubId=A.SubId and X.FSId=' + QUOTEDSTR(CKOrdNo.Text) + ')  ');
    if Trim(fsj)<>'' then
    begin
      sql.Add('  and A.Subid in('+Trim(fsj)+')');
    end else
    begin
      sql.Add('  and 1=2');
    end;
    sql.Add('  Group by A.MainId,A.Subid,A.GangHao,A.APID) AA ');
    sql.Add('  inner join JYOrder_Main B on AA.MainId=B.MainId  ');
    sql.Add('  inner join JYOrder_Sub C on AA.SubId=C.SubId  ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_GangHao);
  SInitCDSData20(ADOQueryTemp, CDS_GangHao);
  SelOKNo(CDS_GangHao,True);
  
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select APId=Cast(Null as varchar(20))');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_GangHaoSel);
  SInitCDSData20(ADOQueryTemp,CDS_GangHaoSel);
  if CDS_GangHaoSel.IsEmpty=False then
  begin
    CDS_GangHaoSel.Delete;
  end;
  CDS_GangHao.DisableControls;
  with CDS_GangHao do
  begin
    First;
    while not Eof do
    begin
      if FieldByName('SSel').AsBoolean=True then
      begin
        with CDS_GangHaoSel do
        begin
          Append;
          CDS_GangHaoSel.FieldByName('APID').Value:=CDS_GangHao.FieldByName('APID').Value;
          Post;
        end;
      end;
      Next;
    end;
  end;
  CDS_GangHao.EnableControls;
  initMXKC();
end;

procedure TfrmSXKCCK220314.V2Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue:Boolean;
begin
  mvalue:=TcxCheckBox(Sender).EditingValue;
  with CDS_GangHao do
  begin
    Edit;
    FieldByName('SSel').Value:=mvalue;
  end;
  if mvalue=True then
  begin
    with CDS_GangHaoSel do
    begin
      Append;
      FieldByName('APId').Value:=Trim(CDS_GangHao.fieldbyname('APId').AsString);
      Post;
    end;
  end else
  begin
    CDS_GangHaoSel.Locate('APId',Trim(CDS_GangHao.fieldbyname('APId').AsString),[]);
    CDS_GangHaoSel.Delete;
  end;
  initMXKC();
end;

procedure TfrmSXKCCK220314.V3Column1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue:Boolean;
begin
  mvalue:=TcxCheckBox(Sender).EditingValue;
  with CDS_TuoTuan do
  begin
    Edit;
    FieldByName('SSel').Value:=mvalue;
  end;
  if mvalue=True then
  begin
    with CDS_TuoTuanSel do
    begin
      Append;
      FieldByName('RKOrdID').Value:=Trim(CDS_TuoTuan.fieldbyname('RKOrdID').AsString);
      Post;
    end;
  end else
  begin
    CDS_TuoTuanSel.Locate('RKOrdID',Trim(CDS_TuoTuan.fieldbyname('RKOrdID').AsString),[]);
    CDS_TuoTuanSel.Delete;
  end;
  initMXKC();
end;

end.

