Ejemplo n.º 1
0
        public static folderDTO createFolder(String child, int uid, int parentFolder)
        {
            String    query  = "";
            String    query1 = "";
            folderDTO folder = new folderDTO();

            folder.folderName     = child;
            folder.parentFolderId = parentFolder;
            folder.id             = uid;
            if (parentFolder == 0)
            {
                query = String.Format("SELECT * FROM folderTable where folderName='{0}' and parentFolderId is NULL", child);
            }
            else
            {
                query = String.Format("SELECT * FROM folderTable where folderName='{0}' and parentFolderId='{1}'", child, parentFolder);
            }
            using (sqlConn connection = new sqlConn())
            {
                var reader = connection.ExcueteReader(query);
                if (reader.Read())
                {
                    return(null);
                }
                else
                {
                    using (sqlConn connection1 = new sqlConn())
                    {
                        if (parentFolder == 0)
                        {
                            query1 = String.Format("INSERT INTO folderTable (folderName,id) VALUES ('{0}','{1}')", child, uid);
                        }
                        else
                        {
                            query1 = String.Format("INSERT INTO folderTable (folderName,parentFolderId,id) VALUES ('{0}','{1}','{2}')", child, parentFolder, uid);
                        }

                        int retValue = connection1.ExcueteQuery(query1);

                        if (retValue == 1)
                        {
                            String sql    = "SELECT folderId FROM userInfo.folders ORDER BY folderId DESC LIMIT 1";
                            var    result = connection1.ExcueteScalar(sql);
                            int    id     = Int32.Parse(result.ToString());
                            folder.folderId = id;
                            return(folder);
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static int save(userDTO user)
        {
            String query = String.Format("INSERT INTO userInfo.user(name, login, password) VALUES('{0}', '{1}', '{2}')", user.name, user.login, user.password);

            query = query + "; Select LAST_INSERT_ID()";
            using (sqlConn connection = new sqlConn())
            {
                int userId = 0;
                if (user.id == 0)
                {
                    try
                    {
                        var    obj  = connection.ExcueteScalar(query);
                        String obj1 = obj.ToString();
                        userId = Int32.Parse(obj1);
                    }
                    catch (Exception)
                    {
                        userId = 0;
                    }
                }
                return(userId);
            }
        }