Esempio n. 1
0
 public ArrayList GetAudits()
 {
     ArrayList list_audits = new ArrayList();
     try
     {
         connection = new SQLiteConnection("Data Source=" + dbpath + "; Version=3; MultipleActiveResultSets=True; foreign keys=true;");
         connection.Open();
         command = new SQLiteCommand(connection);
         command.CommandText = "SELECT * FROM audit;";
         SQLiteDataReader r = command.ExecuteReader();
         while (r.Read())
         {
             Audit a = new Audit(r.GetInt32(0), r.GetInt32(1), r.GetInt32(2));
             a.Date = r.GetDateTime(3);
             SQLiteCommand command2 = new SQLiteCommand(connection);
             command2.CommandText = "SELECT * FROM results WHERE auditNumber=@auditNumber;";
             command2.Parameters.AddWithValue("@auditNumber", a.AuditNumber);
             SQLiteDataReader r_inner = command2.ExecuteReader();
             while (r_inner.Read())
             {
                 a.AddResult(r_inner.GetInt32(1), r_inner.GetInt32(2));
             }
             list_audits.Add(a);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show("Error SQL Reading Audits", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Log.WriteLog(e.Message);
     }
     connection.Close();
     return list_audits;
 }
        //functions
        public void Compare()
        {
            if (currentCustomer == null)
            {
                MessageBox.Show("Kein Kunde ausgewählt. Bitte einen Kunden auswählen und Audit erneut starten.", "Kein Kunde ausgewählt.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                currentAudit = new Audit(list_audits.Count, currentCustomer.Cnumber, currentSystemInventory.SystemInventoryNumber);
                //Count Systems
                //
                //get List of system types
                List<string> types = new List<string>();
                foreach (ClientSystem c in currentSystemInventory.List_Systems)
                {
                    //Add  only types of systems with detailed Information and types which aren't in the list already
                    if ((!types.Contains(c.Type)) && (c.Type != null) && !(c.Type.Equals("")))
                    {
                        types.Add(c.Type);
                    }
                }
                //count occurence of types in Systeminventory
                int[] count = new int[types.Count];
                for (int i = 0; i < types.Count; i++)
                {
                    count[i] = 0;
                    foreach (ClientSystem c in currentSystemInventory.List_Systems)
                    {
                        //do this only for systems with detailed information
                        if (c.Type != null && !(c.Type.Equals("")))
                        {
                            if (c.Type.Equals(types[i]))
                            {
                                count[i]++;
                                Log.WriteLog(String.Format("{0} occures {1} times", types[i], count[i]));
                            }
                        }
                    }
                }
                //Compare against Licennse Inventory
                for (int i = 0; i < types.Count; i++)
                {
                    int licenses = 0;
                    //Get the licensenumber of the current type (if licensetype is known)
                    int licensenumber = -1;
                    foreach (License l in list_allAvailableLicenses)
                    {
                        if (l.Name.Equals(types[i]))
                        {
                            licensenumber = l.LicenseNumber;
                        }
                    }
                    if (licensenumber == -1)
                    {
                        //licensetype unknown, learn it (shouldn't happen because license should be learned during inventoryprocess)
                        License newlicense = new License(list_allAvailableLicenses.Count, types[i]);
                        list_allAvailableLicenses.Add(newlicense);
                        db.SaveLicense(newlicense);
                        licensenumber = newlicense.LicenseNumber;
                    }
                    //Get the corresponding count of the licensinventory, if the license isn't in the inventory the count is 0 (initialised)
                    for (int x = 0; x < currentLicenseInventory.Inventory.Count; x++)
                    {
                        Tuple<int, int> t = (Tuple<int, int>)currentLicenseInventory.Inventory[x];
                        if (t.Item1 == licensenumber)
                        {
                            licenses = t.Item2;
                            x = currentLicenseInventory.Inventory.Count;
                        }
                    }
                    //Add result to Audit, Licensenumber and number of free licenses of this type
                    currentAudit.AddResult(licensenumber, licenses - count[i]);
                }
                //Add licenses of invetory to results which aren't already added
                ArrayList helpList = new ArrayList();
                foreach (Tuple<int, int> tuplelicense in currentLicenseInventory.Inventory)
                {
                    bool contains = false;
                    Tuple<int, int> helpTuple = new Tuple<int, int>(-1, -1);
                    foreach (Tuple<int, int> t in currentAudit.Results)
                    {
                        helpTuple = (Tuple<int, int>)t;
                        if (helpTuple.Item1 == tuplelicense.Item1)
                        {
                            contains = true;
                            break;
                        }
                    }
                    if (!contains)
                    {
                        currentAudit.AddResult(tuplelicense.Item1, tuplelicense.Item2);
                    }
                }
                list_audits.Add(currentAudit);
                db.SaveAudit(currentAudit);
                callingController.UpdateInformation();
                MessageBox.Show("Audit abgeschlossen.", "Audit abgeschlossen", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            UpdateView(false);

        }