unit U_jitaibiao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxPC, cxCheckComboBox, cxDropDownEdit, Menus, RM_e_Xls, TeEngine,
  Series, TeeProcs, Chart, DbChart;

type
  TfrmMachineManage = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    RMXLSExport2: TRMXLSExport;
    Label1: TLabel;
    ToolButton3: TToolButton;
    ADOQueryPrt: TADOQuery;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    Label2: TLabel;
    cxGrid3: TcxGrid;
    cxgrdbtblvwTv3: TcxGridDBTableView;
    v3Column37: TcxGridDBColumn;
    v3Column38: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    v3Column3: TcxGridDBColumn;
    v3Column4: TcxGridDBColumn;
    v3Column5: TcxGridDBColumn;
    v3Column6: TcxGridDBColumn;
    v3Column7: TcxGridDBColumn;
    v3Column8: TcxGridDBColumn;
    v3Column9: TcxGridDBColumn;
    v3Column10: TcxGridDBColumn;
    v3Column11: TcxGridDBColumn;
    v3Column12: TcxGridDBColumn;
    v3Column13: TcxGridDBColumn;
    v3Column14: TcxGridDBColumn;
    v3Column15: TcxGridDBColumn;
    v3Column16: TcxGridDBColumn;
    v3Column17: TcxGridDBColumn;
    v3Column18: TcxGridDBColumn;
    v3Column19: TcxGridDBColumn;
    v3Column20: TcxGridDBColumn;
    v3Column21: TcxGridDBColumn;
    v3Column22: TcxGridDBColumn;
    v3Column23: TcxGridDBColumn;
    v3Column24: TcxGridDBColumn;
    v3Column25: TcxGridDBColumn;
    v3Column26: TcxGridDBColumn;
    v3Column27: TcxGridDBColumn;
    v3Column28: TcxGridDBColumn;
    v3Column29: TcxGridDBColumn;
    v3Column30: TcxGridDBColumn;
    v3Column31: TcxGridDBColumn;
    v3Column32: TcxGridDBColumn;
    v3Column33: TcxGridDBColumn;
    v3Column34: TcxGridDBColumn;
    v3Column35: TcxGridDBColumn;
    v3Column36: TcxGridDBColumn;
    v3Column39: TcxGridDBColumn;
    v3Column40: TcxGridDBColumn;
    v3Column41: TcxGridDBColumn;
    v3Column42: TcxGridDBColumn;
    v3Column43: TcxGridDBColumn;
    v3Column44: TcxGridDBColumn;
    v3Column45: TcxGridDBColumn;
    v3Column46: TcxGridDBColumn;
    v3Column47: TcxGridDBColumn;
    v3Column48: TcxGridDBColumn;
    v3Column49: TcxGridDBColumn;
    v3Column50: TcxGridDBColumn;
    v3Column51: TcxGridDBColumn;
    v3Column52: TcxGridDBColumn;
    v3Column53: TcxGridDBColumn;
    v3Column54: TcxGridDBColumn;
    v3Column55: TcxGridDBColumn;
    v3Column56: TcxGridDBColumn;
    v3Column57: TcxGridDBColumn;
    v3Column58: TcxGridDBColumn;
    v3Column59: TcxGridDBColumn;
    v3Column60: TcxGridDBColumn;
    v3Column61: TcxGridDBColumn;
    v3Column62: TcxGridDBColumn;
    v3Column63: TcxGridDBColumn;
    v3Column64: TcxGridDBColumn;
    v3Column65: TcxGridDBColumn;
    v3Column66: TcxGridDBColumn;
    v3Column67: TcxGridDBColumn;
    v3Column68: TcxGridDBColumn;
    v3Column69: TcxGridDBColumn;
    v3Column70: TcxGridDBColumn;
    v3Column71: TcxGridDBColumn;
    v3Column72: TcxGridDBColumn;
    v3Column73: TcxGridDBColumn;
    v3Column74: TcxGridDBColumn;
    v3Column75: TcxGridDBColumn;
    v3Column76: TcxGridDBColumn;
    v3Column77: TcxGridDBColumn;
    v3Column78: TcxGridDBColumn;
    v3Column79: TcxGridDBColumn;
    v3Column80: TcxGridDBColumn;
    v3Column81: TcxGridDBColumn;
    v3Column82: TcxGridDBColumn;
    v3Column83: TcxGridDBColumn;
    v3Column84: TcxGridDBColumn;
    v3Column85: TcxGridDBColumn;
    v3Column86: TcxGridDBColumn;
    v3Column87: TcxGridDBColumn;
    v3Column88: TcxGridDBColumn;
    v3Column89: TcxGridDBColumn;
    v3Column90: TcxGridDBColumn;
    v3Column91: TcxGridDBColumn;
    v3Column92: TcxGridDBColumn;
    v3Column93: TcxGridDBColumn;
    v3Column94: TcxGridDBColumn;
    v3Column95: TcxGridDBColumn;
    v3Column96: TcxGridDBColumn;
    v3Column97: TcxGridDBColumn;
    v3Column98: TcxGridDBColumn;
    v3Column99: TcxGridDBColumn;
    v3Column100: TcxGridDBColumn;
    v3Column101: TcxGridDBColumn;
    v3Column102: TcxGridDBColumn;
    v3Column103: TcxGridDBColumn;
    v3Column104: TcxGridDBColumn;
    v3Column105: TcxGridDBColumn;
    v3Column106: TcxGridDBColumn;
    v3Column107: TcxGridDBColumn;
    v3Column108: TcxGridDBColumn;
    v3Column109: TcxGridDBColumn;
    v3Column110: TcxGridDBColumn;
    v3Column111: TcxGridDBColumn;
    v3Column112: TcxGridDBColumn;
    v3Column113: TcxGridDBColumn;
    v3Column114: TcxGridDBColumn;
    v3Column115: TcxGridDBColumn;
    v3Column116: TcxGridDBColumn;
    v3Column117: TcxGridDBColumn;
    v3Column118: TcxGridDBColumn;
    v3Column119: TcxGridDBColumn;
    v3Column120: TcxGridDBColumn;
    v3Column121: TcxGridDBColumn;
    v3Column122: TcxGridDBColumn;
    v3Column123: TcxGridDBColumn;
    v3Column124: TcxGridDBColumn;
    v3Column125: TcxGridDBColumn;
    v3Column126: TcxGridDBColumn;
    v3Column127: TcxGridDBColumn;
    v3Column128: TcxGridDBColumn;
    v3Column129: TcxGridDBColumn;
    v3Column130: TcxGridDBColumn;
    v3Column131: TcxGridDBColumn;
    v3Column132: TcxGridDBColumn;
    v3Column133: TcxGridDBColumn;
    v3Column134: TcxGridDBColumn;
    v3Column135: TcxGridDBColumn;
    v3Column136: TcxGridDBColumn;
    v3Column137: TcxGridDBColumn;
    v3Column138: TcxGridDBColumn;
    v3Column139: TcxGridDBColumn;
    v3Column140: TcxGridDBColumn;
    v3Column141: TcxGridDBColumn;
    v3Column142: TcxGridDBColumn;
    v3Column143: TcxGridDBColumn;
    v3Column144: TcxGridDBColumn;
    v3Column145: TcxGridDBColumn;
    v3Column146: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxgrdbtblvwTv3Column1: TcxGridDBColumn;
    pzname: TEdit;
    pbname: TEdit;
    cxgrdbtblvwTv3Column2: TcxGridDBColumn;
    cxgrdbtblvwTv3Column3: TcxGridDBColumn;
    btn1: TToolButton;
    lbl1: TLabel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure CustomerChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure v2Column8PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure pbnameChange(Sender: TObject);
    procedure pznameChange(Sender: TObject);
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
    procedure PrintReport(FZDYNo: string);
    procedure InitGrid();
  public
    fFlag: integer;
    { Public declarations }
    RKFlag, FCYID, fmanage, k: string;
  end;

