Пример #1
0
        private void MapSetup_Load(object sender, EventArgs e)
        {
            // Prepare cmbMapConfigName datasource
            List<string> mapConfigs = new List<string>();
            DirectoryInfo dirInfo = new DirectoryInfo(PathHelper.MapConfigFolder);
            FileInfo[] files = dirInfo.GetFiles("*.xml");
            foreach (FileInfo file in files)
            {
                mapConfigs.Add(file.Name.ToString().Substring(0, file.Name.ToString().LastIndexOf(".")));
            }
            // Binding datasource for cmbMapConfigName and set default value.
            cmbMapConfigName.DataSource = mapConfigs;
            ConfigHelper ch = new ConfigHelper();
            cmbMapConfigName.SelectedItem = ch.GetDefaultMapConfigName().Trim();

            // Initialize nudImageColumns, nudImageRows value.
            nudImageColumns.Value = ch.GettlpFlawImagesColumns(cmbMapConfigName.SelectedItem.ToString());
            nudImageRows.Value = ch.GettlpFlawImagesRows(cmbMapConfigName.SelectedItem.ToString());

            // Initialize rdoMapGridOn,rdoMapGridOff
            rdoMapGridOn.Checked = ch.GetIsDisplayMapGrid(cmbMapConfigName.SelectedItem.ToString());
            rdoMapGridOff.Checked = !ch.GetIsDisplayMapGrid(cmbMapConfigName.SelectedItem.ToString());

            // Initialize rdoFixCellSize, rdoCountSize
            rdoFixCellSize.Checked = ch.GetIsFixCellSizeMode(cmbMapConfigName.SelectedItem.ToString());
            rdoCountSize.Checked = !ch.GetIsFixCellSizeMode(cmbMapConfigName.SelectedItem.ToString());

            if (rdoFixCellSize.Checked)
            {
                txtFixSizeCD.Text = ch.GetFixCellSizeCD(cmbMapConfigName.SelectedItem.ToString()).ToString();
                txtFixSizeCD.Enabled = true;
                txtFixSizeMD.Text = ch.GetFixCellSizeMD(cmbMapConfigName.SelectedItem.ToString()).ToString();
                txtFixSizeMD.Enabled = true;
                txtCountSizeCD.Text = "";
                txtCountSizeCD.Enabled = false;
                txtCountSizeMD.Text = "";
                txtCountSizeMD.Enabled = false;
                lblSCMD.Text = ch.GetFixCellSizeSmybol(cmbMapConfigName.SelectedItem.ToString());
                lblSCCD.Text = ch.GetFixCellSizeSmybol(cmbMapConfigName.SelectedItem.ToString());
            }
            else if (rdoCountSize.Checked)
            {
                txtCountSizeCD.Text = ch.GetCountSizeCD(cmbMapConfigName.SelectedItem.ToString()).ToString();
                txtCountSizeCD.Enabled = true;
                txtCountSizeMD.Text = ch.GetCountSizeMD(cmbMapConfigName.SelectedItem.ToString()).ToString();
                txtCountSizeMD.Enabled = true;
                txtFixSizeCD.Text = "";
                txtFixSizeCD.Enabled = false;
                txtFixSizeMD.Text = "";
                txtFixSizeMD.Enabled = false;
            }
            else
            {
                TextBox[] txts = { txtFixSizeCD, txtFixSizeMD, txtCountSizeCD, txtCountSizeMD };
                foreach (TextBox txt in txts)
                {
                    txt.Enabled = false;
                    txt.Text = "";
                }
            }

            // Initialize cmbBottomAxes default selected
            cmbBottomAxes.SelectedItem = ch.GetBottomAxes(cmbMapConfigName.SelectedItem.ToString());

            // Initialize chkCDInverse, chkMDInverse
            chkCDInverse.Checked = ch.IsCdInver_X(cmbMapConfigName.SelectedItem.ToString());
            chkMDInverse.Checked = ch.IsMdInver_Y(cmbMapConfigName.SelectedItem.ToString());

            // Initialize cmbMapSize default. (x:y)
            int x = ch.GetMapProportion_X(cmbMapConfigName.SelectedItem.ToString());
            int y = ch.GetMapProportion_Y(cmbMapConfigName.SelectedItem.ToString());
            cmbMapSize.SelectedItem = String.Format("{0}:{1}", x, y);

            // prepare shape list
            Dictionary<string, string> shapes = new Dictionary<string, string>();
            shapes.Add("Triangle", "▲");
            shapes.Add("InvertedTriangle", "▼");
            shapes.Add("Square", "■");
            shapes.Add("Circle", "●");
            shapes.Add("Plus", "✚");
            shapes.Add("Cross", "✖");
            shapes.Add("Star", "★");

            // Initialize FlawLegend (dgvFlawLegends)

            List<Column> columns = new List<Column>();
            Column flawType = new Column(0, "FlawType", 60);
            Column name = new Column(1, "Name", 120);
            Column shape = new Column(2, "Shape", 80);
            Column color = new Column(3, "Color", 80);
            columns.Add(flawType);
            columns.Add(name);
            columns.Add(shape);
            columns.Add(color);
            foreach (Column c in columns)
            {
                if (c.Name == "Shape")
                {
                    DataGridViewComboBoxColumn cmbShape = new DataGridViewComboBoxColumn();
                    cmbShape.HeaderText = c.Name;
                    cmbShape.DisplayIndex = c.Index;
                    cmbShape.DataPropertyName = c.Name;
                    cmbShape.Width = c.Width;
                    cmbShape.DataSource = new BindingSource(shapes, null);
                    cmbShape.DisplayMember = "Value";
                    cmbShape.ValueMember = "Key";
                    dgvFlawLegends.Columns.Add(cmbShape);
                }
                else
                {
                    DataGridViewCell cell = new DataGridViewTextBoxCell();
                    DataGridViewColumn column = new DataGridViewColumn();
                    column.CellTemplate = cell;
                    column.Name = c.Name;
                    column.HeaderText = c.Name;
                    column.Width = c.Width;
                    column.DataPropertyName = c.Name;
                    column.SortMode = DataGridViewColumnSortMode.Automatic;
                    if (c.Name == "FlawType" || c.Name == "Name" || c.Name == "Color")
                    {
                        column.ReadOnly = true;
                    }
                    dgvFlawLegends.Columns.Add(column);
                }
            }
            dgvFlawLegends.MultiSelect = false;
            dgvFlawLegends.AutoGenerateColumns = false;

            // Get datatable of _dtbFlawLegends
            _dtbFlawLegends = ch.GetDataTablePrevFlawLegend(cmbMapConfigName.SelectedItem.ToString());
            dgvFlawLegends.DataSource = _dtbFlawLegends;
        }
