Beispiel #1
0
 /// <summary>
 /// Chỉnh sửa lại cột STT khi có thao tác xóa trên ListView
 /// </summary>
 /// <param name="list">ListView Cần Chỉnh</param>
 public void SuaMaSoThanNhan(ListView list)
 {
     for (int i = 0; i < list.Items.Count; i++)
     {
         list.Items[i].Text = Convert.ToString(i + 1);
         ThanNhanInfo tn = (ThanNhanInfo)list.Items[i].Tag;
         tn.MaThanNhan     = Convert.ToInt32(list.Items[i].Text);
         list.Items[i].Tag = tn;
     }
 }
        public bool XoaRaKhoiCSDL(ThanNhanInfo tn)
        {
            String sql = "DELETE ThanNhan where MATHANNHAN=" + tn.MaThanNhan + " and MAKTX='" + tn.SinhVien.MaKTX + "'";

            try
            {
                SqlCommand command = new SqlCommand(sql);
                ser.Load(command);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
        public bool ThemVaoCSDL(ThanNhanInfo tn)
        {
            String sql = "Insert into ThanNhan(MATHANNHAN,MAKTX,HOTEN,NGHENGHIEP,QUANHE) VALUES(" +
                         "@mathannha,@maktx,@hoten,@nghenghiep,@quanhe)";
            SqlCommand command = new SqlCommand(sql);

            command.Parameters.Add("@mathannha", SqlDbType.Int).Value      = tn.MaThanNhan;
            command.Parameters.Add("@maktx", SqlDbType.NVarChar, 7).Value  = tn.SinhVien.MaKTX;
            command.Parameters.Add("@hoten", SqlDbType.NVarChar, 30).Value = tn.HoTenThanNhan;
            command.Parameters.Add("@nghenghiep", SqlDbType.Int).Value     = tn.NgheNghiep.MaNgheNghiep;
            command.Parameters.Add("@quanhe", SqlDbType.Int).Value         = tn.QuanHe.MaQuanHe;
            //try
            {
                ser.Load(command);
                return(true);
            }
            //catch (Exception e)
            {
                //  e.ToString();
                return(false);
            }
        }