示例#1
0
 public string GetActiveEvents(Users.NewUser user, string now)
 {
     try {
         db.CreateDataBase(user.userGroupId, db.scheduler);
         List <Event> xx = new List <Event>();
         if (user.userType > 0)
         {
             using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(user.userGroupId, dataBase))) {
                 connection.Open();
                 string sql = string.Format(@"
                         SELECT rowid, room, clientId, content, startDate, endDate, userId FROM scheduler WHERE userId = '{0}' AND endDate > {1}", user.userId, now);
                 using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                     using (SQLiteDataReader reader = command.ExecuteReader()) {
                         while (reader.Read())
                         {
                             Event x = new Event();
                             x.id        = reader.GetValue(0) == DBNull.Value ? 0 : reader.GetInt32(0);
                             x.room      = reader.GetValue(1) == DBNull.Value ? 0 : reader.GetInt32(1);
                             x.clientId  = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
                             x.content   = reader.GetValue(3) == DBNull.Value ? "" : reader.GetString(3);
                             x.startDate = reader.GetValue(4) == DBNull.Value ? 0 : reader.GetInt64(4);
                             x.endDate   = reader.GetValue(5) == DBNull.Value ? 0 : reader.GetInt64(5);
                             x.userId    = reader.GetValue(6) == DBNull.Value ? "" : reader.GetString(6);
                             xx.Add(x);
                         }
                     }
                     connection.Close();
                 }
             }
         }
         return(JsonConvert.SerializeObject(xx, Formatting.None));
     } catch (Exception e) { return(JsonConvert.SerializeObject(e.Message, Formatting.None)); }
 }
示例#2
0
    public string Init(Users.NewUser user, Clients.NewClient client, string lang)
    {
        NewWeeklyMenus x = new NewWeeklyMenus();

        x.id        = null;
        x.title     = null;
        x.note      = null;
        x.diet      = new Diets.NewDiet();
        x.diet.id   = client.clientData.diet.id;
        x.diet.diet = t.Tran(client.clientData.diet.diet, lang);
        x.menuList  = new List <string>()
        {
            "", "", "", "", "", "", ""
        };
        x.menuDes = new List <MenuDes>()
        {
            new MenuDes(), new MenuDes(), new MenuDes(), new MenuDes(), new MenuDes(), new MenuDes(), new MenuDes()
        };
        x.date                = DateTime.UtcNow.ToString();
        x.client              = client;
        x.userId              = user.userId;
        x.userGroupId         = user.userGroupId;
        x.isNutritionStandard = false;
        return(JsonConvert.SerializeObject(x, Formatting.None));
    }
示例#3
0
    public string Init(Users.NewUser user)
    {
        NewMyMeals x = new NewMyMeals();

        x.id          = null;
        x.title       = null;
        x.description = null;
        x.userId      = user.userId;
        x.userGroupId = user.userGroupId;
        List <Meals.NewMeal> mm = new List <Meals.NewMeal>();
        List <Foods.MealsRecommendationEnergy> ee = new List <Foods.MealsRecommendationEnergy>();

        Meals.NewMeal m = new Meals.NewMeal();
        m.code        = "MM0";
        m.title       = "";
        m.description = "";
        m.isSelected  = true;
        m.isDisabled  = false;
        mm.Add(m);
        Foods.MealsRecommendationEnergy e = new Foods.MealsRecommendationEnergy();
        e.meal.code = m.code;
        e.meal.energyMinPercentage = 0;
        e.meal.energyMaxPercentage = 0;
        ee.Add(e);
        JsonFileMeals data = new JsonFileMeals();

        data.meals      = mm;
        data.energyPerc = ee;
        x.data          = data;
        return(JsonConvert.SerializeObject(x, Formatting.None));
    }
