public int insertChiTietHoaDonNhap(BKIT.Entities.ChiTietHoaDonNhap objChiTietHoaDonNhap)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "INSERT INTO ChiTietHoaDonNhap(IDChiTietHoaDonNhap,IDHoaDonNhap,IDSanPham,SoLuong,GiaNhap) " +
                                  "VALUES (@idchitiethoadonnhap,@idhoadonnhap,@idsanpham,@soluong,@gianhap)";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                int ID = GetNextAVailableID();
                objChiTietHoaDonNhap.IDChiTietHoaDonNhap = ID;
                db.AddInParameter(dbCommand, "idchitiethoadonnhap", DbType.Int32, objChiTietHoaDonNhap.IDChiTietHoaDonNhap);
                db.AddInParameter(dbCommand, "idhoadonnhap", DbType.Int32, objChiTietHoaDonNhap.IDHoaDonNhap);
                db.AddInParameter(dbCommand, "idsanpham", DbType.Int32, objChiTietHoaDonNhap.IDSanPham);
                db.AddInParameter(dbCommand, "soluong", DbType.Int32, objChiTietHoaDonNhap.SoLuong);
                db.AddInParameter(dbCommand, "gianhap", DbType.Decimal, objChiTietHoaDonNhap.GiaNhap);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(ID);
            }
            catch
            {
                dbCommand.Connection.Close();
                return(-1);
            }
        }
        public bool deleteChiTietHoaDonNhap(BKIT.Entities.ChiTietHoaDonNhap objChiTietHoaDonNhap)
        {
            Database  db         = DatabaseFactory.CreateDatabase();
            string    sqlCommand = "DELETE FROM ChiTietHoaDonNhap WHERE IDChiTietHoaDonNhap = @idchitiethoadonnhap";
            DbCommand dbCommand  = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "idchitiethoadonnhap", DbType.Int32, objChiTietHoaDonNhap.IDChiTietHoaDonNhap);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public bool updateChiTietHoaDonNhap(BKIT.Entities.ChiTietHoaDonNhap objChiTietHoaDonNhap)
        {
            Database db         = DatabaseFactory.CreateDatabase();
            string   sqlCommand = "UPDATE ChiTietHoaDonNhap SET IDHoaDonNhap = @idhoadonnhap, IDSanPham = @idsanpham, SoLuong = @soluong, GiaNhap = @gianhap " +
                                  "WHERE IDChiTietHoaDonNhap = @idchitiethoadonnhap";
            DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);

            try
            {
                db.AddInParameter(dbCommand, "idhoadonnhap", DbType.Int32, objChiTietHoaDonNhap.IDHoaDonNhap);
                db.AddInParameter(dbCommand, "idsanpham", DbType.Int32, objChiTietHoaDonNhap.IDSanPham);
                db.AddInParameter(dbCommand, "soluong", DbType.Int32, objChiTietHoaDonNhap.SoLuong);
                db.AddInParameter(dbCommand, "gianhap", DbType.Decimal, objChiTietHoaDonNhap.GiaNhap);
                db.AddInParameter(dbCommand, "idchitiethoadonnhap", DbType.Int32, objChiTietHoaDonNhap.IDChiTietHoaDonNhap);
                db.ExecuteNonQuery(dbCommand);
                dbCommand.Connection.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#4
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     //save Hoa Don
     HoaDonNhap objHoaDonNhap = new HoaDonNhap();
     objHoaDonNhap.Ngay = dateNgay.DateTime;
     objHoaDonNhap.IDNhanvien = arrIDNhanvien[cboNhanvien.SelectedIndex];
     objHoaDonNhap.Ghichu = txtGhiChu.Text;
     int IDHoaDonNhap = new DataAccess().insertHoaDonNhap(objHoaDonNhap);
     if (IDHoaDonNhap >= 0)
     {
         foreach (DataRow aRow in table.Rows)
         {
             ChiTietHoaDonNhap objChiTiet = new ChiTietHoaDonNhap();
             objChiTiet.IDHoaDonNhap = IDHoaDonNhap;
             objChiTiet.IDSanPham = Convert.ToInt32(aRow["IDSanPham"]);
             objChiTiet.GiaNhap = Convert.ToDecimal(aRow["GiaNhap"]);
             objChiTiet.SoLuong = Convert.ToInt32(aRow["SoLuong"]);
             if (new DataAccess().insertChiTietHoaDonNhap(objChiTiet) < 0)
             {
                 //error
                 MessageBox.Show(this, "Thêm mới Chi tiết hóa đơn nhập không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 //delete
                 new DataAccess().deleteHoaDonNhap(objHoaDonNhap);
             }
         }
     }
     else
     {
         //error
         MessageBox.Show(this, "Thêm mới Hóa đơn nhập không thành công", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     btnAddChiTietHD.Enabled = false;
     btnSave.Enabled = false;
     btnClear.Enabled = true;
 }
示例#5
0
 public bool updateChiTietHoaDonNhap(ChiTietHoaDonNhap objChiTietHoaDonNhap)
 {
     return new ChiTietHoaDonNhapService().updateChiTietHoaDonNhap(objChiTietHoaDonNhap);
 }
示例#6
0
 public int insertChiTietHoaDonNhap(ChiTietHoaDonNhap objChiTietHoaDonNhap)
 {
     return new ChiTietHoaDonNhapService().insertChiTietHoaDonNhap(objChiTietHoaDonNhap);
 }
示例#7
0
 public bool deleteChiTietHoaDonNhap(ChiTietHoaDonNhap objChiTietHoaDonNhap)
 {
     return new ChiTietHoaDonNhapService().deleteChiTietHoaDonNhap(objChiTietHoaDonNhap);
 }