public ResponseObjectPackage<Dictionary<int, object>> GetDictionaryObjectByID(int dictionaryID, int pkValue) { Dictionary dictionary = new DictionariesLogic().GetDictionaryViewModel(dictionaryID).GetDataOrExceptionIfError(); string sql = string.Format( "select {0} " + Environment.NewLine + "from {1} " + Environment.NewLine + "where {2} = {3}", string.Join(", ", dictionary.fields.Select(e => e.columnName)), dictionary.tableName, dictionary.GetPrimaryKey().columnName, pkValue ); RequestPackage request = new RequestPackage() { requestString = sql }; List<Dictionary<string, object>> response = new DBUtils().RunSqlAction(new DynamicCRUD().GetDictionaryData, request).GetDataOrExceptionIfError(); if (response.Count > 1 || response.Count == 0) { throw new Exception("Запрос данных полей из словаря возвратил не одну строку! dictionaryID = " + dictionaryID + " pkValue = " + pkValue); } Dictionary<int, object> result = new Dictionary<int, object>(); foreach (DictionaryField field in dictionary.fields) { result.Add(field.ID, response[0][field.columnName]); } return new ResponseObjectPackage<Dictionary<int, object>>() { resultData = result }; }
public ResponseObjectPackage<Form> BuildForm(int formID) { FormModel formModel = new ControlPropertiesLogic().GetFormByID(formID).GetDataOrExceptionIfError(); Dictionary dictionary = null; if (formModel.dictionaryID.HasValue) { dictionary = new DictionariesLogic().GetDictionaryViewModel(formModel.dictionaryID.Value).GetDataOrExceptionIfError(); } List<int> queryIDs = new ControlPropertiesLogic().GetControlQueryMappingByFormID(formID).GetDataOrExceptionIfError() .Select(e => e.queryID).Distinct().ToList(); Control window = new ControlPropertiesLogic().BuildWindow(formID).GetDataOrExceptionIfError(); List<QueryType> queries = new List<QueryType>(); foreach (int queryID in queryIDs) { List<QueryQueryInParameterModel> mapping = new QueryInParametersLogic().GetQueryQueryInParametersByQueryID(queryID).GetDataOrExceptionIfError(); queries.Add(new QueryType() { queryID = queryID, inParametersMapping = mapping }); } List<FormInParameterModel> inParameters = this.GetFormInParametersByFormID(formID).GetDataOrExceptionIfError(); List<FormOutParameterModel> outParameters = this.GetFormOutParametersByFormID(formID).GetDataOrExceptionIfError(); Form form = new Form() { ID = formID, dictionary = dictionary, queries = queries, window = window, inParameters = inParameters, outParameters = outParameters }; return new ResponseObjectPackage<Form>() { resultData = form }; }
public ResponseObjectPackage<List<DictionaryTreeItem>> GetDictionariesTree() { List<DictionaryGruopModel> dictGroups = this.GetAllDictionaryGroups().GetDataOrExceptionIfError(); List<DictionaryModel> dicts = new DictionariesLogic().GetAllDictionaries().GetDataOrExceptionIfError(); List<DictionaryTreeItem> list = new List<DictionaryTreeItem>(); Func<DictionaryGruopModel, DictionaryTreeItem> fillDictionaryGroup = null; fillDictionaryGroup = (g) => { DictionaryTreeItem thisItem = new DictionaryTreeItem(g); foreach (DictionaryGruopModel group_ in dictGroups.Where(e => e.dictionaryGroupID_Parent == g.ID)) { thisItem.children.Add(fillDictionaryGroup(group_)); } foreach (DictionaryModel dict_ in dicts.Where(e => e.dictionaryGroupID == g.ID)) { thisItem.children.Add(new DictionaryTreeItem(dict_)); } return thisItem; }; foreach (DictionaryGruopModel group in dictGroups.Where(e => e.dictionaryGroupID_Parent == null)) { list.Add(fillDictionaryGroup(group)); } return new ResponseObjectPackage<List<DictionaryTreeItem>>() { resultData = list }; }
public JsonResult GetAllDictionaries() { try { ResponseObjectPackage<List<DictionaryModel>> response = new DictionariesLogic().GetAllDictionaries().GetSelfOrExceptionIfError(); return Json(response); } catch (Exception ex) { return this.HandleException(ex); } }
public ResponseObjectPackage<List<Dictionary<string, object>>> GetDictionaryData(int dictionaryID) { DictionaryModel dictionary = new DictionariesLogic().GetDictionaryByID(dictionaryID).GetDataOrExceptionIfError(); List<DictionaryFieldModel> fields = new DictionaryFieldsLogic().GetDictionaryFieldsByDictionaryID(dictionaryID).GetDataOrExceptionIfError(); string sql = string.Format( "select {0} " + "from {1};", string.Join(", ", fields.Select(e => e.columnName)), dictionary.tableName ); RequestPackage request = new RequestPackage() { requestString = sql }; ResponseObjectPackage<List<Dictionary<string, object>>> response = new DBUtils().RunSqlAction(new DynamicCRUD().GetDictionaryData, request); return response; }
private DictionaryValue FillDictionaryValue(Dictionary<int, string> row, int dictionaryID) { Dictionary dictionary = new DictionariesLogic().GetDictionaryViewModel(dictionaryID).GetDataOrExceptionIfError(); DictionaryValue dictVal = new DictionaryValue(dictionary, row); return dictVal; }