private void 添加ToolStripMenuItem_Click(object sender, EventArgs e) { AreaSetting areaSetting = new AreaSetting(); if (areaSetting.ShowDialog() == DialogResult.OK) { if (_areas != null) { foreach (UserArea area in _areas) { if (area.Name == areaSetting.AreaName) { Helper.ShowMessageBox("提示", "已存在相同名称!"); return; } } UserArea command = new UserArea(areaSetting.AreaName); AddCommand(command); } else { UserArea command = new UserArea(areaSetting.AreaName); _areas.Add(command); RefreshAreaList(); } } }
public InvokeResult SetArea(string userId, string areaId) { InvokeResult result = new InvokeResult { Success = true }; try { List <IBatisNetBatchStatement> statements = new List <IBatisNetBatchStatement>(); UserArea ua = new UserArea { UserId = userId.ToGuid() }; statements.Add(new IBatisNetBatchStatement { StatementName = ua.GetDeleteMethodName(), ParameterObject = ua.ToStringObjectDictionary(false), Type = SqlExecuteType.DELETE }); ua.AreaId = areaId.ToGuid(); statements.Add(new IBatisNetBatchStatement { StatementName = ua.GetCreateMethodName(), ParameterObject = ua.ToStringObjectDictionary(false), Type = SqlExecuteType.INSERT }); BuilderFactory.DefaultBulder().ExecuteNativeSqlNoneQuery(statements); } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
/// <summary> /// Maps the GPO_USR_REGION_RANGE. /// </summary> /// <param name="reader">The reader.</param> /// <param name="rowNumber">The row number.</param> /// <returns></returns> private object MapGPO_USR_USER_AREA(IDataReader reader, int rowNumber) { UserArea user_area = new UserArea(); user_area.Id = Convert.ToString(reader["ID"]); user_area.AreaId = Convert.ToString(reader["AREA_ID"]); user_area.UserId = Convert.ToString(reader["USER_ID"]); return(user_area); }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { if (Helper.ShowMessageBox("确认", "确认删除此项?") == DialogResult.OK) { if (_areas != null && _areas.Count > 0 && _selectRowIndex != -1) { UserArea command = _areas[_selectRowIndex]; DeleteArea(command); } } }
public void DeleteArea(UserArea area) { lock (_lock) { if (_areas != null) { _areas.Remove(area); } RefreshAreaList(); } }
private UserArea AddUserAreaIfNotExists(IUserAreaDefinition userArea, UserArea dbUserArea) { if (dbUserArea == null) { dbUserArea = new UserArea(); dbUserArea.UserAreaCode = userArea.UserAreaCode; dbUserArea.Name = userArea.Name; _dbContext.UserAreas.Add(dbUserArea); } return(dbUserArea); }
private void 移ToolStripMenuItem_Click(object sender, EventArgs e) { if (_currentArea != _areas[_areas.Count - 1]) { int index = _areas.IndexOf(_currentArea); UserArea temp = new UserArea(_areas[index + 1].Name); temp.Actions = _areas[index + 1].Actions; _areas[index + 1] = _currentArea; _areas[index] = temp; RefreshAreaList(); } }
public void AddCommand(UserArea area) { lock (_lock) { if (_areas != null) { _areas.Add(area); } else { Helper.ShowMessageBox("添加失败!", "添加展区失败!"); } RefreshAreaList(); } }
private async Task <UserArea> GetUserAreaAsync(IUserAreaDefinition userArea) { var dbUserArea = await _dbContext .UserAreas .Where(a => a.UserAreaCode == userArea.UserAreaCode) .SingleOrDefaultAsync(); if (dbUserArea == null) { dbUserArea = new UserArea(); dbUserArea.UserAreaCode = userArea.UserAreaCode; dbUserArea.Name = userArea.Name; _dbContext.UserAreas.Add(dbUserArea); } return(dbUserArea); }
private void dbCommandList_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { _selectRowIndex = e.RowIndex; if (e.Clicks == 1 && e.Button == MouseButtons.Right && e.RowIndex >= 0) { contextMenuStrip.Show(Cursor.Position); } if (_selectRowIndex >= 0 && _currentArea != _areas[_selectRowIndex]) { _currentArea = _areas[_selectRowIndex]; if (OnCurrentAreaChanged != null) { OnCurrentAreaChanged(this, null); } dbAreaList.Rows[_selectRowIndex].Selected = true; } }
public async Task ExecuteAsync(EnsureUserAreaExistsCommand command, IExecutionContext executionContext) { var userArea = _userAreaRepository.GetByCode(command.UserAreaCode); EntityNotFoundException.ThrowIfNull(userArea, command.UserAreaCode); var dbUserArea = await _dbContext .UserAreas .SingleOrDefaultAsync(a => a.UserAreaCode == userArea.UserAreaCode); if (dbUserArea == null) { dbUserArea = new UserArea(); dbUserArea.UserAreaCode = userArea.UserAreaCode; dbUserArea.Name = userArea.Name; _dbContext.UserAreas.Add(dbUserArea); } }
public OperationResult SetUserArea(UserAreaModel model) { var entity = UserAreas.FirstOrDefault( t => t.UserId == model.UserId && t.AreaId == model.AreaId); if (entity == null) { entity = new UserArea { UserId = model.UserId, AreaId = model.AreaId, }; UserAreaRepository.Insert(entity); return(new OperationResult(OperationResultType.Success, "添加成功")); } else { return(new OperationResult(OperationResultType.Success, "已经存在")); } }
public void RefreshAreaList() { dbAreaList.Rows.Clear(); _currentArea = null; if (_areas != null) { foreach (UserArea area in _areas) { dbAreaList.Rows.Add(area.Name); } } if (dbAreaList.Rows.Count > 0) { dbAreaList.Rows[dbAreaList.Rows.Count - 1].Selected = true; _currentArea = _areas[dbAreaList.Rows.Count - 1]; } if (OnCurrentAreaChanged != null) { OnCurrentAreaChanged(this, null); } }
//加载配置 public List <UserArea> LoadConfig() { try { XmlDocument config = new XmlDocument(); config.Load(_configFile); XmlNode root = config.SelectSingleNode("Root"); #region LoadNormalCommand XmlNodeList areas = root.SelectNodes("Area"); _areas.Clear(); foreach (XmlNode area in areas) { string areaName = area.SelectSingleNode("AreaName").InnerText; UserArea tempArea = new UserArea(areaName); _areas.Add(tempArea); XmlNodeList actions = area.SelectNodes("Action"); foreach (XmlNode action in actions) { string actionName = action.SelectSingleNode("ActionName").InnerText; string actionReceiveData = action.SelectSingleNode("ActionReceiveData").InnerText; UserAction userAction = new UserAction(actionName, actionReceiveData); tempArea.Actions.Add(userAction); XmlNodeList operations = action.SelectNodes("Operation"); foreach (XmlNode operation in operations) { string operationName = operation.SelectSingleNode("OperationName").InnerText; string operationTypeString = operation.SelectSingleNode("OperationType").InnerText; CommunicationType operationType = (CommunicationType)Enum.Parse(typeof(CommunicationType), operationTypeString, true); XmlNode operationSetting = operation.SelectSingleNode("OperationSetting"); object setting = null; if (operationType == CommunicationType.Com) { ComSetting cs = new ComSetting(); cs.ComNumber = operationSetting.SelectSingleNode("ComNumber").InnerText; cs.BaudRate = int.Parse(operationSetting.SelectSingleNode("BaudRate").InnerText); cs.DataBits = int.Parse(operationSetting.SelectSingleNode("DataBit").InnerText); cs.StopBits = int.Parse(operationSetting.SelectSingleNode("StopBit").InnerText); cs.Parity = (Parity)Enum.Parse(typeof(Parity), operationSetting.SelectSingleNode("Parity").InnerText); setting = cs; } else if (operationType == CommunicationType.TCP || operationType == CommunicationType.UDP) { NetworkSetting ns = new NetworkSetting(); ns.Ip = operationSetting.SelectSingleNode("IP").InnerText; ns.Port = int.Parse(operationSetting.SelectSingleNode("Port").InnerText); setting = ns; } string dataTypeString = operation.SelectSingleNode("OperationDataType").InnerText; DataType dataType = (DataType)Enum.Parse(typeof(DataType), dataTypeString, true); string data = operation.SelectSingleNode("OperationData").InnerText; int time = int.Parse(operation.SelectSingleNode("OperationTime").InnerText); UserOperation userOperation = new UserOperation(operationName, operationType, dataType, setting, data, time); userAction.Operations.Add(userOperation); } } } return(_areas); #endregion } catch { Helper.ShowMessageBox("提示", "未找到配置文件!"); return(null); } }
private User MapAndAddUser(AddUserCommand command, IExecutionContext executionContext, Role role, IUserAreaDefinition userArea, UserArea dbUserArea) { var user = new User(); user.FirstName = command.FirstName.Trim(); user.LastName = command.LastName.Trim(); user.Email = command.Email; user.RequirePasswordChange = command.RequirePasswordChange; user.LastPasswordChangeDate = executionContext.ExecutionDate; user.CreateDate = executionContext.ExecutionDate; user.Role = role; user.UserArea = dbUserArea; if (userArea.AllowPasswordLogin) { var password = command.GeneratePassword ? _passwordGenerationService.Generate() : command.Password; var hashResult = _passwordCryptographyService.CreateHash(password); user.Password = hashResult.Hash; user.PasswordEncryptionVersion = hashResult.HashVersion; } if (userArea.UseEmailAsUsername) { user.Username = command.Email; } else { user.Username = command.Username.Trim(); } _dbContext.Users.Add(user); return(user); }
public ModelInvokeResult <LisenceUserPK> Update(string strUserId, LisenceUser lisenceUser) { ModelInvokeResult <LisenceUserPK> result = new ModelInvokeResult <LisenceUserPK> { Success = true }; try { List <IBatisNetBatchStatement> statements0 = new List <IBatisNetBatchStatement>(); List <IBatisNetBatchStatement> statements = new List <IBatisNetBatchStatement>(); Guid?_UserId = strUserId.ToGuid(); if (_UserId == null) { result.Success = false; result.ErrorCode = 59996; return(result); } lisenceUser.UserId = _UserId; /***********************begin 自定义代码*******************/ lisenceUser.OperatedBy = NormalSession.UserId.ToGuid(); lisenceUser.OperatedOn = DateTime.Now; /***********************end 自定义代码*********************/ /***********************begin 自定义代码*******************/ //解析 List <string> groupIds = new List <string>(); List <string> areaIds = new List <string>(); string areaId = null; string[] parts = lisenceUser.UserType.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (parts[0] == GlobalManager.DIKey_01001_NormalUser) { lisenceUser.UserType = parts[0]; groupIds.AddRange(parts[1].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); areaIds.AddRange(parts[2].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); areaId = parts[3]; } //绑定用户角色 if (groupIds.Count > 0) { GroupMember gm = new GroupMember() { UserId = lisenceUser.UserId }; statements.Add(new IBatisNetBatchStatement { StatementName = gm.GetDeleteMethodName(), ParameterObject = gm.ToStringObjectDictionary(false), Type = SqlExecuteType.DELETE }); foreach (string groupId in groupIds) { gm.GroupId = Guid.Parse(groupId); gm.UserId = lisenceUser.UserId; gm.OperatedBy = NormalSession.UserId.ToGuid(); gm.OperatedOn = DateTime.Now; statements.Add(new IBatisNetBatchStatement { StatementName = gm.GetCreateMethodName(), ParameterObject = gm.ToStringObjectDictionary(false), Type = SqlExecuteType.INSERT }); } } //绑定用户辖区 if (areaIds.Count > 0) { UserArea ua = new UserArea() { UserId = lisenceUser.UserId }; statements.Add(new IBatisNetBatchStatement { StatementName = ua.GetDeleteMethodName(), ParameterObject = ua.ToStringObjectDictionary(false), Type = SqlExecuteType.DELETE }); foreach (string itemId in areaIds) { ua.AreaId = itemId.ToGuid(); ua.UserId = lisenceUser.UserId; ua.OperatedBy = NormalSession.UserId.ToGuid(); ua.OperatedOn = DateTime.Now; statements.Add(new IBatisNetBatchStatement { StatementName = ua.GetCreateMethodName(), ParameterObject = ua.ToStringObjectDictionary(false), Type = SqlExecuteType.INSERT }); } } User user = new User() { UserId = lisenceUser.UserId, UserCode = lisenceUser.UserCode, UserName = lisenceUser.UserName, UserType = lisenceUser.UserType, PasswordHash = lisenceUser.PasswordHash, Gender = "N", CreatedBy = NormalSession.UserId.ToGuid(), CreatedOn = DateTime.Now, OperatedBy = NormalSession.UserId.ToGuid(), OperatedOn = DateTime.Now, Area1 = areaId }; statements.Add(new IBatisNetBatchStatement { StatementName = user.GetUpdateMethodName(), ParameterObject = user.ToStringObjectDictionary(false), Type = SqlExecuteType.UPDATE }); /***********************end 自定义代码*********************/ BuilderFactory.DefaultBulder(GetHttpHeader(GlobalManager.ConnectIdKey)).ExecuteNativeSqlNoneQuery(statements); var param0 = lisenceUser.ToStringObjectDictionary(false); if (!string.IsNullOrEmpty(areaId)) { param0["Area1"] = areaId; var rows = BuilderFactory.DefaultBulder(GetHttpHeader(GlobalManager.ConnectIdKey)).List <DictItemEx>("CTE_AreaCityProvice_List", new { ItemId = areaId }.ToStringObjectDictionary()); var city = rows.Where(item => item.Levels == 2).FirstOrDefault(); if (city != null) { param0["CityId"] = city.ItemId; } } statements0.Add(new IBatisNetBatchStatement { StatementName = lisenceUser.GetUpdateMethodName(), ParameterObject = param0, Type = SqlExecuteType.UPDATE }); BuilderFactory.DefaultBulder().ExecuteNativeSqlNoneQuery(statements0); result.instance = new LisenceUserPK { UserId = _UserId }; } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
private User MapAndAddUser(AddMasterCofoundryUserCommand command, IExecutionContext executionContext, Role superUserRole, UserArea userArea) { var user = new User(); user.FirstName = command.FirstName; user.LastName = command.LastName; user.Username = command.Email; user.Email = command.Email; user.RequirePasswordChange = false; user.LastPasswordChangeDate = executionContext.ExecutionDate; user.CreateDate = executionContext.ExecutionDate; user.Role = superUserRole; var hashResult = _passwordCryptographyService.CreateHash(command.Password); user.Password = hashResult.Hash; user.PasswordEncryptionVersion = (int)hashResult.EncryptionVersion; user.UserArea = userArea; EntityNotFoundException.ThrowIfNull(user.UserArea, CofoundryAdminUserArea.AreaCode); _dbContext.Users.Add(user); return(user); }
//保存配置(包含时间轴配置) public void SaveConfig(List <UserArea> p_areas, List <UserAction> p_shaft_actions) { if (p_areas != null && p_areas.Count > 0) { XmlDocument config = new XmlDocument(); XmlNode root = config.CreateNode(XmlNodeType.Element, "Root", null); config.AppendChild(root); #region NormalCommands for (int i = 0; i < p_areas.Count; i++) { Console.WriteLine(i); UserArea currentArea = p_areas[i]; XmlNode area = config.CreateNode(XmlNodeType.Element, "Area", null); XmlNode areaname = config.CreateNode(XmlNodeType.Element, "AreaName", null); areaname.InnerText = currentArea.Name; area.AppendChild(areaname); for (int count_action = 0; count_action < currentArea.Actions.Count; count_action++) { UserAction temp = currentArea.Actions[count_action]; XmlNode action = config.CreateNode(XmlNodeType.Element, "Action", null); XmlElement actionName = config.CreateElement("ActionName"); actionName.InnerText = temp.Name; XmlElement receiveData = config.CreateElement("ActionReceiveData"); receiveData.InnerText = temp.ReceiveCommand; action.AppendChild(actionName); action.AppendChild(receiveData); for (int count_opreation = 0; count_opreation < temp.Operations.Count; count_opreation++) { UserOperation operation = temp.Operations[count_opreation]; XmlNode operationNode = config.CreateNode(XmlNodeType.Element, "Operation", null); XmlNode operationName = config.CreateNode(XmlNodeType.Element, "OperationName", null); operationName.InnerText = operation.Name; XmlNode operationType = config.CreateNode(XmlNodeType.Element, "OperationType", null); operationType.InnerText = operation.OpreationType.ToString(); XmlNode operationDataType = config.CreateNode(XmlNodeType.Element, "OperationDataType", null); operationDataType.InnerText = operation.DataType.ToString(); XmlNode operationData = config.CreateNode(XmlNodeType.Element, "OperationData", null); if (operation.DataType == DataType.Hex) { operationData.InnerText = operation.Data.Replace(" ", "").Trim(); } else { operationData.InnerText = operation.Data; } XmlNode operationTime = config.CreateNode(XmlNodeType.Element, "OperationTime", null); operationTime.InnerText = operation.DelayTime.ToString(); XmlNode operationSetting = config.CreateNode(XmlNodeType.Element, "OperationSetting", null); if (operation.Setting as ComSetting != null) { SaveComSetting(config, operation, operationSetting); } else if (operation.Setting as NetworkSetting != null) { SaveIPSetting(config, operation, operationSetting); } operationNode.AppendChild(operationName); operationNode.AppendChild(operationType); operationNode.AppendChild(operationDataType); operationNode.AppendChild(operationData); operationNode.AppendChild(operationTime); operationNode.AppendChild(operationSetting); action.AppendChild(operationNode); } area.AppendChild(action); } root.AppendChild(area); } #endregion if (p_shaft_actions != null && p_shaft_actions.Count > 0) { #region TimeShaft XmlNode timeShaft = config.CreateNode(XmlNodeType.Element, "TimeShaft", null); root.AppendChild(timeShaft); for (int i = 0; i < p_shaft_actions.Count; i++) { XmlNode action = config.CreateNode(XmlNodeType.Element, "Action", null); timeShaft.AppendChild(action); UserAction temp = _shaft_actions[i]; XmlElement actionName = config.CreateElement("ActionName"); actionName.InnerText = temp.Name; XmlElement receiveData = config.CreateElement("ActionReceiveData"); receiveData.InnerText = temp.ReceiveCommand; action.AppendChild(actionName); action.AppendChild(receiveData); for (int count_opreation = 0; count_opreation < temp.Operations.Count; count_opreation++) { UserOperation operation = temp.Operations[count_opreation]; XmlNode operationNode = config.CreateNode(XmlNodeType.Element, "Operation", null); XmlNode operationName = config.CreateNode(XmlNodeType.Element, "OperationName", null); operationName.InnerText = operation.Name; XmlNode operationType = config.CreateNode(XmlNodeType.Element, "OperationType", null); operationType.InnerText = operation.OpreationType.ToString(); XmlNode operationDataType = config.CreateNode(XmlNodeType.Element, "OperationDataType", null); operationDataType.InnerText = operation.DataType.ToString(); XmlNode operationData = config.CreateNode(XmlNodeType.Element, "OperationData", null); operationData.InnerText = operation.Data; XmlNode operationTime = config.CreateNode(XmlNodeType.Element, "OperationTime", null); operationTime.InnerText = operation.DelayTime.ToString(); XmlNode operationSetting = config.CreateNode(XmlNodeType.Element, "OperationSetting", null); if (operation.Setting as ComSetting != null) { SaveComSetting(config, operation, operationSetting); } else if (operation.Setting as NetworkSetting != null) { SaveIPSetting(config, operation, operationSetting); } operationNode.AppendChild(operationName); operationNode.AppendChild(operationType); operationNode.AppendChild(operationDataType); operationNode.AppendChild(operationData); operationNode.AppendChild(operationTime); operationNode.AppendChild(operationSetting); action.AppendChild(operationNode); } } root.AppendChild(timeShaft); #endregion } config.Save(_configFile); } }