/// <summary> /// Формирует описание структуры JSON-ответа для клиентского JsonStore из XML-описания. /// </summary> /// <param name="bioCode"/> /// <param name="cursorDef">XML-описание курсора.</param> public static JsonStoreMetadata ConstructMetadata(String bioCode, XmlNode cursorDef) { JsonStoreMetadata vResult = new JsonStoreMetadata(); vResult.Fields = new List<JsonStoreMetadataFieldDef>(); vResult.ReadOnly = Xml.getAttribute<Boolean>(cursorDef as XmlElement, "readOnly", true); vResult.Multiselection = Xml.getAttribute<Boolean>(cursorDef as XmlElement, "multiselection", false); XmlNodeList xmlFields = cursorDef.SelectNodes("fields/field[not(@generate) or (@generate='true')]"); if (xmlFields == null || xmlFields.Count <= 0) return vResult; foreach (XmlElement xmlEl in xmlFields) { String v_field_name = xmlEl.GetAttribute("name"); if (vResult.IndexOf(v_field_name) >= 0) throw new EBioException(String.Format("В описании объекта {0} поле {1} определено более 1 раза.", bioCode, v_field_name)); JsonStoreMetadataFieldDef fldDef = new JsonStoreMetadataFieldDef(); if (xmlEl.HasAttribute("generate") && xmlEl.GetAttribute("generate") != "true") continue; fldDef.Name = v_field_name; if (String.IsNullOrEmpty(fldDef.Name)) continue; fldDef.Header = xmlEl.GetAttribute("header"); if (!String.IsNullOrEmpty(fldDef.Header)) fldDef.Header = fldDef.Header.Replace("\\n", "\n"); fldDef.Hidden = Xml.getAttribute<Boolean>(xmlEl, "hidden", false); fldDef.ReadOnly = Xml.getAttribute<Boolean>(xmlEl, "readOnly", vResult.ReadOnly); fldDef.Type = jsonUtl.detectFieldType(xmlEl.GetAttribute("type")); fldDef.Width = Xml.getAttribute<Int32>(xmlEl, "width", 0); fldDef.Format = Xml.getAttribute<String>(xmlEl, "format", null); if (String.IsNullOrEmpty(fldDef.Format)) { if ((fldDef.Type == JSFieldType.Date) || (fldDef.Type == JSFieldType.DateUTC)) fldDef.Format = "dd.MM.yyyy HH:mm:ss"; if (fldDef.Type == JSFieldType.Int) fldDef.Format = "0"; if (fldDef.Type == JSFieldType.Currency) fldDef.Format = "#,##0.00 р"; } fldDef.Align = jsonUtl.detectAlignment(fldDef.Type, xmlEl.GetAttribute("align")); fldDef.Group = Xml.getAttribute<Int32>(xmlEl, "group", -1); fldDef.GroupAggr = xmlEl.GetAttribute("group_aggr"); Int32 pkIndx = Xml.getAttribute<Int32>(xmlEl, "pk", 0); String boolVals = xmlEl.GetAttribute("boolVals"); String defaultVal = xmlEl.GetAttribute("defaultVal"); //if (fldDef.type == "currency") fldDef.Type = "float"; if (pkIndx > 0) fldDef.PK = pkIndx; //if (fldDef.type == CJsonStoreMetadataFieldType.ftDate) // fldDef.dateFormat = "Y-m-d\\TH:i:s"; else if (fldDef.Type == JSFieldType.Boolean && !String.IsNullOrEmpty(boolVals)) fldDef.BoolVals = boolVals; if (!String.IsNullOrEmpty(defaultVal) && fldDef.Type != JSFieldType.Date) if (fldDef.Type == JSFieldType.Boolean) fldDef.DefaultVal = Utl.Convert2Type<Boolean>(defaultVal); else if (fldDef.Type == JSFieldType.String) fldDef.DefaultVal = defaultVal; else fldDef.DefaultVal = Utl.Convert2Type<Double>(defaultVal); vResult.Fields.Add(fldDef); } if (vResult.Multiselection) { var v_pks = vResult.GetPKFields(); if ((v_pks == null) || (v_pks.Length != 1)) throw new Exception(String.Format("Для режима multiselection, необходимо чтобы для ио [{0}] был определен первичный ключь(не составной).", bioCode)); } return vResult; }
private void _returnParamsToRow(JsonStoreMetadata metadata, JsonStoreRow row, Params bioParams) { var v_out_params = bioParams.Where(p => { return (p.ParamDir != ParamDirection.Input)/* || String.Equals(p.Name, CJsonStoreMetadata.csPKFieldName)*/; }); foreach (var p in v_out_params) row.Values[metadata.IndexOf(p.Name)] = p.Value; }