예제 #1
0
        public void ResetIncludeFields(DataRow drTemplate = null)
        {
            if (drTemplate == null)
            {
                drTemplate = DBContext.GetNoteTemplateById(this.Templates);
            }

            if (drTemplate["TableColums"].ToInt() == 0)
            {
                if (_inclFields.Count > 0)
                {
                    _inclFields.Clear();
                }
            }
            else
            {
                _inclFields.Clear();
                if (drTemplate != null)
                {
                    foreach (DataColumn col in drTemplate.Table.Columns)
                    {
                        if (col.ColumnName.StartsWith("ColumName") && (!drTemplate.IsNull(col)))
                        {
                            _inclFields.Add(NoteInclude.GetNameByHeader((string)drTemplate[col]));
                        }
                    }
                }
            }
        }
예제 #2
0
        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);
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        // объект, заполненный данными из БД
        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);
        }
예제 #4
0
        private static void updNoteIncl(NoteInclude incl, int noteId, Note note)
        {
            string sqlText = "";

            // добавить
            if (incl.Id == 0)
            {
                incl.IdNotes = noteId;
                try
                {
                    sqlText = incl.GetSQLInsertText(note.IncludeFields) + "; SELECT @@IDENTITY";

                    using (DBContext db = new DBContext())
                    {
                        DataTable dtTmp = db.GetQueryTable(sqlText);
                        incl.Id = Convert.ToInt32(dtTmp.Rows[0][0]);
                    }
                }
                catch (Exception ex)
                {
                    showErrorBox("NoteIncludeTable", "добавления", ex.Message + ": " + sqlText);
                }
            }
            else
            {
                try
                {
                    sqlText = incl.GetSQLUpdateText(note.IncludeFields);
                    using (DBContext db = new DBContext())
                    {
                        db.ExecuteCommand(sqlText);
                    }
                }
                catch (Exception ex)
                {
                    showErrorBox("NoteIncludeTable", "обновления", ex.Message + ": " + sqlText);
                }
            }
        }