//获取唯一值添加到listbox_Value中
        private void btn_GetValue_Click(object sender, EventArgs e)
        {
            if (listBox_Field.SelectedItem == null)
            {
                MessageBox.Show("请先选中一个字段!", "提示");
                return;
            }
            listBox_Value.Items.Clear();
            string       strSepratorOfString = "";
            GSOFieldAttr fieldef             = sourcefDataset.GetField(listBox_Field.SelectedItem.ToString().Trim());

            if (fieldef == null)
            {
                return;
            }
            if (fieldef.Type == EnumFieldType.Text)
            {
                strSepratorOfString = "'";
            }

            try
            {
                for (int i = 0; i < sourcefDataset.GetAllFeatures().Length; i++)
                {
                    GSOFeature feature = sourcefDataset.GetFeatureAt(i);
                    if (feature != null)
                    {
                        object fieldValue = feature.GetValue(listBox_Field.SelectedItem.ToString().Trim());
                        if (fieldValue != null && listBox_Value.Items.Contains(strSepratorOfString + fieldValue.ToString() + strSepratorOfString) == false)
                        {
                            listBox_Value.Items.Add(strSepratorOfString + fieldValue.ToString() + strSepratorOfString);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
        private void Set()
        {
            if (listBoxCopyLayerList.SelectedItems.Count <= 0)
            {
                MessageBox.Show("请选择要复制的数据集!", "提示");
                return;
            }
            if (comboBoxTargetDataSource.SelectedItem == null)
            {
                MessageBox.Show("请选择目标数据源!", "提示");
                return;
            }
            if (checkBoxCopyOne.Checked == true && textboxNewLayerName.Text.Trim() == "")
            {
                MessageBox.Show("请给要复制的数据集命名!", "提示");
                return;
            }
            if (checkBoxCopyOne.Checked == true)
            {
                GSODataSource dsTarget = Utility.getDataSourceByFullName(globeControl1, comboBoxTargetDataSource.SelectedItem.ToString().Trim());
                if (dsTarget != null)
                {
                    GSODataset newDataset = dsTarget.GetDatasetByName(textboxNewLayerName.Text.Trim());
                    if (newDataset != null)
                    {
                        MessageBox.Show("输入的新的数据集的名称已存在目标数据源中!", "提示");
                        return;
                    }
                    GSOFeatureDataset newFeatureDataset = dsTarget.CreateFeatureDataset(textboxNewLayerName.Text.Trim());
                    if (newFeatureDataset == null)
                    {
                        MessageBox.Show("输入的新数据集的名称不符合要求!", "提示");
                        return;
                    }
                    GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());
                    if (ds != null)
                    {
                        GSODataset        dataset        = ds.GetDatasetByName(listBoxCopyLayerList.SelectedItem.ToString().Trim());
                        GSOFeatureDataset featureDataset = dataset as GSOFeatureDataset;
                        if (featureDataset != null)
                        {
                            try
                            {
                                featureDataset.Open();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "提示");
                                if (featureDataset.IsOpened == true)
                                {
                                    featureDataset.Close();
                                }
                                return;
                            }
                            //向新数据集写入字段
                            for (int i = 0; i < featureDataset.FieldCount; i++)
                            {
                                GSOFieldAttr fieldFromDs = featureDataset.GetField(i);
                                newFeatureDataset.AddField(fieldFromDs);
                            }

                            //向新的要素集写入数据
                            for (int i = 0; i < featureDataset.GetAllFeatures().Length; i++)
                            {
                                GSOFeature featureInDs       = featureDataset.GetFeatureAt(i);
                                GSOFeature featureInTargetDs = featureInDs.Clone();
                                featureInDs.Dispose();
                                newFeatureDataset.AddFeature(featureInTargetDs);
                            }
                            newFeatureDataset.Save();
                            featureDataset.Close();
                            MessageBox.Show("复制成功!", "提示");
                        }
                    }
                }
            }
            else if (checkBoxCopyMult.Checked == true)
            {
                GSODataSource dsTarget = Utility.getDataSourceByFullName(globeControl1, comboBoxTargetDataSource.SelectedItem.ToString().Trim());
                if (dsTarget != null)
                {
                    string datasetNames = "";
                    for (int i = 0; i < listBoxCopyLayerList.SelectedItems.Count; i++)
                    {
                        GSODataset datasetInTargetDs = dsTarget.GetDatasetByName(listBoxCopyLayerList.SelectedItems[i].ToString().Trim());
                        if (datasetInTargetDs != null)
                        {
                            datasetNames += "\"" + listBoxCopyLayerList.SelectedItems[i].ToString().Trim() + "\" ";
                        }
                    }
                    if (datasetNames != "")
                    {
                        MessageBox.Show("数据集名称" + datasetNames + "在目标数据源中已存在", "提示");
                        return;
                    }
                    GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());
                    if (ds != null)
                    {
                        progressBar1.Visible = true;
                        progressBar1.Maximum = listBoxCopyLayerList.SelectedItems.Count - 1;
                        progressBar1.Minimum = 0;
                        for (int j = 0; j < listBoxCopyLayerList.SelectedItems.Count; j++)
                        {
                            //获取要复制的要素集
                            GSODataset        datasetInDs        = ds.GetDatasetByName(listBoxCopyLayerList.SelectedItems[j].ToString().Trim());
                            GSOFeatureDataset featureDatasetInDs = datasetInDs as GSOFeatureDataset;
                            if (featureDatasetInDs == null)
                            {
                                continue;
                            }
                            featureDatasetInDs.Open();

                            //创建新的数据库要素集
                            GSOFeatureDataset featureDatasetInTargetDs = dsTarget.CreateFeatureDataset(listBoxCopyLayerList.SelectedItems[j].ToString().Trim());

                            if (featureDatasetInTargetDs == null)
                            {
                                continue;
                            }
                            featureDatasetInTargetDs.Open();
                            for (int i = 0; i < featureDatasetInDs.FieldCount; i++)
                            {
                                GSOFieldAttr fieldInDs = featureDatasetInDs.GetField(i);
                                featureDatasetInTargetDs.AddField(fieldInDs);
                            }

                            //(2)向新的要素集写入数据
                            for (int i = 0; i < featureDatasetInDs.GetAllFeatures().Length; i++)
                            {
                                GSOFeature featureInDs       = featureDatasetInDs.GetFeatureAt(i);
                                GSOFeature featureInTargetDs = featureInDs.Clone();
                                featureInDs.Dispose();
                                featureDatasetInTargetDs.AddFeature(featureInTargetDs);
                            }
                            featureDatasetInTargetDs.Save();
                            featureDatasetInTargetDs.Close();
                            featureDatasetInDs.Close();

                            progressBar1.Value = j;
                        }
                        progressBar1.Visible = false;
                        MessageBox.Show("数据复制成功!", "提示");
                    }
                }
            }
        }
        private void btn_Union_Click(object sender, EventArgs e)
        {
            if (comboBoxTargetDataSource.SelectedItem == null)
            {
                MessageBox.Show("请选择目标数据源!", "提示");
                return;
            }
            string newLayerName = textBoxUnionLayerName.Text.Trim();

            if (newLayerName == "")
            {
                MessageBox.Show("请输入目标数据集名称!", "提示");
                return;
            }
            if (comboBoxDataSourceList1.SelectedItem == null)
            {
                MessageBox.Show("请选择要合并的数据源1!", "提示");
                return;
            }
            if (comboBoxUnionLayerList1.SelectedItem == null)
            {
                MessageBox.Show("请选择要合并的要素集1!", "提示");
                return;
            }
            if (comboBoxDataSourceList2.SelectedItem == null)
            {
                MessageBox.Show("请选择要合并的数据源2!", "提示");
                return;
            }
            if (comboBoxUnionLayerList2.SelectedItem == null)
            {
                MessageBox.Show("请选择要合并的要素集2!", "提示");
                return;
            }
            GSODataSource dsTarget = Utility.getDataSourceByFullName(globeControl1, comboBoxTargetDataSource.SelectedItem.ToString().Trim());

            if (dsTarget != null)
            {
                GSODataset dataset = dsTarget.GetDatasetByName(newLayerName);
                if (dataset != null)
                {
                    MessageBox.Show("目标数据集名称已存在目标数据源中!", "提示");
                    return;
                }
                GSOFeatureDataset featureDatasetInTargetDs = dsTarget.CreateFeatureDataset(newLayerName);
                if (featureDatasetInTargetDs == null)
                {
                    MessageBox.Show("目标数据集名称不符合要求!", "提示");
                    return;
                }
                GSODataSource dsUnion1 = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList1.SelectedItem.ToString().Trim());
                GSODataSource dsUnion2 = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList2.SelectedItem.ToString().Trim());
                if (dsUnion1 != null && dsUnion2 != null)
                {
                    GSOFeatureDataset datasetInUnionDs1 = dsUnion1.GetDatasetByName(comboBoxUnionLayerList1.SelectedItem.ToString().Trim()) as GSOFeatureDataset;
                    GSOFeatureDataset datasetInUnionDs2 = dsUnion1.GetDatasetByName(comboBoxUnionLayerList2.SelectedItem.ToString().Trim()) as GSOFeatureDataset;
                    if (datasetInUnionDs1 != null && datasetInUnionDs2 != null)
                    {
                        //判断要合并的数据集结构是否相同
                        datasetInUnionDs1.Open();
                        datasetInUnionDs2.Open();
                        if (datasetInUnionDs1.FieldCount != datasetInUnionDs2.FieldCount)
                        {
                            MessageBox.Show("要合并的数据集结构不相同,无法合并!", "错误");
                            return;
                        }
                        for (int i = 0; i < datasetInUnionDs1.FieldCount; i++)
                        {
                            if (datasetInUnionDs1.GetField(i).Equals(datasetInUnionDs2.GetField(i)) == false)
                            {
                                MessageBox.Show("要合并的数据集结构不相同,无法合并!", "错误");
                                return;
                            }
                        }
                        featureDatasetInTargetDs.Open();
                        for (int i = 0; i < datasetInUnionDs1.FieldCount; i++)
                        {
                            GSOFieldAttr fieldInUnionDs = datasetInUnionDs1.GetField(i);
                            featureDatasetInTargetDs.AddField(fieldInUnionDs);
                        }
                        //向新的数据集写入数据
                        for (int i = 0; i < datasetInUnionDs1.GetAllFeatures().Length; i++) //循环添加第一个要素集的所有feature到新数据集中
                        {
                            GSOFeature featureInUnionDs1 = datasetInUnionDs1.GetFeatureAt(i);
                            GSOFeature featureInTargetDs = featureInUnionDs1.Clone();
                            featureDatasetInTargetDs.AddFeature(featureInTargetDs);
                        }
                        for (int i = 0; i < datasetInUnionDs2.GetAllFeatures().Length; i++) //循环添加第一个要素集的所有feature到新数据集中
                        {
                            GSOFeature featureInUnionDs2 = datasetInUnionDs2.GetFeatureAt(i);
                            GSOFeature featureInTargetDs = featureInUnionDs2.Clone();
                            featureDatasetInTargetDs.AddFeature(featureInTargetDs);
                        }
                        featureDatasetInTargetDs.Save();
                        featureDatasetInTargetDs.Close();
                        datasetInUnionDs1.Close();
                        datasetInUnionDs2.Close();
                        MessageBox.Show("数据集合并成功!", "提示");
                        this.Close();
                    }
                }
            }
        }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            GSOLayer          l1      = ctl.Globe.Layers[comboBoxLayerSource.SelectedIndex];
            GSOFeatureDataset flayer1 = l1.Dataset as GSOFeatureDataset;
            GSOLayer          l2      = ctl.Globe.Layers[comboBoxLayerTarget.SelectedIndex];
            GSOFeatureDataset flayer2 = l2.Dataset as GSOFeatureDataset;

            string sourceIDFieldName = comboBoxFieldSource.SelectedItem.ToString().Trim();
            string targetIDFieldName = comboBoxFiledTarget.SelectedItem.ToString().Trim();

            if (sourceIDFieldName == null || targetIDFieldName == null)
            {
                MessageBox.Show("请选择唯一标识字段!", "提示");
                return;
            }
            if (isSameType(flayer1, sourceIDFieldName, flayer2, targetIDFieldName) == false)
            {
                MessageBox.Show("请选择类型相同的唯一标识字段!", "提示");
                return;
            }
            //for (int i = 1; i <= changeCount; i++)
            {
                string sourceChangeFieldName = comboBoxChangeSource1.SelectedItem == null ? "" : comboBoxChangeSource1.SelectedItem.ToString().Trim();
                string targetChangeFieldName = comboBoxChangeTarget1.SelectedItem == null ? "" : comboBoxChangeTarget1.SelectedItem.ToString().Trim();
                if (sourceChangeFieldName == "" || targetChangeFieldName == "")
                {
                    MessageBox.Show("请选择要修改的字段!", "提示");
                    return;
                }
                if (isSameType(flayer1, sourceChangeFieldName, flayer2, targetChangeFieldName) == false)
                {
                    MessageBox.Show("请选择类型相同的要修改的字段!", "提示");
                    return;
                }
                for (int j = 0; j < flayer1.GetAllFeatures().Length; j++)
                {
                    if (flayer1.GetFeatureAt(j) == null)
                    {
                        continue;
                    }
                    object      fieldValue          = flayer1.GetFeatureAt(j).GetValue(sourceIDFieldName);
                    GSOFeatures targetLayerFeatures = flayer2.GetFeatureByFieldValue(targetIDFieldName, fieldValue.ToString().Trim(), true);
                    if (targetLayerFeatures != null)
                    {
                        for (int m = 0; m < targetLayerFeatures.Length; m++)
                        {
                            GSOFeature targetLayerFeature = targetLayerFeatures[m];
                            if (targetLayerFeature != null)
                            {
                                fieldValue = flayer1.GetFeatureAt(j).GetValue(sourceChangeFieldName);
                                if (flayer1.GetField(sourceChangeFieldName) != null)
                                {
                                    switch (flayer1.GetField(sourceChangeFieldName).Type)
                                    {
                                    case EnumFieldType.Double:
                                        double dFieldValue = 0.0;
                                        if (double.TryParse(fieldValue.ToString(), out dFieldValue) == true)
                                        {
                                            targetLayerFeature.SetFieldValue(targetChangeFieldName, dFieldValue);
                                        }
                                        break;

                                    case EnumFieldType.INT32:
                                        int intFieldValue = 0;
                                        if (int.TryParse(fieldValue.ToString(), out intFieldValue) == true)
                                        {
                                            targetLayerFeature.SetFieldValue(targetChangeFieldName, intFieldValue);
                                        }
                                        break;

                                    case EnumFieldType.DateTime:
                                        DateTime datatimeFieldValue = DateTime.Now;
                                        if (DateTime.TryParse(fieldValue.ToString(), out datatimeFieldValue) == true)
                                        {
                                            targetLayerFeature.SetFieldValue(targetChangeFieldName, datatimeFieldValue);
                                        }
                                        break;

                                    case EnumFieldType.Text:
                                        targetLayerFeature.SetFieldValue(targetChangeFieldName, fieldValue.ToString());
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            MessageBox.Show("修改成功!", "提示");
        }