Example #1
0
        public void add(DepartmentDto department)
        {
            SqlConnection cn = null;
            SqlTransaction tc = null;
            try
            {
                cn = DbHelperSQL.getConnection();
                tc=DbHelperSQL.startTransaction(cn);

                //生成部门完整编号FullNo
                if (department.ParentNo.Length > 0)
                {
                    DepartmentDto parent = this.departmentDAL.getByDepartmentNo(cn,tc,department.ParentNo);
                    if (null == parent)
                    {
                        DbHelperSQL.rollBackTransaction(tc);
                        throw new MakeException(ExpSort.普通, "找不到上级部门" + department.ParentNo + "操作失败");
                    }
                    department.FullNo = parent.FullNo + department.DepartmentNo + '|';
                }
                else
                {
                    department.FullNo = department.DepartmentNo + '|';
                }

                //检查部门编号是否重复
                DepartmentDto oldDepartment = this.departmentDAL.getByDepartmentNo(cn,tc,department.DepartmentNo);
                if (null != oldDepartment)
                {
                    DbHelperSQL.rollBackTransaction(tc);
                    throw new MakeException(ExpSort.普通, "部门编号" + department.DepartmentNo + "已经存在,操作失败");
                }

                //执行新增写进数据库
                this.departmentDAL.add(cn,tc,department);

                DbHelperSQL.commitTransaction(tc);
            }
            catch (DalException dalEx)
            {
                DbHelperSQL.rollBackTransaction(tc);
                throw new MakeException(ExpSort.数据库, dalEx.Message);
            }
            finally
            {
                DbHelperSQL.closeConnection(cn);
            }
        }
 protected void btnNew_Click(object sender, EventArgs e)
 {
     department = MakeUtil.getRequestDataToModel<DepartmentDto>(Request, typeof(DepartmentDto), -1);
     try
     {
         this.departmentEbi.add(department);
         MakeUtil.addOperationNote(Request.UserHostAddress, SystemUser, "新增部门", department.DepartmentNo);
         Script.alertMsg("新增成功", this.Page);
         Script.scriptRedirect("Department-New.aspx", this.Page);
         //Script.PageRedirect(this.Page);
     }
     catch (MakeException makeEx)
     {
         Script.alertMsg(makeEx.Message, this.Page);
         this.DataBind();
     }
 }
 protected void tvDepartment_SelectedNodeChanged(object sender, EventArgs e)
 {
     DepartmentDto department = new DepartmentDto
     {
         DepartmentNo = this.tvDepartment.SelectedNode.Value,
         DepartmentName = this.tvDepartment.SelectedNode.Text
     };
     if (department.DepartmentNo.Length == 0)
         department.DepartmentName = "";
     this.selectedValue = department;
     if (null != SelectChanged)
     {
         SelectChanged(this, new EventArgs());
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     //if (!MakeUtil.checkSysConfirm(Session, Response)) return;
     if (!this.Page.IsPostBack)
     {
         this.NavigationTree.create();
         this.department = new DepartmentDto();
         this.DataBind();
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!MakeUtil.checkSysConfirm(Session, Response)) return;
            if (!this.Page.IsPostBack)
            {
                string departmentNo = MakeUtil.getStringFromRequestByName(Request, "departmentNo", -1).Trim();
                try
                {
                    this.department = this.departmentEbi.getByDepartmentNo(departmentNo);
                    if (null == this.department)
                    {
                        Script.alertMsg("找不到部门资料" + departmentNo, this.Page);
                        Script.closeDivWin(this.Page, "DepartmentModify" + departmentNo);
                        return;
                    }

                    this.NavigationTree.create();

                    this.bindAll();
                    this.setButtonsState();
                }
                catch (MakeException makeEx)
                {
                    Script.alertMsg(makeEx.Message, this.Page);
                    return;
                }
            }
        }