МОСС: Итератинг кроз прилагођене листе и враћање филтриране податке за ИнфоПатх

Пословни сценарио:

Обезбедите метод који омогућава корисницима да брзо уђе тачне дописа куповину.

Пословни проблем:

Клијент послује са неколико стотина произвођача.

Vendors are "type" специфичан. То значи да продавац продаје рачунарску опрему (e.g. Шумовита долина) или канцеларијски материјал (e.g. Стаплес).

Како би крајњи корисници који креирају куповину дописа изабрали важећи продавца?

Пословна решења:

Differentiate vendors in the system via "type".

Enable users to select the "type" производа, а затим обезбедити филтрирани скуп одговарајућих продаваца.

Техничко решење:

ИнфоПатх образац је дизајниран тако да омогућава корисницима да уђу на мрежи дописа куповину.

Два ИнфоПатх листе избор контрола продавац избор. Прво, the user selects a "purchase type". This limits a second selection list to contain only vendors that sell for that purchase type. This is a classic cascading drop-down.

Vendors are stored in a MOSS custom list with custom columns for vendor attributes such as name, address and especially "type".

Implement a web service for an InfoPath client to consume that iterates through the custom vendor list, returning only vendors matching a supplied "type".

Invoke the web service via the InfoPath form.

Научене лекције:

  • Прво, it seems necessary to go this route. I would have preferred to do the filtering entirely within InfoPath and not create any web service functionality here. Међутим, forms server does not provide the required filtering capability. We can put a rule onto a the "type" selection list in the form to sort of re-open the vendor query, али не могу да га правилно. Стога, било је неопходно да се спроведе веб сервис.
  • This is a classic "cascading selection list" проблем у свету ИнфоПатх образаца сервера и постоји много добрих примера вани који објашњавају како да се реши ово.
  • Празну вредност за колону у листи произвођача не враћа празан стринг референце када овако: инитИтем["Vendor Name"]. Уместо тога, она враћа нулл.

Неке друге белешке:

  • Ја дају низ[] продаваца, јер сам имао неких потешкоћа враћа АрраиЛист. ИнфоПатх се жалила због тога, а ја нисам имао времена ни воље да се боре око тога. Ово, наравно, ставља вештачку границу од укупног броја продаваца. Такође ме је приморан да спроведе трим() method on the array because I hate the idea of returning back 100’s of null vendors. InfoPath doesn’t care, but it nagged at me. (Поново, this was easier than fighting InfoPath over ArrayLists).
  • I implemented a GetSpecificVendorByName() function as well, which may be instructive.

Код:

коришћење Систем;
коришћење System.Web;
коришћење System.Web.Services;
коришћење System.Web.Services.Protocols;
коришћење Microsoft.SharePoint;
коришћење System.Configuration;

