unit U_GetDllForm;

interface

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

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_CPAllTop, U_PBAllTop, U_PBAllTopQ30, U_CPAllTopQ30, U_CarTKTop,
  U_KHTop, U_DJTop, U_JYFTop, U_BIHZList, U_PBNameDayQtyList, U_CarTKHZTop,
  U_OrderHSList, U_DeptType, U_BXList,U_DJMoneyTop,U_DCMoneyTop,U_BXListChk,U_DCTimeZhou,U_purview;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取Dll中得窗体                              //
     //        参数说明：App>>调用应用程序；                        //
    //                 FormH>>调用窗口句柄 ；                      //
   //                 FormID>>窗口号;                             //
  //                 Language>>语言种类;                         //
 //                 WinStyle>>窗口类型；                        //
/////////////////////////////////////////////////////////////////

var
  frmOrderHSListDJ, frmOrderHSListDJTS, frmOrderHSListchk, frmOrderHSListHD, frmOrderHSListGL, frmOrderHSListCX: TfrmOrderHSList;
  frmBXListGL, frmBXListCX: TfrmBXList;

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
  i: Integer;
  bFound: Boolean;
  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);

  if trim(DataBaseStr) = '' then
  begin
    server := '139.196.189.214,7781';
  //server:='.';
    dtbase := 'yongjindata';
    user := 'yifusa';
 // user := 'sa';
  //dtbase := 'yifudata';
    pswd := 'rightsoft@123';              
  // pswd:='rightsoft';
    DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
//
 // DCode:='ADMIN';
  //Dname:='李静';
