// Calculate entiry piece score and send NG signal when piece fail public void CalcEntirePieceResult() { // get current using unit NowUnit ucd = _units.Find(x => x.ComponentName == "Flaw Map CD"); int score = 0; double top = Convert.ToDouble(_cuts.Last()) - JobHelper.PxPInfo.Height; double bottom = Convert.ToDouble(_cuts.Last()); string rowFilter = String.Format("MD > {0} AND MD < {1} AND CD > {2}", top, bottom, _tmpOffset); DataRow[] flawRows = _dtbFlaws.Select(rowFilter); ConfigHelper ch = new ConfigHelper(); string gradeConfigFile = ch.GetDefaultGradeConfigName(); DataTable gradeColumn = ch.GetDataTableOfdgvColumns(gradeConfigFile); DataTable gradeRow = ch.GetDataTableOfdgvRows(gradeConfigFile); string roiMode = ch.GetGradeNoRoiMode(gradeConfigFile); bool showScore = ch.IsGradePointEnable(gradeConfigFile); double limitScore = ch.GetPassFailScore(gradeConfigFile); if (roiMode == "Symmetrical" && showScore) { bool pieceResult; if (flawRows.Length > 0) { foreach (DataRow drCol in gradeColumn.Rows) { foreach (DataRow drRow in gradeRow.Rows) { string rangeName = String.Format("{0}{1}", drCol["Name"], drRow["Name"]); int subPieceScore = 0; //string subPieceFilter = String.Format("(CD >= {0} AND CD <= {1}) AND (MD > {2} AND MD < {3})", drCol["Start"], drCol["End"], (Convert.ToDouble(drRow["Start"]) + top), (Convert.ToDouble(drRow["End"]) + top)); string subPieceFilter = String.Format("(CD >= {0} AND CD <= {1}) AND (MD > {2} AND MD < {3})", Convert.ToDouble(drCol["Start"]) / ucd.Conversion, Convert.ToDouble(drCol["End"]) / ucd.Conversion, (Convert.ToDouble(drRow["Start"]) / ucd.Conversion + top), (Convert.ToDouble(drRow["End"]) / ucd.Conversion + top)); DataRow[] subFlawRows = _dtbFlaws.Select(subPieceFilter); foreach (DataRow dr in subFlawRows) { string pointFilter = String.Format("SubpieceName = 'ROI-{0}' AND ClassName = '{1}'", rangeName, dr["FlawClass"]); subPieceScore += Convert.ToInt32(_dtbPoints.Select(pointFilter).First()["Score"]); } score += subPieceScore; } } if (score >= limitScore) { pieceResult = false; } else { pieceResult = true; } } else { pieceResult = true; } _doffResult.Add(pieceResult); // Fire when doff is fail if (!JobHelper.IsOnpeHistory) { if (pieceResult == false) { _fire.FireEvent(0, 0, 0); } else { _fire.FireEvent(1, 0, 0); } } } else { _doffResult.Add(true); } // Calc flaw number of this job foreach (DataRow dr in flawRows) { string name = dr["FlawClass"].ToString(); if (!_jobDoffNum.ContainsKey(name)) { _jobDoffNum.Add(name, 1); } else { _jobDoffNum[name]++; } } }
// Reload points and grades data public void ReloadDataTables() { ConfigHelper ch = new ConfigHelper(); string grade_name = ch.GetDefaultGradeConfigName(); // Get Points score _dtbPoints = ch.GetDataTabledgvPoints(grade_name); // Get Grade _dtbGrades = ch.GetDataTabledgvGrade(grade_name); }
private void btnGradeSetting_Click(object sender, EventArgs e) { try { ConfigHelper ch = new ConfigHelper(); GradeSetup gs = new GradeSetup(); gs.ShowDialog(); // re-binding datasource // Prepare cmbGradeConfigFiles datasource List<string> gradeConfigs = new List<string>(); DirectoryInfo dirInfo = new DirectoryInfo(PathHelper.GradeConfigFolder); FileInfo[] files = dirInfo.GetFiles("*.xml"); foreach (FileInfo file in files) { gradeConfigs.Add(file.Name.ToString().Substring(0, file.Name.ToString().LastIndexOf("."))); } // Binding cmbGradeConfigFiles cmbGradeConfigFiles.DataSource = gradeConfigs; cmbGradeConfigFiles.SelectedItem = ch.GetDefaultGradeConfigName().Trim(); // Reload datatable score ReloadDataTables(); // Re-configure Chart XYDiagram diagram = null; DrawDummyPoint(); if ((XYDiagram)chartControl.Diagram != null) { diagram = (XYDiagram)chartControl.Diagram; double width = Convert.ToDouble(diagram.AxisX.Range.ScrollingRange.MaxValue); double height = Convert.ToDouble(diagram.AxisY.Range.ScrollingRange.MaxValue); InitChart(width, height); if (chartControl.Series != null) { //UNDONE: 歷史資料切換設定時需重判好壞 ReCalcPieceResult(); DrawChartPoint(); JobHelper.IsOnpeHistory = true; UpdateUIControl(); JobHelper.IsOnpeHistory = false; } } } catch { } }
private void MapWindow_Load(object sender, EventArgs e) { ConfigHelper ch = new ConfigHelper(); cmbFilterType.SelectedItem = ch.GetFilterType().Trim(); // Prepare cmbGradeConfigFiles datasource List<string> gradeConfigs = new List<string>(); DirectoryInfo dirInfo = new DirectoryInfo(PathHelper.GradeConfigFolder); FileInfo[] files = dirInfo.GetFiles("*.xml"); foreach (FileInfo file in files) { gradeConfigs.Add(file.Name.ToString().Substring(0, file.Name.ToString().LastIndexOf("."))); } // Binding cmbGradeConfigFiles cmbGradeConfigFiles.DataSource = gradeConfigs; cmbGradeConfigFiles.SelectedItem = ch.GetDefaultGradeConfigName().Trim(); // Initialize dgvFlawLegend without data. List<Column> columns = new List<Column>(); Column display = new Column(0, "Display", 60); Column shape = new Column(2, "Shape", 60); columns.Add(display); columns.Add(shape); foreach (Column c in columns) { if (c.Name == "Display") { DataGridViewCell cell = new DataGridViewCheckBoxCell(); 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; column.FillWeight = c.Width; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dgvFlawLegend.Columns.Add(column); } 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; column.FillWeight = c.Width; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; column.ReadOnly = true; dgvFlawLegend.Columns.Add(column); } } dgvFlawLegend.MultiSelect = false; dgvFlawLegend.AutoGenerateColumns = false; columns = new List<Column>(); Column flawType = new Column(1, "FlawType", 60); Column name = new Column(1, "Name", 60); shape = new Column(2, "Shape", 60); Column pieceDoff = new Column(1, "PieceDoffNum", 60); Column jobDoff = new Column(1, "JobDoffNum", 60); columns.Add(flawType); columns.Add(name); columns.Add(shape); columns.Add(pieceDoff); columns.Add(jobDoff); foreach (Column c in columns) { 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; column.FillWeight = c.Width; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dgvFlawLegendDetial.Columns.Add(column); } dgvFlawLegendDetial.MultiSelect = false; dgvFlawLegendDetial.AutoGenerateColumns = false; // set datasource to dgvdgvFlawLegend // Initialize merge FlawLegend _dtbFlawLegends = new DataTable(); _dtbFlawLegends.Columns.Add("Display", typeof(bool)); _dtbFlawLegends.Columns.Add("FlawType", typeof(int)); _dtbFlawLegends.Columns.Add("Name", typeof(string)); _dtbFlawLegends.Columns.Add("Shape", typeof(string)); _dtbFlawLegends.Columns.Add("Color", typeof(string)); _dtbFlawLegends.Columns.Add("PieceDoffNum", typeof(int)); _dtbFlawLegends.Columns.Add("JobDoffNum", typeof(int)); dgvFlawLegend.DataSource = _dtbFlawLegends; dgvFlawLegendDetial.DataSource = _dtbFlawLegends; // Get Points score string grade_name = ch.GetDefaultGradeConfigName(); _dtbPoints = new DataTable(); _dtbPoints = ch.GetDataTabledgvPoints(grade_name); // Get Grade _dtbGrades = new DataTable(); _dtbGrades = ch.GetDataTabledgvGrade(grade_name); // Init doffResult _doffResult = new List<bool>(); _jobDoffNum = new Dictionary<string, int>(); // Setting UI controls status SettingUIControlStatus(true); }
// Draw sub piece range and annotation private void DrawSubPiece() { // get current using unit NowUnit ucd = _units.Find(x => x.ComponentName == "Flaw Map CD"); _totalScore = 0; DataRow[] flawRows = _dtbFlaws.Select(_dtbFlaws.DefaultView.RowFilter); ConfigHelper ch = new ConfigHelper(); string gradeConfigFile = ch.GetDefaultGradeConfigName(); DataTable gradeColumn = ch.GetDataTableOfdgvColumns(gradeConfigFile); DataTable gradeRow = ch.GetDataTableOfdgvRows(gradeConfigFile); string roiMode = ch.GetGradeNoRoiMode(gradeConfigFile); bool showScore = ch.IsGradePointEnable(gradeConfigFile); bool showGrade = ch.IsGradeMarksEnable(gradeConfigFile); if (roiMode == "Symmetrical") { foreach (DataRow drCol in gradeColumn.Rows) { foreach (DataRow drRow in gradeRow.Rows) { // Add rangearea string rangeName = String.Format("{0}{1}", drCol["Name"], drRow["Name"]); Series range = new Series(rangeName, ViewType.RangeArea); range.ShowInLegend = false; range.CrosshairEnabled = DevExpress.Utils.DefaultBoolean.False; range.ArgumentScaleType = ScaleType.Numerical; range.Points.Add(new SeriesPoint(drCol["Start"], drRow["Start"], drRow["End"])); range.Points.Add(new SeriesPoint(drCol["End"], drRow["Start"], drRow["End"])); RangeAreaSeriesView view = (RangeAreaSeriesView)range.View; view.Color = Color.Red; view.Transparency = 230; view.Marker1.Visible = false; view.Marker2.Visible = false; view.Border1.Color = Color.Transparent; view.Border2.Color = Color.Transparent; chartControl.Series.Add(range); int subPieceScore = 0; string subPieceGrade = "F"; if (showScore) { string subPieceFilter = String.Format("(CD >= {0} AND CD <= {1}) AND (MD > {2} AND MD < {3})", Convert.ToDouble(drCol["Start"]) / ucd.Conversion, Convert.ToDouble(drCol["End"]) / ucd.Conversion, (Convert.ToDouble(drRow["Start"]) / ucd.Conversion + _topOfPart), (Convert.ToDouble(drRow["End"]) / ucd.Conversion + _topOfPart)); DataRow[] subFlawRows = _dtbFlaws.Select(subPieceFilter); foreach (DataRow dr in subFlawRows) { string pointFilter = String.Format("SubpieceName = 'ROI-{0}' AND ClassName = '{1}'", rangeName, dr["FlawClass"]); subPieceScore += Convert.ToInt32(_dtbPoints.Select(pointFilter).First()["Score"]); } } if (showGrade) { string gradeFilter = String.Format("SubpieceName = 'ROI-{0}' AND Score >= {1}", rangeName, subPieceScore); DataRow[] r = _dtbGrades.Select(gradeFilter); if (_dtbGrades.Select(gradeFilter).Length > 0) { subPieceGrade = _dtbGrades.Select(gradeFilter).First()["GradeName"].ToString(); } } // Add annotation TextAnnotation annotation = new TextAnnotation(); PaneAnchorPoint paPoint = new PaneAnchorPoint(); RelativePosition relPosition = new RelativePosition(); annotation.LabelMode = true; annotation.BackColor = System.Drawing.Color.Transparent; annotation.Border.Visible = false; annotation.ConnectorStyle = AnnotationConnectorStyle.None; annotation.Font = new System.Drawing.Font("Tahoma", 8F, FontStyle.Bold); annotation.TextColor = Color.Blue; annotation.Name = rangeName; string annotationScore = ""; if (showScore) { annotationScore = String.Format(" - {0}", subPieceScore); } string annotationGrade = ""; if (showGrade) { annotationGrade = String.Format("({0})", subPieceGrade); } annotation.Text = String.Format("{0}{1}{2}", rangeName, annotationScore, annotationGrade); string annotationX = Convert.ToString(Convert.ToDouble(drCol["Start"]) + (Convert.ToDouble(drCol["End"]) - Convert.ToDouble(drCol["Start"])) * 0.3); string annotationY = Convert.ToString(Convert.ToDouble(drRow["End"]) - (Convert.ToDouble(drRow["End"]) - Convert.ToDouble(drRow["Start"])) * 0.1); paPoint.AxisXCoordinate.AxisValueSerializable = annotationX; paPoint.AxisYCoordinate.AxisValueSerializable = annotationY; annotation.AnchorPoint = paPoint; relPosition.Angle = 0; relPosition.ConnectorLength = 0; annotation.ShapePosition = relPosition; chartControl.AnnotationRepository.AddRange(new Annotation[] { annotation }); _totalScore += subPieceScore; } } } DrawDummyPoint(); // Calculate flaw quantity Dictionary<string, int> flawLegendRefDic = new Dictionary<string, int>(); int i = 0; foreach (DataGridViewRow dgvr in dgvFlawLegendDetial.Rows) { dgvr.Cells["PieceDoffNum"].Value = "0"; flawLegendRefDic.Add(dgvr.Cells["Name"].Value.ToString(), i); i++; } if (flawRows.Length > 0) { foreach (DataRow dr in flawRows) { string flawName = dr["FlawClass"].ToString(); int rowPosition = flawLegendRefDic[flawName]; int flawQuantity = Convert.ToInt32(dgvFlawLegendDetial.Rows[rowPosition].Cells["PieceDoffNum"].Value) + 1; dgvFlawLegendDetial.Rows[rowPosition].Cells["PieceDoffNum"].Value = flawQuantity.ToString(); } } }
private void GradeSetup_Load(object sender, EventArgs e) { // Prepare cmbConfig datasource List<string> gradeConfigs = new List<string>(); DirectoryInfo dirInfo = new DirectoryInfo(PathHelper.GradeConfigFolder); FileInfo[] files = dirInfo.GetFiles("*.xml"); foreach (FileInfo file in files) { gradeConfigs.Add(file.Name.ToString().Substring(0, file.Name.ToString().LastIndexOf("."))); } // Binding cmbConfig cmbConfig.DataSource = gradeConfigs; ConfigHelper ch = new ConfigHelper(); cmbConfig.SelectedItem = ch.GetDefaultGradeConfigName().Trim(); //ROI Settings //----------------------------------------------------------------------------------------// // Initialize Roi Mode RadioButton[] rdos = { rdoNoRoi, rdoSymmetrical }; foreach (RadioButton rdo in rdos) { string roiMode = ch.GetGradeNoRoiMode(cmbConfig.SelectedItem.ToString()); if (rdo.Text == roiMode) { rdo.Checked = true; } else { rdo.Checked = false; } } // Initialize TextBox of Columns, Rows txtColumns.Text = ch.GetGradeColumns(cmbConfig.SelectedItem.ToString()).ToString(); txtRows.Text = ch.GetGradeRows(cmbConfig.SelectedItem.ToString()).ToString(); // Initialize dgvColumns without data. Column name = new Column(0, "Name", 75); Column start = new Column(1, "Start", 60); Column end = new Column(2, "End", 60); List<Column> columns = new List<Column>(); columns.Add(name); columns.Add(start); columns.Add(end); foreach (Column c in columns) { 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; column.FillWeight = c.Width; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; if (column.Name == "Name") { column.ReadOnly = true; } dgvColumns.Columns.Add(column); } dgvColumns.MultiSelect = false; dgvColumns.AutoGenerateColumns = false; // Initialize dgvRows without data. foreach (Column c in columns) { 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; column.FillWeight = c.Width; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; if (column.Name == "Name") { column.ReadOnly = true; } dgvRows.Columns.Add(column); } dgvRows.MultiSelect = false; dgvRows.AutoGenerateColumns = false; // Initialize DataTable of dgvColumns and dgvRows _dtbColumns = ch.GetDataTableOfdgvColumns(cmbConfig.SelectedItem.ToString().Trim()); dgvColumns.DataSource = _dtbColumns; _dtbRows = ch.GetDataTableOfdgvRows(cmbConfig.SelectedItem.ToString().Trim()); dgvRows.DataSource = _dtbRows; // Grade Settings //----------------------------------------------------------------------------------------// // Initialize Point is enable. chkEnablePonit.Checked = ch.IsGradePointEnable(cmbConfig.SelectedItem.ToString().Trim()); // Initialize SubPiece (cmbSubPoints) _pointsSubpieceNames = new List<string>(); _pointsSubpieceNames = ch.GetSubPointsNameList(cmbConfig.SelectedItem.ToString().Trim()); cmbSubPoints.DataSource = _pointsSubpieceNames; // Initialize dgvPoint without data Column className = new Column(0, "ClassName", 200); Column score = new Column(1, "Score", 200); columns = new List<Column>(); columns.Add(className); columns.Add(score); foreach (Column c in columns) { 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; column.FillWeight = c.Width; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; if (c.Name == "ClassName") { //column.ReadOnly = true; } dgvPoint.Columns.Add(column); } dgvPoint.MultiSelect = false; dgvPoint.AutoGenerateColumns = false; // Initialize dgvGrade without data Column gradeName = new Column(0, "GradeName", 200); score = new Column(1, "Score", 200); columns = new List<Column>(); columns.Add(gradeName); columns.Add(score); foreach (Column c in columns) { 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; column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; if (c.Name == "GradeName") { //column.ReadOnly = true; } dgvGrade.Columns.Add(column); } dgvGrade.MultiSelect = false; dgvGrade.AutoGenerateColumns = false; // Set dgvPoint datasource _dtbPoints = ch.GetDataTabledgvPoints(cmbConfig.SelectedItem.ToString().Trim()); dgvPoint.DataSource = _dtbPoints; DataView dvPoints = _dtbPoints.DefaultView; dvPoints.RowFilter = String.Format("SubpieceName='{0}'", cmbSubPoints.SelectedItem.ToString().Trim()); // Initialize grade is enable (marks) chkEnableGrade.Checked = ch.IsGradeMarksEnable(cmbConfig.SelectedItem.ToString().Trim()); // Initialize SubPiece (cmbSubPoints) _marksSubpieceNames = ch.GetSubMarksNameList(cmbConfig.SelectedItem.ToString().Trim()); cmbSubMarks.DataSource = _marksSubpieceNames; // Set dgvGrade datasource _dtbGrades = ch.GetDataTabledgvGrade(cmbConfig.SelectedItem.ToString().Trim()); dgvGrade.DataSource = _dtbGrades; DataView dvGrade = _dtbGrades.DefaultView; dvGrade.RowFilter = String.Format("SubpieceName='{0}'", cmbSubMarks.SelectedItem.ToString().Trim()); // Initialize Tab of grade/pass or fail chkEnablePFS.Checked = ch.IsGradePassFailEnable(cmbConfig.SelectedItem.ToString().Trim()); txtFilterScore.Text = ch.GetPassFailScore(cmbConfig.SelectedItem.ToString().Trim()).ToString(); }
// Save xml private void btnSaveGradeConfigFile_Click(object sender, EventArgs e) { // if some data wrong will tip. if (_dtbColumns.Rows.Count < 1 || _dtbRows.Rows.Count < 1 || _dtbPoints.Rows.Count < 1 || _dtbGrades.Rows.Count < 1) { MessageBox.Show("Input has null value."); return; } DataHelper dh = new DataHelper(); if (dh.HasNull(_dtbColumns) || dh.HasNull(_dtbRows) || dh.HasNull(_dtbPoints) || dh.HasNull(_dtbGrades)) { MessageBox.Show("Input has null value."); return; } // Save default config file to system config ConfigHelper ch = new ConfigHelper(); if (String.IsNullOrEmpty(cmbConfig.Text)) { cmbConfig.Text = DateTime.Now.ToShortDateString(); } // if save error break; if (!ch.SaveGradeSetupConfigFile(cmbConfig.Text.Trim())) { MessageBox.Show("File name is empty."); return; } // ROI-Setting //----------------------------------------------------------------------------------// // initialize grade xml sechma string sechma_path = PathHelper.SystemConfigFolder + "grade_sechma.xml"; XmlDocument document = new XmlDocument(); document.Load(sechma_path); XPathNavigator navigator = document.CreateNavigator(); // save roi mode RadioButton[] rdos = { rdoNoRoi, rdoSymmetrical }; foreach (RadioButton rdo in rdos) { if (rdo.Checked) { navigator.SelectSingleNode("//roi/mode").SetValue(rdo.Text.Trim()); } } // Save roi columns , rows size navigator.SelectSingleNode("//roi/columns/size").SetValue(_dtbColumns.Rows.Count.ToString()); navigator.SelectSingleNode("//roi/rows/size").SetValue(_dtbRows.Rows.Count.ToString()); // save roi data (start, end) of columns , rows. // Remove old columns for add new record if (navigator.Select("//roi/columns/column").Count > 0) { XPathNavigator first = navigator.SelectSingleNode("//roi/columns/column[1]"); XPathNavigator last = navigator.SelectSingleNode("//roi/columns/column[last()]"); navigator.MoveTo(first); navigator.DeleteRange(last); } // save _dgvColumns data to xml for (int i = 0; i < _dtbColumns.Rows.Count; i++) { string name = _dtbColumns.Rows[i]["Name"].ToString(); string start = _dtbColumns.Rows[i]["Start"].ToString(); string end = _dtbColumns.Rows[i]["End"].ToString(); navigator.SelectSingleNode("//roi/columns").AppendChildElement(string.Empty, "column", string.Empty, null); // Move to last column element and add name, start, end value. navigator.SelectSingleNode("//roi/columns/column[last()]").AppendChildElement(string.Empty, "name", string.Empty, name); navigator.SelectSingleNode("//roi/columns/column[last()]").AppendChildElement(string.Empty, "start", string.Empty, start); navigator.SelectSingleNode("//roi/columns/column[last()]").AppendChildElement(string.Empty, "end", string.Empty, end); } // Remove old rows for add new record. if (navigator.Select("//roi/rows/row").Count > 0) { XPathNavigator first = navigator.SelectSingleNode("//roi/rows/row[1]"); XPathNavigator last = navigator.SelectSingleNode("//roi/rows/row[last()]"); navigator.MoveTo(first); navigator.DeleteRange(last); } // save _dtbRows data to xml for (int i = 0; i < _dtbRows.Rows.Count; i++) { string name = _dtbRows.Rows[i]["Name"].ToString(); string start = _dtbRows.Rows[i]["Start"].ToString(); string end = _dtbRows.Rows[i]["End"].ToString(); navigator.SelectSingleNode("//roi/rows").AppendChildElement(string.Empty, "row", string.Empty, null); // Move to last column element and add name, start, end value. navigator.SelectSingleNode("//roi/rows/row[last()]").AppendChildElement(string.Empty, "name", string.Empty, name); navigator.SelectSingleNode("//roi/rows/row[last()]").AppendChildElement(string.Empty, "start", string.Empty, start); navigator.SelectSingleNode("//roi/rows/row[last()]").AppendChildElement(string.Empty, "end", string.Empty, end); } // Grade - Setting //----------------------------------------------------------------------------------// // Points // Save is points enable? navigator.SelectSingleNode("//grade/points/enable").SetValue(chkEnablePonit.Checked.ToString()); // Remove old points/sub_piece for add new record. (_dtbPoints) if (navigator.Select("//grade/points/sub_piece").Count > 0) { XPathNavigator first = navigator.SelectSingleNode("//grade/points/sub_piece[1]"); XPathNavigator last = navigator.SelectSingleNode("//grade/points/sub_piece[last()]"); navigator.MoveTo(first); navigator.DeleteRange(last); } // save _dtbPoints List<string> pointsSubpieces = _pointsSubpieceNames; // prepare flawtype convert dictionary string map_config_path = ch.GetDefaultMapConfigName(); Dictionary<string, int> flawlegends = ch.GetPrevFlawLegendDictionaryID(map_config_path); foreach (string subpieceName in pointsSubpieces) { navigator.SelectSingleNode("//grade/points").AppendChildElement(string.Empty, "sub_piece", string.Empty, null); // Move to last column element and add name value. navigator.SelectSingleNode("//grade/points/sub_piece[last()]").AppendChildElement(string.Empty, "name", string.Empty, subpieceName); string expr = String.Format("SubpieceName='{0}'", subpieceName); // check all same if (chkAllSameOfPoint.Checked) { expr = String.Format("SubpieceName='{0}'", "All"); } DataRow[] drs = _dtbPoints.Select(expr); foreach (DataRow dr in drs) { string className = dr["ClassName"].ToString(); int classID = flawlegends[className]; string score = dr["Score"].ToString(); navigator.SelectSingleNode("//grade/points/sub_piece[last()]").AppendChildElement(string.Empty, "flawtype_score", string.Empty, score); navigator.SelectSingleNode("//grade/points/sub_piece[last()]/flawtype_score[last()]").CreateAttribute(string.Empty, "id", string.Empty, classID.ToString()); } } // Remove old grade(marks)/subpiece for add new record . (_dtbGrades) if (navigator.Select("//grade/marks/sub_piece").Count > 0) { XPathNavigator first = navigator.SelectSingleNode("//grade/marks/sub_piece[1]"); XPathNavigator last = navigator.SelectSingleNode("//grade/marks/sub_piece[last()]"); navigator.MoveTo(first); navigator.DeleteRange(last); } // Marks // Save is grade(marks) enable? navigator.SelectSingleNode("//grade/marks/enable").SetValue(chkEnableGrade.Checked.ToString()); // save _dtbGrades List<string> marksSubpieces = _marksSubpieceNames; foreach (string subpieceName in marksSubpieces) { navigator.SelectSingleNode("//grade/marks").AppendChildElement(string.Empty, "sub_piece", string.Empty, null); //Move to last column element and add name value. navigator.SelectSingleNode("//grade/marks/sub_piece[last()]").AppendChildElement(string.Empty, "name", string.Empty, subpieceName); string expr = String.Format("SubpieceName='{0}'", subpieceName); // check all same if (chkAllSameOfGrade.Checked) { expr = String.Format("SubpieceName='{0}'", "All"); } DataRow[] drs = _dtbGrades.Select(expr); foreach (DataRow dr in drs) { string className = dr["GradeName"].ToString(); string score = dr["Score"].ToString(); navigator.SelectSingleNode("//grade/marks/sub_piece[last()]").AppendChildElement(string.Empty, "mark", string.Empty, score); navigator.SelectSingleNode("//grade/marks/sub_piece[last()]/mark[last()]").CreateAttribute(string.Empty, "id", string.Empty, className); } } // Pass or Fail // Save filter score is enable? navigator.SelectSingleNode("//grade/pass_fail/enable").SetValue(chkEnablePFS.Checked.ToString()); int filterScore = int.TryParse(txtFilterScore.Text, out filterScore) ? filterScore : 0; navigator.SelectSingleNode("//grade/pass_fail/score").SetValue(filterScore.ToString()); // Finish Save //----------------------------------------------------------------------------------// string grade_path = PathHelper.GradeConfigFolder + cmbConfig.Text.Trim() + ".xml"; try { document.Save(grade_path); // Re binding cmbMapConfigName datasource List<string> graeConfigs = new List<string>(); DirectoryInfo dirInfo = new DirectoryInfo(PathHelper.GradeConfigFolder); FileInfo[] files = dirInfo.GetFiles("*.xml"); foreach (FileInfo file in files) { graeConfigs.Add(file.Name.ToString().Substring(0, file.Name.ToString().LastIndexOf("."))); } // Binding datasource for cmbMapConfigName and set default value. cmbConfig.DataSource = graeConfigs; cmbConfig.SelectedItem = ch.GetDefaultGradeConfigName().Trim(); MessageBox.Show("Success."); } catch { MessageBox.Show("Fail."); } // Refresh datas // Refresh dgvPoint datasource _dtbPoints.Clear(); DataTable tmpPoints = ch.GetDataTabledgvPoints(cmbConfig.SelectedItem.ToString().Trim()); foreach (DataRow dr in tmpPoints.Rows) { DataRow d = _dtbPoints.NewRow(); d["SubpieceName"] = dr["SubpieceName"]; d["ClassName"] = dr["ClassName"]; d["Score"] = dr["Score"]; _dtbPoints.Rows.Add(d); } DataView dvPoints = _dtbPoints.DefaultView; dvPoints.RowFilter = String.Format("SubpieceName='{0}'", cmbSubPoints.SelectedItem.ToString().Trim()); tmpPoints.Dispose(); // Refresh dgvGrade datasource _dtbGrades.Clear(); DataTable tmpGrades = ch.GetDataTabledgvGrade(cmbConfig.SelectedItem.ToString().Trim()); foreach (DataRow dr in tmpGrades.Rows) { DataRow d = _dtbGrades.NewRow(); d["SubpieceName"] = dr["SubpieceName"]; d["GradeName"] = dr["GradeName"]; d["Score"] = dr["Score"]; _dtbGrades.Rows.Add(d); } DataView dvGrade = _dtbGrades.DefaultView; dvGrade.RowFilter = String.Format("SubpieceName='{0}'", cmbSubMarks.SelectedItem.ToString().Trim()); tmpGrades.Dispose(); }
private void btnReset_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Are you sure you want to reset subpiece setting?", "Reset Setting", MessageBoxButtons.YesNo,MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { // Prepare cmbConfig datasource List<string> gradeConfigs = new List<string>(); DirectoryInfo dirInfo = new DirectoryInfo(PathHelper.GradeConfigFolder); FileInfo[] files = dirInfo.GetFiles("*.xml"); foreach (FileInfo file in files) { gradeConfigs.Add(file.Name.ToString().Substring(0, file.Name.ToString().LastIndexOf("."))); } // Binding cmbConfig cmbConfig.DataSource = gradeConfigs; ConfigHelper ch = new ConfigHelper(); cmbConfig.SelectedItem = ch.GetDefaultGradeConfigName().Trim(); //ROI Settings //----------------------------------------------------------------------------------------// // Initialize Roi Mode RadioButton[] rdos = { rdoNoRoi, rdoSymmetrical }; foreach (RadioButton rdo in rdos) { string roiMode = ch.GetGradeNoRoiMode(cmbConfig.SelectedItem.ToString()); if (rdo.Text == roiMode) { rdo.Checked = true; } else { rdo.Checked = false; } } // Initialize TextBox of Columns, Rows txtColumns.Text = ch.GetGradeColumns(cmbConfig.SelectedItem.ToString()).ToString(); txtRows.Text = ch.GetGradeRows(cmbConfig.SelectedItem.ToString()).ToString(); // Initialize DataTable of dgvColumns and dgvRows _dtbColumns = ch.GetDataTableOfdgvColumns(cmbConfig.SelectedItem.ToString().Trim()); dgvColumns.DataSource = _dtbColumns; _dtbRows = ch.GetDataTableOfdgvRows(cmbConfig.SelectedItem.ToString().Trim()); dgvRows.DataSource = _dtbRows; // Grade Settings //----------------------------------------------------------------------------------------// // Initialize Point is enable. chkEnablePonit.Checked = ch.IsGradePointEnable(cmbConfig.SelectedItem.ToString().Trim()); // Initialize SubPiece (cmbSubPoints) _pointsSubpieceNames = ch.GetSubPointsNameList(cmbConfig.SelectedItem.ToString().Trim()); // Set dgvPoint datasource _dtbPoints = ch.GetDataTabledgvPoints(cmbConfig.SelectedItem.ToString().Trim()); dgvPoint.DataSource = _dtbPoints; DataView dvPoints = _dtbPoints.DefaultView; dvPoints.RowFilter = String.Format("SubpieceName='{0}'", cmbSubPoints.SelectedItem.ToString().Trim()); // Initialize grade is enable (marks) chkEnableGrade.Checked = ch.IsGradeMarksEnable(cmbConfig.SelectedItem.ToString().Trim()); // Initialize SubPiece (cmbSubPoints) cmbSubMarks.DataSource = ch.GetSubMarksNameList(cmbConfig.SelectedItem.ToString().Trim()); // Set dgvGrade datasource _dtbGrades = ch.GetDataTabledgvGrade(cmbConfig.SelectedItem.ToString().Trim()); dgvGrade.DataSource = _dtbGrades; DataView dvGrade = _dtbGrades.DefaultView; dvGrade.RowFilter = String.Format("SubpieceName='{0}'", cmbSubMarks.SelectedItem.ToString().Trim()); // Initialize Tab of grade/pass or fail chkEnablePFS.Checked = ch.IsGradePassFailEnable(cmbConfig.SelectedItem.ToString().Trim()); txtFilterScore.Text = ch.GetPassFailScore(cmbConfig.SelectedItem.ToString().Trim()).ToString(); } }