unit U_MLMangeRS_SMCX;

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, cxTextEdit,
  cxButtonEdit, Menus, cxLookAndFeelPainters, cxButtons, cxImage;

type
  TfrmMLMangeRS_SMCX = class(TForm)
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel1: TPanel;
    DataSource2: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    cxGridPopupMenu4: TcxGridPopupMenu;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGridPopupMenu5: TcxGridPopupMenu;
    Panel5: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1MLNo: TcxGridDBColumn;
    v1MLName: TcxGridDBColumn;
    v1MLMF: TcxGridDBColumn;
    v1MLKZ: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1GYLXName: TcxGridDBColumn;
    v1SKID: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    SMRK: TEdit;
    v1ColNameKH: TcxGridDBColumn;
    v1ColNameEng: TcxGridDBColumn;
    v1PTID: TcxGridDBColumn;
    v1ColNo: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    V2MYName: TcxGridDBColumn;
    V2MYCode: TcxGridDBColumn;
    V2GYLXName: TcxGridDBColumn;
    V2MLCF: TcxGridDBColumn;
    V2MYMF: TcxGridDBColumn;
    V2MYColor: TcxGridDBColumn;
    V2JH: TcxGridDBColumn;
    V2MQty: TcxGridDBColumn;
    V2GYType: TcxGridDBColumn;
    V2MYKZ: TcxGridDBColumn;
    V2MYColorNo: TcxGridDBColumn;
    V2CoDYGangNo: TcxGridDBColumn;
    V2KgQty: TcxGridDBColumn;
    Button3: TButton;
    Panel3: TPanel;
    Panel2: TPanel;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    ComboBox2: TComboBox;
    ComboBox1: TComboBox;
    BtnPrt: TButton;
    BtnQX: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure SMRKKeyPress(Sender: TObject; var Key: Char);
    procedure Button1Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Button3Click(Sender: TObject);
    procedure BtnQXClick(Sender: TObject);
    procedure BtnPrtClick(Sender: TObject);
  private
    { Private declarations }
    PState:Integer;
    FCPID,FTopID:String;
    procedure InitTree();
    procedure InitGrid();
    procedure ReadINIFile();
    procedure ButtonColorCSH();
    procedure InitSHDY();
    procedure InitRSML();
    procedure GxgridXS();
  public
    canshu1:string;
    { Public declarations }
  end;

var
  frmMLMangeRS_SMCX: TfrmMLMangeRS_SMCX;

implementation
uses
  U_DataLink,U_Fun,U_CPAdd,U_FileUp,U_MLManage_LR,U_BPZdy_LR,U_BPZdy_SH,U_MLManage_LRRS,
  U_MLManage_FHLR,U_MLManage_ZHLR,U_BPZdy_HXK,U_MLMange_CX,U_BPZdy_LRPB,U_BPZdy_LRGX,
  U_CPManage_TP,U_BPZdy_LRSHK, U_BPZdy_PanelCX,U_MLManage_LRCX,U_RSColorBig;

{$R *.dfm}

procedure TfrmMLMangeRS_SMCX.InitTree();
begin
  
end;