示例#4
0
 public string Save(Users.NewUser user, NewClient x, string lang)
 {
     try {
         db.CreateDataBase(user.userGroupId, db.clients);
         db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "note");  //new column in clients tbl.
         SaveResponse r = new SaveResponse();
         if (x.clientId == null && Check(user.userGroupId, x) == false)
         {
             r.data    = null;
             r.message = t.Tran("client is already registered", lang);
             return(JsonConvert.SerializeObject(r, Formatting.None));
         }
         else
         {
             if (x.clientId == null)
             {
                 //************TODO***************
                 int clientsLimit = MonthlyLimitOfClients(user.userType);
                 if (NumberOfClientsPerMonth(user.userGroupId) > clientsLimit)
                 {
                     r.data    = null;
                     r.message = string.Format("{0} {1}.", t.Tran("client was not saved. the maximum number of clients in one month is", lang), clientsLimit);
                     return(JsonConvert.SerializeObject(r, Formatting.None));
                 }
                 else
                 {
                     x.clientId = Convert.ToString(Guid.NewGuid());
                 }
             }
             using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(user.userGroupId, dataBase))) {
                 connection.Open();
                 string sql = @"INSERT OR REPLACE INTO clients VALUES
                         (@clientId, @firstName, @lastName, @birthDate, @gender, @phone, @email, @userId, @date, @isActive, @note)";
                 using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                     using (SQLiteTransaction transaction = connection.BeginTransaction()) {
                         command.Parameters.Add(new SQLiteParameter("clientId", x.clientId));
                         command.Parameters.Add(new SQLiteParameter("firstName", x.firstName));
                         command.Parameters.Add(new SQLiteParameter("lastName", x.lastName));
                         command.Parameters.Add(new SQLiteParameter("birthDate", x.birthDate));
                         command.Parameters.Add(new SQLiteParameter("gender", x.gender.value));
                         command.Parameters.Add(new SQLiteParameter("phone", x.phone));
                         command.Parameters.Add(new SQLiteParameter("email", x.email));
                         command.Parameters.Add(new SQLiteParameter("userId", x.userId));
                         command.Parameters.Add(new SQLiteParameter("date", x.date));
                         command.Parameters.Add(new SQLiteParameter("isActive", x.isActive));
                         command.Parameters.Add(new SQLiteParameter("note", x.note));
                         command.ExecuteNonQuery();
                         transaction.Commit();
                     }
                 }
                 connection.Close();
             }
             r.data = x;
             r.data.gender.title = GetGenderTitle(r.data.gender.value);
             r.message           = null;
             return(JsonConvert.SerializeObject(r, Formatting.None));
         }
     } catch (Exception e) { return(e.Message); }
 }
示例#5
0
 public string SaveProduct(NewProduct product, Users.NewUser user)
 {
     if (product.productId == null)
     {
         return(Save(product, user));
     }
     else
     {
         return(Update(product));
     }
 }
示例#6
0
    public string Save(string userId, NewMenu x, Users.NewUser user, MyMeals.NewMyMeals myMeals)
    {
        db.CreateDataBase(userId, db.menues);
        if (x.id == null && Check(userId, x) != false)
        {
            return("error");
        }
        else
        {
            try {
                string sql = null;
                if (x.id == null)
                {
                    x.id = Convert.ToString(Guid.NewGuid());
                    sql  = string.Format(@"BEGIN;
                    INSERT INTO menues (id, title, diet, date, note, userId, clientId, userGroupId, energy)
                    VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}');
                    COMMIT;", x.id, x.title, x.diet, x.date, x.note, user.userId, x.client.clientId, string.IsNullOrEmpty(x.userGroupId) ? userId : x.userGroupId, x.energy);
                }
                else
                {
                    sql = string.Format(@"BEGIN;
                    UPDATE menues SET
                    title = '{1}', diet = '{2}', date = '{3}', note = '{4}', userId = '{5}', clientId = '{6}', userGroupId = '{7}', energy = '{8}'
                    WHERE id = '{0}';
                    COMMIT;", x.id, x.title, x.diet, x.date, x.note, user.userId, x.client.clientId, string.IsNullOrEmpty(x.userGroupId) ? userId : x.userGroupId, x.energy);
                }
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
                    connection.Open();
                    using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                        command.ExecuteNonQuery();
                    }
                    connection.Close();
                }

                SaveJsonToFile(userId, x.id, JsonConvert.SerializeObject(x.data, Formatting.None));
                if (myMeals != null)
                {
                    if (myMeals.data != null)
                    {
                        if (myMeals.data.meals.Count > 2)
                        {
                            SaveMyMealsJsonToFile(userId, x.id, JsonConvert.SerializeObject(myMeals, Formatting.None));
                        }
                    }
                }
                string json = JsonConvert.SerializeObject(x, Formatting.None);
                return(json);
            } catch (Exception e) { return(e.Message); }
        }
    }
示例#7
0
    public string Save(Users.NewUser user, NewWeeklyMenus x)
    {
        SaveResponse r = new SaveResponse();

        try {
            //db.CreateDataBase(user.userGroupId, db.weeklymenus);
            //db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.weeklymenus, "isNutritionStandard", "VARCHAR");  //new column in menues tbl.
            if (string.IsNullOrEmpty(x.id) && Check(user.userGroupId, x.title))
            {
                r.data      = x;
                r.msg       = "there is already a menu with the same name";
                r.isSuccess = false;
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }
            Global G = new Global();
            if (!G.CheckUserPermission(user, x.userId) && !string.IsNullOrWhiteSpace(x.id))
            {
                r.isSuccess = false;
                r.msg       = "you can only save menus that you have created yourself";
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }
            if (string.IsNullOrEmpty(x.id))
            {
                x.id = Convert.ToString(Guid.NewGuid());
            }
            x.title = G.RemoveSingleQuotes(x.title);
            x.note  = G.RemoveSingleQuotes(x.note);
            string sql = string.Format(@"BEGIN;
                                    INSERT OR REPLACE INTO weeklymenus (id, title, note, dietId, diet, menuList, date, clientId, userId, userGroupId, isNutritionStandard)
                                    VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}');
                                    COMMIT;", x.id, x.title, x.note, x.diet.id, x.diet.diet, string.Join(",", x.menuList), x.date, x.client.clientId, x.userId, x.userGroupId, x.isNutritionStandard);
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(user.userGroupId, dataBase))) {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    command.ExecuteNonQuery();
                }
            }
            r.data      = x;
            r.msg       = "saved";
            r.isSuccess = true;
            return(JsonConvert.SerializeObject(r, Formatting.None));
        } catch (Exception e) {
            r.data      = x;
            r.msg       = e.Message;
            r.msg1      = "report a problem";
            r.isSuccess = false;
            L.SendErrorLog(e, x.id, user.userId, "WeeklyMenus", "Save");
            return(JsonConvert.SerializeObject(r, Formatting.None));
        }
    }
