protected void btnSaveRoot_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtRootCode.Text.Trim())) { lblrootMessage.Text = "代码不能为空!"; return; } if (string.IsNullOrEmpty(txtRootName.Text.Trim())) { lblrootMessage.Text = "名称不能为空!"; return; } using (var edm = new GoldEntities()) { var tmp = edm.CreateObject <DataDict>(); tmp.Name = txtRootName.Text.Trim(); tmp.Code = txtRootCode.Text.Trim(); tmp.Category = "root"; tmp.Enabled = true; edm.AddToDataDict(tmp); edm.SaveChanges(); TreeNode node = new TreeNode(); node.Value = tmp.Code; node.Text = tmp.Name; TreeView1.Nodes.Add(node); txtRootCode.Text = ""; txtRootName.Text = ""; lblrootMessage.Text = "保存成功!"; } }
protected void btnSaveValue_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtValueCode.Text.Trim())) { lblMessage2.Text = "代码不能为空!"; return; } if (string.IsNullOrEmpty(txtValueName.Text.Trim())) { lblMessage2.Text = "名称不能为空!"; return; } using (var edm = new GoldEntities()) { var tmp = edm.CreateObject <DataDict>(); tmp.Name = txtValueName.Text.Trim(); tmp.Code = txtValueCode.Text.Trim(); int x; if (!string.IsNullOrEmpty(txtValueOrder.Text.Trim()) && int.TryParse(txtValueOrder.Text.Trim(), out x)) { tmp.Order = x; } tmp.Category = TreeView1.SelectedNode.Value; tmp.Enabled = true; edm.AddToDataDict(tmp); edm.SaveChanges(); GridView1.DataBind(); txtValueCode.Text = ""; txtValueName.Text = ""; txtValueOrder.Text = ""; lblMessage2.Text = "保存成功!"; } }