using NPOI.Util; using SourceGrid; using System; using System.Collections; 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; namespace OTSIncAReportApp._1_UI.OTSReportExport { public partial class Category : Form { List CheckTheOptions = new List(); DataTable ElementList = new DataTable(); public List OutElementList = new List(); /// /// 窗体是否修改 /// public bool IsModify = false; public List vs = new List(); private bool isRemove = false; Hashtable table; public Category(List a_ElementList,DataTable AllList,bool a_Remove) { InitializeComponent(); ElementList = AllList.Copy(); CheckTheOptions = a_ElementList.Copy(); OutElementList = a_ElementList.Copy(); isRemove = a_Remove; #region 国际化语言 OTSCommon.Language lan = new OTSCommon.Language(this); table = lan.GetNameTable(this.Name); #endregion } //public Category(List a_ElementList,DataTable AllList, bool a_Remove) //{ // ElementList = AllList; // isRemove = a_Remove; // InitializeComponent(); //} private void Category_Load(object sender, EventArgs e) { if (ElementList != null) { if (ElementList.Rows.Count > 0) { FlowLayoutPanel flowLayoutPanel = new FlowLayoutPanel(); flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight; flowLayoutPanel.WrapContents = true; flowLayoutPanel.Dock = DockStyle.Fill; flowLayoutPanel.AutoScroll = true; flowLayoutPanel.Padding = new Padding(20, 10, 20, 25); panel2.Controls.Add(flowLayoutPanel); for (int i = 0; i < ElementList.Rows.Count; i++) { // 添加控件到 FlowLayoutPanel 中 CheckBox box1 = new CheckBox(); box1.Text = ElementList.Rows[i]["StrName"].ToString(); box1.Width = flowLayoutPanel.Width - 40; box1.Height = 25; Font font = new Font("宋体", 15, FontStyle.Regular); box1.Font = font; if (CheckTheOptions.Count == 0) { if (!isRemove) box1.Checked = true; else box1.Checked = false; } else { for (int a = 0; a < CheckTheOptions.Count; a++) { if (ElementList.Rows[i]["STDId"].ToString() == CheckTheOptions[a].ToString()) box1.Checked = true; } } flowLayoutPanel.Controls.Add(box1); } Panel panel = new Panel(); panel.Size = new Size(10, 10); panel.BackColor = Color.Transparent; flowLayoutPanel.Controls.Add(panel); this.checkBox_selall.CheckedChanged -= new System.EventHandler(this.checkBox_selall_CheckedChanged); checkBox_selall.Checked = true; this.checkBox_selall.CheckedChanged += new System.EventHandler(this.checkBox_selall_CheckedChanged); } } } private void checkBox_selall_CheckedChanged(object sender, EventArgs e) { if (checkBox_selall.Checked) { foreach (Control control in panel2.Controls) { if (control.GetType() == typeof(FlowLayoutPanel)) { foreach (Control control1 in control.Controls) { if (control1.GetType() == typeof(System.Windows.Forms.CheckBox)) { ((CheckBox)control1).Checked = true; } } } } } else { foreach (Control control in panel2.Controls) { if (control.GetType() == typeof(FlowLayoutPanel)) { foreach (Control control1 in control.Controls) { if (control1.GetType() == typeof(System.Windows.Forms.CheckBox)) { ((CheckBox)control1).Checked = false; } } } } } } /// /// 确定按钮 /// /// /// private void button3_Click(object sender, EventArgs e) { OutElementList.Clear(); vs.Clear(); List blList = new List(); foreach (Control control in panel2.Controls) { if (control.GetType() == typeof(FlowLayoutPanel)) { foreach (Control control1 in control.Controls) { if (control1.GetType() == typeof(System.Windows.Forms.CheckBox)) { if (((CheckBox)control1).Checked) { blList.Add(true); OutElementList.Add(control1.Text); } else { blList.Add(false); } } } } } for (int i=0;i < ElementList.Rows.Count; i++) { if(blList[i]) { vs.Add(ElementList.Rows[i]["STDId"].ToString()); } } IsModify = true; this.Close(); } /// /// 取消按钮 /// /// /// private void button4_Click(object sender, EventArgs e) { vs.Clear(); vs= CheckTheOptions.Copy(); OutElementList.Clear(); for (int i = 0; i < ElementList.Rows.Count; i++) { for (int a = 0; a < CheckTheOptions.Count; a++) { if (CheckTheOptions[a] == ElementList.Rows[i]["STDId"].ToString()) { OutElementList.Add(ElementList.Rows[i]["StrName"].ToString()); } } } this.Close(); } } }