Пример #1
0
  void handleFinish(DialogCode result)
  {
    if (result == WDialog::Accepted) {
      /*
       * Update the model with data from the edit widgets.
       *
       * You will want to do some validation here...
       *
       * Note that we directly update the source model to avoid
       * problems caused by the dynamic sorting of the proxy model,
       * which reorders row numbers, and would cause us to switch to editing
       * the wrong data.
       */
      WAbstractItemModel *m = model_;
      int modelRow = item_.row();

      WAbstractProxyModel *proxyModel = dynamic_cast<WAbstractProxyModel *>(m);
      if (proxyModel) {
	m = proxyModel->sourceModel();
	modelRow = proxyModel->mapToSource(item_).row();
      }

      m->setData(modelRow, 1, boost::any(nameEdit_->text()));
      m->setData(modelRow, 2, boost::any(typeEdit_->currentText()));
      m->setData(modelRow, 3, boost::any(boost::lexical_cast<int>
					 (sizeEdit_->text().toUTF8())));
      m->setData(modelRow, 4, boost::any(createdPicker_->date()));
      m->setData(modelRow, 5, boost::any(modifiedPicker_->date()));
    }

    delete this;
  }
Пример #2
0
void PriceEditDialog::handleFinish(DialogCode result)
{
    if (result == WDialog::Accepted)
    {
        /*
         * Update the model with data from the edit widgets.
         *
         * You will want to do some validation here...
         *
         * Note that we directly update the source model to avoid
         * problems caused by the dynamic sorting of the proxy model,
         * which reorders row numbers, and would cause us to switch to editing
         * the wrong data.
         */

        if(m_chbCostEnabled->isChecked() && m_chbPercentEnabled->isChecked())
        {
            WMessageBox::show("Error", WString(tr("msg.ambiguous.select")), Ok);
            return;
        }


        /*! При выставленном варианте расчета статический Поле цена не доступна
            1) Вариант расчета 0 Динамический  1 Статический
            2) Устанавливается Цена или процент
            3) Процента или Цена

        */
        WAbstractItemModel *m = m_model;
        //int id =
        int modelRow = m_item.row();
        int valueType = 0;
        int modifyStatic = 0;
        //int staticValue = 0;
        double value = 0.00;
        //char number[50];

        WAbstractProxyModel *proxyModel = dynamic_cast<WAbstractProxyModel *>(m);
        if (proxyModel)
        {
            m = proxyModel->sourceModel();
            modelRow = proxyModel->mapToSource(m_item).row();
        }
            //modelRow++;



        if(m_chbPercentEnabled->isChecked())
        {
            valueType = 2;
            //sprintf(number,"%.2f%%",boost::lexical_cast<double>(m_lePercent->text().toUTF8()));
            //m->setData(modelRow, 3, boost::any(std::string("0.00")));
            m->setData(modelRow, 5, boost::any(m_lePercent->text().toUTF8()+"%"));/// Процент
            m->setData(modelRow, 2, boost::any(value = boost::lexical_cast<double>(m_lePercent->text().toUTF8())),UserRole);/// Процент

        }else if(m_chbCostEnabled->isChecked())
        {
            valueType = 1;
            //m->setData(modelRow, 3, boost::any(boost::lexical_cast<double>(m_leCost->text().toUTF8())));/// Цена
            //sprintf(number,"%.2f%%",boost::lexical_cast<double>(m_leCost->text().toUTF8()));
            //m->setData(modelRow, 2, boost::any(std::string("0.00%")));
            m->setData(modelRow, 6, boost::any(m_leCost->text().toUTF8()));/// Цена
            m->setData(modelRow, 2, boost::any(value = boost::lexical_cast<double>(m_leCost->text().toUTF8())),UserRole);/// Цена
        }else{
            if(atof(m_leCost->text().toUTF8().c_str()) || atof(m_lePercent->text().toUTF8().c_str()))
                WMessageBox::show("Error", WString(tr("msg.notselected.valuetype")), Ok);

        }

        if(m_chbModifyStatic->isChecked())
            modifyStatic = 1;
        //log("info")<<" Percetn "<<valueType<<" Dinamic "<<m_rbGroup->checkedId();
        m->setData(modelRow, 3, boost::any(valueType),UserRole); /// Value type Процент / Цена
        m->setData(modelRow, 4, boost::any(m_rbGroup->checkedId()),UserRole); /// PriceType Динамический статический
        m->setData(modelRow, 5, boost::any(modifyStatic),UserRole); /// Изменять фиксированные цены
        m->setData(modelRow, 6, boost::any(m_dpModified->date()),UserRole);
        m->setData(modelRow, 7, boost::any(m_roundingMethod->currentIndex()+1),UserRole);

        int priceType = ((m_rbGroup->checkedId()-1)<<1) | (valueType-1);
        bool changeFixed = false;
        WDate modifiDate = WDate::currentDate();

#ifdef DEBUG
        log("info")<<"updateUserPrice(m_id "<<m_id<<",valueType "<<valueType<<",value "<<value<<",priceType "<<priceType<<",changeFixed "<<changeFixed<<",modifiDate "<<modifiDate.toString()<<" rounding "<<m_roundingMethod->currentIndex()+1<<" ) "<<__LINE__;
#endif

        ((Portal *)WApplication::instance())->getSession()->updateUserPrice(m_id,valueType,value,priceType,changeFixed,modifiDate,m_roundingMethod->currentIndex()+1);
    }

    delete this;
}