123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MeasureData;
- using System.Configuration;
- namespace HOZProject
- {
- public partial class UControl_Init : UserControl
- {
- #region 全局变量
- String[] sT;
- String[] firms;
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- private FormHOZMain formHOZMain;
- public FormHOZMain FormHOZMainObject { get => formHOZMain; set => formHOZMain = value; }
- //模板路径
- private string readConfigPath;
- public string ReadConfigPath { get => readConfigPath; set => readConfigPath = value; }
- #endregion
- public UControl_Init(FormHOZMain formHOZ)
- {
- InitializeComponent();
- FormHOZMainObject = formHOZ;
- }
- private void UControl_Init_Load(object sender, EventArgs e)
- {
-
- }
- private void btnClose_Click(object sender, EventArgs e)
- {
- Form fParent = this.ParentForm;
- fParent.Close();
- }
- private void pbCutHoleFile_Click(object sender, EventArgs e)
- {
- if (FormHOZMainObject.m_MeasureFile == null)
- {
- MessageBox.Show("请新建一个测量文件");
- }
- else
- {
- if (!FormHOZMainObject.m_MeasureFile.GetCutHolesFromFile(""))
- {
- MessageBox.Show("导入切孔失败");
- }
- else
- {
- List<CutHole> ListCutHole = FormHOZMainObject.m_MeasureFile.ListCutHole;
- //文件路径
- string filePath = FormHOZMainObject.m_MeasureFile.FilePath;
- string fileName = FormHOZMainObject.m_MeasureFile.FileName;
- FormHOZMainObject.CreateCutHoleList(ListCutHole);
- //显示导入的切孔数量
- lblCutHoleCount.Text = string.Format("成功导入{0}个切孔",ListCutHole.Count);
- tbCutHoleFilePath.Text = filePath + fileName;
- }
- }
- }
- /// <summary>
- /// 根据一个切孔,自动计算其他切孔信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void pbCutHoleAuto_Click(object sender, EventArgs e)
- {
- }
- private void pbTemplateFile_Click(object sender, EventArgs e)
- {
- string FilePathName;
- string fileNameWithoutExtension;
- //新建一个文件对话框
- OpenFileDialog pOpenFileDialog = new OpenFileDialog();
- //设置对话框标题
- pOpenFileDialog.Title = "选择模板文件";
- //设置打开文件类型
- pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
- //监测文件是否存在
- pOpenFileDialog.CheckFileExists = true;
- //文件打开后执行以下程序
- if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
- {
- FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
- fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
- this.txtWPTF.Text = fileNameWithoutExtension;
- }
- }
- private void pbFIBTemplateFile_Click(object sender, EventArgs e)
- {
- string FilePathName;
- string fileNameWithoutExtension;
- //新建一个文件对话框
- OpenFileDialog pOpenFileDialog = new OpenFileDialog();
- //设置对话框标题
- pOpenFileDialog.Title = "选择模板文件";
- //设置打开文件类型
- pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
- //监测文件是否存在
- pOpenFileDialog.CheckFileExists = true;
- //文件打开后执行以下程序
- if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
- {
- FilePathName = System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
- fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(FilePathName);
- this.txtWFIBF.Text = fileNameWithoutExtension;
- }
- }
- #region 创建与读取样品参数文件
- private void btnCreateConfig_Click(object sender, EventArgs e)
- {
- ConfigFile cfm = new ConfigFile();
- cfm.Is_Photograph = chkWIsP.Checked;
- cfm.PT_Depostion = chkWPT.Checked;
- cfm.PT_ELYFile = txtWPTF.Text;
- cfm.FIB_ELYFile = txtWFIBF.Text;
- cfm.Stretch_Magnification = Convert.ToDouble(cbbWLZ.Text);
- cfm.Location_Magnification = Convert.ToDouble(cbbWQGF.Text);
- cfm.Location_Voltage = Convert.ToDouble(cbbWQGD.Text);
- cfm.Photograph_Magnification = Convert.ToDouble(cbbWPZF.Text);
- cfm.Photograph_Voltage = Convert.ToDouble(cbbWPZD.Text);
- if (cbbWXZ.SelectedIndex == 0)
- {
- cfm.Correction_Angle = 36.0;
- }
- else
- {
- cfm.Correction_Angle = 54.0;
- }
- cfm.Sample_Type = cbbWYP.Text;
- cfm.Firm = cbbWCS.Text;
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- saveFileDialog.Filter = "样品参数文件|*.cfg";
- if (saveFileDialog.ShowDialog() == DialogResult.OK)
- {
- cfm.Save(saveFileDialog.FileName);
- }
- else
- {
- return;
- }
- List<String> _sT = sT.ToList();
- if (_sT.IndexOf(cbbWYP.Text) < 0)
- {
- _sT.Add(cbbWYP.Text);
- sT = _sT.ToArray();
- string wsT = "";
- for (int i = 0; i < sT.Length; i++)
- {
- wsT += sT[i] + ",";
- }
- wsT = wsT.Substring(0, wsT.Length - 1);
- config.AppSettings.Settings["Sample_Type"].Value = wsT;
- }
- List<String> _firms = firms.ToList();
- if (_firms.IndexOf(cbbWCS.Text) < 0)
- {
- _firms.Add(cbbWCS.Text);
- firms = _firms.ToArray();
- string wFirms = "";
- for (int i = 0; i < firms.Length; i++)
- {
- wFirms += firms[i] + ",";
- }
- wFirms = wFirms.Substring(0, wFirms.Length - 1);
- config.AppSettings.Settings["Firm"].Value = wFirms;
- }
- config.Save(ConfigurationSaveMode.Modified);
- ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
- }
- public void Reloadconfig()
- {
- String sample_Type = ConfigurationManager.AppSettings["Sample_Type"];
- String firm = ConfigurationManager.AppSettings["Firm"];
- sT = sample_Type.Split(',');
- cbbWYP.Items.Clear();
- for (int i = 0; i < sT.Length; i++)
- {
- cbbWYP.Items.Add(sT[i]);
- }
- firms = firm.Split(',');
- cbbWCS.Items.Clear();
- for (int i = 0; i < firms.Length; i++)
- {
- cbbWCS.Items.Add(firms[i]);
- }
- cbbWYP.SelectedIndex = 0;
- cbbWCS.SelectedIndex = 0;
- cbbWXZ.SelectedIndex = 0;
- cbbWPZD.SelectedIndex = 0;
- cbbWPZF.SelectedIndex = 0;
- cbbWLZ.SelectedIndex = 0;
- cbbWQGD.SelectedIndex = 0;
- cbbWQGF.SelectedIndex = 0;
- }
- public void ReadConfigInfo()
- {
- if (!ReadConfigPath.Equals(""))
- {
- Reloadconfig();
- ConfigFile cfm = new ConfigFile();
- cfm.Read(ReadConfigPath);
- chkWIsP.Checked = cfm.Is_Photograph;
- chkWPT.Checked = cfm.PT_Depostion;
- txtWPTF.Text = cfm.PT_ELYFile;
- txtWFIBF.Text = cfm.FIB_ELYFile;
- cbbWLZ.Text = cfm.Stretch_Magnification.ToString();
- cbbWQGF.Text = cfm.Location_Magnification.ToString();
- cbbWQGD.Text = cfm.Location_Voltage.ToString();
- cbbWPZF.Text = cfm.Photograph_Magnification.ToString();
- cbbWPZD.Text = cfm.Photograph_Voltage.ToString();
- cbbWXZ.Text = cfm.Correction_Angle.ToString();
- cbbWYP.Text = cfm.Sample_Type;
- cbbWCS.Text = cfm.Firm;
- }
- }
- private void btnReadConfig_Click(object sender, EventArgs e)
- {
- //OpenFileDialog openFileDialog = new OpenFileDialog();
- //openFileDialog.Filter = "样品参数文件|*.cfg";
- //if (openFileDialog.ShowDialog() == DialogResult.OK)
- //{
- // ConfigFile cfm = new ConfigFile();
- // cfm.Read(openFileDialog.FileName);
- //}
- ReadConfigInfo();
- }
- #endregion
-
- }
- }
|