Ejemplo n.º 1
0
        public virtual bool InsertOrUpdate(SMC_Unit unit)
        {
            try
            {
                int i = 0;
                if (SMC_UnitDao.Get(unit.Unit_ID) == null)
                {
                    //i = SMC_UnitDao.Insert(unit);
                    SMC_AutoTableIDDao autoDao = new SMC_AutoTableIDDao(AppConfig.statisticDBKey);
                    //if (autoDao.HasMaxID("SMC_Unit"))
                    //{
                    //    int max_id = autoDao.GetMaxID("SMC_Unit");
                    //    unit.Unit_ID = max_id + 1;
                    //}
                    //else
                    //{
                    //    unit.Unit_ID = 1;
                    //}
                    Beyondbit.BUA.Client.Org org = new Beyondbit.BUA.Client.Org();
                    org.OrgName = unit.Unit_Name;
                    org.OrgType = "Unit_Org";

                    Beyondbit.BUA.Client.IOrgService os = Beyondbit.BUA.Client.ServiceFactory.Instance().GetOrgService();

                    if (String.IsNullOrEmpty(unit.Upper_Unit_ID))
                    {
                        Beyondbit.BUA.Client.Org topOrg = null;
                        try
                        {
                            topOrg = os.GetTopOrg();
                        }
                        catch (Exception ex)
                        {
                            throw new BOException("调用统一授权接口失败:" + ex.Message, ex);
                        }
                        org.ParentOrgCode = topOrg.OrgCode;
                        //org.OrgCode = NPinyin.Pinyin.GetInitials(unit.Unit_Name, System.Text.Encoding.UTF8);
                        org.OrgCode        = "smc_" + NPinyin.Pinyin.GetInitials(unit.Unit_Name, System.Text.Encoding.UTF8);
                        unit.Upper_Unit_ID = "";
                    }
                    else
                    {
                        org.ParentOrgCode = unit.Upper_Unit_ID;
                        //org.OrgCode = unit.Upper_Unit_ID + "_" + NPinyin.Pinyin.GetInitials(unit.Unit_Name, System.Text.Encoding.UTF8);
                        org.OrgCode = "smc_" + NPinyin.Pinyin.GetInitials(unit.Unit_Name, System.Text.Encoding.UTF8);
                    }

                    try
                    {
                        os.AddOrg(org);
                    }
                    catch (Exception ex)
                    {
                        throw new BOException("调用统一授权借口失败:" + ex.Message, ex);
                    }

                    unit.Unit_ID = org.OrgCode;

                    try
                    {
                        i = SMC_UnitDao.Insert(unit);
                    }
                    catch (Exception ex)
                    {
                        throw new BOException("调用方法InsertOrUpdate失败:" + ex.Message, ex);
                    }
                    if (true)
                    {
                        //autoDao.UpdateMaxID("SMC_Unit");
                    }
                }
                else
                {
                    Beyondbit.BUA.Client.IOrgService os  = Beyondbit.BUA.Client.ServiceFactory.Instance().GetOrgService();
                    Beyondbit.BUA.Client.Org         org = os.GetOrgBaseInfo(Beyondbit.BUA.Client.ObjectType.Org, unit.Unit_ID);
                    org.OrgName = unit.Unit_Name;
                    os.ModiOrg(org);
                    unit.Unit_UpdateTime = DateTime.Now;

                    i = SMC_UnitDao.Update(unit);
                }

                return(true);
            }
            catch (DalException ex)
            {
                throw new BOException("调用方法InsertOrUpdate失败", ex);
            }
        }
Ejemplo n.º 2
0
        public ActionResult DelUnit(string unit_id)
        {
            JsonReturnMessages data = new JsonReturnMessages()
            {
                IsSuccess = true, Msg = "操作成功"
            };
            SMC_Unit unit = BoFactory.GetSMC_UnitBo.Get(unit_id);

            if (unit != null)
            {
                //判断是否被关联引用
                PageView view = new PageView();
                view.PageIndex = 0;
                view.PageSize  = 15;

                //看是否有下级组织机构
                var units = BoFactory.GetSMC_UnitBo.QueryUnitByUpperUnitCode(view, unit_id);
                if (units.total > 0)
                {
                    data.IsSuccess = false;
                    data.Msg       = "该组织存在下级组织,请先删除下级组织后再执行此操作!";
                    return(Json(data));
                }

                var rel = BoFactory.GetSMC_RoleBo.QueryRolesByUnitID(view, unit_id);
                if (rel.total > 0)
                {
                    data.IsSuccess = false;
                    data.Msg       = "有角色的组织不能删除,请先删除组织下的角色后再执行此操作!";
                    return(Json(data));
                }
                else
                {
                    rel = BoFactory.GetSMC_UserListBo.QueryUserListByUnitID(view, unit_id);
                    if (rel.total > 0)
                    {
                        data.IsSuccess = false;
                        data.Msg       = "有用户的组织不能删除,请先删除组织下的用户后再执行此操作!";
                        return(Json(data));
                    }
                }
            }
            else
            {
                data.IsSuccess = false;
                data.Msg       = "组织不存在";
            }

            try
            {
                //从同意授权
                Beyondbit.BUA.Client.IOrgService os = Beyondbit.BUA.Client.ServiceFactory.Instance().GetOrgService();
                os.DelOrg(unit_id);
            }
            catch (Exception e)
            {
                //ata.IsSuccess = false;
                //data.Msg = e.Message;
            }

            if (unit != null)
            {
                BoFactory.GetSMC_UnitBo.Delete(unit);
            }

            return(Json(data));
        }