예제 #1
0
        /// <summary>
        /// 保存
        /// </summary>
        private void Save()
        {
            //判断输入有效性
            if (!ValidateValue())
            {
                return;
            }

            //取控件中的科室数据信息
            if (this.departmentStat == null)
            {
                this.departmentStat = new Neusoft.HISFC.Models.Base.DepartmentStat();
            }

            //如果是科室分类,则取科室分类的最大编码。
            if (this.chbClass.Checked)
            {
                this.departmentStat.NodeKind = 0;

                //如果是新增科室分类,则取
                if (this.departmentStat.DeptCode == "")
                {
                    this.GetMaxCode();
                }
            }
            else
            {
                this.departmentStat.NodeKind = 1;
            }

            Neusoft.HISFC.Models.Base.Department deptment = new Neusoft.HISFC.Models.Base.Department();

            //在增加科室时判断该科室是否已经存在

            if (!this.DoEvent(this.txtDeptCode.Text.Trim()))
            {
                MessageBox.Show("该科室在本科室结构中已存在,请重新选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            #region 科室基本信息
            if (!this.chbClass.Checked)                                  //不是科室分类
            {
                deptment.ID        = this.txtDeptCode.Text.Trim();       //科室编码
                deptment.Name      = this.comboDeptName.Text.Trim();     //科室名称
                deptment.SpellCode = this.txtSpellCode.Text.Trim();      //拼音码
                deptment.WBCode    = this.txtWbCode.Text.Trim();         //五笔码
                deptment.UserCode  = this.txtUserCode.Text.Trim();       //自定义码
                deptment.ShortName = this.txtDeptSimpleName.Text.Trim(); //科室简称

                //如果英文名称不为空
                if (this.txtDeptEnglish.Text != "")
                {
                    deptment.EnglishName = this.txtDeptEnglish.Text.Trim();//科室英文名称
                }

                if (this.comboDeptType.SelectedIndex != -1)
                {
                    deptment.DeptType.ID = this.comboDeptType.Tag;//科室类型ID
                }
                //停用
                if (this.chbStop.Checked)
                {
                    deptment.ValidState = Neusoft.HISFC.Models.Base.EnumValidState.Valid;//有效性状态
                }
                else
                {
                    deptment.ValidState = Neusoft.HISFC.Models.Base.EnumValidState.Invalid;
                }
                //排序ID
                if (txtSortID.Text != "")
                {
                    deptment.SortID = Neusoft.FrameWork.Function.NConvert.ToInt32(txtSortID.Text.Trim()); //排序ID
                }
                deptment.SpecialFlag = this.comboDeptPro.SelectedIndex.ToString();                        //特殊科室标识
                deptment.IsRegDept   = this.chbReg.Checked;                                               //是否挂号科室
                deptment.IsStatDept  = this.chbTat.Checked;                                               //是否统计科室
                deptment.Memo        = this.txtMark.Text.Trim();                                          //备注

                #region  是否已经存在编码相同但名称不同的科室
                Neusoft.HISFC.Models.Base.Department depttempt = deptMgr.GetDeptmentById(deptment.ID);
                if (depttempt == null)
                {
                    MessageBox.Show("该科室编码没有与之相对应的科室" + deptMgr.Err);
                    return;
                }
                if ((depttempt.ID == deptment.ID) && (depttempt.Name != deptment.Name))
                {
                    if (MessageBox.Show("已经存在编码为" + depttempt.ID + "的记录" + depttempt.Name + "是否要替换为:" + deptment.Name + "吗", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
                    {
                        return;
                    }
                }
            }
            #endregion

            //将控件中的数据保存到实体中
            this.departmentStat.DeptCode   = this.txtDeptCode.Text.Trim();                                            //科室编码
            this.departmentStat.DeptName   = this.comboDeptName.Text.Trim();                                          //科室名称
            this.departmentStat.SpellCode  = this.txtSpellCode.Text.Trim();                                           //拼音码
            this.departmentStat.WBCode     = this.txtWbCode.Text.Trim();                                              //五笔码
            this.departmentStat.ValidState = Neusoft.HISFC.Models.Base.EnumValidState.Valid;                          //有效标志。0 在用。1停用
            this.departmentStat.SortId     = Neusoft.FrameWork.Function.NConvert.ToInt32(this.txtSortID.Text.Trim()); //排序号
            this.departmentStat.Memo       = this.txtMark.Text.Trim();                                                //备注

            //保存时,如果没有拼音码或者五笔码,则自动生成
            if (this.txtSpellCode.Text.Trim() == "" || this.txtWbCode.Text.Trim() == "")
            {
                CreateSpell();    //产生拼音码和五笔码
            }
            //定义科室分类表管理类

            Neusoft.FrameWork.Management.PublicTrans.BeginTransaction();

            Neusoft.HISFC.BizLogic.Manager.DepartmentStatManager deptStatManager = new Neusoft.HISFC.BizLogic.Manager.DepartmentStatManager();
            ////定义事务
            //Neusoft.FrameWork.Management.Transaction trans = new Neusoft.FrameWork.Management.Transaction(deptStatManager.Connection);
            //trans.BeginTransaction();

            ////管理类设置当前事务
            //deptStatManager.SetTrans(trans.Trans);

            deptMgr.SetTrans(Neusoft.FrameWork.Management.PublicTrans.Trans);
            try
            {
                //Do科室分类表,先保存,如果不存在则插入一条记录
                int parm = deptStatManager.UpdateDepartmentStat(this.departmentStat);

                if (parm == 0)
                {
                    parm = deptStatManager.InsertDepartmentStat(this.departmentStat);
                }

                if (parm != 1)
                {
                    Neusoft.FrameWork.Management.PublicTrans.RollBack();
                    MessageBox.Show("数据保存失败:" + deptStatManager.Err);
                    return;
                }
                #region 基础数据维护
                if (!this.chbClass.Checked)
                {
                    if (deptMgr.Insert(deptment) == -1)
                    {
                        if (deptMgr.DBErrCode == 1)
                        {
                            if (deptMgr.Update(deptment) == -1 || deptMgr.Update(deptment) == 0)
                            {
                                Neusoft.FrameWork.Management.PublicTrans.RollBack();
                                MessageBox.Show("保存科室信息失败" + deptMgr.Err);
                                return;
                            }
                        }
                        else
                        {
                            Neusoft.FrameWork.Management.PublicTrans.RollBack();
                            MessageBox.Show("保存科室信息失败" + deptMgr.Err);
                            return;
                        }
                    }
                }
                #endregion
            }
            catch (Exception a)
            {
                Neusoft.FrameWork.Management.PublicTrans.RollBack();
                MessageBox.Show(a.Message);
                return;
            }
            Neusoft.FrameWork.Management.PublicTrans.Commit();
            this.FindForm().DialogResult = DialogResult.OK;



            #endregion
        }
예제 #2
0
        private void tvDepartmentLevelTree1_DragDrop(object sender, DragEventArgs e)
        {
            /*该程序段变量注释!
             * dragNode为【拖动】节点
             * objectNode为【目标】节点
             * */
            try
            {
                //获得进行"Drag"操作中【拖动】的节点
                TreeNode     dragNode = null;
                ListViewItem item     = null;

                //是在内部拖动
                dragNode = e.Data.GetData("System.Windows.Forms.TreeNode") as TreeNode;

                //是从ListView拖动
                if (dragNode == null)
                {
                    item     = e.Data.GetData("System.Windows.Forms.ListViewItem") as ListViewItem;
                    dragNode = (item.Tag) as TreeNode;
                }
                if (dragNode != null)
                {
                    //根据窗口位置转换成TreeView位置
                    Point position = this.tvDepartmentLevelTree1.PointToClient(new Point(e.X, e.Y));
                    //根据TreeView位置取当前【目标】节点
                    TreeNode objectNode = this.tvDepartmentLevelTree1.GetNodeAt(position);

                    //在目标组件中加入拖入的项目
                    if (objectNode != null)
                    {
                        //如果拖动后的位置跟拖动前的位置没变,则提示不能拖动
                        if (dragNode.Parent == objectNode)
                        {
                            MessageBox.Show("无法移动科室:源科室与目标科室相同!", "提示");
                            return;
                        }

                        //如果目标节点是拖动节点的子节点,则不允许拖动
                        if (objectNode.FullPath.IndexOf(dragNode.FullPath) > 0)
                        {
                            MessageBox.Show("无法移动科室:不能将科室移动到其下级科室中!", "提示");
                            return;
                        }

                        //更改拖动科室的父级科室编码和名称
                        Neusoft.HISFC.BizLogic.Manager.DepartmentStatManager deptMgr    = new Neusoft.HISFC.BizLogic.Manager.DepartmentStatManager();
                        Neusoft.HISFC.Models.Base.DepartmentStat             parentDept = objectNode.Tag as Neusoft.HISFC.Models.Base.DepartmentStat;
                        Neusoft.HISFC.Models.Base.DepartmentStat             dept       = dragNode.Tag as Neusoft.HISFC.Models.Base.DepartmentStat;

                        //目标节点的统计大类编码,用于比较拖动的科室是否在同一个统计大类中
                        string statCode = "";

                        //如果目标节点是统计大类(一级节点),则将大类付与拖动科室的父级
                        if (parentDept == null)
                        {
                            //取目标节点统计大类的编码
                            statCode = objectNode.Tag.ToString();

                            //只能在同一大类下进行拖动
                            if (statCode != dept.StatCode)
                            {
                                MessageBox.Show("无法移动科室:不能将科室移动到另一个科室分类中。", "提示");
                                return;
                            }
                            if (MessageBox.Show("确定要把科室" + dept.DeptName + "转到" + objectNode.Text + "下吗?", "科室转移提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
                            {
                                dept.PardepCode = "AAAA";
                                dept.PardepName = objectNode.Text;
                            }
                        }
                        else
                        {
                            //取目标节点的统计大类编码
                            statCode = parentDept.StatCode;

                            //只能在同一大类下进行拖动
                            if (statCode != dept.StatCode)
                            {
                                MessageBox.Show("无法移动科室:不能将科室移动到另一个科室分类中。", "提示");
                                return;
                            }

                            if (MessageBox.Show("确定要把科室“" + dept.DeptName + "”转到“" + parentDept.DeptName + "”下吗?", "科室转移提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                            {
                                return;
                            }

                            //如果目标节点是科室,则将科室信息付与拖动科室的父级
                            dept.PardepCode = parentDept.DeptCode;
                            dept.PardepName = parentDept.DeptName;
                        }

                        if (deptMgr.UpdateDepartmentStat(dept) != 1)
                        {
                            MessageBox.Show("更新科室信息时出错:" + deptMgr.Err);
                            return;
                        }
                        //删除拖动的节点以前的位置
                        this.tvDepartmentLevelTree1.DelDepartment(dragNode);
                        //在新的位置插入拖动的节点
                        this.tvDepartmentLevelTree1.AddDepartment(objectNode, dragNode);
                    }
                }
            }
            catch
            {
            }
        }