示例#8
0
 public string Delete(string userId, string clientId, Users.NewUser user)
 {
     try {
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
             connection.Open();
             string sql = @"delete from clients where clientId = @clientId;
                     delete from clientsdata where clientId = @clientId";
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 command.Parameters.Add(new SQLiteParameter("clientId", clientId));
                 command.ExecuteNonQuery();
             }
             connection.Close();
         }
     } catch (Exception e) { return("error: " + e); }
     return(JsonConvert.SerializeObject(GetClients(userId, user, null, null), Formatting.None));
 }
示例#9
0
    public string Load(string userId, Users.NewUser user, string query, int?limit, int offset, bool isClientGroup)
    {
        List <NewClient> xx = new List <NewClient>();

        db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "cids", "VARCHAR(200)");  //new column in cids tbl.
        try {
            Global G = new Global();
            query = G.SpecChrSearchQuery(query);
            bool isAdminTypeSql = user.adminType > (int)Global.AdminType.supervisor;

            if (string.IsNullOrWhiteSpace(userId))
            {
                return(JsonConvert.SerializeObject(xx, Formatting.None));
            }
            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, cids 
                        FROM clients
                        WHERE {0}
                        {1}
                        ORDER BY rowid DESC {2}"
                                           , isClientGroup ? "(cids NOT NULL AND cids <> '')" : "(cids IS NULL OR cids = '')"
                                           , !string.IsNullOrWhiteSpace(query)
                                        ? string.Format("AND (LOWER(firstName) LIKE '%{0}%' OR LOWER(lastName) LIKE '%{0}%' OR LOWER(clientId) = '{0}' {1})", query, isAdminTypeSql ? string.Format("AND userId = '{0}' ", user.userId) : null)
                                        : isAdminTypeSql ? string.Format("AND userId = '{0}' ", user.userId) : null
                                           , limit != null ? string.Format("LIMIT {0} OFFSET {1}", limit, offset) : null);
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            NewClient x = GetData(reader, userId, false, connection);
                            xx.Add(x);
                        }
                    }
                }
            }
            return(JsonConvert.SerializeObject(xx, Formatting.None));
        } catch (Exception e) {
            L.SendErrorLog(e, null, userId, "Clients", "Load");
            return(JsonConvert.SerializeObject(xx, Formatting.None));
        }
    }
示例#10
0
    public List <NewClient> GetClients(string userId, Users.NewUser user, string order, string dir)
    {
        List <NewClient> xx = new List <NewClient>();

        try {
            db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "note");  //new column in clients tbl.
            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 {0} ORDER BY {1} {2}"
                                           , user.adminType > 0 ? string.Format("WHERE userId = '{0}' ", user.userId) : ""
                                           , string.IsNullOrEmpty(order) ? "rowid" : order
                                           , string.IsNullOrEmpty(dir) ? "DESC" : dir);
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        Gender g = new Gender();
                        while (reader.Read())
                        {
                            NewClient x = new NewClient();
                            x.clientId     = reader.GetValue(0) == DBNull.Value ? "" : 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.Today.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);
                            xx.Add(x);
                        }
                    }
                }
                connection.Close();
            }
            return(xx);
        } catch (Exception e) { return(new List <NewClient>()); }
    }
示例#11
0
    public string SendWeeklyMenu(string email, Users.NewUser user, string pdfLink, string title, string note, string lang)
    {
        try {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(string.Format(@"<h3>{0}</h3>", title));
            if (!string.IsNullOrWhiteSpace(note))
            {
                sb.AppendLine(string.Format(@"<p>{0}</p>", note));
            }
            sb.AppendLine("<hr />");
            sb.AppendLine(string.Format(@"<i>* {0}</i>", t.Tran("this is an automatically generated email – please do not reply to it", lang)));

            string subject = string.Format("{0} - {1}"
                                           , !string.IsNullOrWhiteSpace(user.companyName) ? user.companyName : string.Format("{0} {1}", user.firstName, user.lastName)
                                           , title);

            bool sent = SendMail_menu(email, subject, sb.ToString(), lang, pdfLink); /*SendMail(email, subject, sb.ToString(), lang, pdfLink);*/
            return(sent == true?t.Tran("menu sent successfully", lang) : t.Tran("menu is not sent", lang));
        } catch (Exception e) { return("error: " + e); }
    }
