using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace PunchAndWeld { public partial class FrmDoorSill_214_3_Condition : Form { public event Action AfterOkButtonClick; public event Action AfterCancelClick; public string ConfigCode { get; set; } public string ProduceModel { get; set; } public FrmDoorSill_214_3_Condition(string configCode,string produceModel) { InitializeComponent(); if (!string.IsNullOrEmpty(configCode)) { SetContend(groupBox1, configCode); } if (!string.IsNullOrEmpty(produceModel)) { SetContend(groupBox2, produceModel); } } private void CBoxCfg_CheckedChanged(object sender, EventArgs e) { CheckBox cbox = sender as CheckBox; SetChecked(groupBox1, cbox); } private void CBoxLeftOrRight_CheckedChanged(object sender, EventArgs e) { CheckBox cbox = sender as CheckBox; SetChecked(groupBox2, cbox); } void SetContend(GroupBox grp, string txt) { foreach (Control c in grp.Controls) { if (c is CheckBox) { if ((c as CheckBox).Text == txt) { (c as CheckBox).Checked = true; return; } } } } string GetChecked(GroupBox grp) { foreach (Control c in grp.Controls) { if (c is CheckBox) { if ((c as CheckBox).Checked == true) { (c as CheckBox).Checked = true; return c.Text?.Trim(); } } } return null; } void SetChecked(GroupBox grp, CheckBox cbox) { foreach (Control c in grp.Controls) { if (c is CheckBox) { if (cbox.Checked == true) { if (cbox.Name != c.Name) { (c as CheckBox).Checked = false; } } } } } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); this.Dispose(); if(AfterCancelClick != null) { AfterCancelClick(); } } private void btnOK_Click(object sender, EventArgs e) { ConfigCode = GetChecked(groupBox1); ProduceModel = GetChecked(groupBox2); if(string.IsNullOrEmpty(ConfigCode)) { MessageBox.Show("配置设置未填写"); return; } if (string.IsNullOrEmpty(ProduceModel)) { MessageBox.Show("生产模式设置未填写"); return; } //base.DialogResult = DialogResult.OK; if (AfterOkButtonClick != null) { AfterOkButtonClick(ConfigCode, ProduceModel); } //FrmDoorSill_214_3 doorSill = new FrmDoorSill_214_3(this, cfg, pmodel); //doorSill.Show(); } } }