2024-09-12 12:37:41 +00:00
|
|
|
package database
|
|
|
|
|
|
|
|
import "database/sql"
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
func RemoveFromBinder(db *sql.DB, location LocateCardResult) error {
|
2024-09-13 19:05:28 +00:00
|
|
|
query := `UPDATE CardLocation SET CardPrintingId = NULL WHERE Id = ?;`
|
2024-09-12 12:37:41 +00:00
|
|
|
|
|
|
|
update, err := db.Prepare(query)
|
|
|
|
defer update.Close()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
_, err = update.Exec(location.CardLocationId)
|
2024-09-12 12:37:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
func RemoveFromBox(db *sql.DB, location LocateCardResult) error {
|
2024-09-13 19:05:28 +00:00
|
|
|
deleteQuery := `DELETE FROM CardLocation WHERE Id = ?;`
|
2024-09-12 12:37:41 +00:00
|
|
|
|
|
|
|
del, err := db.Prepare(deleteQuery)
|
|
|
|
defer del.Close()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
_, err = del.Exec(location.CardLocationId)
|
2024-09-12 12:37:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-09-13 19:05:28 +00:00
|
|
|
updateQuery := `UPDATE CardLocation SET Position = Position - 1 WHERE Position > ? AND StorageAreaId = ?;`
|
2024-09-12 12:37:41 +00:00
|
|
|
|
|
|
|
update, err := db.Prepare(updateQuery)
|
|
|
|
defer update.Close()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-09-13 11:32:18 +00:00
|
|
|
_, err = update.Exec(location.Position, location.StorageAreaId)
|
2024-09-12 12:37:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|