| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 | 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<List<string>> leixingMingchengs = new List<List<string>>();        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<string> newLeixingMingcheng = new List<string>();                leixingMingchengs.Add(newLeixingMingcheng);            }            ReadXml();        }        private void timer1_Tick(object sender, EventArgs e)        {            //DateTime time =   DateTime.Now;            //  (DateTime.Now-time).TotalSeconds;        }        /// <summary>        /// 添加名稱        /// </summary>        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();        }        /// <summary>        /// 修改名稱        /// </summary>        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();        }        /// <summary>        /// 刪除名稱        /// </summary>        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();            }        }        /// <summary>        /// 關閉界面        /// </summary>        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<string> newListString = new List<string>();                //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();            }        }    }}
 |