1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
public class Mock_Database_CS : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private ObservableCollection<MyData> _MyDataList;
public ObservableCollection<MyData> MyDataList
{
get { return _MyDataList; }
set { _MyDataList = value; }
}
public Mock_Database_CS()
{
MyDataList = new ObservableCollection<MyData>();
}
//Methode pour récupérer les images
//Elles seront placées dans un caroussel sous Intuiface
//This method is only for test purpose.
//Replace it with thec ode needed to retrieve the data from your database
public void GenerateMockData()
{
NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=openpg;Password=openpgpwd;Database=test;");
conn.Open();
NpgsqlDataAdapter myDataAdapter = new NpgsqlDataAdapter("SELECT * FROM product_product;", conn);
DataSet ds = new DataSet();
myDataAdapter.Fill(ds, "product_product");
foreach (DataRow dr in ds.Tables["product_product"].Rows)
{
MyData d = new MyData()
{
Id = dr[0].ToString(),
defaultCode = dr[1].ToString(),
nameTemplate = dr[2].ToString(),
//listPrice = dr[3].ToString(),
//supplyMethod = dr[8].ToString(),
};
MyDataList.Add(d);
}
conn.Close();
}
public void search(string productName)
{
using (NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=openpg;Password=openpgpwd;Database=test;"))
{
conn.Open();
NpgsqlCommand command = new NpgsqlCommand("SELECT * FROM product_product WHERE default_code = :productName;", conn);
command.Parameters.Add(new NpgsqlParameter("productName", NpgsqlDbType.Text));
command.Parameters[0].Value = productName;
using (NpgsqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
MyDataList.Add(new MyData
{
Id = reader.GetString(0),
defaultCode = reader.GetString(9),
nameTemplate = reader.GetString(10)
});
}
}
}
}
public void ClearList()
{
MyDataList.Clear();
}
} |
Partager