コード例 #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (IDHoaDonNhap != null && IDChiTietHDN != null)
     {
         DialogResult dialogResult = MessageBox.Show(this, "Are you sure ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (dialogResult == DialogResult.Yes)
         {
             ChiTietHDN dltChiTietHDN = dbAddNew.ChiTietHDNs.Where(p => p.MaHDN == (txtIdImport.Text).ToString()).SingleOrDefault();
             HoaDonNhap dltHoaDonNhap = dbAddNew.HoaDonNhaps.Where(p => p.MaHDN == (txtIdImport.Text).ToString()).SingleOrDefault();
             dbAddNew.ChiTietHDNs.Remove(dltChiTietHDN);
             dbAddNew.HoaDonNhaps.Remove(dltHoaDonNhap);
             dbAddNew.SaveChanges();
             renewPanel();
         }
     }
     else
     {
         MessageBox.Show(this, "Please select row to delele", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (state == 1)
            {
                chiTietHDN.MaSanPham = txtIdProduct.Text;
                var product = dbAddNew.SanPhams.Find(chiTietHDN.MaSanPham);
                if (product == null)
                {
                    MessageBox.Show(this, "This product isn't exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    /*chiTietHDN.MaHDN = txtIdImport.Text;
                     *
                     * chiTietHDN.SoLuong = Convert.ToInt32(txtQuantity.Text);
                     * chiTietHDN.KhuyenMai = Convert.ToDouble(txtPromo.Text);
                     * chiTietHDN.ThanhTien = Convert.ToDouble((lbAllPrice.Text));
                     * chiTietHDN.DonGia = Convert.ToDouble(txtUnitPrice.Text);
                     *
                     * hoaDonNhap.MaHDN = txtIdImport.Text;
                     * hoaDonNhap.MaNCC = txtIdSupplier.Text;
                     * hoaDonNhap.MaNhanVien = txtIdSaler.Text;
                     * hoaDonNhap.NgayNhap = DateTime.Now;
                     * hoaDonNhap.TongTien = Convert.ToDouble(lbTotalPrice.Text);
                     *
                     * dbAddNew.ChiTietHDNs.Add(chiTietHDN);
                     * dbAddNew.SaveChanges();
                     * dbAddNew.HoaDonNhaps.Add(hoaDonNhap);
                     * dbAddNew.SaveChanges();*/
                    renewPanel();
                }
                else
                {
                    /*ChiTietHDN editChiTietHDN = dbAddNew.ChiTietHDNs.Find(chiTietHDN.MaSanPham);*/
                    /*MessageBox.Show(IDChiTietHDN.ToString() + " " + IDHoaDonNhap.ToString());*/
                    SanPham updateSanPham = dbAddNew.SanPhams.Find(chiTietHDN.MaSanPham);

                    chiTietHDN.MaHDN = txtIdImport.Text;

                    chiTietHDN.SoLuong   = Convert.ToInt32(txtQuantity.Text);
                    chiTietHDN.KhuyenMai = Convert.ToDouble(txtPromo.Text);
                    chiTietHDN.ThanhTien = Convert.ToDouble((lbAllPrice.Text));
                    chiTietHDN.DonGia    = Convert.ToDouble(txtUnitPrice.Text);

                    hoaDonNhap.MaHDN      = txtIdImport.Text;
                    hoaDonNhap.MaNCC      = txtIdSupplier.Text;
                    hoaDonNhap.MaNhanVien = txtIdSaler.Text;
                    hoaDonNhap.NgayNhap   = DateTime.Now;
                    hoaDonNhap.TongTien   = Convert.ToDouble(lbTotalPrice.Text);

                    dbAddNew.ChiTietHDNs.Add(chiTietHDN);
                    dbAddNew.SaveChanges();
                    dbAddNew.HoaDonNhaps.Add(hoaDonNhap);
                    dbAddNew.SaveChanges();

                    updateSanPham.SoLuong += Convert.ToInt32(txtQuantity.Text);
                    updateSanPham.GiaNhap  = Convert.ToDouble(txtUnitPrice.Text);
                    updateSanPham.GiaBan   = Convert.ToDouble(txtUnitPrice.Text) * 1.1;

                    dbAddNew.SaveChanges();
                    renewPanel();
                }
            }
            if (state == 2)
            {
                ChiTietHDN editChiTietHDN = dbAddNew.ChiTietHDNs.Find(IDChiTietHDN);
                /*MessageBox.Show(IDChiTietHDN.ToString() + " " + IDHoaDonNhap.ToString());*/
                HoaDonNhap editHoaDonNhap = dbAddNew.HoaDonNhaps.Find(IDHoaDonNhap);

                editChiTietHDN.MaHDN     = txtIdImport.Text;
                editChiTietHDN.MaSanPham = txtIdProduct.Text;
                editChiTietHDN.SoLuong   = Convert.ToInt32(txtQuantity.Text);
                editChiTietHDN.DonGia    = Convert.ToDouble(txtUnitPrice.Text);
                editChiTietHDN.KhuyenMai = Convert.ToDouble(txtPromo.Text);
                editChiTietHDN.ThanhTien = Convert.ToDouble(lbTotalPrice.Text);

                editHoaDonNhap.MaHDN      = txtIdImport.Text;
                editHoaDonNhap.MaNCC      = txtIdSupplier.Text;
                editHoaDonNhap.MaNhanVien = txtIdSaler.Text;
                editHoaDonNhap.NgayNhap   = Convert.ToDateTime(lbDate.Text);
                editHoaDonNhap.TongTien   = Convert.ToDouble(lbAllPrice.Text);

                dbAddNew.SaveChanges();
                renewPanel();
            }
        }