Exemplo n.º 1
0
        private void themPhuKien()
        {
            string tenphukien = cbTen.Text;

            using (quanlithucungEntities1 quanli = new quanlithucungEntities1()) {
                PHUKIEN pk = quanli.PHUKIENs.FirstOrDefault(p => p.Tenphukien.ToLower() == tenphukien.ToLower());
                if (pk == null)
                {
                    Console.WriteLine("aa");
                    quanli.insertCTPK(mapn, int.Parse(txtSoLuong.Text), double.Parse(txtGia.Text), tenphukien, cbLoai.SelectedValue.ToString(), null, txtdonvi.Text);

                    quanli.SaveChanges();
                    MessageBox.Show("Thêm thành công");
                }
                else
                {
                    pk.Soluong += int.Parse(txtSoLuong.Text);
                    CTNhapPhuKien pkm = new CTNhapPhuKien();
                    pkm.MaPN       = mapn;
                    pkm.MaPhuKien  = pk.Maphukien;
                    pkm.TenPhuKien = pk.Tenphukien;
                    pkm.MaLoai     = cbLoai.SelectedValue.ToString();
                    pkm.GiaNhap    = double.Parse(txtGia.Text);
                    pkm.Soluong    = int.Parse(txtSoLuong.Text);
                    pkm.Donvi      = txtdonvi.Text;
                    pkm.Anh        = pk.HinhAnh;
                    quanli.CTNhapPhuKiens.Add(pkm);
                    quanli.SaveChanges();
                    MessageBox.Show("Thêm thành công");
                }
            }
        }
Exemplo n.º 2
0
 private void btnSua_Click(object sender, EventArgs e)
 {
     using (quanlithucungEntities1 quanli = new quanlithucungEntities1())
     {
         CTNhapPhuKien sua = quanli.CTNhapPhuKiens.FirstOrDefault(p => p.MaPN == txtmaphieunhap.Text);
         sua.MaPN = txtmaphieunhap.Text;
         //sua.MaPhuKien = txtmaphukien.Text;
         sua.TenPhuKien = txttenphukien.Text;
         //sua.LoaiPhuKien = cbLoaiPhuKien.Text;
         sua.Soluong = int.Parse(txtSoluong.Text);
         sua.GiaNhap = double.Parse(txtGianhap.Text);
         quanli.SaveChanges();
         loaddulieu();
     }
 }
Exemplo n.º 3
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     using (quanlithucungEntities1 quanli = new quanlithucungEntities1())
     {
         CTNhapPhuKien them = new CTNhapPhuKien();
         them.MaPN = txtmaphieunhap.Text;
         //them.MaPhuKien = txtmaphukien.Text;
         //them.LoaiPhuKien = cbLoaiPhuKien.Text;
         them.TenPhuKien = txttenphukien.Text;
         them.Soluong    = int.Parse(txtSoluong.Text);
         them.GiaNhap    = double.Parse(txtGianhap.Text);
         quanli.CTNhapPhuKiens.Add(them);
         quanli.SaveChanges();
         loaddulieu();
     }
 }