unit U_CKCHHZList;

interface

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

type
  TfrmCKCHHZList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ADOQueryPrint: TADOQuery;
    Panel1: TPanel;
    Label2: TLabel;
    Label3: TLabel;
    Label7: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    SPName: TEdit;
    ConNo: TEdit;
    RCGangNo: TEdit;
    N3: TMenuItem;
    N4: TMenuItem;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    cxGridLevel2: TcxGridLevel;
    V1Column1: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1Column4: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1Column6: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column9: TcxGridDBBandedColumn;
    V1Column10: TcxGridDBBandedColumn;
    V1Column12: TcxGridDBBandedColumn;
    V1Column13: TcxGridDBBandedColumn;
    V1Column14: TcxGridDBBandedColumn;
    V1Column15: TcxGridDBBandedColumn;
    V1Column16: TcxGridDBBandedColumn;
    V1Column17: TcxGridDBBandedColumn;
    V1Column18: TcxGridDBBandedColumn;
    Label5: TLabel;
    Label11: TLabel;
    ToolButton1: TToolButton;
    V1Column11: TcxGridDBBandedColumn;
    Label1: TLabel;
    CKOrdNo: TEdit;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SPIDKeyPress(Sender: TObject; var Key: Char);
    procedure SPSpecChange(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure Tv1DblClick(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure V1Column7CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure V1Column13CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
  private
    BtnArg: string;
    procedure SetStatus();
    procedure InitGrid();
    { Private declarations }
  public
    canshu1: string;
    { Public declarations }
  end;

//var
//  frmLCKJYList: TfrmLCKJYList;

implementation

uses
  U_DataLink, U_RTFun, U_Fun, U_ZDYHelp, U_SysLogHelp, U_LCKJYList;

{$R *.dfm}

procedure TfrmCKCHHZList.SetStatus();
begin

end;

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

procedure TfrmCKCHHZList.FormCreate(Sender: TObject);
begin
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 180;

end;

procedure TfrmCKCHHZList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add(' EXEC P_DB_KKJD ' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.DateTime))));
      sql.Add(' ,' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1))));
      if CheckBox1.Checked then
        sql.Add(' ,''未出库'' ');
      if CheckBox2.Checked then
        sql.Add(' ,''已出库'' ');
      if (CheckBox2.Checked = False) and (CheckBox1.Checked = False) then
        sql.Add(' ,''全部'' ');
//      ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmCKCHHZList.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;

  InitGrid();

end;

procedure TfrmCKCHHZList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmCKCHHZList.TBCloseClick(Sender: TObject);
begin
  WriteCxBandedGrid(trim(self.Caption) + 'Tv1', Tv1, '进度管理');
  Close;
end;

procedure TfrmCKCHHZList.FormShow(Sender: TObject);
begin
  ReadCxBandedGrid(trim(self.Caption) + 'Tv1', Tv1, '进度管理');
  SetStatus();

  InitGrid();

end;

procedure TfrmCKCHHZList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  TcxGridToExcel(self.Caption, cxGrid1);
end;

procedure TfrmCKCHHZList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  end;
end;

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

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

procedure TfrmCKCHHZList.SPIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    {if Length(Trim(SPID.Text))<4 then Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        sql.Clear;
        sql.Add(' select A.* ');
        sql.Add(',ConNo=(select ConNo from Contract_Main CM where CM.MainId=A.CGMainId)');
        //sql.Add(' ,ConNo=(select ConNo from Contract_Main CM where CM.MainId=A.CGMainId )');
        sql.Add(' from CK_SXPB_CR A');
        sql.add(' where SPID like :SXID');
        Parameters.ParamByName('SXID').Value:='%'+Trim(SXID.Text)+'%';
        Open;
        //ShowMessage(SQL.Text);
      end;
      SCreateCDS20(ADOQueryMain,CDS_Main);
      SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end; }
  end;
end;

procedure TfrmCKCHHZList.SPSpecChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKCHHZList.FactoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmCKCHHZList.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  Fsunhao: double;
begin

  if AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('ISSHCL').Index] = null then
    Exit;
  if AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('sunhao').Index] = null then
    Exit;
  Fsunhao := AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('sunhao').Index];
  if AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('ZPPS').Index] = null then
    Exit;
  if (AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('ZPPS').Index]) > 0 then
  begin
      //损耗±2% 绿色、 损耗±2% ~ ±5% 黄色、 损耗大于±5% 红色
    if Fsunhao < 0 then
      Fsunhao := -Fsunhao;
    if Fsunhao <= 2 then
      ACanvas.Brush.Color := $00FF00;
    if (Fsunhao > 2) and (Fsunhao <= 5) then
      ACanvas.Brush.Color := $00FFFF;
    if Fsunhao > 5 then
      ACanvas.Brush.Color := $4763FF;
  end;

  if AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('ISSHCL').Index] = True then
  begin
    ACanvas.Brush.Color := $F0CAA6;
  end;
end;

procedure TfrmCKCHHZList.Tv1DblClick(Sender: TObject);
begin
  try
    frmLCKJYList := TfrmLCKJYList.Create(Application);
    with frmLCKJYList do
    begin
      APID.text := trim(Self.CDS_Main.FieldByName('spID').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmLCKJYList.Free;
  end;
end;

procedure TfrmCKCHHZList.N4Click(Sender: TObject);
begin
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add(' update  CK_SXPB_CR SET  ISQTCK=(case when ISQTCK=''已取消'' then null else ''已取消'' end) ');
      sql.Add(' where SPID=' + quotedstr(trim(CDS_Main.FieldByName('SPID').AsString)));
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('开卡分析确认取消')));
      sql.Add(',' + quotedstr(trim('缸号：' + trim(CDS_Main.FieldByName('RCGangNo').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('确认取消！', '提示信息');
    CDS_Main.Delete;
  except
    application.MessageBox('确认取消！', '提示信息', 0);
  end;
end;

procedure TfrmCKCHHZList.ToolButton1Click(Sender: TObject);
var
  fPrintFile, fPrintFile10, FMainID, FKHName, FFPNo: string;
  i: Integer;
begin
  ExportFtErpFile('仓库打包打卷单.rmf', ADOQueryTemp);

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\仓库打包打卷单.rmf';
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找到' + fPrintFile), '提示', 0);
  end;
end;

procedure TfrmCKCHHZList.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked then
    CheckBox2.Checked := False;
  InitGrid();

end;

procedure TfrmCKCHHZList.CheckBox2Click(Sender: TObject);
begin
  if CheckBox2.Checked then
    CheckBox1.Checked := False;
  InitGrid();
end;

procedure TfrmCKCHHZList.V1Column7CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  ACanvas.Font.Color := $FF0000;
end;

procedure TfrmCKCHHZList.V1Column13CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  ACanvas.Font.Color := $0000FF;
end;

end.