示例#12
0
文件: Prices.cs 项目: igprog/ppweb
    public static Discount GetDiscountData(Users.NewUser user)
    {
        Files    F = new Files();
        Discount x = new Discount();
        Global   G = new Global();

        x = F.GetSettingsData().discount;
        if (G.DateDiff(Convert.ToDateTime(Global.NowLocal()), Convert.ToDateTime(x.dateTo), false) < 0)
        {
            x.perc = 0;
        }
        if (user != null)
        {
            if (!string.IsNullOrWhiteSpace(user.userGroupId) && (user.licenceStatus != Global.LicenceStatus.demo))
            {
                double oldUserDiscountPerc = F.GetSettingsData().discount.oldUserDiscountPerc.packages.Where(a => a.package == user.package).FirstOrDefault().discountPerc;
                x.perc = oldUserDiscountPerc > x.perc ? oldUserDiscountPerc : x.perc;
            }
        }
        return(x);
    }
示例#13
0
文件: Menues.cs 项目: igprog/ppweb
    public string Delete(Users.NewUser user, NewMenu menu)
    {
        var x = new Global.Response();

        try {
            if (!string.IsNullOrEmpty(user.userGroupId) && !string.IsNullOrEmpty(menu.id))
            {
                Global G = new Global();
                if (!G.CheckUserPermission(user, menu.userId))
                {
                    x.isSuccess = false;
                    x.msg       = "you can only delete menus that you have created yourself";
                    return(JsonConvert.SerializeObject(x, Formatting.None));
                }
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(user.userGroupId, userDataBase))) {
                    connection.Open();
                    string sql = string.Format("DELETE FROM menues WHERE id = '{0}'", menu.id);
                    using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                        command.ExecuteNonQuery();
                    }
                    F.DeleteJsonFile(user.userGroupId, menu.id, "menues", null);
                }
                x.isSuccess = true;
                x.msg       = "deleted";
                return(JsonConvert.SerializeObject(x, Formatting.None));
            }
            else
            {
                x.isSuccess = false;
                x.msg       = "error";
                return(JsonConvert.SerializeObject(x, Formatting.None));
            }
        } catch (Exception e) {
            x.isSuccess = false;
            x.msg       = e.Message;
            L.SendErrorLog(e, menu.id, user.userId, "Menues", "Delete");
            return(JsonConvert.SerializeObject(x, Formatting.None));
        }
    }
示例#14
0
文件: Scheduler.cs 项目: igprog/ppweb
 public string GetSchedulerEvents(Users.NewUser user, int room, string uid, bool shawAll)
 {
     try {
         //db.CreateDataBase(user.userGroupId, db.scheduler);
         List <Event> xx = new List <Event>();
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(user.userGroupId, dataBase))) {
             connection.Open();
             long   fromLastMonth = !shawAll ? (long)(DateTime.UtcNow.AddMonths(-1) - new DateTime(1970, 1, 1)).TotalMilliseconds : 0;
             string sql           = string.Format(@"
                         SELECT rowid, room, clientId, content, startDate, endDate, userId FROM scheduler WHERE room = {0} {1} {2}"
                                                  , room
                                                  , user.adminType == 0 && uid == null ? "" : string.Format(" AND userId = '{0}'", uid == null ? user.userId : uid)
                                                  , !shawAll ? string.Format("AND startDate > {0}", fromLastMonth) : null);
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 using (SQLiteDataReader reader = command.ExecuteReader()) {
                     while (reader.Read())
                     {
                         Event x = new Event();
                         x.id        = reader.GetValue(0) == DBNull.Value ? 0 : reader.GetInt32(0);
                         x.room      = reader.GetValue(1) == DBNull.Value ? 0 : reader.GetInt32(1);
                         x.clientId  = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
                         x.content   = reader.GetValue(3) == DBNull.Value ? "" : reader.GetString(3);
                         x.startDate = reader.GetValue(4) == DBNull.Value ? 0 : reader.GetInt64(4);
                         x.endDate   = reader.GetValue(5) == DBNull.Value ? 0 : reader.GetInt64(5);
                         x.userId    = reader.GetValue(6) == DBNull.Value ? "" : reader.GetString(6);
                         xx.Add(x);
                     }
                 }
             }
         }
         return(JsonConvert.SerializeObject(xx, Formatting.None));
     } catch (Exception e) {
         L.SendErrorLog(e, user.rowid.ToString(), uid, "Scheduler", "GetSchedulerEvents");
         return(JsonConvert.SerializeObject(e.Message, Formatting.None));
     }
 }
