예제 #1
0
 /// <summary>
 ///     Inserts the specified value.
 /// </summary>
 /// <param name="value">The value.</param>
 public void Insert(SanPhamModel value)
 {
     try
     {
         var entity = value.ToEntity();
         sanPhamService.Insert(entity);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message,
                         Resources.Insert_Fault, MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }
        public void SaveHoaDonNhap(HoaDonNhapModel value)
        {
            var sanPhamCtrl = app.Resolve <ISanPhamController <SanPhamModel> >();

            var hdEntity = value.ToEntity();

            hdEntity.NhanVienID   = nhanVienService.GetByMa(hdEntity.MaNV).ID;
            hdEntity.NhaCungCapID = nhaCungCapService.GetByMa(hdEntity.MaNCC).ID;

            hoaDonNhapService.Insert(hdEntity);

            foreach (var hds in value.ChiTietHDNModel)
            {
                if (hds.SanPham != null)
                {
                    var sp = hds.SanPham;
                    sp.DonGiaBan  = (hds.DonGia + Math.Round(hds.DonGia * (decimal)0.1));
                    sp.DonGiaNhap = hds.DonGia;
                    sp.SoLuong    = hds.SoLuong;
                    sanPhamService.Insert(sp);
                    hds.SanPhamID = sp.ID;
                }
                else
                {
                    var sp = sanPhamService.GetByMa(hds.MaGiayDep);
                    sp.DonGiaBan  = (hds.DonGia + Math.Round(hds.DonGia * (decimal)0.1));
                    sp.DonGiaNhap = hds.DonGia;
                    sp.SoLuong    = sp.SoLuong + hds.SoLuong;

                    hds.SanPhamID = sp.ID;

                    sanPhamService.Update(sp);
                }
                hds.SoHDN        = hdEntity.SoHDN;
                hds.HoaDonNhapID = hdEntity.ID;
                chiTietHdnService.Insert(hds.ToEntity());
            }
            // update UI on SanPham View
            hoaDonNhapView.HideForm();
            sanPhamCtrl.ReviewGrid();
            PostView();
        }