/// <summary> /// 获取配方数据 /// </summary> private void GetRecipeData() { try { recipeData = FindData(); recipeNameCbx.Items.Clear(); foreach (var name in recipeData) { recipeNameCbx.Items.Add(name.name.ToString()); } if (int.Parse(INI_FILE_RD.InifileReadValue("配置", "列表索引", INI_FILE_RD.iniPath)) < recipeNameCbx.Items.Count) { recipeNameCbx.SelectedIndex = int.Parse(INI_FILE_RD.InifileReadValue("配置", "列表索引", INI_FILE_RD.iniPath)); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//列表选择改变时更新ID显示并修改WINCC变量ID,使之保持一致 private void recipeNameCbx_SelectedIndexChanged(object sender, EventArgs e) { if (!winccProcessState) { return; } try { foreach (var name in recipeData) { if (name.name == recipeNameCbx.SelectedItem.ToString()) { recipeidTbx.Text = name.id.ToString(); hMI.Tags[recipeControlID].Write(name.id); } } //列表索引写入INI文件 INI_FILE_RD.InifileWriteValue("配置", "列表索引", recipeNameCbx.SelectedIndex.ToString(), INI_FILE_RD.iniPath); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }