private string GetDeptString(EmpDept[] depts) { string deptStr = ""; foreach (EmpDept dept in depts) { deptStr += dept.DeptName; deptStr += "\n"; } if (deptStr.Length > 0) { deptStr = deptStr.Remove(deptStr.Length - 1); } return deptStr; }
private void SaveEmpDept(string empId, EmpDept[] empDepts, SqlTransaction trans) { try { // delete all. empDAO.deleteEmpDeptByEmpId(trans, empId); // insert new. foreach (EmpDept empDept in empDepts) { empDept.EmpId = empId; empDAO.addEmpDept(trans, empDept, "N001"); } } catch (DAOException) { throw; } }
private void UpdateDept(EmpDept[] depts) { DgvDept.Rows.Clear(); List<string> strs = new List<string>(); foreach (EmpDept dept in depts) { strs.Add(dept.DeptName); } DgvDept.Rows.Add(strs.ToArray()); }
private SqlParameter[] BuildEmpDeptParam(EmpDept empDept, string currentUser, bool isInsertOP) { List<SqlParameter> paras = new List<SqlParameter>(); paras.Add(new SqlParameter("@EmpID",SqlDbType.VarChar,20)); paras.Add(new SqlParameter("@DeptID",SqlDbType.VarChar,20)); paras.Add(new SqlParameter("@UpdateUser", SqlDbType.VarChar, 20)); paras[0].Value = empDept.EmpId; paras[1].Value = empDept.DeptId; paras[2].Value = currentUser; if (isInsertOP) { paras.Add(new SqlParameter("@CreateUser", SqlDbType.VarChar, 20)); paras[3].Value = currentUser; } return paras.ToArray(); }
public List<EmpDept> searchDeptByEmpID(string strEmpID) { string sqlStr = dbUtil.getSqlStatement("SQL_EmpDept_SearchByEmpID"); SqlParameter[] sqlParms = { new SqlParameter("@EmpID",SqlDbType.VarChar,20) }; sqlParms[0].Value = strEmpID; try { List<EmpDept> empdeptList = new List<EmpDept>(); DataSet searchResult = DAO.DBAccess.ExecuteAdapter(DAO.DBAccess.SQLConnectionString, CommandType.Text, sqlStr, sqlParms); foreach (DataTable dt in searchResult.Tables) { foreach (DataRow dr in dt.Rows) { EmpDept dept = new EmpDept(); dept.EmpId = dr["EmpID"].ToString(); dept.DeptId = dr["DeptId"].ToString(); dept.DeptName = dr["DeptName"].ToString(); empdeptList.Add(dept); } } return empdeptList; } catch (Exception ex) { throw new DAOException("E0001", ex); } }
public int addEmpDept(SqlTransaction trans, EmpDept empDept, string currentUser) { string sqlStr = dbUtil.getSqlStatement("SQL_EMP_EmpDept_Insert"); SqlParameter[] sqlParms = BuildEmpDeptParam(empDept, currentUser, true); try { return (int)DAO.DBAccess.ExecuteNonQuery(trans, CommandType.Text, sqlStr, sqlParms); } catch (Exception ex) { throw new DAOException("E0001", ex); } }