unit U_GetDllForm;

interface

uses
  Windows, Messages, forms, OleCtnrs, DateUtils, SysUtils, ADODB, 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_Fun, U_YFCR, U_FKCR, U_YFFKList, U_YSCR, U_SKCR, U_YSSKList,
  U_ProductOrderCost, U_YFFP, U_YSFP, U_YFCR_SH, U_FKCR_SH, U_YFCRLZ, U_YSCRLZ,
  U_YSHZMX, U_YFCRYCL, U_YSCROL, U_YSCRPB_GZ, U_SKCROLJ, U_YSHZMXOLJ, U_YSCR_SH,
  U_YSCRPB_XN, U_YSFP_WX, U_SKCRLZ, U_YSHZMXDL, U_FKCRLZ, U_YSCRPB_ZHYH,
  U_YSHZMXView, U_YFCRLZView, U_YFCRLZQty, U_SKCR_SH, U_SKCR_YF, U_SKCR_CX,
  U_YSFP_WXCI, U_YSCRJZC, U_YSCR_Gd, U_SKCR_Gd, U_YFZDList_MX, U_YSZDList_MX,
  U_YFMXlist, U_YSMXlist, U_FKCR_GD, U_YFCR_GD, U_YSCRPB, U_YSCRPB_QT, U_YSCRKP,
  U_YSCR_PBSH, U_YSFP_WXSH, U_CaiWuHuilV, U_YSCRPB_QTHZ, U_YSFP_FHDJ,
  U_YSCRPB_QTTJ, U_SKCR_YWCX;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取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 := 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 := '47.100.233.156,7781';
//   server:='.';
  dtbase := 'chuangpingData';
  user := 'sa';
//   pswd:='rightsoft';
  pswd := 'rightsoft@123';
  DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
//  DConString := DataBaseStr;
   //DParameters1:='';
   //DParameters1:='管理';//103
   //DParameters2:='';
