Ejemplo n.º 1
0
enum SetResponse itemCost::set(const ParameterList &pParams)
{
  _captive = true;

  QVariant param;
  bool     valid;

  param = pParams.value("mode", &valid);
  if (valid)
  {
    if (param.toString() == "new")
    {
      _mode = cNew;
      _lowerLevel->hide();
      _lowerLevelLit->hide();
      setWindowTitle("Create Item Cost");
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;
      _costelem->setEnabled(false);
      setWindowTitle("Enter Actual Cost");
    }
    else if (param.toString() == "view")
    {
      _actualCost->setEnabled(false);
      _costelem->setEnabled(false);
      setWindowTitle("View Actual Cost");
    }
  }
      
  param = pParams.value("item_id", &valid);
  if (valid)
  {
    _item->setId(param.toInt());
    _item->setReadOnly(TRUE);
    _actualCost->setFocus();
  }
  else
    _item->setFocus();

  param = pParams.value("itemcost_id", &valid);
  if (valid)
  {
    _itemcostid = param.toInt();
    _item->setReadOnly(TRUE);

    q.prepare( "SELECT item_id, formatBoolYN(itemcost_lowlevel) AS lowlevel,"
               "       itemcost_actcost, itemcost_curr_id, itemcost_updated "
               "FROM item, itemcost "
               "WHERE ( (itemcost_item_id=item_id)"
               " AND    (itemcost_id=:itemcost_id) );" );
    q.bindValue(":itemcost_id", _itemcostid);
    q.exec();
    if (q.first())
    {
      _item->setId(q.value("item_id").toInt());
      _lowerLevel->setText(q.value("lowlevel").toString());
      _actualCost->set(q.value("itemcost_actcost").toDouble(),
		       q.value("itemcost_curr_id").toInt(),
		       QDate::currentDate(),
		       false);
    }
    else if (q.lastError().type() != QSqlError::NoError)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }
  }

  sPopulateCostelem();

  return _foundCostElems ? NoError : UndefinedError;
}
Ejemplo n.º 2
0
enum SetResponse itemCost::set(const ParameterList &pParams)
{
  XSqlQuery itemet;
  XDialog::set(pParams);
  _captive = true;

  QVariant param;
  bool     valid;

  param = pParams.value("bomitem_id", &valid);
  if (valid)
  {
    _type = cBOMItemCost;
    _bomitemid = param.toInt();
    itemet.prepare( "SELECT bomitem_item_id "
               "FROM bomitem "
               "WHERE (bomitem_id=:bomitem_id);" );
    itemet.bindValue(":bomitem_id", _bomitemid);
    itemet.exec();
    if (itemet.first())
    {
      _item->setId(itemet.value("bomitem_item_id").toInt());
      _item->setReadOnly(true);
    }
  }

  param = pParams.value("bomitem_item_id", &valid);
  if (valid)
  {
    _type = cBOMItemCost;
    _item->setId(param.toInt());
    _item->setReadOnly(true);
  }

  param = pParams.value("bomitemcost_id", &valid);
  if (valid)
  {
    _type = cBOMItemCost;
    _itemcostid = param.toInt();
    _item->setReadOnly(true);

    itemet.prepare( "SELECT bomitem_item_id, formatBoolYN(bomitemcost_lowlevel) AS lowlevel,"
               "       bomitemcost_actcost, bomitemcost_curr_id, bomitemcost_updated "
               "FROM bomitem, bomitemcost "
               "WHERE ( (bomitemcost_bomitem_id=bomitem_id)"
               " AND    (bomitemcost_id=:bomitemcost_id) );" );
    itemet.bindValue(":bomitemcost_id", _itemcostid);
    itemet.exec();
    if (itemet.first())
    {
      _item->setId(itemet.value("bomitem_item_id").toInt());
      _lowerLevel->setText(itemet.value("lowlevel").toString());
      _actualCost->set(itemet.value("bomitemcost_actcost").toDouble(),
                       itemet.value("bomitemcost_curr_id").toInt(),
                       QDate::currentDate(),
                       false);
    }
    else if (itemet.lastError().type() != QSqlError::NoError)
    {
      systemError(this, itemet.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }
  }

  param = pParams.value("item_id", &valid);
  if (valid)
  {
    _type = cItemCost;
    _item->setId(param.toInt());
    _item->setReadOnly(true);
  }

  param = pParams.value("itemcost_id", &valid);
  if (valid)
  {
    _type = cItemCost;
    _itemcostid = param.toInt();
    _item->setReadOnly(true);

    itemet.prepare( "SELECT item_id, formatBoolYN(itemcost_lowlevel) AS lowlevel,"
               "       itemcost_actcost, itemcost_curr_id, itemcost_updated "
               "FROM item, itemcost "
               "WHERE ( (itemcost_item_id=item_id)"
               " AND    (itemcost_id=:itemcost_id) );" );
    itemet.bindValue(":itemcost_id", _itemcostid);
    itemet.exec();
    if (itemet.first())
    {
      _item->setId(itemet.value("item_id").toInt());
      _lowerLevel->setText(itemet.value("lowlevel").toString());
      _actualCost->set(itemet.value("itemcost_actcost").toDouble(),
		       itemet.value("itemcost_curr_id").toInt(),
		       QDate::currentDate(),
		       false);
    }
    else if (itemet.lastError().type() != QSqlError::NoError)
    {
      systemError(this, itemet.lastError().databaseText(), __FILE__, __LINE__);
      return UndefinedError;
    }
  }

  param = pParams.value("mode", &valid);
  if (valid)
  {
    if (param.toString() == "new")
    {
      _mode = cNew;
      _lowerLevel->hide();
      _lowerLevelLit->hide();
      if (_type == cItemCost)
        setWindowTitle("Create Item Cost");
      else
        setWindowTitle("Create BOM Item Cost");
    }
    else if (param.toString() == "edit")
    {
      _mode = cEdit;
      _costelem->setEnabled(false);
      if (_type == cItemCost)
        setWindowTitle("Enter Actual Cost");
      else
        setWindowTitle("Enter BOM Item Actual Cost");
    }
    else if (param.toString() == "view")
    {
      _actualCost->setEnabled(false);
      _costelem->setEnabled(false);
      _postCost->setEnabled(false);
      _save->hide();
      _close->setText("&Close");
      if (_type == cItemCost)
        setWindowTitle("View Actual Cost");
      else
        setWindowTitle("View BOM Item Actual Cost");
    }
  }

  sPopulateCostelem();

  return _foundCostElems ? NoError : UndefinedError;
}