51 lines
979 B
Go
51 lines
979 B
Go
package database
|
|
|
|
import "database/sql"
|
|
|
|
func RemoveFromBinder(db *sql.DB, location LocateCardResult) error {
|
|
query := `UPDATE CardLocation SET CardPrintingId = NULL WHERE Id = ?;`
|
|
|
|
update, err := db.Prepare(query)
|
|
defer update.Close()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = update.Exec(location.CardLocationId)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func RemoveFromBox(db *sql.DB, location LocateCardResult) error {
|
|
deleteQuery := `DELETE FROM CardLocation WHERE Id = ?;`
|
|
|
|
del, err := db.Prepare(deleteQuery)
|
|
defer del.Close()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = del.Exec(location.CardLocationId)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
updateQuery := `UPDATE CardLocation SET Position = Position - 1 WHERE Position > ? AND StorageAreaId = ?;`
|
|
|
|
update, err := db.Prepare(updateQuery)
|
|
defer update.Close()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = update.Exec(location.Position, location.StorageAreaId)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|