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
                                     frmProductOrderMoneyList
uses
  U_DataLink, U_Fun, U_iniParam, U_MJManageNewFDNew, U_ProductOrderList,
  U_ProductOrderAnPai, U_OrderJDList, U_MJEdit, U_JYOrderCDMore,
  U_CKProductBCPInList, U_SYRName_XS_List, U_CP_KZ_XL, U_CKProductBCPOutList,
  U_BanCpHCSaoM, U_CKProductBCPHCList, U_CKProductBCPKCList,
  U_ProductOrderNewList_JD, U_CKProductBCPKCHZList, U_CpRkSaoMNew,
  U_ClothContractList, U_ClothContractListDH, U_ClothContractListLL,
  U_ClothContractKCList, U_ContractList, U_ProductOrderNewList,
  U_ClothContractListWJG, U_ClothPDInfoList, U_CP_CRC, U_ClothHCList,
  U_ProductOrder_Ph, U_ClothContractList_CG, U_ClothContractList_Tp,
  U_ClothContractList_Help, U_ClothContractList_JG, U_CKPHKCList, U_HCList,
  U_ProductOrder_Ph10, U_CrkAccount, U_CKProductBCPInList_Other,
  U_CKProductBCPOutList_other, U_ProductOrder_Ph_other,
  U_CKProductBCPKCList_other, U_CKProductBCPKCHZList_other, U_CrkAccount_other,
  U_KCRLLTZ, U_MJManageNewFDNew_other, U_JYOrderCDOne_Other, U_xslist_other,
  U_YHList_other, U_CKProductBCPKCHZListSUM_other, U_KCRLLTZ_other, U_CKEJK,
  U_ModulePromptList, U_CKSMEdit, U_KH_XS_List, U_CP_XL, U_CP_COL_XL,
  U_CKProductCPKCHZList_Yj, U_KWSMEdit, U_CP_KC, U_SYR_CP_XS_List,
  U_SYR_CP_Col_XS_List, U_THRK_CP_list, U_CKProductBCPOutHZ_List, U_CKPDlist,
  U_ProductOrderMoneyList, U_ProductOrderNewList_OrdJD,
  U_ProductOrderMoneyList_BPXCX, U_ProductOrderShenH;

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

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 := GName;
  DCode := 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:='.';
//  pswd:='rightsoft';
  server := '106.15.78.45,7781';
  pswd := 'rightsoft@2222';
  dtbase := 'xiangyingData';
  user := 'xiangyingsa';
  DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
  DConString := DataBaseStr;
