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_ClothSCList, U_ClothSCListAnPaiJiTaiAP, U_ClothSCDCGAnPai,
  U_ClothGMList, U_MJManageNewFDJJAP, U_JYOrderCDOne, U_DcgGzList;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取Dll中得窗体                              //
     //        参数说明：App>>调用应用程序；                        //
    //                 FormH>>调用窗口句柄 ；                      //
   //                 FormID>>窗口号;                             //
  //                 Language>>语言种类;                         //
 //                 WinStyle>>窗口类型；                        //
/////////////////////////////////////////////////////////////////
var
  frmClothSCListLR, frmClothSCListSC1, frmClothSCListSC2, frmClothSCListCX, frmClothSCListCXy, frmClothSCListLRy: TfrmClothSCList;
  frmJYOrderCDOnePBGL, frmJYOrderCDOnePBCX: TfrmJYOrderCDOnePB;
  frmClothSCListAnPaiJiTaiAPGL1, frmClothSCListAnPaiJiTaiAPGL2, frmClothSCListAnPaiJiTaiAPCX: TfrmClothSCListAnPaiJiTaiAP;
  frmClothSCDCGAnPai1, frmClothSCDCGAnPai2, frmClothSCDCGAnPai1gl, frmClothSCDCGAnPai1GL2: TfrmClothSCDCGAnPai;
  frmMJManageNewFDJJAPy, frmMJManageNewFDJJAP: TfrmMJManageNewFDJJAP;

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
    user := 'longfengsa';
    dtbase := 'xianghengdata';
    server := '116.62.5.81,7781';
    pswd := 'rightsoft@81';
//  dtbase := 'maishuodata';
//  dtbase := 'guanyuandata';
    DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
