using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; //20190718 - do not save profiles without a barcode - maanie namespace MagusEvents { class Person{ public int AASID { get; set; } public int AAID { get; set; } public int AC { get; set; } public string Ref { get; set; } public string FirstName { get; set; } public string Surname { get; set; } public string organisation { get; set; } public string Role { get; set; } public string Barcode { get; set; } public string RoleColor { get; set; } public string Color { get; set; } public string User_pic { get; set; } public string Category { get; set; } public string aZones { get; set; } public string LastUpdate { get; set; } public string SCANID { get; set; } public Person GetRow(string Barcode,int AC) { Database Data = new Database(); string sql = "SELECT * FROM Persons WHERE Barcode = '" + Barcode + "' AND AC = '" + AC + "'"; Console.WriteLine(sql); Person Profile = Data.GetPersonProfile(sql); return Profile; } public Person GetByNFC(string Barcode, int AC) { Database Data = new Database(); string sql = "SELECT * FROM Persons WHERE SCANID = '" + Barcode + "' AND AC = '" + AC + "'"; Person Profile = Data.GetPersonProfile(sql); Console.WriteLine("NFC " + Profile.SCANID); return Profile; } public Person GetImagesUpdates() { Database Data = new Database(); string sql = "SELECT * FROM Persons WHERE User_pic IS NULL OR User_pic = '' OR User_pic = 0 LIMIT 1 "; Person Profile = Data.GetImageUpdates(sql); return Profile; } public int save_to_db(string Web_Data,int UPDATE =0) { int last_saved = 0; try { var JsonObjects = JsonConvert.DeserializeObject(Web_Data); int count = JsonObjects.data.Count; if (count > 0) { Database SQL = new Database(); int i = 0; foreach (var Services in JsonObjects.data) { //20190718 - do not save profiles without a barcode - maanie if(Services.Barcode != "" && Services.Barcode != null) { Console.WriteLine("Savine Line UID: " + Services.SCANID + " " + Services.AASID); string ZONESLIST = Services.aZones; Services.aZones = ZONESLIST.Replace('"', ' '); if (Services.AASID > 0) { Console.WriteLine("Updated UID: " + Services.SCANID + " " + Services.AASID); if (UPDATE == 0) { string path = @"c:\temp_acc\" + Services.AAID + ".jpg"; if (File.Exists(path)) { Services.User_pic = 1; } } last_saved = Services.AASID; string sql = "UPDATE Persons SET " + " AASID = '" + Services.AASID + "'," + " AAID = '" + Services.AAID + "'," + " AC = '" + Services.AC + "'," + " Ref = '" + Services.Ref + "'," + " LastUpdate = '" + Services.LastUpdate + "'," + " FirstName = '" + Services.FirstName + "'," + " Surname = '" + Services.Surname + "'," + " Category = '" + Services.Category + "'," + " organisation = '" + Services.organisation + "', " + " Role = '" + Services.Role + "', " + " Barcode = '" + Services.Barcode + "'," + " aZones = '" + Services.aZones + "'," + " RoleColor = '" + Services.Color + "'," + " SCANID = '" + Services.SCANID + "'," + " User_pic = '" + Services.User_pic + "'" + " WHERE AASID = '" + Services.AASID + "'; "; bool updated = SQL.ExecuteData(sql); if (updated == false) { sql = "insert into Persons (AASID, AAID,AC,Ref,LastUpdate,FirstName,Surname,organisation,Role,Barcode,aZones,Category,RoleColor,SCANID,User_pic)" + " values ('" + Services.AASID + "', '" + Services.AAID + "','" + Services.AC + "','" + Services.Ref + "','" + Services.LastUpdate + "','" + Services.FirstName + ",'" + ",'" + Services.Surname + "','" + Services.organisation + "','" + Services.Role + "','" + Services.Barcode + "','" + Services.aZones + "','" + Services.Category + "','" + Services.Color + "','" + Services.SCANID + "','" + Services.User_pic + "')"; bool Insert = SQL.ExecuteData(sql); } Console.WriteLine(sql); } i++; } } } } catch(Exception Error) { Console.WriteLine(Error.ToString()); } return last_saved; } public void save_to_db(string[] fieldData) { Database SQL = new Database(); string sql = "UPDATE Persons SET " + " AASID = '" + fieldData[0] + "'," + " AAID = '" + fieldData[1] + "'," + " AC = '" + fieldData[2] + "'," + " Ref = '" + fieldData[3] + "'," + " LastUpdate = '" + fieldData[4] + "'," + " FirstName = '" + fieldData[5] + "'," + " Surname = '" + fieldData[6] + "'," + " User_pic = '" + fieldData[7] + "'," + " Category = '" + fieldData[8] + "', " + " IDnumber = '" + fieldData[9] + "', " + " RoleColor = '" + fieldData[10] + "'," + " organisation = '" + fieldData[11] + "'," + " Role = '" + fieldData[12] + "'," + " Barcode = '" + fieldData[13] + "'," + " SCANID = '" + fieldData[14] + "'," + " aZones = '" + fieldData[15] + "'" + " WHERE AASID = '" + fieldData[0] + "'; "; bool updated = SQL.ExecuteData(sql); if (updated == false) { sql = "insert into Persons (AASID, AAID, AC, Ref, LastUpdate, FirstName, Surname, User_pic, Category, IDnumber, RoleColor, organisation, Role, Barcode, SCANID, aZones)" + " values ('" + fieldData[0] + "', '" + fieldData[1] + "','" + fieldData[2] + "','" + fieldData[3] + "','" + fieldData[4] + "','" + fieldData[5] + ",'" + ",'" + fieldData[6] + "','" + fieldData[7] + "','" + fieldData[8] + "','" + fieldData[9] + "','" + fieldData[10] + "','" + fieldData[11] + "','" + fieldData[12] + "','" + fieldData[13] + "','" + fieldData[14] + "','" + fieldData[15] + "')"; bool Insert = SQL.ExecuteData(sql); } } } }