Пример #2
0
        private void btnMapSetting_Click(object sender, EventArgs e)
        {
            // Deal Flaw Legends datasoure
            ConfigHelper ch = new ConfigHelper();

            XYDiagram diagram = null;
            if ((XYDiagram)chartControl.Diagram != null)
            {
                diagram = (XYDiagram)chartControl.Diagram;
            }

            MapSetup ms = new MapSetup();
            ms.ShowDialog();
            if (_legend != null && _legend.Count > 0)
            {
                // Reload flawlegend
                _dtbFlawLegends.Rows.Clear();
                // Add jobloaded records
                foreach (FlawLegend f in _legend)
                {
                    DataRow dr = _dtbFlawLegends.NewRow();
                    dr["Display"] = f.VisibleFlags;
                    dr["FlawType"] = f.ClassID;
                    dr["Name"] = f.Name;
                    dr["Shape"] = "Cone";
                    dr["Color"] = String.Format("#{0:X2}{1:X2}{2:X2}", ColorTranslator.FromWin32((int)f.Color).R,
                                                            ColorTranslator.FromWin32((int)f.Color).G,
                                                            ColorTranslator.FromWin32((int)f.Color).B);
                    dr["PieceDoffNum"] = 0;
                    dr["JobDoffNum"] = 0;
                    _dtbFlawLegends.Rows.Add(dr);
                }

                string mapConfig = ch.GetDefaultMapConfigName().Trim();
                DataTable dtbLegendFromConfig = ch.GetDataTablePrevFlawLegend(mapConfig);

                foreach (DataRow d in dtbLegendFromConfig.Rows)
                {
                    string expr = String.Format("FlawType={0} AND Name='{1}'", d["FlawType"].ToString().Trim(), d["Name"].ToString().Trim());
                    DataRow[] drs = _dtbFlawLegends.Select(expr);
                    if (drs.Length > 0)
                    {
                        drs[0]["Shape"] = d["Shape"].ToString().Trim();
                        drs[0]["Color"] = d["Color"].ToString().Trim();
                    }
                }

                dgvFlawLegend.ClearSelection();
                dgvFlawLegendDetial.ClearSelection();

                // Re-configure Chart
                if (diagram != null)
                {
                    double width = Convert.ToDouble(diagram.AxisX.Range.ScrollingRange.MaxValue);
                    double height = Convert.ToDouble(diagram.AxisY.Range.ScrollingRange.MaxValue);
                    InitChart(width, height);
                    DrawChartPoint();
                }
            }
            // Refresh pxptab tablelayout
            _pnl.ColumnCount = ch.GettlpFlawImagesColumns();
            _pnl.RowCount = ch.GettlpFlawImagesRows();
            _pnl.ColumnStyles.Clear();
            int phdHeight = _pnl.Height / _pnl.RowCount;
            int phdrWidth = _pnl.Width / _pnl.ColumnCount;
            for (int i = 0; i < _pnl.RowCount; i++)
            {
                _pnl.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            }

            for (int i = 0; i < _pnl.ColumnCount; i++)
            {
                _pnl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            }
            // 呼叫 RefreshtlpImagesControls 重新加入控制項, 然後重新計算總頁數
            if (_dtbFlaws != null)
            {
                _pxp.RefreshtlpImagesControls(1);
                int dataCount = _dtbFlaws.Select(_dtbFlaws.DefaultView.RowFilter).Length;
                int totalPage = dataCount % (_pnl.ColumnCount * _pnl.RowCount) == 0 ?
                             dataCount / (_pnl.ColumnCount * _pnl.RowCount) :
                             dataCount / (_pnl.ColumnCount * _pnl.RowCount) + 1;
                _pxp.Controls["lblTotalPage"].Text = totalPage.ToString();
            }
        }
