PowerBuilder PowerScript Выбор нескольких вариантов из раскрывающегося списка

У меня большие трудности с пониманием этой концепции: в настоящее время мы представляем нашим представителям раскрывающееся меню на экране заказа, которое предоставит им несколько вариантов дополнений в зависимости от продукта, добавленного к заказу в строке. до. Проблема заключается в том, что они могут выбрать только один из вариантов, и позиция записывается в заказ, а представители затем не могут выбрать второе дополнение для добавления в заказ (в случае, если клиент хотел добавить оба варианта). -ons вместо одного). Приведенный ниже код является работой программиста, работавшего до меня, поэтому я не уверен, хорошо ли он написан, поскольку Powerscript для меня нов.

Предостережения - это должно оставаться раскрывающимся списком, и я не могу просто добавить второе дополнение в фоновом режиме. Для правильной работы системы заказов выбранные дополнения должны идти сразу после основного товара, один за другим. Я также не могу добавить «комплектный» продукт, так как это испортит отчеты о продажах.

String contact_type, contact_name 
Long contact_no, ll_child_row
long product_no, addon_product_no
string addon
string null_string
string promo_key
string addon_edition_code
int qty
real price
DataWindowChild contact_child 
AcceptText()

If GetColumnName() = 'attn_freeform' Then 
    AcceptText()
    GetChild('attn_freeform', contact_child)
    ll_child_row = contact_child.GetRow()
    If ll_child_row > 0 Then
        contact_name = contact_child.GetItemString(ll_child_row, 'contact_name')
        If data = contact_name Then 
            contact_type = contact_child.GetItemString(ll_child_row, 'tar_contact_type')
            contact_no = contact_child.GetItemNumber(ll_child_row, 'tar_contact_no')
            SetItem(row, "ship2_tar_contact_type", contact_type)
            SetItem(row, "ship2_tar_contact_no", contact_no)
        Else
            SetItem(row, "ship2_tar_contact_type", '')
            SetItem(row, "ship2_tar_contact_no", -1)
        End If
    Else
        SetItem(row, "ship2_tar_contact_type", '')
        SetItem(row, "ship2_tar_contact_no", -1)
    End If      
End If 

if GetColumnName() = 'quantity' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetItem(row + 1,"quantity",integer(data))
    AcceptText()
end if 
if GetColumnName() = 'package_no' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetItem(row + 1,"package_no",dw_order_detail.getitemnumber(row,"package_no"))
    AcceptText()
end if 
if GetColumnName() = 'attn_freeform' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetItem(row + 1,"attn_freeform",data)
    AcceptText()
end if 
if GetColumnName() = 'promo_key' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetItem(row + 1,"promo_key",data)
    AcceptText()
end if 
if GetColumnName() = 'order_type' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetItem(row + 1,"order_type",dw_order_detail.getitemstring(row,"order_type"))
end if 

if GetColumnName() = 'product_no' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetNull(null_string)
    dw_order_detail.deleterow(row + 1)
    dw_order_detail.SetItem(row,"name_1",null_string)
end if  

product_no = 0
if GetColumnName() = 'product_no' and isnull(dw_order_detail.GetItemString(row,"name_1")) then 
product_no = dw_order_detail.GetItemNumber(row,'product_no')
int checkAddon
Select isnull(count(*),0) into :checkAddon From  product p JOIN mag_addons t ON p.edition_code = t.primary_edition and p.product_no = :product_no;
    if checkAddon > 0 then
        dw_order_detail.SetItem(row, "teach_12",0)
    end if
end if 

promo_key = dw_order_detail.getitemstring(row,"promo_key")  
qty = dw_order_detail.getitemnumber(row,"quantity")
AcceptText()

if GetColumnName() = 'name_1'  then //the dropdown for addon selection appears here
    long ll_row, ll_inserted_row
    SetNull(null_string)
    product_no = 0
    product_no = dw_order_detail.GetItemNumber(row,'product_no')
    addon = dw_order_detail.GetItemString(row,"name_1") //this sets the name of the addon
if isnull(addon) or addon = "Select Add On..."  then 
    return
end if 
Select p.product_no, t.add_on_edition into :addon_product_no, :addon_edition_code from product p JOIN mag_addons t ON p.edition_code = t.add_on_edition and p.description = :addon JOIN product d ON t.primary_edition = d.edition_code;
if row + 1  <  dw_order_detail.RowCount() then 
     if dw_order_detail.GetItemString(row + 1,'addondesc') = addon then
        return
    end if 
end if 
if product_no >= 1 then 
    SELECT price INTO :price FROM dbo.get_price(:promo_key,:addon_edition_code,:qty, :vg_project_id);
    if price = 0 then 
        price = .99 
    end if
    ll_row = dw_order_detail.GetRow()
    ll_inserted_row = dw_order_detail.InsertRow(row + 1)
    SetItem(row + 1,"order_no",dw_order_detail.getitemnumber(row,"order_no"))
    SetItem(row + 1,"line_item_no",dw_order_detail.getitemnumber(row,"line_item_no") + 1)
    SetItem(row + 1,"status_code",dw_order_detail.getitemstring(row,"status_code"))
    SetItem(row + 1,"ship2_tar_contact_type",dw_order_detail.getitemstring(row,"ship2_tar_contact_type"))
    SetItem(row + 1,"ship2_tar_contact_no",dw_order_detail.getitemnumber(row,"ship2_tar_contact_no"))
    SetItem(row + 1,"attn_freeform",dw_order_detail.getitemstring(row,"attn_freeform"))
    SetItem(row + 1,"promo_key",promo_key)
    SetItem(row + 1,"product_no",addon_product_no)
    SetItem(row + 1,"quantity",dw_order_detail.getitemnumber(row,"quantity"))
    SetItem(row + 1,"price",price)
    SetItem(row + 1,"price_1",price)
    SetItem(row + 1,"package_no",dw_order_detail.getitemnumber(row,"package_no"))
    SetItem(row + 1,"order_type",dw_order_detail.getitemstring(row,"order_type"))
    SetItem(row + 1,"shipping_rate",dw_order_detail.getitemnumber(row,"shipping_rate"))
    SetItem(row + 1,"sales_tax_rate",dw_order_detail.getitemnumber(row,"sales_tax_rate"))
    SetItem(row + 1,"ship2_tar_acct_type",dw_order_detail.getitemstring(row,"ship2_tar_acct_type"))
    SetItem(row + 1,"ship2_tar_acct_no",dw_order_detail.getitemnumber(row,"ship2_tar_acct_no"))
    SetItem(row + 1,"jt_id",dw_order_detail.getitemnumber(row,"jt_id"))
    SetItem(row + 1,"year_began_teach",dw_order_detail.getitemnumber(row,"year_began_teach"))
    SetItem(row + 1,"preferred_email",dw_order_detail.getitemstring(row,"preferred_email"))
    SetItem(row + 1,"email",dw_order_detail.getitemstring(row,"email"))
    SetItem(row + 1,"addondesc",dw_order_detail.getitemstring(row,"name_1"))
    SetItem(row,"teach_12",1)
    SetItem(row + 1,"teach_12",2)

    dw_order_detail.AcceptText()
end if
dw_order_detail.ScrollToRow(ll_inserted_row)
dw_order_detail.SetFocus()
end if
dw_order_detail.AcceptText()

person soundwave    schedule 02.09.2015    source источник
comment
Это из какого события?   -  person Matt Balent    schedule 03.09.2015
comment
Прошло некоторое время с тех пор, как я сделал Powerbuilder. Но я, кажется, помню, что вы можете использовать раскрывающееся окно данных и поместить в него любое окно данных, которое хотите. Я думаю, вы могли бы создать окно данных с флажком в каждой строке, а затем поместить его в раскрывающийся список.   -  person Slapout    schedule 03.09.2015
comment
@MattBalent это с мероприятия itemchanged   -  person soundwave    schedule 03.09.2015
comment
Accepttext внутри события itemchanged ничего не делает, поэтому вы можете удалить все это. Вы должны использовать свойство dwo.name, а не метод GetColumnName().   -  person Matt Balent    schedule 04.09.2015
comment
Я понимаю удаление accepttext, что нормально, но свойство dwo.name не существует, в документации Sybase PowerBuilder 11.5 рекомендуется использовать dwo.GetColumnName   -  person soundwave    schedule 08.09.2015
comment
В событии itemchanged для окна данных (даже в 11.5) есть три параметра: row, dwo и data. Если у вас их нет, то вы не участвуете в событии itemchanged.   -  person Matt Balent    schedule 08.09.2015
comment
Да, у меня есть эти три параметра, и я могу подтвердить, что нахожусь в событии itemchanged, но .name выдает ошибку Incompatible property name for type dw_order_detail   -  person soundwave    schedule 08.09.2015
comment
Неважно, я предполагал, что dwo является общим и коррелирует с dw_order_detail, тогда как это просто dwo   -  person soundwave    schedule 08.09.2015
comment
К сожалению, это все еще не помогает понять, как добавить возможность выбора второго продукта дополнения вместо одного.   -  person soundwave    schedule 08.09.2015


Ответы (1)


После долгих головных болей и переписывания кода я смог создать продукт SQL, который я рассматривал как набор обоих дополнительных продуктов, и использовал код в PowerBuilder для проверки этих связанных продуктов, а затем вставил отдельный элемент строки для каждого. Я жестко закодировал некоторые из них, так как это нужно было сделать как можно скорее, поэтому, если у кого-то есть идеи для более красивого, более эффективного нежестко запрограммированного сценария, пожалуйста, дайте мне знать.

Все изменения происходят в событии itemchanged():

String contact_type, contact_name 
Long contact_no, ll_child_row
long product_no, addon_product_no
string addon
string null_string
string promo_key
string addon_edition_code
int qty
real price
long product_no_1, product_no_2, add_on_edition_1, add_on_edition_2
int cnt
string addondesc_1, addondesc_2
DataWindowChild contact_child 

AcceptText()
If GetColumnName() = 'attn_freeform' Then 
    AcceptText()
    GetChild('attn_freeform', contact_child)
    ll_child_row = contact_child.GetRow()
    If ll_child_row > 0 Then
        contact_name = contact_child.GetItemString(ll_child_row, 'contact_name')
    If data = contact_name Then 
        contact_type = contact_child.GetItemString(ll_child_row, 'tar_contact_type')
        contact_no = contact_child.GetItemNumber(ll_child_row, 'tar_contact_no')
        SetItem(row, "ship2_tar_contact_type", contact_type)
        SetItem(row, "ship2_tar_contact_no", contact_no)
    Else
        SetItem(row, "ship2_tar_contact_type", '')
        SetItem(row, "ship2_tar_contact_no", -1)
    End If
Else
    SetItem(row, "ship2_tar_contact_type", '')
    SetItem(row, "ship2_tar_contact_no", -1)
    End If      
End If 

if GetColumnName() = 'quantity' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetItem(row + 1,"quantity",integer(data))
    AcceptText()
end if 
if GetColumnName() = 'package_no' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetItem(row + 1,"package_no",dw_order_detail.getitemnumber(row,"package_no"))
    AcceptText()
end if 
if GetColumnName() = 'attn_freeform' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetItem(row + 1,"attn_freeform",data)
    AcceptText()
end if 
if GetColumnName() = 'promo_key' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetItem(row + 1,"promo_key",data)
    AcceptText()
end if 
if GetColumnName() = 'order_type' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetItem(row + 1,"order_type",dw_order_detail.getitemstring(row,"order_type"))
end if 

if GetColumnName() = 'product_no' and not isnull(dw_order_detail.GetItemString(row,"name_1")) then
    SetNull(null_string)
    dw_order_detail.deleterow(row + 1)
    dw_order_detail.SetItem(row,"name_1",null_string)
end if  

product_no = 0
if GetColumnName() = 'product_no' and isnull(dw_order_detail.GetItemString(row,"name_1")) then 
    product_no = dw_order_detail.GetItemNumber(row,'product_no')
    int checkAddon 
    Select isnull(count(*),0) into :checkAddon From  product p JOIN TARDIS_Magazine_AddOns t ON p.edition_code = t.primary_edition and p.product_no = :product_no;
    //sets a new dropdown for addons if they exist
    if checkAddon > 0 then
        dw_order_detail.SetItem(row, "teach_12",0)
    end if
end if 

promo_key = dw_order_detail.getitemstring(row,"promo_key")  
qty = dw_order_detail.getitemnumber(row,"quantity")
AcceptText()
if GetColumnName() = 'name_1' then 
    long ll_row, ll_inserted_row
    SetNull(null_string)
    product_no = 0
    product_no = dw_order_detail.GetItemNumber(row,'product_no')
    addon = dw_order_detail.GetItemString(row,"name_1")
    if isnull(addon) or addon = "Select Add On..."  then 
        return
    end if 
    //do this once for one addon as normal
    if addon <> 'SS + GS 3-6' and addon <> 'SS + GS 3-6 TE' then
        Select p.product_no, t.add_on_edition into :addon_product_no, :addon_edition_code from product p JOIN TARDIS_Magazine_AddOns t ON p.edition_code = t.add_on_edition and p.description = :addon JOIN product d ON t.primary_edition = d.edition_code;
    elseif addon = 'SS + GS 3-6' then
        product_no_1 = 2576
        product_no_2 = 2579
        add_on_edition_1 = 304
        add_on_edition_2 = 314
        addondesc_1 = 'ScienceSpin 3-6'
        addondesc_2 = 'Geography Spin 3-6'
    elseif addon = 'SS + GS 3-6 TE' then
        product_no_1 = 2577
        product_no_2 = 2580
        add_on_edition_1 = 305
        add_on_edition_2 = 315
        addondesc_1 = 'ScienceSpin 3-6 TE'
        addondesc_2 = 'Geography Spin 3-6 TE'
    end if  
    if row + 1  <  dw_order_detail.RowCount() then 
        if dw_order_detail.GetItemString(row + 1,'addondesc') = addon then
            return
        end if 
    end if
    //the following condition should be executed once as normal if there is only one addon
    if addon <> 'SS + GS 3-6' and addon <> 'SS + GS 3-6 TE' then
    if product_no >= 1 then 
        SELECT price INTO :price FROM dbo.get_price(:promo_key,:addon_edition_code,:qty, :vg_project_id);
        if price = 0 then 
            price = .99 
        end if
    ll_row = dw_order_detail.GetRow()
    //the following line inserts a row
    ll_inserted_row = dw_order_detail.InsertRow(row + 1)
    //the following lines set the data into each field on the row
    SetItem(row + 1,"order_no",dw_order_detail.getitemnumber(row,"order_no"))
    SetItem(row + 1,"line_item_no",dw_order_detail.getitemnumber(row,"line_item_no") + 1)
    SetItem(row + 1,"status_code",dw_order_detail.getitemstring(row,"status_code"))
    SetItem(row + 1,"ship2_tar_contact_type",dw_order_detail.getitemstring(row,"ship2_tar_contact_type"))
    SetItem(row + 1,"ship2_tar_contact_no",dw_order_detail.getitemnumber(row,"ship2_tar_contact_no"))
    SetItem(row + 1,"attn_freeform",dw_order_detail.getitemstring(row,"attn_freeform"))
    SetItem(row + 1,"promo_key",promo_key)
    SetItem(row + 1,"product_no",addon_product_no)
    SetItem(row + 1,"quantity",dw_order_detail.getitemnumber(row,"quantity"))
    SetItem(row + 1,"price",price)
    SetItem(row + 1,"price_1",price)
    SetItem(row + 1,"package_no",dw_order_detail.getitemnumber(row,"package_no"))
    SetItem(row + 1,"order_type",dw_order_detail.getitemstring(row,"order_type"))
    SetItem(row + 1,"shipping_rate",dw_order_detail.getitemnumber(row,"shipping_rate"))
    SetItem(row + 1,"sales_tax_rate",dw_order_detail.getitemnumber(row,"sales_tax_rate"))
    SetItem(row + 1,"ship2_tar_acct_type",dw_order_detail.getitemstring(row,"ship2_tar_acct_type"))
    SetItem(row + 1,"ship2_tar_acct_no",dw_order_detail.getitemnumber(row,"ship2_tar_acct_no"))
    SetItem(row + 1,"jt_id",dw_order_detail.getitemnumber(row,"jt_id"))
    SetItem(row + 1,"year_began_teach",dw_order_detail.getitemnumber(row,"year_began_teach"))
    SetItem(row + 1,"preferred_email",dw_order_detail.getitemstring(row,"preferred_email"))
    SetItem(row + 1,"email",dw_order_detail.getitemstring(row,"email"))
    SetItem(row + 1,"addondesc",dw_order_detail.getitemstring(row,"name_1"))
    SetItem(row,"teach_12",1)
    SetItem(row + 1,"teach_12",2)


    dw_order_detail.AcceptText()
    end if
