public static List <BaseCompany> GetCurrLoginUserRoleCompany(string companyId, string userId) { List <BaseVillage> villages = VillageServices.QueryVillageByUserId(userId); List <BaseCompany> validCompanys = new List <BaseCompany>(); List <BaseCompany> allComapnys = CompanyServices.QueryCompanyAndSubordinateCompany(companyId); foreach (var item in villages) { CompanyServices.GetCurrLoginUserRoleCompany(validCompanys, allComapnys, item.CPID); } return(validCompanys); }
public static bool Delete(string recordId) { if (string.IsNullOrWhiteSpace(recordId)) { throw new ArgumentNullException("recordId"); } ICompany factory = CompanyFactory.GetFactory(); BaseCompany model = factory.QueryCompanyByRecordId(recordId); if (model == null) { throw new MyException("待删除的单位不存在"); } List <BaseCompany> models = factory.QueryCompanysByMasterID(model.CPID); if (models.Count > 0) { throw new MyException("请先删除该公司下的所有下级公司"); } List <BaseVillage> villages = VillageServices.QueryVillageByCompanyId(recordId); if (villages.Count != 0) { throw new MyException("请先删除该单位下的所有的小区"); } ISysUser factoryUser = SysUserFactory.GetFactory(); using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { try { dbOperator.BeginTransaction(); bool result = factory.Delete(recordId, dbOperator); if (!result) { throw new MyException("移除单位信息失败"); } result = factoryUser.DeleteByCompanyId(recordId, dbOperator); if (!result) { throw new MyException("移除用户信息失败"); } dbOperator.CommitTransaction(); if (result) { OperateLogServices.AddOperateLog(OperateType.Delete, string.Format("recordId:{0}", recordId)); } return(result); } catch { dbOperator.RollbackTransaction(); throw; } } }
/// <summary> /// 系统初始化默认单位CS /// </summary> public static bool InitSystemDefaultCompanyCS(string VName, string CPName, string userno, string pwd, string systemmodelpath) { try { ICompany factory = CompanyFactory.GetFactory(); using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { try { dbOperator.BeginTransaction(); BaseCompany compamy = GetCompanyModel(); compamy.CPName = CPName; compamy.UserAccount = userno; compamy.UserPassword = pwd; bool result = factory.Add(compamy, dbOperator); if (!result) { throw new MyException("添加默认单位失败"); } BaseVillage village = GetVillage(compamy.CPID); village.VName = VName; result = VillageServices.AddVillageDefaultUser(village, dbOperator); if (!result) { throw new MyException("添加默认小区失败"); } result = SysUserServices.AddCompanyDefaultUserCS(compamy, village, dbOperator, systemmodelpath); if (!result) { throw new MyException("添加默认用户失败"); } BaseParkinfo parkinfo = GetParkinfo(village.VID); result = ParkingServices.AddParkinfoDefault(parkinfo, dbOperator); if (!result) { throw new MyException("添加默认车场失败"); } dbOperator.CommitTransaction(); ParkArea area = GetParkArea(parkinfo.PKID); result = ParkAreaServices.AddDefualt(area); if (result) { ParkBox box = GetParkBox(area.AreaID); result = ParkBoxServices.AddDefault(box); if (result) { result = ParkGateServices.AddDefault(GetParkGate(box.BoxID, 1)); result = ParkGateServices.AddDefault(GetParkGate(box.BoxID, 2)); } } } catch (Exception ex) { dbOperator.RollbackTransaction(); throw; } } } catch (Exception ex) { ExceptionsServices.AddExceptions(ex, "添加系统默认单用户失败"); return(false); } return(true); }