示例#1
0
        public void UpdateDataTest() {
            var target = new HasManyEditForm();

            var input_record = DummySetData[0];
            var input_property = "Set";

            target.OwningRecord = input_record;
            target.PropertyName = input_property;

            Assert.AreEqual(DummyData.Count, target.AllRecords.Count, "AllRecords count");
            Assert.AreEqual(DummySetData[0].Set.Count, target.SelectedRecords.Count, "SelectedRecords count");
            Assert.AreEqual(DummyData.Count - DummySetData[0].Set.Count, target.UnselectedRecords.Count, "UnselectedRecords count");

            Assert.AreEqual(DummyData[0].Value, ((DummyModel)target.SelectedRecords[0]).Value, "First selected record");
            Assert.AreEqual(DummyData[1].Value, ((DummyModel)target.UnselectedRecords[0]).Value, "First unselected record");
        }
示例#2
0
        /// <summary>
        /// Shows a form that allows a user to associate selected database records with another record.
        /// </summary>
        /// <param name="Owner">Window that is the owner of the form that is shown</param>
        /// <param name="Title">Text to show in the form's title bar and a caption label</param>
        /// <param name="OwningRecord">Instance of a DbRecord that has a one-to-many relationship with other records</param>
        /// <param name="PropertyName">Name of the property that holds the set of associated records (must be of type HasMany&lt;T&gt;)</param>
        public static void SelectRecords(IWin32Window Owner, String Title,
                DbRecord OwningRecord, String PropertyName) {
            String Name = OwningRecord.GetType().Name + "." + PropertyName;

            using (var form = new HasManyEditForm()) {
                // Important for FormData.LoadFormData and FormData.SaveFormData
                form.Name = Name;
                form.Text = Title;
                form.lblText.Text = Title;

                form.OwningRecord = OwningRecord;
                form.PropertyName = PropertyName;

                if (Owner == null)
                    form.ShowInTaskbar = true;

                form.ShowDialog(Owner);
            }
        }