/// <inheritdoc /> public object GetValue(DataBinding binding) { if (binding == null) throw new ArgumentNullException("binding"); return GetValueImpl(binding); }
public void HandlesDegenerateCaseWithMoreThanOneProviderButOneIsEmpty() { DataBinding[][] bindingsPerProvider = new DataBinding[][] { new DataBinding[] { new DataBinding(0, null) }, new DataBinding[] { new DataBinding(0, null) }, }; IDataProvider[] providers = new IDataProvider[] { Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>() }; IDataItem[][] itemsPerProvider = new IDataItem[][] { new IDataItem[] { new ScalarDataItem<int>(1, null, true), new ScalarDataItem<int>(2, null, false) }, new IDataItem[0] }; using (Mocks.Record()) { SetupResult.For(providers[0].GetItems(bindingsPerProvider[0], true)).Return(itemsPerProvider[0]); SetupResult.For(providers[1].GetItems(bindingsPerProvider[1], true)).Return(itemsPerProvider[1]); } using (Mocks.Playback()) { List<IList<IDataItem>> items = new List<IList<IDataItem>>(PairwiseJoinStrategy.Instance.Join(providers, bindingsPerProvider, true)); Assert.Count(0, items); } }
/// <summary> /// Creates a bound data accessor. /// </summary> /// <param name="binding">The binding to query.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="binding"/> is null.</exception> public BoundDataAccessor(DataBinding binding) { if (binding == null) throw new ArgumentNullException("binding"); this.binding = binding; }
public void HandlesDegenerateCaseWithOneProvider() { DataBinding[] bindings = new DataBinding[] { new DataBinding(0, null) }; IDataProvider[] providers = new IDataProvider[] { Mocks.StrictMock<IDataProvider>() }; using (Mocks.Record()) { Expect.Call(providers[0].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem<int>(1, null, true), new ScalarDataItem<int>(2, null, false), new ScalarDataItem<int>(3, null, true) }); } using (Mocks.Playback()) { List<IDataItem> items = new List<IDataItem>(IntersectionMergeStrategy.Instance.Merge(providers, bindings, true)); Assert.Count(3, items); Assert.AreEqual(1, items[0].GetValue(bindings[0])); Assert.IsTrue(items[0].IsDynamic); Assert.AreEqual(2, items[1].GetValue(bindings[0])); Assert.IsFalse(items[1].IsDynamic); Assert.AreEqual(3, items[2].GetValue(bindings[0])); Assert.IsTrue(items[2].IsDynamic); } }
public void ConstructorWithPathAndIndex() { DataBinding binding = new DataBinding(42, "path"); Assert.AreEqual("path", binding.Path); Assert.AreEqual(42, binding.Index); }
/// <inheritdoc /> public bool CanBind(DataBinding binding) { if (binding == null) throw new ArgumentNullException("binding"); return CanBindImpl(binding); }
public void AccessorObtainsAValueFromTheRow() { DataBinding binding = new DataBinding(0, null); ScalarDataBinder binder = new ScalarDataBinder(binding, "name"); IDataSourceResolver resolver = Mocks.StrictMock<IDataSourceResolver>(); DataBindingContext context = new DataBindingContext(new NullConverter()); DataSource source = new DataSource("name"); source.AddDataSet(new ItemSequenceDataSet(new IDataItem[] { new ScalarDataItem<int>(42, null, false), new ScalarDataItem<string>("42", null, false) }, 1)); using (Mocks.Record()) { Expect.Call(resolver.ResolveDataSource("name")).Return(source); } using (Mocks.Playback()) { IDataAccessor accessor = binder.Register(context, resolver); Assert.IsTrue(context.DataSets.Contains(source), "The data sets list should contain the source that was resolved during binder registration."); List<IDataItem> items = new List<IDataItem>(context.GetItems(true)); Assert.Count(2, items); Assert.AreEqual(42, accessor.GetValue(items[0])); Assert.AreEqual("42", accessor.GetValue(items[1])); } }
public void JoinsItemsCombinatorially() { DataBinding[][] bindingsPerProvider = new DataBinding[][] { new DataBinding[] { new DataBinding(0, null) }, new DataBinding[] { }, new DataBinding[] { new DataBinding(0, null) }, }; IDataProvider[] providers = new IDataProvider[] { Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>() }; IDataItem[][] itemsPerProvider = new IDataItem[][] { new IDataItem[] { new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(2, null, true) }, new IDataItem[] { new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(2, null, false), new ScalarDataItem<int>(3, null, false) }, new IDataItem[] { new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(2, null, true) } }; using (Mocks.Record()) { Expect.Call(providers[0].GetItems(bindingsPerProvider[0], true)).Return(itemsPerProvider[0]); Expect.Call(providers[1].GetItems(bindingsPerProvider[1], true)).Return(itemsPerProvider[1]); Expect.Call(providers[2].GetItems(bindingsPerProvider[2], true)).Return(itemsPerProvider[2]); } using (Mocks.Playback()) { List<IList<IDataItem>> items = new List<IList<IDataItem>>(CombinatorialJoinStrategy.Instance.Join(providers, bindingsPerProvider, true)); Assert.Count(12, items); int index = 0; for (int i = 0; i < itemsPerProvider[0].Length; i++) { for (int j = 0; j < itemsPerProvider[1].Length; j++) { for (int k = 0; k < itemsPerProvider[2].Length; k++) { Assert.AreSame(itemsPerProvider[0][i], items[index][0]); Assert.AreSame(itemsPerProvider[1][j], items[index][1]); Assert.AreSame(itemsPerProvider[2][k], items[index][2]); index += 1; } } } } }
public void HandlesDegenerateCaseWithZeroProviders() { DataBinding[][] bindingsPerProvider = new DataBinding[0][]; IDataProvider[] providers = new IDataProvider[0]; List<IList<IDataItem>> items = new List<IList<IDataItem>>(PairwiseJoinStrategy.Instance.Join(providers, bindingsPerProvider, true)); Assert.Count(0, items); }
public void KeepsOnlyIntersectionIncludingRightNumberOfDuplicatesAndExcludesBadItems() { DataBinding[] bindings = new DataBinding[] { new DataBinding(0, null) }; IDataProvider[] providers = new IDataProvider[] { Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>() }; using (Mocks.Record()) { IDataItem badItem = Mocks.StrictMock<IDataItem>(); Expect.Call(badItem.GetValue(bindings[0])).Throw(new InvalidOperationException("Test exception")); Expect.Call(providers[0].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(2, null, true), new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(3, null, false), new ScalarDataItem<int>(6, null, false), }); Expect.Call(providers[1].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(1, null, false), badItem, new ScalarDataItem<int>(2, null, true), new ScalarDataItem<int>(6, null, false), new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(4, null, false), }); Expect.Call(providers[2].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(5, null, false), new ScalarDataItem<int>(3, null, false), new ScalarDataItem<int>(2, null, true) }); } using (Mocks.Playback()) { List<IDataItem> items = new List<IDataItem>(IntersectionMergeStrategy.Instance.Merge(providers, bindings, true)); Assert.Count(3, items); Assert.AreEqual(1, items[0].GetValue(bindings[0])); Assert.IsFalse(items[0].IsDynamic); Assert.AreEqual(1, items[1].GetValue(bindings[0])); Assert.IsFalse(items[1].IsDynamic); Assert.AreEqual(2, items[2].GetValue(bindings[0])); Assert.IsTrue(items[2].IsDynamic); } }
/// <summary> /// Creates a scalar data binder. /// </summary> /// <param name="binding">The data binding.</param> /// <param name="sourceName">The data source name to query, or an empty string if it is anonymous.</param> public ScalarDataBinder(DataBinding binding, string sourceName) { if (binding == null) throw new ArgumentNullException("binding"); if (sourceName == null) throw new ArgumentNullException("sourceName"); this.binding = binding; this.sourceName = sourceName; }
public void ReplaceIndexCreatesANewInstanceWithTheNewIndex() { DataBinding oldBinding = new DataBinding(42, "path"); DataBinding newBinding = oldBinding.ReplaceIndex(23); Assert.AreNotSame(oldBinding, newBinding); Assert.AreEqual("path", newBinding.Path); Assert.AreEqual(23, newBinding.Index); }
public void HandlesDegenerateCaseWithZeroProviders() { DataBinding[] bindings = new DataBinding[] { new DataBinding(0, null) }; IDataProvider[] providers = new IDataProvider[0]; List<IDataItem> items = new List<IDataItem>(IntersectionMergeStrategy.Instance.Merge(providers, bindings, true)); Assert.Count(0, items); }
/// <inheritdoc /> protected override bool CanBindImpl(DataBinding binding) { foreach (IDataSet dataSet in DataSets) { if (!dataSet.CanBind(binding)) return false; } return true; }
public void JoinsItemsSequentiallyAndPadsWithNullsUntilExhausted() { DataBinding[][] bindingsPerProvider = new DataBinding[][] { new DataBinding[] { new DataBinding(0, null) }, new DataBinding[] { }, new DataBinding[] { new DataBinding(0, null) }, }; IDataProvider[] providers = new IDataProvider[] { Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>() }; IDataItem[][] itemsPerProvider = new IDataItem[][] { new IDataItem[] { new ScalarDataItem<int>(1, null, true), new ScalarDataItem<int>(2, null, false) }, new IDataItem[] { }, new IDataItem[] { new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(2, null, false), new ScalarDataItem<int>(3, null, false) } }; using (Mocks.Record()) { Expect.Call(providers[0].GetItems(bindingsPerProvider[0], true)).Return(itemsPerProvider[0]); Expect.Call(providers[1].GetItems(bindingsPerProvider[1], true)).Return(itemsPerProvider[1]); Expect.Call(providers[2].GetItems(bindingsPerProvider[2], true)).Return(itemsPerProvider[2]); } using (Mocks.Playback()) { List<IList<IDataItem>> items = new List<IList<IDataItem>>(SequentialJoinStrategy.Instance.Join(providers, bindingsPerProvider, true)); Assert.Count(3, items); Assert.AreSame(itemsPerProvider[0][0], items[0][0]); Assert.AreSame(NullDataItem.Instance, items[0][1]); Assert.AreSame(itemsPerProvider[2][0], items[0][2]); Assert.AreSame(itemsPerProvider[0][1], items[1][0]); Assert.AreSame(NullDataItem.Instance, items[1][1]); Assert.AreSame(itemsPerProvider[2][1], items[1][2]); Assert.AreSame(NullDataItem.Instance, items[2][0]); Assert.AreSame(NullDataItem.Instance, items[2][1]); Assert.AreSame(itemsPerProvider[2][2], items[2][2]); } }
public void GetValueCallsRowsGetValueWithTheBinding() { IDataItem item = Mocks.StrictMock<IDataItem>(); DataBinding binding = new DataBinding(0, null); using (Mocks.Record()) { Expect.Call(item.GetValue(binding)).Return(42); } using (Mocks.Playback()) { BoundDataAccessor accessor = new BoundDataAccessor(binding); Assert.AreEqual(42, accessor.GetValue(item)); } }
public void EliminatesDuplicatesAndIncludesBadItems() { DataBinding[] bindings = new DataBinding[] { new DataBinding(0, null) }; IDataProvider[] providers = new IDataProvider[] { Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>() }; using (Mocks.Record()) { IDataItem badItem = Mocks.StrictMock<IDataItem>(); Expect.Call(badItem.GetValue(bindings[0])).Repeat.Twice().Throw(new InvalidOperationException("Test exception")); Expect.Call(providers[0].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem<int>(1, null, true), new ScalarDataItem<int>(1, null, true), new ScalarDataItem<int>(2, null, false), }); Expect.Call(providers[1].GetItems(bindings, true)).Return(EmptyArray<IDataItem>.Instance); Expect.Call(providers[2].GetItems(bindings, true)).Return(new IDataItem[] { badItem, new ScalarDataItem<int>(3, null, true), new ScalarDataItem<int>(2, null, true) }); } using (Mocks.Playback()) { List<IDataItem> items = new List<IDataItem>(UnionMergeStrategy.Instance.Merge(providers, bindings, true)); Assert.Count(4, items); Assert.AreEqual(1, items[0].GetValue(bindings[0])); Assert.IsTrue(items[0].IsDynamic); Assert.AreEqual(2, items[1].GetValue(bindings[0])); Assert.IsFalse(items[1].IsDynamic); Assert.Throws<InvalidOperationException>(delegate { items[2].GetValue(bindings[0]); }); Assert.AreEqual(3, items[3].GetValue(bindings[0])); Assert.IsTrue(items[3].IsDynamic); } }
private void RemoveCommandHandler(DataBinding binding) { var view = binding.View; if (view == null) return; string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed default: if (view is AbsSpinner) ((AdapterView)view).ItemSelected -= AdapterView_ItemSelected; else if (view is AdapterView) ((AdapterView)view).ItemClick -= AdapterView_ItemClick; else { var command = (RelayCommand)binding.ViewModelPropertyInfo.GetValue(viewModel); if (command != null) command.CanExecuteChanged -= binding.Command_CanExecuteChanged; view.Click -= View_Click; } break; } }
/// <summary> /// hàm thực hiện việc khởi tạo thông tin của Form /// </summary> private void InitData() { m_KhoaLinh = THU_VIEN_CHUNG.Laydanhmuckhoa("NOI", 0); if (KIEU_THUOC_VT == "THUOC") { m_dtKhoXuat = CommonLoadDuoc.LAYTHONGTIN_KHOTHUOC_LE_NOITRU(); m_dtKhonhan = CommonLoadDuoc.LAYTHONGTIN_KHOTHUOC_AO(true); } else { m_dtKhoXuat = CommonLoadDuoc.LAYTHONGTIN_KHOVATTU_CHAN(); m_dtKhonhan = CommonLoadDuoc.LAYTHONGTIN_KHOVATTU_AO(true); } DataBinding.BindDataCombobox(cboKhoxuat, m_dtKhoXuat, TDmucKho.Columns.IdKho, TDmucKho.Columns.TenKho, "---Kho xuất---", true); DataBinding.BindDataCombobox(cboKhoaLinh, m_KhoaLinh, DmucKhoaphong.Columns.IdKhoaphong, DmucKhoaphong.Columns.TenKhoaphong, "---Khoa lĩnh---", true); b_Hasloaded = true; }
public static object Deserialize(BinaryReader binaryReader, ISurrogateContext context) { var dataBinding = new DataBinding(); dataBinding.SetDataSourceReference(context.Dependencies[0]); //DataSourceProperty dataBinding.DataSourceProperty = binaryReader.ReadString(); //Object dataBinding.ObjReference = context.Dependencies[1] as IStateObject; //Next var next = binaryReader.ReadString(); dataBinding.NextBinding = next == "" ? null : next; //Previous var previous = binaryReader.ReadString(); dataBinding.PreviousBinding = previous == "" ? null : previous; //ObjectProperty dataBinding.ObjProperty = binaryReader.ReadString(); return(dataBinding); }
/// <summary> /// Issue select statement /// セレクトSQL文発行 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public List <T> GetDataList <T>() { DataTable dataTable = new DataTable(); try { this.CreateSelectSql(); SqliteDatabase sqliteDataBase = new SqliteDatabase(CONNECT_TABLE); dataTable = sqliteDataBase.ExecuteQuery(this.ExecutetSql.ToString()); } catch (SqliteException ex) { Debug.Log(ex.Message + " " + this.ExecutetSql.ToString()); } finally { this.Init(this.BaseType); } return(DataBinding <T> .DataTableToObjectList(dataTable)); }
/// <include file='doc\HyperLinkDataBindingHandler.uex' path='docs/doc[@for="HyperLinkDataBindingHandler.DataBindControl"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override void DataBindControl(IDesignerHost designerHost, Control control) { DataBindingCollection bindings = ((IDataBindingsAccessor)control).DataBindings; DataBinding textBinding = bindings["Text"]; DataBinding urlBinding = bindings["NavigateUrl"]; if ((textBinding != null) || (urlBinding != null)) { HyperLink hyperLink = (HyperLink)control; if (textBinding != null) { hyperLink.Text = SR.GetString(SR.Sample_Databound_Text); } if (urlBinding != null) { // any value will do, we just need an href to be rendered hyperLink.NavigateUrl = "url"; } } }
/// <summary> /// Constructs the column definition with the configuration /// </summary> /// <param name="name">The column name</param> /// <param name="valueBinding">The row value binding</param> /// <param name="totalAggregator">The total aggregator (optional)</param> /// <param name="totalFormat">The total format (optional)</param> public TableColumnDefinition ( string name, DataBinding valueBinding, IAggregateFunction totalAggregator = null, string totalFormat = null ) { Validate.IsNotEmpty(name); Validate.IsNotNull(valueBinding); this.ColumnId = Guid.NewGuid(); this.Name = name; this.Title = name; this.ValueBinding = valueBinding; if (totalAggregator != null) { DefineTotal(totalAggregator, totalFormat); } }
[Test] public void ChangeTest() { DataBindingCollection a = new DataBindingCollection(); a.Changed += delegate { changed = true; }; DataBinding b = new DataBinding("a", typeof(DataBindingCollectionTest), "b"); a.Add(b); Assert.AreEqual(true, changed, "DB1"); changed = false; a.Clear(); Assert.AreEqual(false, changed, "DB2"); a.Remove(b); Assert.AreEqual(true, changed, "DB3"); }
protected string GetDataBindingLabel(DataBinding binding) { if (binding.dataContext == DataBinding.DataContext.Constant) { plyVar constant = binding.constant; if (((constant != null) ? constant.GetValue() : null) != null) { return(binding.constant.GetValue().ToString()); } return("null"); } if (binding.dataContext == DataBinding.DataContext.GlobalProperty) { if (binding.member == null) { return("null"); } return(BloxMemberInfo.SimpleMemberPath(binding.member)); } return("-select-"); }
private void frm_baocao_thuockedon_theobacsy_Load(object sender, EventArgs e) { try { baocaO_TIEUDE1.Init(); AutocompleteThuoc(); DataBinding.BindDataCombobox(cboDoiTuong, THU_VIEN_CHUNG.LaydanhsachDoituongKcb(), DmucDoituongkcb.Columns.IdDoituongKcb, DmucDoituongkcb.Columns.TenDoituongKcb, "---Chọn đối tượng---", false); DataBinding.BindDataCombobox(cboStock, CommonLoadDuoc.LAYTHONGTIN_KHOTHUOC_TATCA(), TDmucKho.Columns.IdKho, TDmucKho.Columns.TenKho, "---Chọn kho ---", false); DataTable dtBacsi = THU_VIEN_CHUNG.LaydanhsachBacsi(-1, -1); cboBacSyChiDinh.DropDownDataSource = dtBacsi; cboBacSyChiDinh.DropDownDataMember = DmucNhanvien.Columns.IdNhanvien; cboBacSyChiDinh.DropDownDisplayMember = DmucNhanvien.Columns.TenNhanvien; cboBacSyChiDinh.DropDownValueMember = DmucNhanvien.Columns.IdNhanvien; } catch { } }
private void LoadCombobox() { try { SqlQuery sqlQuery = new Select(TTestTypeList.Columns.TestTypeId, TTestTypeList.Columns.TestTypeName).From( TTestTypeList.Schema); DataTable testType = sqlQuery.ExecuteDataSet().Tables[0]; DataBinding.BindDataCombox(cboTestType, testType, TTestTypeList.Columns.TestTypeId, TTestTypeList.Columns.TestTypeName, "-----Chọn loại xét nghiệm-----"); DataTable barcodeType = new DataTable(); barcodeType.Columns.Add("BarcodeTypeId"); barcodeType.Columns.Add("BarcodeType"); for (int i = 0; i < 2; i++) { var rows = barcodeType.NewRow(); switch (i) { case 0: rows["BarcodeTypeId"] = 0; rows["BarcodeType"] = "Không barcode"; break; case 1: rows["BarcodeTypeId"] = 1; rows["BarcodeType"] = "Có barcode"; break; } barcodeType.Rows.Add(rows); } DataBinding.BindDataCombox(cboBarcodeType, barcodeType, "BarcodeTypeId", "BarcodeType", "-----Chọn loại barcode-----"); cboBarcodeType.SelectedIndex = 1; } catch (Exception ex) { Utility.ShowMsg(ex.Message); } }
private void AddCommandHandler(DataBinding binding) { if (binding.ViewProperty == null || binding.ViewProperty.ContainingObject == null) return; var view = binding.ViewProperty.ContainingObject; string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed #if __DIALOG__ case "MonoTouch.Dialog.StringElement": case "MonoTouch.Dialog.StyledStringElement": ((StringElement)view).Tapped += () => ExecuteCommand(binding); break; #endif case "MonoTouch.UIKit.UIButton": { var button = (UIButton)view; button.TouchUpInside += HandleTouchUpInside; var command = (RelayCommand)binding.ViewModelPropertyInfo.GetValue(viewModel); if (command != null) { command.CanExecuteChanged += binding.Command_CanExecuteChanged; button.Enabled = command.IsEnabled; } } break; case "MonoTouch.UIKit.UIBarButtonItem": { var button = (UIBarButtonItem)view; button.Clicked += (s, e) => ExecuteCommand(binding); var command = (RelayCommand)binding.ViewModelPropertyInfo.GetValue(viewModel); if (command != null) { command.CanExecuteChanged += binding.Command_CanExecuteChanged; button.Enabled = command.IsEnabled; } } break; } }
public void CombinesItemsIntoASingleSequence() { DataBinding[] bindings = new DataBinding[] { new DataBinding(0, null) }; IDataProvider[] providers = new IDataProvider[] { Mocks.StrictMock <IDataProvider>(), Mocks.StrictMock <IDataProvider>(), Mocks.StrictMock <IDataProvider>() }; using (Mocks.Record()) { Expect.Call(providers[0].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem <int>(1, null, false), new ScalarDataItem <int>(2, null, false), }); Expect.Call(providers[1].GetItems(bindings, true)).Return(EmptyArray <IDataItem> .Instance); Expect.Call(providers[2].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem <int>(3, null, true), }); } using (Mocks.Playback()) { List <IDataItem> items = new List <IDataItem>(ConcatenationMergeStrategy.Instance.Merge(providers, bindings, true)); Assert.Count(3, items); Assert.AreEqual(1, items[0].GetValue(bindings[0])); Assert.IsFalse(items[0].IsDynamic); Assert.AreEqual(2, items[1].GetValue(bindings[0])); Assert.IsFalse(items[1].IsDynamic); Assert.AreEqual(3, items[2].GetValue(bindings[0])); Assert.IsTrue(items[2].IsDynamic); } }
public void CombinesItemsIntoASingleSequence() { DataBinding[] bindings = new DataBinding[] { new DataBinding(0, null) }; IDataProvider[] providers = new IDataProvider[] { Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>(), Mocks.StrictMock<IDataProvider>() }; using (Mocks.Record()) { Expect.Call(providers[0].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem<int>(1, null, false), new ScalarDataItem<int>(2, null, false), }); Expect.Call(providers[1].GetItems(bindings, true)).Return(EmptyArray<IDataItem>.Instance); Expect.Call(providers[2].GetItems(bindings, true)).Return(new IDataItem[] { new ScalarDataItem<int>(3, null, true), }); } using (Mocks.Playback()) { List<IDataItem> items = new List<IDataItem>(ConcatenationMergeStrategy.Instance.Merge(providers, bindings, true)); Assert.Count(3, items); Assert.AreEqual(1, items[0].GetValue(bindings[0])); Assert.IsFalse(items[0].IsDynamic); Assert.AreEqual(2, items[1].GetValue(bindings[0])); Assert.IsFalse(items[1].IsDynamic); Assert.AreEqual(3, items[2].GetValue(bindings[0])); Assert.IsTrue(items[2].IsDynamic); } }
void LoadDataCombobox() { try { _dtObjectType = new LObjectTypeController().FetchAll().ToDataTable(); DataBinding.BindDataCombobox_Basic(cboObjectType, _dtObjectType, LObjectType.Columns.Id, LObjectType.Columns.SName); _dtDepartment = new LDepartmentController().FetchAll().ToDataTable(); DataBinding.BindDataCombobox_Basic(cboDepartment, _dtDepartment, LDepartment.Columns.Id, LDepartment.Columns.SName); _dtLoaiXetNghiem = new TTestTypeListController().FetchAll().ToDataTable(); DataBinding.BindDataCombobox_Basic(cboLoaiXN, _dtLoaiXetNghiem, TTestTypeList.Columns.TestTypeId, TTestTypeList.Columns.TestTypeName); _dtUser = new Select().From(SysUser.Schema).ExecuteDataSet().Tables[0]; //foreach (DataRow row in _dtUser.Rows) //{ // if(string.IsNullOrEmpty(Utility.sDbnull(row[TblUser.Columns.SFullName],""))) // { // row[TblUser.Columns.SFullName] = row[TblUser.Columns.PkSuid].ToString(); // } //} _dtUser.AcceptChanges(); DataBinding.BindDataCombobox_Basic(cboNguoiGui, _dtUser, SysUser.Columns.PkSuid, SysUser.Columns.SFullName); cboNguoiNhan.DataSource = _dtUser; cboNguoiNhan.DisplayMember = SysUser.Columns.SFullName; cboNguoiNhan.ValueMember = SysUser.Columns.PkSuid; cboNguoiNhan.SelectedIndex = 0; cboTrangThaiBN.SelectedIndex = 0; cboTrangthai.SelectedIndex = 0; cboStatusPrint.SelectedIndex = 0; } catch (Exception) { Utility.ShowMsg("Có lỗi trong quá trình lấy thông tin combobox"); return; } }
private void LoadKho() { if (KIEU_THUOC_VT == "THUOC") { m_dtKhoNhan = CommonLoadDuoc.LAYTHONGTIN_KHOTHUOC_LE_NOITRU(); m_dtKhoTra = CommonLoadDuoc.LAYTHONGTIN_TUTHUOC(); } else { m_dtKhoNhan = CommonLoadDuoc.LAYTHONGTIN_KHOVATTU_CHAN(); m_dtKhoTra = CommonLoadDuoc.LAYTHONGTIN_KHOVATTU_LE(new List <string> { "TATCA", "NOITRU" }); } DataBinding.BindDataCombobox(cboKhoNhan, m_dtKhoNhan, TDmucKho.Columns.IdKho, TDmucKho.Columns.TenKho, "---Chọn kho nhận---", true); cboNhanVien.SelectedValue = globalVariables.gv_intIDNhanvien; DataBinding.BindDataCombobox(cboKhoaTra, m_KhoaLinh, DmucKhoaphong.Columns.IdKhoaphong, DmucKhoaphong.Columns.TenKhoaphong, "--Chọn khoa trả--", true); }
/// <summary> /// hàm thực hienj việc lưu lại thông itn /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void txtUserName_LostFocus(object sender, EventArgs eventArgs) { try { if (_oldUid != Utility.sDbnull(txtUserName.Text)) { _oldUid = Utility.sDbnull(txtUserName.Text); globalVariables.UserName = _oldUid; bool isAdmin = new LoginService().isAdmin(Utility.sDbnull(_oldUid)); DataBinding.BindDataCombobox(cboKhoaKCB, THU_VIEN_CHUNG.LaydanhsachKhoaKhidangnhap(globalVariables.UserName, Utility.Bool2byte(isAdmin)), DmucKhoaphong.Columns.MaKhoaphong, DmucKhoaphong.Columns.TenKhoaphong, "---Khoa làm việc---", false); cboKhoaKCB.SelectedIndex = Utility.GetSelectedIndex(cboKhoaKCB, PropertyLib._AppProperties.Makhoathien); } } catch (Exception ex) { Utility.ShowMsg("Lỗi:" + ex); } }
void LoadDataToCombobox() { try { DataTable dtDepartment = new Select().From(LDepartment.Schema).ExecuteDataSet().Tables[0]; DataBinding.BindDataCombobox_Basic(cboDepartment, dtDepartment, LDepartment.Columns.Id, LDepartment.Columns.SName); DataTable dtDoctor = new Select().From(LUser.Schema).ExecuteDataSet().Tables[0]; DataBinding.BindDataCombobox_Basic(cboDoctor, dtDoctor, LUser.Columns.UserId, LUser.Columns.UserName); DataTable dtObjectType = new Select().From(LObjectType.Schema).ExecuteDataSet().Tables[0]; DataBinding.BindDataCombobox_Basic(cboObjectType, dtObjectType, LObjectType.Columns.Id, LObjectType.Columns.SName); DataTable dtTestTypeList = new Select().From(TTestTypeList.Schema).ExecuteDataSet().Tables[0]; DataBinding.BindDataCombobox_Basic(cboTestTypeList, dtTestTypeList, TTestTypeList.Columns.TestTypeId, TTestTypeList.Columns.TestTypeName); } catch (Exception) { Utility.ShowMsg("Có lỗi trong quá trình lấy thông tin combobox"); throw; } }
private void frm_ChooseCapPhatNoiTru_Load(object sender, EventArgs e) { DataBinding.BindData(cboDoiTuong, LoadDataCommon.CommonBusiness.LayThongTin_DoiTuong(), LObjectType.Columns.ObjectTypeCode, LObjectType.Columns.ObjectTypeName); if (thamso.Equals("KHOA")) { if (globalVariables.IsAdmin) { m_dtKhoa = LoadDataCommon.CommonBusiness.LayThongTin_KhoaNoiTru(); } else { m_dtKhoa = LoadDataCommon.CommonBusiness.LayThongTin_KhoaNoiTruTheoKhoa(globalVariables.DepartmentID); } } else { m_dtKhoa = LoadDataCommon.CommonBusiness.LayThongTin_KhoaNoiTruTheoKhoa(globalVariables.DepartmentID); } DataBinding.BindData(cboKhoa, m_dtKhoa, LDepartment.Columns.DepartmentId, LDepartment.Columns.DepartmentName); LoadKhoTheoVatTuThuoc(); }
private void cboKhoaTra_SelectedIndexChanged(object sender, EventArgs e) { try { if (!b_Hasloaded) { return; } string IDKhoa = cboKhoaTra.SelectedValue.ToString(); DataRow[] arrdr = m_dtKhoTra.Select("ID_KHOA=" + IDKhoa); DataTable _newTable = m_dtKhoTra.Clone(); if (arrdr.Length > 0) { _newTable = arrdr.CopyToDataTable(); } DataBinding.BindDataCombobox(cboKhoXuat, _newTable, TDmucKho.Columns.IdKho, TDmucKho.Columns.TenKho, "--Tủ thuốc--", false); } catch { } }
void InitData() { DataTable dtnhominphoi = new Select().From(DmucChung.Schema) .Where(DmucChung.Columns.Loai).IsEqualTo(THU_VIEN_CHUNG.Laygiatrithamsohethong("BHYT_STT_INPHOI", "STT_INPHOIBHYT", true)) .And(DmucChung.Columns.MotaThem).IsEqualTo("2") .ExecuteDataSet().Tables[0]; txtNhominphoiBHYT.Init(dtnhominphoi, new List <string>() { DmucChung.Columns.Ma, DmucChung.Columns.Ma, DmucChung.Columns.Ten }); txtQuychuan.Init(); txtDonvitinh.Init(); m_dtLoaiDichvuCLS = THU_VIEN_CHUNG.LayDulieuDanhmucChung("LOAIDICHVUCLS", true); DataTable m_dtLoaiDichvuCLS_new = m_dtLoaiDichvuCLS.Clone(); if (globalVariables.gv_dtQuyenNhanvien_Dmuc.Select(QheNhanvienDanhmuc.Columns.Loai + "= 0").Length <= 0) { m_dtLoaiDichvuCLS_new = m_dtLoaiDichvuCLS.Copy(); } else { foreach (DataRow dr in m_dtLoaiDichvuCLS.Rows) { if (Utility.CoquyenTruycapDanhmuc(Utility.sDbnull(dr[DmucChung.Columns.Ma]), "0")) { m_dtLoaiDichvuCLS_new.ImportRow(dr); } } } DataBinding.BindDataCombox(cboServiceType, m_dtLoaiDichvuCLS_new, DmucChung.Columns.Ma, DmucChung.Columns.Ten, "Chọn", false); m_dtNhomDichVu = THU_VIEN_CHUNG.LayDulieuDanhmucChung("NHOMBAOCAOCLS", true); DataBinding.BindDataCombox(cbonhombaocao, m_dtNhomDichVu, DmucChung.Columns.Ma, DmucChung.Columns.Ten); DataTable dtNhomin = THU_VIEN_CHUNG.LayDulieuDanhmucChung("NHOM_INPHIEU_CLS", true); DataBinding.BindDataCombox(cboNhomin, dtNhomin, DmucChung.Columns.Ma, DmucChung.Columns.Ten); m_dtKhoaChucNang = THU_VIEN_CHUNG.Laydanhmuckhoa("ALL", 1); DataBinding.BindDataCombobox(cboDepartment, m_dtKhoaChucNang, DmucKhoaphong.Columns.IdKhoaphong, DmucKhoaphong.Columns.TenKhoaphong, "---Chọn---", true); }
public virtual void BindingShouldNotAddSameBehavior() { IBindingPath path = new BindingPath("test"); var bindingManager = new BindingManager(); var target = new BindingSourceAccessorMock { Source = new ObserverMock { GetActualSource = b => new object(), Path = path } }; var source = new BindingSourceAccessorMock(); DataBinding binding = CreateDataBinding(target, source, bindingManager); var first = new BindingBehaviorMock { Id = Guid.Empty, Attach = binding1 => true }; binding.Behaviors.Add(first); ShouldThrow(() => binding.Behaviors.Add(first)); }
private void frm_ChooseIn_Load(object sender, EventArgs e) { if (!globalVariables.IsAdmin) { if (thamso.Equals("KHO")) { m_dtKhoaNoiTru = LoadDataCommon.CommonBusiness.LayThongTin_KhoaNoiTru(); DataBinding.BindDataCombox(cboKhoa, m_dtKhoaNoiTru, LDepartment.Columns.DepartmentId, LDepartment.Columns.DepartmentName, "--Khoa nội trú---"); } else { m_dtKhoaNoiTru = LoadDataCommon.CommonBusiness.LayThongTin_KhoaNoiTruTheoKhoa(globalVariables.DepartmentID); DataBinding.BindData(cboKhoa, m_dtKhoaNoiTru, LDepartment.Columns.DepartmentId, LDepartment.Columns.DepartmentName); } } else { m_dtKhoaNoiTru = LoadDataCommon.CommonBusiness.LayThongTin_KhoaNoiTru(); DataBinding.BindDataCombox(cboKhoa, m_dtKhoaNoiTru, LDepartment.Columns.DepartmentId, LDepartment.Columns.DepartmentName, "--Khoa nội trú---"); } }
private void frmArchiverReport_Load(object sender, EventArgs e) { try { DataTable dtTestType = new Select("*").From(TTestTypeList.Schema.Name).OrderAsc(TTestTypeList.Columns.IntOrder). ExecuteDataSet().Tables[0]; DataBinding.BindDataCombobox_Basic(cboTestType, dtTestType, TTestTypeList.Columns.TestTypeId, TTestTypeList.Columns.TestTypeName); DataTable dtObjectType = new Select("*").From(LObjectType.Schema.Name).ExecuteDataSet().Tables[0]; DataBinding.BindDataCombobox_Basic(cboObjectType, dtObjectType, LObjectType.Columns.Id, LObjectType.Columns.SName); DataTable dtDepartment = new Select("*").From(LDepartment.Schema.Name).ExecuteDataSet().Tables[0]; DataBinding.BindDataCombobox_Basic(cboDepartment, dtDepartment, LDepartment.Columns.Id, LDepartment.Columns.SName); DataTable dtDevices = new Select("*").From(DDeviceList.Schema.Name).ExecuteDataSet().Tables[0]; DataBinding.BindDataCombobox_Basic(cboDevices, dtDevices, DDeviceList.Columns.DeviceId, DDeviceList.Columns.DeviceName); } catch (Exception ex) { Utility.ShowMsg(ex.Message); Dispose(); } }
private void UpdateView(DataBinding binding) { if (((binding.Mode == BindingMode.OneWay) || (binding.Mode == BindingMode.TwoWay)) && binding.ViewProperty != null && binding.ViewProperty.ContainingObject != null) { var viewProperty = binding.ViewProperty; if (binding.UpdateViewAction != null) { binding.UpdateViewAction(); } else { var value = (binding.ViewModelPropertyInfo == null) ? viewModel : binding.ViewModelPropertyInfo.GetValue(viewModel); if (rootViewExtensionPoints != null) { rootViewExtensionPoints.UpdateView(viewProperty, value); } else { UpdateView(viewProperty, value); } } } }
/// <summary> /// hàm thực hiện việc khởi tạo thông tin của Form /// </summary> private void InitData() { m_KhoaLinh = THU_VIEN_CHUNG.Laydanhmuckhoa("NOI", 0); if (KIEU_THUOC_VT == "THUOC") { m_dtKhoNhan = CommonLoadDuoc.LAYTHONGTIN_KHOTHUOC_LE_NOITRU(); m_dtKhoTra = CommonLoadDuoc.LAYTHONGTIN_TUTHUOC(); } else { m_dtKhoNhan = CommonLoadDuoc.LAYTHONGTIN_KHOVATTU_CHAN(); m_dtKhoTra = CommonLoadDuoc.LAYTHONGTIN_KHOVATTU_LE(new List <string> { "TATCA", "NOITRU" }); } DataBinding.BindDataCombobox(cboKhoNhan, m_dtKhoNhan, TDmucKho.Columns.IdKho, TDmucKho.Columns.TenKho, "---kho nhận---", true); DataBinding.BindDataCombobox(cboKhoaLinh, m_KhoaLinh, DmucKhoaphong.Columns.IdKhoaphong, DmucKhoaphong.Columns.TenKhoaphong, "---Khoa trả---", true); b_Hasloaded = true; }
private void frm_thongkenhapvien_Load(object sender, EventArgs e) { try { DataBinding.BindDataCombobox(cboDoituongKCB, THU_VIEN_CHUNG.LaydanhsachDoituongKcb(), DmucDoituongkcb.Columns.IdDoituongKcb, DmucDoituongkcb.Columns.TenDoituongKcb, "Chọn đối tượng KCB", true); m_dtKhoathucHien = THU_VIEN_CHUNG.Laydanhmuckhoa("NOI", 0); DataBinding.BindDataCombobox(cboKhoaNoiTru, m_dtKhoathucHien, DmucKhoaphong.Columns.MaKhoaphong, DmucKhoaphong.Columns.TenKhoaphong, "Chọn khoa KCB", true); var query = from khoa in m_dtKhoathucHien.AsEnumerable() where Utility.sDbnull(khoa[DmucKhoaphong.Columns.MaKhoaphong]) == globalVariables.MA_KHOA_THIEN select khoa; if (query.Count() > 0) { cbokhoa.SelectedValue = globalVariables.MA_KHOA_THIEN; } m_blnhasLoaded = true; } catch (Exception ex) { Utility.CatchException("Lỗi khi load chức năng!", ex); } }
/// <summary> /// hàm thực hiện việc khởi tạo thông tin của Form /// </summary> private void InitData() { txtNhacungcap.Init(); if (KIEU_THUOC_VT == "THUOC") { m_dtKhoXuat = CommonLoadDuoc.LAYTHONGTIN_KHOTHUOC_CHAN(); } else { m_dtKhoXuat = CommonLoadDuoc.LAYTHONGTIN_KHOVATTU_CHAN(); } if (m_dtKhoXuat.Rows.Count > 1) { DataBinding.BindDataCombobox(cboKhoXuat, m_dtKhoXuat, TDmucKho.Columns.IdKho, TDmucKho.Columns.TenKho, "---Kho trả---", false); } else { DataBinding.BindDataCombobox(cboKhoXuat, m_dtKhoXuat, TDmucKho.Columns.IdKho, TDmucKho.Columns.TenKho, "---Chọn---", true); } }
private void RemoveTwoWayHandler(DataBinding binding) { if (binding.ViewProperty == null || binding.ViewProperty.ContainingObject == null) { return; } var view = binding.ViewProperty.ContainingObject; string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed case "MonoTouch.UIKit.UITextField": if (textFieldTextDidChangeObserver != null) { NSNotificationCenter.DefaultCenter.RemoveObserver(textFieldTextDidChangeObserver); textFieldTextDidChangeObserver = null; } break; case "MonoTouch.UIKit.UITextView": ((UITextView)view).Changed -= HandleTextViewChanged; break; } }
public void Init() { log = LogManager.GetCurrentClassLogger(); AutocompleteDmuc(); dtpNgayIn.Value = globalVariables.SysDate; dtpFromDate.Value = globalVariables.SysDate; dtpToDate.Value = globalVariables.SysDate; baocaO_TIEUDE1.Init("BHYT_21A"); AutocompleteKcbbd(); DataBinding.BindData(cboObjectType, THU_VIEN_CHUNG.LaydanhsachDoituongKcb(new List <string> { "DV", "BHYT" }), DmucDoituongkcb.Columns.MaDoituongKcb, DmucDoituongkcb.Columns.TenDoituongKcb); txtNhomBHYT.Init(); if (cboObjectType.DataSource != null && cboObjectType.Items.Count > 0) { cboObjectType.SelectedIndex = 0; } if (cboTuyen.Items.Count > 0) { cboTuyen.SelectedIndex = 0; } }
public virtual void BindingShouldNotAddBehaviorIfAttachReturnsFalse() { IBindingPath path = new BindingPath("test"); var bindingManager = new BindingManager(); var target = new BindingSourceAccessorMock { Source = new ObserverMock { GetActualSource = b => new object(), Path = path } }; var source = new BindingSourceAccessorMock(); DataBinding binding = CreateDataBinding(target, source, bindingManager); var first = new BindingBehaviorMock { Id = Guid.Empty, Attach = binding1 => false }; binding.Behaviors.Add(first); binding.Behaviors.Count.ShouldEqual(0); binding.Behaviors.Contains(first).ShouldBeFalse(); }
/// <summary> /// load thông tin /// của form hiện tai /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frm_baocao_tonkho_Load(object sender, EventArgs e) { DataTable dtkho = null; if (KIEU_THUOC_VT == "THUOC") { baocaO_TIEUDE1.Init("thuoc_baocao_nhapxuatton_khochan"); dtkho = KieuKho == "ALL" ? CommonLoadDuoc.LAYTHONGTIN_KHOTHUOC_TATCA() : (KieuKho == "CHAN" ? CommonLoadDuoc.LAYTHONGTIN_KHOTHUOC_CHAN() : CommonLoadDuoc.LAYTHONGTIN_KHOTHUOC_LE()); } else { baocaO_TIEUDE1.Init("vt_baocao_nhapxuatton_khochan"); dtkho = KieuKho == "ALL" ? CommonLoadDuoc.LAYTHONGTIN_KHOVATTU_TATCA() : (KieuKho == "CHAN" ? CommonLoadDuoc.LAYTHONGTIN_KHOVATTU_CHAN() : CommonLoadDuoc.LAYTHONGTIN_KHOVATTU_LE(new List <string> { "TATCA", "NGOAITRU", "NOITRU" })); } DataBinding.BindData(cboKho, dtkho, TDmucKho.Columns.IdKho, TDmucKho.Columns.TenKho); DataTable m_dtNhomThuoc = new Select().From(DmucLoaithuoc.Schema).Where(DmucLoaithuoc.Columns.KieuThuocvattu).IsEqualTo(KIEU_THUOC_VT) .OrderAsc(DmucLoaithuoc.Columns.SttHthi).ExecuteDataSet().Tables[0]; allowChanged = true; cboKho_SelectedIndexChanged(cboKho, e); }
public virtual void BindingShouldThrowExceptionDuplicateIdBehavior() { IBindingPath path = BindingPath.Create("test"); var bindingManager = new BindingManager(); var target = new BindingSourceAccessorMock { Source = new BindingSourceMock { GetSource = b => new object(), Path = path } }; var source = new BindingSourceAccessorMock(); DataBinding binding = CreateDataBinding(target, source, bindingManager); var first = new BindingBehaviorMock { Id = Guid.Empty, Attach = binding1 => true }; var second = new BindingBehaviorMock { Id = Guid.Empty, Attach = binding1 => true }; binding.Behaviors.Add(first); ShouldThrow(() => binding.Behaviors.Add(second)); }
private void frm_thongkechuyenvien_Load(object sender, EventArgs e) { try { DataBinding.BindDataCombobox(cboDoituongKCB, THU_VIEN_CHUNG.LaydanhsachDoituongKcb(), DmucDoituongkcb.Columns.IdDoituongKcb, DmucDoituongkcb.Columns.TenDoituongKcb, "Chọn đối tượng KCB", true); //DataBinding.BindDataCombobox(cboNoichuyenden,THU_VIEN_CHUNG.LayDanhSachBenhVien(), // DmucBenhvien.Columns.IdBenhvien,DmucBenhvien.Columns.TenBenhvien,"Chọn bệnh viện",true); txtBenhVien.Init(globalVariables.gv_dtDmucBenhVien, new List <string>() { DmucBenhvien.Columns.IdBenhvien, DmucBenhvien.Columns.MaBenhvien, DmucBenhvien.Columns.TenBenhvien }); txtTenBenh.Init(globalVariables.gv_dtDmucBenh, new List <string>() { DmucBenh.Columns.IdBenh, DmucBenh.Columns.MaBenh, DmucBenh.Columns.TenBenh }); txtBacSy.Init(globalVariables.gv_dtDmucNhanvien, new List <string> () { DmucNhanvien.Columns.IdNhanvien, DmucNhanvien.Columns.MaNhanvien, DmucNhanvien.Columns.TenNhanvien }); m_dtKhoathucHien = THU_VIEN_CHUNG.Laydanhmuckhoa("NGOAI", 0); DataBinding.BindDataCombobox(cbokhoa, m_dtKhoathucHien, DmucKhoaphong.Columns.MaKhoaphong, DmucKhoaphong.Columns.TenKhoaphong, "Chọn khoa KCB", true); var query = from khoa in m_dtKhoathucHien.AsEnumerable() where Utility.sDbnull(khoa[DmucKhoaphong.Columns.MaKhoaphong]) == globalVariables.MA_KHOA_THIEN select khoa; if (query.Any()) { cbokhoa.SelectedValue = globalVariables.MA_KHOA_THIEN; } m_blnhasLoaded = true; } catch (Exception ex) { Utility.CatchException("Lỗi khi load chức năng!", ex); } }
private void AddCommandHandler(DataBinding binding) { var view = binding.View; if (view == null) return; string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed case "MonoTouch.UIKit.UIButton": { var button = (UIButton)view; button.TouchUpInside += HandleTouchUpInside; var command = (RelayCommand)binding.ViewModelPropertyInfo.GetValue(viewModel); if (command != null) { command.CanExecuteChanged += binding.Command_CanExecuteChanged; button.Enabled = command.IsEnabled; } } break; default: break; } }
/// <summary> /// Sets the data binding. /// </summary> /// <param name="xPath">The x path.</param> /// <param name="element">The element.</param> protected void SetDataBinding(string xPath, SdtElement element) { element.SdtProperties.RemoveAllChildren<DataBinding>(); DataBinding dataBinding = new DataBinding() { XPath = xPath, StoreItemId = new StringValue(this.customXmlPartHelper.customXmlPartCore.GetStoreItemId(element.Ancestors<Document>().First().MainDocumentPart)) }; element.SdtProperties.Append(dataBinding); }
private void UpdateList(DataBinding binding) { if (binding.ViewModelListPropertyInfo != null && binding.ListAdapter != null) { var list = (IList)binding.ViewModelListPropertyInfo.GetValue(viewModel); if (binding.ListAdapter.SetList(list)) { var listView = binding.View; if (listView is AbsListView) ((AbsListView)listView).ClearChoices(); // Apparently, calling BaseAdapter.NotifyDataSetChanged() does not clear the choices, so we do that here. } } }
private void UpdateView(DataBinding binding) { if ((binding.Mode == BindingMode.OneWay) || (binding.Mode == BindingMode.TwoWay) && binding.View != null && binding.ViewModelPropertyInfo != null) { var view = binding.View; var value = binding.ViewModelPropertyInfo.GetValue(viewModel); if (rootViewExtensionPoints != null) rootViewExtensionPoints.UpdateView(view, value); else UpdateView(view, value); } }
private DataBinding AddBinding(string propertyName, BindingMode mode = BindingMode.OneWay, string listPropertyName = null, View view = null, AdapterView commandParameterSelectedItemAdapterView = null) { string idName = (view != null) ? view.Id.ToString() : IdName(propertyName); int? resourceId = AndroidHelpers.FindResourceId(idName); if (view == null && resourceId.HasValue) view = rootView.FindViewById(resourceId.Value); if (view == null) return null; bool itemIsValue = false; string itemTemplateName = null, itemValueId = null; int? commandParameterListId = null; if (view.Tag != null) { // Get optional parameters from tag: // {Binding propertyName, Mode=OneWay|TwoWay|Command} // {List ItemsSource=listPropertyName, ItemIsValue=false|true, ItemTemplate=listItemTemplateName, ItemValueId=listItemValueId} // {CommandParameter ListId=<view Id>} // Defaults: // propertyName is known by convention from view Id = <rootview prefix><propertyName>; the default for the rootview prefix is the rootview class name + "_". // Mode = OneWay // Additional defaults for views derived from AdapterView (i.e. lists): // ItemsSource = propertyName + "List" // ItemIsValue = false // ItemTemplate = ItemsSource + "Item" // ItemValueId : if ItemIsValue = true then the default for ItemValueId = ItemTemplate string tag = view.Tag.ToString(); if (tag != null && tag.Contains("{")) { var match = Regex.Match(tag, @"({Binding\s+((?<assignment>[^,{}]+),?)+\s*})?(\s*{List\s+((?<assignment>[^,{}]+),?)+\s*})?(\s*{CommandParameter\s+((?<assignment>[^,{}]+),?)+\s*})?"); if (match.Success) { var gc = match.Groups["assignment"]; if (gc != null) { var cc = gc.Captures; if (cc != null) { for (int i = 0; i < cc.Count; i++) { string[] assignmentElements = cc[i].Value.Split('='); if (assignmentElements.Length == 1) { string value = assignmentElements[0].Trim(); if (value != "") propertyName = value; } else if (assignmentElements.Length == 2) { string name = assignmentElements[0].Trim(); string value = assignmentElements[1].Trim(); switch (name) { case "Mode": Enum.TryParse<BindingMode>(value, true, out mode); break; case "ItemsSource": listPropertyName = value; break; case "ItemIsValue": Boolean.TryParse(value, out itemIsValue); break; case "ItemTemplate": itemTemplateName = value; break; case "ItemValueId": itemValueId = value; break; case "ListId": commandParameterListId = AndroidHelpers.FindResourceId(value); if (commandParameterSelectedItemAdapterView == null && commandParameterListId.HasValue) commandParameterSelectedItemAdapterView = rootView.FindViewById<AdapterView>(commandParameterListId.Value); break; default: throw new ArgumentException("Unknown tag binding parameter: " + name); } } } } } } } } var binding = new DataBinding { View = view, ResourceId = resourceId, Mode = mode, ViewModelPropertyInfo = viewModel.GetType().GetProperty(propertyName), CommandParameterListId = commandParameterListId, CommandParameterListView = commandParameterSelectedItemAdapterView }; if (binding.View is AdapterView) { if (listPropertyName == null) listPropertyName = propertyName + "List"; var pi = viewModel.GetType().GetProperty(listPropertyName); if (pi == null && binding.ViewModelPropertyInfo.PropertyType.GetInterface("IList") != null) { listPropertyName = propertyName; pi = binding.ViewModelPropertyInfo; binding.ViewModelPropertyInfo = null; } binding.ViewModelListPropertyInfo = pi; pi = binding.View.GetType().GetProperty("Adapter", BindingFlags.Public | BindingFlags.Instance); if (pi != null) { var adapter = pi.GetValue(binding.View); if (adapter == null) { if (itemTemplateName == null) itemTemplateName = listPropertyName + "Item"; if (itemIsValue && itemValueId == null) itemValueId = itemTemplateName; int? itemTemplateResourceId = AndroidHelpers.FindResourceId(itemTemplateName, AndroidHelpers.ResourceCategory.Layout); int? itemValueResourceId = AndroidHelpers.FindResourceId(itemValueId); if (itemTemplateResourceId.HasValue) { adapter = new DataBindableListAdapter<object>(layoutInflater, itemTemplateResourceId.Value, itemTemplateName + "_", itemValueResourceId, rootViewExtensionPoints); pi.SetValue(binding.View, adapter); } } binding.ListAdapter = adapter as IDataBindableListAdapter; } } switch (binding.Mode) { case BindingMode.TwoWay: AddTwoWayHandler(binding); break; case BindingMode.Command: AddCommandHandler(binding); break; } dataBindings.Add(idName, binding); return binding; }
private void AddListHandlers(DataBinding binding) { if (binding != null && binding.ListAdapter != null) binding.ListAdapter.AddHandlers(); }
private void RemoveListHandlers(DataBinding binding) { if (binding != null && binding.ListAdapter != null) binding.ListAdapter.RemoveHandlers(); }
public void IgnoresMissingMetadataColumns() { string document = "value,[Metadata]\n123"; Func<TextReader> documentReaderProvider = delegate { return new StringReader(document); }; CsvDataSet dataSet = new CsvDataSet(documentReaderProvider, false) { HasHeader = true }; DataBinding binding = new DataBinding(0, null); List<IDataItem> items = new List<IDataItem>(dataSet.GetItems(new DataBinding[] { binding }, true)); Assert.AreEqual("123", items[0].GetValue(binding)); PropertyBag map = DataItemUtils.GetMetadata(items[0]); Assert.IsFalse(map.ContainsKey("Metadata")); }
private void RemoveTwoWayHandler(DataBinding binding) { var view = binding.View; if (view == null) return; string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed default: if (view is AbsSpinner) ((AdapterView)view).ItemSelected -= AdapterView_ItemSelected; else if (view is AbsListView) ((AdapterView)view).ItemClick -= AdapterView_ItemClick; else if (view is EditText) ((TextView)view).AfterTextChanged -= TextView_AfterTextChanged; else throw new NotImplementedException("View type not implemented: " + viewTypeName); break; } }
public void JoinProducesCoveringsOfAllPairs(int[] counts, int empiricalUpperBound) { int dimensions = counts.Length; DataBinding binding = new DataBinding(0, null); IDataProvider[] providers = new IDataProvider[dimensions]; DataBinding[][] bindingsPerProvider = new DataBinding[dimensions][]; for (int i = 0; i < dimensions; i++) { providers[i] = Mocks.StrictMock<IDataProvider>(); bindingsPerProvider[i] = new DataBinding[] { binding }; IDataItem[] providerItems = new IDataItem[counts[i]]; for (int j = 0; j < counts[i]; j++) providerItems[j] = new ScalarDataItem<int>(j, null, false); Expect.Call(providers[i].GetItems(bindingsPerProvider[i], true)).Return(providerItems); } Mocks.ReplayAll(); List<IList<IDataItem>> itemLists = new List<IList<IDataItem>>(PairwiseJoinStrategy.Instance.Join(providers, bindingsPerProvider, true)); int[][] values = new int[itemLists.Count][]; using (TestLog.BeginSection(String.Format("{0} combinations.", itemLists.Count))) { for (int i = 0; i < itemLists.Count; i++) { IList<IDataItem> itemList = itemLists[i]; Assert.AreEqual(dimensions, itemList.Count); values[i] = new int[dimensions]; for (int j = 0; j < itemList.Count; j++) { int value = (int)itemList[j].GetValue(binding); values[i][j] = value; if (j != 0) TestLog.Write(","); TestLog.Write(value); } TestLog.WriteLine(); } } // Check pairings. bool missingPairing = false; double meanOccurrences = 0; double stdevOccurrences = 0; int pairingCount = 0; using (TestLog.BeginSection("Pairings")) { for (int firstDimension = 0; firstDimension < dimensions; firstDimension++) { for (int secondDimension = firstDimension + 1; secondDimension < dimensions; secondDimension++) { for (int firstValue = 0; firstValue < counts[firstDimension]; firstValue++) { for (int secondValue = 0; secondValue < counts[secondDimension]; secondValue++) { int occurrences = 0; for (int i = 0; i < values.Length; i++) if (values[i][firstDimension] == firstValue && values[i][secondDimension] == secondValue) occurrences += 1; TestLog.WriteLine("{0} x {1} : ({2}, {3}) -> {4} occurrences.", firstDimension, secondDimension, firstValue, secondValue, occurrences); if (occurrences == 0) missingPairing = true; pairingCount += 1; double diff = occurrences - meanOccurrences; meanOccurrences += diff / pairingCount; stdevOccurrences += diff * (occurrences - meanOccurrences); } } } } } if (pairingCount > 1) stdevOccurrences = Math.Sqrt(stdevOccurrences / (pairingCount - 1)); else stdevOccurrences = 0; using (TestLog.BeginSection("Statistics")) { // A mean of exactly 1 implies we have found a minimal covering. // A low standard deviation indicates good uniformity among the covered pairs. 0 would be ideal. TestLog.WriteLine("Pairing Occurrence Mean: {0}", meanOccurrences); TestLog.WriteLine("Pairing Occurrence Stdev: {0}", stdevOccurrences); } Assert.IsFalse(missingPairing, "One or more pairings were not covered!"); Assert.LessThanOrEqualTo(values.Length, empiricalUpperBound, "There were more combinations produced than previously measured. Has the algorithm gotten worse?"); }