// public bool ThemMoiPhieuNhap(PhieuNhap phieuNhap) { try { List <PhieuNhap> DanhSach = new List <PhieuNhap>(); OpenDataBase(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandText = "ThemMoiPhieuNhap"; sqlCommand.Parameters.Add("@MaPhieuNhap", SqlDbType.Char).Value = phieuNhap.MaPhieuNhap; sqlCommand.Parameters.Add("@MaNhanVien", SqlDbType.Char).Value = phieuNhap.NhanVien; sqlCommand.Parameters.Add("@MaNhaCungCap", SqlDbType.Char).Value = phieuNhap.NhaCungCap; sqlCommand.Parameters.Add("@NgayNhap", SqlDbType.DateTime).Value = phieuNhap.NgayNhap; sqlCommand.Connection = sqlConnection; int k = sqlCommand.ExecuteNonQuery(); return(k > 0); } catch (Exception ex) { throw ex; } }
//Thêm loại hóa đơn public Result InsertPN(string MaPN, string maNV, string ngayLap, string ghiChu) { if (checkPrimaryKeyMaHoaDon(MaPN) == false) { return(Result.PRIMARY_KEY); } try { PhieuNhap hd = new PhieuNhap(); hd.MaPN = MaPN; hd.MaNV = maNV; hd.GhiChu = ghiChu; hd.NgayLapPN = DateTime.Parse(ngayLap); hd.TongTienNhap = 0; qlch.PhieuNhaps.InsertOnSubmit(hd); qlch.SubmitChanges(); return(Result.SUCCESS); } catch { return(Result.FAILED); } }
public void insert(DTO_PhieuNhap obj) { using (CellphoneComponentEntities db = new CellphoneComponentEntities()) { var resultMaNhanVien = db.Database .SqlQuery <String>("select MaNhanVien from dbo.NhanVien where TenNhanVien = N'" + obj.TenNhanVien + "'") .FirstOrDefault(); var resultMaNhaCungCap = db.Database .SqlQuery <String>("select MaNhaCungCap from dbo.NhaCungCap where TenNhaCungCap = N'" + obj.TenNhaCungCap + "'") .FirstOrDefault(); PhieuNhap phieuNhap = new PhieuNhap(); phieuNhap.MaPhieuNhap = obj.MaPhieuNhap; phieuNhap.MaNhaCungCap = resultMaNhaCungCap; phieuNhap.MaNhanVien = resultMaNhanVien; phieuNhap.NgayChinhSua = obj.NgayChinhSua; phieuNhap.NgayNhap = obj.NgayNhap; phieuNhap.TongTien = obj.TongTien; phieuNhap.GhiChu = obj.GhiChu; db.PhieuNhaps.Add(phieuNhap); db.SaveChanges(); } }