话不多说直接上代码
//唤出动态输入窗体
FrmInputs frm = new FrmInputs("新增库存品类", new string[] { "名称", "初始数量" },//定义各项名称 new Dictionary<string, HZH_Controls.TextInputType>() { { "初始数量", HZH_Controls.TextInputType.Integer} },//定义验证方式 不控制输入:NotControl 任意数字:Number 非负数:UnsignNumber 正数:PositiveNumber 整数:Integer 非负整数:PositiveInteger 正则验证:Regex new Dictionary<string, string>() { { "初始数量", "^\\d{0,18}$" } },//正则表达式可不写 new Dictionary<string, KeyBoardType>() { { "初始数量", KeyBoardType.UCKeyBorderNum } },//小键盘样式 new List<string>() { "名称", "初始数量" });//必填项 frm.ShowDialog(this); string[] i = frm.Values;//取值 Stock stock = new Stock(); stock.productName = i[0].Trim().ToString(); stock.number = int.Parse(i[1].Trim()); stock.createTime = DateTime.Now.ToString(); using (DataClasses1DataContext con = new DataClasses1DataContext()) { con.Stock.InsertOnSubmit(stock); con.SubmitChanges(); }