在VUSERCLASS中写方法,在METHOD中写参数调用,等于参数化了。
VuserClass代码如下 :
using System;
using System.Collections;
using System.Diagnostics;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Data;
using System.Web;
using System.Reflection;
using Common;
using Proxy;
using DAT;
using ShangXin;
using ShangXin.Data;
using ShangXinInterface;
namespace LRQueryCustomer
{
///
/// Summary description for VuserClass.
///
[ClassInterface(ClassInterfaceType.AutoDual)]
public class VuserClass
{
public static string
ifCanCreatePuDongOrderWithBiz = "";
Proxy.LoginProxy
loginProxy;
Method methodLR = new
Method();
LoadRunner.LrApi lr;
public VuserClass()
{
// LoadRunner
Standard API Interface
::
DO NOT REMOVE!!!
lr = new
LoadRunner.LrApi();
}
//
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int Initialize()
{
try
{
RemotingConfiguration.Configure(@"D:\Escalade
liunx\CODE_20051020100023\Code\OAERP\ShangXin.OAERP.App\bin\Debug\App.exe.config");
lr.start_transaction("init");
lr.start_transaction("GetLoginByLoginNameAndPassword");
loginProxy =
new LoginProxy();
LoginData
loginData =
loginProxy.GetLoginByLoginNameAndPassword("administrator","");
lr.end_transaction("GetLoginByLoginNameAndPassword",lr.PASS);
Proxy.EmployeeProxy
employeeProxy = new EmployeeProxy();
CertificationInfo
CI = new CertificationInfo();
Common.CertificationInfo
ci= PersonalCertificationInfo.GetCertificationInfo();
CI.LoginName
= SXConvert.ToString(loginData.Rows[0][LoginData.LOGINNAME]);
CI.Password =
SXConvert.ToString(loginData.Rows[0][LoginData.PASSWORD]);
CI.EmployeeId
= SXConvert.ToInt32(loginData.Rows[0][LoginData.EMPLOYEEID]);
CI.EmployeeName
=
employeeProxy.GetEmployeeDataByPKID(SXConvert.ToInt32(loginData.Rows[0][LoginData.EMPLOYEEID])).Rows[0][EmployeeData.NAME].ToString();
CI.RecordCount
= SXConvert.ToInt32(loginData.Rows[0][LoginData.RECORDCOUNT]);
lr.start_transaction("GetAllAuthsByLoginId");
int loginID =
SXConvert.ToInt32(loginData.Rows[0][LoginData.PKID]);
AuthData ad =
loginProxy.GetAllAuthsByLoginId(loginID);
methodLR.SetAuth(ad,CI);
lr.end_transaction("GetAllAuthsByLoginId",lr.PASS);
lr.start_transaction("GetGroupsByLoginID");
GroupData
groupData = loginProxy.GetGroupsByLoginID(loginID);
methodLR.GetGroupAuth(groupData,CI);
lr.end_transaction("GetGroupsByLoginID",lr.PASS);
lr.start_transaction("AddToCurrentEmployee");
if
(AuthenticationManager.CheckAuthentication(CI,EnumAuthority.AuthLoginSystem))
{
methodLR.AddToCurrentEmployee(ci,CI);
lr.end_transaction("AddToCurrentEmployee",lr.PASS);
DataRow
BizDR = new
SystemParameterValueProxy().GetSystemParameterValueByParentCode(SystemParametersCode.CANCREATEPUDONGORDERWITHBIZ,Bools.TRUE).Rows[0];
ifCanCreatePuDongOrderWithBiz
= BizDR[SystemParameterValueData.OTHER1].ToString();
}
else
{
lr.end_transaction("AddToCurrentEmployee",lr.FAIL);
}
lr.end_transaction("init",lr.PASS);
}
catch(Exception ex)
{
string error
= ex.Message;
}
return
lr.PASS;
}
//
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int Actions()
{
#region
查询客户
//条件为空查询
try
{
lr.start_transaction("GetCustomerCountByCondition");
object[]
param = {methodLR.GetQueryCustomerConditions()};
Object
obj =
System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
MethodInfo
method =
obj.GetType().GetMethod("GetCustomerCountByCondition");
DataTable
dt = (DataTable)method.Invoke(obj,param);
int
count = Convert.ToInt32(dt.Rows[0][0]);
if(count>0)
lr.end_transaction("GetCustomerCountByCondition",lr.PASS);
else
lr.end_transaction("GetCustomerCountByCondition",lr.FAIL);
}
catch(Exception
ex)
{
string
error = ex.Message;
}
//综合查询
try
{
lr.start_transaction("GetQueryCustomerByAll");
object[]
param8 = {methodLR.GetQueryCustomerByAll()};
Object
obj8 =
System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
MethodInfo
method8 =
obj8.GetType().GetMethod("GetCustomerCountByCondition");
DataTable
dt8 = (DataTable)method8.Invoke(obj8,param8);
int
count8 = Convert.ToInt32(dt8.Rows[0][0]);
if(count8>0)
lr.end_transaction("GetQueryCustomerByAll",lr.PASS);
else
lr.end_transaction("GetQueryCustomerByAll",lr.FAIL);
}
catch(Exception
ex)
{
string
error = ex.Message;
}
#endregion
return
lr.PASS;
}
//
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public int Terminate()
{
// TO DO: Add
virtual user's termination routines
return
lr.PASS;
}
}
}
Method代码如下:
using System;
using Common;
using Proxy;
using DAT;
using ShangXin;
using ShangXin.Data;
using ShangXinInterface;
using System.Collections;
using System.Data;
namespace LRQueryCustomer
{
///
/// Method 的摘要说明。
///
public class Method
{
Proxy.LoginProxy loginProxy =
new LoginProxy();
public Method()
{
//
// TODO:
在此处添加构造函数逻辑
//
}
public void SetAuth(AuthData
auth,CertificationInfo ci)
{
for(int
i=0;i
{
ci.AddAuthority((EnumAuthority)(Enum.Parse(typeof(EnumAuthority),auth.Rows[i]["PKID"].ToString())));
}
}
public void
GetGroupAuth(GroupData groupData,CertificationInfo ci)
{
try
{
//判断组记录是否为空
if
(groupData.Rows.Count > 0)
{
for(int
i=0; i
{
//根据组,获取对应的权限信息,并加载到该用户的权限列表中
int
groupID =
SXConvert.ToInt32(groupData.Rows[i][GroupData.PKID]);
AuthData
Groupad = loginProxy.GetGroupAuthByGroupId(groupID);
//加载权限
if
(Groupad.Rows.Count > 0)
{
SetAuth(Groupad,ci);
ci.AddGroup(groupID);
}
int
parentGroupID = loginProxy.GetParentGroupByGroupID(groupID);
if
(parentGroupID > 0)
{
GroupData
subGroupData = loginProxy.GetGroupByPKID(parentGroupID);
//循环加载
GetGroupAuth(subGroupData,ci);
}
}
}
}
catch(Exception
exp)
{
throw
new Exception(exp.Message);
}
}
public void
AddToCurrentEmployee(CertificationInfo ci,CertificationInfo
CI)
{
//先清空当前用户的权限列表
ci.ClearAuthority();
//增加基本属性与权限列表
ci.LoginName
= CI.LoginName;
ci.Password
= CI.Password;
ci.EmployeeId
= CI.EmployeeId;
ci.EmployeeName
= CI.EmployeeName;
ci.RecordCount
= CI.RecordCount;
for(int
i=0;i
{
ci.AddAuthority((EnumAuthority)CI.Authority[i]);
}
for(int
i=0;i
{
ci.AddGroup((int)CI.Group[i]);
}
}
//按客户地址
public Hashtable
GetQueryCustomerByAddress()
{
Hashtable
conditions = new Hashtable();
int parentId
= -1;//上一级公司
int
customerTypeId = -1;//客户类型
string code =
"";//客户编码
int
salesManId = -1;//销售员
int
employeeId = 64;//
string
customerName = "";//客户名称
int
telePhinstId =
23;//话务员
string
telephone="";//客户电话
string
address="天堂区幸福大道第31450号";//客户地址
conditions.Add("PARENTID",parentId);
conditions.Add("CUSTOMERTYPEID",customerTypeId);
conditions.Add("CODE",code);
conditions.Add("SALESMANID",salesManId);
conditions.Add("EMPLOYEEID",employeeId);
conditions.Add("CUSTOMERNAME",customerName);
conditions.Add("TELEPHINSTID",telePhinstId);
conditions.Add("TELEPHONE",telephone);
conditions.Add("ADDRESS",address);
return
conditions;
}
//综合查询
public Hashtable
GetQueryCustomerByAll()
{
Hashtable
conditions = new Hashtable();
int parentId
= -1;//上一级公司
int
customerTypeId = -1;//客户类型
string code =
"005305";//客户编码
int
salesManId =-1 ;//销售员
int
employeeId = 64;//
string
customerName = "一本万利公司第120分公司";//客户名称
int
telePhinstId
=-1;//话务员
string
telephone="88888888";//客户电话
string
address="天堂区幸福大道第120号";//客户地址
conditions.Add("PARENTID",parentId);
conditions.Add("CUSTOMERTYPEID",customerTypeId);
conditions.Add("CODE",code);
conditions.Add("SALESMANID",salesManId);
conditions.Add("EMPLOYEEID",employeeId);
conditions.Add("CUSTOMERNAME",customerName);
conditions.Add("TELEPHINSTID",telePhinstId);
conditions.Add("TELEPHONE",telephone);
conditions.Add("ADDRESS",address);
return
conditions;
}
#endregion
}
}