示例#15
0
 public string Save(NewProduct product, Users.NewUser user)
 {
     try {
         product.productId    = Guid.NewGuid();
         product.productOwner = user.userId;
         SqlConnection connection = new SqlConnection(connectionString);
         connection.Open();
         string     sql     = @"INSERT INTO Products VALUES
                     (@ProductId, @ProductGroup, @ProductOwner, @Title, @ShortDescription, @LongDescription, @Address, @PostalCode, @City, @Phone, @Email, @Web, @Price, @Latitude, @Longitude, @Image, @DateModified, @IsActive, @DisplayType)";
         SqlCommand command = new SqlCommand(sql, connection);
         command.Parameters.Add(new SqlParameter("ProductId", product.productId));
         command.Parameters.Add(new SqlParameter("ProductGroup", product.productGroup));
         command.Parameters.Add(new SqlParameter("ProductOwner", product.productOwner));
         command.Parameters.Add(new SqlParameter("Title", product.title));
         command.Parameters.Add(new SqlParameter("ShortDescription", product.shortDescription));
         command.Parameters.Add(new SqlParameter("LongDescription", product.longDescription));
         command.Parameters.Add(new SqlParameter("Address", product.address));
         command.Parameters.Add(new SqlParameter("PostalCode", product.postalCode));
         command.Parameters.Add(new SqlParameter("City", product.city));
         command.Parameters.Add(new SqlParameter("Phone", product.phone));
         command.Parameters.Add(new SqlParameter("Email", product.email));
         command.Parameters.Add(new SqlParameter("Web", product.web));
         command.Parameters.Add(new SqlParameter("Price", product.price));
         command.Parameters.Add(new SqlParameter("Latitude", product.latitude));
         command.Parameters.Add(new SqlParameter("Longitude", product.longitude));
         command.Parameters.Add(new SqlParameter("Image", product.image));
         command.Parameters.Add(new SqlParameter("DateModified", DateTime.Now));
         command.Parameters.Add(new SqlParameter("IsActive", product.isActive));
         command.Parameters.Add(new SqlParameter("DisplayType", product.displayType));
         command.ExecuteNonQuery();
         connection.Close();
         return(JsonConvert.SerializeObject(product, Formatting.Indented));
     } catch (Exception e) {
         return(string.Format(@"Error! Product not saved. ({0})", e.Message));
     }
 }
示例#16
0
    public string Save(Users.NewUser user, NewClient x, string lang)
    {
        SaveResponse r = new SaveResponse();

        try {
            //db.CreateDataBase(user.userGroupId, db.clients);
            db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "note");                 //new column in clients tbl.
            db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "cids", "VARCHAR(200)"); //new column in cids tbl.
            db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "dailyActivities", "TEXT");
            db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "myRecommendedEnergyIntake", "VARCHAR(50)");
            db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "myRecommendedEnergyExpenditure", "VARCHAR(50)");
            db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "myMeals", "TEXT");
            db.AddColumn(user.userGroupId, db.GetDataBasePath(user.userGroupId, dataBase), db.clients, "allergens", "TEXT");
            string sql = null;
            if (x.clientId == null && !Check(user.userGroupId, x))
            {
                r.data      = null;
                r.isSuccess = false;
                r.msg       = t.Tran("client is already registered", lang);
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }
            Global G = new Global();
            x.note = G.RemoveSingleQuotes(x.note);
            if (x.clientId == null)
            {
                x.clientId = Convert.ToString(Guid.NewGuid());
            }
            //************TODO***************
            int clientsLimit = MonthlyLimitOfClients(user.userType);
            if (NumberOfClientsPerMonth(user.userGroupId) > clientsLimit)
            {
                r.data = null;
                r.msg  = string.Format("{0} {1}.", t.Tran("client was not saved. the maximum number of clients in one month is", lang), clientsLimit);
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }
            sql = string.Format(@"INSERT OR REPLACE INTO clients VALUES
                                ('{0}', '{1}', '{2}', '{3}', {4}, '{5}', '{6}', '{7}', '{8}', {9}, '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}')"
                                , x.clientId
                                , x.firstName
                                , x.lastName
                                , x.birthDate
                                , x.gender.value
                                , x.phone
                                , x.email
                                , x.userId
                                , x.date
                                , x.isActive
                                , x.note
                                , x.cids
                                , x.clientData.dailyActivities.activities == null ? null : JsonConvert.SerializeObject(x.clientData.dailyActivities.activities, Formatting.None)
                                , x.clientData.myCalculation.recommendedEnergyIntake
                                , x.clientData.myCalculation.recommendedEnergyExpenditure
                                , JsonConvert.SerializeObject(x.clientData.myMeals, Formatting.None)
                                , x.allergens);
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(user.userGroupId, dataBase))) {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteTransaction transaction = connection.BeginTransaction()) {
                        command.ExecuteNonQuery();
                        transaction.Commit();
                    }
                }
            }
            r.data = x;
            r.data.gender.title = GetGenderTitle(r.data.gender.value);
            r.data.userGroupId  = user.userGroupId;
            r.msg       = null;
            r.isSuccess = true;
            return(JsonConvert.SerializeObject(r, Formatting.None));
        } catch (Exception e) {
            r.data      = null;
            r.msg       = e.Message;
            r.isSuccess = false;
            L.SendErrorLog(e, x.clientId, x.userId, "Clients", "Save");
            return(JsonConvert.SerializeObject(r, Formatting.None));
        }
    }
