コード例 #1
0
        protected override ReadOnlyCollection <PropertyInfo> GetOrderedPropertiesInternal()
        {
            List <PropertyInfo> list = new List <PropertyInfo>();

            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.IdNumber), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.Name), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.Designation), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.DateOfJoining), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.DateOfBirth), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.BloodGroup), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.NidNumber), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.PassPortNumber), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.CurrentAllocation), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.PhoneNumber), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.Photo), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.NidScan), list);
            DomainObjectHelper.AddProperty <ContactDO>(nameof(this.PassportScan), list);

            return(new ReadOnlyCollection <PropertyInfo>(list));
        }
コード例 #2
0
        private void ImportClick(object sender, EventArgs e)
        {
            try
            {
                if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    string file = this.openFileDialog1.FileName;

                    string error = string.Empty;

                    ReadOnlyCollection <PropertyInfo> collection = new ContactDO().GetOrderedProperties();

                    DataTable data = ExcelHelper.Import(file, collection, ref error);

                    this.ShowErrorIfNotEmpty(error);

                    error = string.Empty;
                    List <ContactDO> contacts = DomainObjectHelper.GetDomainObjectFromDataTable <ContactDO>(data, ref error);

                    this.ShowErrorIfNotEmpty(error);

                    foreach (ContactDO record in contacts)
                    {
                        error = string.Empty;
                        DataBaseHelper.Insert(Program.ConnectionString, ContactDO.TableName, record, ref error);
                        this.ShowErrorIfNotEmpty(error);
                    }

                    this.ReloadContacts();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while trying to import data: " + ex.Message);
            }
        }