/// <summary> /// This method is inherited from the IComparer interface. It compares the two objects passed using a case insensitive comparison. /// </summary> /// <param name="x">First object to be compared</param> /// <param name="y">Second object to be compared</param> /// <returns>The result of the comparison. "0" if equal, negative if 'x' is less than 'y' and positive if 'x' is greater than 'y'</returns> public int Compare(object x, object y) { int compareResult = 0; Copyinfo.Forms.Controls.ListView.TBListViewItem listviewX, listviewY; // Cast the objects to be compared to ListViewItem objects listviewX = (Copyinfo.Forms.Controls.ListView.TBListViewItem)x; listviewY = (Copyinfo.Forms.Controls.ListView.TBListViewItem)y; string a = listviewX.SubItems[ColumnToSort].Text; string b = listviewY.SubItems[ColumnToSort].Text; // Compare the two items if (ItsColumnWithInt(ColumnToSort)) { compareResult = ObjectCompare.Compare(int.Parse(a), int.Parse(b)); } else if (ItsColumnWithDate(ColumnToSort)) { switch (this.additionalItemType) { case Copyinfo.Forms.Controls.ListView.TBListViewItem.AdditionalItemClassType.None: compareResult = 0; break; case Copyinfo.Forms.Controls.ListView.TBListViewItem.AdditionalItemClassType.MachineRecord: Copyinfo.Database.MachineRecord recordX = (Copyinfo.Database.MachineRecord)listviewX.additionalItem; Copyinfo.Database.MachineRecord recordY = (Copyinfo.Database.MachineRecord)listviewY.additionalItem; compareResult = DateTime.Compare(recordX.datetime, recordY.datetime); break; case Copyinfo.Forms.Controls.ListView.TBListViewItem.AdditionalItemClassType.Device: Copyinfo.Database.Device deviceX = (Copyinfo.Database.Device)listviewX.additionalItem; Copyinfo.Database.Device deviceY = (Copyinfo.Database.Device)listviewY.additionalItem; compareResult = DateTime.Compare(deviceX.instalation_datetime, deviceY.instalation_datetime); break; } } else { compareResult = ObjectCompare.Compare(a, b); } // Calculate correct return value based on object comparison if (OrderOfSort == SortOrder.Ascending) { // Ascending sort is selected, return normal result of compare operation return(compareResult); } else if (OrderOfSort == SortOrder.Descending) { // Descending sort is selected, return negative result of compare operation return(-compareResult); } else { // Return '0' to indicate they are equal return(0); } //int compareResult; //System.Windows.Forms.ListViewItem listviewX, listviewY; //// Cast the objects to be compared to ListViewItem objects //listviewX = (System.Windows.Forms.ListViewItem)x; //listviewY = (System.Windows.Forms.ListViewItem)y; //string a = listviewX.SubItems[ColumnToSort].Text; //string b = listviewY.SubItems[ColumnToSort].Text; //// Compare the two items //if (itsColumnWithInt(ColumnToSort)) // compareResult = ObjectCompare.Compare(int.Parse(a), int.Parse(b)); //else //if (itsColumnWithDate(ColumnToSort)) //{ // Copyinfo.Forms.TBListViewItem_MachineRecord recordA = (Copyinfo.Forms.TBListViewItem_MachineRecord)x; // Copyinfo.Forms.TBListViewItem_MachineRecord recordB = (Copyinfo.Forms.TBListViewItem_MachineRecord)y; // compareResult = DateTime.Compare(recordA.record.datetime, recordB.record.datetime); //} //else //{ // compareResult = ObjectCompare.Compare(a, b); //} //// Calculate correct return value based on object comparison //if (OrderOfSort == SortOrder.Ascending) //{ // // Ascending sort is selected, return normal result of compare operation // return compareResult; //} //else if (OrderOfSort == SortOrder.Descending) //{ // // Descending sort is selected, return negative result of compare operation // return (-compareResult); //} //else //{ // // Return '0' to indicate they are equal // return 0; //} }