コード例 #1
0
ファイル: Note.cs プロジェクト: dmitriyChernov89/FlyDoc
        public void ResetIncludeFields(NoteTemplate template)
        {
            if (template == null)
            {
                _inclFields.Clear(); return;
            }

            _inclFields.Clear();
            if (template.TableColums >= 0)
            {
                PropertyInfo[] pInfos = template.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
                foreach (PropertyInfo pInfo in pInfos)
                {
                    if (pInfo.Name.StartsWith("ColumName"))
                    {
                        string colName = Convert.ToString(pInfo.GetValue(template, null));
                        if (string.IsNullOrEmpty(colName) == false)
                        {
                            string sRet = NoteInclude.GetNameByHeader(colName);
                            if (string.IsNullOrEmpty(sRet) == false)
                            {
                                _inclFields.Add(sRet);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Note.cs プロジェクト: dmitriyChernov89/FlyDoc
        // объект, заполненный данными из БД
        public Note(int noteId) : this()
        {
            DBContext.PopulateEntityById(this, noteId);
            if (this.Id == 0)
            {
                return;
            }

            // внутренняя таблица NoteInclude
            DataTable dt = DBContext.GetNoteIncludeByNoteId(noteId);

            if (dt != null)
            {
                this.Include = new List <NoteInclude>();
                NoteInclude noteIncl;
                // коллекция имен полей таблицы
                List <string> colNames = DBContext.GetColumnsNameList(dt);
                // коллекция свойств объекта типа NoteInclude
                List <PropertyInfo> pInfo = typeof(NoteInclude).GetProperties().ToList();
                // для каждой строки таблицы создаем объект NoteInclude, заполняем его через рефлексию
                foreach (DataRow row in dt.Rows)
                {
                    noteIncl = new NoteInclude();
                    foreach (PropertyInfo item in pInfo)
                    {
                        if (colNames.Contains(item.Name))
                        {
                            item.SetValue(noteIncl, (row.IsNull(item.Name) ? null : row[item.Name]), null);
                        }
                    }
                    // и добавляем в коллекцию Include
                    this.Include.Add(noteIncl);
                }
            }

            // шаблон
            _template = new NoteTemplate(Templates);

            // отдел
            _dep = new Department(IdDepartment);
        }