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); }
public string readfile(string filename, UserBean u) { using (FileStream fsRead = new FileStream(path + "/" + filename, FileMode.Open)) { int fsLen = (int)fsRead.Length; byte[] heByte = new byte[fsLen]; int r = fsRead.Read(heByte, 0, heByte.Length); string myStr = System.Text.Encoding.UTF8.GetString(heByte); return(myStr); } }
public static bool queryuserinfo(UserBean u) { string selectuserinfo = queryuser.Replace("@username", u.Username); int count = (int)(Int64)ExecuteScalar(selectuserinfo, null); if (count == 1) { return(true); } else { return(false); } }
public static bool insertd(string fname, UserBean u) { string insertdairys = insertdairy.Replace("@username", u.Username).Replace("@time", DateTime.Now.ToString("yyyyMMdd")).Replace("@filename", fname); int count = ExecuteNonQuery(insertdairys, null); if (count > 0) { return(true); } else { return(false); } }
public static bool queryfile(string filename, UserBean user) { string selectfile = queryfilename.Replace("@username", user.Username).Replace("@filename", filename); int count = (int)(Int64)ExecuteScalar(selectfile, null); if (count == 1) { return(true); } else { return(false); } }