/// <summary> /// 系统初始化默认单位 /// </summary> public static void InitSystemDefaultCompany() { try { ICompany factory = CompanyFactory.GetFactory(); bool hasCompany = factory.SystemExistCompany(); if (!hasCompany) { using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { try { dbOperator.BeginTransaction(); BaseCompany compamy = GetCompanyModel(); bool result = factory.Add(compamy, dbOperator); if (!result) { throw new MyException("添加默认单位失败"); } result = SysUserServices.AddCompanyDefaultUser(compamy, dbOperator); if (!result) { throw new MyException("添加默认用户失败"); } dbOperator.CommitTransaction(); } catch { dbOperator.RollbackTransaction(); throw; } } } } catch (Exception ex) { ExceptionsServices.AddExceptions(ex, "添加系统默认单用户失败"); } }
public static bool Add(BaseCompany model) { if (model == null) { throw new ArgumentNullException("model"); } using (DbOperator dbOperator = ConnectionManager.CreateConnection()) { try { dbOperator.BeginTransaction(); model.CPID = GuidGenerator.GetGuid().ToString(); ICompany factory = CompanyFactory.GetFactory(); BaseCompany dbModel = factory.QueryCompanyByCompanyName(model.CPName); if (dbModel != null) { throw new MyException("系统已存在相同单位名称的单位"); } bool result = factory.Add(model, dbOperator); result = SysUserServices.AddCompanyDefaultUser(model, dbOperator); if (!result) { throw new MyException("添加默认用户失败"); } dbOperator.CommitTransaction(); if (result) { OperateLogServices.AddOperateLog <BaseCompany>(model, OperateType.Add); } 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); }