//---------------保存CCRMRoleModule--------------------------- public CRMRoleModule Save(CRMRoleModule entity) { if (this.dataCtx.Connection != null) { if (this.dataCtx.Connection.State == ConnectionState.Closed) { this.dataCtx.Connection.Open(); } } DbTransaction tran = this.dataCtx.Connection.BeginTransaction(); dataCtx.Transaction = tran; try { var qry = from t in CRMRoleModules where t.ID == entity.ID select t; var obj = qry.SingleOrDefault(); if (obj != null) { this.CopyEntity(obj, entity); } else { this.CRMRoleModules.InsertOnSubmit(entity); } this.dataCtx.SubmitChanges(); tran.Commit(); return(entity); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { dataCtx.Connection.Close(); } }
//---------------保存CRMRole--------------------------- public CRMRole Save(CRMRole entity, IList<CRMProduct> prodList,IList<CRMRoleModule> ModuleRights, IList<CRMDepartment> depList, IList<CRMProvince> ProvinceList) { if (this.dataCtx.Connection != null) if (this.dataCtx.Connection.State == ConnectionState.Closed) this.dataCtx.Connection.Open(); DbTransaction tran = this.dataCtx.Connection.BeginTransaction(); dataCtx.Transaction = tran; try { var qry = from t in CRMRoles where t.RoleID == entity.RoleID select t; var obj = qry.SingleOrDefault(); if (obj != null) this.CopyEntity(obj, entity); else this.CRMRoles.InsertOnSubmit(entity); this.dataCtx.SubmitChanges(); //delete Role relationship with product var qryDel = from t in CRMRoleProds where t.RoleID == entity.RoleID select t; foreach (var item in qryDel.ToList()) { this.CRMRoleProds.DeleteOnSubmit(item); } //add new foreach (var prod in prodList) { //insert sub product var subList = GetSubProds(prod.ProdID); foreach (var sub in subList) { var p = new CRMRoleProd(); p.RoleID = entity.RoleID; p.ProdID = sub; this.CRMRoleProds.InsertOnSubmit(p); } } this.dataCtx.SubmitChanges(); //delete Role relationship with module var qryDelM = from t in CRMRoleModules where t.RoleID == entity.RoleID select t; foreach (var item in qryDelM.ToList()) { this.CRMRoleModules.DeleteOnSubmit(item); } //add new foreach (var Module in ModuleRights) { if (Module!=null) { var p = new CRMRoleModule(); p.RoleID = entity.RoleID; p.ModuleID = Module.ModuleID; p.ReadOnly = Module.ReadOnly; p.New = Module.New; p.Edit = Module.Edit; p.Del = Module.Del; this.CRMRoleModules.InsertOnSubmit(p); } } this.dataCtx.SubmitChanges(); //delete Role relationship with Department var qryDelDep = from t in CRMRoleDeps where t.RoleID == entity.RoleID select t; foreach (var item in qryDelDep.ToList()) { this.CRMRoleDeps.DeleteOnSubmit(item); } //add new foreach (var dep in depList) { if (dep != null) { var p = new CRMRoleDep(); p.RoleID = entity.RoleID; p.DepID = dep.DepID; this.CRMRoleDeps.InsertOnSubmit(p); } } this.dataCtx.SubmitChanges(); //delete Role relationship with province var qryDelProvince = from t in CRMRoleProvinces where t.RoleID == entity.RoleID select t; foreach (var item in qryDelProvince.ToList()) { this.CRMRoleProvinces.DeleteOnSubmit(item); } //add new foreach (var prov in ProvinceList) { if (prov != null) { var p = new CRMRoleProvince(); p.RoleID = entity.RoleID; p.ProvinceID = prov.ProvinceID; this.CRMRoleProvinces.InsertOnSubmit(p); } } this.dataCtx.SubmitChanges(); tran.Commit(); return entity; } catch (Exception ex) { tran.Rollback(); throw ex; } finally { dataCtx.Connection.Close(); } }
//---------------保存CCRMRoleModule--------------------------- public CRMRoleModule Save(CRMRoleModule entity) { if (this.dataCtx.Connection != null) if (this.dataCtx.Connection.State == ConnectionState.Closed) this.dataCtx.Connection.Open(); DbTransaction tran = this.dataCtx.Connection.BeginTransaction(); dataCtx.Transaction = tran; try { var qry = from t in CRMRoleModules where t.ID == entity.ID select t; var obj = qry.SingleOrDefault(); if (obj != null) this.CopyEntity(obj, entity); else this.CRMRoleModules.InsertOnSubmit(entity); this.dataCtx.SubmitChanges(); tran.Commit(); return entity; } catch (Exception ex) { tran.Rollback(); throw ex; } finally { dataCtx.Connection.Close(); } }
//Click Save Button protected void btnSave_Click(object sender, EventArgs e) { try { var entity = GetSaveEntity(); //角色对应部门权限 List<CRMDepartment> DepList = new List<CRMDepartment>(); string[] arrD = DDCLDep.SelectedValuesToString().Split(','); foreach (var ID in arrD) { if (!string.IsNullOrEmpty(ID)) { var d = new CRMDepartment(); d.DepID = long.Parse(ID); DepList.Add(d); } } //角色对应产品权限 List<CRMProduct> ProdList = new List<CRMProduct>(); string[] arrP = DDCLProduct.SelectedValuesToString().Split(','); foreach (var ID in arrP) { if (!string.IsNullOrEmpty(ID)) { var p = new CRMProduct(); p.ProdID = long.Parse(ID); ProdList.Add(p); } } //角色对应区域省份权限 List<CRMProvince> ProvinceList = new List<CRMProvince>(); string[] arrPv = DDCLProvince.SelectedValuesToString().Split(','); foreach (var ID in arrPv) { if (!string.IsNullOrEmpty(ID)) { var p = new CRMProvince(); p.ProvinceID = int.Parse(ID); ProvinceList.Add(p); } } //角色对应模块权限 //string[] arrM = DDCLModule.SelectedValuesToString().Split(','); List<CRMRoleModule> ModList = new List<CRMRoleModule>(); foreach (RepeaterItem item in rptMod.Items) { var p = new CRMRoleModule(); p.ModuleID = long.Parse(((HiddenField)item.FindControl("HidID")).Value); var cb = (CheckBoxList)item.FindControl("cblRight"); p.ReadOnly = cb.Items[0].Selected ; p.New = cb.Items[1].Selected ; p.Edit = cb.Items[2].Selected; p.Del =cb.Items[3].Selected ; ModList.Add(p); } entity = svr.Save(entity, ProdList, ModList, DepList, ProvinceList); hidID.Value = entity.RoleID.ToString(); this.ShowSaveOK(); } catch (Exception ex) { this.ShowMessage(ex.Message); } }
//Click Save Button protected void btnSave_Click(object sender, EventArgs e) { try { var entity = GetSaveEntity(); //角色对应部门权限 List <CRMDepartment> DepList = new List <CRMDepartment>(); string[] arrD = DDCLDep.SelectedValuesToString().Split(','); foreach (var ID in arrD) { if (!string.IsNullOrEmpty(ID)) { var d = new CRMDepartment(); d.DepID = long.Parse(ID); DepList.Add(d); } } //角色对应产品权限 List <CRMProduct> ProdList = new List <CRMProduct>(); string[] arrP = DDCLProduct.SelectedValuesToString().Split(','); foreach (var ID in arrP) { if (!string.IsNullOrEmpty(ID)) { var p = new CRMProduct(); p.ProdID = long.Parse(ID); ProdList.Add(p); } } //角色对应区域省份权限 List <CRMProvince> ProvinceList = new List <CRMProvince>(); string[] arrPv = DDCLProvince.SelectedValuesToString().Split(','); foreach (var ID in arrPv) { if (!string.IsNullOrEmpty(ID)) { var p = new CRMProvince(); p.ProvinceID = int.Parse(ID); ProvinceList.Add(p); } } //角色对应模块权限 //string[] arrM = DDCLModule.SelectedValuesToString().Split(','); List <CRMRoleModule> ModList = new List <CRMRoleModule>(); foreach (RepeaterItem item in rptMod.Items) { var p = new CRMRoleModule(); p.ModuleID = long.Parse(((HiddenField)item.FindControl("HidID")).Value); var cb = (CheckBoxList)item.FindControl("cblRight"); p.ReadOnly = cb.Items[0].Selected; p.New = cb.Items[1].Selected; p.Edit = cb.Items[2].Selected; p.Del = cb.Items[3].Selected; ModList.Add(p); } entity = svr.Save(entity, ProdList, ModList, DepList, ProvinceList); hidID.Value = entity.RoleID.ToString(); this.ShowSaveOK(); } catch (Exception ex) { this.ShowMessage(ex.Message); } }
//---------------保存CRMRole--------------------------- public CRMRole Save(CRMRole entity, IList <CRMProduct> prodList, IList <CRMRoleModule> ModuleRights, IList <CRMDepartment> depList, IList <CRMProvince> ProvinceList) { if (this.dataCtx.Connection != null) { if (this.dataCtx.Connection.State == ConnectionState.Closed) { this.dataCtx.Connection.Open(); } } DbTransaction tran = this.dataCtx.Connection.BeginTransaction(); dataCtx.Transaction = tran; try { var qry = from t in CRMRoles where t.RoleID == entity.RoleID select t; var obj = qry.SingleOrDefault(); if (obj != null) { this.CopyEntity(obj, entity); } else { this.CRMRoles.InsertOnSubmit(entity); } this.dataCtx.SubmitChanges(); //delete Role relationship with product var qryDel = from t in CRMRoleProds where t.RoleID == entity.RoleID select t; foreach (var item in qryDel.ToList()) { this.CRMRoleProds.DeleteOnSubmit(item); } //add new foreach (var prod in prodList) { //insert sub product var subList = GetSubProds(prod.ProdID); foreach (var sub in subList) { var p = new CRMRoleProd(); p.RoleID = entity.RoleID; p.ProdID = sub; this.CRMRoleProds.InsertOnSubmit(p); } } this.dataCtx.SubmitChanges(); //delete Role relationship with module var qryDelM = from t in CRMRoleModules where t.RoleID == entity.RoleID select t; foreach (var item in qryDelM.ToList()) { this.CRMRoleModules.DeleteOnSubmit(item); } //add new foreach (var Module in ModuleRights) { if (Module != null) { var p = new CRMRoleModule(); p.RoleID = entity.RoleID; p.ModuleID = Module.ModuleID; p.ReadOnly = Module.ReadOnly; p.New = Module.New; p.Edit = Module.Edit; p.Del = Module.Del; this.CRMRoleModules.InsertOnSubmit(p); } } this.dataCtx.SubmitChanges(); //delete Role relationship with Department var qryDelDep = from t in CRMRoleDeps where t.RoleID == entity.RoleID select t; foreach (var item in qryDelDep.ToList()) { this.CRMRoleDeps.DeleteOnSubmit(item); } //add new foreach (var dep in depList) { if (dep != null) { var p = new CRMRoleDep(); p.RoleID = entity.RoleID; p.DepID = dep.DepID; this.CRMRoleDeps.InsertOnSubmit(p); } } this.dataCtx.SubmitChanges(); //delete Role relationship with province var qryDelProvince = from t in CRMRoleProvinces where t.RoleID == entity.RoleID select t; foreach (var item in qryDelProvince.ToList()) { this.CRMRoleProvinces.DeleteOnSubmit(item); } //add new foreach (var prov in ProvinceList) { if (prov != null) { var p = new CRMRoleProvince(); p.RoleID = entity.RoleID; p.ProvinceID = prov.ProvinceID; this.CRMRoleProvinces.InsertOnSubmit(p); } } this.dataCtx.SubmitChanges(); tran.Commit(); return(entity); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { dataCtx.Connection.Close(); } }