Beispiel #1
0
        public LabelStyle(int idT)
        {
            _idT = idT;
            _ti  = classesOfMetods.getTableInfo(idT);
            String layerName = Program.RelationVisbleBdUser.GetNameInBd(idT);

            tLayer = Program.app.mapLib.getLayer(layerName);
            save   = false;

            CenterToParent();
            InitializeComponent();

            if (!SyncController.HasRight(idT))
            {
                button_save.Enabled = false;
            }
        }
        /// <summary>Делать если есть слои для выбора
        /// </summary>
        private void SetButtonStateForSelectLayer()
        {
            wm.TbbSnapToPoint.IsEnabled                = true;
            wm.TbbSnapToLine.IsEnabled                 = true;
            wm.TbtbSelectingObject.IsEnabled           = true;
            wm.TbtbSelectingObjectsRectangle.IsEnabled = true;
            wm.TbtbSelectingObjectPolygon.IsEnabled    = true;
            wm.TbbUnselectingObjects.IsEnabled         = true;
            CanCopyInSQLite           = false;
            CanDeleteGeometry         = false;
            wm.TbbRotateBtn.IsEnabled = false;


            wm.TbtbRotateMouse.IsEnabled = false;
            if (_currentTable is CosM.CosmeticTableBaseM)
            {
                wm.TbtbRotateMouse.IsEnabled = true;
            }
            else if (_currentTable is Interfaces.tablesInfo && _writeTable)
            {
                tablesInfo tInfo = classesOfMetods.getTableInfo((_currentTable as Interfaces.tablesInfo).idTable);
                if (tInfo != null && tInfo.GeomType_GC.Trim() != "POINT")
                {
                    wm.TbtbRotateMouse.IsEnabled = true;
                }
            }

            wm.TbtbMoveObj.IsEnabled    = (_currentTable != null) && (_writeTable || _currentTable is CosM.CosmeticTableBaseM);
            wm.TbtbVertexEdit.IsEnabled = false;
            CanNodeAdd  = false;
            CanNodeMove = false;
            CanNodeDel  = false;
            wm.TbtbJoinGeometry.IsEnabled                      = false;
            wm.TbtbIntersectGeometry.IsEnabled                 = false;
            wm.TbtbJoinIntersectGeometry.IsEnabled             = false;
            wm.TbtbSymDifference.IsEnabled                     = false;
            wm.TbtbSeparatGeometry.IsEnabled                   = false;
            wm.TbtbClippingPolygonAnotherPolygon.IsEnabled     = false;
            wm.TbtbClippingPolygonBySpecifyingPoints.IsEnabled = false;
            wm.TbtbClippingPolygonBySpecifyingLine.IsEnabled   = false;
        }
