1. SL verifies whether the value in a list is empty.

Source: Internet
Author: User

 

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;
}
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.