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_MLRklist, U_MLCKlist, U_MLKcList, U_MLKcHzList, U_PBRklist,
  U_PBCKlist, U_PBKcList, U_SPRklist, U_SPCKlist, U_SPKcList, U_HJGRklist,
  U_HJGCKlist, U_HJGKcList, U_TCRklist, U_TCCKlist, U_TCKcList, U_CPRklist,
  U_CPCKlist, U_CPKcList, U_QBKcList;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取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 := '121.40.233.100,7781';
 // server := '.';
  dtbase := 'sanshuidata';
  user := 'sa';
  pswd := 'rightsoft@123';
//  pswd := 'rightsoft';
  DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
  DConString := DataBaseStr;
//  DName := 'ADMIN';
// 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 frmQBKcList = nil then
        begin
          frmQBKcList := TfrmQBKcList.Create(application.MainForm);
          with frmQBKcList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmQBKcList.BringToFront;
       //句柄
        mnewHandle := frmQBKcList.Handle;
      end;

    111:  //纱线入库
      begin
        if frmSPRklist = nil then
        begin
          frmSPRklist := TfrmSPRklist.Create(application.MainForm);
          with frmSPRklist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSPRklist.BringToFront;
       //句柄
        mnewHandle := frmSPRklist.Handle;
      end;

    121:  //纱线出库
      begin
        if frmSPCKlist = nil then
        begin
          frmSPCKlist := TfrmSPCKlist.Create(application.MainForm);
          with frmSPCKlist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSPCKlist.BringToFront;
       //句柄
        mnewHandle := frmSPCKlist.Handle;
      end;

    131:  //纱线库存
      begin
        if frmSPKcList = nil then
        begin
          frmSPKcList := TfrmSPKcList.Create(application.MainForm);
          with frmSPKcList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSPKcList.BringToFront;
       //句柄
        mnewHandle := frmSPKcList.Handle;
      end;
    211:  //坯布入库
      begin
        if frmPBRklist = nil then
        begin
          frmPBRklist := TfrmPBRklist.Create(application.MainForm);
          with frmPBRklist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPBRklist.BringToFront;
       //句柄
        mnewHandle := frmPBRklist.Handle;
      end;
    221:  //坯布出库
      begin
        if frmPBCKlist = nil then
        begin
          frmPBCKlist := TfrmPBCKlist.Create(application.MainForm);
          with frmPBCKlist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPBCKlist.BringToFront;
       //句柄
        mnewHandle := frmPBCKlist.Handle;
      end;
    231:  //坯布库存
      begin
        if frmPBKcList = nil then
        begin
          frmPBKcList := TfrmPBKcList.Create(application.MainForm);
          with frmPBKcList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmPBKcList.BringToFront;
       //句柄
        mnewHandle := frmPBKcList.Handle;
      end;

    311:  //后加工入库
      begin
        if frmHJGRklist = nil then
        begin
          frmHJGRklist := TfrmHJGRklist.Create(application.MainForm);
          with frmHJGRklist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmHJGRklist.BringToFront;
       //句柄
        mnewHandle := frmHJGRklist.Handle;
      end;

    321:  //后加工出库
      begin
        if frmHJGCKlist = nil then
        begin
          frmHJGCKlist := TfrmHJGCKlist.Create(application.MainForm);
          with frmHJGCKlist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmHJGCKlist.BringToFront;
       //句柄
        mnewHandle := frmHJGCKlist.Handle;
      end;

    331:  //后加工库存
      begin
        if frmHJGKcList = nil then
        begin
          frmHJGKcList := TfrmHJGKcList.Create(application.MainForm);
          with frmHJGKcList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmHJGKcList.BringToFront;
       //句柄
        mnewHandle := frmHJGKcList.Handle;
      end;

    411:  //待检布入库
      begin
        if frmTCRklist = nil then
        begin
          frmTCRklist := TfrmTCRklist.Create(application.MainForm);
          with frmTCRklist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmTCRklist.BringToFront;
       //句柄
        mnewHandle := frmTCRklist.Handle;
      end;

    421:  //待检布出库
      begin
        if frmTCCKlist = nil then
        begin
          frmTCCKlist := TfrmTCCKlist.Create(application.MainForm);
          with frmTCCKlist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmTCCKlist.BringToFront;
       //句柄
        mnewHandle := frmTCCKlist.Handle;
      end;

    431:  //待检布库存
      begin
        if frmTCKcList = nil then
        begin
          frmTCKcList := TfrmTCKcList.Create(application.MainForm);
          with frmTCKcList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmTCKcList.BringToFront;
       //句柄
        mnewHandle := frmTCKcList.Handle;
      end;
    511:  //成品入库
      begin
        if frmCPRklist = nil then
        begin
          frmCPRklist := TfrmCPRklist.Create(application.MainForm);
          with frmCPRklist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCPRklist.BringToFront;
       //句柄
        mnewHandle := frmCPRklist.Handle;
      end;

    521:  //成品出库
      begin
        if frmCPCKlist = nil then
        begin
          frmCPCKlist := TfrmCPCKlist.Create(application.MainForm);
          with frmCPCKlist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCPCKlist.BringToFront;
       //句柄
        mnewHandle := frmCPCKlist.Handle;
      end;

    531:  //成品库存
      begin
        if frmCPKcList = nil then
        begin
          frmCPKcList := TfrmCPKcList.Create(application.MainForm);
          with frmCPKcList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCPKcList.BringToFront;
       //句柄
        mnewHandle := frmCPKcList.Handle;
      end;
    911:  //面料入库
      begin
        if frmMLRklist = nil then
        begin
          frmMLRklist := TfrmMLRklist.Create(application.MainForm);
          with frmMLRklist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMLRklist.BringToFront;
       //句柄
        mnewHandle := frmMLRklist.Handle;
      end;
    921:  //面料出库
      begin
        if frmMLCKlist = nil then
        begin
          frmMLCKlist := TfrmMLCKlist.Create(application.MainForm);
          with frmMLCKlist do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMLCKlist.BringToFront;
       //句柄
        mnewHandle := frmMLCKlist.Handle;
      end;
    931:  //面料库存
      begin
        if frmMLKcList = nil then
        begin
          frmMLKcList := TfrmMLKcList.Create(application.MainForm);
          with frmMLKcList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMLKcList.BringToFront;
       //句柄
        mnewHandle := frmMLKcList.Handle;
      end;

    932:  //面料库存汇总
      begin
        if frmMLKcHzList = nil then
        begin
          frmMLKcHzList := TfrmMLKcHzList.Create(application.MainForm);
          with frmMLKcHzList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmMLKcHzList.BringToFront;
       //句柄
        mnewHandle := frmMLKcHzList.Handle;
      end;

  end;

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

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

end.

