Пример #1
0
        private void btnCreateGrid_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to create new subpiece setting?", "Create Setting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (dialogResult == DialogResult.Yes)
            {
                int x = int.TryParse(txtColumns.Text, out x) ? x : 1;
                int y = int.TryParse(txtRows.Text, out y) ? y : 1;

                _dtbColumns.Clear();
                for (int i = 0; i < x; i++)
                {
                    DataRow dr = _dtbColumns.NewRow();
                    dr["Name"] = i + 1;
                    _dtbColumns.Rows.Add(dr);
                }
                _dtbRows.Clear();
                for (int i = 0; i < y; i++)
                {
                    DataRow dr = _dtbRows.NewRow();
                    dr["Name"] = i + 1;
                    _dtbRows.Rows.Add(dr);
                }

                // SubpieceName Reset

                _pointsSubpieceNames = new List<string>();
                _marksSubpieceNames = new List<string>();
                _pointsSubpieceNames.Add("All");
                _marksSubpieceNames.Add("All");
                for (int i = 0; i < x; i++)
                {
                    for (int j = 0; j < y; j++)
                    {
                        string name = String.Format("ROI-{0}{1}", i + 1, j + 1);
                        _pointsSubpieceNames.Add(name);
                        _marksSubpieceNames.Add(name);
                    }
                }
                cmbSubMarks.DataSource = null;
                cmbSubMarks.DataSource = _marksSubpieceNames;
                cmbSubPoints.DataSource = null;
                cmbSubPoints.DataSource = _pointsSubpieceNames;

                // Add Points set
                ConfigHelper ch = new ConfigHelper();
                string map_path = ch.GetDefaultMapConfigName();
                Dictionary<int, string> legends = ch.GetPrevFlawLegendDictionary(map_path);
                _dtbPoints.Rows.Clear();
                foreach (string subpiece in _pointsSubpieceNames)
                {
                    foreach (KeyValuePair<int, string> l in legends)
                    {
                        // SubpieceName, ClassName, Score
                        DataRow dr = _dtbPoints.NewRow();
                        dr["SubpieceName"] = subpiece;
                        dr["ClassName"] = l.Value;
                        dr["Score"] = 0;
                        _dtbPoints.Rows.Add(dr);
                    }
                }

                // Refresh Mark
                foreach (string subpiece in _marksSubpieceNames)
                {
                    string expr = String.Format("SubpieceName='{0}'", subpiece);
                    DataRow[] drs = _dtbGrades.Select(expr);
                    if (drs.Length < 1)
                    {
                        DataRow dr = _dtbGrades.NewRow();
                        dr["SubpieceName"] = subpiece;
                        dr["GradeName"] = "A";
                        dr["Score"] = 0;
                        _dtbGrades.Rows.Add(dr);
                    }
                }
            }
        }