Example #1
0
        private void txtMaHang_TextChanged(object sender, EventArgs e)
        {
            if (kiemTraTonTai(txtMaHang.Text) != null)
            {
                Hang h = kiemTraTonTai(txtMaHang.Text);

                txtTenHang.Text   = h.TenHang;
                txtDonViTinh.Text = h.DonViTinh;
                txtDonGia.Text    = h.DonGia.ToString();

                cboLoai.DataSource    = bulLoaiHang.layDanhSachMaLoaiHang(txtMaHang.Text);
                cboLoai.DisplayMember = "TenLoai";
                cboLoai.ValueMember   = "MaLoai";
                int vt = -1;
                for (int i = 0; i < bulLoaiHang.layDanhSachMaLoaiHang(txtMaHang.Text).Count; i++)
                {
                    if (bulLoaiHang.layDanhSachMaLoaiHang(txtMaHang.Text)[i].MaLoai.Contains(h.MaLoai))
                    {
                        vt = i;
                        break;
                    }
                }
                cboLoai.SelectedIndex = vt;

                txtSoLuongCo.Text = h.SoLuongCo.ToString();

                cboNCC.DataSource    = bulNhaCungCap.layDanhSachMaNCC(txtMaHang.Text);
                cboNCC.DisplayMember = "TenNhaCungCap";
                cboNCC.ValueMember   = "MaNhaCungCap";
                for (int i = 0; i < bulNhaCungCap.layDanhSachMaNCC(txtMaHang.Text).Count; i++)
                {
                    if (bulNhaCungCap.layDanhSachMaNCC(txtMaHang.Text)[i].MaNhaCungCap.Contains(h.MaNhaCungCap))
                    {
                        vt = i;
                        break;
                    }
                }
                cboNCC.SelectedIndex = vt;

                txtTenHang.Enabled   = false;
                txtDonViTinh.Enabled = false;
                txtDonGia.Enabled    = false;
                cboLoai.Enabled      = false;
                txtSoLuongCo.Enabled = false;
                cboNCC.Enabled       = false;
                btnXoaHang.Enabled   = true;
            }
            else
            {
                Hang h = kiemTraTonTai(txtMaHang.Text);

                txtTenHang.Text   = "";
                txtDonViTinh.Text = "";
                txtDonGia.Text    = "";
                //cboLoai.SelectedValue = "";
                txtSoLuongCo.Text = "";
                //cboNCC.SelectedValue = "";
                btnXoaHang.Enabled = false;
            }
        }
Example #2
0
 private void frmThemHang_Load(object sender, EventArgs e)
 {
     cboLoai.DataSource    = bulLoaiHang.layDanhSachMaLoaiHang(txtMaHang.Text);
     cboLoai.DisplayMember = "TenLoai";
     cboLoai.ValueMember   = "MaLoai";
     cboNCC.DataSource     = bulNhaCungCap.layDanhSachMaNCC(txtMaHang.Text);
     cboNCC.DisplayMember  = "TenNhaCungCap";
     cboNCC.ValueMember    = "MaNhaCungCap";
     while (true)
     {
         Random rd = new Random();
         string ma = "MH";
         int    n  = rd.Next(0, 1000);
         ma = ma + n;
         if (!kiemTraTonTai(ma))
         {
             txtMaHang.Text = ma;
             break;
         }
     }
 }