public static ExpensesCollection GetExpensesList(List <QueryElement> list) { ExpensesCollection coll = new ExpensesCollection(); StringBuilder sb = new StringBuilder(); sb.AppendFormat(" {0} ", "select * from expenses where 1=1"); if (list.Count > 0) { MySqlParameter[] pars = new MySqlParameter[list.Count]; for (int i = 0; i < list.Count; i++) { QueryElement query = list[i]; if (query.QueryElementType == MySqlDbType.DateTime) { sb.AppendFormat("{0} {1} {2} @{3} ", query.QueryLogic, query.Queryname, query.QueryOperation, query.Queryname + i); pars[i] = new MySqlParameter("@" + query.Queryname + i, query.QueryElementType); } else { sb.AppendFormat("{0} {1} {2} @{3} ", query.QueryLogic, query.Queryname, query.QueryOperation, query.Queryname); pars[i] = new MySqlParameter("@" + query.Queryname, query.QueryElementType); } if (query.QueryOperation.Equals("like")) { pars[i].Value = "%" + query.Queryvalue + "%"; } else { pars[i].Value = query.Queryvalue; } } using (MySqlDataReader reader = MySqlDBHelper.GetReader(sb.ToString(), pars)) { while (reader.Read()) { coll.Add(new ExpensesInfo(reader)); } } } else { using (MySqlDataReader reader = MySqlDBHelper.GetReader(sb.ToString())) { while (reader.Read()) { coll.Add(new ExpensesInfo(reader)); } } } return(coll); }
private void BindExpensesListDataGrid(List <QueryElement> list) { ExpensesCollection coll = ExpensesMethods.GetExpensesList(list); this.ExpensesListDataGrid.DataSource = coll; this.ExpensesListDataGrid.DataBind(); for (int i = 0; i < coll.Count; i++) { ExpensesInfo expenses = coll[i]; CardInfo cardInfo = CardMethods.GetCardByCardNumber(expenses.CardNumber, expenses.OwnerId); string bank = StaticRescourse.DisplayBank(cardInfo.BankId); this.ExpensesListDataGrid.Items[i].Cells[4].Text = StaticRescourse.DisplaySpendType(expenses.SpendType); this.ExpensesListDataGrid.Items[i].Cells[6].Text = expenses.SpendDate.ToString("yyyy-MM-dd"); this.ExpensesListDataGrid.Items[i].Cells[7].Text = StaticRescourse.DisplaySpendMode(expenses.SpendMode); } }