Beispiel #1
0
        public string writefile(string context, UserBean u)
        {
            randomlength r        = new randomlength(10, true);
            string       filename = r.getrand();

            Console.WriteLine(filename);
            //string filename ="hello";
            DBhelper d = new DBhelper();

            while (DBhelper.queryfile(filename, u))
            {
                filename = r.getrand();
            }
            byte[] myByte = System.Text.Encoding.UTF8.GetBytes(context);
            using (FileStream fsWrite = new FileStream(path + "/" + filename, FileMode.Append))
            {
                fsWrite.Write(myByte, 0, myByte.Length);
            };
            if (!DBhelper.insertd(filename, u))
            {
                MessageBox.Show("保存文件失败!");
            }
            else
            {
                MessageBox.Show("保存成功!");
            }
            return(filename);
        }
Beispiel #2
0
        public static bool createuser(string name, string password)
        {
            SQLiteParameter p     = new SQLiteParameter("@name", name);
            int             count = (int)(Int64)ExecuteScalar(queryuser, p);

            if (count >= 1)
            {
                MessageBox.Show("用户已存在!");
                return(false);
            }
            randomlength r        = new randomlength(8, true);
            string       rootname = r.getrand();

            count = (int)(Int64)ExecuteScalar("select count(*) from user where rootbase like '" + rootname + "'", null);
            while (count != 0)
            {
                rootname = r.getrand();
            }
            string inusersqls = inusersql.Replace("@name", name).Replace("@pwd", password).Replace("@rootname", rootname);

            ExecuteNonQuery(inusersqls, null);
            string createusert = createusertable.Replace("@username", name);

            count = ExecuteNonQuery(createusertable, null);
            if (count != 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }