コード例 #1
0
ファイル: NSClients.cs プロジェクト: igprog/ppweb
    public string Load(string userId)
    {
        List <NewNSClient> xx = new List <NewNSClient>();

        DB.CreateDataBase(userId, DB.nsClients);
        try {
            if (string.IsNullOrWhiteSpace(userId))
            {
                return(JsonConvert.SerializeObject(xx, Formatting.None));
            }
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DB.GetDataBasePath(userId, userDataBase))) {
                connection.Open();
                string sql = "SELECT id, name, address, nutritionStandard, note FROM nsclients";
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            NewNSClient x = GetData(reader, connection);
                            xx.Add(x);
                        }
                    }
                }
            }
            return(JsonConvert.SerializeObject(xx, Formatting.None));
        } catch (Exception e) {
            L.SendErrorLog(e, null, userId, "NSClients", "Load");
            return(JsonConvert.SerializeObject(xx, Formatting.None));
        }
    }
コード例 #2
0
ファイル: NSClients.cs プロジェクト: igprog/ppweb
    private bool Check(string userId, NewNSClient x)
    {
        bool exists = false;

        try {
            int count = 0;
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DB.GetDataBasePath(userId, userDataBase))) {
                connection.Open();
                string sql = string.Format(@"SELECT COUNT([rowid]) FROM nsclients WHERE TRIM(LOWER(name)) = '{0}'", x.name.Trim().ToLower());
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            count = reader.GetInt32(0);
                        }
                    }
                }
            }
            exists = count == 0;
            return(exists);
        } catch (Exception e) {
            L.SendErrorLog(e, x.id, userId, "NSClients", "Check");
            return(false);
        }
    }
コード例 #3
0
ファイル: NSClients.cs プロジェクト: igprog/ppweb
    public string Init()
    {
        NewNSClient x = new NewNSClient();

        x.id                = null;
        x.name              = null;
        x.address           = null;
        x.nutritionStandard = null;
        x.note              = null;
        return(JsonConvert.SerializeObject(x, Formatting.None));
    }
コード例 #4
0
ファイル: NSClients.cs プロジェクト: igprog/ppweb
    private NewNSClient GetData(SQLiteDataReader reader, SQLiteConnection connection)
    {
        NewNSClient x = new NewNSClient();

        x.id                = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
        x.name              = reader.GetValue(1) == DBNull.Value ? null : reader.GetString(1);
        x.address           = reader.GetValue(2) == DBNull.Value ? null : reader.GetString(2);
        x.nutritionStandard = reader.GetValue(3) == DBNull.Value ? null : reader.GetString(3);
        x.note              = reader.GetValue(4) == DBNull.Value ? null : reader.GetString(4);
        return(x);
    }
コード例 #5
0
ファイル: NSClients.cs プロジェクト: igprog/ppweb
    public string Save(string userId, NewNSClient x, string lang)
    {
        SaveResponse r = new SaveResponse();

        r.response = new Global.Response();
        try {
            DB.CreateDataBase(userId, DB.nsClients);
            string sql = null;
            if (x.id == null && !Check(userId, x))
            {
                r.data         = x;
                r.response.msg = T.Tran("client is already registered", lang);
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }
            Global G = new Global();
            x.name    = G.RemoveSingleQuotes(x.name);
            x.note    = G.RemoveSingleQuotes(x.note);
            x.address = G.RemoveSingleQuotes(x.address);
            if (x.id == null)
            {
                x.id = Convert.ToString(Guid.NewGuid());
            }
            sql = string.Format(@"INSERT OR REPLACE INTO nsclients VALUES
                                    ('{0}', '{1}', '{2}', '{3}', '{4}')"
                                , x.id, x.name, x.address, x.nutritionStandard, x.note);
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DB.GetDataBasePath(userId, userDataBase))) {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteTransaction transaction = connection.BeginTransaction()) {
                        command.ExecuteNonQuery();
                        transaction.Commit();
                    }
                }
            }

            r.data               = x;
            r.response.msg       = T.Tran("saved", lang);
            r.response.isSuccess = true;
            return(JsonConvert.SerializeObject(r, Formatting.None));
        } catch (Exception e) {
            r.data               = x;
            r.response.msg       = e.Message;
            r.response.isSuccess = false;
            L.SendErrorLog(e, x.id, userId, "NSClients", "Save");
            return(JsonConvert.SerializeObject(r, Formatting.None));
        }
    }