Example #1
0
        protected IList <SmartBox.Console.Common.Entities.SMC_Unit> GetUnitData()
        {
            List <SmartBox.Console.Common.Entities.SMC_Unit> units = new List <Common.Entities.SMC_Unit>();

            SmartBox.Console.Common.Entities.SMC_Unit unitDefault = new Common.Entities.SMC_Unit();
            unitDefault.Unit_Name = "请选择单位";
            unitDefault.Unit_ID   = "";
            units.Add(unitDefault);



            if (this.IsSystemManager)
            {
                IList <SmartBox.Console.Common.Entities.SMC_Unit> _units = Bo.BoFactory.GetSMC_UnitBo.GetAllUnits();
                units.AddRange(_units);
            }
            else
            {
                SmartBox.Console.Common.Entities.SMC_Unit unit = Bo.BoFactory.GetSMC_UnitBo.Get(this.CurrentUser.UnitCode);
                if (unit != null)
                {
                    units.Add(unit);
                }
            }
            return(units);
        }
        private void insertOrUpdateOrg(Org org, SMC_Unit parentUnit)
        {
            try
            {
                if (org.OrgType.ToLower() != "unit_org" && !String.IsNullOrEmpty(org.ParentOrgCode))
                    return;
                IList<KeyValuePair<string, object>> pars = new List<KeyValuePair<string, object>>();
                pars.Add(new KeyValuePair<string, object>("unit_id", org.OrgCode));

                SMC_Unit unit = Bo.BoFactory.GetSMC_UnitBo.Get(pars);
                //更新到内网
                if (unit != null)
                {
                    unit.Unit_Name = org.OrgName;
                    unit.Unit_Sequence = org.OrgSequence;
                    unit.Unit_UpdateTime = DateTime.Now;
                    unit.Unit_UpdateUser = "";
                    if (parentUnit == null)
                    {
                        unit.Unit_Path = org.OrgCode;
                        unit.Upper_Unit_ID = "";
                    }
                    else
                    {
                        unit.Unit_Path = parentUnit.Unit_Path + ".." + org.OrgCode;
                        unit.Upper_Unit_ID = parentUnit.Unit_ID;
                    }
                    Bo.BoFactory.GetSMC_UnitBo.Update(unit);
                }
                else
                {
                    unit = new SMC_Unit();
                    unit.Unit_CreatedTime = DateTime.Now;
                    unit.Unit_ID = org.OrgCode;
                    unit.Unit_CreatedUser = "";
                    unit.Unit_Demo = "";
                    unit.Unit_Name = org.OrgName;
                    if (parentUnit == null)
                    {
                        unit.Unit_Path = org.OrgCode;
                        unit.Upper_Unit_ID = "";
                    }
                    else
                    {
                        unit.Unit_Path = parentUnit.Unit_Path + ".." + org.OrgCode;
                        unit.Upper_Unit_ID = parentUnit.Unit_ID;
                    }
                    unit.Unit_Sequence = 0;
                    if (org != null)
                        unit.Unit_Sequence = org.OrgSequence;
                    unit.Unit_UpdateTime = DateTime.Now;
                    unit.Unit_UpdateUser = "";
                    unit.Upper_Unit_ID = "";

                    Bo.BoFactory.GetSMC_UnitBo.Insert(unit);
                }
            }
            catch (Exception ex)
            {
                SmartBox.Console.Common.Log4NetHelper.Error(ex);
            }
        }
