unit U_GetDllForm;

interface

uses
  Windows, Messages, forms, OleCtnrs, DateUtils, SysUtils, ADODB, dxCore,
  ActiveX;

function GetDllForm(App: Tapplication; FormH: hwnd; FormID: integer; Language: integer; WinStyle: integer; GCode: Pchar; GName: Pchar; DataBase: Pchar; Title: PChar; Parameters1: PChar; Parameters2: PChar; Parameters3: PChar; Parameters4: PChar; Parameters5: PChar; Parameters6: PChar; Parameters7: PChar; Parameters8: PChar; Parameters9: PChar; Parameters10: PChar; DataBaseStr: PChar): hwnd; export; stdcall;

function ConnData(): Boolean;

implementation

uses
  U_DataLink, U_MachineManage, U_PurviewDC, U_KuWeiManage, U_WarpBeamManage,
  U_TrayManage, U_MachineBaoYang, U_JTBY, U_JTBY_LS, U_WXJL, U_JXQK, U_JXXL,
  U_JTQK, U_JXSC, U_JTQty, U_GZQty, U_YYBB;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取Dll中得窗体                              //
     //        参数说明：App>>调用应用程序；                        //
    //                 FormH>>调用窗口句柄 ；                      //
   //                 FormID>>窗口号;                             //
  //                 Language>>语言种类;                         //
 //                 WinStyle>>窗口类型；                        //
/////////////////////////////////////////////////////////////////
function GetDllForm(App: Tapplication; FormH: hwnd; FormID: integer; Language: integer; WinStyle: integer; GCode: Pchar; GName: Pchar; DataBase: Pchar; Title: PChar; Parameters1: PChar; Parameters2: PChar; Parameters3: PChar; Parameters4: PChar; Parameters5: PChar; Parameters6: PChar; Parameters7: PChar; Parameters8: PChar; Parameters9: PChar; Parameters10: PChar; DataBaseStr: PChar): hwnd;
var
  mnewHandle: hwnd;
  mstyle: TFormStyle;     // 0:子窗口; 1：普通窗口
  mstate: TWindowState;
  mborderstyle: TFormBorderStyle;
