private void btnSearch_Click(object sender, EventArgs e) { LogItemRequest request = new LogItemRequest(); request.StartDate = dtStart.Value; request.EndDate = dtEnd.Value; if (!string.IsNullOrEmpty(cbLogType.Text)) { request.logType = (LOGTYPE?)Enum.Parse(typeof(LOGTYPE), cbLogType.Text); } if (!string.IsNullOrEmpty(txtSiteId.Text)) { request.SiteId = txtSiteId.Text; } if (!string.IsNullOrEmpty(txtAccountId.Text)) { request.AccountId = int.Parse(txtAccountId.Text); } BaseResultInfo res = DataHelper.SearchItems(request); List <LogItem> items = res.GetResult <List <LogItem> >(); lblResult.Text = "NUMBER OF ITEMS {0}".StringFormat(items.Count); dgGrid.DataSource = items; dgGrid.Update(); }
public BaseResultInfo SearchItems(LogItemRequest request) { BaseResultInfo result = new BaseResultInfo(); SqlParameterList commandParams = new SqlParameterList(); string select = " select * from LogTBL where InsertDate > @StartDate and InsertDate < @EndDate"; commandParams.Add("@StartDate", SqlDbType.DateTime, request.StartDate); commandParams.Add("@EndDate", SqlDbType.DateTime, request.EndDate); if (request.logType.HasValue) { select += " and LogType = @LogType"; commandParams.Add("@LogType", SqlDbType.NVarChar, request.logType.ToString()); } if (!string.IsNullOrEmpty(request.SiteId)) { select += " and SiteId = @SiteId"; commandParams.Add("@SiteId", SqlDbType.NVarChar, request.SiteId); } if (request.AccountId.HasValue) { select += " and AccountId = @AccountId"; commandParams.Add("@AccountId", SqlDbType.Int, request.AccountId); } List <LogItem> items = new List <LogItem>(); try { using (SqlConnection conn = new SqlConnection(base.ConnectionString)) { using (SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, select, commandParams.ToArray())) { while (dr.Read()) { LogItem a = Serializer.DeSerialize <LogItem>(dr); items.Add(a); } result.ResultObject = items; } } } catch (Exception ex) { if (result.Error == null) { result.Error = new BaseErrorInfo(); } result.Error.BuildException(ex); } return(result); }
public override async Task <LogItemReply> GetLogItem(LogItemRequest request, ServerCallContext context) { var item = await _service.GetById(request.Id); var content = new LogContent { Id = item.Id.ToString(), Date = Timestamp.FromDateTime(item.Date), Level = item.Level, Logger = item.Logger, Message = item.Message }; return(new LogItemReply { Item = content }); }
public static BaseResultInfo SearchItems(LogItemRequest request) { LogItemRepository repository = new LogItemRepository(); return(repository.SearchItems(request)); }