Exemplo n.º 1
0
        private void toolAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (AddParent())
            {
                // 字典的实体类
                DataDictDto dto = new DataDictDto();
                dto.FieldTypeName     = slueditField.EditValue.ToString();
                dto.FieldTypeSerialNo = gvDataDict.RowCount;

                // 字典编辑对话框
                FrmDataDictInfo frmInfo = new FrmDataDictInfo();
                frmInfo.Tag         = "ADD";
                frmInfo.dataDictDto = dto;

                if (frmInfo.ShowDialog() == DialogResult.OK)
                {
                    // 更新数据库
                    UpdateInfo();

                    if (slueditField.Enabled)
                    {
                        slueditField.Enabled = false;
                    }
                }
            }

            // 设置当前状态为“新增”
            ctrlPanel.Tag = "ADD";
        }
        /// <summary>
        /// 获取单个实体
        /// </summary>
        /// <param name="DataType">父级值</param>
        /// <param name="ItemId">主键值</param>
        /// <returns></returns>
        public DataDictDto GetEntityByDataTypeAndItemId(string DataType, string ItemId)
        {
            var DataResult = new DataDictDto();

            using (var db = _dbContext.GetIntance())
            {
                DataResult = db.Queryable <DataDictEntity>().Where(de => de.DeleteMark == 1 && de.DataType == DataType && de.ItemCode == ItemId).OrderBy(de => de.SortCode)
                             .Select(de => new DataDictDto
                {
                    CRowId         = de.CRowId,
                    DataType       = de.DataType,
                    ItemCode       = de.ItemCode,
                    ItemName       = de.ItemName,
                    Remark         = de.Remark,
                    SortCode       = de.SortCode,
                    CreateDate     = de.CreateDate,
                    CreateUserId   = de.CreateUserId,
                    CreateUserName = de.CreateUserName,
                    DeleteMark     = de.DeleteMark,
                    ModifyDate     = de.ModifyDate,
                    ModifyUserId   = de.ModifyUserId,
                    ModifyUserName = de.ModifyUserName
                }).ToList().SingleOrDefault();
            }
            return(DataResult);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加纪录
        /// </summary>
        /// <param name="dto"></param>
        private bool Add(DataDictDto dto)
        {
            //int recordCnt = PropertyHelper.DataDictItems.Count<DataDictDto>(item => item.FieldTypeName == dto.FieldTypeName
            //                                              && item.FieldTypeValue == dto.FieldTypeValue);
            //if (recordCnt > 0)
            //{
            //    MessageUtil.ShowWarning("重复的条目值,请重新输入!");

            //    return false;
            //}

            //try
            //{
            //    CallerFactory.Instance.GetService<ISystemConfigService>().Add(dto);

            //    MessageUtil.ShowTips("添加新条目成功!");
            //}
            //catch (Exception ex)
            //{
            //    MessageUtil.ShowWarning(ex.Message);
            //    return false;
            //}

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 加入树形结构的根节点
        /// </summary>
        /// <returns></returns>
        private bool AddParent()
        {
            if (dataDictList.Exists(q => q.FieldTypeValue == slueditField.EditValue.ToString()))
            {
                return(true);
            }

            DataDictDto dto = new DataDictDto();

            dto.FieldTypeName     = "分类管理";
            dto.FieldTypeValue    = slueditField.EditValue.ToString();
            dto.FieldTypeSerialNo = tvType.TopNode.GetNodeCount(false) - 1;

            try
            {
                // 记录写入数据库
                CallerFactory.Instance.GetService <ISystemConfigService>().Add(dto);
                return(true);
            }
            catch (Exception ex)
            {
                MessageUtil.ShowWarning(ex.Message);
                return(false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 更新纪录
        /// </summary>
        /// <param name="fieldInfo"></param>
        private bool Update(DataDictDto fieldInfo)
        {
            try
            {
                CallerFactory.Instance.GetService <ISystemConfigService>().UpdateDataDict(fieldInfo);

                MessageUtil.ShowTips("更新条目成功!");
                return(true);
            }
            catch (Exception ex)
            {
                MessageUtil.ShowWarning(ex.Message);
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 更新纪录
        /// </summary>
        /// <param name="fieldInfo">实体对象</param>
        private void Update(DataDictDto fieldInfo)
        {
            try
            {
                // 更新作为子节点的记录
                CallerFactory.Instance.GetService <ISystemConfigService>().UpdateDataDict(fieldInfo);
                // 禁止编辑标签文本
                tvType.LabelEdit = false;

                MessageUtil.ShowTips("更新条目成功!");
            }
            catch (Exception ex)
            {
                MessageUtil.ShowWarning(ex.Message);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 添加纪录
        /// </summary>
        /// <param name="dto">实体对象</param>
        private void Add(DataDictDto dto)
        {
            if (PropertyHelper.DataDictItems.Count <DataDictDto>(q => q.FieldTypeName == dto.FieldTypeName &&
                                                                 q.FieldTypeValue == dto.FieldTypeValue) > 0)
            {
                MessageUtil.ShowWarning("重复的条目值,请重新输入!");
                return;
            }

            try
            {
                // 记录写入数据库
                CallerFactory.Instance.GetService <ISystemConfigService>().Add(dto);
                MessageUtil.ShowTips("添加新条目成功!");
            }
            catch (Exception ex)
            {
                MessageUtil.ShowWarning(ex.Message);
            }
        }
Exemplo n.º 8
0
        private void toolDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // 是否选中条目
            int[] selected = gvDataDict.GetSelectedRows();
            if (selected.Length == 0)
            {
                MessageUtil.ShowWarning("请选择要删除的信息!");
                return;
            }

            // 表格选中的记录
            DataDictDto item = (DataDictDto)gvDataDict.GetFocusedRow();

            string str = string.Format("确实要删除该用户信息吗?");

            if (DialogResult.Yes == MessageUtil.ShowYesNoAndTips(str))
            {
                int[] idx = selected.Reverse().ToArray();

                try
                {
                    foreach (int rowIndex in idx)
                    {
                        // 表格中删除选中的列
                        DataDictDto dataDict = (DataDictDto)gvDataDict.GetRow(rowIndex);
                        gvDataDict.DeleteRow(rowIndex);

                        // 在数据库中删除信息
                        CallerFactory.Instance.GetService <ISystemConfigService>().Delete(dataDict);
                    }

                    MessageUtil.ShowTips("删除成功!");
                }
                catch (Exception ex)
                {
                    MessageUtil.ShowWarning(ex.Message);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="subNodes">树的子节点集合</param>
        /// <param name="tn">待删除节点</param>
        public void Delete(List <TreeNode> subNodes, TreeNode tn)
        {
            // 节点实体对象
            DataDictDto fieldInfo = new DataDictDto();

            try
            {
                foreach (TreeNode node in subNodes)
                {
                    // 确定子节点的父节点
                    if (node.Parent.Tag != null)
                    {
                        fieldInfo.FieldTypeName = node.Parent.Tag.ToString();
                    }
                    else
                    {
                        fieldInfo.FieldTypeName = node.Parent.Text;
                    }

                    fieldInfo.FieldTypeValue    = node.Text;  // 节点值
                    fieldInfo.FieldTypeSerialNo = node.Index; // 节点序号

                    // 从数据库中删除节点
                    CallerFactory.Instance.GetService <ISystemConfigService>().Delete(fieldInfo);
                }

                // 删除视图上指定节点
                tvType.Nodes.Remove(tn);

                MessageUtil.ShowTips("条目已删除!");
            }
            catch (Exception ex)
            {
                MessageUtil.ShowError(ex.Message);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 删除或移动节点后更新字段
        /// </summary>
        /// <param name="node">节点</param>
        void UpdateNode(TreeNode node)
        {
            DataDictDto fieldInfo = new DataDictDto();

            foreach (TreeNode tn in node.Nodes)
            {
                // 更新移动树形节点的数据库记录
                if (tn.Parent.Tag != null)
                {
                    fieldInfo.FieldTypeName = tn.Parent.Tag.ToString();
                }
                else
                {
                    fieldInfo.FieldTypeName = tn.Parent.Text;
                }

                fieldInfo.FieldTypeValue    = tn.Text;
                fieldInfo.FieldTypeSerialNo = tn.Index;

                CallerFactory.Instance.GetService <ISystemConfigService>().UpdateDataDict(fieldInfo);
            }

            PropertyHelper.DataDictItems = CallerFactory.Instance.GetService <ISystemConfigService>().GetAllDataDicts();
        }
Exemplo n.º 11
0
        public ActionResult Edit(DataDictDto model)
        {
            var resultModel = new RespResultCountViewModel();

            try
            {
                #region 验证
                if (string.IsNullOrEmpty(model.DataType) && string.IsNullOrEmpty(model.ItemCode))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "修改失败!原因:字典分类ID或字典ID是空";
                    return(Ok(resultModel));
                }
                if (string.IsNullOrEmpty(model.ItemName))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "名称不允许为空";
                    return(Ok(resultModel));
                }
                if (string.IsNullOrEmpty(model.ItemCode))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "编码不允许为空";
                    return(Ok(resultModel));
                }
                if (string.IsNullOrEmpty(model.CRowId))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "主键不允许为空";
                    return(Ok(resultModel));
                }
                if (_dataDictService.ExistFullName(model.DataType, model.ItemName, model.CRowId, User.GetCurrentUserOrganizeId()))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "已存在相同名称!";
                    return(Ok(resultModel));
                }
                if (_dataDictService.ExistEnCode(model.DataType, model.ItemCode, model.CRowId, User.GetCurrentUserOrganizeId()))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "已存在相同编号!";
                    return(Ok(resultModel));
                }
                #endregion

                DataDictEntity dataDictEntity = _mapper.Map <DataDictEntity>(model);
                dataDictEntity.ItemName       = model.ItemName;
                dataDictEntity.ModifyDate     = DateTime.Now;
                dataDictEntity.ModifyUserId   = User.GetCurrentUserId();
                dataDictEntity.ModifyUserName = User.GetCurrentUserName();

                bool result = _dataDictService.Update(dataDictEntity);
                if (result)
                {
                    resultModel.code = 0;
                    resultModel.msg  = "修改成功";
                }
                else
                {
                    resultModel.code = -1;
                    resultModel.msg  = "修改失败!原因:根据主键没有找到要处理的数据";
                }
                return(Ok(resultModel));
            }
            catch (Exception ex)
            {
                resultModel.code = -1;
                resultModel.msg  = "操作失败!原因:" + ex.Message;
                return(Ok(resultModel));
            }
        }
Exemplo n.º 12
0
        public ActionResult Create(DataDictDto model)
        {
            RespResultViewModel resultModel = new RespResultCountViewModel();

            try
            {
                #region 验证
                if (string.IsNullOrEmpty(model.ItemName))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "名称不允许为空";
                    return(Ok(resultModel));
                }
                if (string.IsNullOrEmpty(model.ItemCode))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "编码不允许为空";
                    return(Ok(resultModel));
                }

                if (_dataDictService.ExistFullName(model.DataType, model.ItemName, model.CRowId, User.GetCurrentUserOrganizeId()))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "已存在相同名称!";
                    return(Ok(resultModel));
                }
                if (_dataDictService.ExistEnCode(model.DataType, model.ItemCode, model.CRowId, User.GetCurrentUserOrganizeId()))
                {
                    resultModel.code = -1;
                    resultModel.msg  = "已存在相同编号!";
                    return(Ok(resultModel));
                }
                #endregion

                DataDictEntity dataDictEntity = _mapper.Map <DataDictEntity>(model);
                dataDictEntity.ItemName       = model.ItemName;
                dataDictEntity.CRowId         = ConstDefine.CreateGuid();
                dataDictEntity.CreateUserId   = User.GetCurrentUserId();
                dataDictEntity.CreateUserName = User.GetCurrentUserName();
                dataDictEntity.CreateDate     = DateTime.Now;
                dataDictEntity.DeleteMark     = 1;
                dataDictEntity.ModifyDate     = System.DateTime.Now;
                dataDictEntity.ModifyUserId   = "";
                dataDictEntity.ModifyUserName = "";
                dataDictEntity.OrgId          = User.GetCurrentUserOrganizeId();

                bool result = _dataDictService.Insert(dataDictEntity);
                if (result)
                {
                    resultModel.code = 0;
                    resultModel.msg  = "新增成功";
                }
                else
                {
                    resultModel.code = -1;
                    resultModel.msg  = "新增失败";
                }
                return(Ok(resultModel));
            }
            catch (Exception ex)
            {
                resultModel.code = -1;
                resultModel.msg  = "操作失败" + ex.ToString();
                return(Ok(resultModel));
            }
        }
 /// <summary>
 /// 更新字典条目
 /// </summary>
 /// <param name="item">实体</param>
 /// <returns></returns>
 public int UpdateDataDict(DataDictDto item)
 {
     return(baseSytemConfigService.UpdateDataDict(item.MapTo <DataDict>()));
 }
 /// <summary>
 /// 删除字典条目
 /// </summary>
 /// <param name="item">实体</param>
 /// <returns></returns>
 public int Delete(DataDictDto item)
 {
     return(baseSytemConfigService.Delete(item.MapTo <DataDict>()));
 }
 /// <summary>
 /// 加入字典条目
 /// </summary>
 /// <param name="item">实体</param>
 /// <returns></returns>
 public int Add(DataDictDto item)
 {
     return(baseSytemConfigService.Add(item.MapTo <DataDict>()));
 }