Exemplo n.º 1
0
        public static void ReplaceMachineRecrod(MachineRecord r)
        {
            if (r != null)
            {
                var collection = iDatabase.GetCollection <MachineRecord>(Collections.machine_records.ToString());

                var filter = Builders <MachineRecord> .Filter.Eq(e => e.id, r.id);

                collection.ReplaceOne(filter, r);

                collection = iDatabase.GetCollection <MachineRecord>(Collections.machine_records_other.ToString());
                collection.ReplaceOne(filter, r);
            }
        }
Exemplo n.º 2
0
        //static public List<Device> getAllDevices()
        //{
        //    MongoCollection<Device> collection = database.GetCollection<Device>(Collections.device.ToString());
        //    MongoCursor<Device> all = collection.FindAll();

        //    List<Device> list = new List<Device>();

        //    foreach (Device m in all)
        //    {
        //        list.Add(m);
        //    }

        //    return list;
        //}

        #endregion

        #region GetSetDocument

        #region Save

        //static public string SaveDevice(Device d)
        //{
        //    if (d != null)
        //    {
        //        if (DeviceExists(d))
        //            return "";
        //        ObjectId adressid = SaveAddress(d.getAddress());
        //        var col = database.GetCollection(Collections.device.ToString());
        //        d.instalation_address = adressid;
        //        var dev = d;
        //        WriteConcernResult res = col.Save(dev);
        //        Global.log("SaveDevice: " +  res.UpdatedExisting.ToString());
        //        return dev.serial_number;
        //    }
        //    else
        //    {
        //        return "";
        //    }
        //}

        //static private ObjectId SaveAddress(Address d)
        //{
        //    if (d != null)
        //    {
        //        var col = database.GetCollection(Collections.addresses.ToString());
        //        var obj = d;
        //        WriteConcernResult res = col.Save(obj);
        //        Global.log("SaveAddress: " + res.UpdatedExisting.ToString());
        //        return obj.id;
        //    }
        //    else
        //    {
        //        return new ObjectId();
        //    }
        //}

        private static ObjectId SaveMachineRecord_Deleted(MachineRecord r)
        {
            if (r != null)
            {
                var col = database.GetCollection(CollectionsDeleted.machine_record_deleted.ToString());
                var obj = r;
                WriteConcernResult res = col.Save(obj);
                Global.Log("SaveMachineRecord_Deleted: " + res.UpdatedExisting.ToString());
                return((ObjectId)obj.id);
            }
            else
            {
                return(new ObjectId());
            }
        }
Exemplo n.º 3
0
        public int Compare(MachineRecord x, MachineRecord y)
        {
            // Sprawdzanie datą

            int datetime_compare = DateTime.Compare(x.datetime, y.datetime);

            if (datetime_compare > 0)
            {
                return(1);
            }
            else if (datetime_compare < 0)
            {
                return(-1);
            }

            return(0);
        }
Exemplo n.º 4
0
        static public bool DeleteMachineRecord(MachineRecord r)
        {
            if (r == null)
            {
                throw new ArgumentNullException("Machine record in Database.MongoTB.DeleteMachineRecord is null");
            }

            var collection  = database.GetCollection <MachineRecord>(Collections.machine_records.ToString());
            var entityQuery = Query <MachineRecord> .EQ(e => e.id, r.id);

            WriteConcernResult result = collection.Remove(entityQuery);

            r.id = new ObjectId();
            if (r.parsed_by_email == false)
            {
                DeleteHTMLSerial(r.full_serialnumber);
                DeleteHTMLCounter(r.full_counter);
            }
            SaveMachineRecord_Deleted(r);

            return(true);
        }
Exemplo n.º 5
0
        static internal MachineRecord GetFirstInMonth(string serial_number, DateTime month)
        {
            if (serial_number != null)
            {
                //var collection = database.GetCollection<MachineRecord>(Collections.machine_records.ToString());
                //var filter = Builders<MachineRecord>.Filter.Gte(e => e.datetime, month) & Builders<MachineRecord>.Filter.Eq(e => e.serial_number, serial_number);
                //var entityQuery = Query<MachineRecord>(filter);

                var collection = _database.GetCollection <MachineRecord>(Collections.machine_records.ToString());
                var filter     = Builders <MachineRecord> .Filter.Gte(e => e.datetime, month) & Builders <MachineRecord> .Filter.Eq(e => e.serial_number, serial_number);

                IMongoCollection <MachineRecord> col;

                MachineRecord record = collection.Find <MachineRecord>(filter).FirstOrDefault();
                if (record != null)
                {
                    record.InitValues();
                }
                return(record);
            }

            return(null);
        }
Exemplo n.º 6
0
 internal static void ReplaceMachineRecord(MachineRecord record)
 {
     MongoTB.ReplaceMachineRecrod(record);
 }
Exemplo n.º 7
0
 internal static void DeleteMachineRecord(MachineRecord additionalItem)
 {
     MongoTB.DeleteMachineRecord(additionalItem);
 }
    /// <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;
        //}
    }