示例#17
0
文件: Menues.cs 项目: igprog/ppweb
    public string Save(string userId, NewMenu x, Users.NewUser user, MyMeals.NewMyMeals myMeals)
    {
        SaveResponse r = new SaveResponse();

        try {
            //db.CreateDataBase(userId, db.menues);
            db.AddColumn(userId, db.GetDataBasePath(userId, userDataBase), db.menues, MENU_DATA, "TEXT"); //new column in menues tbl.
            db.AddColumn(userId, db.GetDataBasePath(userId, userDataBase), db.menues, MY_MEALS, "TEXT");  //new column in menues tbl.
            if (string.IsNullOrWhiteSpace(x.id) && Check(userId, x) != false)
            {
                r.data      = x;
                r.msg       = "there is already a menu with the same name";
                r.isSuccess = false;
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }
            Global G = new Global();
            if (!G.CheckUserPermission(user, x.userId))
            {
                r.data      = x;
                r.msg       = "you can only save menus that you have created yourself";
                r.isSuccess = false;
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }

            string myMealsData = null;
            if (myMeals != null)
            {
                if (myMeals.data != null)
                {
                    if (myMeals.data.meals.Count > 2)
                    {
                        myMealsData = JsonConvert.SerializeObject(myMeals, Formatting.None);
                    }
                }
            }
            x.data.meals = CombineTitleDesc(x);
            string sql = null;
            if (string.IsNullOrEmpty(x.id))
            {
                x.id = Guid.NewGuid().ToString();
                sql  = @"BEGIN;
                INSERT INTO menues (id, title, diet, date, note, userId, clientId, userGroupId, energy, menuData, myMeals)
                VALUES (@Id, @Title, @Diet, @Date, @Note, @UserId, @ClientId, @UserGroupId, @Energy, @MenuData, @MyMealsData);
                COMMIT;";
            }
            else
            {
                sql = @"BEGIN;
                UPDATE menues SET
                title = @Title, diet = @Diet, date = @Date, note = @Note, userId = @UserId, clientId = @ClientId, userGroupId = @UserGroupId, energy = @Energy, menuData = @MenuData, myMeals = @MyMealsData
                WHERE id = @Id;
                COMMIT;";
            }
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, userDataBase))) {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    command.Parameters.Add(new SQLiteParameter("Id", x.id));
                    command.Parameters.Add(new SQLiteParameter("Title", x.title));
                    command.Parameters.Add(new SQLiteParameter("Diet", x.diet));
                    command.Parameters.Add(new SQLiteParameter("Date", x.date));
                    command.Parameters.Add(new SQLiteParameter("Note", x.note));
                    command.Parameters.Add(new SQLiteParameter("UserId", user.userId));
                    command.Parameters.Add(new SQLiteParameter("ClientId", x.client.clientId));
                    command.Parameters.Add(new SQLiteParameter("UserGroupId", string.IsNullOrEmpty(x.userGroupId) ? userId : x.userGroupId));
                    command.Parameters.Add(new SQLiteParameter("Energy", x.energy));
                    command.Parameters.Add(new SQLiteParameter("MenuData", JsonConvert.SerializeObject(x.data, Formatting.None)));
                    command.Parameters.Add(new SQLiteParameter("MyMealsData", myMealsData));
                    command.ExecuteNonQuery();
                }
            }

            Files F = new Files();
            F.RemoveJsonFile(userId, x.id, "menues", MENU_DATA, db, userDataBase, null);     //******* Remove json file if exists (old sistem).
            F.RemoveJsonFile(userId, x.id, "menues", MY_MEALS, db, userDataBase, "mymeals"); //******* Remove myMeals json file if exists (old sistem).

            r.data      = x;
            r.msg       = "saved";
            r.isSuccess = true;
            return(JsonConvert.SerializeObject(r, Formatting.None));
        } catch (Exception e) {
            r.data      = x;
            r.msg       = e.Message;
            r.msg1      = "report a problem";
            r.isSuccess = false;
            L.SendErrorLog(e, x.id, userId, "Menues", "Save");
            return(JsonConvert.SerializeObject(r, Formatting.None));
        }
    }
