unit U_GetDllForm;

interface

uses
  Windows, Messages, forms, OleCtnrs, DateUtils, SysUtils, ADODB, ActiveX,
  dxCore;

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_YFCRLZ, U_YSCRLZ, U_YSHZMX, U_YFCRYCL,
  U_YSCROL, U_SKCROLJ, U_YSHZMXOLJ, U_SKCRLZ, U_YSHZMXDL, U_FKCRLZ, U_YSHZMXView,
  U_YFCRLZView, U_YFCRLZQty, U_YSCRJZC, U_YSCR_Gd, U_SKCR_Gd, U_YFZDList_MX,
  U_YSYGGJList, U_YSZDList_MX, U_YFMXlist, U_YSMXlist, U_YKHXList, U_FDINVOICE,
  U_FPINVOICE_TJ;

       /////////////////////////////////////////////////////////////////
      //         功能说明:取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 := '139.224.12.182,7781';     // 122.224.36.142,7781
  dtbase := 'aidengdata'; //jinzhicaidata
  user := 'aidengsa';
  pswd := 'rightsoft@3203';

  DConString := 'Provider=SQLOLEDB.1;Password=' + pswd + ';Persist Security Info=True;User ID=' + user + ';Initial Catalog=' + dtbase + ';Data Source=' + server;
  if trim(DataBaseStr) <> '' then
    DConString := DataBaseStr;

 // DParameters1:='无订单号';
    //DParameters1:='管理';//103
 // DParameters2:='人民币';
  // DParameters3:='项目分开';
  // DParameters4:='对方单位分开';
   //DParameters5:='开票';
  //DParameters6:='其它'; //应付款
  //DParameters7:='匹数'; //应收款
   //DCode:='test';
   //DName:='虞晓';
   //DParameters9:='支付台头';
   //DParameters8:='FactoryNo1Name';
   //DParameters10:='P_YSSK_ListTT';
  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
    1:  //应付款登记
      begin
        if frmYFCR = nil then
        begin
          frmYFCR := TfrmYFCR.Create(application.MainForm);
          with frmYFCR do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYFCR.BringToFront;
       //句柄
        mnewHandle := frmYFCR.Handle;

      end;
    221:  //员工工价对账单
      begin
        if frmYSYGGJList = nil then
        begin
          frmYSYGGJList := TfrmYSYGGJList.Create(application.MainForm);
          with frmYSYGGJList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSYGGJList.BringToFront;
       //句柄
        mnewHandle := frmYSYGGJList.Handle;

      end;
    15:  //应付款登记 坯布 染费 加工费
      begin
        if frmYFCRLZ = nil then
        begin
          frmYFCRLZ := TfrmYFCRLZ.Create(application.MainForm);
          with frmYFCRLZ do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYFCRLZ.BringToFront;
       //句柄
        mnewHandle := frmYFCRLZ.Handle;

      end;
    12:  //应付款登记  原材料仓库
      begin
        if frmYFCRYCL = nil then
        begin
          frmYFCRYCL := TfrmYFCRYCL.Create(application.MainForm);
          with frmYFCRYCL do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYFCRYCL.BringToFront;
       //句柄
        mnewHandle := frmYFCRYCL.Handle;

      end;
    11:  //应付款登记  原材料仓库
      begin
        if frmYFCRLZQty = nil then
        begin
          frmYFCRLZQty := TfrmYFCRLZQty.Create(application.MainForm);
          with frmYFCRLZQty do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYFCRLZQty.BringToFront;
       //句柄
        mnewHandle := frmYFCRLZQty.Handle;

      end;
    13:  //应付款登记 坯布 染费 加工费查询
      begin
        if frmYFCRLZView = nil then
        begin
          frmYFCRLZView := TfrmYFCRLZView.Create(application.MainForm);
          with frmYFCRLZView do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYFCRLZView.BringToFront;
       //句柄
        mnewHandle := frmYFCRLZView.Handle;

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

      end;
    21:  //付款登记(路展 台头)
      begin
        if frmFKCRLZ = nil then
        begin
          frmFKCRLZ := TfrmFKCRLZ.Create(application.MainForm);
          with frmFKCRLZ do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmFKCRLZ.BringToFront;
       //句柄
        mnewHandle := frmFKCRLZ.Handle;

      end;
    3:  //应付款付款统计
      begin
        if frmYFFKList = nil then
        begin
          frmYFFKList := TfrmYFFKList.Create(application.MainForm);
          with frmYFFKList do
          begin
            caption := Trim(Title);
            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
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCR.BringToFront;
       //句柄
        mnewHandle := frmYSCR.Handle;

      end;
    41:  //应收款登记
      begin
        if frmYSCRLZ = nil then
        begin
          frmYSCRLZ := TfrmYSCRLZ.Create(application.MainForm);
          with frmYSCRLZ do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCRLZ.BringToFront;
       //句柄
        mnewHandle := frmYSCRLZ.Handle;

      end;
    42:  //应收款登记
      begin
        if frmYSCROL = nil then
        begin
          frmYSCROL := TfrmYSCROL.Create(application.MainForm);
          with frmYSCROL do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCROL.BringToFront;
       //句柄
        mnewHandle := frmYSCROL.Handle;

      end;
    43:  //应收款登记(锦织彩)
      begin
        if frmYSCRJZC = nil then
        begin
          frmYSCRJZC := TfrmYSCRJZC.Create(application.MainForm);
          with frmYSCRJZC do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCRJZC.BringToFront;
       //句柄
        mnewHandle := frmYSCRJZC.Handle;

      end;
    44:  //应收款登记(广东)
      begin
        if frmYSCR_Gd = nil then
        begin
          frmYSCR_Gd := TfrmYSCR_Gd.Create(application.MainForm);
          with frmYSCR_Gd do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYSCR_Gd.BringToFront;
       //句柄
        mnewHandle := frmYSCR_Gd.Handle;

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

      end;
    51:  //收款登记
      begin
        if frmSKCROLJ = nil then
        begin
          frmSKCROLJ := TfrmSKCROLJ.Create(application.MainForm);
          with frmSKCROLJ do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSKCROLJ.BringToFront;
       //句柄
        mnewHandle := frmSKCROLJ.Handle;

      end;
    52:  //收款登记(路展)
      begin
        if frmSKCRLZ = nil then
        begin
          frmSKCRLZ := TfrmSKCRLZ.Create(application.MainForm);
          with frmSKCRLZ do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSKCRLZ.BringToFront;
       //句柄
        mnewHandle := frmSKCRLZ.Handle;

      end;
    54:  //收款登记(广东)
      begin
        if frmSKCR_Gd = nil then
        begin
          frmSKCR_Gd := TfrmSKCR_Gd.Create(application.MainForm);
          with frmSKCR_Gd do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmSKCR_Gd.BringToFront;
       //句柄
        mnewHandle := frmSKCR_Gd.Handle;

      end;
    6:  //应收款收款统计
      begin
        if frmYSSKList = nil then
        begin
          frmYSSKList := TfrmYSSKList.Create(application.MainForm);
          with frmYSSKList do
          begin
            caption := Trim(Title);
            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;
    7:  //订单核算统计查询
      begin
        if frmProductOrderCost = nil then
        begin
          frmProductOrderCost := TfrmProductOrderCost.Create(application.MainForm);
          with frmProductOrderCost do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmProductOrderCost.BringToFront;
       //句柄
        mnewHandle := frmProductOrderCost.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;
    81:  //销项发票登记
      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;
    9:
      begin
        if frmYKHXList = nil then
        begin
          frmYKHXList := TfrmYKHXList.Create(application.MainForm);
          with frmYKHXList do
          begin
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmYKHXList.BringToFront;
       //句柄
        mnewHandle := frmYKHXList.Handle;

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

      end;

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

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

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

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

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

      end;
    202:  //发票管理
      begin
        if frmFDINVOICE = nil then
        begin
          frmFDINVOICE := TfrmFDINVOICE.Create(application.MainForm);
          with frmFDINVOICE do
          begin
            fInvoiceFlag := '1';
            fInvoiceFlag := trim(Parameters1);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmFDINVOICE.BringToFront;
       //句柄
        mnewHandle := frmFDINVOICE.Handle;
      end;

    203:  //发票统计查询
      begin
        if frmFPInvoice_TJ = nil then
        begin
          frmFPInvoice_TJ := TfrmFPInvoice_TJ.Create(application.MainForm);
          with frmFPInvoice_TJ do
          begin
            fInvoiceFlag := '1';
            fInvoiceFlag := trim(Parameters1);
            caption := Trim(Title);
            FormStyle := mstyle;
            windowState := mstate;
            BorderStyle := mborderstyle;
           //show;
          end;
        end
        else
          frmFPInvoice_TJ.BringToFront;
       //句柄
        mnewHandle := frmFPInvoice_TJ.Handle;
      end;
  end;  // end case

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

function ConnData(): Boolean;
begin
  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
  CoInitialize(nil);
  dxUnitsLoader.Initialize;


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

end.

