MOSS: Перабор карыстацкіх спісаў і вяртанне адфільтраваць дадзеных у InfoPath

Бізнес-сцэнар:

Стварэнне спосабу, які дазваляе карыстальнікам ўводзіць дакладныя заявак на закупкі хутка.

Бізнес-задачы:

Кліент вядзе бізнэс з некалькіх сотняў пастаўшчыкоў.

Vendors are "type" канкрэтны. Гэта азначае, што прадавец прадае камп'ютэрнае абсталяванне (e.g. Лагчына) або канцылярскіх прыладаў (e.g. Клямары).

Як мы дазваляюць канчатковым карыстальнікам, якія ствараюць заяўкі, увядзіце карэктнае пастаўшчыка?

Business Solution:

Differentiate vendors in the system via "type".

Enable users to select the "type" прадукту, а затым забяспечыць адфільтраваным набор адпаведных пастаўшчыкоў.

Тэхнічнае рашэнне:

InfoPath форма была распрацавана, што дазваляе карыстальнікам ўводзіць онлайн заявак на закупкі.

Два InfoPath выбару кантрольных спісаў выбару пастаўшчыка. Першы, 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".

Укараненне вэб-сэрвіс для кліента InfoPath спажываць, які ажыццяўляе перабор карыстацкі спіс пастаўшчыкоў, returning only vendors matching a supplied "type".

Выклік вэб-службы з дапамогай формаў InfoPath.

Урокі:

  • Першы, уяўляецца неабходным ісці па гэтым шляху. Я б аддаў перавагу, каб зрабіць фільтраванне цалкам у InfoPath і не ствараюць ніякіх функцыянальнасці вэб-сэрвісу тут. Аднак, Forms Server не забяспечвае неабходную фільтраванне. We can put a rule onto a the "type" Спіс выбару ў форме для сартавання зноў адкрыць запыт пастаўшчыку, але мы не можам прымусіць яго працаваць правільна. Таму, гэта было неабходна для ажыццяўлення вэб-сэрвіс.
  • This is a classic "cascading selection list" problem in the InfoPath forms server world and there are many good examples out there that explain how to solve this.
  • A blank value for a column in the vendor list does not return an empty string when referenced like this: initItem["Vendor Name"]. Замест, it returns a null.

Some other Notes:

  • I return an array[] of vendors because I had some difficulty returning an ArrayList. InfoPath was complaining about it and I didn’t have the time or the inclination to fight over it. Гэта, вядома, puts an artificial limit on the total number of vendors. It also compelled me to implement a trim() method on the array because I hate the idea of returning back 100’s of null vendors. InfoPath не клапоціцца, але яна бурчэла на мяне. (Зноў, гэта было лягчэй, чым барацьба за InfoPath ArrayLists).
  • Я рэалізаваў GetSpecificVendorByName() Функцыя таксама, якія могуць быць павучальныя.

Код:

выкарыстанне Сістэма;
выкарыстанне 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.
///
/// </рэзюмэ>
[WebService(Namespace = "http://www.conchango.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
грамадскасць клас VendorService : System.Web.Services.WebService
{

/// <рэзюмэ>
/// Represents a vendor from a custom sharepoint list maintained by MSUSA.
/// </рэзюмэ>
грамадскасць клас Прадавец
{
грамадскасць Прадавец() { }

грамадскасць Прадавец(Пляваць initItem)
{
калі (! (initItem["Vendor Name"] == нулявы)) VendorName = initItem["Vendor Name"].ToString();
калі (! (initItem["Address 1"] == нулявы)) VendorAddress1 = initItem["Address 1"].ToString();
калі (! (initItem["Address 2"] == нулявы)) VendorAddress2 = initItem["Address 2"].ToString();
калі (! (initItem["City"] == нулявы)) VendorCity = initItem["City"].ToString();
калі (! (initItem["VendorPhone"] == нулявы)) VendorPhone = initItem["VendorPhone"].ToString();
калі (! (initItem["PurchaseType"] == нулявы)) VendorType = initItem["PurchaseType"].ToString();
калі (! (initItem["State"] == нулявы)) VendorState = initItem["State"].ToString();
калі (! (initItem["Zip"] == нулявы)) VendorZip = initItem["Zip"].ToString();
калі (!(initItem["Fax"] == нулявы)) VendorFax = initItem["Fax"].ToString();
калі (!(initItem["SalesRepName"] == нулявы)) VendorSalesRepName = initItem["SalesRepName"].ToString();

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

грамадскасць Int VendorItemId;
грамадскасць радок VendorName;
грамадскасць радок VendorAddress1;
грамадскасць радок VendorAddress2;
грамадскасць радок VendorCity;
грамадскасць радок VendorState;
грамадскасць радок VendorZip;
грамадскасць радок VendorPhone;
грамадскасць радок VendorType;
грамадскасць радок VendorSalesRepName;
грамадскасць радок VendorFax;
}

грамадскасць VendorService () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

прыватны Прадавец[] GenerateTestVendors()
{
Прадавец[] resultList;
resultList = новы Прадавец[100];

Прадавец v;
v = новы Прадавец();
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 = новы Прадавец();

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 = новы Прадавец();
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;

}

[WebMethod]
грамадскасць Прадавец GetSpecificVendorById(Int VendorID)
{
радок SpVendorSiteName; // Name of the actual MOSS site that hosts the vendor custom list.
радок SpVendorListName; // Name of the actual MOSS list containing vendors.

SpVendorSiteName = ConfigurationSettings.AppSettings["VendorListHostingSite"].ToString();
SpVendorListName = ConfigurationSettings.AppSettings["VendorList"].ToString();

выкарыстанне (SPSite site = новы SPSite(SpVendorSiteName))
{

выкарыстанне (SPWeb web = site.OpenWeb())
{

SPList currentList = web.Lists[SpVendorListName];

Пляваць specificItem = currentList.Items[VendorID];

вяртанне новы Прадавец(specificItem);

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

}

[WebMethod]
// Assumes that the vendor name is unique, from a business perspective
грамадскасць Прадавец GetSpecificVendorByVendorName(радок Имя_вендора)
{
радок SpVendorSiteName; // Name of the actual MOSS site that hosts the vendor custom list.
радок SpVendorListName; // Name of the actual MOSS list containing vendors.

SpVendorSiteName = ConfigurationSettings.AppSettings["VendorListHostingSite"].ToString();
SpVendorListName = ConfigurationSettings.AppSettings["VendorList"].ToString();

выкарыстанне (SPSite site = новы SPSite(SpVendorSiteName))
{
выкарыстанне (SPWeb web = site.OpenWeb())
{

SPList currentList = web.Lists[SpVendorListName];

Еогеасп (Пляваць vendorItem ў currentList.Items)
{
калі (vendorItem["Vendor Name"] == нулявы) працягваць;

калі (vendorItem["Vendor Name"].ToString().Роўна(Имя_вендора))
вяртанне новы Прадавец(vendorItem);
}

Прадавец v = новы Прадавец();
v.VendorPhone = "not found: " + Имя_вендора;

вяртанне v;

вяртанне нулявы;

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

} // метад

[WebMethod]
грамадскасць Прадавец[] GetVendorsOfType (радок Тып фільтра)
{

радок SpVendorSiteName; // Name of the actual MOSS site that hosts t
he vendor custom list.
радок SpVendorListName; // Name of the actual MOSS list containing vendors.

SpVendorSiteName = ConfigurationSettings.AppSettings["VendorListHostingSite"].ToString();
SpVendorListName = ConfigurationSettings.AppSettings["VendorList"].ToString();

Прадавец[] resultList;
Int vendorIndex = 0;
resultList = новы Прадавец[1000];

// Initialize the list with a default friendly message.
Прадавец v = новы Прадавец();
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();
#EndRegion

калі (праўда)
{
выкарыстанне (SPSite site = новы SPSite(SpVendorSiteName))
{
выкарыстанне (SPWeb web = site.OpenWeb())
{

v = нулявы;

SPList currentList = web.Lists[SpVendorListName];

// Iterate through all the items in the vendor list.
Еогеасп (Пляваць vendorItem ў currentList.Items)
{

радок lowerVendorType;

lowerVendorType = vendorItem["PurchaseType"].ToString().ToLower();
lowerVendorType = lowerVendorType.Substring(3);

калі (lowerVendorType.Equals(Тып фільтра))
{
resultList[vendorIndex ] = новы Прадавец(vendorItem);
}
} // iterating thru all the vendors in the list


вяртанне TrimVendorArray(vendorIndex, resultList);
// return resultList;

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

} // if true

вяртанне нулявы;
}

прыватны Прадавец[] TrimVendorArray(Int newsize, Прадавец[] originalVendorArray)
{
Прадавец[] trimmedArray;

калі (newsize == 0) newsize = 1;
trimmedArray = новы Прадавец[newsize];

Int currentCounter = 0;

для (currentCounter = 0; currentCounter < newsize; currentCounter )
{
trimmedArray[currentCounter] = originalVendorArray[currentCounter];
}

вяртанне trimmedArray;

}
}

Пакінуць каментар

Ваш электронны адрас не будзе апублікаваны. Абавязковыя палі пазначаныя * *