示例#18
0
    public string Save(string userId, Menues.NewMenu x, Users.NewUser user)
    {
        Menues.SaveResponse r = new Menues.SaveResponse();
        try {
            DB.CreateDataBase(userId, DB.nutritionStandards);
            if (string.IsNullOrWhiteSpace(x.id) && Check(userId, x))
            {
                r.data      = x;
                r.msg       = "there is already a menu with the same name";
                r.isSuccess = false;
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }
            Global G = new Global();
            if (!G.CheckUserPermission(user, x.userId))
            {
                r.data      = x;
                r.msg       = "you can only save menus that you have created yourself";
                r.isSuccess = false;
                return(JsonConvert.SerializeObject(r, Formatting.None));
            }

            Menues M = new Menues();
            x.data.meals = M.CombineTitleDesc(x);
            string sql = null;
            if (string.IsNullOrEmpty(x.id))
            {
                x.id = Guid.NewGuid().ToString();
                sql  = @"BEGIN;
                INSERT INTO nutritionstandards (id, title, diet, date, note, userId, clientId, userGroupId, nutritionStandard, mealModule, energy, recommendedEnergy, recommendedModuleEnergy, menuData)
                VALUES (@Id, @Title, @Diet, @Date, @Note, @UserId, @ClientId, @UserGroupId, @NutritionStandard, @MealModule, @Energy, @RecommendedEnergy, @RecommendedModuleEnergy, @MenuData);
                COMMIT;";
            }
            else
            {
                sql = @"BEGIN;
                UPDATE nutritionstandards SET
                title = @Title, diet = @Diet, date = @Date, note = @Note, userId = @UserId, clientId = @ClientId, userGroupId = @UserGroupId, nutritionStandard = @NutritionStandard, mealModule = @MealModule, energy = @Energy, recommendedEnergy = @RecommendedEnergy, recommendedModuleEnergy = @RecommendedModuleEnergy, menuData = @MenuData
                WHERE id = @Id;
                COMMIT;";
            }
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DB.GetDataBasePath(userId, userDataBase))) {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    command.Parameters.Add(new SQLiteParameter("Id", x.id));
                    command.Parameters.Add(new SQLiteParameter("Title", x.title));
                    command.Parameters.Add(new SQLiteParameter("Diet", x.diet));
                    command.Parameters.Add(new SQLiteParameter("Date", x.date));
                    command.Parameters.Add(new SQLiteParameter("Note", x.note));
                    command.Parameters.Add(new SQLiteParameter("UserId", user.userId));
                    command.Parameters.Add(new SQLiteParameter("ClientId", x.client.clientId));
                    command.Parameters.Add(new SQLiteParameter("UserGroupId", string.IsNullOrEmpty(x.userGroupId) ? userId : x.userGroupId));
                    command.Parameters.Add(new SQLiteParameter("NutritionStandard", x.nutritionStandard.code));
                    command.Parameters.Add(new SQLiteParameter("MealModule", x.nutritionStandard.module.code));
                    command.Parameters.Add(new SQLiteParameter("Energy", x.energy));
                    command.Parameters.Add(new SQLiteParameter("recommendedEnergy", x.nutritionStandard.energy));
                    command.Parameters.Add(new SQLiteParameter("recommendedModuleEnergy", x.nutritionStandard.module.energy));
                    command.Parameters.Add(new SQLiteParameter("MenuData", JsonConvert.SerializeObject(x.data, Formatting.None)));
                    command.ExecuteNonQuery();
                }
            }
            r.data      = x;
            r.isSuccess = true;
            return(JsonConvert.SerializeObject(r, Formatting.None));
        } catch (Exception e) {
            r.data      = x;
            r.msg       = e.Message;
            r.msg1      = "report a problem";
            r.isSuccess = false;
            L.SendErrorLog(e, x.id, userId, "Menues", "Save");
            return(JsonConvert.SerializeObject(r, Formatting.None));
        }
    }
示例#19
0
文件: Global.cs 项目: igprog/ppweb
 public bool CheckUserPermission(Users.NewUser user, string authorId)
 {
     return(CheckUserPermission(user.userGroupId, user.userId, user.adminType, authorId));
 }
示例#20
0
 public string Load(string userId, Users.NewUser user)
 {
     try {
         return(JsonConvert.SerializeObject(GetClients(userId, user, null, null), Formatting.None));
     } catch (Exception e) { return("Error: " + e); }
 }
示例#21
0
    public string SendMenu(string email, Menues.NewMenu currentMenu, Users.NewUser user, string lang, string pdfLink)
    {
        try {
            StringBuilder sb    = new StringBuilder();
            StringBuilder meal1 = new StringBuilder();
            StringBuilder meal2 = new StringBuilder();
            StringBuilder meal3 = new StringBuilder();
            StringBuilder meal4 = new StringBuilder();
            StringBuilder meal5 = new StringBuilder();
            StringBuilder meal6 = new StringBuilder();

            sb.AppendLine(string.Format(@"<h3>{0}</h3>", currentMenu.title));
            if (!string.IsNullOrWhiteSpace(currentMenu.note))
            {
                sb.AppendLine(string.Format(@"<p>{0}</p>", currentMenu.note));
            }

            if (!string.IsNullOrEmpty(pdfLink))
            {
                // sb.AppendLine(string.Format(@"<p>{0}.</p>", t.Tran("the menu is in the attachment", lang)));
            }
            else
            {
                foreach (Meals.NewMeal x in currentMenu.data.meals)
                {
                    switch (x.code)
                    {
                    case "B":
                        meal1.AppendLine(AppendMeal(x, currentMenu.data.selectedFoods));
                        break;

                    case "MS":
                        meal2.AppendLine(AppendMeal(x, currentMenu.data.selectedFoods));
                        break;

                    case "L":
                        meal3.AppendLine(AppendMeal(x, currentMenu.data.selectedFoods));
                        break;

                    case "AS":
                        meal4.AppendLine(AppendMeal(x, currentMenu.data.selectedFoods));
                        break;

                    case "D":
                        meal5.AppendLine(AppendMeal(x, currentMenu.data.selectedFoods));
                        break;

                    case "MBS":
                        meal6.AppendLine(AppendMeal(x, currentMenu.data.selectedFoods));
                        break;

                    default:
                        break;
                    }
                }
                sb.AppendLine(meal1.ToString());
                sb.AppendLine(meal2.ToString());
                sb.AppendLine(meal3.ToString());
                sb.AppendLine(meal4.ToString());
                sb.AppendLine(meal5.ToString());
                sb.AppendLine(meal6.ToString());
            }

            sb.AppendLine("<hr />");
            sb.AppendLine(string.Format(@"<i>* {0}</i>", t.Tran("this is an automatically generated email – please do not reply to it", lang)));

            string subject = string.Format("{0} - {1}"
                                           , !string.IsNullOrWhiteSpace(user.companyName) ? user.companyName : string.Format("{0} {1}", user.firstName, user.lastName)
                                           , currentMenu.title);

            bool sent = SendMail_menu(email, subject, sb.ToString(), lang, pdfLink);  // SendMail(email, subject, sb.ToString(), lang);
            return(sent == true?t.Tran("menu sent successfully", lang) : t.Tran("menu is not sent", lang));
        } catch (Exception e) { return("error: " + e); }
    }
