예제 #1
0
        private void BtnLuuPhieuNhap_Click(object sender, RoutedEventArgs e)
        {
            if (ctpn.Count > 0)
            {
                NhaCungCapController nhaCungCap = new NhaCungCapController();
                PhieuNhapController  phieuNhap  = new PhieuNhapController();
                NguyenLieuController nguyenLieu = new NguyenLieuController();
                int      mancc    = nhaCungCap.NameToId(cbbNhaCungCap.Text);
                DateTime ngayNhap = DateTime.Now;
                int      tongTien = Convert.ToInt32(txtTongTien.Text);

                try
                {
                    phieuNhap.Create(manv, mancc, ngayNhap, txtGhiChuPN.Text, tongTien);

                    int maPN = phieuNhap.GetLastId();

                    foreach (var item in ctpn)
                    {
                        int      maNL = nguyenLieu.NameToId(item.TenNL);
                        DateTime hsd  = Convert.ToDateTime(item.HanSuDung);
                        phieuNhap.CreateDetails(maPN, maNL, hsd, item.SoLuongNhap, item.Gia, item.GhiChu);
                    }

                    MessageBox.Show("Lưu phiếu nhập thành công!", "Thông báo!", MessageBoxButton.OK, MessageBoxImage.Information);

                    ctpn.Clear();
                    cbbTenNguyenLieu.IsEnabled     = false;
                    cbbTenNguyenLieu.SelectedIndex = 0;
                    txtSoLuongNhap.IsEnabled       = false;
                    txtSoLuongNhap.Text            = "";
                    dtpHanSuDung.IsEnabled         = false;
                    dtpHanSuDung.SelectedDate      = DateTime.Now;
                    txtGia.IsEnabled    = false;
                    txtGia.Text         = "";
                    txtGhiChu.IsEnabled = false;
                    txtGhiChu.Text      = "";

                    LoadDSPhieuNhap();

                    txtGhiChuPN.Text = "";
                    tongTien         = 0;
                    txtTongTien.Text = tongTien.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }