PowerBuilder PowerScript从下拉列表中选择多个选项

时间:2015-09-02 19:46:30

标签: powerbuilder

我在解决这个概念时遇到了很大的困难:我们目前在订单屏幕上显示我们的销售代表下拉菜单,根据添加到订单中的产品,它们将显示多个附加选项在之前的行。问题在于他们只能选择其中一个选项,并且订单项会写入订单,然后代表无法选择第二个加载项添加到订单中(如果客户想要同时添加 - 而不是一个)。下面发布的代码是我之前的程序员的工作,所以我不确定它是否写得好,因为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()

1 个答案:

答案 0 :(得分:0)

经过多次头痛和重写代码后,我能够创建一个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()