Beispiel #3
0
        private void button_preview_Click(object sender, EventArgs e)
        {
            String result = parseResult(textBox1.Text);

            if (result.Replace(" ", "") == "")
            {
                MessageBox.Show(Rekod.Properties.Resources.LabelControl_NotEmpty, Properties.Resources.AWT_EditLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (result.Contains("SELECT") || result.Contains("DROP") || result.Contains("INSERT") || result.Contains("UPDATE") || result.Contains("DELETE"))
            {
                MessageBox.Show(Rekod.Properties.Resources.LabelControl_InvalidExpression, Properties.Resources.AWT_EditLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            tablesInfo ti     = classesOfMetods.getTableInfo(_idT);
            SqlWork    sqlCmd = new SqlWork(true);

            sqlCmd.sql = string.Format("SELECT {0} FROM \"{1}\".\"{2}\" LIMIT 1", result, ti.nameSheme, ti.nameDB);
            try
            {
                sqlCmd.ExecuteReader(null);
                if (sqlCmd.CanRead())
                {
                    MessageBox.Show(sqlCmd.GetValue <string>(0));
                }
                else
                {
                    MessageBox.Show(Rekod.Properties.Resources.LabelControl_ErrorShowResult, Properties.Resources.AWT_EditLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Rekod.Properties.Resources.LabelControl_InvalidExpression, Properties.Resources.AWT_EditLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                sqlCmd.Close();
            }
        }
Beispiel #4
0
        private void button5_Click(object sender, EventArgs e)
        {
            int    splitPlace = textBox1.SelectionStart;
            String leftPart   = textBox1.Text.Substring(0, splitPlace);
            String rightPart  = textBox1.Text.Substring(splitPlace);


            if (textBox2.Text.Replace(" ", "") == "")
            {
                MessageBox.Show(Properties.Resources.LabelControl_NotEmpty, Properties.Resources.AWT_EditLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (textBox2.Text.Contains("SELECT") || textBox2.Text.Contains("DROP") || textBox2.Text.Contains("INSERT") || textBox2.Text.Contains("UPDATE") || textBox2.Text.Contains("DELETE"))
            {
                MessageBox.Show(Rekod.Properties.Resources.LabelControl_InvalidExpression, Properties.Resources.AWT_EditLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            tablesInfo ti     = classesOfMetods.getTableInfo(_idT);
            SqlWork    sqlCmd = new SqlWork(true);

            sqlCmd.sql = string.Format("SELECT {0} FROM \"{1}\".\"{2}\" LIMIT 1", textBox2.Text, ti.nameSheme, ti.nameDB);
            try
            {
                sqlCmd.ExecuteNonQuery(null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Rekod.Properties.Resources.LabelControl_InvalidExpression, Properties.Resources.AWT_EditLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                sqlCmd.Close();
            }

            textBox1.Text            = leftPart + (((leftPart.Replace(" ", "") != "") ? "+" : "") + "{" + textBox2.Text + "}") + rightPart;
            textBox1.SelectionStart  = textBox1.Text.Length;
            textBox1.SelectionLength = 0;
            textBox1.Focus();
        }
Beispiel #5
0
 public ExportToExcel(tablesInfo ti, List <string> listParams)
 {
     InitializeComponent();
     _tableInfo  = ti;
     _listParams = listParams;
 }
        public void Create(object parameter = null)
        {
            if (CanCreate)
            {
                cti.ThreadProgress.ShowWait(_progressKey);
                try
                {
                    CanLoad    = false;
                    _tableInfo = CreateTable();

                    if (_tableInfo != null)
                    {
                        DataGrid importGrid = parameter as DataGrid;
                        var      headers    = FindChild <StackPanel>(importGrid, "HeaderStackPanel");

                        List <FieldMatch> fields = new List <FieldMatch>();
                        for (int i = 0; i < headers.Count - 1; i++)
                        {
                            bool loadField = (bool)FindChild <CheckBox>(importGrid, "LoadField")[i + 1].IsChecked;
                            if (!loadField)
                            {
                                continue;
                            }
                            string          nameDB      = FindChild <TextBox>(importGrid, "headerDBName")[i + 1].Text;
                            string          nameSystem  = FindChild <TextBox>(importGrid, "headerSystemName")[i + 1].Text;
                            string          name        = (string)importGrid.Columns[i].Header;
                            var             type_item   = FindChild <ComboBox>(importGrid, "headerFieldTypeCb")[i + 1].SelectedValue;
                            EnumWrapper     enumWrapper = type_item as EnumWrapper;
                            AbsM.EFieldType eFieldType  = (AbsM.EFieldType)enumWrapper.Value;

                            if (loadField)
                            {
                                var field = CreateField(nameDB, nameSystem, (int)eFieldType, name, _tableInfo);
                                if (field != null)
                                {
                                    fields.Add(field);
                                }
                            }
                        }

                        var cls = new classesOfMetods();
                        Program.field_info = cls.loadFieldInfo();

                        _importer.SetTableInfo(_tableInfo);
                        if (_importer is SHPImporter)
                        {
                            (_importer as SHPImporter).Load(fields, _tableType == AbsM.ETableType.MapLayer);
                        }
                        else
                        {
                            _importer.Load(fields);
                        }
                        if (Program.sscUser != null)
                        {
                            DBTablesEdit.SyncController.RegisterTable(_tableInfo.idTable, Group.name);
                        }
                    }
                    else
                    {
                        cti.ThreadProgress.Close(_progressKey);
                        CanLoad = true;
                    }
                }
                catch (Exception ex)
                {
                    cti.ThreadProgress.Close(_progressKey);
                    CanLoad = true;
                    MessageBox.Show(ex.Message, Resources.AET_CreatingTable, MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
        /// <summary>
        /// Создание поля таблицы
        /// </summary>
        /// <param name="nameDB">Название поля в БД</param>
        /// <param name="nameSystem">Системное название поля</param>
        /// <param name="name">Название поля в файле данных</param>
        /// <param name="ti">Информация о таблице</param>
        public FieldMatch CreateField(string nameDB, string nameSystem, int fieldTypeID, string name, tablesInfo ti)
        {
            if (nameDB != ti.pkField)
            {
                try
                {
                    bool   existField = false;
                    string nameField  = nameDB;
                    int    countt     = 0;
                    var    fieldNames = new List <string>();

                    if (classesOfMetods.isReservedName(nameField))
                    {
                        cti.ThreadProgress.Close(_progressKey);
                        nameField += "_";
                        if (MessageBox.Show(Resources.AEAtr_ReservedName + Environment.NewLine + String.Format(Resources.AEAtr_SaveRenameField, nameField),
                                            Resources.AEAtr_CreatingAttribute, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                        {
                            MessageBox.Show(Resources.AEAtr_NotSaveField, Resources.AEAtr_CreatingAttribute,
                                            MessageBoxButton.OK, MessageBoxImage.Information);
                            cti.ThreadProgress.ShowWait(_progressKey);
                            return(null);
                        }
                        cti.ThreadProgress.ShowWait(_progressKey);
                    }

                    using (SqlWork sqlCmd = new SqlWork())
                    {
                        sqlCmd.sql = "SELECT name_db FROM " + Program.scheme + ".table_field_info WHERE id_table=" + ti.idTable.ToString();
                        sqlCmd.ExecuteReader();
                        while (sqlCmd.CanRead())
                        {
                            fieldNames.Add(sqlCmd.GetString(0));
                        }
                        sqlCmd.Close();//считали все поля таблицы с базы и занеесли в лист
                        while (fieldNames.Contains(nameField))
                        {
                            existField = true;
                            countt++;
                            nameField = nameDB + countt.ToString();//если такое имя уже существует пробуем другое имя
                        }
                        if (existField)
                        {
                            cti.ThreadProgress.Close(_progressKey);
                            if (MessageBox.Show(String.Format(Resources.AEAtr_SaveRenameField, nameField),
                                                Resources.AEAtr_CreatingAttribute, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                            {
                                MessageBox.Show(Resources.AEAtr_NotSaveField, Resources.AEAtr_CreatingAttribute,
                                                MessageBoxButton.OK, MessageBoxImage.Information);
                                cti.ThreadProgress.ShowWait(_progressKey);
                                return(null);
                            }
                            cti.ThreadProgress.ShowWait(_progressKey);
                        }
                    }

                    int?id_f = null;
                    using (SqlWork sqlCmd = new SqlWork())
                    {
                        sqlCmd.sql = "SELECT " + Program.scheme + ".create_field(" + ti.idTable.ToString() + ",@field_name_db,@field_name_map," + fieldTypeID + ",@field_name_lable)";
                        var parms = new Params[]
                        {
                            new Params
                            {
                                paramName = "@field_name_db",
                                typeData  = NpgsqlTypes.NpgsqlDbType.Text,
                                value     = nameField
                            },
                            new Params
                            {
                                paramName = "@field_name_map",
                                typeData  = NpgsqlTypes.NpgsqlDbType.Text,
                                value     = nameSystem
                            },
                            new Params
                            {
                                paramName = "@field_name_lable",
                                typeData  = NpgsqlTypes.NpgsqlDbType.Text,
                                value     = null
                            }
                        };

                        sqlCmd.ExecuteReader(parms);
                        if (sqlCmd.CanRead())
                        {
                            id_f = sqlCmd.GetInt32(0);
                        }
                        if (id_f != null)
                        {
                            return(new FieldMatch()
                            {
                                Dest = (new Interfaces.fieldInfo()
                                {
                                    nameDB = nameField,
                                    TypeField = (Interfaces.TypeField)fieldTypeID
                                }),
                                Src = name
                            });
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Rekod.Classes.workLogFile.writeLogFile(Resources.AEAtr_ErrorCreateAtrField + " " +
                                                           Resources.DGBH_ErrorHeader + ": " + ex.Message, true, true);
                    return(null);
                }
            }
            else
            {
                return(null);
                //return new FieldMatch()
                //{
                //    Dest = (new Interfaces.fieldInfo()
                //    {
                //        nameDB = nameDB,
                //        TypeField = TypeField.Integer
                //    }),
                //    Src = name
                //};
            }
        }
        public PgImportTableVM(FileInfo fileInfo, ImportTableV importWindow)
        {
            _fileInfo     = fileInfo;
            _importWindow = importWindow;
            _tableInfo    = null;
            _dataTable    = null;
            _geomType     = 0;
            _progressKey  = "importProgress" + DateTime.Now.Ticks.ToString();
            _srid         = -1;
            CanLoad       = true;

            switch (_fileInfo.Extension.ToLower())
            {
            case ".dbf":
                _importer = new DBFImporter();
                break;

            case ".xls":
            case ".xlsx":
                _importer = new ExcelImporter();
                break;

            case ".shp":
            case ".tab":
            case ".bna":
            case ".csv":
            case ".geojson":
            case ".gml":
            case ".gmt":
            case ".itf":
            case ".kml":
            case ".mif":
            case ".xml":
            case ".gxt":
            case ".dxf":
            case ".sqlite":
                _importer = new SHPImporter();
                break;

            default:
                _importer = null;
                break;
            }

            if (_importer == null)
            {
                MessageBox.Show(Rekod.Properties.Resources.ImportWindow_NotSupportExtension);
                return;
            }
            _importer.WorkerSupportsCancellation = true;
            _importer.ProgressChanged           += new System.ComponentModel.ProgressChangedEventHandler(importer_ProgressChanged);
            _importer.RunWorkerCompleted        += new System.ComponentModel.RunWorkerCompletedEventHandler(importer_RunWorkerCompleted);

            try
            {
                _importer.Init(_fileInfo, _tableInfo);
                _dataTable = _importer.GetPreviewTable();
                if (_importer is SHPImporter)
                {
                    _geomType = (AbsM.EGeomType)((SHPImporter)_importer).GetGeometryType();
                    _srid     = ((SHPImporter)_importer).GetSRID();
                }
            }
            catch (Exception e)
            {
                cti.ThreadProgress.Close(_progressKey);
                MessageBox.Show(Properties.Resources.LabelControl_ErrorShowResult + Environment.NewLine + e.Message, Properties.Resources.error, MessageBoxButton.OK, MessageBoxImage.Error);

                _importer.CancelAsync();
                _importer.Dispose();
                return;
            }

            if (_dataTable == null)
            {
                MessageBox.Show(Properties.Resources.LabelControl_ErrorShowResult);
                _importer.CancelAsync();
                _importer.Dispose();
                return;
            }

            _knownGeometry = _geomType != 0;
        }
Beispiel #9
0
        private void button2_Click(object sender, EventArgs e)
        {
            String result = parseResult(textBox1.Text);

            if (result.Replace(" ", "") == "" && check_showLabel.Checked)
            {
                MessageBox.Show(Rekod.Properties.Resources.LabelControl_NotEmpty, Properties.Resources.AWT_EditLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (result.Contains("SELECT") || result.Contains("DROP") || result.Contains("INSERT") || result.Contains("UPDATE") || result.Contains("DELETE"))
            {
                MessageBox.Show(Rekod.Properties.Resources.LabelControl_InvalidExpression, Properties.Resources.AWT_EditLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            SqlWork sqlCmd = new SqlWork(true);

            if (result.Replace(" ", "") != "")
            {
                tablesInfo ti = classesOfMetods.getTableInfo(_idT);

                sqlCmd.sql = string.Format("SELECT {0} FROM \"{1}\".\"{2}\" LIMIT 1", result, ti.nameSheme, ti.nameDB);
                try
                {
                    sqlCmd.ExecuteNonQuery(null);
                }
                catch
                {
                    MessageBox.Show(Rekod.Properties.Resources.LabelControl_InvalidExpression, Properties.Resources.AWT_EditLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    sqlCmd.Close();
                }
            }
            _rezult = result;
            if (!userStyle)
            {
                Params par = new Params();
                par.paramName = "@labelexpr";
                par.typeData  = NpgsqlDbType.Varchar;
                par.value     = (!String.IsNullOrEmpty(result.Replace(" ", ""))) ? result : null;
                sqlCmd        = new SqlWork();

                if (!Program.WorkSets.CurrentWorkSet.IsDefault)
                {
                    sqlCmd.sql = String.Format("UPDATE sys_scheme.table_info_sets SET lablefiled=@labelexpr, label_showlabel={1} WHERE id_table={0} AND id_set = {2}",
                                               _idT, check_showLabel.Checked, Program.WorkSets.CurrentWorkSet.Id);
                }
                else
                {
                    sqlCmd.sql = String.Format("UPDATE sys_scheme.table_info SET lablefiled=@labelexpr, label_showlabel={1} WHERE id={0}", _idT, check_showLabel.Checked);
                }

                sqlCmd.ExecuteNonQuery(new IParams[] { par });
                sqlCmd.Close();

                sqlCmd     = new SqlWork();
                sqlCmd.sql = String.Format("SELECT sys_scheme.create_view_for_table({0})", _idT);
                sqlCmd.ExecuteNonQuery();
                sqlCmd.Close();

                classesOfMetods.reloadLayer(_idT);
                SyncController.ReloadStyle(_idT);
            }
            if (_parent != null)
            {
                _parent.CloseElemsAfter(this, true);
            }
            Program.mainFrm1.axMapLIb1.mapRepaint();
        }