Ejemplo n.º 1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Department dept = new Department();
            dept.ParentDeptId = GetParentId();
            dept.Name = TxtName.Text;
            dept.Code = TxtCode.Text;

            if (SaveData(dept))
            {
                this.DialogResult = DialogResult.OK;
            }
        }
Ejemplo n.º 2
0
        public int addDept(Department dept, string currentUser)
        {
            string sqlStr = dbUtil.getSqlStatement("SQL_Dept_Insert");

            SqlParameter[] sqlParms = DeptToParam(dept, currentUser, true);

            try
            {
                return (int)DAO.DBAccess.ExecuteNonQuery(DAO.DBAccess.SQLConnectionString, CommandType.Text, sqlStr, sqlParms);
            }
            catch (Exception ex)
            {
                throw new DAOException("E0001", ex);
            }
        }
Ejemplo n.º 3
0
        private bool ParentExisted(Department dept, List<Department> depts)
        {
            if (dept.ParentDeptId == null || dept.ParentDeptId.Equals(string.Empty))
            {
                return false;
            }

            foreach (Department depttemp in depts)
            {
                if (depttemp.DeptId.Equals(dept.ParentDeptId))
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 4
0
 private void ReloadData()
 {
     try
     {
         dept = icompany.getDept(GetCurDeptId());
         if (null != dept)
         {
             deptBkup = dept.Clone() as Department;
         }
         else
         {
             deptBkup = null;
             ShowErrorInfo("无有效数据。");
         }
     }
     catch (BIZException be)
     {
         dept = null;
         deptBkup = null;
         ShowErrorInfo("读取部门信息失败: " + be.Message);
     }
     catch (DAOException de)
     {
         dept = null;
         deptBkup = null;
         ShowErrorInfo("读取部门信息失败: " + de.Message);
     }
 }
Ejemplo n.º 5
0
        protected override bool SavePageData()
        {
            if (dept == null)
            {
                return false;
            }

            if (!DataChanged)
            {
                return true;
            }

            try
            {
                icompany.Save(dept);
                deptBkup = dept.Clone() as Department;
                return true;
            }
            catch (BIZException be)
            {
                ShowErrorInfo("数据保存失败: " + be.Message);
                return false;
            }
            catch (DAOException de)
            {
                ShowErrorInfo("数据保存失败: " + de.Message);
                return false;
            }
        }
Ejemplo n.º 6
0
 protected override void RecoverData()
 {
     dept = deptBkup.Clone() as Department;
 }
Ejemplo n.º 7
0
        private SqlParameter[] DeptToParam(Department dept, string currentUser, bool isInsertOp)
        {
            List<SqlParameter> paras = new List<SqlParameter>();
            paras.Add(new SqlParameter("@DeptID",SqlDbType.VarChar,20));
            paras.Add(new SqlParameter("@ParentDeptID",SqlDbType.VarChar,20));
            paras.Add(new SqlParameter("@Code",SqlDbType.VarChar,20));
            paras.Add(new SqlParameter("@DeptName",SqlDbType.NVarChar,100));
            paras.Add(new SqlParameter("@UpdateUser",SqlDbType.VarChar,20));

            paras[0].Value = dept.DeptId;
            paras[1].Value = dept.ParentDeptId;
            paras[2].Value = dept.Code;
            paras[3].Value = dept.Name;
            paras[4].Value = currentUser;

            if (isInsertOp)
            {
                paras.Add(new SqlParameter("@CreateUser", SqlDbType.VarChar, 20));
                paras[5].Value = currentUser;
            }

            return paras.ToArray();
        }
Ejemplo n.º 8
0
 private void DataRowToDept(DataRow dr, Department dept)
 {
     dept.DeptId = dr["DeptId"].ToString();
     dept.Code = dr["Code"].ToString();
     dept.Name = dr["Name"].ToString();
     dept.ParentDeptId = dr["ParentDeptId"].ToString();
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="hashTable"></param>
        /// <returns></returns>
        public List<Department> searchDeptChildByDeptID(string parentDeptId)
        {
            string sqlStr = dbUtil.getSqlStatement("SQL_Dept_Child_SearchByDeptID");
            SqlParameter[] sqlParms = {
                new SqlParameter("@ParentDeptId",SqlDbType.VarChar,20)
            };

            sqlParms[0].Value = parentDeptId;

            DataSet searchResult = null;
            try
            {
                List<Department> depts = new List<Department>();
                searchResult = DAO.DBAccess.ExecuteAdapter(DAO.DBAccess.SQLConnectionString, CommandType.Text, sqlStr, sqlParms);
                foreach (DataTable dt in searchResult.Tables)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        Department dept = new Department();
                        DataRowToDept(dr, dept);
                        depts.Add(dept);
                    }
                }

                return depts;
            }
            catch (Exception ex)
            {
                throw new DAOException("E0001", ex);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// ���ҷ���ID�IJ��š�
        /// ���Ҳ���������null.
        /// </summary>
        /// <param name="deptId"></param>
        /// <returns></returns>
        public Department searchDeptByDeptID(string deptId)
        {
            string sqlStr = dbUtil.getSqlStatement("SQL_Dept_SearchByDeptID");
            SqlParameter[] sqlParms = {
                new SqlParameter("@DeptID",SqlDbType.VarChar,20)
            };
            sqlParms[0].Value = deptId;

            DataSet searchResult = null;
            try
            {
                searchResult = DAO.DBAccess.ExecuteAdapter(DAO.DBAccess.SQLConnectionString, CommandType.Text, sqlStr, sqlParms);
                UtilService utilService = new UtilService();
                if (utilService.isNullDataset(searchResult))
                {
                    return null;
                }

                Department dept = new Department();
                DataRowToDept(searchResult.Tables[0].Rows[0], dept);
                return dept;
            }
            catch (Exception ex)
            {
                throw new DAOException("E0001", ex);
            }
        }
Ejemplo n.º 11
0
        public List<Department> searchDeptAll()
        {
            List<Department> deptList = new List<Department>();

            string sqlStr = dbUtil.getSqlStatement("SQL_Dept_SearchAll");
            DataSet searchResult = null;
            try
            {
                searchResult = DAO.DBAccess.ExecuteAdapter(DAO.DBAccess.SQLConnectionString, CommandType.Text, sqlStr, null);
                foreach (DataTable dt in searchResult.Tables)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        Department dept = new Department();
                        DataRowToDept(dr, dept);
                        deptList.Add(dept);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new DAOException("E0001", ex);
            }
            return deptList;
        }
Ejemplo n.º 12
0
        public void Save(Department dept)
        {
            bool insert = (dept.DeptId == null || dept.DeptId.Equals(string.Empty));

            try
            {
                if (insert)
                {
                    dept.DeptId = compDAO.getNewDeptId(dept.ParentDeptId);
                    compDAO.insertDept(dept, "N001");
                }
                else
                {
                    compDAO.updateDept(dept, "N001");
                }
            }
            catch (DAOException)
            {
                throw;
            }
        }
Ejemplo n.º 13
0
 public void getDeptTest()
 {
     CompanyImpl target = new CompanyImpl(); // TODO: Initialize to an appropriate value
     string deptId = string.Empty; // TODO: Initialize to an appropriate value
     Department expected = new Department(); // TODO: Initialize to an appropriate value
     Department actual;
     actual = target.getDept(deptId);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Ejemplo n.º 14
0
 private bool SaveData(Department dept)
 {
     try
     {
         icompany.Save(dept);
         return true;
     }
     catch (BIZException be)
     {
         MessageBox.Show("数据保存失败: " + be.Message);
         return false;
     }
     catch (DAOException de)
     {
         MessageBox.Show("数据保存失败: " + de.Message);
         return false;
     }
 }