/// <summary> /// 数据查询 /// </summary> /// <param name="resultMsg">执行结果</param> /// <param name="criteria">查询条件</param> /// <returns>泛型</returns> public IList<Models.SoaTest.ModelTestuser> QueryTestuserList(out string resultMsg, CriteriaTestuser criteria) { resultMsg = string.Empty; IList<ModelTestuser> list = new List<ModelTestuser>(); try { //存储过程名称 string sql = string.Format("SELECT TOP {0} * FROM [TestUser] WHERE (@uname IS NULL OR [UName] =@uname)", criteria.Count); //参数添加 IList<DBParameter> parm = new List<DBParameter>(); parm.Add(new DBParameter() { ParameterName = "uname", ParameterValue = criteria.UName, ParameterInOut = BaseDict.ParmIn, ParameterType = DbType.String }); DBHelper.DBNAME = "SqlServerDataAccess_SoaTest"; //查询执行 using (IDataReader dr = DBHelper.ExecuteReader(sql, false, parm)) { //DataReader 转换成 List list = GetModel(dr); } } catch (Exception ex) { resultMsg = string.Format("{0} {1}", BaseDict.ErrorPrefix, ex.ToString()); } return list; }
public void QueryTestuserListTest() { IFacadeTestUser facade = new Factories().InstanceTestUser(); var resultMsg =string.Empty; var criteria = new CriteriaTestuser() { Count = 100 }; var list = facade.QueryTestuserList(out resultMsg, criteria); var data = facade.QueryTable(out resultMsg, count: 20); if (list.Count > 0 && data.Tables[0].Rows.Count > 0) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }
private void button2_Click(object sender, EventArgs e) { var timeOld = DateTime.Now; var resultMsg = string.Empty; var criteria = new CriteriaTestuser(); criteria.UName = null; criteria.Count = Convert.ToInt32(textBox1.Text); OperateClass ope = new OperateClass(); ope.Method = "QueryTestuserList"; ope.Parameters = new object[] { resultMsg, criteria }; ClientProxy proxy = new ClientProxy(); var resultOpc = proxy.FacadeTestUserOperate(ope); var list = (IList<ModelTestuser>)resultOpc.ResultObj; var timeNew = DateTime.Now; var timeSpan = timeNew - timeOld; var msg = string.Format("返回数据:{0} 条,耗时 {1} 秒!", list.Count, timeSpan.TotalSeconds); MessageBox.Show(msg); }