Esempio n. 1
0
        public MResponse GetCollectionPointAndRep(string deptId)
        {
            CollectionPointDAO dao = new CollectionPointDAO();
            MCollectionAndRep  collectionAndRep = dao.GetCollecitonPointAndRep(deptId);
            MResponseObj <MCollectionAndRep> response
                = new MResponseObj <MCollectionAndRep>()
                {
                ResObj  = collectionAndRep,
                Success = collectionAndRep != null
                };

            return(response);
        }
        public MCollectionAndRep GetCollecitonPointAndRep(string deptId)
        {
            MCollectionAndRep res = null;
            SqlDataReader reader = null;
            try
            {
                connection.Open();
                string sql = @"SELECT e.ID repId,e.Name repName,c.ID pointId,c.Name pointName,c.CollectionTime time FROM Department d 
                                JOIN CollectionPoint c ON d.CollectionPointID = c.ID
						        JOIN Employee e ON d.RepID = e.ID WHERE d.ID = @deptId";
                SqlCommand cmd = new SqlCommand(sql, connection);
                cmd.Parameters.AddWithValue("@deptId", deptId);
                 reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    res = new MCollectionAndRep()
                    {
                        RepId = (int)reader["repId"],
                        RepName = reader["repName"].ToString(),
                        PointId = (int)reader["pointId"],
                        PointName = reader["pointName"].ToString(),
                        ColTime = reader["time"].ToString()
                    };
                }

            }
            catch (Exception e)
            {

                return null;
            }
            finally
            {
                if (reader != null) reader.Close();
                connection.Close();
            }
            return res;

        }