Private string strcheck0 (observablecollection <tabmaterialinquiry> datalist)
{
Dictionary <string, string> mesg = new dictionary <string, string> ();
Mesg. add ("count", "quantity"); mesg. add ("needtime", "demand time"); mesg. add ("sendprice", "submit price"); mesg. add ("unit", "unit"); mesg. add ("type", "type and model ");
Mesg. Add ("name", "material name"); If (mesg = NULL)
Return NULL;
Int I = 1;
Foreach (VAR item in datalist)
{
String mexg = slcommon. datavalidation. getproperties (item, mesg );
If (! String. isnullorempty (Mexico G ))
{
Return "no." + I. tostring () + "row" + mexg;
}
I = I + 1;
}
Return "";
}
Getproperties method definition:
//////////////////////////////////////// ////////////////////////////////////////
// Create: tangang
// Function: data verification is not empty on the page.
// Parameter: the entity to be verified. The attribute and name to be verified by dictionary <string, string>
// Key: property value for verification: the prompt message is displayed.
// Dictionary <"projectname", "Project name">
// Return error message
// Description:
// Time: 2012-06-7
// Call description
// Dictionary <string, string> mesg = new dictionary <string, string> ();
// Mesg. Add ("projectname", "Project name ");
// Mesg. Add ("Address", "Project address ");
// Mesg. Add ("icationicationtime", "notification time ");
// Mesg. Add ("totalfunds", "total funds ");
// Return slcommon. datavalidation. getproperties (projectitem. projectdocument, mesg );
//
//
//////////////////////////////////////// ////////////////////////////////////////
Using system;
Using system. net;
Using system. windows;
Using system. Windows. controls;
Using system. Windows. documents;
Using system. Windows. Ink;
Using system. Windows. input;
Using system. Windows. Media;
Using system. Windows. Media. animation;
Using system. Windows. shapes;
Using system. Collections. Generic;
Namespace glodon. Module. slcommon
{
Public class datavalidation
{
//
/// <Summary>
/// The verification data is not empty.
/// </Summary>
/// <Typeparam name = "T"> </typeparam>
/// <Param name = "T"> entity to be verified </param>
/// <Param name = "mesg"> set of attribute key-value pairs to be verified </param>
/// <Returns> </returns>
Public static string getproperties <t> (T, Dictionary <string, string> mesg)
{
String tstr = string. empty;
If (t = NULL)
{
Return tstr;
}
// Obtain the property object
System. reflection. propertyinfo [] properties = T. GetType (). getproperties (system. reflection. bindingflags. instance | system. reflection. bindingflags. Public );
If (properties. Length <= 0)
{
Return tstr;
}
Foreach (system. reflection. propertyinfo item in properties)
{
String name = item. Name;
Object value = item. getvalue (T, null );
// If it is of the string type, it determines whether it is null.
If (item. propertytype. Name. startswith ("string "))
{
Foreach (VAR items in mesg)
{
If (name. Equals (items. Key) // determines whether the object is specified by the user.
{
If (value = NULL)
{
Tstr = items. Value + "cannot be blank ";
Return tstr;
}
If (string. isnullorempty (value. tostring (). Trim ()))
{
Tstr = items. Value + "cannot be blank ";
Return tstr;
}
}
}
}
Else
{
Foreach (VAR items in mesg)
{
If (name. Equals (items. Key) // determines whether the object is specified by the user.
{
If (value = NULL)
{
Tstr = items. Value + "cannot be blank ";
Return tstr;
}
If (string. isnullorempty (value. tostring ()))
{
Tstr = items. Value + "cannot be blank ";
Return tstr;
}
}
}
}
}
Return tstr;
}
}
}