Exemple #1
0
        /// <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);
        }