Exemplo n.º 1
0
        /// <summary>
        /// 窗口载入事件
        /// </summary>
        private void FrmConfig_Load(object sender, EventArgs e)
        {
            // 读取配置文件
            if (File.Exists(Config.PATH_CONFIG_FILE))
            {
                try
                {
                    var data = File.ReadAllLines(Config.PATH_CONFIG_FILE).ToList();
                    if (data != null && data.Count > 0)
                    {
                        // 第一行为主界面每行多少个按钮
                        tbButtonCountPerRow.Text = data[0];
                        // 第二行为语言选项
                        if (data[1].Equals(LANGUAGES.ID.ToString()))
                        {
                            rbId.Checked = true;
                        }
                        else if (data[1].Equals(LANGUAGES.NAME.ToString()))
                        {
                            rbName.Checked = true;
                        }
                        else if (data[1].Equals(LANGUAGES.ID_NAME.ToString()))
                        {
                            rbIdName.Checked = true;
                        }
                        else if (data[1].Equals(LANGUAGES.NAME_ID.ToString()))
                        {
                            rbNameId.Checked = true;
                        }
                        // 第三行为字段名
                        string[] fieldNames = data[2].Split(',');
                        tbDlbmFieldName.Text = fieldNames[0];
                        tbDlmcFieldName.Text = fieldNames[1];

                        // 后面的数据添加到表格
                        for (int i = Config.RowsCountExceptData; i < data.Count; i++)
                        {
                            string[] tmpData = data[i].Split(',');
                            AddNewRow(tmpData[0], tmpData[1]);
                        }
                    }
                }
                catch (Exception)
                {
                    DialogUtils.ShowDialogError("配置文件读取失败");
                }
            }
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string fieldName  = tbFieldName.Text = tbFieldName.Text.Trim();
            string fieldValue = tbFieldName.Text = tbFieldValue.Text.Trim();

            try
            {
                File.WriteAllText(Config.PATH_BZ_CONFIG_FILE, fieldName + "," + fieldValue);
                _actionSave.Invoke(fieldName, fieldValue);
                Close();
            }
            catch (Exception)
            {
                DialogUtils.ShowDialogWarning("配置文件保存失败,请关闭可能占用的应用程序后重试");
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 菜单:刷新
 /// </summary>
 private void menuRefresh_Click(object sender, EventArgs e)
 {
     Init();
     if (File.Exists(Config.PATH_CONFIG_FILE))
     {
         RefreshLayout();
     }
     else
     {
         DialogResult result = DialogUtils.ShowDialogQuestion("未发现配置文件,是否立即配置?");
         if (result == DialogResult.Yes)
         {
             FrmConfig frmConfig = new FrmConfig();
             frmConfig._actionSave = RefreshLayout;
             frmConfig.ShowDialog();
         }
     }
 }
Exemplo n.º 4
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            string dlbm = tbDlbm.Text = tbDlbm.Text.Trim();
            string dlmc = tbDlmc.Text = tbDlmc.Text.Trim();

            if (dlbm.Contains(' '))
            {
                DialogUtils.ShowDialogWarning("地类编码包含空格");
                return;
            }
            if (dlmc.Contains(' '))
            {
                DialogUtils.ShowDialogWarning("地类名称包含空格");
                return;
            }
            _actionAddNewRow.Invoke(dlbm, dlmc);

            // _actionAddNewRow(dlbm, dlmc);
            Close();
        }
Exemplo n.º 5
0
        private void btnBz_Click(object sender, EventArgs e)
        {
            Init();

            try
            {
                if (Config._currentLayerName == null || Config._currentLayerName.Equals(""))
                {
                    DialogUtils.ShowDialogWarning("未选择图层,请在赋值界面选择图层");
                    return;
                }
                if (_fieldName == null || _fieldName == null)
                {
                    DialogUtils.ShowDialogWarning("未设置字段名和字段值");
                    return;
                }

                IEnumLayer layers = Utils.getFeatureLayers(mMap);
                if (layers == null || layers.Next() == null)
                {
                    Utils.ShowDialogWarning("没有矢量图层");
                    return;
                }
                if (Config._currentLayerName == null || Config._currentLayerName.Equals(""))
                {
                    Utils.ShowDialogWarning("请先选择图层");
                    return;
                }
                if (mDocument != null)
                {
                    Utils.setValue(mMap, Config._currentLayerName, _fieldName, _fieldValue);
                    //Utils.setValue(mMap, _currentLayerName, _fieldNameDlbm, vals[0], true, 400);
                    mDocument.ActiveView.Refresh();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 保存配置文件
        /// </summary>
        /// <param name="column"></param>
        private void Save(int column)
        {
            if (File.Exists(Config.PATH_CONFIG_FILE))
            {
                File.Delete(Config.PATH_CONFIG_FILE);
            }
            int    dataCount = dataGridView.Rows.Count - 1;
            string rl        = column.ToString();

            List <string> data = new List <string>();

            // 每行按钮个数
            data.Add(rl);
            // 语言
            data.Add(Config.LANGUAGE.ToString());
            // 字段名:编码,名称
            data.Add(tbDlbmFieldName.Text + "," + tbDlmcFieldName.Text);


            for (int i = 0; i < dataCount; i++)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(dataGridView.Rows[i].Cells[0].Value);
                sb.Append(",");
                sb.Append(dataGridView.Rows[i].Cells[1].Value);
                data.Add(sb.ToString());
            }
            try
            {
                File.WriteAllLines(Config.PATH_CONFIG_FILE, data.ToArray());
                DialogUtils.ShowDialogInfo("配置文件保存成功");
            }
            catch (Exception e)
            {
                DialogUtils.ShowDialogError("配置文件保存失败,请检查是否被占用,文件路径:" + Config.PATH_CONFIG_FILE);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 刷新布局
        /// </summary>
        private void RefreshLayout()
        {
            dataList.Clear();
            try
            {
                dataList = File.ReadAllLines(Config.PATH_CONFIG_FILE).ToList();
                if (dataList.Count > 0)
                {
                    // 获取每行多少按钮
                    string colStr = dataList[0];

                    if (!int.TryParse(colStr, out columns))
                    {
                        columns = 5;
                    }
                    // 设置语言
                    if (dataList[1].Equals(LANGUAGES.ID.ToString()))
                    {
                        Config.LANGUAGE = LANGUAGES.ID;
                    }
                    else if (dataList[1].Equals(LANGUAGES.NAME.ToString()))
                    {
                        Config.LANGUAGE = LANGUAGES.NAME;
                    }
                    else if (dataList[1].Equals(LANGUAGES.ID_NAME.ToString()))
                    {
                        Config.LANGUAGE = LANGUAGES.ID_NAME;
                    }
                    else if (dataList[1].Equals(LANGUAGES.NAME_ID.ToString()))
                    {
                        Config.LANGUAGE = LANGUAGES.NAME_ID;
                    }
                    // 字段名称
                    string[] fieldNames = dataList[2].Split(',');
                    _fieldNameDlbm = fieldNames[0];
                    _fieldNameDlmc = fieldNames[1];


                    // 将前面的非数据条目移除
                    for (int i = 0; i < Config.RowsCountExceptData; i++)
                    {
                        dataList.RemoveAt(0);
                    }

                    // 添加表格控件
                    rootPanel.Controls.Clear();
                    TableLayoutPanel tableLayout = new TableLayoutPanel();
                    tableLayout.Dock = DockStyle.Fill;
                    rootPanel.Controls.Add(tableLayout);
                    // 添加列
                    for (int i = 0; i < columns; i++)
                    {
                        tableLayout.ColumnCount++;
                        tableLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, tableLayout.Width * columns / 10.0f));    //利用百分比计算,0.2f表示占用本行长度的20%
                    }
                    // 计算需要多少行
                    int rows = (dataList.Count) / columns;
                    if ((dataList.Count) % columns > 0)
                    {
                        rows++;
                    }
                    // 添加行
                    for (int i = 0; i < rows; i++)
                    {
                        tableLayout.RowCount++;
                        tableLayout.RowStyles.Add(new RowStyle(SizeType.Percent, tableLayout.Height * rows / 10.0f));
                    }
                    // 遍历添加按钮
                    for (int rowIndex = 0; rowIndex < rows; rowIndex++)
                    {
                        for (int colIndex = 0; colIndex < columns; colIndex++)
                        {
                            var index = rowIndex * columns + colIndex;
                            if (index < dataList.Count)
                            {
                                Button button = new Button();
                                button.FlatStyle = FlatStyle.System;
                                button.Font      = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                                //button.Text = dataList[rowIndex * columns + colIndex ]; //map.Keys.ToArray()[rowIndex * columns + colIndex];
                                string tmpData = dataList[rowIndex * columns + colIndex];
                                button.Tag    = tmpData;
                                button.Text   = GetButtonText(tmpData);
                                button.Dock   = DockStyle.Fill;
                                button.Click += new EventHandler(ButtonClickEvent);
                                tableLayout.Controls.Add(button, colIndex, rowIndex);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                DialogUtils.ShowDialogError("配置文件读取失败");
            }
        }