Пример #3
0
        private void cmbMapConfigName_DropDownClosed(object sender, EventArgs e)
        {
            try
            {
                ConfigHelper ch = new ConfigHelper();
                // Set nudImageColumns, nudImageRows value.
                nudImageColumns.Value = ch.GettlpFlawImagesColumns(cmbMapConfigName.SelectedItem.ToString());
                nudImageRows.Value = ch.GettlpFlawImagesRows(cmbMapConfigName.SelectedItem.ToString());

                // Set rdoMapGridOn,rdoMapGridOff
                rdoMapGridOn.Checked = ch.GetIsDisplayMapGrid(cmbMapConfigName.SelectedItem.ToString());
                rdoMapGridOff.Checked = !ch.GetIsDisplayMapGrid(cmbMapConfigName.SelectedItem.ToString());

                // Set rdoFixCellSize, rdoCountSize
                rdoFixCellSize.Checked = ch.GetIsFixCellSizeMode(cmbMapConfigName.SelectedItem.ToString());
                rdoCountSize.Checked = !ch.GetIsFixCellSizeMode(cmbMapConfigName.SelectedItem.ToString());

                if (rdoFixCellSize.Checked)
                {
                    txtFixSizeCD.Text = ch.GetFixCellSizeCD(cmbMapConfigName.SelectedItem.ToString()).ToString();
                    txtFixSizeCD.Enabled = true;
                    txtFixSizeMD.Text = ch.GetFixCellSizeMD(cmbMapConfigName.SelectedItem.ToString()).ToString();
                    txtFixSizeMD.Enabled = true;
                    txtCountSizeCD.Text = "";
                    txtCountSizeCD.Enabled = false;
                    txtCountSizeMD.Text = "";
                    txtCountSizeMD.Enabled = false;
                    lblSCMD.Text = ch.GetFixCellSizeSmybol(cmbMapConfigName.SelectedItem.ToString());
                    lblSCCD.Text = ch.GetFixCellSizeSmybol(cmbMapConfigName.SelectedItem.ToString());
                }
                else if (rdoCountSize.Checked)
                {
                    txtCountSizeCD.Text = ch.GetCountSizeCD(cmbMapConfigName.SelectedItem.ToString()).ToString();
                    txtCountSizeCD.Enabled = true;
                    txtCountSizeMD.Text = ch.GetCountSizeMD(cmbMapConfigName.SelectedItem.ToString()).ToString();
                    txtCountSizeMD.Enabled = true;
                    txtFixSizeCD.Text = "";
                    txtFixSizeCD.Enabled = false;
                    txtFixSizeMD.Text = "";
                    txtFixSizeMD.Enabled = false;
                }
                else
                {
                    TextBox[] txts = { txtFixSizeCD, txtFixSizeMD, txtCountSizeCD, txtCountSizeMD };
                    foreach (TextBox txt in txts)
                    {
                        txt.Enabled = false;
                        txt.Text = "";
                    }
                }

                // Set cmbBottomAxes default selected
                cmbBottomAxes.SelectedItem = ch.GetBottomAxes(cmbMapConfigName.SelectedItem.ToString());

                // Set chkCDInverse, chkMDInverse
                chkCDInverse.Checked = ch.IsCdInver_X(cmbMapConfigName.SelectedItem.ToString());
                chkMDInverse.Checked = ch.IsMdInver_Y(cmbMapConfigName.SelectedItem.ToString());

                // Set cmbMapSize default. (x:y)
                int x = ch.GetMapProportion_X(cmbMapConfigName.SelectedItem.ToString());
                int y = ch.GetMapProportion_Y(cmbMapConfigName.SelectedItem.ToString());
                cmbMapSize.SelectedItem = String.Format("{0}:{1}", x, y);

                // Set FlawLegends
                _dtbFlawLegends.Rows.Clear();
                DataTable dtb = ch.GetDataTablePrevFlawLegend(cmbMapConfigName.SelectedItem.ToString());
                foreach (DataRow dr in dtb.Rows)
                {
                    DataRow newDr = _dtbFlawLegends.NewRow();
                    newDr["FlawType"] = dr["FlawType"];
                    newDr["Name"] = dr["Name"];
                    newDr["Shape"] = dr["Shape"];
                    newDr["Color"] = dr["Color"];
                    _dtbFlawLegends.Rows.Add(newDr);
                }
            }
            catch { }
        }
