MOSS: Iterating միջոցով մաքսային ցուցակներում, եւ վերադառնալով ֆիլտրացված տվյալների InfoPath

Բիզնես Սցենար:

Տրամադրել է մեթոդ, որը հնարավորություն է տալիս օգտվողներին մուտք գործել ճշգրիտ գնման requisitions արագ.

Բիզնես խնդիրը:

Հաճախորդը ունի մի քանի հարյուր վաճառողներին.

Vendors are "type" հատուկ. Սա նշանակում է, որ վաճառողը վաճառում է համակարգչային տեխնիկա (e.g. Անտառապատ հովիտ) կամ Գրասենյակային պարագաներ (e.g. Staples).

Ինչպես ենք տալիս վերջնական օգտագործողների, ովքեր ստեղծել գնման requisitions ընտրել վավեր մատակարարին?

Բիզնես Solution:

Differentiate vendors in the system via "type".

Enable users to select the "type" Ապրանքի ապա տրամադրել ֆիլտրացված շարք համապատասխան վաճառողներին.

Տեխնիկական Solution:

An InfoPath ձեւը արդեն մշակված է, որ հնարավորություն է տալիս օգտվողներին մուտք գործել առցանց գնումների requisitions.

Երկու 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.

Արտադրողներ պահվում են MOSS մաքսային ցուցակի հետ մաքսային սյուների համար վաճառողի հատկանիշներ, ինչպիսիք են անունը, address and especially "type".

Իրականացնել վեբ ծառայություն, որը հաճախորդի InfoPath է սպառում, որ iterates միջոցով մաքսային vendor ցուցակում, returning only vendors matching a supplied "type".

Վկայակոչել վեբ ծառայություն միջոցով InfoPath ձեւով.

Քաղված դասերը:

  • Առաջին, թվում անհրաժեշտ է գնալ այդ ճանապարհով. Ես նախընտրում անել զտիչ ամբողջությամբ ներսում InfoPath եւ ստեղծել ցանկացած վեբ ծառայություն ֆունկցիոնալությունը այստեղ. Սակայն, ձեւերը սերվեր չի տրամադրում պահանջվող զտիչ հնարավորություն. We can put a rule onto a the "type" ընտրությունը ցուցակ ձեւի տեսակավորելու են կրկին բացել է վաճառողի հարցումը, սակայն մենք չենք կարող հասնել այն աշխատի. Ուստի, անհրաժեշտ էր իրականացնել ինտերնետային ծառայություն.
  • This is a classic "cascading selection list" խնդիր է InfoPath ձեւերի սերվերի աշխարհում եւ կան շատ լավ օրինակները դուրս այնտեղ, որ բացատրել, թե ինչպես պետք է լուծել այդ.
  • Դատարկ արժեք է սյունակում է վաճառողի ցուցակում չի վերադառնում դատարկ տողը, երբ Ուղեկցող նման: initItem["Vendor Name"]. Փոխարեն, Այն վերադարձնում է առ.

Որոշ այլ Notes:

  • Ես վերադարձնում զանգված[] եւ վաճառողներին, քանի որ ես ինչ - որ դժվարությամբ է վերադառնում ArrayList. InfoPath էր բողոքում, եւ ես չէի ունենա ժամանակ կամ ցանկություն պայքարելու է դրա. Սա, Իհարկե, դնում արհեստական ​​սահմանափակում ընդհանուր թվի ձայների վաճառողներին. Այն նաեւ ստիպված եմ կատարել մի փոքր կարճացրեք() method on the array because I hate the idea of returning back 100’s of null vendors. InfoPath չի հետաքրքրում, բայց nagged ինձ. (Կրկին, դա ավելի հեշտ է, քան պատերազմը 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(լարային vendorName)
{
լարային 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().Հավասար(vendorName))
վերադարձ նոր Վաճառող(vendorItem);
}

Վաճառող v = նոր Վաճառող();
v.VendorPhone = "not found: " + vendorName;

վերադարձ 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;

}
}

Ավելացնել կարծիք

Ձեր էլ. Փոստի հասցեն չի հրապարակվելու. Պահանջվող դաշտերը նշված են աստղանիշով *