using OTSCLRINTERFACE; using OTSCommon; using OTSCommon.DBOperate; using OTSCommon.DBOperate.Model; using OTSIncAReportApp.OTSRstMgrFunction; using OTSIncAReportGraph.Class; using OTSIncAReportGrids.OTSIncAReportGridsFuncation; using OTSPeriodicTable; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.SQLite; using System.Drawing; using System.Linq; using System.Reflection; using System.Threading; using System.Windows.Forms; using static OTSDataType.otsdataconst; using Color = System.Drawing.Color; namespace OTSIncAReportApp._1_UI.Control_Grids.ParticlesGridDevidePage { public partial class ListOfSimilarParticles : Form { OTSIncAReportGrids.ParticlesGridDevidePage _particlesGridDevidePage; CPosXrayClr SelXrayclr = new CPosXrayClr(); DataTable particlesAll; DataTable particles; Hashtable table; int _classifyid; List _RenameInfo; private Thread m_mythread; //记录线程是否已经运行完成的状态 private bool m_mythread_state = false; //底层操作类 OTSReportGridsFun m_OTSIncAReportGridsFun = null; frmReportApp m_ReportApp; public ListOfSimilarParticles(OTSIncAReportGrids.ParticlesGridDevidePage particlesGridDevidePage, uint[] SelXray, int classifyid, List RenameInfo,frmReportApp ReportApp) { InitializeComponent(); _particlesGridDevidePage = particlesGridDevidePage; SelXrayclr.SetXrayData(SelXray); table = particlesGridDevidePage.table; _classifyid = classifyid; _RenameInfo = RenameInfo; m_ReportApp = ReportApp; m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO)); //设置窗体的双缓冲,以保证大数据时拖动不卡 this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles(); //利用反射设置DataGridView的双缓冲 Type dgvType = this.dgV_SimilarParticles.GetType(); PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic); pi.SetValue(this.dgV_SimilarParticles, true, null); this.control_XRayTable1 = new OTSIncAReportGraph.Controls.Control_XRayTable(null); this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom; this.control_XRayTable1.GBInfoStr = ""; this.control_XRayTable1.GoodChineseName = ""; this.control_XRayTable1.MaterialName = ""; this.control_XRayTable1.Location = new System.Drawing.Point(0, 400); this.control_XRayTable1.Name = "control_XRayTable1"; this.control_XRayTable1.ShowAnalysisXray = true; this.control_XRayTable1.ShowSearchXray = false; this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200); this.control_XRayTable1.STDName = ""; this.control_XRayTable1.Visible = false; this.control_XRayTable1.label_close.Visible = true; panel1.Controls.Add(this.control_XRayTable1); } private void btn_Search_Click(object sender, EventArgs e) { double val; if (!double.TryParse(tB_SimilarRatio.Text, out val)) { MessageBox.Show("The value must range from 0 to 100!"); return; } else { this.Cursor = Cursors.WaitCursor; particlesAll = ObtainSourceOfSimilarParticles(_classifyid); DataTable elementchemistry = _particlesGridDevidePage.Particledata.GetElementChemistry(); for (int i = 0; i < particlesAll.Rows.Count; i++) { string str = "XRayId = " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString(); DataRow[] drs = elementchemistry.Select(str); string ConcatenatedString = ""; for (int j = 0; j < drs.Length; j++) { ConcatenatedString += drs[j]["name"] + "-" + drs[j]["Percentage"] + ';'; } particlesAll.Rows[i]["Element"] = ConcatenatedString; } particlesAll.Columns.Add("SimilarRatio", typeof(double)); DataTable mergeParticles = _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_mergeParticles(""); if (mergeParticles != null && mergeParticles.Rows.Count > 0) { _particlesGridDevidePage.RemoveMergeParticles(ref particlesAll, mergeParticles); } DataTable XRayData = _particlesGridDevidePage.Particledata.GetXRayData(); particlesAll.Columns.Add("XRayDataCount"); particles = particlesAll.Clone(); for (int i = 0; i < particlesAll.Rows.Count; i++) { if (int.Parse(particlesAll.Rows[i]["particleId"].ToString()) > -1) { particlesAll.Rows[i]["XRayDataCount"] = 0; string str = " XrayIndex= " + particlesAll.Rows[i]["particleId"].ToString() + " and fieldid = " + particlesAll.Rows[i]["fieldid"].ToString(); DataRow[] drs = XRayData.Select(str); uint xraycount = 0; if (drs != null) { if (drs.Length > 0) { uint[] Analysis_xray = new uint[2000]; for (int j = 0; j < 2000; j++) { Analysis_xray[j] = BitConverter.ToUInt32((byte[])drs[0][2], j * 4); } for (int j = 0; j < 2000; j++) { xraycount += Analysis_xray[j]; } particlesAll.Rows[i]["XRayDataCount"] = xraycount; CPosXrayClr Xrayclr = new CPosXrayClr(); Xrayclr.SetXrayData(Analysis_xray); particlesAll.Rows[i]["SimilarRatio"] = GetCosValue(SelXrayclr, Xrayclr); if ((double)particlesAll.Rows[i]["SimilarRatio"] >= val / 100) { particles.ImportRow(particlesAll.Rows[i]); } } } } } particles.DefaultView.Sort = "SimilarRatio DESC"; particles = particles.DefaultView.ToTable(); BindDataGridView(); SetDataGridViewStyle(); cBx_All.Checked = false; cBx_All.Checked = true; label3.Text = "共搜索到" + (dgV_SimilarParticles.Rows.Count-1).ToString() + "个相似颗粒"; this.Cursor = Cursors.Default; } } private void SetDataGridViewStyle() { //用户不能调整标题的高度 dgV_SimilarParticles.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //用户不能调整 行高 dgV_SimilarParticles.AllowUserToResizeRows = false; //点击选择整行 dgV_SimilarParticles.SelectionMode = DataGridViewSelectionMode.FullRowSelect; //居中显示 System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dgV_SimilarParticles.DefaultCellStyle = dataGridViewCellStyle1; dgV_SimilarParticles.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; //再次重覆禁用拖动表头高度,居然有效果了 dgV_SimilarParticles.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //设置grid可以复制 dgV_SimilarParticles.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; //设置每列的宽度 dgV_SimilarParticles.Columns[0].Width = 30;//第一列序号的宽度设置一下吧,要不太丑 dgV_SimilarParticles.Columns[1].Width = 100; for (int i = 4; i < dgV_SimilarParticles.Columns.Count; i++) { dgV_SimilarParticles.Columns[i].Width = 65; } //设置序号列不排序 dgV_SimilarParticles.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; dgV_SimilarParticles.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable; //设置序号列不可以设置宽度 dgV_SimilarParticles.Columns[0].Resizable = DataGridViewTriState.False; dgV_SimilarParticles.RowsDefaultCellStyle.BackColor = Color.Azure; if (dgV_SimilarParticles.Rows.Count > 0) { dgV_SimilarParticles.Rows[0].Frozen = true; } } private void BindDataGridView() { dgV_SimilarParticles.Visible = false; dgV_SimilarParticles.Rows.Clear(); dgV_SimilarParticles.Columns.Clear(); string str_DefaultComputedColName = "", str_ElementsColName = ""; DataSet ds = XMLoperate.GetXmlData(Application.StartupPath + RptConfigFile.m_ReportMgrParamFile, "XMLData"); DataTable dt = ds.Tables["Member"]; foreach (DataRow element in dt.Rows) { string RegName = element["RegName"].ToString(); if (RegName == "DefaultComputedColName") { str_DefaultComputedColName = element["strValue"].ToString(); } if (RegName == "ElementsColName") { str_ElementsColName = element["strValue"].ToString(); } } string[] strs = str_DefaultComputedColName.Split(','); Dictionary keyValues = new Dictionary() { }; keyValues.Add("SimilarRatio", "相似度"); keyValues.Add("TypeName", table["str6"].ToString()); keyValues.Add("ParticleImage", table["str5"].ToString()); keyValues.Add("FieldId", "FieldId"); keyValues.Add("ParticleId", "ParticleId"); keyValues.Add("SEMPosX", "SEMPosX"); keyValues.Add("SEMPosY", "SEMPosY"); for (int i = 0; i < strs.Count(); i++) { if (strs[i] == "ParticleCoordinate") { keyValues.Add("AbPosX", "PosX"); keyValues.Add("AbPosY", "PosY"); } if (strs[i] == "Area") { keyValues.Add("Area", table["str21"].ToString()); } if (strs[i] == "EquivalentCircleDiameter") { keyValues.Add("Equivalent", table["str22"].ToString()); } if (strs[i] == "MaxDiameter") { keyValues.Add("DMAX", table["str23"].ToString()); } if (strs[i] == "MinDiameter") { keyValues.Add("DMIN", table["str24"].ToString()); } if (strs[i] == "DiameterRatio") { keyValues.Add("DiameterRatio", table["str25"].ToString()); } if (strs[i] == "FerretDiameter") { keyValues.Add("DFERET", table["str26"].ToString()); } if (strs[i] == "PERP") { keyValues.Add("DPERP", table["str27"].ToString()); } if (strs[i] == "PERI") { keyValues.Add("PERIMETER", table["str28"].ToString()); } if (strs[i] == "INSCR") { keyValues.Add("DINSCR", table["str29"].ToString()); } if (strs[i] == "MEAN") { keyValues.Add("DMEAN", table["str30"].ToString()); } if (strs[i] == "ELONG") { keyValues.Add("DELONG", table["str31"].ToString()); } if (strs[i] == "ASPECT_ELONG") { keyValues.Add("ASPECT_ELONG", table["str32"].ToString()); } if (strs[i] == "Orientation") { keyValues.Add("ORIENTATION", table["str33"].ToString()); } if (strs[i] == "XRayDataCount") { keyValues.Add("XRayDataCount", "XRay计数"); } } keyValues.Add("Element", "Element"); Dictionary.Enumerator en = keyValues.GetEnumerator(); for (int irow = 0; irow < keyValues.Count; irow++) { if (en.MoveNext()) { if (en.Current.Key == "ParticleImage") { DataGridViewImageColumn iconColumn = new DataGridViewImageColumn(); iconColumn.Name = en.Current.Key; iconColumn.HeaderText = en.Current.Value; dgV_SimilarParticles.Columns.Add(iconColumn); } else if (en.Current.Key == "Element") { } else { dgV_SimilarParticles.Columns.Add(en.Current.Key, en.Current.Value); if (en.Current.Key == "Area" || en.Current.Key == "EquivalentCircleDiameter" || en.Current.Key == "MaxDiameter" || en.Current.Key == "MinDiameter" || en.Current.Key == "DiameterRatio" || en.Current.Key == "FerretDiameter" || en.Current.Key == "PERP" || en.Current.Key == "PERI" || en.Current.Key == "INSCR" || en.Current.Key == "MEAN" || en.Current.Key == "ELONG" || en.Current.Key == "ASPECT_ELONG" || en.Current.Key == "Orientation") { int id = dgV_SimilarParticles.Columns.Count; dgV_SimilarParticles.Columns[id - 1].Tag = "NumericType"; } } } } if (particlesAll == null) { return; } string particleM = ""; List ElementTypeSort = new List(str_ElementsColName.Split(',').ToList());//去重 for (int i = 0; i < ElementTypeSort.Count; i++) { if (ElementTypeSort[0] == "") { ElementTypeSort.RemoveAt(0); break; } dgV_SimilarParticles.Columns.Add(ElementTypeSort[i], ElementTypeSort[i]); int id = dgV_SimilarParticles.Columns.Count; dgV_SimilarParticles.Columns[id - 1].Tag = "NumericType"; } string filePath = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\"; KeyValuePair FieldImage = new KeyValuePair(); for (int i = 0; i < particles.Rows.Count; i++) { Dictionary.Enumerator enl = keyValues.GetEnumerator(); int add_rowindex = dgV_SimilarParticles.Rows.Add(); for (int k = 0; k < keyValues.Count; k++) { if (enl.MoveNext()) { if (enl.Current.Key == "ParticleImage") { if (particles.Columns.Contains("SubParticles")) { string subt = particles.Rows[i]["SubParticles"].ToString(); if (subt != null && subt != "") { double ScanFieldSize = _particlesGridDevidePage.result.GetScanFieldSizeX(); string filePatht = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\"; string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp"; Bitmap tempbit = _particlesGridDevidePage.Particledata.ReadImageFile(imagePatht); int pixw = tempbit.Width; double xs = pixw / ScanFieldSize; particleM = particleM + "," + subt; Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapForBig(subt, xs, _particlesGridDevidePage.result.FilePath, tempbit.Height, tempbit.Width); if (bmap != null) { string[] str = subt.Split(','); bmap.Tag = new List() { str[0].Split(':')[0], str[0].Split(':')[1], particles.Rows[i]["TypeId"].ToString() }; dgV_SimilarParticles.Rows[add_rowindex].Height = 150; dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = bmap; dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure; dgV_SimilarParticles.Rows[add_rowindex].DefaultCellStyle.ForeColor = Color.Chocolate; } else { dgV_SimilarParticles.Rows[add_rowindex].Height = 150; dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Style.BackColor = Color.Azure; } } } else { if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null) { string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp"; FieldImage = new KeyValuePair(particles.Rows[i]["fieldid"].ToString(), _particlesGridDevidePage.Particledata.ReadImageFile(imagePath)); } Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particles.Rows[i]["RectLeft"]), Y = Convert.ToInt32(particles.Rows[i]["RectTop"]), Width = Convert.ToInt32(particles.Rows[i]["RectWidth"]), Height = Convert.ToInt32(particles.Rows[i]["RectHeight"]) }; Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapByParticle(FieldImage.Value, rectangle); bmap.Tag = new List() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString(), particles.Rows[i]["XrayId"].ToString() }; dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = bmap; dgV_SimilarParticles.Rows[add_rowindex].Height = bmap.Height + 20; } } if (enl.Current.Key == "DiameterRatio") { double d = Convert.ToDouble(particles.Rows[i]["DMAX"]) / Convert.ToDouble(particles.Rows[i]["DMIN"]); dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2); } if (en.Current.Key == "Element") { } if (enl.Current.Key == "ASPECT_ELONG") { double d = Convert.ToDouble(particles.Rows[i]["DELONG"]) / Convert.ToDouble(particles.Rows[i]["DMEAN"]); dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(d, 2); } if (particles.Columns.Contains(enl.Current.Key)) { double num = 0; if (double.TryParse(particles.Rows[i][enl.Current.Key].ToString(), out num)) { if (enl.Current.Key == "SimilarRatio") { dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 5); } else { dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(num, 2);} } else if (enl.Current.Key == "Element") { List elementtemp = new List(ElementTypeSort); string[] strcbo = particles.Rows[i][enl.Current.Key].ToString().Split(';'); for (int j = 0; j < strcbo.Length; j++) { if (ElementTypeSort.Count == 0) { break; } string[] str = strcbo[j].Split('-'); if (ElementTypeSort.Contains(str[0])) { dgV_SimilarParticles.Rows[add_rowindex].Cells[str[0].ToString()].Value = Math.Round(double.Parse(str[1]), 2).ToString(); } elementtemp.Remove(str[0].ToString()); } foreach (var ele in elementtemp) { dgV_SimilarParticles.Rows[add_rowindex].Cells[ele].Value = "0"; } } else { double val = 0; if (double.TryParse(Convert.ToString(particles.Rows[i][enl.Current.Key]), out val)) { dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = val; } else { dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = particles.Rows[i][enl.Current.Key]; } } } if (enl.Current.Key == "TypeName") { if (particles.Rows[i]["TypeId"].ToString() == "9") { dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = "Not Identified"; } } if (enl.Current.Key == "Equivalent") { double dSize = Convert.ToDouble(particles.Rows[i]["Area"]); double Diameter = Math.Sqrt(dSize / Math.PI) * 2; dgV_SimilarParticles.Rows[add_rowindex].Cells[k].Value = Math.Round(Diameter, 2); } if (enl.Current.Key == "AbPosX") { Point point = OTSIncAReportGrids.ParticlesGridDevidePage.CalculateParticleCenterPosition(_particlesGridDevidePage.result, new Point(Convert.ToInt32(particles.Rows[i]["SEMPosX"]), Convert.ToInt32(particles.Rows[i]["SEMPosY"])), new Point(Convert.ToInt32(particles.Rows[i]["PosX"]), Convert.ToInt32(particles.Rows[i]["PosY"]))); dgV_SimilarParticles.Rows[add_rowindex].Cells["AbPosX"].Value = point.X; dgV_SimilarParticles.Rows[add_rowindex].Cells["AbPosY"].Value = point.Y; } } } } DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn(); checkBoxColumn.HeaderText = "选择"; checkBoxColumn.Name = "IsSelected"; checkBoxColumn.TrueValue = true; checkBoxColumn.FalseValue = false; checkBoxColumn.Width = 30; checkBoxColumn.ReadOnly = false; dgV_SimilarParticles.Columns.Insert(0, checkBoxColumn); if (_RenameInfo != null) { dgV_SimilarParticles.Rows[0].Cells[2].Value = _RenameInfo[1]; } dgV_SimilarParticles.Visible = true; } private double GetCosValue(CPosXrayClr posXray, CPosXrayClr posXray1) { if (posXray == null) return 0; if (posXray1 == null) return 0; if (posXray.GetChannelsNum() != posXray1.GetChannelsNum()) { return 0; } var pXrayData = posXray.GetXrayData(); var pXrayData1 = posXray1.GetXrayData(); // 公式: (x1y1+x2y2+x3y3+...x2000y2000) / (sqrt(x1^2 + x2^2 + ...x2000^2) * sqrt(y1^2 + y2^2 + ...y2000^2)) double dotProduct = 0; double d1 = 0; double d2 = 0; for (int i = 0; i < posXray.GetChannelsNum(); i++) { double r1 = pXrayData[i]; double r2 = pXrayData1[i]; r1 *= r2; dotProduct = dotProduct + r1; } d1 = posXray.GetXrayDataVectorNorm(); d2 = posXray1.GetXrayDataVectorNorm(); return (0 == d1 || 0 == d2) ? 0 : dotProduct / (d1 * d2); } private void ListOfSimilarParticles_Load(object sender, EventArgs e) { btn_Search_Click(null, null); } private void btn_OK_Click(object sender, EventArgs e) { if (_RenameInfo == null) { string CategoryName = ""; //循环选中颗粒 DataGridViewRow dgvr = dgV_SimilarParticles.Rows[0]; CategoryName = dgvr.Cells[2].Value.ToString(); string TypeId = ""; string TypeName = ""; string TypeColor = ""; string GroupName = ""; string GroupID = ""; string GroupColor = ""; string[] resulta = _particlesGridDevidePage.result.GetSTDName().Split('.'); DataTable data = ReadClassification(_particlesGridDevidePage.result.FilePath, resulta[0]); ModifyCategoryForm modifyCategoryForm = new ModifyCategoryForm(data, CategoryName); DialogResult result = modifyCategoryForm.ShowDialog(); if (modifyCategoryForm.DoYouWantToModifyIt) { TypeId = modifyCategoryForm.OutTypeAndName[0]; TypeName = modifyCategoryForm.OutTypeAndName[1]; TypeColor = modifyCategoryForm.OutTypeAndName[2]; GroupName = modifyCategoryForm.OutTypeAndName[3]; GroupID = modifyCategoryForm.OutTypeAndName[4]; GroupColor = modifyCategoryForm.OutTypeAndName[5]; _RenameInfo = new List(); _RenameInfo.Add(TypeId); _RenameInfo.Add(TypeName); _RenameInfo.Add(TypeColor); _RenameInfo.Add(GroupName); _RenameInfo.Add(GroupID); _RenameInfo.Add(GroupColor); } else { return; } } List> cmdlist = new List>(); foreach (DataGridViewRow row in dgV_SimilarParticles.Rows) { if (row.Cells["IsSelected"].Value != null && (bool)row.Cells["IsSelected"].Value) { row.Cells[1].Value = _RenameInfo[0]; Bitmap ls_bp = (Bitmap)row.Cells[3].Value; List list_str = (List)ls_bp.Tag; int i_ls_fieldid = Convert.ToInt32(list_str[0]); int i_ls_particleid = Convert.ToInt32(list_str[1]); List ints = new List(); ints.Add(i_ls_fieldid); ints.Add(i_ls_particleid); var cmd = _particlesGridDevidePage.Particledata.GetUpdataAIncACmd(ints, _RenameInfo); cmdlist.Add(cmd); } } _particlesGridDevidePage.Particledata.ExecuteNonQueryBatch(cmdlist); this.DialogResult = DialogResult.OK; this.Close(); } /// /// 读取标准库的ClassifySTD表 /// /// /// private DataTable ReadClassification(string a_address, string STDName) { DataTable dt_STDGroups = new DataTable(); DataTable dt_ClassifySTD = new DataTable(); DataTable dt_IncAData = new DataTable(); var systype = m_ReportApp.m_RptConfigFile.Systype; if (systype == OTS_SysType_ID.IncA) { dt_ClassifySTD.Columns.Add("STDId"); dt_ClassifySTD.Columns.Add("StrName"); dt_ClassifySTD.Columns.Add("Color"); dt_ClassifySTD.Columns.Add("KeyElementList"); dt_ClassifySTD.Columns.Add("SubElementList"); dt_ClassifySTD.Columns.Add("UsingImgPropertyList"); dt_ClassifySTD.Columns.Add("UsingOtherPropertyList"); dt_ClassifySTD.Columns.Add("Expression"); dt_ClassifySTD.Columns.Add("Hardness"); dt_ClassifySTD.Columns.Add("Density"); dt_ClassifySTD.Columns.Add("Electrical_conductivity"); dt_ClassifySTD.Columns.Add("BSE"); dt_ClassifySTD.Columns.Add("Formula"); dt_ClassifySTD.Columns.Add("Element"); dt_ClassifySTD.Columns.Add("IfElementAnalysis"); dt_ClassifySTD.Columns.Add("ListNum"); dt_ClassifySTD.Columns.Add("GroupId"); dt_ClassifySTD.Columns.Add("GroupName"); dt_ClassifySTD.Columns.Add("GroupColor"); DataTable da = _particlesGridDevidePage.Particledata.GetParticleListForParticlSizeID("area", ""); for (int i = 0; i < da.Rows.Count; i++) { if (Convert.ToInt64(da.Rows[i]["TypeId"]) > 9) { DataRow newRow = dt_ClassifySTD.NewRow(); newRow["STDId"] = da.Rows[i]["TypeId"]; newRow["StrName"] = da.Rows[i]["TypeName"]; newRow["Color"] = da.Rows[i]["TypeColor"]; newRow["GroupId"] = da.Rows[i]["GroupId"]; newRow["GroupName"] = da.Rows[i]["GroupName"]; newRow["GroupColor"] = da.Rows[i]["GroupColor"]; dt_ClassifySTD.Rows.Add(newRow); } } } else { SqLiteHelper sh_STDGroups = new SqLiteHelper("data source='" + a_address + "\\" + STDName + ".db" + "'"); dt_STDGroups = sh_STDGroups.ExecuteQuery("select * from STDGroups"); SqLiteHelper sh_ClassifySTD = new SqLiteHelper("data source='" + a_address + "\\" + STDName + ".db" + "'"); dt_ClassifySTD = sh_ClassifySTD.ExecuteQuery("select * from ClassifySTD"); dt_ClassifySTD.Columns.Add("GroupName"); dt_ClassifySTD.Columns.Add("GroupColor"); for (int i = 0; i < dt_ClassifySTD.Rows.Count; i++) { for (int a = 0; a < dt_STDGroups.Rows.Count; a++) { if (dt_ClassifySTD.Rows[i]["GroupId"].ToString() == dt_STDGroups.Rows[a]["id"].ToString()) { dt_ClassifySTD.Rows[i]["GroupName"] = dt_STDGroups.Rows[a]["name"].ToString(); dt_ClassifySTD.Rows[i]["GroupColor"] = dt_STDGroups.Rows[a]["color"].ToString(); continue; } } } SqLiteHelper sh_Inclusion = new SqLiteHelper("data source='" + a_address + "\\FIELD_FILES\\Inclusion.db" + "'"); dt_IncAData = sh_Inclusion.ExecuteQuery("select * from IncAData"); for (int i = 0; i < dt_IncAData.Rows.Count; i++) { if (Convert.ToInt64(dt_IncAData.Rows[i]["TypeId"]) > 50000) { DataRow newRow = dt_ClassifySTD.NewRow(); newRow["STDId"] = dt_IncAData.Rows[i]["TypeId"]; newRow["StrName"] = dt_IncAData.Rows[i]["TypeName"]; newRow["Color"] = dt_IncAData.Rows[i]["TypeColor"]; newRow["GroupId"] = dt_IncAData.Rows[i]["GroupId"]; newRow["GroupName"] = dt_IncAData.Rows[i]["GroupName"]; newRow["GroupColor"] = dt_IncAData.Rows[i]["GroupColor"]; dt_ClassifySTD.Rows.Add(newRow); } } } return dt_ClassifySTD; } private void cBx_All_CheckedChanged(object sender, EventArgs e) { CheckBox selectAllCheckBox = (CheckBox)sender; foreach (DataGridViewRow row in dgV_SimilarParticles.Rows) { DataGridViewCheckBoxCell checkBox = row.Cells["IsSelected"] as DataGridViewCheckBoxCell; checkBox.Value = selectAllCheckBox.Checked; } dgV_SimilarParticles.Rows[0].Cells[0].Value = true; } DataTable ObtainSourceOfSimilarParticles(int _classifyid) { if (_classifyid == -1) { return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_InvalidParticle(""); } else if (_classifyid == 9) { return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_NotIdentifyParticle(""); } else if (_classifyid != 4) { return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_analyticalParticle(""); } else if (_classifyid == 4) { return _particlesGridDevidePage.Particledata.GetInfoForPartucleDevidePage_LowCountsParticle(""); } return null; } private void btn_Cannnel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } private void dgV_SimilarParticles_MouseUp(object sender, MouseEventArgs e) { var SelectRows = dgV_SimilarParticles.SelectedRows; if (SelectRows.Count != 0) { if (SelectRows.Count == 1) { DataGridViewRow dgvr = SelectRows[0]; Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value; List list_str = (List)ls_bp.Tag; uint[] Search_xray = new uint[2000]; uint[] Analysis_xray = new uint[2000]; int i_xray_id = 0; List list_celementchemistryclr = new List(); _particlesGridDevidePage.ReportFun.GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(Convert.ToInt32(dgvr.Cells["particleId"].Value), Convert.ToInt32(dgvr.Cells["fieldid"].Value), out Search_xray, out Analysis_xray, out i_xray_id, out list_celementchemistryclr); List list_showelementinfo = new List(); for (int i = 0; i < list_celementchemistryclr.Count; i++) { OTSIncAReportGraph.Controls.ShowElementInfo ls_sei = new OTSIncAReportGraph.Controls.ShowElementInfo(); ls_sei.ElementName = list_celementchemistryclr[i].Name; ls_sei.Percentage = list_celementchemistryclr[i].Percentage; ls_sei.dKF = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).K_Peak); double de_sx2 = 0; if (CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "" || CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak == "-") { de_sx2 = 0; } else { de_sx2 = Convert.ToDouble(CListPeriodic.GetPeriodicByEleName(ls_sei.ElementName).L_Peak); } ls_sei.dLF = de_sx2; list_showelementinfo.Add(ls_sei); } list_showelementinfo.Sort((p1, p2) => p2.Percentage.CompareTo(p1.Percentage)); string str_IncAName = ""; str_IncAName = Convert.ToString(dgvr.Cells[2].Value); Particle particle = _particlesGridDevidePage.result.List_OTSField.Find(x => x.FieldID == Convert.ToInt32(dgvr.Cells["fieldid"].Value)).ParticleList.Find(x => x.ParticleId == Convert.ToInt32(dgvr.Cells["particleId"].Value)); if (particle == null) { return; } control_XRayTable1.SetParticleInfo("Area:" + Math.Round(particle.Area, 2) + " " + "DMAX:" + Math.Round(particle.DMAX, 2) + " " + "DELONG:" + Math.Round(particle.DELONG, 2) + " " + "DFERET:" + Math.Round(particle.DFERET, 2) + " " + "DINSCR:" + Math.Round(particle.DINSCR, 2) + "\n" + "DMEAN:" + Math.Round(particle.DMEAN, 2) + " " + "DMIN:" + Math.Round(particle.DMIN, 2) + " " + "DPERP:" + Math.Round(particle.DPERP, 2) + " " + "ORIENTATION:" + Math.Round(particle.ORIENTATION, 2) + " " + "PERIMETER:" + Math.Round(particle.PERIMETER, 2)); control_XRayTable1.Visible = true; control_XRayTable1.SetXRayShowLineValue(null, Analysis_xray, list_showelementinfo); //颗粒国标信息 control_XRayTable1.GBInfoStr = ""; control_XRayTable1.MaterialName = str_IncAName;//杂夹物 control_XRayTable1.List_ShowElementInfo = list_showelementinfo; string str = " particleId= " + dgvr.Cells["particleId"].Value.ToString() + " and fieldid = " + dgvr.Cells["fieldid"].Value.ToString(); DataRow[] drs = particles.Select(str); if (drs.Length > 0) { Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particle.RectLeft), Y = Convert.ToInt32(particle.RectTop), Width = Convert.ToInt32(particle.RectWidth), Height = Convert.ToInt32(particle.RectHeight) }; Bitmap dpImage = new Bitmap(_particlesGridDevidePage.result.GetImageWidth(), _particlesGridDevidePage.result.GetImageHeight()); using (Graphics graphics = Graphics.FromImage(dpImage)) { graphics.Clear(Color.White); // 清除位图背景为白色 } string filePath = _particlesGridDevidePage.result.FilePath + "\\FIELD_FILES\\"; string imagePath = filePath + "Field" + dgvr.Cells["fieldid"].Value.ToString() + ".bmp"; Bitmap m_originalImage = DrawFunction.ReadImageFile(imagePath); foreach (Segment seg in particle.SegmentList) { int f_length = seg.Length; for (int m = 0; m < f_length; m++) { int lsjs_x = seg.Start + m; int lsjs_y = seg.Height; var pixelColor = m_originalImage.GetPixel(lsjs_x, lsjs_y); dpImage.SetPixel(lsjs_x, lsjs_y, Color.Black); } } Bitmap bmap = _particlesGridDevidePage.Particledata.GetBitmapByParticle(dpImage, rectangle); Bitmap bmap1 = _particlesGridDevidePage.Particledata.GetBitmapByParticle(m_originalImage, rectangle); control_XRayTable1.SetBitmapOfPictureBox(bmap1, bmap); Invalidate(); } else { control_XRayTable1.Visible = false; } } } } private void movetoparticleToolStripMenuItem_Click(object sender, EventArgs e) { //先获取鼠标所选择的行里的颗粒的FieldID和ParticleID string i_ls_fieldid = ""; string i_ls_particleid = ""; int cou = dgV_SimilarParticles.SelectedRows.Count; if (cou > 0) { DataGridViewRow dgvr = dgV_SimilarParticles.SelectedRows[cou - 1]; Bitmap ls_bp = (Bitmap)dgvr.Cells[3].Value; List list_str = (List)ls_bp.Tag; if (list_str != null) { i_ls_fieldid = list_str[0]; i_ls_particleid = list_str[1]; } } DataOperation.DataAccess.ParticleData particleData = new DataOperation.DataAccess.ParticleData(_particlesGridDevidePage.result.FilePath); Particle particle = particleData.GetParticleByFidAndPid(i_ls_fieldid, i_ls_particleid); //取得Field的Position,然后执行线程移动SEM到当前Field的位置 if (m_mythread == null) { return; } if (m_mythread.ThreadState == ThreadState.Running || m_mythread.ThreadState == ThreadState.WaitSleepJoin) { return; } if (m_mythread.ThreadState == ThreadState.Stopped) { m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO)); } Point point = OTSIncAReportGrids.ParticlesGridDevidePage.CalculateParticleCenterPosition(_particlesGridDevidePage.result, new Point(particle.SEMPosX, particle.SEMPosY), new Point(particle.PosX, particle.PosY)); //改为线程调用,先判断线程状态 m_mythread.Start(point); } #region 连接电镜相关 /// /// 移动SEM到指定位置线程函数 /// private void Thread_GO(object in_obj) { if (m_mythread_state == false) { m_mythread_state = true; Point sem_point = (Point)in_obj; //第一步,连接电镜 m_OTSIncAReportGridsFun.Connection_ForParticlesGrid(); Thread.Sleep(500); //第二步,移动到指定位置,先读取再设置 if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true) { m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(sem_point.X, sem_point.Y); } Thread.Sleep(1500); m_mythread_state = false; } } #endregion private void dgV_SimilarParticles_KeyUp(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Down) { dgV_SimilarParticles_MouseUp(null, null); } if (e.KeyData == Keys.Up) { dgV_SimilarParticles_MouseUp(null, null); } if (e.KeyData == Keys.Space) { dgV_SimilarParticles_CellMouseDoubleClick(null,null); } } private void tB_SimilarRatio_KeyUp(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter) { btn_Search_Click(null, null); } } private void dgV_SimilarParticles_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { var SelectRows = dgV_SimilarParticles.SelectedRows; if (SelectRows.Count != 0) { if (SelectRows.Count == 1) { DataGridViewRow dgvr = SelectRows[0]; if ((bool)dgvr.Cells[0].EditedFormattedValue == true) { dgvr.Cells[0].Value = false; } else { dgvr.Cells[0].Value = true; } dgV_SimilarParticles.Rows[0].Cells[0].Value = true; } } } public ListOfSimilarParticles(OTSIncAReportGrids.ParticlesGridDevidePage particlesGridDevidePage, uint[] SelXray, int classifyid, frmReportApp ReportApp) { InitializeComponent(); _particlesGridDevidePage = particlesGridDevidePage; SelXrayclr.SetXrayData(SelXray); table = particlesGridDevidePage.table; _classifyid = classifyid; m_ReportApp = ReportApp; m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO)); //设置窗体的双缓冲,以保证大数据时拖动不卡 this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles(); //利用反射设置DataGridView的双缓冲 Type dgvType = this.dgV_SimilarParticles.GetType(); PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic); pi.SetValue(this.dgV_SimilarParticles, true, null); this.control_XRayTable1 = new OTSIncAReportGraph.Controls.Control_XRayTable(null); this.control_XRayTable1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); this.control_XRayTable1.Dock = System.Windows.Forms.DockStyle.Bottom; this.control_XRayTable1.GBInfoStr = ""; this.control_XRayTable1.GoodChineseName = ""; this.control_XRayTable1.MaterialName = ""; this.control_XRayTable1.Location = new System.Drawing.Point(0, 400); this.control_XRayTable1.Name = "control_XRayTable1"; this.control_XRayTable1.ShowAnalysisXray = true; this.control_XRayTable1.ShowSearchXray = false; this.control_XRayTable1.Size = new System.Drawing.Size(1004, 200); this.control_XRayTable1.STDName = ""; this.control_XRayTable1.Visible = false; this.control_XRayTable1.label_close.Visible = true; panel1.Controls.Add(this.control_XRayTable1); } private void 从此颗粒之下取消选择ToolStripMenuItem_Click(object sender, EventArgs e) { var SelectRows = dgV_SimilarParticles.SelectedRows; if (SelectRows.Count != 0) { DataGridViewRow dgvr = SelectRows[0]; for (int i = dgvr.Index + 1; i < dgV_SimilarParticles.Rows.Count; i++) { dgV_SimilarParticles.Rows[i].Cells[0].Value=false; } if(dgvr.Index + 1!= dgV_SimilarParticles.Rows.Count) { this.cBx_All.CheckedChanged -= new System.EventHandler(this.cBx_All_CheckedChanged); cBx_All.Checked=false; this.cBx_All.CheckedChanged += new System.EventHandler(this.cBx_All_CheckedChanged); } } } } }