public UCSearchRawMaterials() { InitializeComponent(); LoadData(); model = new BLL.ViewModel(); ds = BLL.RawMaterials.getRawMaterialsList(CreateWhereString(), 0, pageSize, "", 0); BindList <BLL.ViewModel>(ds.Tables[1]); //dgRawMaterials.ItemsSource = ds.Tables[1].DefaultView; this.totalRecordCount = BLL.RawMaterials.getRawMaterialsList(CreateWhereString(), 0, int.MaxValue - 1, "", 0).Tables[1].Rows.Count; btn1Previous.IsEnabled = false; btnAlPrevious.IsEnabled = false; lblRecordCount.Content = this.totalRecordCount.ToString(); if (BLL.RawMaterials.getRawMaterialsList(CreateWhereString(), 0, int.MaxValue - 1, "", 0).Tables[1].Rows.Count < pageSize) { btn1Forward.IsEnabled = false; btnAllForward.IsEnabled = false; } decimal totalAmount = 0; //foreach (DataRow item in ds.Tables[1].Rows) //{ // totalAmount += Decimal.Parse(item["Amount"].ToString()); //} lblTotalWeight.Content = totalAmount.ToString(); }
public void BindList <T>(DataTable dt) { model.Collection.Clear(); var fields = typeof(T).GetProperties(); foreach (DataRow dr in dt.Rows) { BLL.ViewModel rm = new BLL.ViewModel(); foreach (var fieldInfo in fields) { foreach (DataColumn dc in dt.Columns) { if (fieldInfo.Name == dc.ColumnName) { object value = dr[dc.ColumnName]; if (String.IsNullOrEmpty(value.ToString())) { value = String.Empty; } fieldInfo.SetValue(rm, value, null); break; } } } model.Collection.Add(rm); } model.ViewSource.GroupDescriptions.Clear(); model.ViewSource.GroupDescriptions.Add(new PropertyGroupDescription("RegistryNo")); model.ViewSource.View.Refresh(); dgRawMaterials.ItemsSource = model.ViewSource.View; }