Example #3
0
        static OutsideWS.SMC_Unit CopySMC_Unit(SMC_Unit unit)
        {
            OutsideWS.SMC_Unit entity = new OutsideWS.SMC_Unit();
            entity.Unit_CreatedTime = unit.Unit_CreatedTime;
            entity.Unit_CreatedUser = unit.Unit_CreatedUser;
            entity.Unit_Demo = unit.Unit_Demo;
            entity.Unit_ID = Convert.ToInt32(unit.Unit_ID);
            entity.Unit_Name = unit.Unit_Name;
            entity.Unit_Path = unit.Unit_Path;
            entity.Unit_Sequence = unit.Unit_Sequence;
            entity.Unit_UpdateTime = unit.Unit_UpdateTime;
            entity.Unit_UpdateUser = unit.Unit_UpdateUser;
            entity.Upper_Unit_ID = Convert.ToInt32(unit.Upper_Unit_ID);

            return entity;
        }
        public ActionResult AddModifyUnitSave(string Unit_ID, string Upper_Unit_ID, string Unit_Name, int Unit_Sequence, string Unit_Demo)
        {
            JsonReturnMessages data = new JsonReturnMessages() { IsSuccess = true, Msg = "操作成功" };
            SMC_Unit unit = null;
            if (String.IsNullOrEmpty(Unit_ID))
            {
                unit = new SMC_Unit();
                unit.Unit_CreatedTime = DateTime.Now;
            }
            else
            {
                unit = BoFactory.GetSMC_UnitBo.Get(Unit_ID);
            }
            unit.Unit_Demo = Unit_Demo;
            unit.Unit_Name = Unit_Name;
            unit.Unit_Sequence = Unit_Sequence;
            unit.Upper_Unit_ID = Upper_Unit_ID;
            unit.Unit_ID = Unit_ID;

            try
            {
                BoFactory.GetSMC_UnitBo.InsertOrUpdate(unit);
            }
            catch (Exception ex)
            {
                data.IsSuccess = false;
                data.Msg = ex.Message;
                return Json(data);
            }

            SMC_Unit _old_unit = unit;

            string pathString = unit.Unit_ID.ToString();
            while (unit != null && !String.IsNullOrEmpty(unit.Upper_Unit_ID))
            {
                pathString = unit.Upper_Unit_ID + ".." + pathString;
                if (String.IsNullOrEmpty(unit.Upper_Unit_ID))
                    unit = null;
                else
                    unit = BoFactory.GetSMC_UnitBo.Get(unit.Upper_Unit_ID);
            }
            _old_unit.Unit_Path = pathString;
            BoFactory.GetSMC_UnitBo.InsertOrUpdate(_old_unit);

            return Json(data);
        }
        public virtual void BUAUserSyncToInside(string ids, Hashtable result)
        {
            ServiceFactory factory = Beyondbit.BUA.Client.ServiceFactory.Instance();
            IUserService us = factory.GetUserService();
            IOrgService os = factory.GetOrgService();
            SMC_UserDao userDao = new SMC_UserDao(AppConfig.statisticDBKey);
            SMC_BUAUserSyncToInsideDao buaSyncInsideDao = new SMC_BUAUserSyncToInsideDao(AppConfig.statisticDBKey);
            GlobalParamDao globalParamDao = new GlobalParamDao(AppConfig.statisticDBKey);
            GlobalParam p = globalParamDao.GetGlobalParam("user_default_status");
            int batNo = 0;
            try
            {
                batNo = buaSyncInsideDao.GetMaxBatNo();
            }
            catch (Exception e)
            {
            }
            batNo += 1;

            string[] idlist = ids.Split(",".ToCharArray());
            foreach (string uid in idlist)
            {
                if (String.IsNullOrEmpty(uid))
                {
                    continue;
                }
                Beyondbit.BUA.Client.User _u = null;
                try
                {
                    _u = us.GetUserInfo(uid);
                }
                catch (Exception ex)
                {
                    result["Msg"] += uid + ex.Message;
                    continue;
                }

                SMC_BUAUserSyncToInside log = new SMC_BUAUserSyncToInside();
                log.sync_bat_no = batNo;

                try
                {
                    log.sync_status = true;
                    log.sync_time = DateTime.Now;
                    log.sync_user_name = "";
                    log.sync_user_uid = "";
                    log.user_name = _u.UserFullName;
                    log.user_uid = _u.UserUid;
                    log.description = "同步成功";
                    log.busi_id = buaSyncInsideDao.GetMaxId() + 1;
                    SMC_UnitDao unitDao = new SMC_UnitDao(AppConfig.statisticDBKey);

                    SMC_User u = null;
                    u = userDao.GetUser(_u.UserUid);
                    if (u == null)
                    {
                        u = new SMC_User();
                        u.U_NAME = _u.UserFullName;
                        u.U_PASSWORD = _u.UserPassword;
                        u.U_UID = _u.UserUid;
                        int id = userDao.GetMaxId() + 1;
                        u.U_ID = id;
                        string unitCode = os.GetUnitCode(ObjectType.User, u.U_UID);
                        Org unitOrg = os.GetOrgBaseInfo(ObjectType.Org, unitCode);
                        u.U_UNITCODE = unitCode;

                        //List<KeyValuePair<string, string>> pars = new List<KeyValuePair<string,string>>();
                        //pars.Add(new KeyValuePair<string, string>("unit_id",unitCode));
                        SMC_Unit unit = unitDao.Get(unitCode);
                        if (unit == null)
                        {
                            unit = new SMC_Unit();
                            unit.Unit_ID = unitCode;
                            unit.Unit_Name = unitOrg.OrgName;
                            unit.Unit_Sequence = 0;
                            unit.Unit_UpdateTime = DateTime.Now;
                            unit.Unit_CreatedTime = DateTime.Now;
                            unit.Upper_Unit_ID = "";
                            unit.Unit_Path = unitCode;
                            unitDao.Insert(unit);
                        }
                        u.u_unitname = unitOrg.OrgName;
                        u.U_CREATEDDATE = DateTime.Now;
                        u.u_enable_status = p.ConfigValue == "1" ? UserEnabledStatus.Enabled : UserEnabledStatus.UnAuthed;
                        u.u_auth_submit_time = DateTime.Now;
                        u.u_need_sync = false;
                        userDao.Insert(u);
                        userDao.UpdateMaxId();
                    }
                    else
                    {
                        u.U_NAME = _u.UserFullName;
                        u.U_PASSWORD = _u.UserPassword;
                        u.U_CREATEDDATE = DateTime.Now;
                        string unitCode = os.GetUnitCode(ObjectType.User, u.U_UID);
                        Org unitOrg = os.GetOrgBaseInfo(ObjectType.Org, unitCode);

                        //List<KeyValuePair<string, string>> pars = new List<KeyValuePair<string, string>>();
                        //pars.Add(new KeyValuePair<string, string>("unit_id", unitCode));
                        SMC_Unit unit = unitDao.Get(unitCode);
                        if (unit == null)
                        {
                            unit = new SMC_Unit();
                            unit.Unit_ID = unitCode;
                            unit.Unit_Name = unitOrg.OrgName;
                            unit.Unit_Sequence = 0;
                            unit.Unit_UpdateTime = DateTime.Now;
                            unit.Unit_CreatedTime = DateTime.Now;
                            unit.Upper_Unit_ID = "";
                            unit.Unit_Path = unitCode;
                            unitDao.Insert(unit);
                        }

                        u.u_unitname = unitOrg.OrgName;
                        u.U_UNITCODE = unitCode;
                        u.u_enable_status = p.ConfigValue == "1" ? UserEnabledStatus.Enabled : UserEnabledStatus.UnAuthed;
                        u.u_auth_submit_time = DateTime.Now;
                        u.u_need_sync = false;
                        u.u_update_time = DateTime.Now;
                        userDao.Update(u);
                    }

                }
                catch (Exception ex)
                {
                    log.sync_status = false;
                    log.description = "同步失败,原因可能是:" + ex.Message + "。\r\nStackTrace:\r\n" + ex.StackTrace;
                    if (result != null)
                    {
                        result["IsSuccess"] = false;
                        result["Msg"] += log.description;
                    }
                }

                try
                {
                    buaSyncInsideDao.Insert(log);
                    buaSyncInsideDao.UpdateMaxId();
                }
                catch (Exception ex)
                {
                }
            }
        }
        public Service.ApplicationCenterWS.SMC_Unit CopySMC_Unit(SMC_Unit unit)
        {
            Service.ApplicationCenterWS.SMC_Unit entity = new Service.ApplicationCenterWS.SMC_Unit();
            entity.Unit_CreatedTime = unit.Unit_CreatedTime;
            entity.Unit_CreatedUser = unit.Unit_CreatedUser;
            entity.Unit_Demo = unit.Unit_Demo;
            entity.Unit_ID = unit.Unit_ID;
            entity.Unit_Name = unit.Unit_Name;
            entity.Unit_Path = unit.Unit_Path;
            entity.Unit_Sequence = unit.Unit_Sequence;
            entity.Unit_UpdateTime = unit.Unit_UpdateTime;
            entity.Unit_UpdateUser = unit.Unit_UpdateUser;
            entity.Upper_Unit_ID = unit.Upper_Unit_ID;

            return entity;
        }
        private void parseChildTreeData(Hashtable pHash, SMC_Unit parent_unit, SMC_UnitDao unitDao, SMC_UserListDao ulDao, List<Hashtable> objs, int RoleId)
        {
            IList<SMC_UserList> users = ulDao.QueryUserListByUnitID(parent_unit.Unit_ID);
            foreach (SMC_UserList u in users)
            {
                Hashtable uhash = new Hashtable();
                uhash["id"] = "u_" + u.UL_ID;
                uhash["name"] = u.UL_Name;
                uhash["tp"] = "user";
                uhash["checked"] = ulDao.IsUserListInRole(u.UL_ID, RoleId);
                objs.Add(uhash);
                pHash["open"] = true;
            }

            IList<SMC_Unit> units = unitDao.QueryChildUnitsByUnitID(parent_unit.Unit_ID, -1);
            if (units != null && units.Count > 0)
            {
                //QueryUserListByUnitID

                foreach (SMC_Unit unit in units)
                {
                    Hashtable hash = new Hashtable();
                    hash["id"] = unit.Unit_ID;
                    hash["name"] = unit.Unit_Name;
                    hash["tp"] = "unit";
                    objs.Add(hash);

                    List<Hashtable> _objs = new List<Hashtable>();
                    parseChildTreeData(hash, unit, unitDao, ulDao, _objs, RoleId);

                }

            }

            if (objs.Count > 0)
            {
                pHash["children"] = objs;
            }
        }