unit U_LLCKList;

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, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxSkinsCore, dxSkinDarkRoom,
  dxSkinOffice2013White, dxSkinSharpPlus, dxSkinSpringTime,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray, dxSkinOffice2013LightGray,
  dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSilver,
  dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue;

type
  TfrmLLCKList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_Main: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    ToolButton1: TToolButton;
    Panel1: TPanel;
    v1Column1: TcxGridDBColumn;
    Label34: TLabel;
    v1Column7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    KHNameHZ: TEdit;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport2: TRMXLSExport;
    CDS_3: TClientDataSet;
    v1Column17: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Label2: TLabel;
    MYName: TEdit;
    v1Column3: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    Label1: TLabel;
    Note: TEdit;
    labMYType: TLabel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    CheckBox1: TCheckBox;
    v1JCDanWeiJC: TcxGridDBColumn;
    Label3: TLabel;
    JCDanWeiJC: TEdit;
    v1filler: TcxGridDBColumn;
    Label4: TLabel;
    filler: TEdit;
    CDS_2: TClientDataSet;
    v1Column4: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    Label5: TLabel;
    MYTypeFlag: TComboBox;
    v1Column11: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    Label6: TLabel;
    MLOrderNo: TEdit;
    Label7: TLabel;
    KHNameHZZ: TEdit;
    v1Column13: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Label8: TLabel;
    PBBatchNo: TEdit;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Label9: TLabel;
    MYColor: TEdit;
    Tv1Column6: TcxGridDBColumn;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    TV2Ssel: TcxGridDBColumn;
    TV2KHName: TcxGridDBColumn;
    TV2KHNo: TcxGridDBColumn;
    TV2MYType: TcxGridDBColumn;
    TV2PS: TcxGridDBColumn;
    Tv2Qty: TcxGridDBColumn;
    TV2KgQty: TcxGridDBColumn;
    TV2Note: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    TabSheet2: TTabSheet;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    TV3Ssel: TcxGridDBColumn;
    TV3MLOrderNo: TcxGridDBColumn;
    TV3KHCode: TcxGridDBColumn;
    TV3KHName: TcxGridDBColumn;
    TV3CRTime: TcxGridDBColumn;
    TV3PBBatchNo: TcxGridDBColumn;
    TV3GYSNo: TcxGridDBColumn;
    TV3KHNameJC: TcxGridDBColumn;
    TV3KHNameJCDH: TcxGridDBColumn;
    TV3MYType: TcxGridDBColumn;
    TV3MYName: TcxGridDBColumn;
    TV3MYColor: TcxGridDBColumn;
    TV3MYColorNo: TcxGridDBColumn;
    TV3filler: TcxGridDBColumn;
    TV3RCGangNo: TcxGridDBColumn;
    TV3JH: TcxGridDBColumn;
    TV3JKGQTY: TcxGridDBColumn;
    TV3JMQTY: TcxGridDBColumn;
    TV3MYMF: TcxGridDBColumn;
    TV3MYKZ: TcxGridDBColumn;
    TV3SJKZ: TcxGridDBColumn;
    TV3Note: TcxGridDBColumn;
    TV3RCColor: TcxGridDBColumn;
    TV3ZKZT: TcxGridDBColumn;
    TV3CDZSD: TcxGridDBColumn;
    TV3KW: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    TabSheet3: TTabSheet;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    TV4RCGangNo: TcxGridDBColumn;
    TV4JH: TcxGridDBColumn;
    TV4KgQty: TcxGridDBColumn;
    TV4MQty: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    ADOQuery3: TADOQuery;
    ADOQuery2: TADOQuery;
    DS_2: TDataSource;
    DS_3: TDataSource;
    DS_Sub: TDataSource;
    CDS_Sub: TClientDataSet;
    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 ToolButton1Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure ZJStatusChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure v1Column1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure v1Column17CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure v1Column3CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
  private
    FGXName: string;
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitGridByCustomer();
    procedure InitMXGrid();
    procedure InitSubGrid();
    { Private declarations }
  public
    FFInt, FCloth: Integer;
    canshu1: string;

    { Public declarations }
  end;

var
  frmLLCKList: TfrmLLCKList;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LLCKInPut;

{$R *.dfm}

procedure TfrmLLCKList.FormDestroy(Sender: TObject);
begin
  frmLLCKList := nil;
end;

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

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

procedure TfrmLLCKList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('加工出库汇总主表', Tv1, '贸易生产管理');
  WriteCxGrid('加工出库汇总子表', TV4, '贸易生产管理');
  WriteCxGrid('加工出库客户表', TV2, '贸易生产管理');
  WriteCxGrid('加工出库明细表', TV3, '贸易生产管理');
  Close;
end;

