/// <summary> /// 删除多个对象 /// </summary> /// <param name="IDs">需要删除数据的ID,使用“,”分隔</param> public void Del(string IDs) { using (var factory = new BaseAccess()) { try { foreach (var id in IDs.Split(',')) { var model = factory.GetSingle <OrganizationEntity>(id); if (model != null) { //获取所有子节点 List <OrganizationEntity> childrens = new List <OrganizationEntity>() { model }; childrens = GetChilds(factory, model.ID, childrens); foreach (var c in childrens) { factory.Delete <OrganizationEntity>(c, false); } } } factory.Commit(); //清理缓存 CacheshipFactory.Instance.ClearOrganCache(); } catch (Exception ex) { factory.Rollback(); throw ex; } } }
/// <summary> /// 更新 /// </summary> /// <param name="entity"></param> public void Edit(Dictionary_U model) { using (var factory = new BaseAccess()) { try { if (!string.IsNullOrEmpty(model.ID)) { var model_old = factory.GetSingle <Sys_DictionaryEntity>(model.ID); model_old = model.Adapter <Sys_DictionaryEntity>(model_old);//将页面对象的属性转换到数据库对象modle中 factory.Update <Sys_DictionaryEntity>(model_old, false); if ((model.IsCache ?? 0) != (model.IsCache_Old ?? 0)) { //更新其他所有DictType的IsCache string type = model_old.DictType; factory.Update <Sys_DictionaryEntity>(model_old, new string[] { "IsCache" }, Specification <Sys_DictionaryEntity> .Create(c => c.DictType == model_old.DictType && c.ParDictID != Define._TOPPARENTID), false); } factory.Commit(); //清除缓存 if ((model_old.IsCache ?? 0) == 1) { Manage.Open.CacheshipFactory.Instance.ClearDictionaryCache(model_old.DictType); } } } catch (Exception ex) { factory.Rollback(); throw ex; } } }
/// <summary> /// 设置角色菜单 /// </summary> /// <param name="RoleID"></param> /// <param name="MenuIDs"></param> public void SetRoleMenus(string RoleID, List <string> MenuIDs) { using (var factory = new BaseAccess()) { try { if (!string.IsNullOrEmpty(RoleID)) { var menus_old = factory.GetAll <MenuRoleEntity>(Specification <MenuRoleEntity> .Create(c => c.RoleID == RoleID)); factory.Delete <MenuRoleEntity>(menus_old, false); if (MenuIDs != null) { foreach (string id in MenuIDs) { var entity = new MenuRoleEntity() { ID = Guid.NewGuid().ToString(), RoleID = RoleID, MenuID = id }; factory.Insert <MenuRoleEntity>(entity, false); } } factory.Commit(); } } catch (Exception ex) { factory.Rollback(); throw ex; } } }
/// <summary> /// 设置为主分组 /// </summary> /// <param name="OrganID"></param> /// <param name="UserID"></param> public void SetDefaultOrgan(string OrganID, string UserID) { using (var factory = new BaseAccess()) { try { //获取用户的所有分组 var UserAllOrgan = factory.GetAll <UserOrganizationEntity>(Specification <UserOrganizationEntity> .Create(c => c.UserID == UserID)); var defaultOrgan = UserAllOrgan.Where(c => c.IsDefault == (int)YesNo.Yes).ToList() ?? new List <UserOrganizationEntity>(); var setOrgan = UserAllOrgan.Where(w => w.OrganizationID == OrganID).FirstOrDefault(); if (setOrgan != null) { //取消所有原主分组(做荣誉操作,正常情况下不会有多个主分组) foreach (var m in defaultOrgan) { m.IsDefault = (int)YesNo.No; factory.Update <UserOrganizationEntity>(m, false); } //设置需要设置的分组为主分组 setOrgan.IsDefault = (int)YesNo.Yes; factory.Update <UserOrganizationEntity>(setOrgan, false); factory.Commit(); } } catch (Exception e) { factory.Rollback(); throw e; } } }
/// <summary> /// 编辑用户 /// </summary> /// <param name="user"></param> /// <returns></returns> public bool EditUser(User_U user) { using (var factory = new BaseAccess(base._DBConfigPath)) { try { var model = factory.Single <UserEntity>(user.ID); model = user.Adapter <UserEntity>(model);//将页面对象user的属性转换到数据库对象modle中 factory.Update <UserEntity>(model, false); //处理用户分组 var userDep = factory.Single <UserOrganizationEntity>(Specification <UserOrganizationEntity> .Create(c => c.UserID == user.ID && c.IsDefault == 1)); if (userDep.OrganizationID != user.UserDeptID) { userDep.OrganizationID = user.UserDeptID; factory.Update <UserOrganizationEntity>(userDep, false); } factory.Commit(); //清理缓存 Manage.Open.CacheshipFactory.Instance.ClearSSOUserCache(user.ID); return(true); } catch (Exception ex) { factory.Rollback(); return(false); } } }
/// <summary> /// 修改缓存托盘集合 /// </summary> /// <param name="cacheTrayList"></param> public void UpdateCacheTableList(List <CacheStackTray> cacheTrayList) { using (BaseAccess access = new BaseAccess(true)) { try { access.Open(); access.BeginTransaction(); foreach (CacheStackTray entity in cacheTrayList) { string updateSql = string.Format("UPDATE {0} SET Barcode='{1}',Batch={2} WHERE Id ={3}", lineDevice.PrefixTable + "CacheStackTray", entity.Barcode, entity.Batch, entity.Id); access.ExecuteNonQuery(updateSql); //access.Update(entity, new string[] { CacheStackTray.ID }, CacheStackTray.BARCODE, CacheStackTray.BATCH); } access.Commit(); } catch (Exception ex) { access.Rollback(); PrintInfo.I(ex.Message); Console.WriteLine(ex.Message); } finally { access.Close(); } } }
/// <summary> /// 添加用户 /// </summary> /// <param name="user"></param> /// <returns></returns> public bool AddUser(User_I user) { using (var factory = new BaseAccess(base._DBConfigPath)) { try { //user.UserPassword = (user.UserLoginName + Define._PASSWORDSPLIT + appConfig.DefaultPassword).ToMD5(); user.UserPassword = appConfig.DefaultPassword.ToMD5(); user.ID = Guid.NewGuid().ToString(); var userDep = new UserOrganizationEntity() { ID = Guid.NewGuid().ToString(), UserID = user.ID, OrganizationID = user.UserDeptID, IsDefault = 1 }; var model = user.Adapter <UserEntity>(new UserEntity()); factory.Insert <UserEntity>(model, false); factory.Insert <UserOrganizationEntity>(userDep, false); factory.Commit(); return(true); } catch (Exception ex) { factory.Rollback(); return(false); } } }
public static void CreateTable(string prefixTable) { using (BaseAccess access = new BaseAccess(true)) { try { access.Open(); access.BeginTransaction(); //创建缓存托盘表 access.ExecuteNonQuery(GetCacheStackTraySql(prefixTable)); //创建托盘详情表 access.ExecuteNonQuery(GetStackTrayFlowSql(prefixTable)); //创建托盘表 access.ExecuteNonQuery(GetStackTraysSql(prefixTable)); //创建注册托盘表 //access.ExecuteNonQuery(GetRegisterTraySql(prefixTable)); //创建用户事件日志表 access.ExecuteNonQuery(GetUserEventLogSql(prefixTable)); access.Commit(); } catch (Exception ex) { access.Rollback(); throw new Exception("创建表失败:" + ex.Message); } finally { access.Close(); } } }
//更新 public Boolean UpdateConfiguration(Configuration_U model) { using (var factory = new BaseAccess()) { if (!string.IsNullOrEmpty(model.USERID)) { var spec = Specification <SYS_ConfigurationEntity> .Create(c => c.USERID == model.USERID); try { var model_old = factory.GetSingle <SYS_ConfigurationEntity>(spec); string id = model_old.ID; model_old = model.Adapter <SYS_ConfigurationEntity>(model_old);//将页面对象的属性转换到数据库对象modle中 model_old.ID = id; factory.Update <SYS_ConfigurationEntity>(model_old, false); factory.Commit(); return(true); } catch (Exception ex) { factory.Rollback(); return(false); } } return(false); } }
/// <summary> /// 根据当前登陆用户获取用户配置信息 /// 如果没有配置信息则 创建一天空的配置信息 /// </summary> /// <param name="UserId"></param> /// <returns></returns> public Configuration_S GetConfigurationByUserId(string UserId) { using (var factory = new BaseAccess()) { var spec = Specification <SYS_ConfigurationEntity> .Create(c => c.USERID == UserId); try { if (factory.IsExists <SYS_ConfigurationEntity>(spec)) { var entity = factory.GetSingle <SYS_ConfigurationEntity>(spec); return(entity.Adapter <Configuration_S>(new Configuration_S())); } else { var entity = new SYS_ConfigurationEntity(); entity.ID = Guid.NewGuid().ToString(); entity.USERID = UserId; factory.Insert <SYS_ConfigurationEntity>(entity, false); factory.Commit(); return(null); } } catch (Exception ex) { factory.Rollback(); return(null); } } }
/// <summary> /// 保存InStack为2的缓存数据 /// </summary> private void SaveCacheData() { //if (trayCodeList.Count < 2) //{ // PrintInfo.I("托盘个数小于2个,当前{0}个", trayCodeList.Count); // BindDataResult(CommandValue.TRAY_COUNT_ERROR); // return; //} // 此时叠盘机中应该只有一个托盘 // 保存叠盘机堆叠InStack为2的所有托盘数据 using (BaseAccess access = new BaseAccess(true)) { try { access.Open(); access.BeginTransaction(); SaveStackFlowTray(trayCodeList[trayCodeList.Count - 2], access); SaveStackTrays(trayCodeList, access, "2"); DeleteCacheData(access, "2"); //清空托盘list中InStack为2的 int count = trayCodeList.Count; for (int i = count - 1; i > -1; i--) { if (trayCodeList[i].InStack == 2) { trayCodeList.RemoveAt(i); } } access.Commit(); this.mixBatch = false; WriteRunningState("Running", "处理完成", ServicesConfig.WorkStationGroups[0].Key); } catch (Exception ex) { access.Rollback(); WriteRunningState("Error", "保存缓存异常", ServicesConfig.WorkStationGroups[0].Key); PrintInfo.I("异常:{0}", ex.Message); } } BindDataResult(CommandValue.BIND_COMPLETE); }
/// <summary> /// 删除多个对象 /// </summary> /// <param name="IDs">需要删除数据的ID,使用“,”分隔</param> public void Del(string IDs) { using (var factory = new BaseAccess()) { try { foreach (var id in IDs.Split(',')) { var model = factory.GetSingle <Sys_DictionaryEntity>(id); if (model != null) { //获取所有子节点 List <Sys_DictionaryEntity> childrens = new List <Sys_DictionaryEntity>() { model }; childrens = GetChilds(factory, model.ID, childrens); foreach (var c in childrens) { //清除缓存 if ((c.IsCache ?? 0) == 1) { Manage.Open.CacheshipFactory.Instance.ClearDictionaryCache(c.DictType); } factory.Delete <Sys_DictionaryEntity>(c, false); } } } factory.Commit(); } catch (Exception ex) { factory.Rollback(); throw ex; } } }
/// <summary> /// 保存所有缓存数据 /// </summary> private void SaveAllCacheData() { //if (trayCodeList.Count < 2 && type == "2") //{ // PrintInfo.I("托盘个数小于2个,当前{0}个", trayCodeList.Count); // BindDataResult(CommandValue.TRAY_COUNT_ERROR); // return; //} // 保存叠盘机堆叠的所有托盘数据 using (BaseAccess access = new BaseAccess(true)) { try { access.Open(); access.BeginTransaction(); SaveStackFlowTray(trayCodeList[trayCodeList.Count - 1], access); SaveStackTrays(trayCodeList, access, "1"); DeleteCacheData(access, "1"); //清空托盘list trayCodeList.Clear(); access.Commit(); this.mixBatch = false; trayCodeList.Clear(); WriteRunningState("Running", "处理完成", ServicesConfig.WorkStationGroups[0].Key); } catch (Exception ex) { access.Rollback(); WriteRunningState("Error", "保存缓存异常", ServicesConfig.WorkStationGroups[0].Key); PrintInfo.I("异常:{0}", ex.Message); } } //可以放行 BindDataResult(CommandValue.BIND_COMPLETE); }
/// <summary> /// 删除用户 /// </summary> /// <param name="IDs">用户ID,逗号“,”隔开</param> /// <returns></returns> public bool DelUsers(string IDs) { using (var factory = new BaseAccess(base._DBConfigPath)) { try { string[] userIDs = IDs.Split(','); factory.Delete <UserEntity>(userIDs, false); //循环删除用户分组 var userOrgans = factory.GetAll <UserOrganizationEntity>(Specification <UserOrganizationEntity> .Create(c => userIDs.Contains(c.UserID))); foreach (var userOrgan in userOrgans) { factory.Delete <UserOrganizationEntity>(userOrgan, false); } //循环删除用户角色 var userRoles = factory.GetAll <UserRoleEntity>(Specification <UserRoleEntity> .Create(c => userIDs.Contains(c.UserID))); foreach (var userRole in userRoles) { factory.Delete <UserRoleEntity>(userRole, false); } factory.Commit(); //清理缓存 foreach (var id in userIDs) { Manage.Open.CacheshipFactory.Instance.ClearSSOUserCache(id); } return(true); } catch (Exception ex) { factory.Rollback(); return(false); } } }