begin
  mnewHandle := 0;
  DName := PChar(GName);
  DCode := PChar(GCode);
  DdataBase := DataBase;
  DTitCaption := Title;
  DParameters1 := Parameters1;
  DParameters2 := Parameters2;
  DParameters3 := Parameters3;
  DParameters4 := Parameters4;
  DParameters5 := Parameters5;
  DParameters6 := Parameters6;
  DParameters7 := Parameters7;
  DParameters8 := Parameters8;
  DParameters9 := Parameters9;
  DParameters10 := Parameters10;

  MainApplication := App;
  DCurHandle := FormH;
  IsDelphiLanguage := Language;

  Application := TApplication(App);
  DCurHandle := 0;


   //赋值链接字符串
  SetLength(server, 255);
  SetLength(dtbase, 255);
  SetLength(user, 255);
  SetLength(pswd, 255);

  server := '116.62.5.81,7781';
  pswd := 'rightsoft@81';
  dtbase := 'pangtaodata';
  user := 'longfengsa';
  DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
  DConString := DataBaseStr;

   //DParameters1:='高权限';   //高权限
   //DParameters3:='1';
  if not ConnData() then
  begin
    result := 0;
    exit;
  end;

   // 定义窗口类型 、状态
  if WinStyle = 0 then
  begin
    mstyle := fsMDIChild;
    mstate := wsMaximized;
    mborderstyle := bsSizeable;
  end
  else
  begin
    mstyle := fsNormal;
    mstate := wsNormal;
    mborderstyle := bsSizeable;
  end;
  /////////////////////
  //调用子模块窗口
  case FormID of

    111:  //机台管理
      begin
        if frmMachineManage = nil then
        begin
          frmMachineManage := TfrmMachineManage.Create(application.MainForm);
          with frmMachineManage do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMachineManage.BringToFront;
       //句柄
        mnewHandle := frmMachineManage.Handle;
      end;

    121:  //库位管理
      begin
        if frmKuWeiManage = nil then
        begin
          frmKuWeiManage := TfrmKuWeiManage.Create(application.MainForm);
          with frmKuWeiManage do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmKuWeiManage.BringToFront;
       //句柄
        mnewHandle := frmKuWeiManage.Handle;
      end;
    131:  //挡车工账号管理
      begin
        if frmPurviewDC = nil then
        begin
          frmPurviewDC := TfrmPurviewDC.Create(application.MainForm);
          with frmPurviewDC do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPurviewDC.BringToFront;
       //句柄
        mnewHandle := frmPurviewDC.Handle;
      end;

    141:  //经轴管理
      begin
        if frmWarpBeamManage = nil then
        begin
          frmWarpBeamManage := TfrmWarpBeamManage.Create(application.MainForm);
          with frmWarpBeamManage do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmWarpBeamManage.BringToFront;
       //句柄
        mnewHandle := frmWarpBeamManage.Handle;
      end;

    151:  //托盘管理
      begin
        if frmTrayManage = nil then
        begin
          frmTrayManage := TfrmTrayManage.Create(application.MainForm);
          with frmTrayManage do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmTrayManage.BringToFront;
       //句柄
        mnewHandle := frmTrayManage.Handle;
      end;
    221:  //机台保养
      begin
        if frmMachineBaoYang = nil then
        begin
          frmMachineBaoYang := TfrmMachineBaoYang.Create(application.MainForm);
          with frmMachineBaoYang do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMachineBaoYang.BringToFront;
       //句柄
        mnewHandle := frmMachineBaoYang.Handle;
      end;
    231:  //保养提醒
      begin
        if frmJTBY = nil then
        begin
          frmJTBY := TfrmJTBY.Create(application.MainForm);
          with frmJTBY do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJTBY.BringToFront;
       //句柄
        mnewHandle := frmJTBY.Handle;
      end;
    232:  //保养历史
      begin
        if frmJTBY_LS = nil then
        begin
          frmJTBY_LS := TfrmJTBY_LS.Create(application.MainForm);
          with frmJTBY_LS do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJTBY_LS.BringToFront;
       //句柄
        mnewHandle := frmJTBY_LS.Handle;
      end;
    311:  //消息记录
      begin
        if frmWXJL = nil then
        begin
          frmWXJL := TfrmWXJL.Create(application.MainForm);
          with frmWXJL do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmWXJL.BringToFront;
       //句柄
        mnewHandle := frmWXJL.Handle;
      end;
    312:  //机修情况
      begin
        if frmJXQK = nil then
        begin
          frmJXQK := TfrmJXQK.Create(application.MainForm);
          with frmJXQK do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJXQK.BringToFront;
       //句柄
        mnewHandle := frmJXQK.Handle;
      end;
    313:  //机修效率
      begin
        if frmJXXL = nil then
        begin
          frmJXXL := TfrmJXXL.Create(application.MainForm);
          with frmJXXL do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJXXL.BringToFront;
       //句柄
        mnewHandle := frmJXXL.Handle;
      end;
    314:  //机台情况
      begin
        if frmJTQK = nil then
        begin
          frmJTQK := TfrmJTQK.Create(application.MainForm);
          with frmJTQK do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJTQK.BringToFront;
       //句柄
        mnewHandle := frmJTQK.Handle;
      end;
    315:  //语音播报
      begin
        if frmYYBB = nil then
        begin
          frmYYBB := TfrmYYBB.Create(application.MainForm);
          with frmYYBB do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYYBB.BringToFront;
       //句柄
        mnewHandle := frmYYBB.Handle;
      end;
    411:  //机修维修时长统计
      begin
        if frmJXSC = nil then
        begin
          frmJXSC := TfrmJXSC.Create(application.MainForm);
          with frmJXSC do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJXSC.BringToFront;
       //句柄
        mnewHandle := frmJXSC.Handle;
      end;
    412:  //机台故障率统计
      begin
        if frmJTQty = nil then
        begin
          frmJTQty := TfrmJTQty.Create(application.MainForm);
          with frmJTQty do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJTQty.BringToFront;
       //句柄
        mnewHandle := frmJTQty.Handle;
      end;
    413:  //故障类型统计
      begin
        if frmGZQty = nil then
        begin
          frmGZQty := TfrmGZQty.Create(application.MainForm);
          with frmGZQty do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmGZQty.BringToFront;
       //句柄
        mnewHandle := frmGZQty.Handle;
      end;
  end;

  Result := mnewHandle;
//  NewDllApp := Application;
end;
//===========================================================
  //建立数据库连接池
//===========================================================

function ConnData(): Boolean;
begin
  if not Assigned(DataLink_BaseInfo) then
    DataLink_BaseInfo := TDataLink_BaseInfo.Create(Application);
  try
    with DataLink_BaseInfo.ADOLink do
    begin
      //if not Connected then
      begin
        Connected := false;
        ConnectionString := DConString;
        LoginPrompt := false;
        Connected := true;
      end;
    end;
    Result := true;
  except
    Result := false;
    application.MessageBox('数据库连接失败！', '错误', mb_Ok + MB_ICONERROR);
  end;

end;

//initialization
//  OldDllApp := Application;
//
//
//finalization
//  DataLink_BaseInfo.Free;
//  Application := OldDllApp;
initialization
  CoInitialize(nil);
  dxUnitsLoader.Initialize;


finalization
  DataLink_BaseInfo.Free;
  application := NewDllApp;
  dxUnitsLoader.Finalize;

end.

