public virtual JObject GetXClassSchema(HttpContext context) { YZRequest request = new YZRequest(context); String xclass = request.GetString("xclass", null); FlowDataSet dataset = new FlowDataSet(); FlowDataTable table = new FlowDataTable(); FlowDataTable tableFilter = new FlowDataTable(); dataset.Tables.Add(table); if (!String.IsNullOrEmpty(xclass)) { string url = YZUtility.GetUrlFromXClass(xclass); string phyPath = context.Server.MapPath(url); using (StreamReader rd = new StreamReader(phyPath)) { string jsText = rd.ReadToEnd(); string dataColumns = this.GetProperty(jsText, "datasourceColumns", '[', ']'); if (!String.IsNullOrEmpty(dataColumns)) { JArray jDataColumns = JArray.Parse(dataColumns); foreach (JToken token in jDataColumns) { if (token.Type == JTokenType.String) { FlowDataColumn column = new FlowDataColumn((string)token, typeof(string)); table.Columns.Add(column); } } } } } return(YZJsonHelper.SerializeSchema(dataset, "", "DataType")); }
protected virtual object GetDemoValue(FlowDataColumn column, int tableIndex, int rowIndex, int columnIndex) { switch (Type.GetTypeCode(column.DataType)) { case TypeCode.Boolean: return(true); case TypeCode.Byte: case TypeCode.SByte: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Char: return((rowIndex + 1) * 10 + (columnIndex + 1)); case TypeCode.Single: return((Single)(rowIndex + 1) * 10 + (Single)(columnIndex + 1) + (Single)0.123); case TypeCode.Double: return((Double)(rowIndex + 1) * 10000 + (Double)(columnIndex + 1) + (Double)0.123); case TypeCode.Decimal: return((Decimal)(rowIndex + 1) * 10000 + (Decimal)(columnIndex + 1) + (Decimal)0.123); case TypeCode.DBNull: case TypeCode.Empty: return(null); case TypeCode.DateTime: return(DateTime.Now); case TypeCode.String: return(String.Format("{0}1\n{0}2\n<font color=red>{0}3</font>", column.ColumnName)); default: if (column.DataType == typeof(Guid)) { return(Guid.NewGuid()); } else { try { return(Activator.CreateInstance(column.DataType)); } catch (Exception) { return(null); } } } }
protected virtual FlowDataRow CreateNewRow(FlowDataTable table, int tableIndex, int rowIndex) { FlowDataRow row = new FlowDataRow(); for (int i = 0; i < table.Columns.Count; i++) { FlowDataColumn column = table.Columns[i]; row[column.ColumnName] = GetDemoValue(column, tableIndex, rowIndex, i); } return(row); }
protected virtual JArray GenFieldItems(Model model, FlowDataTable srcTable, FlowDataRow srcRow, FlowDataTable settingTable) { JArray rv = new JArray(); foreach (FlowDataColumn settingColumn in settingTable.Columns) { FlowDataColumn srcColumn = srcTable.Columns.TryGetColumn(settingColumn.ColumnName); if (srcColumn == null || !settingColumn.AllowRead) { continue; } JObject fieldItem = this.GenFieldItem(model, srcTable, srcRow, srcColumn, settingColumn); rv.Add(fieldItem); } return(rv); }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { ClientScriptManager cs = this.Page.ClientScript; if (!cs.IsClientScriptIncludeRegistered("MyScript")) { cs.RegisterClientScriptInclude("MyScript", this.ResolveClientUrl("../Scripts/Main.js")); } if (!cs.IsClientScriptIncludeRegistered("FormScript")) { cs.RegisterClientScriptInclude("FormScript", this.Page.ResolveClientUrl("../Scripts/Form.js")); } if (!cs.IsClientScriptIncludeRegistered("XFormScript")) { cs.RegisterClientScriptInclude("XFormScript", this.Page.ResolveClientUrl("../Scripts/XForm.js")); } //获得ColumnInfo string datasourceName = this.Request.QueryString["ds"]; string tableName = this.Request.QueryString["table"]; string orderBy = this.Request.QueryString["orderby"]; this._columnInfos = this.ParseColumnInfos(this.Request.QueryString["cinfs"]); this._columnInfos.ParseFixFilter(this.Page, this.Request.QueryString["fcols"]); bool ms = this.Request.QueryString["ms"] == "1" ? true : false; bool hiddenlink = this.Request.QueryString["hl"] == "1" ? true : false; if (ms) { this._bs.Visible = true; this._bs.OnClientClick = String.Format("F_CloseDialogNBat(mlist,{0},'{1}','');return false;", this.Request.QueryString["idx"], Resources.BPMResource.DataBrowser_Msg_AtleastSelOne); } else { this._bs.Visible = false; } //初始化页导航条 this.Page.Header.Title = tableName; this._navigateBar.InitState(); //获得数据 TableRow row; TableCell cell; BPMConnection cn = new BPMConnection(); FlowDataTable schema = null; FlowDataTable table = null; int rowcount = 0; try { cn.WebOpen(Page); //获得表的Schema schema = DataSourceManager.LoadTableSchema(cn, datasourceName, tableName); //规则化显示行 if (this._columnInfos.DisplayColumnCount == 0) //没有显示行 { //有map则显示map列 if (this._columnInfos.MapColumnCount != 0) { foreach (MyColumnInfo column in this._columnInfos) { if (column.Map) { column.Display = true; } } } else //没有则显示所有列 { foreach (FlowDataColumn column in schema.Columns) { MyColumnInfo columnInfo = this._columnInfos.TryGetColumn(column.ColumnName); if (columnInfo == null) { columnInfo = new MyColumnInfo(column.ColumnName, true, false, column.ColumnName); } columnInfo.Display = true; this._columnInfos.Add(columnInfo); } } } foreach (MyColumnInfo column in this._columnInfos) { FlowDataColumn dbcolumn = schema.Columns.TryGetItem(column.ColumnName); if (dbcolumn != null) { column.AllowSearch = dbcolumn.AllowSearch; } } BPMDBParameterCollection parameters = GetSelectParameters(this._columnInfos); //获得数据 table = DataSourceManager.LoadTableDataPaged(cn, datasourceName, tableName, this._columnInfos.AllOutputColumnNames, parameters, orderBy, (this._navigateBar.CurPage - 1) * this._navigateBar.PageSize, this._navigateBar.PageSize, out rowcount); this._navigateBar.ItemCount = rowcount; } finally { cn.Close(); } //建立ComboBox this._schType.Items.Add(new ListItem(Resources.BPMResource.Com_All, "all")); foreach (MyColumnInfo column in this._columnInfos) { if (!column.Display || column.FixFilter || !column.AllowSearch) { continue; } this._schType.Items.Add(new ListItem(column.DisplayName, column.ColumnName)); } //设置状态值 this._schBox.Text = this.Request.QueryString["sch"]; this._schType.SelectedValue = this.Request.QueryString["schtype"]; //建立List的Header row = CreateHeaderRow(); this._table.Rows.Add(row); //获得按SELECT排序的DisplayColumn MyColumnInfoCollection displayColumnsOrdered = new MyColumnInfoCollection(); foreach (FlowDataColumn tableColumn in schema.Columns) { MyColumnInfo columnInfo = this._columnInfos.TryGetColumn(tableColumn.ColumnName); if (columnInfo == null) { continue; } if (!columnInfo.Display) { continue; } displayColumnsOrdered.Add(columnInfo); } if (ms) { row.Cells.Add(CreateCheckColumn()); } foreach (MyColumnInfo column in displayColumnsOrdered) { if (row.Cells.Count != 0) { row.Cells.Add(CreateSepratorColumn()); } cell = CreateColumn(column.DisplayName, -1); row.Cells.Add(cell); } //总记录数 this._labCount.Text = rowcount.ToString(); //添加行 foreach (FlowDataRow dataRow in table.Rows) { row = CreateItemRow(); this._table.Rows.Add(row); if (ms) { cell = new TableCell(); cell.Text = "<input id=\"" + GetMapValue(this._columnInfos, dataRow) + "\" type=\"checkbox\" onclick=\"checkrow(this);\">"; cell.ColumnSpan = 1; row.Cells.Add(cell); } foreach (MyColumnInfo column in displayColumnsOrdered) { //列分割 if (row.Cells.Count != 0) { row.Cells.Add(CreateEmptyCell(1)); } foreach (string key in dataRow.Keys) { object v = dataRow[key]; } object value = dataRow[column.ColumnName]; if (row.Cells.Count == 0 && !hiddenlink) { HyperLink link = CreateSetValueLink(FormatValue(value), this._columnInfos, dataRow, this._table.Rows.Count - 1); cell = CreateCell(String.Empty, 1); cell.Controls.Add(link); } else { cell = CreateCell(FormatValue(value), 1); } //cell.Style.Add("text-align", "center"); row.Cells.Add(cell); } } } }
protected virtual JObject GenFieldItem(Model model, FlowDataTable table, FlowDataRow row, FlowDataColumn column, FlowDataColumn setting) { object value = row[column.ColumnName]; JObject field = new JObject(); string valuePropertyName; string xclass = setting.MapTo; switch (xclass) { case "Ext.field.Field": valuePropertyName = "html"; break; case "YZSoft.src.field.Users": valuePropertyName = "stringValue"; break; default: valuePropertyName = "value"; break; } value = this.DoRender(setting.SParam1, xclass, value); if (valuePropertyName == "html" && value is string) { value = YZUtility.HtmlEncodeBR((string)value); } field["xclass"] = xclass; field["label"] = setting.DisplayName; field[valuePropertyName] = new JValue(value); if (!table.IsRepeatableTable) { if (setting.AllowWrite || model == Model.Post) { field["xdatabind"] = column.FullName; } else { field["readOnly"] = true; } } else { field["readOnly"] = true; } JObject config = setting.FilterValue as JObject; if (config != null) { foreach (KeyValuePair <string, JToken> kv in config) { field[kv.Key] = kv.Value; } } return(field); }