123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Data;
- using System.Collections;
- using Tofly.Core.Context;
- using Tofly.Core.Context.Support;
- using Tofly.Core.Util;
- using Tofly.Core.Stereotype;
- using Tofly.CoreUI.Message;
- using Tofly.CoreUI.Control;
- using Tofly.CoreUI.Plot.Config;
- using Tofly.Data.General;
- using Tofly.Data.Util;
- using Tofly.Data.MetadataManager;
- using Tofly.DataUI.Catalog.Logic;
- using Tofly.GIS.SpatialDatabase;
- using Tofly.CoreUI.Plot;
- using Tofly.DataUI.DataConnection;
- namespace Tofly.DataUI
- {
-
-
-
- [Component(IsSingleton = "false", Name = "IDataReg")]
- [ConfigAttribute(GroupName = "数据服务管理", ControlCaption = "数据服务注册", Index = "1,1")]
- public class DataReg : IDataReg, IConfigure
- {
- private IDataRegForm pDataRegForm;
- private IAddDataRegForm2 addDataRegForm2;
- private IApplicationContext context;
- public DataReg()
- : this("IDataRegForm")
- {
-
- }
- #region 构造函数
- public DataReg(string name)
- {
- context = ContextRegistry.GetContext();
- pDataRegForm = context.GetObject(name) as IDataRegForm;
-
- addDataRegForm2 = context.GetObject("IAddDataRegForm2") as IAddDataRegForm2;
- if (pDataRegForm != null)
- {
- if (pDataRegForm is IUserControl)
- (pDataRegForm as IUserControl).LoadEvent += FormLoad;
- if (pDataRegForm is IForm)
- (pDataRegForm as IForm).LoadEvent += FormLoad;
- if (pDataRegForm.MetadataTableTree != null)
- {
- pDataRegForm.MetadataTableTree.CodeFieldName = MetadataTableRow.FIELD_TABLEID;
- pDataRegForm.MetadataTableTree.DisplayFieldName = MetadataTableRow.FIELD_TABLEALIASNAME;
- pDataRegForm.MetadataTableTree.SelectedIndexChangedEvent += MetadataTableTreeSelectedIndexChangedEvent;
- }
- if (pDataRegForm.DataRegTree != null)
- {
- pDataRegForm.DataRegTree.CodeFieldName = ConnectionRow.FIELD_CONNECTIONID;
- pDataRegForm.DataRegTree.DisplayFieldName = ConnectionRow.FIELD_CONNECTIONNAME;
- pDataRegForm.DataRegTree.SelectedIndexChangedEvent += DataRegTableTreeSelectedIndexChangedEvent;
-
- pDataRegForm.DataRegTree.DoubleClickEvent += new CoreUI.Control.EventHandler(DataRegTree_DoubleClickEvent);
- }
- if (pDataRegForm.RelationGrid != null)
- pDataRegForm.RelationGrid.LoadEvent += RelationGridLoad;
- if (pDataRegForm.AddTableButton != null)
- pDataRegForm.AddTableButton.ClickEvent += AddTableEvent;
- if (pDataRegForm.EditTableButton != null)
- pDataRegForm.EditTableButton.ClickEvent += EditTableEvent;
- if (pDataRegForm.DelTableButton != null)
- pDataRegForm.DelTableButton.ClickEvent += DelTableEvent;
- if (pDataRegForm.AddFieldButton != null)
- pDataRegForm.AddFieldButton.ClickEvent += AddFieldButtonClickEvent;
- if (pDataRegForm.EditFieldButton != null)
- pDataRegForm.EditFieldButton.ClickEvent += EditFieldButtonClickEvent;
- if (pDataRegForm.FieldGrid != null)
- pDataRegForm.FieldGrid.DoubleClickEvent += new CoreUI.Control.EventHandler(FieldGrid_DoubleClickEvent);
- if (pDataRegForm.DelFieldButton != null)
- pDataRegForm.DelFieldButton.ClickEvent += DelFieldButtonClickEvent;
- if( pDataRegForm.SynDomainButton!=null)
- pDataRegForm.SynDomainButton.ClickEvent += new CoreUI.Control.EventHandler(SynDomainButton_ClickEvent);
- if (pDataRegForm.AddRelationButton != null)
- pDataRegForm.AddRelationButton.ClickEvent += AddRelationButtonClickEvent;
- if (pDataRegForm.EditRelationButton != null)
- pDataRegForm.EditRelationButton.ClickEvent += EditRelationButtonClickEvent;
- if (pDataRegForm.DelRelationButton != null)
- pDataRegForm.DelRelationButton.ClickEvent += DelRelationButtonClickEvent;
- if (pDataRegForm.AddRegButton != null)
- pDataRegForm.AddRegButton.ClickEvent += AddRegButton_ClickEvent;
- if (pDataRegForm.DelRegButton != null)
- pDataRegForm.DelRegButton.ClickEvent += DelRegButton_ClickEvent;
- if (pDataRegForm.ImportButton != null)
- pDataRegForm.ImportButton.ClickEvent += ImportButton_ClickEvent;
- }
- }
- #endregion
- #region 加载一个连接的所有表
-
-
-
-
- void DataRegTree_DoubleClickEvent(object sender)
- {
- ConnectionRow CurrentNodeentity = pDataRegForm.DataRegTree.SelectedValue as ConnectionRow;
- if (CurrentNodeentity != null)
- {
- if (pDataRegForm.DataRegTree.GetFocusedNodeFirstChildData() != null)
- return;
- bool bHasChildNode = false;
- ConnectionInfo conInfo = new ConnectionInfo(CurrentNodeentity.ConnectionStr);
- conInfo.WorkspaceType = CurrentNodeentity.DataBaseType;
- try
- {
- IWorkspace workspace = Data.General.WorkspaceFactoryProvider.GetWorkspaceFactory().OpenWorkspace(conInfo);
- IFeatureWorkspace featureWorkSpace = workspace as IFeatureWorkspace;
- List<string> DataSetTables = new List<string>();
- if (featureWorkSpace != null)
- {
- string[] strDataSet = featureWorkSpace.GetFeatureDatasets();
- if (strDataSet != null)
- {
- foreach (string item in strDataSet)
- {
- try
- {
- IFeatureDataset pDataset = featureWorkSpace.OpenFeatureDataset(item);
- string[] tableNames = featureWorkSpace.GetClassNameFromDataset(pDataset);
- if (tableNames != null && tableNames.Length > 0)
- {
- foreach (string tablename in tableNames)
- {
- if (!DataSetTables.Contains(tablename))
- {
- DataSetTables.Add(tablename);
- }
- }
- }
- }
- catch { }
- }
- }
- }
-
- string[] tablesName = null;
- if (workspace is IMixedWorkspace)
- {
- IMixedWorkspace mixWorkspace = workspace as IMixedWorkspace;
- PluginGISType plugingistype = (PluginGISType)Core.ServiceLocator.ServiceLocatorFactory.
- ServiceLocator.GetInstance<int>(Core.ServiceLocator.ServiceLocatorKeys.CurGISType);
- if(mixWorkspace.WorkspaceType==WorkspaceType.Oracle && plugingistype==PluginGISType.SuperMap)
- if(mixWorkspace.ADOWorkspace!=null)
- tablesName = mixWorkspace.ADOWorkspace.GetObjects(TableType.Table);
- }
- if(tablesName==null)
- tablesName = workspace.GetObjects(TableType.Table);
- object currentNode = pDataRegForm.DataRegTree.GetFocusedNode();
- if (tablesName != null && tablesName.Length > 0)
- {
- object objAttribute = pDataRegForm.DataRegTree.AddNode(new object[] { CurrentNodeentity.ConnectionID, "属性表" }, currentNode, "属性表");
- foreach (string item in tablesName)
- {
- string regtablename = GetRegName(item, CurrentNodeentity.ConnectionID);
- if (regtablename == null)
- pDataRegForm.DataRegTree.AddNode(new object[] { CurrentNodeentity.ConnectionID, item }, objAttribute, conInfo);
- else
- pDataRegForm.DataRegTree.AddNode(new object[] { CurrentNodeentity.ConnectionID, item + "(注册结构:" + regtablename + ")" }, objAttribute, conInfo);
- }
- bHasChildNode = true;
- }
- List<string> lstFeatureTable = new List<string>();
-
- string[] tablePoint = workspace.GetObjects(TableType.PointFeatureClass);
-
- string[] tableLine = workspace.GetObjects(TableType.PolylineFeatureClass);
-
- string[] tablePolygon = workspace.GetObjects(TableType.PolygoneFeatureClass);
- if (tablePoint != null)
- {
- foreach (string item in tablePoint)
- {
- lstFeatureTable.Add(item);
- }
- }
- if (tablePoint != null)
- {
- foreach (string item in tableLine)
- {
- lstFeatureTable.Add(item);
- }
- }
- if (tablePoint != null)
- {
- foreach (string item in tablePolygon)
- {
- lstFeatureTable.Add(item);
- }
- }
- if (DataSetTables != null && DataSetTables.Count > 0)
- {
- for (int i = 0; i < DataSetTables.Count; i++)
- {
- if (!lstFeatureTable.Contains(DataSetTables[i]))
- {
- lstFeatureTable.Add(DataSetTables[i]);
- }
- }
- }
- object objFeature = pDataRegForm.DataRegTree.AddNode(new object[] { CurrentNodeentity.ConnectionID, "图形要素" }, currentNode, "图形要素");
- if (lstFeatureTable.Count > 0)
- {
- foreach (string item in lstFeatureTable)
- {
- string regtablename = GetRegName(item, CurrentNodeentity.ConnectionID);
- if (regtablename == null)
- pDataRegForm.DataRegTree.AddNode(new object[] { CurrentNodeentity.ConnectionID, item }, objFeature, conInfo);
- else
- pDataRegForm.DataRegTree.AddNode(new object[] { CurrentNodeentity.ConnectionID, item + "(注册结构:" + regtablename + ")" }, objFeature, conInfo);
- }
- bHasChildNode = true;
- }
-
- string[] viewInfo = workspace.GetObjects(TableType.View);
- object objView = pDataRegForm.DataRegTree.AddNode(new object[] { CurrentNodeentity.ConnectionID, "视图" }, currentNode, "视图");
- if (viewInfo != null)
- {
- foreach (string item in viewInfo)
- {
- string regtablename = GetRegName(item, CurrentNodeentity.ConnectionID);
- if (regtablename == null)
- pDataRegForm.DataRegTree.AddNode(new object[] { CurrentNodeentity.ConnectionID, item}, objView, conInfo);
- else
- pDataRegForm.DataRegTree.AddNode(new object[] { CurrentNodeentity.ConnectionID, item + "(注册结构:" + regtablename + ")" }, objView, conInfo);
- }
- bHasChildNode = true;
- }
- pDataRegForm.DataRegTree.Refresh();
- pDataRegForm.DataRegTree.ExpendNode(currentNode);
- }
- catch (Exception ex)
- {
- if(!bHasChildNode)
- MessageManager.Show(MessageType.Warning, "数据不存在!", "系统提示");
- }
- }
- }
- private string GetRegName(string tableName, string connectionID)
- {
- DataRegRow row = new DataRegRow();
- row.TableName = tableName;
- row.ConnectionID = connectionID;
- row = DataRegTable.dataRegTable.GetEntityByRow<DataRegRow>(row);
- if (row == null)
- return null;
- else
- return row.TableAliasName;
- }
- #endregion
-
-
-
- public DataRegParameter DataRegParameter { get; set; }
-
-
-
- public IDataRegForm DataRegForm
- {
- get { return pDataRegForm; }
- }
- #region 数据加载
- protected virtual void RelationGridLoad(object sender)
- {
- IComboBoxColumn pColumn = pDataRegForm.RelationGrid.GetColumn(TableRelationRow.FIELD_CTABLEID) as IComboBoxColumn;
- if (pColumn != null && pColumn.DataSource == null)
- {
- pColumn.CodeFieldName = MetadataTableRow.FIELD_TABLEID;
- pColumn.DisplayFieldName = MetadataTableRow.FIELD_TABLEALIASNAME;
- if (DataRegParameter != null && DataRegParameter.ShowSystemTables)
- pColumn.DataSource = MetadataDataSourceUtils.GetTables(true);
- else
- pColumn.DataSource = MetadataDataSourceUtils.GetTables(false);
- }
- }
-
-
-
- protected virtual void FormLoad(object sender)
- {
- if (DataRegParameter != null && DataRegParameter.ShowSystemTables)
- {
- pDataRegForm.MetadataTableTree.DataSource = MetadataDataSourceUtils.GetTables(true);
- pDataRegForm.DataRegTree.DataSource = InitDataRegTreeData();
- }
- else
- {
- pDataRegForm.MetadataTableTree.DataSource = MetadataDataSourceUtils.GetTables(false);
- pDataRegForm.DataRegTree.DataSource = InitDataRegTreeData();
- }
- }
- private List<TreeDataNode> InitDataRegTreeData()
- {
- IQueryFilter queryFilter = new QueryFilter();
- queryFilter.SelectFields = "*";
- List<ConnectionRow> conndataTables = ConnectionTable.connectionTable.GetEntityList<ConnectionRow>(queryFilter);
- TreeDataNode Root = new TreeDataNode();
- Root.ChildNodes = new List<TreeDataNode>();
- if (conndataTables != null)
- {
- foreach (var item in conndataTables)
- {
- TreeDataNode NewNode = new TreeDataNode();
- NewNode.NodeName = item.ConnectionName;
- NewNode.NodeValue = item.ConnectionID;
- NewNode.NodeData = item;
- Root.ChildNodes.Add(NewNode);
- }
- return Root.ChildNodes;
- }
- return Root.ChildNodes;
- }
- bool bRegTree = false ;
- protected virtual void MetadataTableTreeSelectedIndexChangedEvent(object sender, object data)
- {
- if (!bRegTree )
- {
- if (pDataRegForm.DataRegTree.GetAllNodes() != null && pDataRegForm.DataRegTree.GetAllNodes().Count > 0)
- pDataRegForm.DataRegTree.SetFocusedNode(pDataRegForm.DataRegTree.GetAllNodes()[0]);
- else
- pDataRegForm.DataRegTree.SetFocusedNode(null);
- bRegTree = !bRegTree ;
- }
- if (!(data is IRow))
- {
- SetControlEnable(false);
- }
- else
- {
- IRow tableRow = data as IRow;
- if (tableRow.GetValue<bool>("ISSYSTABLE"))
- {
- SetControlEnable(false);
- }
- else
- {
- SetControlEnable(true);
- }
- }
- }
- protected virtual void DataRegTableTreeSelectedIndexChangedEvent(object sender, object data)
- {
- if (bRegTree)
- {
- if (pDataRegForm.MetadataTableTree.GetAllNodes() != null && pDataRegForm.MetadataTableTree.GetAllNodes().Count > 0)
- pDataRegForm.MetadataTableTree.SetFocusedNode(pDataRegForm.MetadataTableTree.GetAllNodes()[0]);
- else
- pDataRegForm.MetadataTableTree.SetFocusedNode(null);
- bRegTree = !bRegTree;
- }
- SetControlEnable(false);
- pDataRegForm.FieldGrid.DataSource = null;
- ConnectionInfo connectionInfo = pDataRegForm.DataRegTree.SelectedValue as ConnectionInfo;
- if (connectionInfo == null)
- return;
- object obj = pDataRegForm.DataRegTree.GetFocusedNode();
- if (obj == null)
- return;
- string tableName = pDataRegForm.DataRegTree.GetValue(obj, 1).ToString();
- if (tableName.Contains("("))
- tableName = tableName.Remove(tableName.IndexOf("("));
- IWorkspace pWorkspace = Data.General.WorkspaceFactoryProvider.GetWorkspaceFactory().OpenWorkspace(connectionInfo);
- if (pWorkspace == null)
- return;
- ITable pTable = null;
- try
- {
- pTable = pWorkspace.OpenTable(tableName);
- if (pTable == null)
- return;
- }
- catch
- {
- return;
- }
- List<TableMetadataRow> rows = new List<TableMetadataRow>();
- NetDataTypeConvert dataTypeConvert = new NetDataTypeConvert();
- foreach (Field field in pTable.Fields)
- {
- TableMetadataRow row = new TableMetadataRow();
- row.AllowNull = field.AllowNull;
- row.CanShow = field.CanShow;
- row.DataType = dataTypeConvert.Convert(field.DataType);
- row.DataType = row.DataType.Replace("SYSTEM.", "");
- row.Decimaldigits = field.Decimaldigits;
- row.DefaultValue = field.DefaultValue;
- row.FieldAliasName = field.FieldAliasName;
- row.FieldID = field.FieldID;
- row.FieldName = field.FieldName;
- row.IsAuto = field.IsAuto;
- row.IsKey = field.IsKey;
- row.MaxLen = field.MaxLen;
- row.ReadOnly = field.ReadOnly;
- row.UniqueGroup = field.UniqueGroup;
- rows.Add(row);
- }
- if (rows == null || rows.Count <= 0)
- return;
-
- pDataRegForm.FieldGrid.DataSource = rows;
- }
- private void SetControlEnable(bool enable)
- {
- if (pDataRegForm.EditTableButton != null)
- pDataRegForm.EditTableButton.Enabled = enable;
- if (pDataRegForm.DelTableButton != null)
- pDataRegForm.DelTableButton.Enabled = enable;
- if (pDataRegForm.AddFieldButton != null)
- pDataRegForm.AddFieldButton.Enabled = enable;
- if (pDataRegForm.EditFieldButton != null)
- pDataRegForm.EditFieldButton.Enabled = enable;
- if (pDataRegForm.DelFieldButton != null)
- pDataRegForm.DelFieldButton.Enabled = enable;
- if (pDataRegForm.ImportButton != null)
- pDataRegForm.ImportButton.Enabled = enable;
- if (pDataRegForm.AddRelationButton != null)
- pDataRegForm.AddRelationButton.Enabled = enable;
- if (pDataRegForm.EditRelationButton != null)
- pDataRegForm.EditRelationButton.Enabled = enable;
- if (pDataRegForm.DelRelationButton != null)
- pDataRegForm.DelRelationButton.Enabled = enable;
- if (pDataRegForm.SynDomainButton != null)
- pDataRegForm.SynDomainButton.Enabled = enable;
- }
- #endregion
- #region 元数据表操作
-
-
-
-
- protected virtual void AddTableEvent(object sender)
- {
- if (pDataRegForm.MetadataTableTree == null)
- return;
- IAddTableForm addTableForm = context.GetObject("IAddTableForm") as IAddTableForm;
- if (addTableForm != null)
- {
- if (addTableForm.ShowDialog(null) == Tofly.CoreUI.Control.DialogResult.OK)
- {
- if (DataRegParameter != null && DataRegParameter.ShowSystemTables)
- pDataRegForm.MetadataTableTree.DataSource = MetadataDataSourceUtils.GetTables(true);
- else
- pDataRegForm.MetadataTableTree.DataSource = MetadataDataSourceUtils.GetTables(false);
- }
- }
- }
-
-
-
-
- protected virtual void EditTableEvent(object sender)
- {
- if (pDataRegForm.MetadataTableTree == null)
- return;
- if (pDataRegForm.MetadataTableTree.SelectedValue == null)
- return;
- IAddTableForm addTableForm = context.GetObject("IAddTableForm") as IAddTableForm;
- if (addTableForm != null)
- {
- addTableForm.InitControlData();
- addTableForm.DataSource = pDataRegForm.MetadataTableTree.SelectedValue;
- if (addTableForm.ShowDialog(null) == Tofly.CoreUI.Control.DialogResult.OK)
- {
- if (DataRegParameter != null && DataRegParameter.ShowSystemTables)
- pDataRegForm.MetadataTableTree.DataSource = MetadataDataSourceUtils.GetTables(true);
- else
- pDataRegForm.MetadataTableTree.DataSource = MetadataDataSourceUtils.GetTables(false);
- }
- }
- }
-
-
-
-
- protected virtual void DelTableEvent(object sender)
- {
- if (pDataRegForm.MetadataTableTree == null)
- return;
- if (pDataRegForm.MetadataTableTree.SelectedValue == null)
- return;
- if (MessageManager.Show(MessageType.Information, "您确认删除数据吗?",
- "系统提示", MessageButton.YesNo) == MessageResult.Yes)
- {
- pDataRegForm.MetadataTableTree.DeleteFocusedNode(true);
- if (DataRegParameter != null && DataRegParameter.ShowSystemTables)
- pDataRegForm.MetadataTableTree.DataSource = MetadataDataSourceUtils.GetTables(true);
- else
- pDataRegForm.MetadataTableTree.DataSource = MetadataDataSourceUtils.GetTables(false);
- pDataRegForm.DataRegTree.DataSource = InitDataRegTreeData();
- }
- }
- #endregion
- #region 字段操作
- protected virtual void DelFieldButtonClickEvent(object sender)
- {
- if (pDataRegForm.FieldGrid == null || pDataRegForm.FieldGrid.SelectedValue == null)
- return;
- if (MessageManager.Show(MessageType.Information, "您确认删除数据吗?",
- "系统提示", MessageButton.YesNo) == MessageResult.Yes)
- pDataRegForm.FieldGrid.DeleteFocusedRow(true);
- }
- void FieldGrid_DoubleClickEvent(object sender)
- {
- if(pDataRegForm.EditFieldButton.Enabled)
- EditFieldButtonClickEvent(sender);
- }
- protected virtual void EditFieldButtonClickEvent(object sender)
- {
- if (pDataRegForm.FieldGrid == null || pDataRegForm.FieldGrid.SelectedValue == null)
- return;
- IAddFieldForm addFieldForm = context.GetObject("IAddFieldForm") as IAddFieldForm;
- if (addFieldForm != null)
- {
- InitFieldFormCodeTableComboBox(addFieldForm);
- addFieldForm.InitControlData();
- addFieldForm.DataSource = pDataRegForm.FieldGrid.SelectedValue;
- if (addFieldForm.ShowDialog(null) == Tofly.CoreUI.Control.DialogResult.OK)
- {
- pDataRegForm.FieldGrid.EditFocusedRow(addFieldForm.DataSource);
- }
- }
- }
- protected virtual void AddFieldButtonClickEvent(object sender)
- {
-
- int ID = GetMaxID()+1;
- IAddFieldForm addFieldForm = context.GetObject("IAddFieldForm",new object[]{ID}) as IAddFieldForm;
- if (addFieldForm != null)
- {
- InitFieldFormCodeTableComboBox(addFieldForm);
- addFieldForm.BeforeSave += FieldBeforeSave;
- if (addFieldForm.ShowDialog(null) == Tofly.CoreUI.Control.DialogResult.OK)
- {
- if (pDataRegForm.FieldGrid != null)
- pDataRegForm.FieldGrid.AddGridRow(addFieldForm.DataSource);
- }
- }
- }
- private int GetMaxID()
- {
- List<IRow> metadataTable = pDataRegForm.FieldGrid.DataSource as List<IRow>;
- if (metadataTable == null || metadataTable.Count == 0)
- return 0;
- int i=0;
- int id = 0;
- foreach (RowBase row in metadataTable)
- {
- i = int.Parse(row[TableMetadataRow.FIELD_FIELDID].ToString());
- id = id < i ? i : id;
- }
- return id;
- }
-
-
-
-
- private void ImportButton_ClickEvent(object sender)
- {
- List<ITable> tables = SelectDataUtils.OpenTableAndGraphs(false);
- if (tables == null || tables.Count == 0)
- return;
- ITable pTable = tables[0];
- List<TableMetadataRow> rows = new List<TableMetadataRow>();
- MetadataTableRow tableRow = pDataRegForm.MetadataTableTree.SelectedValue as MetadataTableRow;
- if (tableRow == null)
- {
- MessageManager.Show(MessageType.Warning, "请选择或者创建元数据结构!", "提示");
- return;
- }
- List<IRow> metadataTable = pDataRegForm.FieldGrid.DataSource as List<IRow>;
- metadataTable.Sort((one, two) => one.GetValue<Int32>(TableMetadataRow.FIELD_FIELDID).CompareTo(two.GetValue<Int32>(TableMetadataRow.FIELD_FIELDID)));
- int addIndex = metadataTable[metadataTable.Count - 1].GetValue<Int32>(TableMetadataRow.FIELD_FIELDID);
- NetDataTypeConvert dataTypeConvert = new NetDataTypeConvert();
- foreach (Field field in pTable.Fields)
- {
- if (metadataTable.Exists(temp => temp.GetValue<string>(TableMetadataRow.FIELD_FIELDNAME).ToUpper().Equals(field.FieldName.ToUpper())))
- continue;
- addIndex++;
- TableMetadataRow row = new TableMetadataRow();
- row.SetValue(TableMetadataRow.FIELD_TABLEID, tableRow.TableID);
- row.AllowNull = field.AllowNull;
- row.CanShow = field.CanShow;
- row.DataType = dataTypeConvert.Convert(field.DataType);
- row.DataType = row.DataType.Replace("SYSTEM.", "");
- row.Decimaldigits = field.Decimaldigits;
- row.DefaultValue = field.DefaultValue;
- row.FieldAliasName = field.FieldAliasName;
-
- row.FieldID = addIndex;
- row.FieldName = field.FieldName;
- row.IsAuto = field.IsAuto;
- row.IsKey = field.IsKey;
- row.MaxLen = field.MaxLen;
- row.ReadOnly = field.ReadOnly;
- row.UniqueGroup = field.UniqueGroup;
- rows.Add(row);
- }
- if (rows == null || rows.Count <= 0)
- return;
-
- try
- {
- MetadataDataSourceUtils.SaveTableMetadataRow(rows);
- pDataRegForm.FieldGrid.AddGridRows(rows.ToArray());
- }
- catch (Exception ex)
- {
- MessageManager.Show(MessageType.Error, ex.Message, "提示");
- }
-
-
- }
- protected virtual bool FieldBeforeSave(object data)
- {
- RowBase row = data as RowBase;
- if (row != null)
- {
- MetadataTableRow tableRow = pDataRegForm.MetadataTableTree.SelectedValue as MetadataTableRow;
- if (tableRow != null)
- row.SetValue(TableMetadataRow.FIELD_TABLEID, tableRow.TableID);
- }
- return true;
- }
- protected virtual void InitFieldFormCodeTableComboBox(IAddFieldForm addFieldForm)
- {
- addFieldForm.CodeTableComboBox.CodeFieldName = MetadataTableRow.FIELD_TABLEID;
- addFieldForm.CodeTableComboBox.DisplayFieldName = MetadataTableRow.FIELD_TABLEALIASNAME;
- addFieldForm.CodeTableComboBox.DataSource = MetadataDataSourceUtils.GetCodeTables();
- }
- protected virtual void SynDomainButton_ClickEvent(object sender)
- {
- try
- {
- ConnectionInfo connectionInfo = pDataRegForm.DataRegTree.SelectedValue as ConnectionInfo;
- if (connectionInfo == null)
- return;
- object obj = pDataRegForm.DataRegTree.GetFocusedNode();
- if (obj == null)
- return;
- string tableName = pDataRegForm.DataRegTree.GetValue(obj, 1).ToString();
- if (tableName.Contains("("))
- tableName = tableName.Remove(tableName.IndexOf("("));
- IWorkspace pWorkspace = Data.General.WorkspaceFactoryProvider.GetWorkspaceFactory().OpenWorkspace(connectionInfo);
- if (pWorkspace == null)
- return;
- ITable pTable = pWorkspace.OpenTable(tableName);
- if (pTable == null)
- return;
- IUpdateDomain pUpdateDomain = context.GetObject("IUpdateDomain") as IUpdateDomain;
- if (pUpdateDomain.SynchorDomainFormStructure(pTable))
- {
- MessageManager.Show("同步成功!");
- }
- }
- catch
- {
- MessageManager.Show("同步失败!");
- }
- }
- #endregion
- #region 子表操作
-
-
-
-
- protected virtual void DelRelationButtonClickEvent(object sender)
- {
- if (pDataRegForm.RelationGrid == null || pDataRegForm.RelationGrid.SelectedValue == null)
- return;
-
-
-
- if (MessageManager.Show(MessageType.Information, "您确认删除数据吗?",
- "系统提示", MessageButton.YesNo) == MessageResult.Yes)
- pDataRegForm.RelationGrid.DeleteFocusedRow(true);
- }
-
-
-
-
- protected virtual void EditRelationButtonClickEvent(object sender)
- {
- if (pDataRegForm.RelationGrid == null || pDataRegForm.RelationGrid.SelectedValue == null)
- return;
- IAddRelationForm addFieldForm = context.GetObject("IAddRelationForm") as IAddRelationForm;
- if (addFieldForm != null)
- {
- InitCTableComboBox(addFieldForm);
- addFieldForm.InitControlData();
- addFieldForm.DataSource = pDataRegForm.RelationGrid.SelectedValue;
- if (addFieldForm.ShowDialog(null) == Tofly.CoreUI.Control.DialogResult.OK)
- {
- pDataRegForm.RelationGrid.EditFocusedRow(addFieldForm.DataSource);
- }
- }
- }
-
-
-
-
- protected virtual void AddRelationButtonClickEvent(object sender)
- {
- if (pDataRegForm.RelationGrid == null)
- return;
- IAddRelationForm addFieldForm = context.GetObject("IAddRelationForm") as IAddRelationForm;
- if (addFieldForm != null)
- {
- InitCTableComboBox(addFieldForm);
- addFieldForm.BeforeSave += RelationBeforeSave;
- if (addFieldForm.ShowDialog(null) == Tofly.CoreUI.Control.DialogResult.OK)
- pDataRegForm.RelationGrid.AddGridRow(addFieldForm.DataSource);
- }
- }
- protected virtual bool RelationBeforeSave(object data)
- {
- RowBase row = data as RowBase;
- if (row != null)
- {
- MetadataTableRow tableRow = pDataRegForm.MetadataTableTree.SelectedValue as MetadataTableRow;
- if (tableRow != null)
- row.SetValue(TableRelationRow.FIELD_PTABLEID, tableRow.TableID);
- if (row.GetValue<string>(TableRelationRow.FIELD_PTABLEID).Equals(
- row.GetValue<string>(TableRelationRow.FIELD_CTABLEID)))
- {
- throw new Exception("主子表不能是同一个表!");
- }
- }
- return true;
- }
- protected virtual void InitCTableComboBox(IAddRelationForm addFieldForm)
- {
- addFieldForm.CTableComboBox.CodeFieldName = MetadataTableRow.FIELD_TABLEID;
- addFieldForm.CTableComboBox.DisplayFieldName = MetadataTableRow.FIELD_TABLEALIASNAME;
- if (DataRegParameter != null && DataRegParameter.ShowSystemTables)
- addFieldForm.CTableComboBox.DataSource = MetadataDataSourceUtils.GetTables(true);
- else
- addFieldForm.CTableComboBox.DataSource = MetadataDataSourceUtils.GetTables(false);
- }
- #endregion
- #region 注册操作
-
-
-
-
- private void AddRegButton_ClickEvent(object sender)
- {
- addDataRegForm2 = ContextRegistry.GetContext().GetObject("IAddDataRegForm2") as IAddDataRegForm2;
- if (addDataRegForm2 != null)
- {
- if (addDataRegForm2.ShowDialog() == Tofly.CoreUI.Control.DialogResult.OK)
- {
- pDataRegForm.DataRegTree.Clear();
- saveConnectionInfo(addDataRegForm2.ConnectionName, addDataRegForm2.ConnectionInfo);
- pDataRegForm.DataRegTree.DataSource = InitDataRegTreeData();
- }
- }
- }
- private void saveConnectionInfo(string connectionname,ConnectionInfo info)
- {
- string errorinfo = "";
- bool successs = Tofly.Data.Util.DefaultRegTableMetadata.SaveConnectionInfo(connectionname, info, ref errorinfo);
- if (!successs && !String.IsNullOrEmpty(errorinfo))
- MessageManager.Show(MessageType.Error, errorinfo, "提示");
- }
-
-
-
-
- private void DelRegButton_ClickEvent(object sender)
- {
- if (pDataRegForm.RegGrid == null || pDataRegForm.RegGrid.SelectedValue == null)
- return;
- MessageResult result = MessageManager.Show("您确认删除数据吗?", "提示", MessageButton.YesNo, MessageType.Information);
- if (result == MessageResult.Yes)
- pDataRegForm.RegGrid.DeleteFocusedRow(true);
- }
- #endregion
- #region IConfigure 成员
- public IUserControl GetFigureControl
- {
- get { return pDataRegForm as IUserControl; }
- }
- #endregion
- }
- }
|