public bool SaveDomain(IYTDomain domain) { try { if (_workspace == null) { Connect(); } if (_domains == null) { _domains = new List <IYTDomain>(); } ITable pTable = _workspace.OpenTable("YT_TEMPLATE_DOMAIN"); IWorkspaceEdit pWksEdit = _workspace as IWorkspaceEdit; pWksEdit.StartEditing(true); pWksEdit.StartEditOperation(); IRow pRow; int oldID = domain.ID; if (oldID > 0) { pRow = pTable.GetRow(domain.ID); } else { pRow = pTable.CreateRow(); } domain.UpdateRow(pRow); pWksEdit.StopEditOperation(); pWksEdit.StopEditing(true); if (oldID <= 0) { _domains.Add(domain); } ComReleaser.ReleaseCOMObject(pTable); DisConnect(); return(true); } catch (Exception ex) { MessageService.Current.Warn("系统发生错误:" + ex.Message); return(false); throw; } }
private void LoadObjectEdit() { TreeNode currentNode = trvDatabase.SelectedNode; if (currentNode.Parent.Text == "模板") { IObjectTemplate template = currentNode.Tag as IObjectTemplate; frmEditTemplate frm = new frmEditTemplate(); frm.SetTemplate(template); frm.SetDatabase(template.Database); frm.ShowDialog(); currentNode.Tag = frm.GetTemplate(); currentNode.Text = frm.GetTemplate().Name; } if (currentNode.Parent.Text == "数据字典") { IYTDomain domain = currentNode.Tag as IYTDomain; frmEditDomain frm = new frmEditDomain(); frm.SetDatabase(currentNode.Parent.Parent.Tag as ITemplateDatabase); frm.SetDomain(domain); DialogResult result = frm.ShowDialog(); if (result == DialogResult.OK) { TreeNode pNode = currentNode.Parent; pNode.Nodes.Clear(); LoadDomains(pNode.Parent.Tag as ITemplateDatabase, pNode); } currentNode.Tag = frm.GetDomain(); } if (currentNode.Parent.Text == "数据集") { IObjectDataset dataset = currentNode.Tag as IObjectDataset; frmEditDataset frm = new frmEditDataset(); frm.SetDatabase(currentNode.Parent.Parent.Tag as ITemplateDatabase); frm.Dataset = dataset; DialogResult result = frm.ShowDialog(); if (result == DialogResult.OK) { currentNode.Tag = frm.Dataset; currentNode.Text = frm.Dataset.Name; } } }
private void DeleteObject() { TreeNode currentNode = trvDatabase.SelectedNode; ITemplateDatabase database = currentNode.Parent.Parent.Tag as ITemplateDatabase; if (currentNode.Parent.Text == "模板") { IObjectTemplate template = currentNode.Tag as IObjectTemplate; database.DeleteObject(template.ID, enumTemplateObjectType.FeatureClass); } if (currentNode.Parent.Text == "数据字典") { IYTDomain domain = currentNode.Tag as IYTDomain; database.DeleteObject(domain.ID, enumTemplateObjectType.Domain); } if (currentNode.Parent.Text == "数据集") { IObjectDataset dataset = currentNode.Tag as IObjectDataset; database.DeleteObject(dataset.ID, enumTemplateObjectType.FeatureDataset); } }
public void LoadDomains() { if (_workspace == null) { Connect(); } if (_domains != null) { _domains.Clear(); } else { _domains = new List <IYTDomain>(); } ITable pDomainTable = _workspace.OpenTable("YT_TEMPLATE_DOMAIN"); ITableSort tableSort = new TableSort(); tableSort.Table = pDomainTable; tableSort.Fields = "DomainName"; tableSort.Sort(null); ICursor pCursor = tableSort.Rows; int[] fieldIndexes = new int[3]; IRow pRow = pCursor.NextRow(); IYTDomain domain = null; while (pRow != null) { domain = new YTDomain(pRow); _domains.Add(domain); pRow = pCursor.NextRow(); } ComReleaser.ReleaseCOMObject(pCursor); ComReleaser.ReleaseCOMObject(pDomainTable); }
private bool SaveDomain() { IYTDomain domain = new YTDomain(); domain.Name = txtName.EditValue == null ? "" : txtName.EditValue.ToString(); domain.Description = txtDescription.EditValue == null ? "" : txtDescription.EditValue.ToString(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { string code = dataGridView1.Rows[i].Cells[0].Value == null ? "" : dataGridView1.Rows[i].Cells[0].Value.ToString(); string description = dataGridView1.Rows[i].Cells[1].Value == null ? "" : dataGridView1.Rows[i].Cells[1].Value.ToString(); if (string.IsNullOrEmpty(code)) { continue; } YTDomainValue pair = new YTDomainValue() { Value = code, Description = description }; domain.ValuePairs.Add(pair); } int back = _database.GetObjectID(domain.Name, enumTemplateObjectType.Domain); if (back > 0 && back != _domain.ID) { MessageBox.Show("该数据字典已经存在,请改名后保存!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } domain.ID = _domain.ID; return(_database.SaveDomain(domain)); _domain = domain; }
public void SetDomain(IYTDomain pDomain) { _domain = pDomain; LoadDomain(); }
public List <IPipelineLayer> ReadLayersFromDatabase() { List <IPipelineLayer> layers = new List <IPipelineLayer>(); ITable pCodeTable = _workspace.OpenTable("YT_PIPE_CODE"); ITableSort tableSort = new TableSortClass(); tableSort.Table = pCodeTable; tableSort.Fields = "Priority"; tableSort.Sort(null); ICursor pCursor = tableSort.Rows; IRow pRow = pCursor.NextRow(); int codeIdx = pCursor.FindField("PipeCode"); int classIdx = pCursor.FindField("ClassCode"); int nameIdx = pCursor.FindField("PipeName"); int autoIdx = pCursor.FindField("AutoNames"); int priIdx = pCursor.FindField("Priority"); while (pRow != null) { IPipelineLayer oneLayer = new PipelineLayer() { Code = pRow.Value[codeIdx].ToString(), Name = pRow.Value[nameIdx].ToString(), AutoNames = pRow.Value[autoIdx].ToString(), Layers = new List <IBasicLayerInfo>(), ClassCode = pRow.Value[classIdx].ToString() }; layers.Add(oneLayer); pRow = pCursor.NextRow(); } Marshal.ReleaseComObject(pCursor); Marshal.ReleaseComObject(tableSort); Marshal.ReleaseComObject(pCodeTable); List <IYTDomain> domains = new List <IYTDomain>(); pCodeTable = _workspace.OpenTable("YT_PIPE_DOMAIN"); pCursor = pCodeTable.Search(null, false); pRow = pCursor.NextRow(); nameIdx = pCursor.FindField("DomainName"); autoIdx = pCursor.FindField("DomainValues"); while (pRow != null) { string domainName = pRow.Value[nameIdx].ToString(); string domainValues = pRow.Value[autoIdx].ToString(); IYTDomain onedomain = new YTDomain(domainName, domainValues); domains.Add(onedomain); pRow = pCursor.NextRow(); } Marshal.ReleaseComObject(pCursor); Marshal.ReleaseComObject(pCodeTable); List <IPipelineTemplate> templates = new List <IPipelineTemplate>(); //! 先读取模板 pCodeTable = _workspace.OpenTable("YT_PIPE_FIELD"); tableSort = new TableSortClass(); tableSort.Table = pCodeTable; tableSort.Fields = "TemplateName"; tableSort.Sort(null); pCursor = tableSort.Rows; string oldTemplate = ""; int[] fieldIndexes = new int[10]; pRow = pCursor.NextRow(); fieldIndexes[0] = pRow.Fields.FindField("TemplateName"); fieldIndexes[1] = pRow.Fields.FindField("TypeName"); fieldIndexes[2] = pRow.Fields.FindField("FieldName"); fieldIndexes[3] = pRow.Fields.FindField("FieldAliasName"); fieldIndexes[4] = pRow.Fields.FindField("FieldType"); fieldIndexes[5] = pRow.Fields.FindField("FieldLength"); fieldIndexes[6] = pRow.Fields.FindField("FieldPrecision"); fieldIndexes[7] = pRow.Fields.FindField("AllowNull"); fieldIndexes[8] = pRow.Fields.FindField("AutoValues"); fieldIndexes[9] = pRow.Fields.FindField("IsKey"); // fieldIndexes[10] = pRow.Fields.FindField("Domains"); IPipelineTemplate oneTemplate = null; while (pRow != null) { string templateName = pRow.Value[fieldIndexes[0]].ToString(); if (!templateName.Equals(oldTemplate)) { if (oneTemplate != null) { templates.Add(oneTemplate); } oneTemplate = new PipelineTemplate() { Name = templateName, Fields = new List <IYTField>() }; oldTemplate = templateName; } IYTField field = new YTField() { TypeName = pRow.Value[fieldIndexes[1]].ToString(), Name = pRow.Value[fieldIndexes[2]].ToString(), AliasName = pRow.Value[fieldIndexes[3]].ToString(), Length = Convert.ToInt32(pRow.Value[fieldIndexes[5]].ToString()), Precision = Convert.ToInt32(pRow.Value[fieldIndexes[6]].ToString()), AllowNull = Convert.ToInt32(pRow.Value[fieldIndexes[7]].ToString()) == -1 ? true : false, AutoNames = pRow.Value[fieldIndexes[8]].ToString(), FieldType = FieldHelper.ConvertFromString(pRow.Value[fieldIndexes[4]].ToString()) }; oneTemplate.Fields.Add(field); pRow = pCursor.NextRow(); } if (oneTemplate != null) { templates.Add(oneTemplate); } Marshal.ReleaseComObject(pCursor); Marshal.ReleaseComObject(tableSort); Marshal.ReleaseComObject(pCodeTable); List <IBasicLayerInfo> basicInfos = new List <IBasicLayerInfo>(); pCodeTable = _workspace.OpenTable("YT_PIPE_LAYER"); tableSort = new TableSortClass(); tableSort.Table = pCodeTable; tableSort.Fields = "Priority,LayerName"; tableSort.Sort(null); pCursor = tableSort.Rows; pRow = pCursor.NextRow(); fieldIndexes = new int[8]; fieldIndexes[0] = pRow.Fields.FindField("PipeCode"); fieldIndexes[1] = pRow.Fields.FindField("BasicName"); fieldIndexes[2] = pRow.Fields.FindField("LayerName"); fieldIndexes[3] = pRow.Fields.FindField("AutoNames"); fieldIndexes[4] = pRow.Fields.FindField("Priority"); fieldIndexes[5] = pRow.Fields.FindField("DataType"); fieldIndexes[6] = pRow.Fields.FindField("Template"); fieldIndexes[7] = pRow.Fields.FindField("Domains"); while (pRow != null) { string pipeCode = pRow.Value[fieldIndexes[0]].ToString(); IPipelineLayer oneLayer = layers.Find(c => c.Code == pipeCode); if (oneLayer == null) { pRow = pCursor.NextRow(); continue; } enumPipelineDataType dataType = Yutai.Pipeline.Config.Helpers.EnumHelper.ConvertDataTypeFromString( pRow.Value[fieldIndexes[5]].ToString().Trim()); IBasicLayerInfo basicLayer = new BasicLayerInfo() { Name = pRow.Value[fieldIndexes[1]].ToString(), AliasName = pRow.Value[fieldIndexes[2]].ToString(), AutoNames = pRow.Value[fieldIndexes[3]].ToString(), DataType = dataType, TemplateName = pRow.Value[fieldIndexes[6]].ToString(), Fields = new List <IYTField>() }; if (pRow.Value[fieldIndexes[6]] != null) { IPipelineTemplate template = templates.Find(c => c.Name == basicLayer.TemplateName); if (template != null) { foreach (IYTField field in template.Fields) { basicLayer.Fields.Add(new YTField(field)); } } } string domainStr = pRow.Value[fieldIndexes[7]] == DBNull.Value ? string.Empty : pRow.Value[fieldIndexes[7]].ToString(); if (!string.IsNullOrEmpty(domainStr)) { //获得Domainzhi值 string[] domainPairs = domainStr.Split('/'); for (int j = 0; j < domainPairs.Length; j++) { string[] domainPair = domainPairs[j].Split(':'); string fieldName = domainPair[0]; string domainName = domainPair[1]; IYTDomain findDomain = domains.FirstOrDefault(c => c.DomainName == domainName); if (findDomain != null) { IYTField pField = basicLayer.Fields.FirstOrDefault(c => c.TypeName == fieldName); if (pField != null) { pField.Domain = new YTDomain(findDomain.DomainName, findDomain.DomainValues); } } } } oneLayer.Layers.Add(basicLayer); pRow = pCursor.NextRow(); } Marshal.ReleaseComObject(pCursor); Marshal.ReleaseComObject(tableSort); Marshal.ReleaseComObject(pCodeTable); return(layers); }
private void mnuPasteObject_Click(object sender, EventArgs e) { if (_copyObject == null) { return; } TreeNode currentNode = trvDatabase.SelectedNode; ITemplateDatabase database = currentNode.Tag as ITemplateDatabase; if (_copyObject.Parent.Text == "模板") { IObjectTemplate template = _copyObject.Tag as IObjectTemplate; template.ID = -1; template.Database = database; frmEditTemplate frm = new frmEditTemplate(); frm.SetTemplate(template); frm.SetDatabase(database); DialogResult result = frm.ShowDialog(); if (result == DialogResult.OK) { TreeNode pNode = currentNode.Nodes[0]; pNode.Nodes.Clear(); LoadTemplates(database, pNode); } } if (_copyObject.Parent.Text == "数据字典") { IYTDomain domain = _copyObject.Tag as IYTDomain; domain.ID = -1; frmEditDomain frm = new frmEditDomain(); frm.SetDatabase(database); frm.SetDomain(domain); DialogResult result = frm.ShowDialog(); if (result == DialogResult.OK) { TreeNode pNode = currentNode.Nodes[1]; pNode.Nodes.Clear(); LoadDomains(database, pNode); } //currentNode.Tag = frm.GetDomain(); } if (_copyObject.Parent.Text == "数据集") { IObjectDataset dataset = _copyObject.Tag as IObjectDataset; dataset.ID = -1; frmEditDataset frm = new frmEditDataset(); frm.SetDatabase(database); frm.Dataset = dataset; DialogResult result = frm.ShowDialog(); if (result == DialogResult.OK) { TreeNode pNode = currentNode.Nodes[2]; pNode.Nodes.Clear(); LoadDatasets(database, pNode); } } _copyObject = null; }