MOSS: Xüsusi siyahıları vasitəsilə Iterating və InfoPath indikatoru data qaytarılması

Biznes Ssenari:

Istifadəçilər tez dəqiq alınması requisitions daxil imkan verir ki, bir üsul təmin.

Biznes problem:

Müştəri neçə yüz satıcıları ilə iş.

Vendors are "type" xüsusi. Bu satıcı kompüter avadanlığının satışı o deməkdir ki, (e.g. Vadi) və ya ofis ləvazimatları (e.g. Staples).

How do we enable end users who create purchase requisitions select a valid vendor?

Business Solution:

Differentiate vendors in the system via "type".

Enable users to select the "type" of product and then provide a filtered set of appropriate vendors.

Texniki Həll:

An InfoPath form has been designed that enables users to enter online purchase requisitions.

Two InfoPath selection lists control vendor selection. Ilk, 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.

Öyrənilmiş Dərslər:

  • Ilk, 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. Lakin, 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, but we can’t get it to work properly. Ona görə də, it was necessary to implement the web service.
  • 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"]. Əvəzində, 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. Bu, əlbəttə, 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 doesn’t care, but it nagged at me. (Yenidən, this was easier than fighting InfoPath over ArrayLists).
  • I implemented a GetSpecificVendorByName() function as well, which may be instructive.

Kod:

istifadə Sistem;
istifadə System.Web;
istifadə System.Web.Services;
istifadə System.Web.Services.Protocols;
istifadə Microsoft.SharePoint;
istifadə System.Configuration;

/// <xülasə>
///
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.
///
/// </xülasə>
[Belediyesi Web Services(Namespace = "http://www.conchango.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
ictimai sinfi VendorService : System.Web.Services.Belediyesi Web Services
{

/// <xülasə>
/// Represents a vendor from a custom sharepoint list maintained by MSUSA.
/// </xülasə>
ictimai sinfi Vendor
{
ictimai Vendor() { }

ictimai Vendor(Tüpürmək initItem)
{
əgər (! (initItem["Vendor Name"] == null)) VendorName = initItem["Vendor Name"].ToString();
əgər (! (initItem["Address 1"] == null)) VendorAddress1 = initItem["Address 1"].ToString();
əgər (! (initItem["Address 2"] == null)) VendorAddress2 = initItem["Address 2"].ToString();
əgər (! (initItem["City"] == null)) VendorCity = initItem["City"].ToString();
əgər (! (initItem["VendorPhone"] == null)) VendorPhone = initItem["VendorPhone"].ToString();
əgər (! (initItem["PurchaseType"] == null)) VendorType = initItem["PurchaseType"].ToString();
əgər (! (initItem["State"] == null)) VendorState = initItem["State"].ToString();
əgər (! (initItem["Zip"] == null)) VendorZip = initItem["Zip"].ToString();
əgər (!(initItem["Fax"] == null)) VendorFax = initItem["Fax"].ToString();
əgər (!(initItem["SalesRepName"] == null)) VendorSalesRepName = initItem["SalesRepName"].ToString();

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

ictimai int VendorItemId;
ictimai sim VendorName;
ictimai sim VendorAddress1;
ictimai sim VendorAddress2;
ictimai sim VendorCity;
ictimai sim VendorState;
ictimai sim VendorZip;
ictimai sim VendorPhone;
ictimai sim VendorType;
ictimai sim VendorSalesRepName;
ictimai sim VendorFax;
}

ictimai VendorService () {

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

xüsusi Vendor[] GenerateTestVendors()
{
Vendor[] resultList;
resultList = yeni Vendor[100];

Vendor v;
v = yeni 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 = yeni 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 = yeni 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;

qayıtmaq resultList;

}

[WebMethod]
ictimai Vendor GetSpecificVendorById(int vendorId)
{
sim SpVendorSiteName; // Name of the actual MOSS site that hosts the vendor custom list.
sim SpVendorListName; // Name of the actual MOSS list containing vendors.

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

istifadə (SPSite site = yeni SPSite(SpVendorSiteName))
{

istifadə (SPWeb web = site.OpenWeb())
{

SPList currentList = web.Lists[SpVendorListName];

Tüpürmək specificItem = currentList.Items[vendorId];

qayıtmaq yeni Vendor(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
ictimai Vendor GetSpecificVendorByVendorName(sim vendorName)
{
sim SpVendorSiteName; // Name of the actual MOSS site that hosts the vendor custom list.
sim SpVendorListName; // Name of the actual MOSS list containing vendors.

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

istifadə (SPSite site = yeni SPSite(SpVendorSiteName))
{
istifadə (SPWeb web = site.OpenWeb())
{

SPList currentList = web.Lists[SpVendorListName];

foreach (Tüpürmək vendorItem ilə currentList.Items)
{
əgər (vendorItem["Vendor Name"] == null) davam etdirmək;

əgər (vendorItem["Vendor Name"].ToString().Bərabər(vendorName))
qayıtmaq yeni Vendor(vendorItem);
}

Vendor v = yeni Vendor();
v.VendorPhone = "not found: " + vendorName;

qayıtmaq v;

qayıtmaq null;

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

} // üsul

[WebMethod]
ictimai Vendor[] GetVendorsOfType (sim filterType)
{

sim SpVendorSiteName; // Name of the actual MOSS site that hosts t
he vendor custom list.
sim SpVendorListName; // Name of the actual MOSS list containing vendors.

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

Vendor[] resultList;
int vendorIndex = 0;
resultList = yeni Vendor[1000];

// Initialize the list with a default friendly message.
Vendor v = yeni 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.
#rayon Filter type = "test"
əgər (filterType.Equals("Test"))
qayıtmaq GenerateTestVendors();
#endregion

əgər (doğru)
{
istifadə (SPSite site = yeni SPSite(SpVendorSiteName))
{
istifadə (SPWeb web = site.OpenWeb())
{

v = null;

SPList currentList = web.Lists[SpVendorListName];

// Iterate through all the items in the vendor list.
foreach (Tüpürmək vendorItem ilə currentList.Items)
{

sim lowerVendorType;

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

əgər (lowerVendorType.Equals(filterType))
{
resultList[vendorIndex ] = yeni Vendor(vendorItem);
}
} // iterating thru all the vendors in the list


qayıtmaq TrimVendorArray(vendorIndex, resultList);
// return resultList;

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

} // if true

qayıtmaq null;
}

xüsusi Vendor[] TrimVendorArray(int newsize, Vendor[] originalVendorArray)
{
Vendor[] trimmedArray;

əgər (newsize == 0) newsize = 1;
trimmedArray = yeni Vendor[newsize];

int currentCounter = 0;

uğrunda (currentCounter = 0; currentCounter < newsize; currentCounter )
{
trimmedArray[currentCounter] = originalVendorArray[currentCounter];
}

qayıtmaq trimmedArray;

}
}

Şəkil Yükləmə

E-poçt ünvanından dərc olunmayacaq. Lazım alanlar qeyd olunur *