public string Get(string userId, string clientId) { try { NewClient x = new NewClient(); using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) { connection.Open(); string sql = string.Format("SELECT clientId, firstName, lastName, birthDate, gender, phone, email, userId, date, isActive, note FROM clients WHERE clientId = '{0}'", clientId); using (SQLiteCommand command = new SQLiteCommand(sql, connection)) { ClientsData c = new ClientsData(); using (SQLiteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { x.clientId = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0); x.firstName = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1); x.lastName = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2); x.birthDate = reader.GetValue(3) == DBNull.Value ? DateTime.Now.ToString() : reader.GetString(3); x.gender.value = reader.GetValue(4) == DBNull.Value ? 0 : reader.GetInt32(4); x.gender.title = GetGender(x.gender.value).title; x.phone = reader.GetValue(5) == DBNull.Value ? "" : reader.GetString(5); x.email = reader.GetValue(6) == DBNull.Value ? "" : reader.GetString(6); x.userId = reader.GetValue(7) == DBNull.Value ? "" : reader.GetString(7); x.date = reader.GetValue(8) == DBNull.Value ? DateTime.Today.ToString() : reader.GetString(8); x.isActive = reader.GetValue(9) == DBNull.Value ? 1 : reader.GetInt32(9); x.note = reader.GetValue(10) == DBNull.Value ? "" : reader.GetString(10); x.profileImg = GetProfileImg(userId, x.clientId); x.clientData = c.GetClientData(userId, clientId, connection); } } } connection.Close(); } return(JsonConvert.SerializeObject(x, Formatting.None)); } catch (Exception e) { return("error: " + e); } }
public string GetClientGroupCalculation(string userId, List <Clients.NewClient> clientGroup) { try { List <Clients.NewClient> xx = new List <Clients.NewClient>(); if (string.IsNullOrWhiteSpace(userId) || clientGroup.Count < 2) { return(JsonConvert.SerializeObject(xx, Formatting.None)); } ClientsData CD = new ClientsData(); using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, userDataBase))) { connection.Open(); foreach (var client in clientGroup) { var clientData = CD.GetClientData(userId, client.clientId, connection); client.clientData = clientData; var calculation = new NewCalculation(); calculation = GetCalculationData(clientData, 1); client.calculation = calculation; xx.Add(client); } } return(JsonConvert.SerializeObject(xx, Formatting.None)); } catch (Exception e) { L.SendErrorLog(e, null, userId, "ClientsData", "GetClientGroupCalculation"); return(JsonConvert.SerializeObject(e.Message, Formatting.None)); } }
private static NewClient GetData(SQLiteDataReader reader, string userId, bool getClientData, SQLiteConnection connection) { NewClient x = new NewClient(); x.clientId = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0); x.firstName = reader.GetValue(1) == DBNull.Value ? null : reader.GetString(1); x.lastName = reader.GetValue(2) == DBNull.Value ? null : reader.GetString(2); x.birthDate = reader.GetValue(3) == DBNull.Value ? DateTime.Now.ToString() : reader.GetString(3); x.gender.value = reader.GetValue(4) == DBNull.Value ? 0 : reader.GetInt32(4); x.gender.title = GetGenderTitle(x.gender.value); x.phone = reader.GetValue(5) == DBNull.Value ? null : reader.GetString(5); x.email = reader.GetValue(6) == DBNull.Value ? null : reader.GetString(6); x.userId = reader.GetValue(7) == DBNull.Value ? null : reader.GetString(7); x.date = reader.GetValue(8) == DBNull.Value ? DateTime.Today.ToString() : reader.GetString(8); x.isActive = reader.GetValue(9) == DBNull.Value ? 1 : reader.GetInt32(9); x.note = reader.GetValue(10) == DBNull.Value ? null : reader.GetString(10); x.cids = reader.GetValue(11) == DBNull.Value ? null : reader.GetString(11); if (string.IsNullOrWhiteSpace(x.cids)) { x.cids = null; } if (!x.clientId.Contains(';')) { x.profileImg = GetProfileImg(userId, x.clientId); } x.clientData = new ClientsData.NewClientData(); Calculations calc = new Calculations(); x.clientData.age = calc.Age(x.birthDate); Users users = new Users(); x.userGroupId = users.GetUserGroupId(x.userId); if (getClientData) { ClientsData c = new ClientsData(); x.clientData = c.GetClientData(userId, x.clientId, connection); } return(x); }