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 Sunny.UI;
using System.Xml;
using System.IO;
public ModuleGrid()
{
InitializeComponent();
uipanelMain.AutoScroll = true;//防止内容过多 当显示不下的时候 可以有滚轮
//DisplayData();//这个在这里使用不知道为什么就是报错 显示未将对象设置引用到对象实例 我直接放最开始调用
//MessageBox.Show("kai ");
}
public static ModuleGrid modgrid;
private void uiButton1_Click(object sender, EventArgs e)
{
modgrid = new ModuleGrid();
modgrid.Show();
ModuleGrid.DisplayData();//这个函数的作用就是新增我们需要的框的控件
}
private static int width = 360;
private static int height = 254;
private static List<GridContent> list;
public static string path = Directory.GetCurrentDirectory()+ "\\ParameterSet\\grid.xml";
public static void DisplayData()
{
try
{
list = new List<GridContent>();
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNodeList nodeList = doc.SelectNodes("/person/list");//xPath相关手册,找节点person的list
int index = 1;
foreach (XmlNode node in nodeList)
{
string no = node.Attributes["no"].Value;
string modeName = node.SelectSingleNode("modeName").InnerText;
//MessageBox.Show("modeName:" + modeName);
GridContent grid = new GridContent();
grid.No = no;
list.Add(grid);
addUIItem(index, modeName);//UI增加
index++;
}
}
catch (Exception ex)
{
log.SaveLog(@"报告模板异常:" + ex.Message);
}
}
class GridContent
{
private string modeName;
private string no;
public string ModeName
{
get
{
return modeName;
}
set
{
modeName = value;
}
}
public string No
{
get
{
return no;
}
set
{
no = value;
}
}
}
private static void addUIItem(int index, string modeName)
{
//1724 -50 - 4*width = 78
UIPanel paneln = new UIPanel();
int curIndex = index / 4;
int mod = index % 4;
int pointX = (width + 65) * (mod) + 25;
int pointY = curIndex * (height) + (curIndex + 1) * 25;
paneln.Location = new Point(pointX, pointY);
paneln.Size = new Size(width, height);
paneln.FillColor = Color.White;
paneln.RectColor = ColorTranslator.FromHtml("#D6D6D6");
UILabel label = new UILabel();
label.AutoSize = false;
label.Text = modeName;
label.Location = new Point(40, 20);
label.Size = new Size(300, 90);
label.Font = new System.Drawing.Font("微软雅黑", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
label.TextAlign = ContentAlignment.MiddleCenter;
UIButton btnDel = new UIButton();
btnDel.Size = new Size(100, 50);
btnDel.Location = new Point(50, 170);
btnDel.Font = new System.Drawing.Font("微软雅黑", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
btnDel.FillColor = Color.White;
btnDel.RectColor = ColorTranslator.FromHtml("#D6D6D6");
btnDel.ForeColor = ColorTranslator.FromHtml("#333333");
btnDel.Text = "删除";
btnDel.Tag = list[index - 1].No;
btnDel.Click += new System.EventHandler(btnDel_Click);
UIButton btnEdit = new UIButton();
btnEdit.Size = new Size(100, 50);
btnEdit.Location = new Point(220, 170);
btnEdit.Font = new System.Drawing.Font("微软雅黑", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
btnEdit.FillColor = Color.White;
btnEdit.RectColor = ColorTranslator.FromHtml("#D6D6D6");
btnEdit.ForeColor = ColorTranslator.FromHtml("#333333");
btnEdit.Text = "编辑";
btnEdit.Tag = list[index - 1].No;
btnEdit.Click += new EventHandler(btnEdit_Click);
paneln.Controls.Add(label);
paneln.Controls.Add(btnDel);
paneln.Controls.Add(btnEdit);
Form1.modgrid.uipanelMain.Controls.Add(paneln);
}
this.Close();
在进入的addUIItem函数里面添加的
编辑
private static void btnEdit_Click(object sender, EventArgs e)
{
UIButton btn = (UIButton)sender;
string no = btn.Tag.ToString();
// new AddModule("edit", no, uipanelMain).Show();
AddModule frm = new AddModule("edit", no, Form1.modgrid.uipanelMain);
frm.Show();
Form1.modgrid.Hide();//如果是关闭 那么下次是无法show的
}
删除
private static void btnDel_Click(object sender, EventArgs e)
{
UIButton btn = (UIButton)sender;
string no = btn.Tag.ToString();
delUI();
delGridItem(no);
//this.Invalidate();
//this.Refresh();
}
public static void delUI()
{
int index = 0;
for (int i = list.Count() - 1; i >= 0; i--)
{
index = (i + 1);
Form1.modgrid.uipanelMain.Controls.RemoveAt(index);
}
}
private static void delGridItem(string no)
{
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlElement root = doc.DocumentElement;
XmlNodeList xmlNodeList = doc.SelectNodes("/person/list[@no='" + no + "']");
foreach (XmlNode xmlNode in xmlNodeList)
{
xmlNode.ParentNode.RemoveChild(xmlNode);
}
doc.Save(path);
DisplayData();
}
private void uiPanel3_Click(object sender, EventArgs e)
{
OpenAddModule();
}
private void pictureBox2_Click(object sender, EventArgs e)
{
OpenAddModule();
}
private void uiLabel3_Click(object sender, EventArgs e)
{
OpenAddModule();