//   DParameters1:='高权限';
   //DataBase:='高权限';
   //DataBase:='1';
   //DParameters2:='成品';
   //DCode:='test';
   //DName:='今墨';
  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;
   ////////////////////
  { GetSWLDZ('192.168.1.246');
   if IpCall<>0 then
   begin
     Result:=0;
     Application.MessageBox('！！网络不通！！','提示',0);
     Exit;
   end;
   if Trim(IpWLDZStr)<>'D4:AE:52:BE:9F:02'  then
   begin
     Result:=0;
     Application.MessageBox('！！数据库连接失败！！','提示',0);
     Exit;
   end; }
   /////////////////////
   //调用子模块窗口
  case FormID of
    0:  //汇率信息管理
      begin
        if frmCaiWuHuiLV = nil then
        begin
          frmCaiWuHuiLV := TfrmCaiWuHuiLV.Create(application.MainForm);
          with frmCaiWuHuiLV do
          begin
            caption := Trim(Title);
            fmanage := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmCaiWuHuiLV.BringToFront;
       //句柄
        mnewHandle := frmCaiWuHuiLV.Handle;

      end;

    1:  //应付款登记
      begin
        if frmYFCR = nil then
        begin
          frmYFCR := TfrmYFCR.Create(application.MainForm);
          with frmYFCR do
          begin
            caption := Trim(Title);
            fmanage := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYFCR.BringToFront;
       //句柄
        mnewHandle := frmYFCR.Handle;

      end;

    100:  //应付款审核
      begin
        if frmYFCR_SH = nil then
        begin
          frmYFCR_SH := TfrmYFCR_SH.Create(application.MainForm);
          with frmYFCR_SH do
          begin
            caption := Trim(Title);
            fmanage := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYFCR_SH.BringToFront;
       //句柄
        mnewHandle := frmYFCR_SH.Handle;

      end;

    2:  //付款登记
      begin
        if frmFKCR = nil then
        begin
          frmFKCR := TfrmFKCR.Create(application.MainForm);
          with frmFKCR do
          begin
            caption := Trim(Title);
            fmanage := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmFKCR.BringToFront;
       //句柄
        mnewHandle := frmFKCR.Handle;

      end;

    200:  //付款审核
      begin
        if frmFKCR_SH = nil then
        begin
          frmFKCR_SH := TfrmFKCR_SH.Create(application.MainForm);
          with frmFKCR_SH do
          begin
            caption := Trim(Title);
            fmanage := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmFKCR_SH.BringToFront;
       //句柄
        mnewHandle := frmFKCR_SH.Handle;

      end;

    3:  //应付款付款统计
      begin
        if frmYFFKList = nil then
        begin
          frmYFFKList := TfrmYFFKList.Create(application.MainForm);
          with frmYFFKList do
          begin
            caption := Trim(Title);
           //fDParameters1:=trim('0');
            fDParameters1 := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYFFKList.BringToFront;
       //句柄
        mnewHandle := frmYFFKList.Handle;

      end;
    31:  //应付款明细账单
      begin
        if frmYFZDList_MX = nil then
        begin
          frmYFZDList_MX := TfrmYFZDList_MX.Create(application.MainForm);
          with frmYFZDList_MX do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYFZDList_MX.BringToFront;
       //句柄
        mnewHandle := frmYFZDList_MX.Handle;

      end;
    4:  //应收款登记(成品)
      begin
        if frmYSCR = nil then
        begin
          frmYSCR := TfrmYSCR.Create(application.MainForm);
          with frmYSCR do
          begin
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCR.BringToFront;
       //句柄
        mnewHandle := frmYSCR.Handle;

      end;

    43:  //费用支出登记
      begin
        if frmYSCRPB_QT = nil then
        begin
          frmYSCRPB_QT := TfrmYSCRPB_QT.Create(application.MainForm);
          with frmYSCRPB_QT do
          begin
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCRPB_QT.BringToFront;
       //句柄
        mnewHandle := frmYSCRPB_QT.Handle;

      end;

    430:  //财务费用支出汇总
      begin
        if frmYSCRPB_QTHZ = nil then
        begin
          frmYSCRPB_QTHZ := TfrmYSCRPB_QTHZ.Create(application.MainForm);
          with frmYSCRPB_QTHZ do
          begin
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCRPB_QTHZ.BringToFront;
       //句柄
        mnewHandle := frmYSCRPB_QTHZ.Handle;

      end;

    431:  //工资发放登记
      begin
        if frmYSCRPB_GZ = nil then
        begin
          frmYSCRPB_GZ := TfrmYSCRPB_GZ.Create(application.MainForm);
          with frmYSCRPB_GZ do
          begin
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCRPB_GZ.BringToFront;
       //句柄
        mnewHandle := frmYSCRPB_GZ.Handle;

      end;

     {432:  //银行收支登记
     begin
       if frmYSCRPB_ZHYH=nil then
       begin
         frmYSCRPB_ZHYH:= TfrmYSCRPB_ZHYH.Create(application.MainForm);
         with frmYSCRPB_ZHYH do
         begin
           fflag:=strtointdef(trim(DataBase),0);
           fmanage:=trim(DParameters1);
           caption:=Trim(Title);
           FormStyle := mstyle ;
           windowState := mstate ;
           BorderStyle := mborderstyle;
           //show;
         end;
       end
       else
         frmYSCRPB_ZHYH.BringToFront;
       //句柄
       mNewHandle:=frmYSCRPB_ZHYH.Handle;

     end ; }

    433:  //费用支出统计查询
      begin
        if frmYSCRPB_QTTJ = nil then
        begin
          frmYSCRPB_QTTJ := TfrmYSCRPB_QTTJ.Create(application.MainForm);
          with frmYSCRPB_QTTJ do
          begin
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCRPB_QTTJ.BringToFront;
       //句柄
        mnewHandle := frmYSCRPB_QTTJ.Handle;

      end;

    44:  //应收款开票管理
      begin
        if frmYSCRKP = nil then
        begin
          frmYSCRKP := TfrmYSCRKP.Create(application.MainForm);
          with frmYSCRKP do
          begin
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCRKP.BringToFront;
       //句柄
        mnewHandle := frmYSCRKP.Handle;

      end;

    400:  //应收款成品审核
      begin
        if frmYSCR_SH = nil then
        begin
          frmYSCR_SH := TfrmYSCR_SH.Create(application.MainForm);
          with frmYSCR_SH do
          begin
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCR_SH.BringToFront;
       //句柄
        mnewHandle := frmYSCR_SH.Handle;

      end;

    5:  //收款登记
      begin
        if frmSKCR = nil then
        begin
          frmSKCR := TfrmSKCR.Create(application.MainForm);
          with frmSKCR do
          begin
            caption := Trim(Title);
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSKCR.BringToFront;
       //句柄
        mnewHandle := frmSKCR.Handle;

      end;

    50:  //收款查询
      begin
        if frmSKCR_YWCX = nil then
        begin
          frmSKCR_YWCX := TfrmSKCR_YWCX.Create(application.MainForm);
          with frmSKCR_YWCX do
          begin
            caption := Trim(Title);
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSKCR_YWCX.BringToFront;
       //句柄
        mnewHandle := frmSKCR_YWCX.Handle;

      end;

    51:  //订单核算查询表
      begin
        if frmSKCR_YF = nil then
        begin
          frmSKCR_YF := TfrmSKCR_YF.Create(application.MainForm);
          with frmSKCR_YF do
          begin
            caption := Trim(Title);
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSKCR_YF.BringToFront;
       //句柄
        mnewHandle := frmSKCR_YF.Handle;

      end;

    500:  //收款审核
      begin
        if frmSKCR_SH = nil then
        begin
          frmSKCR_SH := TfrmSKCR_SH.Create(application.MainForm);
          with frmSKCR_SH do
          begin
            caption := Trim(Title);
            fflag := strtointdef(trim(DataBase), 0);
            fmanage := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSKCR_SH.BringToFront;
       //句柄
        mnewHandle := frmSKCR_SH.Handle;

      end;
    6:  //应收款收款统计
      begin
        if frmYSSKList = nil then
        begin
          frmYSSKList := TfrmYSSKList.Create(application.MainForm);
          with frmYSSKList do
          begin
            caption := Trim(Title);
            fDParameters1 := trim(DParameters1);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSSKList.BringToFront;
       //句柄
        mnewHandle := frmYSSKList.Handle;

      end;
    61:  //应收款对账明细
      begin
        if frmYSZDList_MX = nil then
        begin
          frmYSZDList_MX := TfrmYSZDList_MX.Create(application.MainForm);
          with frmYSZDList_MX do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSZDList_MX.BringToFront;
       //句柄
        mnewHandle := frmYSZDList_MX.Handle;

      end;

    8:  //进项发票登记
      begin
        if frmYFFP = nil then
        begin
          frmYFFP := TfrmYFFP.Create(application.MainForm);
          with frmYFFP do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYFFP.BringToFront;
       //句柄
        mnewHandle := frmYFFP.Handle;

      end;
    9:  //销项发票登记
      begin
        if frmYSFP = nil then
        begin
          frmYSFP := TfrmYSFP.Create(application.MainForm);
          with frmYSFP do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSFP.BringToFront;
       //句柄
        mnewHandle := frmYSFP.Handle;

      end;
  end;  // end case

  Result := mnewHandle;
  NewDllApp := Application;
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');
  finally
    IniFile.Free;
  end;
  if not Assigned(DataLink_YSYF) then
    DataLink_YSYF := TDataLink_YSYF.Create(Application);
  try
    with DataLink_YSYF.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_YSYF.Free;
  Application := OldDllApp;

end.