procedure TfrmLLCKList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select AA.* ');
      sql.Add(',KHNameHZ=dbo.getpinyin(isnull(AA.KHNameJC,''''))+AA.GYSNo+isnull(AA.KHNameJC,'''')');
      sql.Add('from(');
      sql.Add(' select A.* ');
      sql.Add(',KHNameJC=(select Top 1 B.KHNameJC from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHNO=A.GYSNo)');
      sql.Add(',KHNameJCDH=(select Top 1 B.KHNameJC from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHNO=A.ToGYSNo)');
      sql.Add(',KHNameHZZ=dbo.getpinyin(isnull(KM.KHNameJC,''''))+B.KHNO+isnull(KM.KHNameJC,'''')');
      sql.Add(',KHNameJCZ=KM.KHNameJC,B.MLOrderNo,KHNOKH=B.KHNO');
      sql.Add(' from CK_MYSC_CR A  ');
      sql.Add(' left join ML_OrderMainNew B on A.MainId=B.NewMLID');
      sql.Add(' left join KH_Main KM on KM.KHNO=B.KHNO ');
      sql.Add(' where 1=1 ');
      if CheckBox1.Checked = False then
      begin
        sql.Add(' and A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM', now) + '-01') + '''');
        sql.Add(' and A.CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', now + 1)) + '''');
        BegDate.Visible := false;
        EndDate.Visible := false;
      end
      else
      begin
        sql.Add(' and A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.Add(' and A.CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
        BegDate.Visible := true;
        EndDate.Visible := true;
      end;
      sql.Add(' and isnull(CRType,'''')=''来料入库'' ');
      if canshu1 <> '高权限' then
      begin
        sql.add(' and A.filler=''' + trim(DName) + '''');
      end;
      sql.Add(')AA');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
    InitSubGrid();
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmLLCKList.InitGridByCustomer();
begin
  try
    ADOQuery2.DisableControls;
    with ADOQuery2 do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add(' SELECT A.KHName,A.KHCode,A.MYType,SUM(A.PS) as PS,SUM(A.Qty) AS Qty,SUM(A.KgQty) AS KgQty ');
      sql.Add(' from CK_MYSC_CR A  ');
      sql.Add(' where 1=1 ');
      if CheckBox1.Checked = False then
      begin
        sql.Add(' and A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', now)) + '''');
        sql.Add(' and A.CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', now + 1)) + '''');
        BegDate.Visible := false;
        EndDate.Visible := false;
      end
      else
      begin
        sql.Add(' and A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.Add(' and A.CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
        BegDate.Visible := true;
        EndDate.Visible := true;
      end;
      sql.Add(' and isnull(A.CRType,'''')=''来料入库'' ');
      sql.Add(' GROUP BY  A.KHName, A.KHCode, A.MYType ');
      sql.Add(' ORDER BY MIN(A.CRTime),A.KHName');
      Open;
    end;
    SCreateCDS20(ADOQuery2, CDS_2);
    SInitCDSData20(ADOQuery2, CDS_2);
  finally
    ADOQuery2.EnableControls;
  end;
end;