procedure TfrmMLMangeRS_SMCX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * ');
      sql.Add(',SKID=(select B.SKID from BP_ZDY B where B.BPID=A.MBPID)');
      sql.Add(' from ML_Manage A ');
      sql.Add(' where isnull(MLType,'''')=''染色面料'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLMangeRS_SMCX.FormDestroy(Sender: TObject);
begin
  frmMLMangeRS_SMCX:=nil;
end;

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

procedure TfrmMLMangeRS_SMCX.FormShow(Sender: TObject);
begin
  InitGrid();
  ReadCxGrid('扫描查询',Tv1,'样品管理');
end;

procedure TfrmMLMangeRS_SMCX.cxDBTreeList1DblClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmMLMangeRS_SMCX.ReadINIFile();
var
  programIni:Tinifile;  //配置文件名
  FileName:string;
begin
  FileName:=ExtractFilePath(Paramstr(0))+'SYSTEMSET.INI';
  programIni:=Tinifile.create(FileName);
  server:=programIni.ReadString('SERVER','服务器地址','127.0.0.1');
  programIni.Free;
end;

procedure TfrmMLMangeRS_SMCX.ButtonColorCSH();
begin
  
end;

procedure TfrmMLMangeRS_SMCX.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

procedure TfrmMLMangeRS_SMCX.Button2Click(Sender: TObject);
begin
  WriteCxGrid('扫描查询',Tv1,'样品管理');
  Close;
end;

procedure TfrmMLMangeRS_SMCX.InitRSML();
var fsj:string;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_PRT_QCRK_RSML ');
      sql.Add('@MXID='''+trim(SMRK.Text)+'''');
      //ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from RT_PTColor where PTID='''+Trim(CDS_Main.fieldbyname('PTID').AsString)+'''');
      Open;
    end;
    fsj:=Trim(ADOQueryCmd.fieldbyname('ColDaiMa').AsString);
    Panel3.Color:=StrToInt('$'+Trim(fsj));
    Label1.Caption:=CDS_Main.fieldbyname('MYColorNo').AsString+'#';
    Label2.Caption:=CDS_Main.fieldbyname('MYColor').AsString;
    cxgrid2.Visible:=true;
    Button3.Visible:=true;
    Panel3.Visible:=true;
    SMRK.Text:='';
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLMangeRS_SMCX.GxgridXS();
begin
  Button1.Visible:=false;
  Button3.Visible:=false;
  cxGrid1.Visible:=false;
  cxGrid2.Visible:=false;
  Panel3.Visible:=false;
end;

procedure TfrmMLMangeRS_SMCX.InitSHDY();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_View_RSML ');
      sql.Add('@DYID='''+trim(SMRK.Text)+'''');
      //ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
    cxgrid1.Visible:=true;
    button1.Visible:=true;
    SMRK.Text:='';
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLMangeRS_SMCX.SMRKKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    GxgridXS();
    if Copy(SMRK.Text,1,2)='DY' then
    InitSHDY();
    if Copy(SMRK.Text,1,2)='QM' then
    InitRSML();
  end;
end;

procedure TfrmMLMangeRS_SMCX.Button1Click(Sender: TObject);
var i,j,x:Integer;
begin
  i:=0;
  j:=0;
  frmBPZDY_PanelCX:=TfrmBPZDY_PanelCX.create(self);
  with frmBPZDY_PanelCX do
  begin
    FColorFlag:=Trim(self.CDS_Main.fieldbyname('SKID').asstring);
    FBPID:=Trim(self.CDS_Main.fieldbyname('MBPID').asstring);
    FMLID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLMangeRS_SMCX.Tv1CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  frmMLManage_LRCX:=TfrmMLManage_LRCX.Create(Self);
  with frmMLManage_LRCX do
  begin
    FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
    FGYName:='染色';
    FDYID:=Trim(Self.CDS_Main.fieldbyname('DYID').AsString);
    if ShowModal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmMLMangeRS_SMCX.Button3Click(Sender: TObject);
begin
  Panel2.Visible:=true;
end;

procedure TfrmMLMangeRS_SMCX.BtnQXClick(Sender: TObject);
begin
  Panel2.Visible:=False;
end;

procedure TfrmMLMangeRS_SMCX.BtnPrtClick(Sender: TObject);
var
   fPrintFile,Txt,fImagePath:string;
   i,j:Integer;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  if ComboBox2.Text='' then
  begin
    Application.MessageBox('请选择张数!','提示',0);
    Exit;
  end;
  if ComboBox1.Text='' then
  begin
    Application.MessageBox('请选择尺寸!','提示',0);
    Exit;
  end;
  if ComboBox1.Text='9*7' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\期初入库染色面料标签97.rmf';
  end else
  if ComboBox1.Text='8*5' then
  begin
    fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\期初入库染色面料标签85.rmf';
  end;
  if FileExists(fPrintFile)=False then
  begin
    if ComboBox1.Text='9*7' then
      Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\期初入库染色面料标签97.rmf'),'提示',0);
    if ComboBox1.Text='8*5' then
      Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\期初入库染色面料标签85.rmf'),'提示',0);
    exit;
  end;
  try
    Moudle:=LoadLibrary('MakeQRBarcode.dll');
    @Makebar:=GetProcAddress(Moudle,'Make');
    @Mixtext:=GetProcAddress(Moudle,'MixText');
    Txt:=Trim(CDS_Main.fieldbyname('MXID').AsString);
    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
    application.MessageBox('二维码生成失败！','提示信息',MB_ICONERROR);
    exit;
  end;
  RMVariables['QRBARCODE']:=fImagePath;
  RM1.LoadFromFile(fPrintFile);
  //RM1.ShowReport;
  for i:=1 to StrToInt(ComboBox2.Text) do
  begin
    RM1.PrintReport;
  end;
  ComboBox2.ItemIndex:=0;
  ComboBox1.ItemIndex:=-1;
  Panel2.Visible:=False;
end;

end.