else
    if product_no_1 = 2576 or product_no_1 = 2577 then 
        SELECT price INTO :price FROM dbo.get_price(:promo_key,:add_on_edition_1,:qty, :vg_project_id);
        if price = 0 then 
            price = .99 
        end if
    elseif product_no_2 = 2579 or product_no_2 = 2580 then
        SELECT price INTO :price FROM dbo.get_price(:promo_key,:add_on_edition_2,:qty, :vg_project_id);
        if price = 0 then 
            price = .99 
        end if
   end if
FOR cnt = 1 to 2
    ll_row = dw_order_detail.GetRow()
    //the following line inserts a row
    ll_inserted_row = dw_order_detail.InsertRow(row + 1)
    //the following lines set the data into each field on the row
    SetItem(row + 1,"order_no",dw_order_detail.getitemnumber(row,"order_no"))
    SetItem(row + 1,"line_item_no",dw_order_detail.getitemnumber(row,"line_item_no") + 1)
    SetItem(row + 1,"status_code",dw_order_detail.getitemstring(row,"status_code"))
    SetItem(row + 1,"ship2_tar_contact_type",dw_order_detail.getitemstring(row,"ship2_tar_contact_type"))
    SetItem(row + 1,"ship2_tar_contact_no",dw_order_detail.getitemnumber(row,"ship2_tar_contact_no"))
    SetItem(row + 1,"attn_freeform",dw_order_detail.getitemstring(row,"attn_freeform"))
    SetItem(row + 1,"promo_key",promo_key)
    if cnt = 1 then
        SetItem(row + 1,"product_no",add_on_edition_1)
    else 
        SetItem(row + 1,"product_no",add_on_edition_2)
    end if
    SetItem(row + 1,"quantity",dw_order_detail.getitemnumber(row,"quantity"))
    SetItem(row + 1,"price",price)
    SetItem(row + 1,"price_1",price)
    SetItem(row + 1,"package_no",dw_order_detail.getitemnumber(row,"package_no"))
    SetItem(row + 1,"order_type",dw_order_detail.getitemstring(row,"order_type"))
    SetItem(row + 1,"shipping_rate",dw_order_detail.getitemnumber(row,"shipping_rate"))
    SetItem(row + 1,"sales_tax_rate",dw_order_detail.getitemnumber(row,"sales_tax_rate"))
    SetItem(row + 1,"ship2_tar_acct_type",dw_order_detail.getitemstring(row,"ship2_tar_acct_type"))
    SetItem(row + 1,"ship2_tar_acct_no",dw_order_detail.getitemnumber(row,"ship2_tar_acct_no"))
    SetItem(row + 1,"jt_id",dw_order_detail.getitemnumber(row,"jt_id"))
    SetItem(row + 1,"year_began_teach",dw_order_detail.getitemnumber(row,"year_began_teach"))
    SetItem(row + 1,"preferred_email",dw_order_detail.getitemstring(row,"preferred_email"))
    SetItem(row + 1,"email",dw_order_detail.getitemstring(row,"email"))
    if cnt = 1 then
        SetItem(row + 1,"addondesc",addondesc_1)
    else
        SetItem(row + 1,"addondesc",addondesc_2)
    end if
    SetItem(row,"teach_12",1)
    SetItem(row + 1,"teach_12",2)
    dw_order_detail.AcceptText()
NEXT
end if
dw_order_detail.ScrollToRow(ll_inserted_row)
dw_order_detail.SetFocus()
end if
dw_order_detail.AcceptText()
person soundwave    schedule 14.09.2015