コード例 #1
0
ファイル: frmNhapHang.cs プロジェクト: trinhhoangthong1/BTPM1
        void ThemMoi()
        {
            DataRow row = ctrl.NewRow();

            row["ID"]              = txtMaPhieu.Text;
            row["NGAY_NHAP"]       = dtNgayNhap.Value.Date;
            row["TONG_TIEN"]       = numTongTien.Value;
            row["ID_NHA_CUNG_CAP"] = cmbNhaCungCap.SelectedValue;
            row["DA_TRA"]          = numDaTra.Value;
            row["CON_NO"]          = numConNo.Value;
            ctrl.Add(row);

            PhieuNhapController ctrlPN = new PhieuNhapController();

            if (ctrlPN.LayPhieuNhap(txtMaPhieu.Text) != null)
            {
                MessageBox.Show("Mã Phiếu nhập này đã tồn tại !", "Phieu Nhap", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (ThamSo.LaSoNguyen(txtMaPhieu.Text))
            {
                long so = Convert.ToInt64(txtMaPhieu.Text);
                if (so >= ThamSo.LayMaPhieuNhap())
                {
                    ThamSo.GanMaPhieuNhap(so + 1);
                }
            }

            ctrl.Save();
            ctrlMaSP.Save();

            SanPhamController ctrlSP = new SanPhamController();

            foreach (DataGridViewRow view in dataGridView.Rows)
            {
                ctrlSP.CapNhatGiaNhap(Convert.ToString(view.Cells["colSanPham"].Value),
                                      Convert.ToInt64(view.Cells["colDonGiaNhap"].Value),
                                      Convert.ToInt64(view.Cells["colSoLuong"].Value));
            }
        }