//DParameters1:='高权限';
//DParameters3:='1';

  end
  else
  begin
    DConString := DataBaseStr;
  end;

  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
    0:  //权限控制
      begin
        if frmpurviewDL = nil then
        begin
          frmpurviewDL := TfrmpurviewDL.Create(application.MainForm);
          with frmpurviewDL do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmpurviewDL.BringToFront;
       //句柄
        mnewHandle := frmpurviewDL.Handle;
      end;
    100:  //费用报销后台设置
      begin
        if frmDeptType = nil then
        begin
          frmDeptType := TfrmDeptType.Create(application.MainForm);
          with frmDeptType do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmDeptType.BringToFront;
       //句柄
        mnewHandle := frmDeptType.Handle;
      end;
    1001:  //费用报销查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '费用报销查询' then
          begin
            BringWindowToTop(frmBXListCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmBXListCX := TfrmBXList.Create(application.MainForm);
          with frmBXListCX do
          begin
            canshu1 := '查询';
            Title := '费用报销查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBXListCX.BringToFront;
       //句柄
        mnewHandle := frmBXListCX.Handle;
      end;
    1002:  //费用报销管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '费用报销管理' then
          begin
            BringWindowToTop(frmBXListGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmBXListGL := TfrmBXList.Create(application.MainForm);
          with frmBXListGL do
          begin
            canshu1 := '管理';
            Title := '费用报销管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBXListGL.BringToFront;
       //句柄
        mnewHandle := frmBXListGL.Handle;
      end;
    1003:  //费用报销审核
      begin
        if frmBXListChk = nil then
        begin
          frmBXListChk := TfrmBXListChk.Create(application.MainForm);
          with frmBXListChk do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBXListChk.BringToFront;
       //句柄
        mnewHandle := frmBXListChk.Handle;
      end;
    101:  //产品20排行榜
      begin
        if frmCPAllTop = nil then
        begin
          frmCPAllTop := TfrmCPAllTop.Create(application.MainForm);
          with frmCPAllTop do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCPAllTop.BringToFront;
       //句柄
        mnewHandle := frmCPAllTop.Handle;
      end;
    102:  //产品百大排行榜
      begin
        if frmCPAllTopQ30 = nil then
        begin
          frmCPAllTopQ30 := TfrmCPAllTopQ30.Create(application.MainForm);
          with frmCPAllTopQ30 do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCPAllTopQ30.BringToFront;
       //句柄
        mnewHandle := frmCPAllTopQ30.Handle;
      end;
    103:  //坯布Top20排行榜
      begin
        if frmPBAllTop = nil then
        begin
          frmPBAllTop := TfrmPBAllTop.Create(application.MainForm);
          with frmPBAllTop do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPBAllTop.BringToFront;
       //句柄
        mnewHandle := frmPBAllTop.Handle;
      end;
    104:  //坯布百大排行榜
      begin
        if frmPBAllTopQ30 = nil then
        begin
          frmPBAllTopQ30 := TfrmPBAllTopQ30.Create(application.MainForm);
          with frmPBAllTopQ30 do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPBAllTopQ30.BringToFront;
       //句柄
        mnewHandle := frmPBAllTopQ30.Handle;
      end;
    105:  //开/停机天数排行榜
      begin
        if frmCarTKHZTop = nil then
        begin
          frmCarTKHZTop := TfrmCarTKHZTop.Create(application.MainForm);
          with frmCarTKHZTop do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCarTKHZTop.BringToFront;
       //句柄
        mnewHandle := frmCarTKHZTop.Handle;
      end;
    106:  //客户销量排行榜
      begin
        if frmKHTop = nil then
        begin
          frmKHTop := TfrmKHTop.Create(application.MainForm);
          with frmKHTop do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmKHTop.BringToFront;
       //句柄
        mnewHandle := frmKHTop.Handle;
      end;
    107:  //仓库工人排行榜
      begin
        if frmDJTop = nil then
        begin
          frmDJTop := TfrmDJTop.Create(application.MainForm);
          with frmDJTop do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmDJTop.BringToFront;
       //句柄
        mnewHandle := frmDJTop.Handle;
      end;
    108:  //检验分排行榜
      begin
        if frmJYFTop = nil then
        begin
          frmJYFTop := TfrmJYFTop.Create(application.MainForm);
          with frmJYFTop do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJYFTop.BringToFront;
       //句柄
        mnewHandle := frmJYFTop.Handle;
      end;
    109:  //数据大集
      begin
        if frmBIHZList = nil then
        begin
          frmBIHZList := TfrmBIHZList.Create(application.MainForm);
          with frmBIHZList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmBIHZList.BringToFront;
       //句柄
        mnewHandle := frmBIHZList.Handle;
      end;
    110:  //品名日产量分析表
      begin
        if frmPBNameDayQtyList = nil then
        begin
          frmPBNameDayQtyList := TfrmPBNameDayQtyList.Create(application.MainForm);
          with frmPBNameDayQtyList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPBNameDayQtyList.BringToFront;
       //句柄
        mnewHandle := frmPBNameDayQtyList.Handle;
      end;
    111:  //订单核算登记
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '订单核算登记' then
          begin
            BringWindowToTop(frmOrderHSListDJ.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmOrderHSListDJ := TfrmOrderHSList.Create(application.MainForm);
          with frmOrderHSListDJ do
          begin
            canshu1 := '登记';
            Title := '订单核算登记';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmOrderHSListDJ.BringToFront;
       //句柄
        mnewHandle := frmOrderHSListDJ.Handle;
      end;
    1112:  //订单核算登记(统算)
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '订单核算登记(统算)' then
          begin
            BringWindowToTop(frmOrderHSListDJTS.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmOrderHSListDJTS := TfrmOrderHSList.Create(application.MainForm);
          with frmOrderHSListDJTS do
          begin
            canshu1 := '统算';
            Title := '订单核算登记(统算)';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmOrderHSListDJTS.BringToFront;
       //句柄
        mnewHandle := frmOrderHSListDJTS.Handle;
      end;
    112:  //订单核算管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '订单核算管理' then
          begin
            BringWindowToTop(frmOrderHSListGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmOrderHSListGL := TfrmOrderHSList.Create(application.MainForm);
          with frmOrderHSListGL do
          begin
            canshu1 := '管理';
            Title := '订单核算管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmOrderHSListGL.BringToFront;
       //句柄
        mnewHandle := frmOrderHSListGL.Handle;
      end;
    113:  //订单核算查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '订单核算查询' then
          begin
            BringWindowToTop(frmOrderHSListCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmOrderHSListCX := TfrmOrderHSList.Create(application.MainForm);
          with frmOrderHSListCX do
          begin
            canshu1 := '查询';
            Title := '订单核算查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmOrderHSListCX.BringToFront;
       //句柄
        mnewHandle := frmOrderHSListCX.Handle;
      end;
    115:  //订单核算审核
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '订单核算审核' then
          begin
            BringWindowToTop(frmOrderHSListchk.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmOrderHSListchk := TfrmOrderHSList.Create(application.MainForm);
          with frmOrderHSListchk do
          begin
            canshu1 := '审核';
            Title := '订单核算审核';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmOrderHSListchk.BringToFront;
       //句柄
        mnewHandle := frmOrderHSListchk.Handle;
      end;
    116:  //订单核算核对
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '订单核算核对' then
          begin
            BringWindowToTop(frmOrderHSListHD.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmOrderHSListHD := TfrmOrderHSList.Create(application.MainForm);
          with frmOrderHSListHD do
          begin
            canshu1 := '核对';
            Title := '订单核算核对';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmOrderHSListHD.BringToFront;
       //句柄
        mnewHandle := frmOrderHSListHD.Handle;
      end;
      
    117:  //打卷工工资排行榜
      begin
        if frmDJMoneyTop = nil then
        begin
          frmDJMoneyTop := TfrmDJMoneyTop.Create(application.MainForm);
          with frmDJMoneyTop do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmDJMoneyTop.BringToFront;
       //句柄
        mnewHandle := frmDJMoneyTop.Handle;
      end;
    118:  //打卷工工资排行榜
      begin
        if frmDCMoneyTop = nil then
        begin
          frmDCMoneyTop := TfrmDCMoneyTop.Create(application.MainForm);
          with frmDCMoneyTop do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmDCMoneyTop.BringToFront;
       //句柄
        mnewHandle := frmDCMoneyTop.Handle;
      end;
    119:  //圆机产量查询
      begin
        if frmDCTimeZhou = nil then
        begin
          frmDCTimeZhou := TfrmDCTimeZhou.Create(application.MainForm);
          with frmDCTimeZhou do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmDCTimeZhou.BringToFront;
       //句柄
        mnewHandle := frmDCTimeZhou.Handle;
      end;
  end;

  Result := mnewHandle;

end;
//===========================================================
  //建立数据库连接池
//===========================================================

function ConnData(): Boolean;
var
  IniFile: TIniFile;
begin
  try
    IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'SYSTEMSET.INI');
    PicSvr := IniFile.ReadString('SERVER', '服务器地址', '127.0.0.1');
    UserDataFlag := IniFile.ReadString('SERVER', '服务器地址类型', '-1');
  finally
    IniFile.Free;
  end;
  if not Assigned(DataLink_BIView) then
    DataLink_BIView := TDataLink_BIView.Create(Application);
  try
    with DataLink_BIView.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
  CoInitialize(nil);
  dxUnitsLoader.Initialize;


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

end.