/// <резиме>
///
Vendor Service: Provides vendor related services which today are consumed by an infopath client form.
///
/// History:
/// ——–
/// 07/24/07: Initial coding, Paul J. Gavin of Conchango.
///
/// </резиме>
[Вебсервице(Namespace = "http://ввв.цонцханго.цом/")]
[ВебСервицеБиндинг(ConformsTo = ВсиПрофилес.БасицПрофиле1_1)]
јавност класа VendorService : System.Web.Services.Вебсервице
{

/// <резиме>
/// Represents a vendor from a custom sharepoint list maintained by MSUSA.
/// </резиме>
јавност класа Vendor
{
јавност Vendor() { }

јавност Vendor(Пљунути инитИтем)
{
ако (! (инитИтем["Vendor Name"] == null)) VendorName = initItem["Vendor Name"].ТоСтринг();
ако (! (инитИтем["Address 1"] == null)) VendorAddress1 = initItem["Address 1"].ТоСтринг();
ако (! (инитИтем["Address 2"] == null)) VendorAddress2 = initItem["Address 2"].ТоСтринг();
ако (! (инитИтем["City"] == null)) VendorCity = initItem["City"].ТоСтринг();
ако (! (инитИтем["VendorPhone"] == null)) VendorPhone = initItem["VendorPhone"].ТоСтринг();
ако (! (инитИтем["PurchaseType"] == null)) VendorType = initItem["PurchaseType"].ТоСтринг();
ако (! (инитИтем["State"] == null)) VendorState = initItem["State"].ТоСтринг();
ако (! (инитИтем["Zip"] == null)) VendorZip = initItem["Zip"].ТоСтринг();
ако (!(инитИтем["Fax"] == null)) VendorFax = initItem["Fax"].ТоСтринг();
ако (!(инитИтем["SalesRepName"] == null)) VendorSalesRepName = initItem["SalesRepName"].ТоСтринг();

VendorItemId = initItem.ID; // Unique ID maintained via MOSS.
}

јавност инт VendorItemId;
јавност ниска VendorName;
јавност ниска VendorAddress1;
јавност ниска VendorAddress2;
јавност ниска VendorCity;
јавност ниска VendorState;
јавност ниска VendorZip;
јавност ниска VendorPhone;
јавност ниска VendorType;
јавност ниска VendorSalesRepName;
јавност ниска VendorFax;
}

јавност VendorService () {

//Uncomment the following line if using designed components
//ИнитиализеЦомпонент();
}

приватан Vendor[] GenerateTestVendors()
{
Vendor[] resultList;
resultList = нови Vendor[100];

Vendor v;
v = нови Vendor();
v.VendorAddress1 = "v1_address1";
v.VendorAddress2 = "v1_address2";
v.VendorCity = "v1_city";
v.VendorName = "v1_vendorname";
v.VendorPhone = "v1_vendorphone";
v.VendorState = "v1_st";
v.VendorType = "v1_type";
v.VendorZip = "v1_zip";

resultList[0] = v;

v = нови Vendor();

v.VendorAddress1 = "v2_address1";
v.VendorAddress2 = "v2_address2";
v.VendorCity = "v2_city";
v.VendorName = "v2_vendorname";
v.VendorPhone = "v2_vendorphone";
v.VendorState = "v2_st";
v.VendorType = "v2_type";
v.VendorZip = "v2_zip";

resultList[1] = v;

v = нови Vendor();
v.VendorAddress1 = "v3_address1";
v.VendorAddress2 = "v3_address2";
v.VendorCity = "v3_city";
v.VendorName = "v3_vendorname";
v.VendorPhone = "v3_vendorphone";
v.VendorState = "v3_st";
v.VendorType = "v3_type";
v.VendorZip = "v3_zip";

resultList[2] = v;

повратак resultList;

}

[ВебМетход]
јавност Vendor GetSpecificVendorById(инт ВендорИД)
{
ниска СпВендорСитеНаме; // Name of the actual MOSS site that hosts the vendor custom list.
ниска СпВендорЛистНаме; // Name of the actual MOSS list containing vendors.

SpVendorSiteName = ЦонфигуратионСеттингс.АппСеттингс["VendorListHostingSite"].ТоСтринг();
SpVendorListName = ЦонфигуратионСеттингс.АппСеттингс["VendorList"].ТоСтринг();

коришћење (СПСите site = нови СПСите(СпВендорСитеНаме))
{

коришћење (СПВеб web = site.OpenWeb())
{

СПЛист currentList = web.Lists[СпВендорЛистНаме];

Пљунути specificItem = currentList.Items[ВендорИД];

повратак нови Vendor(специфицИтем);

} // using spweb web = site.openweb()
} // using spsite site = new spsite("http://localhost/mizuho")

}

[ВебМетход]
// Assumes that the vendor name is unique, from a business perspective
јавност Vendor GetSpecificVendorByVendorName(ниска вендорНаме)
{
ниска СпВендорСитеНаме; // Name of the actual MOSS site that hosts the vendor custom list.
ниска СпВендорЛистНаме; // Name of the actual MOSS list containing vendors.

SpVendorSiteName = ЦонфигуратионСеттингс.АппСеттингс["VendorListHostingSite"].ТоСтринг();
SpVendorListName = ЦонфигуратионСеттингс.АппСеттингс["VendorList"].ТоСтринг();

коришћење (СПСите site = нови СПСите(СпВендорСитеНаме))
{
коришћење (СПВеб web = site.OpenWeb())
{

СПЛист currentList = web.Lists[СпВендорЛистНаме];

фореацх (Пљунути вендорИтем у currentList.Items)
{
ако (вендорИтем["Vendor Name"] == null) наставити;

ако (вендорИтем["Vendor Name"].ТоСтринг().Једнако(вендорНаме))
повратак нови Vendor(вендорИтем);
}

Vendor v = нови Vendor();
v.VendorPhone = "not found: " + вендорНаме;

повратак v;

повратак null;

} // using spweb web = site.openweb()
} // using spsite site = new spsite("http://localhost/mizuho")

} // метод

[ВебМетход]
јавност Vendor[] GetVendorsOfType (ниска Тип филтера)
{

ниска СпВендорСитеНаме; // Name of the actual MOSS site that hosts t
he vendor custom list.
ниска СпВендорЛистНаме; // Name of the actual MOSS list containing vendors.

SpVendorSiteName = ЦонфигуратионСеттингс.АппСеттингс["VendorListHostingSite"].ТоСтринг();
SpVendorListName = ЦонфигуратионСеттингс.АппСеттингс["VendorList"].ТоСтринг();

Vendor[] resultList;
инт vendorIndex = 0;
resultList = нови Vendor[1000];

// Initialize the list with a default friendly message.
Vendor v = нови Vendor();
v.VendorName = "Select a vendor type to populate this list.";
resultList[0] = v;

// Convert the filter to lower case for easier string comparison later.
filterType = filterType.ToLower();

// If the filter type passed is "test", generate some simple data.
#регија Filter type = "test"
ако (filterType.Equals("test"))
повратак GenerateTestVendors();
#ендрегион

ако (прави)
{
коришћење (СПСите site = нови СПСите(СпВендорСитеНаме))
{
коришћење (СПВеб web = site.OpenWeb())
{

v = null;

СПЛист currentList = web.Lists[СпВендорЛистНаме];

// Iterate through all the items in the vendor list.
фореацх (Пљунути вендорИтем у currentList.Items)
{

ниска lowerVendorType;

lowerVendorType = vendorItem["PurchaseType"].ТоСтринг().ТоЛовер();
lowerVendorType = lowerVendorType.Substring(3);

ако (ловерВендорТипе.Екуалс(Тип филтера))
{
resultList[вендорИндек ] = нови Vendor(вендорИтем);
}
} // iterating thru all the vendors in the list


повратак TrimVendorArray(вендорИндек, resultList);
// return resultList;

} // using spweb web = site.openweb()
} // using spsite site = new spsite("http://localhost/mizuho")

} // if true

повратак null;
}

приватан Vendor[] TrimVendorArray(инт newsize, Vendor[] originalVendorArray)
{
Vendor[] trimmedArray;

ако (newsize == 0) newsize = 1;
trimmedArray = нови Vendor[newsize];

инт currentCounter = 0;

за (currentCounter = 0; currentCounter < newsize; currentCounter )
{
trimmedArray[currentCounter] = originalVendorArray[currentCounter];
}

повратак trimmedArray;

}
}

Леаве а Репли

Ваша емаил адреса неће бити објављена. Обавезна поља су означена *