procedure TfrmLLCKList.InitMXGrid();
begin
  try
    ADOQuery3.DisableControls;
    with ADOQuery3 do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select AA.* ');
      sql.Add(',KHNameHZ=dbo.getpinyin(isnull(AA.KHNameJC,''''))+AA.GYSNo+isnull(AA.KHNameJC,'''')');
      sql.Add('from(');
      sql.Add(' select A.*,D.KGQTY as JKGQTY ,D.MQTY as JMQTY ,D.MXID,D.CDZSD,D.Fsubid,D.CMXID,D.ZKZT,D.JH,D.KW');
      sql.Add(',KHNameJC=(select Top 1 B.KHNameJC from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHNO=A.GYSNo)');
      sql.Add(',KHNameJCDH=(select Top 1 B.KHNameJC from KH_Main B ');
      sql.Add(' where isnull(B.KHFlag,'''')=''GYS'' and isnull(B.Valid,'''')=''Y'' and B.KHNO=A.ToGYSNo)');
      sql.Add(',KHNameHZZ=dbo.getpinyin(isnull(KM.KHNameJC,''''))+B.KHNO+isnull(KM.KHNameJC,'''')');
      sql.Add(',KHNameJCZ=KM.KHNameJC,B.MLOrderNo,KHNOKH=B.KHNO');
      sql.Add(' from CK_MYSC_CR A  ');
      sql.Add(' left join CK_MYSC_CR_MX D on D.MYID=A.MYID');
      sql.Add(' left join ML_OrderMainNew B on A.MainId=B.NewMLID');
      sql.Add(' left join KH_Main KM on KM.KHNO=B.KHNO ');
      sql.Add(' where 1=1 ');

      if CheckBox1.Checked = False then
      begin
        sql.Add(' and A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', now)) + '''');
        sql.Add(' and A.CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', now + 1)) + '''');
        BegDate.Visible := false;
        EndDate.Visible := false;
      end
      else
      begin
        sql.Add(' and A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.Add(' and A.CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
        BegDate.Visible := true;
        EndDate.Visible := true;
      end;
      sql.Add(' and isnull(CRType,'''')=''来料入库'' ');
      sql.Add(')AA');
      sql.Add(' order by AA.CRTime,AA.KHName');
//      ShowMessage(SQL.Text);
      Open;
    end;

    SCreateCDS20(ADOQuery3, CDS_3);
    SInitCDSData20(ADOQuery3, CDS_3);

  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmLLCKList.InitSubGrid();
var
  MYID: string;
begin
  if Order_Main.IsEmpty then
    exit;

  try
    ADOQueryTemp.DisableControls;
    MYID := Order_Main.FieldByName('MYID').AsString;

    with ADOQueryTemp do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('SELECT * FROM CK_MYSC_CR_MX WHERE MYID = ''' + MYID + '''');
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_Sub);
    SInitCDSData20(ADOQueryTemp, CDS_Sub);
  finally
    ADOQueryTemp.EnableControls;
  end;

end;

procedure TfrmLLCKList.InitForm();
var
  fsj: string;
begin
  BegDate.Date := StrToDate(formatdatetime('yyyy-MM', SGetServerDate(ADOQueryTemp)) + '-01');
  EndDate.Date := SGetServerDate(ADOQueryTemp);

  ReadCxGrid('加工出库汇总主表', Tv1, '贸易生产管理');
  ReadCxGrid('加工出库汇总子表', TV4, '贸易生产管理');
  ReadCxGrid('加工出库客户表', TV2, '贸易生产管理');
  ReadCxGrid('加工出库明细表', TV3, '贸易生产管理');

  InitGrid();
  InitGridByCustomer();
  InitMXGrid();
end;

procedure TfrmLLCKList.TBFindClick(Sender: TObject);
begin

  if ADOQueryMain.Active = False then
    Exit
  else
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  end;

  if ADOQuery2.Active = False then
    Exit
  else
  begin
    SDofilter(ADOQuery2, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQuery2, CDS_2);
    SInitCDSData20(ADOQuery2, CDS_2);
  end;

  if ADOQuery3.Active = False then
    Exit
  else
  begin
    SDofilter(ADOQuery3, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQuery3, CDS_3);
    SInitCDSData20(ADOQuery3, CDS_3);
  end;
end;

function TfrmLLCKList.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(' delete YS_Money_CR where YFTypeId=''' + Trim(Order_Main.fieldbyname('MYID').AsString) + '''');
          sql.Add(' insert into CK_MYSC_CR_Log  ');
          sql.Add(' select * from CK_MYSC_CR where MYID=''' + Trim(Order_Main.fieldbyname('MYID').AsString) + '''');
          sql.Add(' UPdate CK_MYSC_CR_Log Set DelTime=getdate(),DelerCode=''' + Trim(DCode) + ''',Deler=''' + Trim(DName) + '''');
          sql.Add(' where MYID=''' + Trim(Order_Main.fieldbyname('MYID').AsString) + '''');
          sql.Add(' Delete CK_MYSC_CR  where MYId=''' + Trim(Order_Main.fieldbyname('MYId').AsString) + '''');
          sql.Add(' delete from TP_File where WBID=''' + trim(Order_Main.fieldbyname('MYId').AsString) + ''' ');
          sql.Add(' and TFType=''加工码单''');
          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;

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

procedure TfrmLLCKList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  InitGridByCustomer();
  InitMXGrid();
  TBFind.Click;
end;

procedure TfrmLLCKList.TBAddClick(Sender: TObject);
begin
  try
    frmLLCKInPut := TfrmLLCKInPut.Create(Application);
    with frmLLCKInPut do
    begin
      PState := 0;
      FMainId := '';
      if ShowModal = 1 then
      begin
        TBRafresh.Click
      end;
    end;
  finally
    frmLLCKInPut.Free;
  end;
end;

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

procedure TfrmLLCKList.CheckBox1Click(Sender: TObject);
begin
  TBRafresh.Click
end;

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

procedure TfrmLLCKList.ToolButton1Click(Sender: TObject);
var
  FFMYType: string;
begin
  {FFMYType:=Trim(Order_Main.fieldbyname('MYType').AsString);
  try
    frmLLRKInPutMH_RCCG:=TfrmLLRKInPutMH_RCCG.Create(Application);
    with frmLLRKInPutMH_RCCG do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MYId').AsString);
      FMYType:=Trim(Self.Order_Main.fieldbyname('MYType').AsString);
      FMYTypeFlag:=Trim(Self.Order_Main.fieldbyname('MYTypeFlag').AsString);
      labMYType.Caption:=Trim(Self.Order_Main.fieldbyname('MYTypeFlag').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmLLRKInPutMH_RCCG.Free;
  end; }
end;

procedure TfrmLLCKList.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);

  if ADOQueryMain.Active = False then
    Exit
  else
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  end;

  if ADOQuery2.Active = False then
    Exit
  else
  begin
    SDofilter(ADOQuery2, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQuery2, CDS_2);
    SInitCDSData20(ADOQuery2, CDS_2);
  end;

  if ADOQuery3.Active = False then
    Exit
  else
  begin
    SDofilter(ADOQuery3, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQuery3, CDS_3);
    SInitCDSData20(ADOQuery3, CDS_3);
  end;
end;

procedure TfrmLLCKList.N2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Trim(canshu1) <> '高权限' then
  begin
    if Order_Main.FieldByName('filltime').AsDateTime + 1 < Now then
    begin
      application.MessageBox('超过一天不能删除', '提示');
      Exit;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where YFTypeId=''' + Trim(Self.Order_Main.fieldbyname('MYId').AsString) + '''');
    sql.Add(' and ChkStatusP=''已审核''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = false then
  begin
    Application.MessageBox('应付款已审核不能操作', '提示');
    exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where YFTypeId=''' + trim(Order_Main.fieldbyname('MYID').AsString) + '''');
    sql.Add(' and (isnull(ChkerP,'''')<>'''' ');
    sql.Add(' or isnull(ChkerQ,'''')<>'''') ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = false then
  begin
    Application.MessageBox('应付款已审核,不能删除', '提示');
    exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin

  end;
end;

procedure TfrmLLCKList.N1Click(Sender: TObject);
var
  FFMYType: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if Trim(canshu1) <> '高权限' then
  begin
    if Order_Main.FieldByName('filltime').AsDateTime + 1 < Now then
    begin
      application.MessageBox('超过一天不能修改', '提示');
      Exit;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where YFTypeId=''' + Trim(Self.Order_Main.fieldbyname('MYId').AsString) + '''');
    sql.Add(' and ChkStatusP=''已审核''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = false then
  begin
    Application.MessageBox('应付款已审核不能操作', '提示');
    exit;
  end;
 { FFMYType:=Trim(Order_Main.fieldbyname('MYType').AsString); //加限制财务ChkerP=''已审核''
  try
    frmLLRKInPutMH_RCCG:=TfrmLLRKInPutMH_RCCG.Create(Application);
    with frmLLRKInPutMH_RCCG do
    begin
      PState:=1;
      FMainId:=Trim(Self.Order_Main.fieldbyname('MYId').AsString);
      FMYType:=Trim(Self.Order_Main.fieldbyname('MYType').AsString);
      FMYTypeFlag:=Trim(Self.Order_Main.fieldbyname('MYTypeFlag').AsString);
      labMYType.Caption:=Trim(Self.Order_Main.fieldbyname('MYTypeFlag').AsString)+'加工码单';
      if ShowModal=1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmLLRKInPutMH_RCCG.Free;
  end; }
end;

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

procedure TfrmLLCKList.Tv1DblClick(Sender: TObject);
begin
  ToolButton1.Click;
end;

procedure TfrmLLCKList.v1Column1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  Id, Id10: Integer;
begin
  Id := TV1.GetColumnByFieldName('PS').Index;
  Id10 := TV1.GetColumnByFieldName('MXHZPS').Index;
  if (AViewInfo.GridRecord.Values[Id]) <> (AViewInfo.GridRecord.Values[Id10]) then
  begin
    ACanvas.Brush.Color := clRed;
  end;
end;

procedure TfrmLLCKList.v1Column17CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  Id, Id10: Integer;
begin
  Id := TV1.GetColumnByFieldName('KgQty').Index;
  Id10 := TV1.GetColumnByFieldName('MXHZKgQty').Index;
  if (AViewInfo.GridRecord.Values[Id]) <> (AViewInfo.GridRecord.Values[Id10]) then
  begin
    ACanvas.Brush.Color := clRed;
  end;
end;

procedure TfrmLLCKList.v1Column3CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  Id, Id10: Integer;
begin
  Id := TV1.GetColumnByFieldName('Qty').Index;
  Id10 := TV1.GetColumnByFieldName('MXHZQty').Index;
  if (AViewInfo.GridRecord.Values[Id]) <> (AViewInfo.GridRecord.Values[Id10]) then
  begin
    ACanvas.Brush.Color := clRed;
  end;
end;

procedure TfrmLLCKList.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  InitSubGrid();
end;

end.