//  DName := '谭明江';
//  DParameters1 := 'BS';
   //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
    101:  //坯布生产计划单录入(二车间)
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '坯布生产计划单录入(二车间)' then
          begin
            BringWindowToTop(frmClothSCListLR.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmClothSCListLR := TfrmClothSCList.Create(application.MainForm);
          with frmClothSCListLR do
          begin
            Title := '坯布生产计划单录入(二车间)';
            FCHEJIAN := '二车间';
            canshu1 := '录入';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmClothSCListLR.BringToFront;
       //句柄
        mnewHandle := frmClothSCListLR.Handle;
      end;

    102:  //坯布生产计划单查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '坯布生产计划单查询(二车间)' then
          begin
            BringWindowToTop(frmClothSCListCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmClothSCListCX := TfrmClothSCList.Create(application.MainForm);
          with frmClothSCListCX do
          begin
            Title := '坯布生产计划单查询(二车间)';
            FCHEJIAN := '二车间';
            canshu1 := '查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmClothSCListCX.BringToFront;
       //句柄
        mnewHandle := frmClothSCListCX.Handle;
      end;

    103:  //坯布生产计划单录入(一车间)
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '坯布生产计划单录入(一车间)' then
          begin
            BringWindowToTop(frmClothSCListLRy.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmClothSCListLRy := TfrmClothSCList.Create(application.MainForm);
          with frmClothSCListLRy do
          begin
            Title := '坯布生产计划单录入(一车间)';
            FCHEJIAN := '一车间';
            canshu1 := '录入';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmClothSCListLRy.BringToFront;
       //句柄
        mnewHandle := frmClothSCListLRy.Handle;
      end;

    104:  //坯布生产计划单查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '坯布生产计划单查询(一车间)' then
          begin
            BringWindowToTop(frmClothSCListCXy.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmClothSCListCXy := TfrmClothSCList.Create(application.MainForm);
          with frmClothSCListCXy do
          begin
            Title := '坯布生产计划单查询(一车间)';
            FCHEJIAN := '一车间';
            canshu1 := '查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmClothSCListCXy.BringToFront;
       //句柄
        mnewHandle := frmClothSCListCXy.Handle;
      end;

    201:  //机台安排
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '机台安排' then
          begin
            BringWindowToTop(frmClothSCListAnPaiJiTaiAPGL1.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmClothSCListAnPaiJiTaiAPGL1 := TfrmClothSCListAnPaiJiTaiAP.Create(application.MainForm);
          with frmClothSCListAnPaiJiTaiAPGL1 do
          begin
            Title := '机台安排';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmClothSCListAnPaiJiTaiAPGL1.BringToFront;
       //句柄
        mnewHandle := frmClothSCListAnPaiJiTaiAPGL1.Handle;
      end;

    202:  //机台安排查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '机台安排查询' then
          begin
            BringWindowToTop(frmClothSCListAnPaiJiTaiAPCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmClothSCListAnPaiJiTaiAPCX := TfrmClothSCListAnPaiJiTaiAP.Create(application.MainForm);
          with frmClothSCListAnPaiJiTaiAPCX do
          begin
            Title := '机台安排查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmClothSCListAnPaiJiTaiAPCX.BringToFront;
       //句柄
        mnewHandle := frmClothSCListAnPaiJiTaiAPCX.Handle;
      end;

    301:  //布票打印
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '布票打印(二车间)' then
          begin
            BringWindowToTop(frmClothSCDCGAnPai1.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmClothSCDCGAnPai1 := TfrmClothSCDCGAnPai.Create(application.MainForm);
          with frmClothSCDCGAnPai1 do
          begin
            Title := '布票打印(二车间)';
            canshu1 := '二车间';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
//            DParameters1:=YD;
           //show;
          end;
        end
        else
          frmClothSCDCGAnPai1.BringToFront;
       //句柄
        mnewHandle := frmClothSCDCGAnPai1.Handle;
      end;

    302:  //布票打印(高权限)
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '布票打印(二车间高权限)' then
          begin
            BringWindowToTop(frmClothSCDCGAnPai1GL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmClothSCDCGAnPai1GL := TfrmClothSCDCGAnPai.Create(application.MainForm);
          with frmClothSCDCGAnPai1GL do
          begin
            Title := '布票打印(二车间高权限)';
            canshu1 := '二车间';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
//            DParameters1:=YD;
           //show;
          end;
        end
        else
          frmClothSCDCGAnPai1GL.BringToFront;
       //句柄
        mnewHandle := frmClothSCDCGAnPai1GL.Handle;
      end;

    303:  //布票打印
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '布票打印(一车间)' then
          begin
            BringWindowToTop(frmClothSCDCGAnPai2.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmClothSCDCGAnPai2 := TfrmClothSCDCGAnPai.Create(application.MainForm);
          with frmClothSCDCGAnPai2 do
          begin
            Title := '布票打印(一车间)';
            canshu1 := '一车间';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
//            DParameters1:=YD;
           //show;
          end;
        end
        else
          frmClothSCDCGAnPai2.BringToFront;
       //句柄
        mnewHandle := frmClothSCDCGAnPai2.Handle;
      end;

    304:  //布票打印(高权限)
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '布票打印(一车间高权限)' then
          begin
            BringWindowToTop(frmClothSCDCGAnPai1GL2.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmClothSCDCGAnPai1GL2 := TfrmClothSCDCGAnPai.Create(application.MainForm);
          with frmClothSCDCGAnPai1GL2 do
          begin
            Title := '布票打印(一车间高权限)';
            canshu1 := '一车间';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
//            DParameters1:=YD;
           //show;
          end;
        end
        else
          frmClothSCDCGAnPai1GL2.BringToFront;
       //句柄
        mnewHandle := frmClothSCDCGAnPai1GL2.Handle;
      end;

    401:  //手工挂码
      begin
        if frmClothGMList = nil then
        begin
          frmClothGMList := TfrmClothGMList.Create(application.MainForm);
          with frmClothGMList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmClothGMList.BringToFront;
       //句柄
        mnewHandle := frmClothGMList.Handle;
      end;

    402: // 坯布检验（二车间）
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '坯布检验(二车间)' then
          begin
            BringWindowToTop(frmMJManageNewFDJJAP.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmMJManageNewFDJJAP := TfrmMJManageNewFDJJAP.Create(application.MainForm);
          with frmMJManageNewFDJJAP do
          begin
            Title := '坯布检验(二车间)';
            canshu1 := '二车间';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
//            DParameters1:=YD;
           //show;
          end;
        end
        else
          frmMJManageNewFDJJAP.BringToFront;
       //句柄
        mnewHandle := frmMJManageNewFDJJAP.Handle;
      end;
    4021: // 坯布检验（一车间）
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '坯布检验(一车间)' then
          begin
            BringWindowToTop(frmMJManageNewFDJJAPy.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmMJManageNewFDJJAPy := TfrmMJManageNewFDJJAP.Create(application.MainForm);
          with frmMJManageNewFDJJAPy do
          begin
            Title := '坯布检验(一车间)';
            canshu1 := '一车间';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
//            DParameters1:=YD;
           //show;
          end;
        end
        else
          frmMJManageNewFDJJAPy.BringToFront;
       //句柄
        mnewHandle := frmMJManageNewFDJJAPy.Handle;
      end;

    501:  //检验信息管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '检验信息管理' then
          begin
            BringWindowToTop(frmJYOrderCDOnePBGL.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
       //if frmBaoGuanListBGZL=nil then
        begin
          frmJYOrderCDOnePBGL := TfrmJYOrderCDOnePB.Create(application.MainForm);
          with frmJYOrderCDOnePBGL do
          begin
            Title := '检验信息管理';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJYOrderCDOnePBGL.BringToFront;
       //句柄
        mnewHandle := frmJYOrderCDOnePBGL.Handle;
      end;
    502:  //检验信息查询
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '检验信息查询' then
          begin
            BringWindowToTop(frmJYOrderCDOnePBCX.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
       //if frmBaoGuanListBGZL=nil then
        begin
          frmJYOrderCDOnePBCX := TfrmJYOrderCDOnePB.Create(application.MainForm);
          with frmJYOrderCDOnePBCX do
          begin
            Title := '检验信息查询';
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmJYOrderCDOnePBCX.BringToFront;
       //句柄
        mnewHandle := frmJYOrderCDOnePBCX.Handle;
      end;

    601:  //次布报告
      begin
        if frmDcgGzList = nil then
        begin
          frmDcgGzList := TfrmDcgGzList.Create(application.MainForm);
          with frmDcgGzList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmDcgGzList.BringToFront;
       //句柄
        mnewHandle := frmDcgGzList.Handle;

      end;
  end;

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

function ConnData(): Boolean;
begin
  if not Assigned(DataLink_WeavingSchedule) then
    DataLink_WeavingSchedule := TDataLink_WeavingSchedule.Create(Application);
  try
    with DataLink_WeavingSchedule.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_WeavingSchedule.Free;
//  Application := OldDllApp;
initialization
  CoInitialize(nil);
  dxUnitsLoader.Initialize;


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

end.

