Several functions used in previous projects

Source: Internet
Author: User

You may be able to use the following for review.

//
// Function: converts all content in ListBox into a string, and each field is separated by commas (,).
//
// Parameter: Lists, The ListBox. items to be converted
//
// Return value: converted string
//
Public string ListToString (ListItemCollection Lists)
{
String result = "";
For (int I = 0; I <Lists. Count; I ++)
{
If (I = 0)
{
Result = Lists [I]. Text;
}
Else
{
Result = result + "," + Lists [I]. Text;
}
}
Return result;
}

//
// Function: Convert all content in string to ListItemCollection to bind to Listbox
//
// Parameter: str, the string to be converted
//
// Return value: converted ListItemCollection
//
Public ListItemCollection StringToList (string str)
{
ListItemCollection lists = new ListItemCollection ();
If (str = "") // the string is empty
{
ErrPosition = "ListItemCollection ";
ErrMsg = "the string is empty ";
}
Else if (str. IndexOf (",") = 0) // The first place is ","
{
ErrPosition = "ListItemCollection ";
ErrMsg = "first ,";
}
Else if (str. Substring (str. Length-1, 1) = ",") // The last bit is ","
{
ErrPosition = "ListItemCollection ";
ErrMsg = "tail bit ,";
}
Else
{
While (str. IndexOf (",")> 0)
{
Int position = str. IndexOf (",");
Lists. Add (str. Substring (0, position ));
Str = str. Remove (0, position + 1 );
}
Lists. Add (str );
}
Return lists;
}

//
// Function: Move the selected data in the source ListBox to the target ListBox.
//
// Parameter: FromLists, source ListBox
//
Public static void MoveListBoxSelectedItem
(ListItemCollection FromLists, ListItemCollection ToLists)
{
For (int I = FromLists. Count-1; I> = 0; I --)
{
If (FromLists [I]. Selected)
{
FromLists [I]. Selected = false;
ToLists. Add (FromLists [I]);
FromLists. Remove (FromLists [I]);
}
}
}

//
// Function: Move all data in the source ListBox to the target ListBox
//
// Parameter: FromLists, source ListBox
//
Public static void MoveListBoxAllItem
(ListItemCollection FromLists, ListItemCollection ToLists)
{
For (int I = FromLists. Count-1; I> = 0; I --)
{
FromLists [I]. Selected = false;
ToLists. Add (FromLists [I]);
FromLists. Remove (FromLists [I]);
}
}

//
// Function: Enter the set of days in which the month is returned.
//
// Parameter: YYYY, MM Month
//
// Return value: ArrayList of the number of days of the month
//
Public static ArrayList GetDaysInMonth (int YYYY, int MM)
{
Int day = DateTime. DaysInMonth (YYYY, MM );
ArrayList days = new ArrayList ();
For (int I = 1; I <= day; I ++)
{
Days. Add (I );
}
Return days;
}

//
// Function: Enter the set of selected days and return the minimum and maximum days.
//
// Parameter: dates. You can pass in Calendar. SelectedDates.
//
// Return value: ArrayList of two values. The first value is the minimum number of days, and the second value is the maximum number of days.
//
Public static ArrayList GetMinMaxDate (SelectedDatesCollection dates)
{
ArrayList Result = new ArrayList ();
DateTime min = new DateTime ();
DateTime max = new DateTime ();
For (int I = 0; I <dates. Count; I ++)
{
If (I> 0)
{
If (dates [I] <min)
{
Min = dates [I];
}
If (dates [I]> max)
{
Max = dates [I];
}
}
Else
{
Min = dates [I];
Max = dates [I];
}
}
Result. Add (min );
Result. Add (max );
Return Result;
}

When a function is called, ListItemCollection uses ListBox. Items as the parameter.

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.