Пример #4
0
        // Initial flaw legend datagridview
        public void InitFlawLegendGrid()
        {
            _dtbFlawLegends.Rows.Clear();
            // Add jobloaded records
            foreach (FlawLegend f in _legend)
            {
                DataRow dr = _dtbFlawLegends.NewRow();
                dr["Display"] = f.VisibleFlags;
                dr["FlawType"] = f.ClassID;
                dr["Name"] = f.Name;
                dr["Shape"] = "Cone";
                dr["Color"] = String.Format("#{0:X2}{1:X2}{2:X2}", ColorTranslator.FromWin32((int)f.Color).R,
                                                        ColorTranslator.FromWin32((int)f.Color).G,
                                                        ColorTranslator.FromWin32((int)f.Color).B);
                dr["PieceDoffNum"] = 0;
                dr["JobDoffNum"] = 0;
                _dtbFlawLegends.Rows.Add(dr);
            }

            // Deal Flaw Legends datasoure
            ConfigHelper ch = new ConfigHelper();

            string mapConfig = ch.GetDefaultMapConfigName().Trim();
            DataTable dtbLegendFromConfig = ch.GetDataTablePrevFlawLegend(mapConfig);

            foreach (DataRow d in dtbLegendFromConfig.Rows)
            {
                string expr = String.Format("FlawType={0} AND Name='{1}'", d["FlawType"].ToString().Trim(), d["Name"].ToString().Trim());
                DataRow[] drs = _dtbFlawLegends.Select(expr);
                if (drs.Length > 0)
                {
                    drs[0]["Shape"] = d["Shape"].ToString().Trim();
                    drs[0]["Color"] = d["Color"].ToString().Trim();
                }
            }

            // Save new record to xml
            string map_path = PathHelper.MapConfigFolder + mapConfig + ".xml";
            XmlDocument document = new XmlDocument();
            document.Load(map_path);
            XPathNavigator navigator = document.CreateNavigator();
            XPathNodeIterator node = navigator.Select("//map_window/flaw_legend");

            // remove old flawlegend for add records
            if (navigator.Select("//map_window/flaw_legend").Count > 0 && _dtbFlawLegends.Rows.Count > 0)
            {
                XPathNavigator first = navigator.SelectSingleNode("//map_window/flaw_legend[1]");
                XPathNavigator last = navigator.SelectSingleNode("//map_window/flaw_legend[last()]");
                navigator.MoveTo(first);
                navigator.DeleteRange(last);
            }

            // save _dtbFlawLegends to xml
            for (int i = 0; i < _dtbFlawLegends.Rows.Count; i++)
            {
                string flawType = _dtbFlawLegends.Rows[i]["FlawType"].ToString();
                string flawName = _dtbFlawLegends.Rows[i]["Name"].ToString();
                string shape = _dtbFlawLegends.Rows[i]["Shape"].ToString();
                string color = _dtbFlawLegends.Rows[i]["Color"].ToString();
                navigator.SelectSingleNode("//config/map_window").AppendChildElement(string.Empty, "flaw_legend", string.Empty, null);
                // Move to last column element and add name, start, end value.
                navigator.SelectSingleNode("//config/map_window/flaw_legend[last()]").AppendChildElement(string.Empty, "flaw_type", string.Empty, flawType);
                navigator.SelectSingleNode("//config/map_window/flaw_legend[last()]").AppendChildElement(string.Empty, "name", string.Empty, flawName);
                navigator.SelectSingleNode("//config/map_window/flaw_legend[last()]").AppendChildElement(string.Empty, "color", string.Empty, color);
                navigator.SelectSingleNode("//config/map_window/flaw_legend[last()]").AppendChildElement(string.Empty, "shape", string.Empty, shape);
            }
            try
            {
                document.Save(map_path);
            }
            catch
            {
                MessageBox.Show("Fail.");
            }
        }