private void AddAttribute() { if (this.IsExists()) { base.RegisterScript("top.ui.alert('此名称已经存在')"); return; } try { using (pm2Entities pm2Entities = new pm2Entities()) { Res_ResourceType res_ResourceType = ( from rt in pm2Entities.Res_ResourceType where rt.ResourceTypeId == this.resourceTypeId select rt).FirstOrDefault <Res_ResourceType>(); Res_Attribute res_Attribute = new Res_Attribute(); res_Attribute.AttributeId = System.Guid.NewGuid().ToString(); res_Attribute.AttributeName = this.txtAttributeName.Text.Trim(); if (res_ResourceType != null) { res_ResourceType.Res_Attribute.Add(res_Attribute); } pm2Entities.SaveChanges(); } System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.Append("top.ui.closeWin(); \n"); stringBuilder.Append("top.ui.reloadTab(); \n"); stringBuilder.Append("top.ui.alert('添加成功'); \n"); base.RegisterScript(stringBuilder.ToString()); } catch { base.RegisterScript("top.ui.alert('添加失败')"); } }
public Res_ResourceType AddModel(pm2Entities pm2) { Res_ResourceType res_ResourceType = new Res_ResourceType(); res_ResourceType.ResourceTypeId = this.hdGuid.Value; res_ResourceType.IsValid = new bool?(true); res_ResourceType.ResourceTypeCode = this.txtResourceCode.Text.Trim() + this.txtCode.Text.Trim(); res_ResourceType.ResourceTypeName = this.txtResourceName.Text.Trim(); res_ResourceType.InputDate = new System.DateTime?(System.DateTime.Now); res_ResourceType.InputUser = PageHelper.QueryUser(this, base.UserCode); if (!string.IsNullOrEmpty(this.ddlCBS.SelectedValue.Trim())) { res_ResourceType.CBSCode = this.ddlCBS.SelectedValue.Trim(); } else { res_ResourceType.CBSCode = null; } string parentId = base.Request["parentId"]; if (!string.IsNullOrEmpty(parentId)) { Res_ResourceType res_ResourceType2 = ( from m in pm2.Res_ResourceType where m.ResourceTypeId == parentId select m).First <Res_ResourceType>(); res_ResourceType2.Res_ResourceType1.Add(res_ResourceType); } return(res_ResourceType); }
public static void Update(ResType resType) { using (pm2Entities entities = new pm2Entities()) { Res_ResourceType type = entities.Res_ResourceType.FirstOrDefault <Res_ResourceType>(c => c.ResourceTypeId == resType.Id); type.ResourceTypeCode = resType.Code; type.ResourceTypeName = resType.Name; type.IsValid = resType.IsValid; type.Res_ResourceType2 = (from rt in entities.Res_ResourceType where rt.ResourceTypeId == resType.ParentId select rt).FirstOrDefault <Res_ResourceType>(); entities.SaveChanges(); } }
public void InitPage() { this.BindCBS(); using (pm2Entities pm2Entities = new pm2Entities()) { if (!string.IsNullOrEmpty(System.Convert.ToString(base.Request.QueryString["parentId"]))) { string parentId = base.Request["parentId"]; Res_ResourceType res_ResourceType = ( from m in pm2Entities.Res_ResourceType where m.ResourceTypeId == parentId select m).First <Res_ResourceType>(); this.txtResourceCode.Text = res_ResourceType.ResourceTypeCode; this.hfldParentId.Value = System.Convert.ToString(base.Request.QueryString["parentId"]); } else { this.hfldParentId.Value = ""; } } if (base.Request.QueryString["id"] != null) { using (pm2Entities pm2Entities2 = new pm2Entities()) { string id = base.Request["id"]; string pid = base.Request["parentId"]; Res_ResourceType res_ResourceType2 = ( from m in pm2Entities2.Res_ResourceType where m.ResourceTypeId == id select m).First <Res_ResourceType>(); this.txtResourceName.Text = res_ResourceType2.ResourceTypeName; if (!string.IsNullOrEmpty(pid)) { string resourceTypeCode = ( from m in pm2Entities2.Res_ResourceType where m.ResourceTypeId == pid select m).First <Res_ResourceType>().ResourceTypeCode; this.txtResourceCode.Text = res_ResourceType2.ResourceTypeCode.Substring(0, resourceTypeCode.Length); this.txtCode.Text = res_ResourceType2.ResourceTypeCode.Substring(resourceTypeCode.Length, res_ResourceType2.ResourceTypeCode.Length - resourceTypeCode.Length); } else { this.txtCode.Text = res_ResourceType2.ResourceTypeCode; } this.ddlCBS.SelectedValue = res_ResourceType2.CBSCode; return; } } this.hdGuid.Value = System.Guid.NewGuid().ToString(); }
public Res_ResourceType UpdateModel(Res_ResourceType model) { model.ResourceTypeCode = this.txtResourceCode.Text.Trim() + this.txtCode.Text.Trim(); model.ResourceTypeName = this.txtResourceName.Text.Trim(); if (!string.IsNullOrEmpty(this.ddlCBS.SelectedValue.Trim())) { model.CBSCode = this.ddlCBS.SelectedValue.Trim(); } else { model.CBSCode = null; } return(model); }
private Res_Resource CreateResource(pm2Entities pm2) { Res_Resource res_Resource = new Res_Resource(); res_Resource.ResourceId = this.hdGuid.Value.Trim(); this.UpdateResource(res_Resource, pm2); res_Resource.InputUser = PageHelper.QueryUser(this, base.UserCode); res_Resource.InputDate = new System.DateTime?(System.DateTime.Now); string parentId = base.Request["parentId"]; Res_ResourceType res_ResourceType = ( from m in pm2.Res_ResourceType where m.ResourceTypeId == parentId select m).First <Res_ResourceType>(); res_ResourceType.Res_Resource.Add(res_Resource); return(res_Resource); }
private void InitTrvwResourceType() { this.trvwResourceType.Nodes.Clear(); string typeCode = this.dropResourceType.SelectedValue; Res_ResourceType res_ResourceType = new Res_ResourceType(); using (pm2Entities pm2Entities = new pm2Entities()) { res_ResourceType = ( from t in pm2Entities.Res_ResourceType where t.ResourceTypeCode == typeCode select t).FirstOrDefault <Res_ResourceType>(); } TreeNode treeNode = new TreeNode(res_ResourceType.ResourceTypeName, res_ResourceType.ResourceTypeId); this.AddChildResourceType(treeNode); this.trvwResourceType.Nodes.Add(treeNode); this.trvwResourceType.DataBind(); }
public static void Add(ResType objResType) { using (pm2Entities entities = new pm2Entities()) { Res_ResourceType type = new Res_ResourceType { ResourceTypeId = objResType.Id, ResourceTypeCode = objResType.Code, ResourceTypeName = objResType.Name, InputUser = objResType.InputUser, InputDate = objResType.InputDate, IsValid = objResType.IsValid, Res_ResourceType2 = (from rt in entities.Res_ResourceType where rt.ResourceTypeId == objResType.ParentId select rt).FirstOrDefault <Res_ResourceType>() }; entities.AddToRes_ResourceType(type); entities.SaveChanges(); } }
public static void Add(ResTypeAttribute typeAttr) { using (pm2Entities entities = new pm2Entities()) { Res_Attribute attribute = new Res_Attribute { AttributeId = typeAttr.Id, AttributeName = typeAttr.Name, InputUser = typeAttr.InputUser, InputDate = typeAttr.InputDate }; Res_ResourceType type = (from rt in entities.Res_ResourceType where rt.ResourceTypeId == typeAttr.ResourceType.Id select rt).FirstOrDefault <Res_ResourceType>(); if (type == null) { throw new Exception("不能确定其所属类别"); } attribute.Res_ResourceType = type; entities.SaveChanges(); } }
public static void Update(List <ResType> resTypeList) { using (pm2Entities entities = new pm2Entities()) { using (List <ResType> .Enumerator enumerator = resTypeList.GetEnumerator()) { ResType resType; while (enumerator.MoveNext()) { resType = enumerator.Current; Res_ResourceType type = entities.Res_ResourceType.FirstOrDefault <Res_ResourceType>(c => c.ResourceTypeId == resType.Id); type.ResourceTypeCode = resType.Code; type.ResourceTypeName = resType.Name; type.IsValid = resType.IsValid; type.CBSCode = resType.CBSCode; type.Res_ResourceType2 = (from rt in entities.Res_ResourceType where rt.ResourceTypeId == resType.ParentId select rt).FirstOrDefault <Res_ResourceType>(); } } entities.SaveChanges(); } }
protected void btnDel_Click(object sender, System.EventArgs e) { System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>(); bool flag = false; System.Collections.IEnumerator enumerator = this.gvResource.Rows.GetEnumerator(); try { while (enumerator.MoveNext()) { GridViewRow gridViewRow = (GridViewRow)enumerator.Current; CheckBox cb = gridViewRow.FindControl("cbBox") as CheckBox; if (cb != null && cb.Checked) { using (pm2Entities pm2Entities = new pm2Entities()) { IQueryable <Res_Resource> source = from m in pm2Entities.Res_Resource where m.Res_ResourceType.ResourceTypeId == cb.ToolTip select m; IQueryable <Res_ResourceType> source2 = from m in pm2Entities.Res_ResourceType where m.Res_ResourceType2.ResourceTypeId == cb.ToolTip select m; string value = ( from m in pm2Entities.Bud_CostAccounting where m.ResourceType == cb.ToolTip select m.Id).FirstOrDefault <string>(); if (source.Count <Res_Resource>() > 0 || source2.Count <Res_ResourceType>() > 0 || !string.IsNullOrEmpty(value)) { flag = true; break; } list.Add(cb.ToolTip); } } } } finally { System.IDisposable disposable = enumerator as System.IDisposable; if (disposable != null) { disposable.Dispose(); } } if (flag) { base.RegisterScript("alert('系统提示:\\n请先删除子项!')"); return; } foreach (string item in list) { using (pm2Entities pm2Entities2 = new pm2Entities()) { Res_ResourceType entity = ( from m in pm2Entities2.Res_ResourceType where m.ResourceTypeId == item select m).First <Res_ResourceType>(); pm2Entities2.DeleteObject(entity); pm2Entities2.SaveChanges(); } } base.RegisterScript(string.Concat(new string[] { "window.location.href='ResourceTypeList.aspx?id=", this.tvResource.SelectedValue, "';document.cookie='scrollTop='+'", base.Request.Cookies["scrollTop"].Value.ToString(), "'" })); }
protected void btnSave_Click(object sender, System.EventArgs e) { if (!this.Page.IsValid) { return; } if (this.txtResourceCode.Text.Trim().Length > 20 || this.txtResourceName.Text.Trim().Length > 20) { base.RegisterScript("top.ui.alert('系统提示', '请输入少于20的字符个数,空格包含在内!!')"); return; } int num = 0; using (pm2Entities pm2Entities = new pm2Entities()) { IQueryable <Res_ResourceType> source = from m in pm2Entities.Res_ResourceType where m.ResourceTypeCode == this.txtResourceCode.Text.Trim() + this.txtCode.Text.Trim() select m; IQueryable <Res_ResourceType> source2 = from m in pm2Entities.Res_ResourceType where m.ResourceTypeName == this.txtResourceName.Text.Trim() select m; if (base.Request["id"] != null) { string id = base.Request["id"]; Res_ResourceType res_ResourceType = ( from m in pm2Entities.Res_ResourceType where m.ResourceTypeId == id select m).First <Res_ResourceType>(); if (res_ResourceType.ResourceTypeCode != this.txtResourceCode.Text.Trim() + this.txtCode.Text.Trim() && source.Count <Res_ResourceType>() > 0) { base.RegisterScript("top.ui.alert('系统提示:类型编码已存在!!请重新定义!!')"); return; } if (res_ResourceType.ResourceTypeName != this.txtResourceName.Text.Trim() && source2.Count <Res_ResourceType>() > 0) { base.RegisterScript("top.ui.alert('系统提示:类型名称已存在!!请重新定义!!')"); return; } this.UpdateModel(res_ResourceType); num = pm2Entities.SaveChanges(); } else { if (source.Count <Res_ResourceType>() > 0) { base.RegisterScript("top.ui.alert('系统提示:类型名称已存在!!请重新定义!!')"); return; } if (source2.Count <Res_ResourceType>() > 0) { base.RegisterScript("top.ui.alert('系统提示:类型名称已存在!!请重新定义!!')"); return; } pm2Entities.AddToRes_ResourceType(this.AddModel(pm2Entities)); num = pm2Entities.SaveChanges(); } } if (num > 0) { string text = this.SetMsg() + "成功!"; string text2 = "/BudgetManage/Resource/ResourceTypeList.aspx?id=" + base.Request["parentId"]; string message = string.Concat(new string[] { "top.ui.closeWin(); \ntop.ui.show( '", text, "'); \ntop.ui.reloadTab({url: '", text2, "'}); \n" }); base.RegisterScript(message); return; } base.RegisterScript("top.ui.alert('系统提示', '" + this.SetMsg() + "失败!');"); }