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_ShuttleLSSCList, U_WireInspection, U_FinishedLSInspection,
  U_FinishedLSInList, U_FinishedLSOutList, U_FinishedLSKCList, U_LSFHSQList,
  U_LSSQSMCK, U_FinishedLSCLList, U_LSJJ, U_LSGZCX, U_ShaRKList, U_ShaKCList,
  U_JTSJY, U_YarnRack, U_JTSKCHZ, U_ShaWDHList, U_ShaWFHList, U_ShaKCHZList,U_LSFHSQListHD;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取Dll中得窗体                              //
     //        参数说明：App>>调用应用程序；                        //
    //                 FormH>>调用窗口句柄 ；                      //
   //                 FormID>>窗口号;                             //
  //                 Language>>语言种类;                         //
 //                 WinStyle>>窗口类型；                        //
/////////////////////////////////////////////////////////////////
var
  frmShaRKListRK, frmShaRKListGQX, frmShaRKListView: TfrmShaRKList;
  frmShuttleLSSCListLR, frmShuttleLSSCListGL, frmShuttleLSSCListCX: TfrmShuttleLSSCList;
  frmFinishedLSInspectionGL, frmFinishedLSInspectionCX: TfrmFinishedLSInspection;
  frmFinishedLSOutListGL, frmFinishedLSOutListCX: TfrmFinishedLSOutList;
  frmFinishedLSKCListGL, frmFinishedLSKCListCX: TfrmFinishedLSKCList;
  frmLSFHSQListLR, frmLSFHSQListSH, frmLSFHSQListCX: TfrmLSFHSQList;

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';
    dtbase := 'yongjindata';
    user := 'yifusa';
    pswd := 'rightsoft@123';
  //server := '.';
  //dtbase := 'yifudata';
  //user := 'sa';
  //pswd := 'rightsoft';
    DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;

   //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
    1:  //原料计划到货情况
      begin
        if frmShaWDHList = nil then
        begin
          frmShaWDHList := TfrmShaWDHList.Create(application.MainForm);
          with frmShaWDHList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmShaWDHList.BringToFront;
       //句柄
        mnewHandle := frmShaWDHList.Handle;
      end;
    2:  //纱线未发货情况
      begin
        if frmShaWFHList = nil then
        begin
          frmShaWFHList := TfrmShaWFHList.Create(application.MainForm);
          with frmShaWFHList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmShaWFHList.BringToFront;
       //句柄
        mnewHandle := frmShaWFHList.Handle;
      end;
    3:  //加弹丝库存汇总查询
      begin
        if frmShaKCHZList = nil then
        begin
          frmShaKCHZList := TfrmShaKCHZList.Create(application.MainForm);
          with frmShaKCHZList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmShaKCHZList.BringToFront;
       //句柄
        mnewHandle := frmShaKCHZList.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(frmShaRKListRK.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmShaRKListRK := TfrmShaRKList.Create(application.MainForm);
          with frmShaRKListRK do
          begin
            Title := '纱线入库管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmShaRKListRK.BringToFront;
       //句柄
        mnewHandle := frmShaRKListRK.Handle;
      end;
    121:  //纱线库存
      begin
        if frmShaKCList = nil then
        begin
          frmShaKCList := TfrmShaKCList.Create(application.MainForm);
          with frmShaKCList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmShaKCList.BringToFront;
       //句柄
        mnewHandle := frmShaKCList.Handle;
      end;
    130:  //纱架管理
      begin
        if frmYarnRack = nil then
        begin
          frmYarnRack := TfrmYarnRack.Create(application.MainForm);
          with frmYarnRack do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYarnRack.BringToFront;
       //句柄
        mnewHandle := frmYarnRack.Handle;
      end;

    131:  //加弹丝排单录入
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '加弹丝排单录入' then
          begin
            BringWindowToTop(frmShuttleLSSCListLR.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmShuttleLSSCListLR := TfrmShuttleLSSCList.Create(application.MainForm);
          with frmShuttleLSSCListLR do
          begin
            Title := '加弹丝排单录入';
            caption := Trim(Title);
            canshu1 := '录入';
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmShuttleLSSCListLR.BringToFront;
       //句柄
        mnewHandle := frmShuttleLSSCListLR.Handle;
      end;
    132:  //加弹丝排单管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '加弹丝排单管理' then
          begin
            BringWindowToTop(frmShuttleLSSCListGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmShuttleLSSCListGL := TfrmShuttleLSSCList.Create(application.MainForm);
          with frmShuttleLSSCListGL do
          begin
            Title := '加弹丝排单管理';
            caption := Trim(Title);
            canshu1 := '管理';
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmShuttleLSSCListGL.BringToFront;
       //句柄
        mnewHandle := frmShuttleLSSCListGL.Handle;
      end;
    133:  //加弹丝排单查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '加弹丝排单查询' then
          begin
            BringWindowToTop(frmShuttleLSSCListCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmShuttleLSSCListCX := TfrmShuttleLSSCList.Create(application.MainForm);
          with frmShuttleLSSCListCX do
          begin
            Title := '加弹排单查询';
            caption := Trim(Title);
            canshu1 := '查询';
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmShuttleLSSCListCX.BringToFront;
       //句柄
        mnewHandle := frmShuttleLSSCListCX.Handle;
      end;

    211:  //加弹丝下机
      begin
        if frmJTSJY = nil then
        begin
          frmJTSJY := TfrmJTSJY.Create(application.MainForm);
          with frmJTSJY do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJTSJY.BringToFront;
       //句柄
        mnewHandle := frmJTSJY.Handle;
      end;

    311:  //加弹丝检验信息管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '加弹丝检验信息管理' then
          begin
            BringWindowToTop(frmFinishedLSInspectionGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmFinishedLSInspectionGL := TfrmFinishedLSInspection.Create(application.MainForm);
          with frmFinishedLSInspectionGL do
          begin
            Title := '加弹丝检验信息管理';
            canshu1 := '管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmFinishedLSInspectionGL.BringToFront;
       //句柄
        mnewHandle := frmFinishedLSInspectionGL.Handle;
      end;

    312:  //检验信息查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '加弹丝检验信息查询' then
          begin
            BringWindowToTop(frmFinishedLSInspectionCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmFinishedLSInspectionCX := TfrmFinishedLSInspection.Create(application.MainForm);
          with frmFinishedLSInspectionCX do
          begin
            Title := '加弹丝检验信息查询';
            canshu1 := '查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmFinishedLSInspectionCX.BringToFront;
       //句柄
        mnewHandle := frmFinishedLSInspectionCX.Handle;
      end;

    411:  //加弹丝入库查询
      begin
        if frmFinishedLSInList = nil then
        begin
          frmFinishedLSInList := TfrmFinishedLSInList.Create(application.MainForm);
          with frmFinishedLSInList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmFinishedLSInList.BringToFront;
       //句柄
        mnewHandle := frmFinishedLSInList.Handle;
      end;

    711:  //加弹丝发货申请录入
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '加弹丝发货申请录入' then
          begin
            BringWindowToTop(frmLSFHSQListLR.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmLSFHSQListLR := TfrmLSFHSQList.Create(application.MainForm);
          with frmLSFHSQListLR do
          begin
            canshu1 := '录入';
            Title := '加弹丝发货申请录入';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmLSFHSQListLR.BringToFront;
       //句柄
        mnewHandle := frmLSFHSQListLR.Handle;
      end;
    712:  //加弹丝发货申请审核
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '加弹丝发货申请审核' then
          begin
            BringWindowToTop(frmLSFHSQListSH.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmLSFHSQListSH := TfrmLSFHSQList.Create(application.MainForm);
          with frmLSFHSQListSH do
          begin
            canshu1 := '审核';
            Title := '加弹丝发货申请审核';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmLSFHSQListSH.BringToFront;
       //句柄
        mnewHandle := frmLSFHSQListSH.Handle;
      end;
    713:  //加弹丝发货申请查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '加弹丝发货申请查询' then
          begin
            BringWindowToTop(frmLSFHSQListCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmLSFHSQListCX := TfrmLSFHSQList.Create(application.MainForm);
          with frmLSFHSQListCX do
          begin
            canshu1 := '查询';
            Title := '加弹丝发货申请查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmLSFHSQListCX.BringToFront;
       //句柄
        mnewHandle := frmLSFHSQListCX.Handle;
      end;
    
    715:  //加弹发货核对
      begin
        if frmLSFHSQListHD = nil then
        begin
          frmLSFHSQListHD := TfrmLSFHSQListHD.Create(application.MainForm);
          with frmLSFHSQListHD do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmLSFHSQListHD.BringToFront;
       //句柄
        mnewHandle := frmLSFHSQListHD.Handle;
      end;

    721:  //加弹丝扫描出库
      begin
        if frmLSSQSMCK = nil then
        begin
          frmLSSQSMCK := TfrmLSSQSMCK.Create(application.MainForm);
          with frmLSSQSMCK do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmLSSQSMCK.BringToFront;
       //句柄
        mnewHandle := frmLSSQSMCK.Handle;
      end;

    511:  //加弹丝出库管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '加弹丝出库管理' then
          begin
            BringWindowToTop(frmFinishedLSOutListGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmFinishedLSOutListGL := TfrmFinishedLSOutList.Create(application.MainForm);
          with frmFinishedLSOutListGL do
          begin
            canshu1 := '管理';
            Title := '加弹丝出库管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmFinishedLSOutListGL.BringToFront;
       //句柄
        mnewHandle := frmFinishedLSOutListGL.Handle;
      end;
    512:  //加弹丝出库查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '加弹丝出库查询' then
          begin
            BringWindowToTop(frmFinishedLSOutListCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmFinishedLSOutListCX := TfrmFinishedLSOutList.Create(application.MainForm);
          with frmFinishedLSOutListCX do
          begin
            canshu1 := '查询';
            Title := '加弹丝出库查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
          end;
        end
        else
          frmFinishedLSOutListCX.BringToFront;
       //句柄
        mnewHandle := frmFinishedLSOutListCX.Handle;
      end;
    611:  //加弹库存查询
      begin
        if frmJTSKCHZ = nil then
        begin
          frmJTSKCHZ := TfrmJTSKCHZ.Create(application.MainForm);
          with frmJTSKCHZ do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJTSKCHZ.BringToFront;
       //句柄
        mnewHandle := frmJTSKCHZ.Handle;
      end;

    811:  //产量查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '拉丝产量统计' then
          begin
            BringWindowToTop(frmFinishedLSCLList.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmFinishedLSCLList := TfrmFinishedLSCLList.Create(application.MainForm);
          with frmFinishedLSCLList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmFinishedLSCLList.BringToFront;
       //句柄
        mnewHandle := frmFinishedLSCLList.Handle;
      end;

    911:  //工资定义
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '拉丝工资设置' then
          begin
            BringWindowToTop(frmLSJJ.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmLSJJ := TfrmLSJJ.Create(application.MainForm);
          with frmLSJJ do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmLSJJ.BringToFront;
       //句柄
        mnewHandle := frmLSJJ.Handle;
      end;
    921:  //工资查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '拉丝工资查询' then
          begin
            BringWindowToTop(frmLSGZCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmLSGZCX := TfrmLSGZCX.Create(application.MainForm);
          with frmLSGZCX do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmLSGZCX.BringToFront;
       //句柄
        mnewHandle := frmLSGZCX.Handle;
      end;
  end;

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

function ConnData(): Boolean;
begin
  if not Assigned(DataLink_YarnTexturing) then
    DataLink_YarnTexturing := TDataLink_YarnTexturing.Create(Application);
  try
    with DataLink_YarnTexturing.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_YarnTexturing.Free;
  application := NewDllApp;
  dxUnitsLoader.Finalize;

end.

