Exemple #1
0
        public void NhapHang(NhapHangDTO info)
        {
            string sql = $"INSERT INTO HoaDonNhapHang VALUES(N'{info.SoHoaDon}', N'{info.Msnv}', N'{info.NgayNhap}', N'{info.NhaCungCap}', N'{info.DiaChi}', N'{info.Thue}', N'{info.TongTien}', N'{info.GhiChu}')";
            _dbconnection.ExcuteNonQuery(sql);

            foreach (DataRow row in info.ChiTiet.Rows)
            {
                _dbconnection.ExcuteNonQuery($"INSERT INTO ChiTietDonNhapHang VALUES(N'{info.SoHoaDon}', N'{row.Field<string>("TenHangHoa")}', N'{row.Field<string>("GiaMua")}', N'{row.Field<string>("SoLuong")}', N'{row.Field<string>("ThanhTien")}')");
                _dbconnection.ExcuteNonQuery($"UPDATE HangHoa SET SoLuongTon=SoLuongTon + {row.Field<string>("SoLuong")} WHERE TenHangHoa=N'{row.Field<string>("TenHangHoa")}'");
            }
        }
Exemple #2
0
        private void btnNhap_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView2.Rows)
            {
                row.Cells[1].ErrorText = row.Cells[1].Value == DBNull.Value ? "Nhập thông tin" : string.Empty;
                row.Cells[2].ErrorText = row.Cells[2].Value == DBNull.Value ? "Nhập thông tin" : string.Empty;
            }

            foreach (var c in from MaterialSingleLineTextField c in tabNhapHang.Controls.OfType<MaterialSingleLineTextField>() where c != txtGhiChuHoaDon select c)
                errorProvider1.SetError(c, string.IsNullOrWhiteSpace(c.Text) ? "Bạn không được để trống thông tin này" : string.Empty);

            if (dataGridView2.Rows.Count == 0 || tabNhapHang.Controls.OfType<MaterialSingleLineTextField>().Any(c => errorProvider1.GetError(c) != string.Empty) || dataGridView2.Rows.Cast<DataGridViewRow>().Any(row => row.Cells[1].ErrorText != string.Empty || row.Cells[2].ErrorText != string.Empty)) return;

            try
            {
                NhapHangDTO info = new NhapHangDTO
                {
                    SoHoaDon = txtSoHoaDon.Text,
                    Msnv = QuanLy.MsnvLogin,
                    NgayNhap = dtpNgayNhap.Value,
                    NhaCungCap = txtNhaCungCap.Text,
                    DiaChi = txtDiaChi.Text,
                    ChiTiet = dtChiTiet,
                    Thue = nudThue.Value,
                    TongTien = int.Parse(lblTongTien.Text, NumberStyles.AllowThousands, CultureInfo.CreateSpecificCulture("vi-VN")),
                    GhiChu = txtGhiChuHoaDon.Text
                };

                using (NhapHangBUS nhaphangBUS = new NhapHangBUS())
                    nhaphangBUS.NhapHang(info);
            }
            catch (SqlException ex)
            {
                if (ex.Number == DbConnection.MssqlEng002627)
                    errorProvider1.SetError(txtSoHoaDon, "Số hóa đơn đã tồn tại trong CSDL");
                else throw;
            }

            RefreshHangHoa();
        }
Exemple #3
0
 public void NhapHang(NhapHangDTO info)
 {
     _nhaphangDAO.NhapHang(info);
 }