private void btn_them_Click(object sender, EventArgs e)
 {
     int Curr = dataLoaiSanh.CurrentCell.RowIndex;
     if (Curr + 2 >= dataLoaiSanh.Rows.Count)
     {
         try
         {
             string loaisanh = Convert.ToString(dataLoaiSanh.Rows[Curr].Cells[1].Value.ToString());
             int dongiamonan = (int)(dataLoaiSanh.Rows[Curr].Cells[2].Value);
             Sanh s = new Sanh(0, loaisanh, dongiamonan);
             if (objsanh.Themsanh(s))
             {
                 MessageBox.Show("Thêm thành công");
                 listSanh.DataSource = objsanh.GetDanhMuc();
                 dataLoaiSanh.DataSource = objsanh.GetLoaiSanh();
             }
             else
             {
                 MessageBox.Show("Thêm thất bại");
             }
         }
         catch
         {
             MessageBox.Show("Nhập Đầy Đủ Thông Tin");
         }
     }
 }
 private void btn_thoat_Click(object sender, EventArgs e)
 {
     int Curr = dataLoaiSanh.CurrentCell.RowIndex;
     int maloaisanh = (int)dataLoaiSanh.Rows[Curr].Cells[0].Value;
     string loaisanh = Convert.ToString(dataLoaiSanh.Rows[Curr].Cells[1].Value.ToString());
     int dongiamonan = (int)dataLoaiSanh.Rows[Curr].Cells[2].Value;
     Sanh s = new Sanh(maloaisanh, loaisanh, dongiamonan);
     if (objsanh.UpdateSanh(s))
     {
         MessageBox.Show("Cập nhật thành công");
         listSanh.DataSource = objsanh.GetDanhMuc();
         dataLoaiSanh.DataSource = objsanh.GetLoaiSanh();
     }
     else
     {
         MessageBox.Show("Cập nhật thất bại");
     }
 }
Esempio n. 3
0
 public Sanh GetloaisanhByMALS(string strLS)
 {
     Sanh s = null;
     try
     {
         if (conn.State != ConnectionState.Open) conn.Open();
         OleDbCommand cmd = new OleDbCommand("SELECT LOAISANH.MaLoaiSanh,SANH.TenSanh, LOAISANH.TenLoaiSanh, SANH.SoLuongBanToiDa, LOAISANH.DonGiaBanToiThieu, SANH.GhiChu FROM LOAISANH INNER JOIN SANH ON LOAISANH.MaLoaiSanh = SANH.MaLoaiSanh where LOAISANH.MaLoaiSanh=@mals", conn);
         cmd.Parameters.Add("@mals", OleDbType.BSTR).Value = strLS;
         OleDbDataReader rd = cmd.ExecuteReader();
         if (rd.Read())
         {
             s = new Sanh();
             s.TenSanh = rd["TenSanh"].ToString();
             s.TenLoaiSanh = rd["TenLoaiSanh"].ToString();
             s.SLBanToiDa = (int)rd["SoLuongBanToiDa"];
             s.DGBanToiThieu = (int)rd["DonGiaBanToiThieu"];
             s.GhiChu = rd["GhiChu"].ToString();
             rd.Close();
         }
     }
     catch (Exception e)
     {
         conn.Close();
     }
     return s;
 }
Esempio n. 4
0
        public bool UpdateSanh(Sanh sanh)
        {
            try
            {
                if (conn.State != ConnectionState.Open) conn.Open();
                string strcmd = "UPDATE LOAISANH SET TenLoaiSanh='" + sanh.TenLoaiSanh + "', DonGiaBanToiThieu='" + sanh.DGBanToiThieu.ToString() + "' where MaLoaiSanh=" + sanh.MaLoaiSanh;
                OleDbCommand cmd = new OleDbCommand(strcmd, conn);
                cmd.ExecuteNonQuery();
                conn.Close();
                return true;
            }

            catch (Exception e)
            {
                conn.Close();
                return false;
            }
        }
Esempio n. 5
0
 public bool ThemSanh(Sanh sanh)
 {
     try
     {
         if (conn.State != ConnectionState.Open) conn.Open();
         OleDbCommand cmd = new OleDbCommand("INSERT INTO LOAISANH([TenLoaiSanh],[DonGiaBanToiThieu]) VALUES (@tenloaisanh,@dongia)", conn);
         cmd.Parameters.Add("@tenloaisanh", OleDbType.BSTR).Value = sanh.TenLoaiSanh;
         cmd.Parameters.Add("@dongia", OleDbType.BSTR).Value = sanh.DGBanToiThieu;
         cmd.ExecuteNonQuery();
         conn.Close();
         return true;
     }
     catch (Exception e)
     {
         conn.Close();
         return false;
     }
 }
Esempio n. 6
0
 public bool UpdateSanh(Sanh s)
 {
     return objDM.UpdateSanh(s);
 }
Esempio n. 7
0
 public bool Themsanh(Sanh s)
 {
     return objDM.ThemSanh(s);
 }