private void Btn_save_Command(object sender, CommandEventArgs e) { TextBox box = (TextBox)Page.FindControl("editinput"); Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); DataTable table = Sqlitehelper.ExecuteQuery("select user_name,(user_name||'\\'||fileinfo_name||'.doc') as path from user inner join fileinfo on user_id=fileinfo_userid where fileinfo_id=" + e.CommandArgument); string opath = MapPath("~/wordsave/") + table.Rows[0]["path"].ToString(); if (File.Exists(opath)) { string npath0 = MapPath("~/wordsave/") + table.Rows[0]["user_name"].ToString() + "\\" + box.Text + ".doc"; File.Move(opath, npath0); } else { string npath = MapPath("~/wordsave/") + table.Rows[0]["user_name"].ToString() + "\\" + box.Text + ".txt"; opath = opath.Replace(".doc", ".txt"); File.Move(opath, npath); } Sqlitehelper.ExecuteNonQuery("update fileinfo set fileinfo_name='" + box.Text + "' where fileinfo_id=" + e.CommandArgument); Response.Redirect("filelist.aspx"); }
protected void Button1_Click(object sender, EventArgs e) { Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "MD5"); DataTable table = Sqlitehelper.ExecuteQuery("select * from user where user_name='" + TextBox1.Text + "' and user_password='******'"); if (table.Rows.Count == 0) { TextBox1.Text = ""; TextBox2.Text = ""; Response.Write("<script>alert('用户名或密码错误')</script>"); } else { Session["uid"] = TextBox1.Text; if (TextBox1.Text == "admin") { Response.Redirect("manager.aspx"); } else { Response.Redirect("index.aspx"); } ; } }
protected void Page_Load(object sender, EventArgs e) { int i = int.Parse(Request.QueryString["eid"]); if (Session["uid"] != null) { Panel panel, subpel, namepel, clpel; Label label1; Button btn_save, btn_cancel; Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); string sql = "select fileinfo_name,fileinfo_id from user inner join fileinfo on user_id=fileinfo_userid where fileinfo_delete=0 and user_name='" + Session["uid"].ToString() + "'"; DataTable table = Sqlitehelper.ExecuteQuery(sql); for (int j = 0; j < table.Rows.Count; j++) { panel = new Panel(); label1 = new Label(); subpel = new Panel(); clpel = new Panel(); clpel.CssClass = "clr"; subpel.CssClass = "subpel"; namepel = new Panel(); namepel.CssClass = "namepel"; label1.Text = table.Rows[j]["fileinfo_name"].ToString(); if (j == (i - 1)) { btn_save = new Button(); btn_save.Text = "保存"; btn_save.CommandArgument = i.ToString(); btn_save.Command += new CommandEventHandler(Btn_save_Command); btn_save.OnClientClick = "return Check"; btn_cancel = new Button(); btn_cancel.Text = "取消"; btn_cancel.Command += new CommandEventHandler(Btn_cancel_Command); subpel.Controls.Add(btn_save); subpel.Controls.Add(btn_cancel); panel.CssClass = "edititem"; TextBox textBox = new TextBox(); textBox.ID = "editinput"; textBox.Text = table.Rows[j]["fileinfo_name"].ToString(); ; namepel.Controls.Add(textBox); } else { namepel.Controls.Add(label1); panel.CssClass = "fileitem"; } panel.Controls.Add(namepel); panel.Controls.Add(subpel); panel.Controls.Add(clpel); div_editlist.Controls.Add(panel); } } }
protected void Button1_Click(object sender, EventArgs e) { Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox3.Text, "MD5"); Sqlitehelper.ExecuteNonQuery($"update user set user_password='******' where user_name='{Session["resetinfo"].ToString()}'"); Session["resetinfo"] = null; Response.Redirect("~/logic.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (Session["uid"] != null) { Panel panel, subpel, namepel, clpel; Label label1; Button btn_open, btn_edit, btn_delete, btn_download; Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); string sql = "select fileinfo_name,fileinfo_id from user inner join fileinfo on user_id=fileinfo_userid where fileinfo_delete=0 and user_name='" + Session["uid"].ToString() + "'"; DataTable table = Sqlitehelper.ExecuteQuery(sql); foreach (DataRow row in table.Rows) { panel = new Panel(); panel.CssClass = "fileitem"; label1 = new Label(); subpel = new Panel(); clpel = new Panel(); clpel.CssClass = "clr"; subpel.CssClass = "subpel"; namepel = new Panel(); namepel.CssClass = "namepel"; label1.Text = row["fileinfo_name"].ToString(); namepel.Controls.Add(label1); btn_open = new Button(); btn_open.Text = "打开"; btn_open.Command += new CommandEventHandler(Btn_open_Command); btn_open.CommandArgument = row["fileinfo_id"].ToString(); btn_edit = new Button(); btn_edit.Text = "重命名"; btn_edit.Command += new CommandEventHandler(Btn_edit_Command); btn_edit.CommandArgument = row["fileinfo_id"].ToString(); btn_delete = new Button(); btn_delete.Text = "删除"; btn_delete.Command += new CommandEventHandler(Btn_delete_Command); btn_delete.CommandArgument = row["fileinfo_id"].ToString(); btn_download = new Button(); btn_download.Text = "下载"; btn_download.Command += new CommandEventHandler(Btn_download_Command);; btn_download.CommandArgument = row["fileinfo_id"].ToString(); subpel.Controls.Add(btn_open); subpel.Controls.Add(btn_edit); subpel.Controls.Add(btn_delete); subpel.Controls.Add(btn_download); panel.Controls.Add(namepel); panel.Controls.Add(subpel); panel.Controls.Add(clpel); div_filelist.Controls.Add(panel); } } }
protected void Button1_Click(object sender, EventArgs e) { Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); DataTable table = Sqlitehelper.ExecuteQuery($"select * from user where user_name='{TextBox1.Text}' and user_check='{TextBox3.Text}' and user_question={DropDownList1.SelectedIndex + 1}"); if (table.Rows.Count > 0) { Session["resetinfo"] = TextBox1.Text; Response.Redirect("~/resetpassword.aspx"); } else { Response.Write("<script>alert('用户名或问题答案错误')</script>"); } }
private void Btn_rdelete_Command(object sender, CommandEventArgs e) { Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); DataTable table = Sqlitehelper.ExecuteQuery("select user_name,(user_name||'\\'||fileinfo_name||'.doc') as path from user inner join fileinfo on user_id=fileinfo_userid where fileinfo_id=" + e.CommandArgument); string path = MapPath("~/wordsave/") + table.Rows[0]["path"].ToString(); if (!File.Exists(path)) { path = path.Replace(".doc", ".txt"); } File.Delete(path); Sqlitehelper.ExecuteNonQuery("delete from fileinfo where fileinfo_id=" + e.CommandArgument); Response.Redirect(Request.RawUrl); }
protected void Button3_Click(object sender, EventArgs e) { Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); DataTable table = Sqlitehelper.ExecuteQuery("select * from fileinfo"); int i = table.Rows.Count + 1; DataTable table2 = Sqlitehelper.ExecuteQuery("select user_id from user where user_name='" + Session["uid"].ToString() + "'"); try { Sqlitehelper.ExecuteNonQuery("insert into fileinfo values(" + i + ",'" + TextBox1.Text + "'," + table2.Rows[0]["user_id"] + " ,1,0)"); } catch { Response.Write("<script>alert('文件名已经存在!')</script>"); } if (op.Text == "") { string text = "<!DOCTYPE html>" + CKEditorControl1.Text; try { Directory.CreateDirectory(MapPath("~/wordsave/") + Session["uid"].ToString()); string path = MapPath("~/wordsave/") + Session["uid"].ToString() + "\\" + TextBox1.Text + ".txt"; File.WriteAllText(path, text); } catch { } } else { try { Directory.CreateDirectory(MapPath("~/wordsave/") + Session["uid"].ToString()); string path = MapPath("~/wordsave/") + Session["uid"].ToString() + "\\" + TextBox1.Text + ".doc"; if (FileUpload1.HasFile) { FileUpload1.SaveAs(path); } } catch { } } TextBox1.Text = ""; op.Text = ""; Response.Redirect(Request.RawUrl); }
protected void Button1_Click(object sender, EventArgs e) { Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); DataTable table = Sqlitehelper.ExecuteQuery("select * from user where user_name='" + TextBox1.Text + "'"); if (table.Rows.Count > 0) { TextBox1.Focus(); Response.Write("<script>alert('用户名已经存在!')</script>"); } else { DataTable table1 = Sqlitehelper.ExecuteQuery("select * from user"); int i = table1.Rows.Count + 1; string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "MD5"); Sqlitehelper.ExecuteNonQuery("insert into user values(" + i + ",'" + TextBox1.Text + "','" + password + "',1,'" + TextBox3.Text + "'," + (DropDownList1.SelectedIndex + 1).ToString() + ")"); Response.Write("<script>alert('注册成功!');location.href='logic.aspx';</script>"); } }
private void Btn_open_Command(object sender, CommandEventArgs e) { Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); DataTable table = Sqlitehelper.ExecuteQuery("select (user_name||'\\'||fileinfo_name||'.doc') as path from user inner join fileinfo on user_id=fileinfo_userid where fileinfo_id=" + e.CommandArgument); string path = MapPath("~/wordsave/") + table.Rows[0]["path"].ToString(); //string wctext = GetWordContent(path); string wctext; if (File.Exists(path)) { wctext = File.ReadAllText(path); if (wctext.StartsWith("<!DOCTYPE html>")) { wctext = File.ReadAllText(path); wctext = wctext.Substring(15); } else { Document doc = new Document(); //加载Word文档 doc.LoadFromFile(path); //使用GetText方法获取文档中的所有文本 wctext = doc.GetText(); wctext = wctext.Replace("\r", "<Br/>"); wctext = wctext.Replace("\n", "<Br/>"); } } else { path = path.Replace(".doc", ".txt"); wctext = File.ReadAllText(path); char[] prc = "<!DOCTYPE html>".ToCharArray(); wctext = wctext.Substring(15); } Session["edittext"] = wctext; Response.Write("<script>parent.location.reload();</script>"); }
private void Btn_download_Command(object sender, CommandEventArgs e) { Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); DataTable table = Sqlitehelper.ExecuteQuery("select (user_name||'\\'||fileinfo_name||'.txt') as path from user inner join fileinfo on user_id=fileinfo_userid where fileinfo_id=" + e.CommandArgument); string path = MapPath("~/wordsave/") + table.Rows[0]["path"].ToString(); if (!File.Exists(path)) { path = path.Replace(".txt", ".doc"); } FileInfo file = new FileInfo(path); Response.Clear(); Response.Charset = "utf-8"; //设置输出的编码 Response.ContentEncoding = System.Text.Encoding.UTF8; // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(Path.GetFileNameWithoutExtension(file.Name) + ".doc")); // 添加头信息,指定文件大小,让浏览器能够显示下载进度 Response.AddHeader("Content-Length", file.Length.ToString()); // 指定返回的是一个不能被客户端读取的流,必须被下载 Response.ContentType = "application/msword"; // 把文件流发送到客户端 Response.WriteFile(file.FullName); Response.End(); }
private void Btn_recov_Command(object sender, CommandEventArgs e) { Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); Sqlitehelper.ExecuteNonQuery("update fileinfo set fileinfo_delete=0 where fileinfo_id=" + e.CommandArgument); Response.Redirect(Request.RawUrl); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["model"] == null) { if (Session["uid"] != null) { Panel panel, subpel, namepel, clpel; Label label1; Button btn_recov, btn_rdelete; Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); string sql = "select fileinfo_name,fileinfo_id from user inner join fileinfo on user_id=fileinfo_userid where fileinfo_delete=1 and user_name='" + Session["uid"].ToString() + "'"; DataTable table = Sqlitehelper.ExecuteQuery(sql); foreach (DataRow row in table.Rows) { panel = new Panel(); panel.CssClass = "fileitem"; label1 = new Label(); subpel = new Panel(); clpel = new Panel(); clpel.CssClass = "clr"; subpel.CssClass = "subpel"; namepel = new Panel(); namepel.CssClass = "namepel"; label1.Text = row["fileinfo_name"].ToString(); namepel.Controls.Add(label1); btn_recov = new Button(); btn_recov.Text = "还原"; btn_recov.CommandArgument = row["fileinfo_id"].ToString(); btn_recov.Command += new CommandEventHandler(Btn_recov_Command); btn_rdelete = new Button(); btn_rdelete.Text = "删除"; btn_rdelete.CommandArgument = row["fileinfo_id"].ToString(); btn_rdelete.Command += new CommandEventHandler(Btn_rdelete_Command); subpel.Controls.Add(btn_recov); subpel.Controls.Add(btn_rdelete); panel.Controls.Add(namepel); panel.Controls.Add(subpel); panel.Controls.Add(clpel); div_hszitem.Controls.Add(panel); } } } else { if (Session["uid"] != null) { Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); DataTable table = Sqlitehelper.ExecuteQuery("select (user_name||'\\'||fileinfo_name||'.doc') as path from user inner join fileinfo on user_id=fileinfo_userid where fileinfo_delete=1"); foreach (DataRow row in table.Rows) { string path = MapPath("~/wordsave/") + row["path"].ToString(); if (File.Exists(path)) { File.Delete(path); } else { path = path.Replace(".doc", ".txt"); File.Delete(path); } } Sqlitehelper.SetConnectionString(MapPath("~/webword.db"), ""); Sqlitehelper.ExecuteNonQuery("delete from fileinfo where fileinfo_delete=1"); } } }