var
  frmMachineManage: TfrmMachineManage;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}

procedure TfrmMachineManage.PrintReport(FZDYNo: string);
var
  fPrintFile, FFCYID: string;
  i, j: Integer;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  if CDS_HZ.IsEmpty then
    Exit;

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\机台标签.rmf';
  with ADOQueryPrt do
  begin
    close;
    sql.Clear;
    sql.Add(' select * from  Machine where MCNO=''' + Trim(FZDYNo) + '''');
    open;
  end;
  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(FZDYNo);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
  except
    CDS_HZ.EnableControls;
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    exit;
  end;
  RMVariables['QRBARCODE'] := fImagePath;
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.PrintReport;
  //  RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + fPrintFile + '!'), '提示', 0);
    Exit;
  end;
end;

procedure TfrmMachineManage.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.* from  cloth_paizhen2 A  ');
      if Trim(k) <> '三角' then
      begin
        sql.Add('where pztype=''排针'' ');
      end
      else
      begin
        sql.Add('where pztype=''三角'' ');
      end;
//      showmessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
end;

procedure TfrmMachineManage.FormDestroy(Sender: TObject);
begin
  frmMachineManage := nil;
end;

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

procedure TfrmMachineManage.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Trim(Self.Caption), cxgrdbtblvwTv3, '排针管理2');
  Close;
end;

procedure TfrmMachineManage.FormShow(Sender: TObject);
begin
  ReadCxGrid(Trim(Self.Caption), cxgrdbtblvwTv3, '排针管理2');
//  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
//  begdate.DateTime:=Enddate.DateTime-30;
  InitGrid();
end;

procedure TfrmMachineManage.TBRafreshClick(Sender: TObject);
begin
//  MCCJ.SetFocus;

  InitGrid();
end;

procedure TfrmMachineManage.ToolButton2Click(Sender: TObject);
var
  sql: string;
begin
  if ADOQueryMain.Active then
  begin
    sql := SGetFilters(Panel1, 1, 2);
    SDofilter(ADOQueryMain, sql);
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  end;
end;

procedure TfrmMachineManage.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(cxgrdbtblvwTv3, ADOQueryMain, trim(Self.Caption));
end;

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

procedure TfrmMachineManage.N1Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  with CDS_HZ do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value := true;
      post;
      next;
    end;
    First;
    EnableControls;
  end;
end;

procedure TfrmMachineManage.N2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  with CDS_HZ do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value := false;
      post;
      next;
    end;
    First;
    EnableControls;
  end;
end;

procedure TfrmMachineManage.CustomerChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmMachineManage.FormCreate(Sender: TObject);
begin
  fmanage := Trim(DParameters1);
end;

procedure TfrmMachineManage.v2Column8PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
//  mvalue := TcxTextEdit(Sender).EditingText;
//  FFieldName := Trim(cxgrdbtblvwTv3.Controller.FocusedColumn.DataBinding.FilterFieldName);
//  try
//    ADOQueryCmd.Connection.BeginTrans;
//    with CDS_HZ do
//    begin
//      Edit;
//      FieldByName(FFieldName).Value := Trim(mvalue);
//      Post;
//    end;
////    with ADOQueryCmd do
////    begin
////      Close;
////      sql.Clear;
////      sql.Add('UPdate Machine ');
////      sql.Add(' Set ' + FFieldName + '=''' + Trim(mvalue) + '''');
////      sql.Add(' where MCID=' + CDS_HZ.fieldbyname('MCID').AsString);
////      ExecSQL;
////    end;
//    ADOQueryCmd.Connection.CommitTrans;
//    tv2.Controller.EditingController.ShowEdit();
//  except
//    tv2.Controller.EditingController.ShowEdit();
//    ADOQueryCmd.Connection.RollbackTrans;
//    Application.MessageBox('保存失败！', '提示', 0);
//  end
end;

procedure TfrmMachineManage.ToolButton3Click(Sender: TObject);
begin
  PrintReport(Trim(CDS_HZ.fieldbyname('MCNO').AsString));
end;

procedure TfrmMachineManage.ToolButton4Click(Sender: TObject);
begin
//  MCCJ.SetFocus;
//  with ADOQueryCmd do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add('insert into Machine(Filler) values(' + quotedstr(Trim(dname)) + ')');
//    ExecSQL;
//  end;
  InitGrid();
end;

procedure TfrmMachineManage.ToolButton5Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;
//  MCCJ.SetFocus;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete Cloth_PaiZhen2 where PZID=' + QuotedStr((CDS_HZ.FieldByName('PZID').AsString)));
    ExecSQL;
  end;
  CDS_HZ.Delete;
end;

procedure TfrmMachineManage.pbnameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmMachineManage.pznameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmMachineManage.btn1Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;
  if CDS_HZ.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  ModalResult := 1;
end;

end.

