| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634 |
- using DevExpress.Charts.Native;
- using DevExpress.XtraDiagram.Bars;
- using DevExpress.XtraEditors.Filtering;
- using OTSCommon.DBOperate;
- using OTSCommon.DBOperate.Model;
- using OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration;
- using OTSIncAReportApp.OTSRstMgrFunction;
- using OTSIncAReportGraph.Controls;
- using OTSPeriodicTable;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SQLite;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using static OTSDataType.otsdataconst;
- using static OTSIncAReportApp.OTSReport_Export;
- namespace OTSIncAReportApp.DataOperation.DataAccess
- {
- public class ParticleData
- {
- private SqlHelper dbHelper;
- public ParticleData(string path)
- {
- dbHelper = new SqlHelper("data source='" + path + "\\FIELD_FILES\\Inclusion.db'");
- }
- /// <summary>
- /// 获取SegmentList
- /// </summary>
- /// <param name="model">Feature</param>
- /// <returns></returns>
- public List<Particle> GetParticleList(Particle model)
- {
- //存放查询数据的数据表
- SQLiteParameter[] Parameter = new SQLiteParameter[1]
- {
- new SQLiteParameter("@FieldId", model.FieldId)
- };
- string sql = "select * from IncAData where Fieldid=@FieldId";
- DataTable DT = dbHelper.ExecuteDataTable(sql, Parameter);
- var result = new List<Particle>();
- foreach (DataRow dr in DT.Rows)
- {
- Particle item = new Particle() { };
- result.Add(item);
- }
- return result;
- }
- /// <summary>
- /// 获取ParticleListBy
- /// </summary>
- /// <param name="model">Feature</param>
- /// <returns></returns>
- public List<Particle> GetParticleListByCon(string con, string max, string min, int display)
- {
- string sqlp = "select a.* from IncAData a ";
- string where = " where 1=1 ";
- if (display == 1)
- {
- where = where + " and a.XrayId >-1 ";
- }
- if (con != "")
- {
- where = where + " and a." + con + ">" + min + " and a." + con + "<" + max;
- }
- sqlp = sqlp + where;
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- List<Particle> listp = dbHelper.TableToList<Particle>(DT);
- return listp;
- }
- /// <summary>
- /// 获取ParticleList
- /// </summary>
- /// <param name="model">Feature</param>
- /// <returns></returns>
- public DataTable GetParticleListAndEm()
- {
- string sqlp = @"select *,
- (select group_concat(name||'-'||Percentage,';')
- from ElementChemistry where XRayId =INcAData.XRayId and fieldid=INcAData.fieldid ) as Element
- from INcAData where xrayid>-1";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- /// <summary>
- /// 获取ParticleList
- /// </summary>
- /// <param name="model">Feature</param>
- /// <returns></returns>
- public Particle GetMergedParticleInfo(int fieldid, int particleid, out uint[] Search_xray, out uint[] Analysis_xray)
- {
- string sqlp = @"select *,
- (select group_concat(name||'-'||Percentage,';')
- from ElementChemistry where XRayId =IncAData.XRayId and fieldid=IncAData.fieldid ) as Element
- from IncAData where FieldId=" + fieldid.ToString() + " and ParticleId="+ particleid.ToString();
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- List<Particle> listp = dbHelper.TableToList<Particle>(DT);
- Particle pte = new Particle();
- Analysis_xray =new uint[2000];
- Search_xray= new uint[2000];
- if (listp.Count > 0)
- {
- pte = listp[0];
- List<OTSCommon.DBOperate.Model.Element> ElementList = new List<OTSCommon.DBOperate.Model.Element>();
- string element = DT.Rows[0]["Element"].ToString();
- for (int i = 0; i < element.Split(';').Count(); i++)
- {
- string elestr = element.Split(';')[i];
- if (elestr != "")
- {
- OTSCommon.DBOperate.Model.Element ele = new OTSCommon.DBOperate.Model.Element() { Name = elestr.Split('-')[0], Percentage = Convert.ToDouble(elestr.Split('-')[1]) };
- ElementList.Add(ele);
- }
- }
- pte.ElementList = ElementList;
- string SubParticlesstr = DT.Rows[0]["SubParticles"].ToString();
- string[] SubParticlesstrG = SubParticlesstr.Split(',');
- foreach (string s in SubParticlesstrG)
- {
- string fieldid1 = s.Split(':')[0];
- string pid1 = s.Split(':')[1];
- Particle particle1 = GetParticleXrayDataByFidAndPid(fieldid1, pid1);
- byte[] bytes = particle1.XRayData;
- for (int i = 0; i < 2000; i++)
- {
- Analysis_xray[i] = Analysis_xray[i]+ BitConverter.ToUInt32(bytes, i * 4);
- }
- Search_xray = Analysis_xray;
- }
- }
- return pte;
- }
- /// <summary>
- /// 获取ParticleList
- /// </summary>
- /// <param name="model">Feature</param>
- /// <returns></returns>
- public DataTable GetParticleStatisticDataListByIncA(string con)
- {
- string sqlp = @"select TypeId,TypeName,TypeColor,count(1) as con,sum(Area) as Area,avg(" + con
- + ") as av,max(" + con
- + ") as max ";
- sqlp = sqlp + "from IncAData where typeid !=-1 and typeid !=4 and fieldid !=-1 group by TypeId";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- public DataTable GetParticleListForParticlSize(string con, string fieldAndPartic)
- {
- string sqlp = @"select TypeId,TypeName,GroupId ,TypeColor,count(1) as con,avg(" + con
- + ") as av,max(" + con
- + ") as max ,GroupName";
- sqlp = sqlp + " from IncAData where typeid !=-1 and fieldid!=-1 and typeid !=4 and ParticleId !=-1";
- if (fieldAndPartic != "")
- {
- sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
- }
- sqlp = sqlp + " group by TypeId ";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- if (con == "area")
- {
- for (int i = 0; i < DT.Rows.Count; i++)
- {
- DT.Rows[i]["max"] = Math.Sqrt((double)DT.Rows[i]["max"] / Math.PI) * 2;
- }
- }
- return DT;
- }
- /// <summary>
- /// 获取ParticleList
- /// </summary>
- /// <param name="model">Feature</param>
- /// <returns></returns>
- public DataTable GetParticleListForParticlSizeID(string con, string fieldAndPartic)
- {
- string sqlp = @"select TypeId,TypeName,TypeColor,count(1) as con,avg(" + con
- + ") as av,max(" + con
- + ") as max ,GroupName ,GroupId,GroupColor";
- sqlp = sqlp + " from IncAData where typeid !=-1 and typeid !=4";
- if (fieldAndPartic != "")
- {
- sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
- }
- sqlp = sqlp + " group by TypeId ";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- if (con == "area")
- {
- for (int i = 0; i < DT.Rows.Count; i++)
- {
- DT.Rows[i]["max"] = Math.Sqrt((double)DT.Rows[i]["max"] / Math.PI) * 2;
- }
- }
- return DT;
- }
- /// <summary>
- /// 获取element含量
- /// </summary>
- /// <returns></returns>
- public DataTable GetElementForArea(string fieldAndPartic)
- {
- string sqlp = @"select e.name,sum(e.percentage*p.area) as earea from ElementChemistry e
- inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid from IncAData where typeid !=-1 and typeid !=4";
- if (fieldAndPartic != "")
- {
- sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||p.fieldid||'-'||p.particleid||',%')";
- }
- sqlp = sqlp + " group by e.name order by sum(e.percentage*p.area) desc";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- /// <summary>
- /// 获取element含量
- /// </summary>
- /// <returns></returns>
- public DataTable GetSmallElementForArea()
- {
- string sqlp = @"select e.name, sum(e.percentage*i.area) as earea from elementchemistry e inner join incadata i on e.xrayid = i.xrayid and e.fieldid = i.fieldid
- group by e.name order by sum(e.percentage*i.area) desc";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- /// <summary>
- /// 获取所有Particle
- /// </summary>
- /// <returns></returns>
- public DataTable GetParticleAll(string fieldAndPartic)
- {
- string sqlp = @"select * from INcAData where typeid !=-1 and typeid !=4";
- if (fieldAndPartic != "")
- {
- sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
- }
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- DT.Columns.Add("ECD",typeof(double));
- for (int i = 0; i < DT.Rows.Count; i++)
- {
- DT.Rows[i]["ECD"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
- }
- DataTable data = DT.Clone();
- for (int i = 0; i < DT.Rows.Count; i++)
- {
- if (Convert.ToInt32(DT.Rows[i]["ParticleId"]) > -1)
- {
- data.Rows.Add(DT.Rows[i].ItemArray);
- }
- }
- return data;
- }
- public DataTable GetParticleAllForBig(string fieldAndPartic)
- {
- string sqlp = @"select * from INcAData where";
- if (fieldAndPartic != "")
- {
- sqlp = sqlp + " '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
- }
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- DT.Columns.Add("ECD", typeof(double));
- for (int i = 0; i < DT.Rows.Count; i++)
- {
- DT.Rows[i]["ECD"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
- }
- DataTable data = DT.Clone();
- for (int i = 0; i < DT.Rows.Count; i++)
- {
- if (Convert.ToInt32(DT.Rows[i]["ParticleId"]) > -1)
- {
- data.Rows.Add(DT.Rows[i].ItemArray);
- }
- }
- return data;
- }
- public DataTable GetParticleAllforparticlelist(string fieldAndPartic)
- {
- string sqlp = @"select * from INcAData where typeid !=-1 and SubParticles is not 'IsSubParticle' ";
- if (fieldAndPartic != "")
- {
- sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
- }
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- public DataTable GetMergedParticle(string fieldAndPartic)
- {
- string sqlp = @"select * from INcAData where typeid !=-1 and SubParticles is not 'IsSubParticle' and SubParticles is not null ";
- if (fieldAndPartic != "")
- {
- sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
- }
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- /// <summary>
- /// 查找所有颗粒的颜色、面积、种类名称信息
- /// </summary>
- /// <returns></returns>
- public DataTable GetParticleTypeInformation()
- {
- string sqlp = @"select Area,TypeName,TypeColor from IncAData";
- DataTable dt = dbHelper.ExecuteDataTable(sqlp, null);
- return dt;
- }
- /// <summary>
- /// 查找IncaData表中所有种类
- /// </summary>
- /// <returns></returns>
- public DataTable GetParticleClassAll()
- {
- string sqlp = @"SELECT DISTINCT TypeName FROM IncaData";
- DataTable dt = dbHelper.ExecuteDataTable(sqlp, null);
- return dt;
- }
- /// <summary>
- /// 获取所有Particle
- /// </summary>
- /// <returns></returns>
- public DataTable GetParticleAllHaveXray(string fieldAndPartic)
- {
- string incaSql = @"select * from IncAData where typeid !=-1 and typeid !=4";
- if (fieldAndPartic != "")
- {
- incaSql = incaSql + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
- }
- DataTable incaDT = dbHelper.ExecuteDataTable(incaSql, null);
- incaDT.Columns.Add("Element");
- DataTable dt_element = GetElementChemistry();
- DataTable elementchemistry = dt_element.Clone();
- for (int i = 0; i < dt_element.Rows.Count; i++)
- {
- if (dt_element.Rows[i]["Name"].ToString() != "Fe")
- {
- elementchemistry.Rows.Add(dt_element.Rows[i].ItemArray);
- }
- }
- for (int i = 0; i < incaDT.Rows.Count; i++)
- {
- string str = "XRayId = " + incaDT.Rows[i]["particleId"].ToString() + " and fieldid = " + incaDT.Rows[i]["fieldid"].ToString();
- DataRow[] drs = elementchemistry.Select(str);
- string ConcatenatedString = "";
- for (int j = 0; j < drs.Length; j++)
- {
- ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
- }
- incaDT.Rows[i]["Element"] = ConcatenatedString;
- }
- return incaDT;
- }
- /// <summary>
- /// 获取所有Particle
- /// </summary>
- /// <returns></returns>
- public DataTable GetParticleHaveXray(string fieldAndPartic)
- {
- string sqlp = @"select *,
- (select group_concat(name||'-'||Percentage,';')
- from ElementChemistry where XRayId =INcAData.XRayId and fieldid=INcAData.fieldid ) as Element from INcAData where xrayid>-1 ";
- if (fieldAndPartic != "")
- {
- sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
- }
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- for (int i = 0; i < DT.Rows.Count; i++)
- {
- DT.Rows[i]["Area"] = Math.Sqrt((double)DT.Rows[i]["Area"] / Math.PI) * 2;
- }
- return DT;
- }
- /// <summary>
- /// 获取所有Particle
- /// </summary>
- /// <returns></returns>
- public List<Particle> GetParticleAllList()
- {
- string sqlp = @"select * from INcAData";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- List<Particle> listp = dbHelper.TableToList<Particle>(DT);
- return listp;
- }
- /// <summary>
- /// 获取所有Particle
- /// </summary>
- /// <returns></returns>
- public DataTable GetParticleAllList_DataTable()
- {
- string sqlp = @"select * from INcAData";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- /// <summary>
- /// 获取所有分类的面积
- /// </summary>
- /// <param name="fieldAndPartic">选择颗粒</param>
- /// <returns></returns>
- public DataTable GetAreaByAllIncA(string fieldAndPartic)
- {
- string sqlp = @"select TypeId,TypeName,GroupId,sum(area) as ar,count(1) as con ,GroupName from INcAData where typeid !=-1 and typeid !=4 and ParticleId > -1";
- if (fieldAndPartic != "")
- {
- sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||fieldid||'-'||particleid||',%')";
- }
- sqlp = sqlp + " group by TypeId";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- /// <summary>
- /// 获取所有大颗粒没有的小颗粒分类
- /// </summary>
- /// <param name="fieldAndPartic">选择颗粒</param>
- /// <returns></returns>
- public DataTable GetSmallParticleInfo()
- {
- string sqlp = @"select TypeId,TypeName,TypeColor,sum(area) as area,sum(ParticleQuant) as ParticleQuant from SmallParticleInfo where TypeId not in(select TypeId from INcAData) group by TypeId";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- /// <summary>
- /// 获取不同分类的面积
- /// </summary>
- /// <param name="fieldAndPartic">选择颗粒</param>
- /// <returns></returns>
- public DataTable GetAreaByIncA(string TypeId, string fieldAndPartic)
- {
- string sqlp = @"select e.name,sum(e.percentage*p.area) as pc,p.TypeId from ElementChemistry e
- inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid where p.TypeId=" + TypeId + " ";
- if (fieldAndPartic != "")
- {
- sqlp = sqlp + " and '" + fieldAndPartic + "' like ('%,'||p.fieldid||'-'||p.particleid||',%')";
- }
- sqlp = sqlp + " group by e.name";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- public DataTable GetAreaByIncA_All()
- {
- string sqlp = @"select e.name,sum(e.percentage*p.area) as pc,p.TypeId from ElementChemistry e
- inner join INcAData p on e.xrayid=p.xrayid and e.fieldid = p.fieldid group by e.name ";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- /// <summary>
- /// 获取全部的物质大类
- /// </summary>
- /// <returns></returns>
- public DataTable GetAllClass()
- {
- string sqlp = @"select GroupName from IncAData group by GroupName order by count(1) desc";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- /// <summary>
- /// 获取所有元素
- /// </summary>
- /// <param name="model">Feature</param>
- /// <returns></returns>
- public DataTable GetAllElement()
- {
- string sqlp = @"select name from ElementChemistry group by name order by count(1) desc";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- /// <summary>
- /// 获取常用夹杂物分类信息
- /// </summary>
- /// <returns></returns>
- public DataTable GetCommonlyUsedClassifyData()
- {
- string sqlp = @"select
- (select count(typeid) from incadata where typeid BETWEEN 10100 and 10199 and typeid BETWEEN 12200 and 12299 and typeid BETWEEN 11300 and 11299 ) as SPINEL ,
- (select count(typeid) from incadata where typeid BETWEEN 10000 and 10999 ) as OXIDE ,
- (select count(typeid) from incadata where typeid BETWEEN 11200 and 11299 and typeid BETWEEN 11400 and 11499 and typeid BETWEEN 11200 and 11599 ) as SULFIDE_OXIDE ,
- (select count(typeid) from incadata where typeid BETWEEN 12000 and 12999 ) as NITRIDE ,
- (select count(typeid) from incadata where typeid BETWEEN 11000 and 11999 ) as SULFIDE ";
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- return DT;
- }
- public bool DeleteFromData(string fieldid, string particleid)
- {
- string sqlp = @"delete from IncAData where FieldId=" + fieldid + " and ParticleId="
- + particleid;
- if (dbHelper.ExecuteQuery_bool(sqlp))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 获取颗粒信息
- /// </summary>
- /// <param name="model">Feature</param>
- /// <returns></returns>
- public Particle GetParticleByFidAndPid(string fieldid, string particleid)
- {
- string sqlp = @"select *,(select xraydata from xraydata where xrayindex=INcAData.xrayid and fieldid="
- + fieldid + ") as XRayData,(select group_concat(name || '_' || Percentage, ';')from ElementChemistry where XRayId = INcAData.XRayId and fieldid ="
- + fieldid + ") as Element from INcAData where fieldid="
- + fieldid + " and particleid= " + particleid;
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- List<Particle> listp = dbHelper.TableToList<Particle>(DT);
- Particle particle = new Particle();
- if (listp.Count > 0)
- {
- particle = listp[0];
- List<OTSCommon.DBOperate.Model.Element> ElementList = new List<OTSCommon.DBOperate.Model.Element>();
- string element = DT.Rows[0]["Element"].ToString();
- for (int i = 0; i < element.Split(';').Count(); i++)
- {
- if (element.Split(';')[i] != "")
- {
- OTSCommon.DBOperate.Model.Element ele = new OTSCommon.DBOperate.Model.Element() { Name = element.Split(';')[i].Split('_')[0], Percentage = Convert.ToDouble(element.Split(';')[i].Split('_')[1]) };
- ElementList.Add(ele);
- }
- }
- particle.ElementList = ElementList;
- }
- return particle;
- }
- public Particle GetParticleXrayDataByFidAndPid(string fieldid, string xrayid)
- {
- string sqlp = @"select xraydata from xraydata where xrayindex=" + xrayid + " and fieldid="
- + fieldid;
- DataTable DT = dbHelper.ExecuteDataTable(sqlp, null);
- List<Particle> listp = dbHelper.TableToList<Particle>(DT);
- if (listp.Count > 0)
- {
- return listp[0];
- }
- else
- {
- return null;
- }
- }
- public enum PARTCLE_TYPE
- {
- SMALL = 0,//过小颗粒
- OVERSIZE = 1,//过大颗粒
- AVE_GRAY_NOT_INRANRE = 2,//亮度不在分析范围内的颗粒
- SEARCH_X_RAY = 3,
- LOW_COUNT = 4,//低计数率颗粒
- NO_INTEREST_ELEMENTS = 5,
- NO_ANALYSIS_X_RAY = 6,//不含分析元素
- NOT_IDENTIFIED_SIC = 7,//非夹杂物颗粒SiC
- NOT_IDENTIFIED_FEO = 8,//非夹杂物颗粒FeO
- NOT_IDENTIFIED = 9,//未识别颗粒
- IDENTIFIED = 10,//分析颗粒,当为可识别类型时,可以被进一步识别为用户类型(1000以上),系统预定义类型(10000以上),所以最终颗粒类型不会为8,但可能为7
- USER_DEFINED_MIN = 1000,
- SYS_DEFINED_MIN = 10000
- }
- #region 分页添加读取数据库函数
- /// <summary>
- /// 获取分页查询所需信息
- /// </summary>
- /// <param name=""></param>
- /// <param name=""></param>
- /// <returns></returns>
- public DataTable GetInfoForPartucleDevidePage(int currentPage, int pagesize, string OrderFunction, string condition)
- {
- int p = (currentPage - 1) * pagesize;
- string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX as 'SEMPosX',FieldPosY as 'SEMPosY',ParticleId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles, (select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = MergedParticleInfo.XRayId and fieldid = MergedParticleInfo.fieldid) as Element from MergedParticleInfo where 1=1 " + condition + " union select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX,FieldPosY,ParticleId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as SubParticles,(select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = INcAData.XRayId and fieldid = INcAData.fieldid ) as Element from INcAData where xrayid > -1 and instr(','||(select ifnull(group_concat(SubParticles, ','),'') from MergedParticleInfo)|| ',',',' || fieldid || ':' || particleid || ',')= 0 " + condition + " order by " + OrderFunction + " limit " + pagesize.ToString() + " offset " + p.ToString();
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
- public DataTable GetIncaSurfaceData( List<string> lst_str)
- {
- DataTable particlesAll = GetInfoForPartucleDevidePage2("");
- DataTable dt_element = GetElementChemistry();
- List<int> list_int = new List<int>();
- for (int a = 0; a < lst_str.Count; a++)
- {
- for (int i = 0; i < dt_element.Rows.Count; i++)
- {
- if (dt_element.Rows[i]["Name"].ToString() == lst_str[a].ToString())
- {
- list_int.Add(i);
- }
- }
- }
- for (int i = 0; i < list_int.Count; i++)
- {
- dt_element.Rows[list_int[i]].Delete();
- }
- dt_element.AcceptChanges();
- 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 = dt_element.Select(str);
- string ConcatenatedString = "";
- for (int j = 0; j < drs.Length; j++)
- {
- ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
- }
- particlesAll.Rows[i]["Element"] = ConcatenatedString;
- }
- return particlesAll;
- }
- public DataTable AddElementColumn(DataTable particlesAll, c_TemplateClass m_mbszclass)
- {
- if (!particlesAll.Columns.Contains("Element"))
- {
- particlesAll.Columns.Add("Element");
- }
- DataTable dt_element = 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 = dt_element.Select(str);
- string ConcatenatedString = "";
- for (int j = 0; j < drs.Length; j++)
- {
- //判断是否在处理元素表中
- bool bl = false;
- for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_qcys.Count; a++)
- {
- if (drs[j]["name"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_qcys[a].ToString())
- {
- bl = true;
- }
- }
- if (!bl)
- {
- ConcatenatedString += drs[j]["name"] + "-" + ChangeDataToD(drs[j]["Percentage"].ToString()) + ';';
- }
- }
- particlesAll.Rows[i]["Element"] = ConcatenatedString;
- }
- return particlesAll;
- }
- /// <summary>
- /// 拼接颗粒
- /// </summary>
- /// <param name="lst_str"></param>
- /// <returns></returns>
- public DataTable GetSplicingParticlesData()
- {
- DataTable particlesAll = GetSplicingParticles();
- return particlesAll;
- }
- /// <summary>
- /// 保留两位小数
- /// </summary>
- /// <param name="strData"></param>
- /// <returns></returns>
- private string ChangeDataToD(string strData)
- {
- Decimal dData = 0.00M;
- if (strData.Contains("E"))
- {
- dData = Convert.ToDecimal(Decimal.Parse(strData.ToString(), System.Globalization.NumberStyles.Float));
- }
- else
- {
- return Convert.ToDouble(strData).ToString("0.00");
- }
- return Convert.ToDouble(dData).ToString("0.00");
- }
- public DataTable GetInfoForPartucleDevidePage2(string condition)
- {
- string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,FieldPosX " +
- "as 'SEMPosX',FieldPosY as 'SEMPosY',XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles," +
- " (select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = MergedParticleInfo.XRayId and fieldid = MergedParticleInfo.fieldid) " +
- "as Element from MergedParticleInfo where 1=1 " + condition + " union select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId," +
- "SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as SubParticles,'' " +
- "as Element from INcAData where xrayid > -1 and instr(','||(select ifnull(group_concat(SubParticles, ','),'') from MergedParticleInfo)|| ',',',' || fieldid || ':' || particleid || ',')= 0 " +
- condition;
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
- public DataTable GetSplicingParticles()
- {
- string sqliteString1 = "select * from MergedParticleInfo";
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString1);
- return DT;
- }
- public DataTable GetInfoForPartucleDevidePage_analyticalParticle(string condition)
- {
- string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,SubParticles,TypeName,TypeColor,'' as Element from INcAData where (xrayid > -1 and typeid !=9 and typeid !=-1 and typeid !=4 and SubParticles is not 'IsSubParticle') " +
- condition;
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
- public DataTable GetInfoForPartucleDevidePage_otherParticle(string condition)
- {
- string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,SubParticles,TypeName,TypeColor,'' as Element from INcAData where (xrayid > -1 and SubParticles is not 'IsSubParticle' and (typeid =9 or typeid =-1 or typeid =4)) " +
- condition;
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
- /// <summary>
- /// 获取拼接颗粒
- /// </summary>
- /// <param name="condition">帅选条件</param>
- /// <returns></returns>
- public DataTable GetInfoForPartucleDevidePage_mergeParticles(string condition)
- {
- string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,SubParticles,TypeName,TypeColor,'' as Element from INcAData where (SubParticles Is not null and SubParticles is not 'IsSubParticle' )" + condition;
- DataTable DT1 = new DataTable();
- try
- {
- DT1 = dbHelper.ExecuteQuery(sqliteString);
- }
- catch
- {
- }
- return DT1;
- }
- public DataTable GetInfoForPartucleDevidePage_allParticles(string condition)
- {
- string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,SubParticles,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 and SubParticles is not 'IsSubParticle' " +
- condition;
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
-
-
-
-
-
-
-
-
-
- public DataTable GetInfoForPartucleDevidePage_NotIdentifyParticle(string condition)
- {
- string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,SubParticles,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 and typeid =9 " +
- condition;
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
- public DataTable GetInfoForPartucleDevidePage_InvalidParticle(string condition)
- {
- string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,SubParticles,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 and typeid =-1 " +
- condition;
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
- public DataTable GetInfoForPartucleDevidePage_LowCountsParticle(string condition)
- {
- string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,SegmentNum,SEMPosX,SEMPosY,XrayId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,SubParticles,TypeName,TypeColor,'' as Element from INcAData where xrayid > -1 typeid =4 " +
- condition;
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
- public DataTable GetClassificationOfAllParticles(string condition)
- {
- string sqliteString1 = "select distinct TypeName from INcAData "+ condition;
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString1);
- return DT;
- }
- public DataTable GetXRayData()
- {
- string sqliteString = @"select * from xraydata";
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
- public DataTable GetElementChemistry()
- {
- string sqliteString = "select * from ElementChemistry";
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
- /// <summary>
- /// 得到图形形状
- /// </summary>
- /// <returns></returns>
- public DataTable GetSegment()
- {
- string sqliteString = "select * from Segment";
- DataTable DT = new DataTable();
- DT = dbHelper.ExecuteQuery(sqliteString);
- return DT;
- }
- /// <summary>
- /// 全部颗粒不带元素
- /// </summary>
- /// <param name="condition"></param>
- /// <returns></returns>
- public DataTable GetAllParticleWithMergeParticlesWithoutEle(string condition)
- {
- DataTable particlesAll = GetParticleAllforparticlelist(condition);
- return particlesAll;
- }
- /// <summary>
- /// 全部颗粒带元素
- /// </summary>
- /// <param name="condition"></param>
- /// <returns></returns>
- public DataTable GetAllParticleWithMergeParticles(string condition)
- {
- DataTable particlesAll=new DataTable();
- DataTable particlesAll1 = GetInfoForPartucleDevidePage_allParticles(condition);
- DataTable mergeParticles = GetInfoForPartucleDevidePage_mergeParticles(condition);
- if (mergeParticles != null && mergeParticles.Rows.Count > 0)
- {
- RemoveMergeParticles(ref particlesAll1, mergeParticles);
- }
- particlesAll = particlesAll1.Copy();
- foreach (DataRow item in mergeParticles.Rows)
- {
- particlesAll.ImportRow(item);
- }
- DataTable elementchemistry = 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;
- }
- return particlesAll;
- }
-
- public void RemoveMergeParticles(ref DataTable dataTable_Particle, DataTable dataTable_MergeParticles)
- {
- foreach (DataRow row in dataTable_Particle.Rows)
- {
- foreach (DataRow MergeParticlesRow in dataTable_MergeParticles.Rows)
- {
- string subt = MergeParticlesRow["SubParticles"].ToString();
- string[] sub = subt.Split(',');
- if (row.RowState == DataRowState.Deleted)
- {
- break;
- }
- if (row["fieldid"].ToString() == Convert.ToString(sub[0]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[0]).Split(':')[1])
- {
- row.Delete();
- break;
- }
- if (row["fieldid"].ToString() == Convert.ToString(sub[1]).Split(':')[0] && row["ParticleId"].ToString() == Convert.ToString(sub[1]).Split(':')[1])
- {
- row.Delete();
- break; ;
- }
- }
- }
- dataTable_Particle.AcceptChanges();
- }
- /// <summary>
- /// 拼接颗粒图
- /// </summary>
- /// <param name="sub">拼接字符串</param>
- /// <param name="xs">xs = pixw / ScanFieldSize</param>
- /// <param name="path">报告文件路径</param>
- /// <param name="picHeight">图像高</param>
- /// <param name="picWidth">帧图宽</param>
- /// <param name="X_AXIS_DIRECTION">电镜x轴正方向</param>
- /// <param name="Y_AXIS_DIRECTION">电镜y轴正方向</param>
- /// <returns></returns>
- public Bitmap GetBitmapForBig(string sub, double xs, string path, int picHeight, int picWidth, OTS_X_AXIS_DIRECTION X_AXIS_DIRECTION, OTS_Y_AXIS_DIRECTION Y_AXIS_DIRECTION)
- {
- string vs = "," + sub.Replace(':', '-') + ",";
- DataTable dataTable = GetParticleAllForBig(vs);
- if (dataTable.Rows.Count == 0)
- {
- return null;
- }
- //内接矩形
- double max_Y = Convert.ToInt64(dataTable.Rows[0]["RectTop"]);
- double max_X = Convert.ToInt64(dataTable.Rows[0]["RectLeft"]);
- double min_Y = max_Y;
- double min_X = max_X;
- //拼接field矩形
- double B_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs;
- double R_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs;
- double T_Y = B_Y;
- double L_X = R_X;
- foreach (DataRow item in dataTable.Rows)
- {
- double lefttopXH = Convert.ToInt64(item["FieldPosX"]) * xs;
- if (X_AXIS_DIRECTION == OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
- {
- if (lefttopXH > L_X)
- {
- L_X = lefttopXH;
- }
- if (lefttopXH < R_X)
- {
- R_X = lefttopXH;
- }
- }
- else
- {
- if (lefttopXH < R_X)
- {
- R_X = lefttopXH;
- }
- if (lefttopXH > L_X)
- {
- L_X = lefttopXH;
- }
- }
- double lrfttopYH = Convert.ToInt64(item["FieldPosY"]) * xs;
- if (Y_AXIS_DIRECTION == OTS_Y_AXIS_DIRECTION.UP_TOWARD)
- {
- if (lrfttopYH < B_Y)
- {
- B_Y = lrfttopYH;
- }
- if (lrfttopYH > T_Y)
- {
- T_Y = lrfttopYH;
- }
- }
- else
- {
- if (lrfttopYH > B_Y)
- {
- B_Y= lrfttopYH;
- }
- if (lrfttopYH < T_Y)
- {
- T_Y = lrfttopYH;
- }
- }
- }
- int WIDTH = Math.Abs(Convert.ToInt32(R_X - L_X)) + picWidth;
- int HEIGHT = Math.Abs(Convert.ToInt32(B_Y - T_Y)) + picHeight;
- //构造最终的图片白板
- Bitmap tableChartImage = new Bitmap(WIDTH, HEIGHT);
- Graphics graph = Graphics.FromImage(tableChartImage);
- //初始化这个大图
- graph.DrawImage(tableChartImage, 0, 0);
- foreach (DataRow item in dataTable.Rows)
- {
- string filePath = path + "\\FIELD_FILES\\";
- string imagePath = filePath + "Field" + item["fieldid"].ToString() + ".bmp";
- //然后将取出的数据,转换成Bitmap对象
- Bitmap ls_bt = ReadImageFile(imagePath);
- int x = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosX"]) * xs - L_X));
- int y = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosY"]) * xs - T_Y));
- graph.DrawImage(ls_bt, x, y);
- //颗粒外接矩形
- double lefttopX = x+Convert.ToInt64(item["RectLeft"]);
- if (lefttopX < min_X)
- {
- min_X = lefttopX;
- }
- if (lefttopX + Convert.ToInt64(item["RectWidth"]) > max_X)
- {
- max_X = lefttopX + Convert.ToInt64(item["RectWidth"]);
- }
- double lrfttopY = y+ Convert.ToInt64(item["RectTop"]);
- if (lrfttopY + Convert.ToInt64(item["RectHeight"]) > max_Y)
- {
- max_Y = lrfttopY + Convert.ToInt64(item["RectHeight"]);
- }
- if ( lrfttopY< min_Y)
- {
- min_Y = lrfttopY;
- }
- }
- int width = Convert.ToInt32(max_X - min_X);
- int height = Convert.ToInt32(max_Y - min_Y);
- int X = Convert.ToInt32(min_X);
- int Y = Convert.ToInt32(min_Y);
- Rectangle rectangle = new Rectangle() { X = X, Y = Y, Width = width, Height = height };
- Bitmap bmap = tableChartImage.Clone(rectangle, PixelFormat.Format8bppIndexed);
- return bmap;
- }
- /// <summary>
- /// 拼接颗粒黑白图
- /// </summary>
- /// <param name="sub">拼接字符串</param>
- /// <param name="xs">xs = pixw / ScanFieldSize</param>
- /// <param name="path">报告文件路径</param>
- /// <param name="picHeight">图像高</param>
- /// <param name="picWidth">帧图宽</param>
- /// <param name="X_AXIS_DIRECTION">电镜x轴正方向</param>
- /// <param name="Y_AXIS_DIRECTION">电镜y轴正方向</param>
- /// <returns></returns>
- public Bitmap GetBitmapForBigBlackAndWhiteImage(string sub, double xs, string path, int picHeight, int picWidth, OTS_X_AXIS_DIRECTION X_AXIS_DIRECTION, OTS_Y_AXIS_DIRECTION Y_AXIS_DIRECTION)
- {
- string vs = "," + sub.Replace(':', '-') + ",";
- DataTable dataTable = GetParticleAllForBig(vs);
- if (dataTable.Rows.Count == 0)
- {
- return null;
- }
- //内接矩形
- double max_Y = Convert.ToInt64(dataTable.Rows[0]["RectTop"]);
- double max_X = Convert.ToInt64(dataTable.Rows[0]["RectLeft"]);
- double min_Y = max_Y;
- double min_X = max_X;
- //拼接field矩形
- double B_Y = Convert.ToInt64(dataTable.Rows[0]["FieldPosY"]) * xs;
- double R_X = Convert.ToInt64(dataTable.Rows[0]["FieldPosX"]) * xs;
- double T_Y = B_Y;
- double L_X = R_X;
- foreach (DataRow item in dataTable.Rows)
- {
- double lefttopXH = Convert.ToInt64(item["FieldPosX"]) * xs;
- if (X_AXIS_DIRECTION == OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
- {
- if (lefttopXH > L_X)
- {
- L_X = lefttopXH;
- }
- if (lefttopXH < R_X)
- {
- R_X = lefttopXH;
- }
- }
- else
- {
- if (lefttopXH < R_X)
- {
- R_X = lefttopXH;
- }
- if (lefttopXH > L_X)
- {
- L_X = lefttopXH;
- }
- }
- double lrfttopYH = Convert.ToInt64(item["FieldPosY"]) * xs;
- if (Y_AXIS_DIRECTION == OTS_Y_AXIS_DIRECTION.UP_TOWARD)
- {
- if (lrfttopYH < B_Y)
- {
- B_Y = lrfttopYH;
- }
- if (lrfttopYH > T_Y)
- {
- T_Y = lrfttopYH;
- }
- }
- else
- {
- if (lrfttopYH > B_Y)
- {
- B_Y = lrfttopYH;
- }
- if (lrfttopYH < T_Y)
- {
- T_Y = lrfttopYH;
- }
- }
- }
- int WIDTH = Math.Abs(Convert.ToInt32(R_X - L_X)) + picWidth;
- int HEIGHT = Math.Abs(Convert.ToInt32(B_Y - T_Y)) + picHeight;
- //构造最终的图片白板
- Bitmap tableChartImage = new Bitmap(WIDTH, HEIGHT);
- Graphics graph = Graphics.FromImage(tableChartImage);
- graph.Clear(Color.White);
- //初始化这个大图
- graph.DrawImage(tableChartImage, 0, 0);
- foreach (DataRow item in dataTable.Rows)
- {
- string strs = @"select * from Segment where FieldId="+item["fieldid"].ToString()+" and ParticleId="+item["particleid"].ToString();
- DataTable DTS = dbHelper.ExecuteDataTable(strs, null);
- DataRow[] dd = DTS.Select();
- List<Segment> flist = dbHelper.RowsToList<Segment>(dd);
- int x = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosX"]) * xs - L_X));
- int y = Math.Abs(Convert.ToInt32(Convert.ToDouble(item["FieldPosY"]) * xs - T_Y));
- //颗粒外接矩形
- double lefttopX = x + Convert.ToInt64(item["RectLeft"]);
- if (lefttopX < min_X)
- {
- min_X = lefttopX;
- }
- if (lefttopX + Convert.ToInt64(item["RectWidth"]) > max_X)
- {
- max_X = lefttopX + Convert.ToInt64(item["RectWidth"]);
- }
- double lrfttopY = y + Convert.ToInt64(item["RectTop"]);
- if (lrfttopY + Convert.ToInt64(item["RectHeight"]) > max_Y)
- {
- max_Y = lrfttopY + Convert.ToInt64(item["RectHeight"]);
- }
- if (lrfttopY < min_Y)
- {
- min_Y = lrfttopY;
- }
- foreach (Segment seg in flist)
- {
- int f_length = seg.Length;
- for (int m = 0; m < f_length; m++)
- {
- int lsjs_x = seg.Start + m+ x;
- int lsjs_y = seg.Height+ y;
- tableChartImage.SetPixel(lsjs_x, lsjs_y, Color.Black);
- }
- }
- }
- int width = Convert.ToInt32(max_X - min_X);
- int height = Convert.ToInt32(max_Y - min_Y);
- int X = Convert.ToInt32(min_X);
- int Y = Convert.ToInt32(min_Y);
- Rectangle rectangle = new Rectangle() { X = X, Y = Y, Width = width, Height = height };
- Bitmap bmap = GetBitmapByParticle(tableChartImage, rectangle);
- return bmap;
- }
- /// <summary>
- /// 通过FileStream 来打开文件,这样就可以实现不锁定Image文件,到时可以让多用户同时访问Image文件
- /// </summary>
- /// <param name="path"></param>
- /// <returns></returns>
- public Bitmap ReadImageFile(string path)
- {
- if (!File.Exists(path))
- {
- return null;//文件不存在
- }
- FileStream fs = File.OpenRead(path); //OpenRead
- int filelength = 0;
- filelength = (int)fs.Length; //获得文件长度
- Byte[] image = new Byte[filelength]; //建立一个字节数组
- fs.Read(image, 0, filelength); //按字节流读取
- System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
- fs.Close();
- Bitmap bit = new Bitmap(result);
- return bit;
- }
- /// <summary>
- /// 传入单颗颗粒的particle类对象,返回从field中抠取出的bitmap对象,抠取单颗颗粒
- /// </summary>
- /// <param name="in_cotsparticleclr"></param>
- /// <returns></returns>
- public Bitmap GetBitmapByParticle(Bitmap ls_bt, Rectangle offset_rect)
- {
- //为了能把整个颗粒显示完整
- offset_rect.X = offset_rect.X - 20;
- offset_rect.Y = offset_rect.Y - 20;
- offset_rect.Width = offset_rect.Width + 40;
- offset_rect.Height = offset_rect.Height + 40;
- //防止计算偏差后,有坐标溢出现象
- if (offset_rect.X < 0)
- offset_rect.X = 0;
- if (offset_rect.Y < 0)
- offset_rect.Y = 0;
- if (offset_rect.X + offset_rect.Width > ls_bt.Width)
- {
- offset_rect.Width = ls_bt.Width - offset_rect.X;
- }
- if (offset_rect.Y + offset_rect.Height > ls_bt.Height)
- {
- offset_rect.Height = ls_bt.Height - offset_rect.Y;
- }
- Bitmap new_ret_bp;
- //防止为0后面计算出错
- if (offset_rect.Width > 0 && offset_rect.Height > 0)
- {
- //最后通过list_showsegment组建成新的图片,进行返回
- new_ret_bp = ls_bt.Clone(offset_rect, ls_bt.PixelFormat);
- }
- else
- {
- new_ret_bp = new Bitmap(offset_rect.Width, offset_rect.Height);
- }
- return new_ret_bp;
- }
- public void InsertUpdate(List<int> particleID, List<string> particleData)
- {
- List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
- var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
- cmdlist.Add(str);
- try
- {
- dbHelper.ExecuteNonQueryBatch(ref cmdlist);
- }
- catch (Exception e)
- {
- //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
- }
- }
- public KeyValuePair<string, SQLiteParameter[]> GetUpdataAIncACmd(List<int> particleID, List<string> particleData)
- {
- var str = dbHelper.UpdateINCAEntryData(particleID, particleData);
- return str;
- }
- public void ExecuteNonQueryBatch(List<KeyValuePair<string, SQLiteParameter[]>> cmdlist)
- {
- try
- {
- dbHelper.ExecuteNonQueryBatch(ref cmdlist);
- }
- catch (Exception e)
- {
- //NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
- }
- }
- /// <summary>
- /// 传入颗粒的tagid和fieldid,来获取该颗粒下对应的xray数据
- /// </summary>
- /// <param name="in_clr_tagid">颗粒id</param>
- /// <param name="in_clr_fieldid"></param>
- /// <param name="Search_xray"></param>
- /// <param name="Analysis_xray"></param>
- public Particle GetXrayByParticleTagIDAndFieldID_ForMergeParticle(int in_clr_tagid, int in_clr_fieldid, out uint[] Search_xray, out uint[] Analysis_xray)
- {
- Search_xray = new uint[2000];
- Analysis_xray = new uint[2000];
- Particle particle = new Particle();
- particle = GetMergedParticleInfo(in_clr_fieldid, in_clr_tagid, out Search_xray, out Analysis_xray);
- return particle;
- }
- public List<ShowElementInfo> GetShowElementInfos_ForMergeParticle(List<Element> list_celementchemistryclr)
- {
- List<ShowElementInfo> list_showelementinfo = new List<ShowElementInfo>();
- for (int i = 0; i < list_celementchemistryclr.Count; i++)
- {
- ShowElementInfo ls_sei = new 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));
- return list_showelementinfo;
- }
-
- //public Bitmap GetParticlescreenshot(string subt, ResultFile result)
- //{
- // Bitmap bmap = null;
- // KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
- // if (subt != null && subt != "" && subt != "IsSubParticle")
- // {
- // double ScanFieldSize = result.GetScanFieldSizeX();
- // string filePatht = result.FilePath + "\\FIELD_FILES\\";
- // string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
- // Bitmap tempbit = ReadImageFile(imagePatht);
- // int pixw = tempbit.Width;
- // double xs = pixw / ScanFieldSize;
- // OTS_X_AXIS_DIRECTION X_AXIS_DIRECTION = result.GetXAxisDirEnum();
- // OTS_Y_AXIS_DIRECTION Y_AXIS_DIRECTION = result.GetYAxisDirEnum();
-
- // bmap = GetBitmapForBig(subt, xs, result.FilePath, tempbit.Height, tempbit.Width, X_AXIS_DIRECTION, Y_AXIS_DIRECTION);
- // if (bmap != null)
- // {
- // string[] str = subt.Split(',');
- // bmap.Tag = new List<string>() { str[0].Split(':')[0], str[0].Split(':')[1]};
- // }
- // }
- // else if (subt != "IsSubParticle")
- // {
- // if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
- // {
- // string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
- // FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), 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 = GetBitmapByParticle(FieldImage.Value, rectangle);
- // bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString(), particles.Rows[i]["XrayId"].ToString() };
- // dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
- // dgV_ParticlesDevidePage.Rows[add_rowindex].Height = bmap.Height + 20;
- // }
- // return bmap;
- //}
- #endregion
- #region 清洁度
- public ParticleData()
- {
- }
- /// <summary>
- /// 获得颗粒类别
- /// </summary>
- /// <param name="StandardLibraryAddress">标准库地址</param>
- /// <returns></returns>
- public DataTable ObtainParticleCategory_start(string StandardLibraryAddress)
- {
- DataTable dataTable = new DataTable();
- dataTable.Columns.Add("GroupId");
- dataTable.Columns.Add("GroupName");
- dataTable.Columns.Add("inoId");
- dataTable.Columns.Add("display");
- DataTable get_dt = SelectStandardLibraryGrouping(StandardLibraryAddress);
- if (get_dt.Rows.Count==0)
- {
- DataRow data = dataTable.NewRow();
- data["inoId"] = 0;
- data["GroupId"] = 0;
- data["GroupName"] = "Default";
- data["display"] = "0";
- dataTable.Rows.Add(data);
- return dataTable;
- }
- DataRow[] dataRow = get_dt.Select("", "iorder ASC");
- int shul = 0;
- string DefaultGroupId = "";
- foreach (DataRow row in dataRow)
- {
- if (row.ItemArray[1].ToString() != "Default")
- {
- DataRow data = dataTable.NewRow();
- data["inoId"] = shul;
- data["GroupId"] = row.ItemArray[0].ToString();
- data["GroupName"] = row.ItemArray[1].ToString();
- data["display"] = "0";
- dataTable.Rows.Add(data);
- shul++;
- }
- else
- {
- DefaultGroupId = row.ItemArray[0].ToString();
- }
- }
- DataRow data2 = dataTable.NewRow();
- data2["inoId"] = shul;
- data2["GroupId"] = DefaultGroupId;
- data2["GroupName"] = "Default";
- data2["display"] = "0";
- dataTable.Rows.Add(data2);
- return dataTable;
- }
- /// <summary>
- /// 获取规则数据
- /// </summary>
- /// <param name="strings">组类别</param>
- /// <param name="a_SelectedIndex">标准库地址</param>
- /// <returns></returns>
- public List<DataTable> ObtainRuleData_start(DataTable strings, string a_SelectedIndex)
- {
- List<DataTable> List_data = new List<DataTable>();
- DataTable dt_stl = new DataTable();
- SqLiteHelper sh = new SqLiteHelper("data source='" + a_SelectedIndex + "'");
- dt_stl = sh.ExecuteQuery("select * from ClassifySTD");
- dt_stl.Columns.Add("display");
- if (dt_stl == null)
- {
- List_data.Add(dt_stl);
- return List_data;
- }
-
- for (int i = 0; i < strings.Rows.Count; i++)
- {
- DataTable table = dt_stl.Clone();
- table.TableName = strings.Rows[i]["GroupId"].ToString();
- for (int a = 0; a < dt_stl.Rows.Count; a++)
- {
- if (strings.Rows[i]["GroupId"].ToString() == dt_stl.Rows[a]["GroupId"].ToString())
- {
- dt_stl.Rows[a]["display"] = 0;
- table.Rows.Add(dt_stl.Rows[a].ItemArray);
- }
- }
- DataView dvs = table.DefaultView;
- dvs.Sort = "ListNum ASC";
- DataTable TemporaryDataGroup = dvs.ToTable();
- List_data.Add(TemporaryDataGroup);
- }
- return List_data;
- }
- private DataTable SelectStandardLibraryGrouping(string a_SelectedIndex)
- {
- DataTable dt_stl = new DataTable();
- SqLiteHelper sh = new SqLiteHelper("data source='" + a_SelectedIndex + "'");
- dt_stl = sh.ExecuteQuery("select * from STDGroups");
- return dt_stl;
- }
- /// <summary>
- /// 获得颗粒类别
- /// </summary>
- /// <returns></returns>
- public List<string> ObtainParticleCategory(OTSReport_Export m_otsreport_export, BasicData basicData)
- {
- List<string> ClassName = new List<string>();
- if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype != OTS_SysType_ID.IncA)
- {
- DataTable get_dt = ReadClassification(basicData);
- DataTable getClass_dt = get_dt.Clone();
- DataRow[] dataRow = get_dt.Select("", "iorder ASC");
- foreach (DataRow row in dataRow)
- {
- if (row.ItemArray[1].ToString() != "Default")
- {
- getClass_dt.ImportRow(row);
- }
- }
- for (int i = 0; i < getClass_dt.Rows.Count; i++)
- {
- ClassName.Add(getClass_dt.Rows[i][1].ToString());
- }
- ClassName.Add("Default");
- }
- else
- {
- DataTable getClass_dt = ReadClassification(basicData);
- for (int i = 0; i < getClass_dt.Rows.Count; i++)
- {
- ClassName.Add(getClass_dt.Rows[i][1].ToString());
- }
- bool bl = false;
- for (int i = 0; i < getClass_dt.Rows.Count; i++)
- {
- if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid"
- && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified")
- if (getClass_dt.Rows[i]["GroupName"].ToString() == "")
- {
- if (!bl)
- {
- ClassName.Add("Default");
- bl = true;
- }
- }
- else
- {
- bool isDefault = false;
- for (int a = 0; a < ClassName.Count; a++)
- {
- if (getClass_dt.Rows[i]["GroupName"].ToString() == "Default")
- {
- isDefault = true;
- }
- }
- if (isDefault)
- {
- if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default")
- {
- ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
- }
- }
- else
- {
- ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
- }
- }
- }
- }
- return ClassName;
- }
- public DataTable ReadClassification(BasicData basicData)
- {
- DataTable dt_stl = new DataTable();
- SqLiteHelper sh = new SqLiteHelper("data source='" + basicData.GetFilePath() + "\\" + basicData.GetResfile() + "'");
- dt_stl = sh.ExecuteQuery("select * from STDGroups");
- return dt_stl;
- }
- #endregion
- }
- }
|