public bool InsertChiTietPhieuNhap(ChiTietPhieuNhap chiTiet)
        {
            ChiTietPhieuNhapDAL dAL = new ChiTietPhieuNhapDAL();
            var data = dAL.InsertChiTietPhieuNhap(chiTiet);

            DatabaseDAL.CloseConnection();
            return(data);
        }
Example #2
0
        public bool InsertPhieuNhapKho(PhieuNhapKho phieuNhap, DataGridView dataGridView)
        {
            bool                result              = false;
            PhieuNhapDAL        phieuNhapDAL        = new PhieuNhapDAL();
            ChiTietPhieuNhapDAL chiTietPhieuNhapDAL = new ChiTietPhieuNhapDAL();

            try
            {
                if (!DatabaseDAL.TestConnection())
                {
                    DatabaseDAL.CreatConn();
                }
                DatabaseDAL.Transaction();
                try
                {
                    result = phieuNhapDAL.InsertPhieuNhapHang(phieuNhap);
                    for (int i = 0; i < dataGridView.RowCount; i++)
                    {
                        if (dataGridView.Rows[i].Cells["STT"].Value != null)
                        {
                            ChiTietPhieuNhap chiTietPhieu = new ChiTietPhieuNhap();
                            chiTietPhieu.SoChungTu   = phieuNhap.SoChungTu;
                            chiTietPhieu.MaHang      = dataGridView.Rows[i].Cells["MaHang"].Value?.ToString();
                            chiTietPhieu.TenHang     = dataGridView.Rows[i].Cells["TenHang"].Value?.ToString();
                            chiTietPhieu.DonViTinh   = dataGridView.Rows[i].Cells["DonVitinh"].Value?.ToString();
                            chiTietPhieu.SoLuongNhap = Convert.ToInt32(dataGridView.Rows[i].Cells["SoLuongNhap"].Value?.ToString());
                            chiTietPhieu.DonGia      = Convert.ToInt32(dataGridView.Rows[i].Cells["DonGia"]?.Value?.ToString());
                            chiTietPhieu.ThanhTien   = Convert.ToDecimal(dataGridView.Rows[i].Cells["ThanhTien"].Value?.ToString());
                            if (!isEmptyOrNullOrSpecialCharacters(chiTietPhieu.SoChungTu) && !isEmptyOrNullOrSpecialCharacters(chiTietPhieu.MaHang) && !isEmptyOrNullOrSpecialCharacters(chiTietPhieu.TenHang) && !isEmptyOrNullOrSpecialCharacters(chiTietPhieu.DonViTinh) && !isEmptyOrNotNumber(chiTietPhieu.SoLuongNhap) && !isEmptyOrNotNumber(chiTietPhieu.DonGia) && !isEmptyOrNotNumber(chiTietPhieu.ThanhTien))
                            {
                                if (!isBelongToNSX(chiTietPhieu.MaHang, phieuNhap.MaNSX))
                                {
                                    DatabaseDAL.Rollback();
                                    return(false);
                                }
                                result = chiTietPhieuNhapDAL.InsertChiTietPhieuNhap(chiTietPhieu);
                            }
                        }
                    }
                    DatabaseDAL.Commit();
                    DatabaseDAL.CloseConnection();
                    return(result);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    DatabaseDAL.Rollback();
                    DatabaseDAL.CloseConnection();
                    return(false);
                }
            }
            catch (Exception e)
            {
                DatabaseDAL.CloseConnection();
                MessageBox.Show(e.Message);
                return(false);
            }
        }