using Resources; using SmartCoalApplication.MeasureProcedure; using SmartCoalApplication.Resources; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; namespace SmartCoalApplication.Setup { internal partial class BasicInformationSettings : Form { private List> leixingMingchengs = new List>(); private int indexLeixing = new int(); private int indexMingcheng = new int(); private MeasureSettingDialog measureSettingDialog; public BasicInformationSettings() { InitializeComponent(); InitializeLanguageText(); this.Icon = PdnInfo.AppIcon; } public BasicInformationSettings(MeasureSettingDialog measureSettingDialog) { InitializeComponent(); InitializeLanguageText(); this.Icon = PdnInfo.AppIcon; this.measureSettingDialog = measureSettingDialog; } private void InitializeLanguageText() { this.Text = PdnResources.GetString("NewBasicInfoSetting"); this.groupBox1.Text = PdnResources.GetString("NewType"); this.groupBox2.Text = PdnResources.GetString("Menu.operation.text"); this.buttonClose.Text = PdnResources.GetString("Menu.File.Close.Text"); this.buttonDelete.Text = PdnResources.GetString("NewDelete"); this.buttonEdit.Text = PdnResources.GetString("NewEdit"); this.buttonAdd.Text = PdnResources.GetString("NewAdd"); this.groupBox3.Text = PdnResources.GetString("NewName"); } private void BasicInformationSettings_Load(object sender, EventArgs e) { string[] leixings = { PdnResources.GetString("NewFactoryArea"), PdnResources.GetString("NewLaboratory"), PdnResources.GetString("NewLayers"), PdnResources.GetString("NewMadeOf"), PdnResources.GetString("NewFrequency")}; for (int i = 0; i < leixings.Length; i++) { listBoxLeixing.Items.Add(leixings[i]); List newLeixingMingcheng = new List(); leixingMingchengs.Add(newLeixingMingcheng); } ReadXml(); } private void timer1_Tick(object sender, EventArgs e) { //DateTime time = DateTime.Now; // (DateTime.Now-time).TotalSeconds; } /// /// 添加名稱 /// private void buttonAdd_Click(object sender, EventArgs e) { indexLeixing = listBoxLeixing.SelectedIndex; if (indexLeixing == -1) { MessageBox.Show(PdnResources.GetString("NewPleaseSelectType")); return; } Xinzeng from2 = new Xinzeng("", 1); from2.TransferEvent += AddMingcheng; from2.StartPosition = FormStartPosition.CenterScreen; from2.ShowDialog(); } private void AddMingcheng(string mingcheng) { if (leixingMingchengs[indexLeixing].Contains(mingcheng)) { MessageBox.Show(PdnResources.GetString("BasicInformationSetting.ReapeatedName")); return; } leixingMingchengs[indexLeixing].Add(mingcheng); listBoxMingcheng.DataSource = null; listBoxMingcheng.DataSource = leixingMingchengs[indexLeixing]; WriteXml(); } /// /// 修改名稱 /// private void buttonEdit_Click(object sender, EventArgs e) { indexLeixing = listBoxLeixing.SelectedIndex; if (indexLeixing == -1) { MessageBox.Show(PdnResources.GetString("NewPleaseSelectType")); return; } if (listBoxMingcheng.SelectedIndex == -1) { return; } var chooseData = listBoxMingcheng.SelectedItem.ToString(); indexMingcheng = listBoxMingcheng.SelectedIndex; Xinzeng from3 = new Xinzeng(chooseData, 2); from3.TransferEvent += EditMingcheng; from3.StartPosition = FormStartPosition.CenterScreen; from3.ShowDialog(); } private void EditMingcheng(string mingcheng) { indexLeixing = listBoxLeixing.SelectedIndex; if (indexLeixing == -1) { MessageBox.Show(PdnResources.GetString("NewPleaseSelectType")); return; } if (leixingMingchengs[indexLeixing].Contains(mingcheng) && leixingMingchengs[indexLeixing].IndexOf(mingcheng) != indexMingcheng) { MessageBox.Show(PdnResources.GetString("BasicInformationSetting.ReapeatedName")); return; } leixingMingchengs[indexLeixing][indexMingcheng] = mingcheng; listBoxMingcheng.DataSource = null; listBoxMingcheng.DataSource = leixingMingchengs[indexLeixing]; WriteXml(); } /// /// 刪除名稱 /// private void buttonDelete_Click(object sender, EventArgs e) { indexLeixing = listBoxLeixing.SelectedIndex; if (indexLeixing == -1) { MessageBox.Show(PdnResources.GetString("NewPleaseSelectType")); return; } indexMingcheng = listBoxMingcheng.SelectedIndex; if (indexMingcheng == -1) { MessageBox.Show(PdnResources.GetString("NewPleaseSelectDeleteData")); return; } if (leixingMingchengs[indexLeixing].Count == 0) MessageBox.Show(PdnResources.GetString("NewTheContentEmpty")); DialogResult result = MessageBox.Show(PdnResources.GetString("NewLrrecoverableAfterDeletion"), PdnResources.GetString("NewDelete"), MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { leixingMingchengs[indexLeixing].RemoveAt(indexMingcheng); listBoxMingcheng.DataSource = null; listBoxMingcheng.DataSource = leixingMingchengs[indexLeixing]; WriteXml(); } } /// /// 關閉界面 /// private void buttonClose_Click(object sender, EventArgs e) { this.Close(); } private void listBoxLeixing_MouseDown(object sender, MouseEventArgs e) { indexLeixing = listBoxLeixing.SelectedIndex; if (indexLeixing == -1) { return; } listBoxMingcheng.DataSource = null; listBoxMingcheng.DataSource = leixingMingchengs[indexLeixing]; } private void listBoxMingcheng_MouseDown(object sender, MouseEventArgs e) { indexMingcheng = listBoxMingcheng.SelectedIndex; } private void WriteXml() { XmlDocument xDoc = new XmlDocument(); XmlDeclaration declaration = xDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); xDoc.AppendChild(declaration); //根结点 XmlElement genjiedian = xDoc.CreateElement("leixings"); xDoc.AppendChild(genjiedian); //规程结点 for (int i = 0; i < leixingMingchengs.Count; i++) { XmlElement leixing = xDoc.CreateElement(PdnResources.GetString("NewType")); genjiedian.AppendChild(leixing); for (int j = 0; j < leixingMingchengs[i].Count; j++) { XmlElement mingcheng = xDoc.CreateElement(PdnResources.GetString("NewName"));//名称 leixing.AppendChild(mingcheng); mingcheng.InnerText = leixingMingchengs[i][j]; } } string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\basicInformation.xml"; xDoc.Save(filePath); } private void ReadXml() { XmlDocument xDoc = new XmlDocument(); string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\basicInformation.xml"; if (System.IO.File.Exists(filePath)) { xDoc.Load(filePath); } else { XmlDeclaration declaration = xDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); xDoc.AppendChild(declaration); //根结点 XmlElement genjiedian = xDoc.CreateElement("leixings"); xDoc.AppendChild(genjiedian); //规程结点 for (int i = 0; i < 5; i++) { XmlElement leixing = xDoc.CreateElement(PdnResources.GetString("NewType")); genjiedian.AppendChild(leixing); } xDoc.Save(filePath); } XmlNode rootNode = xDoc.SelectSingleNode("leixings"); XmlNodeList leixingList = rootNode.ChildNodes; for (int i = 0; i < leixingList.Count; i++) { //List newListString = new List(); //leixingMingchengs.Add(newListString); XmlNodeList leixingChild = leixingList[i].ChildNodes; for (int j = 0; j < leixingChild.Count; j++) { string mingcheng = ""; mingcheng = leixingChild[j].InnerText; leixingMingchengs[i].Add(mingcheng); } } } private void beforeClosing(object sender, FormClosingEventArgs e) { if (this.measureSettingDialog != null) { this.measureSettingDialog.resetInformation(); } } } }