//  DParameters1 := '查询';
//  DParameters2 := '国内销售部门';
//   DParameters2:='高权限';
//  DName := 'admin';
//   DCode:='test';
//   DName:='俞盼';
//   DParameters1:='管理';
// DParameters3:='柯桥仓库';
//database:='';
  if not ConnData() then
  begin
    result := 0;
    exit;
  end;
  if IsINIFile() then
    ReadINIFile()
  else
    WriteINIFile;
   // 定义窗口类型 、状态
  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
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '大货单录入(国内)' then
          begin
            BringWindowToTop(frmProductOrderNewList.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmProductOrderNewList := TfrmProductOrderNewList.Create(application.MainForm);
          with frmProductOrderNewList do
          begin
            Title := '大货单录入(国内)';
            caption := Trim(Title);
            fsyrName := trim(DataBase);
            fDParameters1 := trim(DParameters1);
            forderType := trim(DParameters2);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderNewList.BringToFront;
       //句柄
        mnewHandle := frmProductOrderNewList.Handle;
      end;
    101:  //大货单录入(国外)
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '大货单录入(国外)' then
          begin
            BringWindowToTop(frmProductOrderNewListGW.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmProductOrderNewListGW := TfrmProductOrderNewList.Create(application.MainForm);
          with frmProductOrderNewListGW do
          begin
            Title := '大货单录入(国外)';
            caption := Trim(Title);
            fsyrName := trim(DataBase);
            fDParameters1 := trim(DParameters1);
            forderType := trim(DParameters2);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderNewListGW.BringToFront;
       //句柄
        mnewHandle := frmProductOrderNewListGW.Handle;
      end;
    1:  //大货单审核
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '大货单审核' then
          begin
            BringWindowToTop(frmProductOrderShenH.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmProductOrderShenH := TfrmProductOrderShenH.Create(application.MainForm);
          with frmProductOrderShenH do
          begin
            Title := '大货单审核';
            caption := Trim(Title);
            fsyrName := trim(DataBase);
            fDParameters1 := trim(DParameters1);
            forderType := trim(DParameters2);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderShenH.BringToFront;
       //句柄
        mnewHandle := frmProductOrderShenH.Handle;
      end;

    2:  //大货单管理
      begin
        bFound := FALSE;
        for i := (App.MainForm.MDIChildCount - 1) downto 0 do
        begin
          if App.MainForm.MDIChildren[i].Caption = '大货单管理' then
          begin
            BringWindowToTop(frmProductOrderGLi.Handle);
            bFound := TRUE;
            Break;
          end;
        end;
        if not bFound then
        begin
          frmProductOrderGLi := TfrmProductOrderNewList.Create(application.MainForm);
          with frmProductOrderGLi do
          begin
            Title := '大货单管理';
            caption := Trim(Title);
            fsyrName := trim(DataBase);
            fDParameters1 := trim(DParameters1);
            forderType := trim(DParameters2);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderGLi.BringToFront;
       //句柄
        mnewHandle := frmProductOrderGLi.Handle;
      end;

    -1:  //订单进度
      begin
        if frmProductOrderNewList_JD = nil then
        begin
          frmProductOrderNewList_JD := TfrmProductOrderNewList_JD.Create(application.MainForm);
          with frmProductOrderNewList_JD do
          begin
            fsyrName := trim(DataBase);
            if trim(DParameters1) <> '' then
            begin
              CustomerNoName.Text := trim(DParameters1);
              CustomerNoName.Enabled := fALSE;
            end;
            forderType := trim(DParameters2);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderNewList_JD.BringToFront;
       //句柄
        mnewHandle := frmProductOrderNewList_JD.Handle;

      end;

    3:  //生产指示单
      begin
        if frmProductOrderMoneyList = nil then
        begin
          frmProductOrderMoneyList := TfrmProductOrderMoneyList.Create(application.MainForm);
          with frmProductOrderMoneyList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderMoneyList.BringToFront;
       //句柄
        mnewHandle := frmProductOrderMoneyList.Handle;
      end;

    31:  //布票箱标签查询
      begin
        if frmProductOrderMoneyList_BPXCX = nil then
        begin
          frmProductOrderMoneyList_BPXCX := TfrmProductOrderMoneyList_BPXCX.Create(application.MainForm);
          with frmProductOrderMoneyList_BPXCX do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderMoneyList_BPXCX.BringToFront;
       //句柄
        mnewHandle := frmProductOrderMoneyList_BPXCX.Handle;
      end;

    4:  //生产指示单进度查询
      begin
        if frmProductOrderNewList_OrdJD = nil then
        begin
          frmProductOrderNewList_OrdJD := TfrmProductOrderNewList_OrdJD.Create(application.MainForm);
          with frmProductOrderNewList_OrdJD do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderNewList_OrdJD.BringToFront;
       //句柄
        mnewHandle := frmProductOrderNewList_OrdJD.Handle;

      end;

    7:  //成品出库列表
      begin
        if frmCKProductBCPOutList = nil then
        begin
          frmCKProductBCPOutList := TfrmCKProductBCPOutList.Create(application.MainForm);
          with frmCKProductBCPOutList do
          begin
            fckname := trim(DParameters3);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductBCPOutList.BringToFront;
       //句柄
        mnewHandle := frmCKProductBCPOutList.Handle;
      end;
    71:  //成品出库汇总列表
      begin
        if frmCKProductBCPOutHZ_List = nil then
        begin
          frmCKProductBCPOutHZ_List := TfrmCKProductBCPOutHZ_List.Create(application.MainForm);
          with frmCKProductBCPOutHZ_List do
          begin
            fckname := trim(DParameters3);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductBCPOutHZ_List.BringToFront;
       //句柄
        mnewHandle := frmCKProductBCPOutHZ_List.Handle;
      end;

    9:  //成品列表
      begin
        if frmCKProductBCPHCList = nil then
        begin
          frmCKProductBCPHCList := TfrmCKProductBCPHCList.Create(application.MainForm);
          with frmCKProductBCPHCList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductBCPHCList.BringToFront;
       //句柄
        mnewHandle := frmCKProductBCPHCList.Handle;

      end;
    10:  //库存列表
      begin
        if frmCKProductBCPKCList = nil then
        begin
          frmCKProductBCPKCList := TfrmCKProductBCPKCList.Create(application.MainForm);
          with frmCKProductBCPKCList do
          begin
            fckname := trim(DParameters3);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductBCPKCList.BringToFront;
       //句柄
        mnewHandle := frmCKProductBCPKCList.Handle;

      end;
    11:  //库存汇总列表
      begin
        if frmCKProductBCPKCHZList = nil then
        begin
          frmCKProductBCPKCHZList := TfrmCKProductBCPKCHZList.Create(application.MainForm);
          with frmCKProductBCPKCHZList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCKProductBCPKCHZList.BringToFront;
       //句柄
        mnewHandle := frmCKProductBCPKCHZList.Handle;

      end;
    111:  //库存汇总列表
      begin
        if frmCP_CRC = nil then
        begin
          frmCP_CRC := TfrmCP_CRC.Create(application.MainForm);
          with frmCP_CRC do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCP_CRC.BringToFront;
       //句柄
        mnewHandle := frmCP_CRC.Handle;

      end;
    114:  //库存汇总列表
      begin
        if frmCP_KC = nil then
        begin
          frmCP_KC := TfrmCP_KC.Create(application.MainForm);
          with frmCP_KC do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCP_KC.BringToFront;
       //句柄
        mnewHandle := frmCP_KC.Handle;
      end;
  end;  // end case

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

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

end.

