Exemple #1
0
        public List <PersonPreview> GetPreviews(List <short> idlist)
        {
            List <PersonPreview> personPreviews = new List <PersonPreview>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    foreach (short empl in idlist)
                    {
                        PersonPreview preview = new PersonPreview();
                        conn.Open();
                        SqlCommand cmd = new SqlCommand("select * from hr.employeePreview where emplid = " + empl, conn);
                        //cmd.Parameters.AddWithValue(@"emplId", empl);
                        SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                        while (reader.Read())
                        {
                            preview.id       = Convert.ToInt16(reader.GetValue(0));
                            preview.fullname = reader.GetValue(1).ToString();
                            preview.position = reader.GetValue(2).ToString();
                            preview.phone    = reader.GetValue(3).ToString();
                        }
                        conn.Close();
                        personPreviews.Add(preview);
                    }
                }
                return(personPreviews);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Помилка при виведенні результатів.");
                return(null);
            }
        }
Exemple #2
0
        //Employee previews on main screen
        public List <PersonPreview> GetPreviews()
        {
            List <PersonPreview> personPreviews = new List <PersonPreview>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    conn.Open();
                    SqlCommand    cmd    = new SqlCommand("select * from hr.employeePreview;", conn);
                    SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                    while (reader.Read())
                    {
                        PersonPreview preview = new PersonPreview()
                        {
                            id       = Convert.ToInt16(reader.GetValue(0)),
                            fullname = reader.GetValue(1).ToString(),
                            position = reader.GetValue(2).ToString(),
                            phone    = reader.GetValue(3).ToString()
                        };
                        personPreviews.Add(preview);
                    }
                    return(personPreviews);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Помилка при завантаженні даних.");
                return(null);
            }
        }