Exemplo n.º 1
0
        public void InsertMilitaryInfo(PersonMilitary military)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("insert into hr.militaryLiable ( emplid, series, serialNumber, militaryDept, militaryRank ) " +
                                                    "values (@emplId, @series, @serialNumber, @militaryDept, @militaryRank) ;", conn);

                    cmd.Parameters.Add(@"emplId", System.Data.SqlDbType.SmallInt); cmd.Parameters[@"emplId"].Value = Convert.ToInt16(military.emplId);
                    cmd.Parameters.AddWithValue(@"series", Convert.ToString(military.series));
                    cmd.Parameters.AddWithValue(@"serialNumber", Convert.ToString(military.serialNumber));
                    cmd.Parameters.AddWithValue(@"militaryDept", Convert.ToString(military.militaryRank));
                    cmd.Parameters.AddWithValue(@"militaryRank", Convert.ToString(military.militaryDept));
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    conn.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("помилка при відправці даних даних (Військ.).");
            }
        }
Exemplo n.º 2
0
        //military info about employee
        public async Task <PersonMilitary> GetPersonMilitaryInfo(short emplid)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    PersonMilitary employee = new PersonMilitary();
                    await conn.OpenAsync();

                    SqlCommand    cmd    = new SqlCommand("EXECUTE hr.GetMilInfo " + emplid.ToString(), conn);
                    SqlDataReader reader = await cmd.ExecuteReaderAsync();

                    while (await reader.ReadAsync())
                    {
                        employee.emplId       = reader.GetInt16(0);
                        employee.series       = reader.GetString(1);
                        employee.serialNumber = reader.GetString(2);
                        employee.militaryDept = reader.GetString(3);
                        employee.militaryRank = reader.GetString(4);
                    }
                    reader.Close();
                    return(employee);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Помилка при завантаженні даних (військовозоб.).");
                return(null);
            }
        }