示例#22
0
    public string Template(Users.NewUser user, string lang)
    {
        NewMyMeals x = new NewMyMeals();

        x.id          = Guid.NewGuid().ToString();
        x.title       = t.Tran("example", lang).ToUpper();
        x.description = t.Tran("this is just an example, not a recommendation", lang);
        x.userId      = user.userId;
        x.userGroupId = user.userGroupId;
        List <Meals.NewMeal> mm = new List <Meals.NewMeal>();
        List <Foods.MealsRecommendationEnergy> ee = new List <Foods.MealsRecommendationEnergy>();
        string meal = t.Tran("meal", lang);

        Meals.NewMeal m = new Meals.NewMeal();
        m.code        = "MM0";
        m.title       = string.Format("{0} 1", meal);
        m.description = "07:00";
        m.isSelected  = true;
        m.isDisabled  = false;
        mm.Add(m);
        Foods.MealsRecommendationEnergy e = new Foods.MealsRecommendationEnergy();
        e.meal.code = m.code;
        e.meal.energyMinPercentage = 10;
        e.meal.energyMaxPercentage = 15;
        ee.Add(e);
        m             = new Meals.NewMeal();
        m.code        = "MM1";
        m.title       = string.Format("{0} 2", meal);
        m.description = "9:30";
        m.isSelected  = true;
        m.isDisabled  = false;
        mm.Add(m);
        e           = new Foods.MealsRecommendationEnergy();
        e.meal.code = m.code;
        e.meal.energyMinPercentage = 5;
        e.meal.energyMaxPercentage = 10;
        ee.Add(e);
        m             = new Meals.NewMeal();
        m.code        = "MM2";
        m.title       = string.Format("{0} 3", meal);
        m.description = "11:00";
        m.isSelected  = true;
        m.isDisabled  = false;
        mm.Add(m);
        e           = new Foods.MealsRecommendationEnergy();
        e.meal.code = m.code;
        e.meal.energyMinPercentage = 20;
        e.meal.energyMaxPercentage = 25;
        ee.Add(e);
        m             = new Meals.NewMeal();
        m.code        = "MM3";
        m.title       = string.Format("{0} 4", meal);
        m.description = "13:00";
        m.isSelected  = true;
        m.isDisabled  = false;
        mm.Add(m);
        e           = new Foods.MealsRecommendationEnergy();
        e.meal.code = m.code;
        e.meal.energyMinPercentage = 10;
        e.meal.energyMaxPercentage = 15;
        ee.Add(e);
        m             = new Meals.NewMeal();
        m.code        = "MM4";
        m.title       = string.Format("{0} 5", meal);
        m.description = "14:30";
        m.isSelected  = true;
        m.isDisabled  = false;
        mm.Add(m);
        e           = new Foods.MealsRecommendationEnergy();
        e.meal.code = m.code;
        e.meal.energyMinPercentage = 10;
        e.meal.energyMaxPercentage = 15;
        ee.Add(e);
        m             = new Meals.NewMeal();
        m.code        = "MM5";
        m.title       = string.Format("{0} 6", meal);
        m.description = "17:00";
        m.isSelected  = true;
        m.isDisabled  = false;
        mm.Add(m);
        e           = new Foods.MealsRecommendationEnergy();
        e.meal.code = m.code;
        e.meal.energyMinPercentage = 5;
        e.meal.energyMaxPercentage = 10;
        ee.Add(e);
        m             = new Meals.NewMeal();
        m.code        = "MM6";
        m.title       = string.Format("{0} 7", meal);
        m.description = "20:00";
        m.isSelected  = true;
        m.isDisabled  = false;
        mm.Add(m);
        e           = new Foods.MealsRecommendationEnergy();
        e.meal.code = m.code;
        e.meal.energyMinPercentage = 2;
        e.meal.energyMaxPercentage = 5;
        ee.Add(e);
        JsonFileMeals data = new JsonFileMeals();

        data.meals      = mm;
        data.energyPerc = ee;
        x.data          = data;
        return(JsonConvert.SerializeObject(x, Formatting.None));
    }