Esempio n. 1
0
 private int Them_phongban(phongban Phongban)
 {
     try
     {
         using (SqlConnection connection =
                    new SqlConnection(@"Server=DESKTOP-27EV1LA\SQLEXPRESS; Database=quanlicanbo;
                            Integrated Security=SSPI"))
             using (SqlCommand command = new SqlCommand("INSERT INTO phongban(phongbanID,tenphongban) " + "VALUES(@phongbanID,@tenphongban);", connection))
             {
                 command.Parameters.Add("phongbanID", SqlDbType.NVarChar, 20).Value =
                     Phongban.phongbanID;
                 object dbTenSV = Phongban.tenphongban;
                 if (dbTenSV == null)
                 {
                     dbTenSV = DBNull.Value;
                 }
                 command.Parameters.Add("tenphongban", SqlDbType.NVarChar, 50).Value =
                     dbTenSV;
                 connection.Open();
                 return(command.ExecuteNonQuery());
             }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Loi khi mo ket noi:" + ex.Message);
         return(-1);
     }
 }
Esempio n. 2
0
 private void hienthi_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         List <phongban> DanhSachSinhVien = new List <phongban>();
         using (SqlConnection connection =
                    new SqlConnection(@"Server=DESKTOP-27EV1LA\SQLEXPRESS; Database=quanlicanbo;
                            Integrated Security=SSPI"))
             using (SqlCommand command =
                        new SqlCommand("SELECT phongbanID, tenphongban FROM phongban; ", connection))
             {
                 connection.Open();
                 using (SqlDataReader reader = command.ExecuteReader())
                 {
                     while (reader.Read())
                     {
                         var sv = new phongban();
                         sv.phongbanID  = reader.GetString(0);
                         sv.tenphongban = reader.GetString(1);
                         DanhSachSinhVien.Add(sv);
                     }
                 }
             }
         MessageBox.Show("Mo va dong co so du lieu thanh cong.");
         dulieu.ItemsSource = DanhSachSinhVien;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Loi khi mo ket noi: " + ex.Message);
     }
 }
Esempio n. 3
0
        private void Xoa_Click(object sender, RoutedEventArgs e)
        {
            phongban sv = new phongban();

            sv.phongbanID = txtID.Text;
            if (Xoa_phongban(sv) > 0)
            {
                MessageBox.Show("Du lieu duoc xoa thanh cong!");
            }
        }
Esempio n. 4
0
        private void Them_Click(object sender, RoutedEventArgs e)
        {
            phongban sv = new phongban();

            sv.phongbanID  = txtID.Text;
            sv.tenphongban = txtTen.Text;
            if (Them_phongban(sv) > 0)
            {
                MessageBox.Show("Du lieu duoc them thanh cong!");
            }
        }
Esempio n. 5
0
 private int Xoa_phongban(phongban Phongban)
 {
     try
     {
         using (SqlConnection connection =
                    new SqlConnection(@"Server=DESKTOP-27EV1LA\SQLEXPRESS; Database=quanlicanbo;
                            Integrated Security=SSPI"))
             using (SqlCommand command = new SqlCommand("DELETE FROM phongban " + "WHERE phongbanID = @phongbanID", connection))
             {
                 command.Parameters.Add("phongbanID", SqlDbType.NVarChar,
                                        20).Value = Phongban.phongbanID;
                 connection.Open();
                 return(command.ExecuteNonQuery());
             }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Loi khi mo ket noi:" + ex.Message);
         return(-1);
     }
 }