| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001 | using OTS.WinFormsUI.Docking;using System;using System.Collections.Generic;using System.Drawing;using System.Linq;using System.Windows.Forms;using System.Collections;using System.Text.RegularExpressions;using System.Text;using System.IO;using System.Data;using OTSCLRINTERFACE;namespace SpectrumSTDEditor{    public partial class STDEditor : DockContent    {        #region 全局变量        public SubMidWindow m_SubMidWindow = null;        public int STDId = -1;        Hashtable table_STDEditor;        //数据库操作对象        public SqlLiteClass m_sc = null;        // 电镜设置对象        COTSControlFunExport m_cfun = null;        //Xray图谱用户控件        UXrayControl XrayControl = null;        //全局Xray 用于存储当前选择行的Xray信息        byte[] xrayByteData = null;        // 连接状态        bool m_bConnectionState = false;        //标准Xray信息列表        public List<STDXray> m_STDXrayList = null;        #endregion        public enum Result        {            NoMatched = 0,            Success = 1,            Fail = 2        }        public STDEditor(SubMidWindow SubMidWindow)        {            InitializeComponent();            m_sc = new SqlLiteClass();            m_SubMidWindow = SubMidWindow;            X = this.Width;            Y = this.Height;            XrayControl=new UXrayControl();            setTag(this);        }        public STDEditor(SubMidWindow SubMidWindow, string STDDBaddress)        {            InitializeComponent();            m_sc = new SqlLiteClass(STDDBaddress);            m_SubMidWindow = SubMidWindow;            X = this.Width;            Y = this.Height;            setTag(this);        }        private void STDEditor_Load(object sender, EventArgs e)        {            m_SubMidWindow.m_MainForm.lan = new Language(this);            //添加Xray用户控件            XrayControl = new UXrayControl();            plXray.Controls.Add(XrayControl);            XrayControl.Dock = DockStyle.Fill;            //绑定数据库中的STDXray             m_STDXrayList = new List<STDXray>();            BindSTDXray();         }        float AmplificationFactor = 1;        //private void button_Extend_Click(object sender, EventArgs e)        //{        //    if (button_Extend.BackColor == SystemColors.ControlDarkDark)        //    {        //        //groupBox_Data.Visible = true;        //        textbox_STDEditor.Height = (int)Math.Round(150 * AmplificationFactor);        //        button_Extend.BackColor = SystemColors.ControlDark;        //    }        //    else        //    {        //        button_Extend.BackColor = SystemColors.ControlDarkDark;        //        textbox_STDEditor.Height = (int)Math.Round(300* AmplificationFactor);        //    }        //}                #region 采集Xray 按钮事件        private void btnCollectXray_Click(object sender, EventArgs e)        {            m_SubMidWindow.m_MainForm.IsModified = true;            string strTime = txtCollectTime.Text.Trim();            if (txtCollectTime.Equals(""))            {                showMessage("Please fill in the collection time name!");                txtCollectTime.Focus();                return;            }            if (!IsMatch(strTime, 1))            {                showMessage("Error collecting time content, the format should be integer!");                txtCollectTime.Focus();                return;            }            if (Convert.ToInt32(strTime) < 50)            {                showMessage("CollectTime must not be less than 100 milliseconds!");                txtCollectTime.Focus();                return;            }            //显示Xray            xrayByteData = IntArrToByteArr(GetCollectXray(strTime));            int color = Convert.ToInt32(m_SubMidWindow.m_MainForm.STDDictionary[STDId].Color);            //根据树节点修改对应的Xray信息            UpdateSTDXray(STDId, xrayByteData);            ShowXrayAtlas(color, xrayByteData);        }        /// <summary>        /// 获取采集当前的Xray信息        /// </summary>        /// <returns></returns>        protected uint[] GetCollectXray(string strTime)        {            try            {                if (null == m_cfun)                {                    //m_cfun = COTSControlFunExport.GetControllerInstance();                }                if (ConnectionSem(connectionEnumType.EDSOnlyPointXRay))                {                    if (EDSInit())                    {                        int iSize = 2000;                        uint[] iXrayData = new uint[iSize];                        //采集XRay数据                        if (m_cfun.CollectSpectrum(uint.Parse(strTime), ref iXrayData))                        {                            return iXrayData;                        }                    }                }                return null;            }            catch /*(Exception ex)*/            {                return null;            }            finally            {                //EDS过程结束                //m_cfun.EDSFinishedInstance();                //关闭连接                DisConnectSem(connectionEnumType.EDSOnlyPointXRay);            }        }        private void btnReadXray_Click(object sender, EventArgs e)        {            OpenFileDialog fileSel = new OpenFileDialog();            fileSel.Filter = "|*.txt";            if (DialogResult.OK == fileSel.ShowDialog())            {                String str = "";                //读取Xray文件                using (StreamReader sr = new StreamReader(fileSel.FileName))                {                    while (!sr.EndOfStream)                    {                        str += sr.ReadLine() + ",";                    }                    str = str.Substring(0, str.Length - 1);                    string[] xrayData = str.Split(',');                    if (xrayData.Length != 2000)                    {                        return;                    }                    uint[] data = new uint[xrayData.Length];                    for (int i = 0; i < xrayData.Length; i++)                    {                        data[i] = Convert.ToUInt32(xrayData[i]);                    }                    //Xray数据                    xrayByteData = IntArrToByteArr(data);                    int color = Convert.ToInt32(m_SubMidWindow.m_MainForm.STDDictionary[STDId].Color);                    //根据树节点修改对应的Xray信息                    UpdateSTDXray(STDId, xrayByteData);                    ShowXrayAtlas(color, xrayByteData);                }            }        }        /// <summary>        /// 将int[] 转换为 byte[]        /// </summary>        /// <param name="intArr"></param>        /// <returns></returns>        public static byte[] IntArrToByteArr(uint[] intArr)        {            int intSize = sizeof(uint) * intArr.Length;            byte[] bytArr = new byte[intSize];            //申请一块非托管内存              //IntPtr ptr = Marshal.AllocHGlobal(intSize);            ////复制int数组到该内存块              //Marshal.Copy(intArr, 0, ptr, intArr.Length);            ////复制回byte数组              //Marshal.Copy(ptr, bytArr, 0, bytArr.Length);            ////释放申请的非托管内存              //Marshal.FreeHGlobal(ptr);            for (int i = 0; i < intArr.Length; i++)            {                byte[] c1 = BitConverter.GetBytes(intArr[i]);                c1.CopyTo(bytArr, i * 4);                        }            return bytArr;        }        /// 将颜色对象转换为uint        /// </summary>        /// <param name="color"></param>        /// <returns></returns>        public uint ParseRGB(Color color)        {            return (uint)(((uint)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R));        }        #region 显示Xray图谱        /// <summary>        /// 显示Xray图谱        /// </summary>        public void ShowXrayAtlas(int colorValue = 0, byte[] XrayData = null)        {            DataTable dt = new DataTable();            dt.Columns.Add("Color", typeof(int));            dt.Columns.Add("SPEC", typeof(byte[]));            DataRow dRow = dt.NewRow();            dRow["Color"] = colorValue;            if (XrayData != null)            {                dRow["SPEC"] = XrayData;            }            else            {                dRow["SPEC"] = new byte[8000];            }            //将选择行的数据传递给Xray控件            XrayControl.Dr = dRow;            XrayControl.Refresh();            XrayData = null;        }        #endregion        #region 常用数据验证的封装,数字字符的验证        /// <summary>        /// 常用数据验证的封装,数字字符的验证        /// </summary>        /// <param name="inputVal">需要验证的数值【字符串,或者数字】</param>        /// <param name="type">类型为哪一个验证</param>        /// <returns>如果验证成功则返回True,否则返回false</returns>        public bool IsMatch(string inputVal, int type)        {            switch (type)            {                case 0:                    return Regex.IsMatch(inputVal, @"^[1-9]d*$");  //匹配正整数                case 1:                    return Regex.IsMatch(inputVal, @"^-?\d+$");  //匹配整数                case 2:                    return Regex.IsMatch(inputVal, @"^[A-Za-z0-9]+$");  //匹配由数字和26个英文字母组成的字符串                 case 3:                    return Regex.IsMatch(inputVal, @"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$");  //匹配正浮点数                case 4:                    return Regex.IsMatch(inputVal, @"^[\u4e00-\u9fa5]{0,}$");  //匹配汉字                case 5:                    return Regex.IsMatch(inputVal, @"^[0-9]+(.[0-9]{1,3})?$");  //匹配1~3位小数的正实数                case 6:                    return Regex.IsMatch(inputVal, @"^[A-Za-z]+$");  //匹配英文字符                default:                    return true;            }        }        #endregion        #region 弹出提示        /// <summary>        /// 弹出提示        /// </summary>        /// <param name="strContent"></param>        protected void showMessage(string strContent)        {            MessageBox.Show(strContent, "Tip");        }        #endregion        #region 连接与关闭设备        public bool ConnectionSem(connectionEnumType connectionType)        {            //获取连接电镜类型            string connTypeStr = GetConnectionType(connectionType);            //连接电镜标识            bool bDisConnResult = false;            //判断连接状态            if (!m_bConnectionState)            {                //连接电镜设置                bDisConnResult = m_cfun.ConncetSem();            }            if (bDisConnResult)            {                m_bConnectionState = true;            }            else            {                m_bConnectionState = false;            }            return bDisConnResult;        }        public bool DisConnectSem(connectionEnumType disConnectType)        {            //获取关闭电镜类型            string connTypeStr = GetConnectionType(disConnectType);            bool bDisConnResult = false;            if (m_bConnectionState)            {                bDisConnResult = m_cfun.DisconnectSem();            }            if (bDisConnResult)            {                m_bConnectionState = false;            }            else            {                m_bConnectionState = true;            }            return bDisConnResult;        }        private string GetConnectionType(connectionEnumType connectionType)        {            string connString = string.Empty;            switch (connectionType)            {                //设置单点采集文字内容                case connectionEnumType.EDSOnlyPointXRay:                    connString = "OnlyPointXRay";                    break;                //设置多点采集文字内容                case connectionEnumType.EDSMultiPointXRay:                    connString = "MultiPointXRay";                    break;                //设置面采集文字内容                case connectionEnumType.EDSAreaXRay:                    connString = "AreaXRay";                    break;                //设置图片                case connectionEnumType.ScanImage:                    connString = "Image";                    break;                default: break;            }            return connString;        }        /// <summary>        /// EDS初始化        /// </summary>        public bool EDSInit()        {            bool bResult = false;            //线程调用 加载            bResult = m_cfun.EDSInit();            return bResult;        }        public enum connectionEnumType        {            EDSOnlyPointXRay = 0,            EDSMultiPointXRay = 1,            EDSAreaXRay = 2,            ScanImage = 3        }        /// <summary>        /// 标准Xray状态        /// </summary>        public enum STDXrayInfoState        {            Add = 0,            Modify = 1,            Delete = 2        }        #endregion        /// <summary>        /// 记录修改后的标准中的Xray信息        /// </summary>        public class STDXray        {            /// <summary>            /// 标准编号            /// </summary>            private string stdID;            /// <summary>            /// Xray数据            /// </summary>            private byte[] xrayData;            /// <summary>            /// 状态            /// </summary>            private int infoState = -1;            public string StdID { get => stdID; set => stdID = value; }            public byte[] XrayData { get => xrayData; set => xrayData = value; }            public int InfoState { get => infoState; set => infoState = value; }        }        #endregion        #region Xray 与 STDDB数据操作        /// <summary>        /// 绑定数据库中已存在的Xray信息        /// </summary>        public void BindSTDXray()        {            //清空STDXray列表中的集合            m_STDXrayList.Clear();            //查询            DataTable dt = m_sc.GetDTFormSysSTDBySQLString("select Id,SPEC from STDMinerals");            if (dt != null)            {                if (dt.Rows.Count > 0)                {                    foreach (DataRow item in dt.Rows)                    {                        STDXray sXray = new STDXray();                        sXray.StdID = item["Id"].ToString();                        sXray.XrayData = (byte[])item["SPEC"];                        sXray.InfoState = 1;                        m_STDXrayList.Add(sXray);                    }                }            }        }        bool SaveOtherDataToXray(string STDDBAddress, int id)        {            #region 数据库存贮方式一            System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");            System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();            try            {                m_dbConnection.Open();                //string insertstr = ("insert into STDMinerals(name,formula,density,Hardness,BSEValue,Electrical_conductivity,color,Element) values(" + m_SubMidWindow.m_MainForm.STDDictionary[id].StrName + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Formula + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Density + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Hardness + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].BSE + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Electrical_conductivity + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Color + "," + m_SubMidWindow.m_MainForm.STDDictionary[id].Element + ");");                string insertstr = ("insert into STDMinerals(name) values(" + m_SubMidWindow.m_MainForm.STDDictionary[id].StrName + ");");                cmm.CommandText = insertstr;                cmm.ExecuteNonQuery();            }            catch (Exception ex)            {                MessageBox.Show(ex.ToString());                return false;            }            m_dbConnection.Close();            #endregion            return true;        }        /// <summary>        /// 保存STDXray至数据库        /// </summary>        public void SaveSTDXray()        {            ArrayList delArrayList = new ArrayList();            if (m_STDXrayList != null)            {                //if (m_STDXrayList.Count > 0)                //{                foreach (STDXray item in m_STDXrayList)                {                    int infoState = item.InfoState;                    //添加状态 根据Xray信息当前只能按照一条操作                    if (infoState == (int)STDXrayInfoState.Add)                    {                        //if (item.XrayData == null)                        //{                        //    item.XrayData = new byte[8000];                        //}                        //string strvaluename = "@data";                        ////编辑添加语句                        //StringBuilder strSqlAdd = new StringBuilder();                        //strSqlAdd.Append("insert into STDMinerals(Id,SPEC) values(" + item.StdID + "," + strvaluename + ");");                        //bool addResult = m_sc.ExecuteBlob(strSqlAdd.ToString(), strvaluename, (byte[])item.XrayData, ((byte[])item.XrayData).Length);                        bool addResult = false;                        //判断STDID在数据库中是否存在                        bool selResult = SelSTDDBBySTDId(item.StdID);                        if (selResult)                        {                            //addResult = UpdateSTDDB(item.StdID, xrayByteData);                            addResult = UpdateSTDDB(item.StdID, item.XrayData);                        }                        else                        {                            addResult = AddSTDDB(item.StdID, item.XrayData);                        }                        if (!addResult)                        {                            continue;                        }                    }                    //修改状态                    else if (infoState == (int)STDXrayInfoState.Modify)                    {                        //判断STDID在数据库中是否存在                        bool selResult = SelSTDDBBySTDId(item.StdID);                        if (selResult)                        {                            UpdateSTDDB(item.StdID, item.XrayData);                        }                        else                        {                            AddSTDDB(item.StdID, item.XrayData);                        }                    }                    //删除状态 编辑批量删除语句                    else if (infoState == (int)STDXrayInfoState.Delete)                    {                        //编辑删除语句                        delArrayList.Add("delete from STDMinerals where id=" + item.StdID + ";");                    }                }                //批量删除                if (delArrayList.Count > 0)                {                    bool delResult = m_sc.DelSTDInfo(delArrayList);                }                //}            }        }        /// <summary>        /// 添加STD信息至数据库        /// </summary>        protected bool AddSTDDB(string stdID, byte[] XrayData)        {            if (XrayData == null)            {                XrayData = new byte[8000];            }            string strvaluename = "@data";            StringBuilder sqlStrAdd = new StringBuilder();            sqlStrAdd.Append("insert into STDMinerals(Id,SPEC) values(" + stdID + "," + strvaluename + ");");            bool addResult = m_sc.ExecuteBlob(sqlStrAdd.ToString(), strvaluename, (byte[])XrayData, ((byte[])XrayData).Length);            return addResult;        }        /// <summary>        /// 修改STD信息至数据库        /// </summary>        protected bool UpdateSTDDB(string stdID, byte[] XrayData)        {            if (XrayData == null)            {                XrayData = new byte[8000];            }            string strValueName = "@data";            StringBuilder sqlStrUpdate = new StringBuilder();            sqlStrUpdate.Append("update STDMinerals set SPEC=" + strValueName  +" where id=" + stdID + ";");            bool updateResult = m_sc.ExecuteBlob(sqlStrUpdate.ToString(), strValueName, (byte[])XrayData, ((byte[])XrayData).Length);            return updateResult;        }        /// <summary>        /// 查询是否存在标准编号        /// </summary>        /// <param name="stdID"></param>        protected bool SelSTDDBBySTDId(string stdID)        {            bool selResult = false;            //编辑查询语句            StringBuilder sqlStr = new StringBuilder();            sqlStr.Append("select * from STDMinerals where id=" + stdID + "");            DataTable dt = m_sc.GetDTFormSysSTDBySQLString(sqlStr.ToString());            if (dt != null)            {                if (dt.Rows.Count > 0)                {                    //已存在状态                    selResult = true;                }            }            return selResult;        }        /// <summary>        /// 根据选择树节点显示对应的Xray信息        /// </summary>        public void SelSTDXray(int Key, STDdata sT)        {            if (sT == null)            {                return;            }            if (m_STDXrayList != null)            {                //if (m_STDXrayList.Count > 0)                //{                    bool isExists = false;                    foreach (STDXray item in m_STDXrayList)                    {                        //修改XrayData信息                        if (item.StdID == Key.ToString())                        {                            string selColor = sT.Color;                            int colorValue = Convert.ToInt32(selColor);                            //显示Xray信息                            if (item.XrayData != null)                            {                                isExists = true;                                ShowXrayAtlas(colorValue, item.XrayData);                            }                            break;                        }                    }                    if (!isExists)                    {                        ShowXrayAtlas();                    }                //}            }        }        public void ShowEditContent(string stdID)        {            if (m_STDXrayList != null)            {                for (int i = 0; i < m_STDXrayList.Count; i++)                {                    if (m_STDXrayList[i].StdID == stdID)                    {                        //获取修改行的信息                        xrayByteData = (byte[])m_STDXrayList[i].XrayData;                                            }                }            }        }        /// <summary>        /// 根据STDId修改对应的Xray信息        /// </summary>        /// <param name="STDId"></param>        protected void UpdateSTDXray(int STDId, byte[] xrayData)        {            if (m_STDXrayList != null)            {                //if (m_STDXrayList.Count > 0)                //{                    bool isExists = false;                    foreach (STDXray item in m_STDXrayList)                    {                        //修改XrayData信息                        if (item.StdID == STDId.ToString())                        {                            item.XrayData = xrayData;                            item.InfoState = (int)STDXrayInfoState.Modify;                            isExists = true;                            break;                        }                    }                    if (!isExists)                    {                        if (!STDId.ToString().Equals(""))                        {                            //添加STD XrayData信息                            STDXray stdXray = new STDXray();                            stdXray.StdID = STDId.ToString();                            stdXray.XrayData = xrayData;                            stdXray.InfoState = (int)STDXrayInfoState.Add;                            m_STDXrayList.Add(stdXray);                        }                    }                //}            }        }        /// <summary>        /// 添加STDXray信息        /// </summary>        /// <param name="STDid">STDid</param>        /// <param name="xrayData">Xray信息</param>        /// <returns></returns>        protected bool AddSTDXray(int STDId, byte[] xrayData)        {            bool addResult = false;            if (m_STDXrayList != null)              {                //if (m_STDXrayList.Count > 0)                //{                    if (!STDId.ToString().Equals(""))                    {                        //添加STD XrayData信息                        STDXray stdXray = new STDXray();                        stdXray.StdID = STDId.ToString();                        stdXray.XrayData = xrayData;                        stdXray.InfoState = (int)STDXrayInfoState.Add;                        m_STDXrayList.Add(stdXray);                        addResult = true;                    }                //}            }            return addResult;        }        /// <summary>        /// 删除STDXray信息        /// </summary>        /// <param name="STDId">所选要删除的STDId</param>        /// <returns></returns>        public bool DelSTDXray(int STDId)        {            bool delResult = false;            if (m_STDXrayList != null)            {                //if (m_STDXrayList.Count > 0)                //{                    if (!STDId.ToString().Equals(""))                    {                        foreach (STDXray item in m_STDXrayList)                        {                            //修改XrayData信息                            if (item.StdID == STDId.ToString())                            {                                item.InfoState = (int)STDXrayInfoState.Delete;                                delResult = true;                                break;                            }                        }                    }                //}            }            return delResult;        }        #endregion        #region 控制BSE、化学式、元素本文框中不能输入下划线        /// <summary>        /// 控件不能输入下划线        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void textBox_KeyPress(object sender, KeyPressEventArgs e)        {            if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||                  (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || !(e.KeyChar == '_'))            {                e.Handled = false;            }            else            {                e.Handled = true;            }        }        #endregion        private void btnTest_Click(object sender, EventArgs e)        {            XrayContrastForm xrayContrastForm = new XrayContrastForm();            xrayContrastForm.STDDictionary = m_SubMidWindow.m_MainForm.STDDictionary;            xrayContrastForm.ShowDialog();        }        private float X = 1;        private float Y = 1;        private void STDEditor_Resize(object sender, EventArgs e)        {            //float newx = (this.Width) / X;            //float newy = this.Height / Y;            //AmplificationFactor = newy;            //setControls(newx, newy, this.tabSTDStandrad.TabPages[0]);            ////button_Extend.BackColor = SystemColors.ControlDarkDark;        }        private void setTag(Control cons)        {            foreach (Control con in cons.Controls)            {                con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;                if (con.Controls.Count > 0)                    setTag(con);            }        }        private void setControls(float newx, float newy, Control cons)        {            foreach (Control con in cons.Controls)            {                if (false)                {                }                else                {                    string[] mytag = con.Tag.ToString().Split(':');                    float a = Convert.ToSingle(mytag[0]) * newx;                    con.Width = (int)a;                    a = Convert.ToSingle(mytag[1]) * newy;                    con.Height = (int)(a);                    a = Convert.ToSingle(mytag[2]) * newx;                    con.Left = (int)(a);                    a = Convert.ToSingle(mytag[3]) * newy;                    con.Top = (int)(a);                    Single currentSize;                    if (con.Name == "button_Extend")                    {                        currentSize = 6f;                    }                    else                    {                        if (Math.Max(newx, newy) < 1)                        {                            currentSize = Convert.ToSingle(mytag[4]) * 1;                        }                        else                        {                            currentSize = Convert.ToSingle(mytag[4]) * Math.Max(newx, newy);                        }                    }                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);                    if (con.Controls.Count > 0)                    {                        setControls(newx, newy, con);                    }                }            }        }        Form_PeriodicTable form_PeriodicTable;        private void button_PeriodicTableSwitch_Click(object sender, EventArgs e)        {            if (form_PeriodicTable == null) //如果子窗体为空则创造实例 并显示            {                form_PeriodicTable = new Form_PeriodicTable();                if (table_STDEditor["language"].ToString() == "EN")                {                    form_PeriodicTable.BackgroundImage = global::SpectrumSTDEditor.Properties.Resources.PeriodicTable_EN;                }                else                {                    form_PeriodicTable.BackgroundImage = global::SpectrumSTDEditor.Properties.Resources.PeriodicTable_ZH;                }                form_PeriodicTable.Show();            }            else            {                if (form_PeriodicTable.IsDisposed) //若子窗体关闭 则打开新子窗体 并显示                {                    form_PeriodicTable = new Form_PeriodicTable();                    if (table_STDEditor["language"].ToString() == "EN")                    {                        form_PeriodicTable.BackgroundImage = global::SpectrumSTDEditor.Properties.Resources.PeriodicTable_EN;                    }                    else                    {                        form_PeriodicTable.BackgroundImage = global::SpectrumSTDEditor.Properties.Resources.PeriodicTable_ZH;                    }                    form_PeriodicTable.Show();                }                else                {                    form_PeriodicTable.Activate(); //使子窗体获得焦点                }            }        }        private void button_ImportFromResult_Click(object sender, EventArgs e)        {            OpenFileDialog openFileDialog = new OpenFileDialog();            openFileDialog.Filter = "(*.db)|*.db";            openFileDialog.RestoreDirectory = true;            openFileDialog.FilterIndex = 1;            if (openFileDialog.ShowDialog() == DialogResult.OK)            {                try                {                    System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + openFileDialog.FileName + "'");                    m_dbConnection.Open();                    string STDId = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column].Tag.ToString();                    Result ret=ImportFromResult(STDId, m_dbConnection);                    if(ret== Result.NoMatched)                    {                        MessageBox.Show("No matching energy spectrum data was found", "Tip");                    }                    m_dbConnection.Close();                    int color = Convert.ToInt32(m_SubMidWindow.m_MainForm.STDDictionary[int.Parse(STDId)].Color);                    for(int i=0;i< m_STDXrayList.Count;i++)                    {                        if(m_STDXrayList[i].StdID== STDId)                        {                            ShowXrayAtlas(color, m_STDXrayList[i].XrayData);                            break;                        }                    }                }                catch /*(Exception ex)*/                {                    MessageBox.Show("Failed to load Xray data!", "Tip");                }            }        }        public Result ImportFromResult(string STDId, System.Data.SQLite.SQLiteConnection m_dbConnection)        {            try            {                System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select FieldId ,XrayId from IncAData where TypeId ="+ STDId , m_dbConnection);                DataSet ds = new DataSet();                m_dataAdapter.Fill(ds);                DataTable dt = ds.Tables[0];                if (dt != null)                {                    if (dt.Rows.Count > 0)                    {                        string sqlstr = "select XrayData from XRayData where FieldId = " + dt.Rows[0]["FieldId"] + " AND XrayIndex =" + dt.Rows[0]["XrayId"];                        m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter(sqlstr, m_dbConnection);                        ds = new DataSet();                        m_dataAdapter.Fill(ds);                        dt = ds.Tables[0];                        if (dt != null)                        {                            if (dt.Rows.Count > 0)                            {                                DialogResult dr = MessageBox.Show("ID Num:" + STDId+ ", this rule has found the first match object, is it loaded?", "Tip", MessageBoxButtons.OKCancel);                                if(dr == DialogResult.OK)                                {                                    m_SubMidWindow.m_MainForm.IsModified = true;                                    if (SelSTDDBBySTDId(STDId))                                    {                                        if (MessageBox.Show("ID Num:" + STDId + ", the database already contains records of this rule XRay curve, is it overwritten?", "Tip", MessageBoxButtons.OKCancel) == DialogResult.OK)                                        {                                            UpdateSTDXray(int.Parse(STDId), (byte[])dt.Rows[0]["XrayData"]);                                        }                                     }                                     else                                    {                                        UpdateSTDXray(int.Parse(STDId), (byte[])dt.Rows[0]["XrayData"]);                                    }                                }                                return Result.Success;                            }                            else                            {                                return Result.NoMatched;                            }                        }                        else                        {                            return Result.NoMatched;                        }                    }                    else                    {                        return Result.NoMatched;                    }                }                else                {                    return Result.NoMatched;                }                      }            catch /*(Exception ee)*/            {                MessageBox.Show("Failed to load Xray data!", "Tip");                return Result.Fail;            }        }        public void ShowTabXray()        {            tabSTDStandrad.SelectedIndex = 1;        }        public void ShowSTD()        {            tabSTDStandrad.SelectedIndex = 0;        }    }}
 |