1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MySqlConnector;
- using mysql_connector2.res;
- using System.Text.RegularExpressions;
- using System.Windows.Controls.Primitives;
- using System.Windows.Media.Media3D;
- using Dapper;
- namespace mysql_connector2.res
- {
- internal class DBDataProvider : IDataProvider
- {
- private string searchFilter = "";
- private Dictionary<string, object> filters = new Dictionary<string, object>();
- private string orderCondition = "";
- static string connectionString = "Server=kolei.ru; User ID=akapralov; Password=300806; Database=akapralov";
- public IEnumerable<Product> getProduct(int pageNum)
- {
- using (MySqlConnection db = new MySqlConnection(connectionString))
- {
- var builder = new SqlBuilder();
- if (orderCondition.Length > 0)
- builder.OrderBy(orderCondition);
- if (filters.Count > 0)
- {
- foreach (var item in filters)
- builder.Where(item.Key, item.Value);
- }
- var template = builder.AddTemplate(
- "SELECT * FROM ProductView /**where**/ /**orderby**/ LIMIT @pageLen OFFSET @offset",
- new { pageLen = Globals.PAGE_LEN, offset = (pageNum - 1) * Globals.PAGE_LEN }
- );
- return db.Query<Product>(
- template.RawSql,
- template.Parameters).ToList();
- }
- }
- public int getProductCount()
- {
- using (MySqlConnection db = new MySqlConnection(connectionString))
- {
- var builder = new SqlBuilder();
- if (filters.Count > 0)
- {
- foreach (var item in filters)
- {
- builder.Where(item.Key, item.Value);
- }
- }
- var template = builder.AddTemplate(
- "SELECT count(*) FROM ProductView /**where**/");
- return db.QuerySingle<int>(
- template.RawSql,
- template.Parameters);
- }
- }
- public void setOrder(string condition)
- {
- orderCondition = condition;
- }
- public void addFilter(string name, object value)
- {
- filters.Add(name, value);
- }
- public void clearFilter()
- {
- filters.Clear();
- }
- public IEnumerable<ProductType> getProductTypes()
- {
- using (MySqlConnection db = new MySqlConnection(connectionString))
- {
- return db.Query<ProductType>("SELECT * FROM ProductType");
- }
- }
- }
- }
|