using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
namespace labzmzl
{
public partial class zmzl_add : Form
{
public zmzl_add()
{
InitializeComponent();
}
private void bt_upload_Click(object sender, EventArgs e)
{
OpenFileDialog opf = new OpenFileDialog();
opf.Filter = "word文档(*.doc;*.docx)|*.doc;*.docx";
if (opf.ShowDialog() == DialogResult.OK)
{
if (opf.FileName != "")
{
this.textBox2.Text = opf.FileName;
}
}
}
private string zlid;
private void bt_save_Click(object sender, EventArgs e)
{
//zlid自动生成
string sqlzlid = "select max(zlid) from lab_zmzl";
SqlCommand cmd = new SqlCommand(sqlzlid, alluse.Class1.conn1);
string id = Convert.ToString(cmd.ExecuteScalar());
if (id == "")
{
zlid = "1";
}
else
{
int zl = Int32.Parse(id) + 1;
zlid = zl.ToString();
}
//
string zlsm = this.textBox1.Text.Trim().ToString();
string wordstr = this.textBox2.Text;
if (wordstr.Trim() == "") { wordstr = Application.StartupPath + "//modal//word.docx"; }
string strsql = "insert into lab_zmzl(zlid,zlsm,zlwd) values('" + zlid + "','" + zlsm + "',@word)";
SqlCommand mycmd = new SqlCommand(strsql, alluse.Class1.conn1);
FileStream fs = File.OpenRead(wordstr);
byte[] byte1 = new byte[fs.Length];
fs.Read(byte1, 0, (int)fs.Length);
fs.Close();
mycmd.Parameters.Add("@word", SqlDbType.Image).Value = byte1;
int n = mycmd.ExecuteNonQuery();
if (n > 0)
{
Class1.tt = new string[] { zlid, zlsm };
Class1.hasdo = "yes";
this.Close();
}
else
{
MessageBox.Show("添加失败!");
}
}
private void bt_clear_Click(object sender, EventArgs e)
{
this.textBox1.Text = "";
this.textBox2.Text = "";
}
}
}
以上是添加,修改类似。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
namespace labzmzl
{
public partial class zmzl_change : Form
{
private string zlzm_zlid;
public zmzl_change(String zlid)
{
InitializeComponent();
zlzm_zlid = zlid;
}
private void zmzl_change_Load(object sender, EventArgs e)
{
string sql = "select zlsm from lab_zmzl where zlid='" + zlzm_zlid + "'";
SqlDataAdapter sda = new SqlDataAdapter(sql, alluse.Class1.conn1);
DataSet ds = new DataSet();
sda.Fill(ds, "lab_zmzl");
this.textBox1.Text = ds.Tables["lab_zmzl"].Rows[0]["zlsm"].ToString();
}
private void bt_upload_Click(object sender, EventArgs e)
{
OpenFileDialog opf = new OpenFileDialog();
opf.Filter = "word文档(*.doc;*.docx)|*.doc;*.docx";
if (opf.ShowDialog() == DialogResult.OK)
{
if (opf.FileName != "")
{
this.textBox2.Text = opf.FileName;
}
}
}
private void bt_clear_Click(object sender, EventArgs e)
{
this.textBox2.Text = "";
}
private void bt_change_Click(object sender, EventArgs e)
{
string zlsm = this.textBox1.Text.Trim().ToString();
string strsql = "update lab_zmzl set zlsm='" + zlsm + "'";// where zlid='" + zlzm_zlid + "'
string wordstr = this.textBox2.Text;
if (wordstr.Trim() != "") { strsql += ",zlwd=@word"; }
strsql += " where zlid='" + zlzm_zlid + "'";
SqlCommand mycmd = new SqlCommand(strsql, alluse.Class1.conn1);
if (wordstr.Trim() != "")
{
FileStream fs1 = File.OpenRead(wordstr);
byte[] bytes1 = new byte[fs1.Length];
fs1.Read(bytes1, 0, (int)fs1.Length);
fs1.Close();
mycmd.Parameters.Add("@word", SqlDbType.Image).Value = bytes1;
}
int n = mycmd.ExecuteNonQuery();
if (n > 0)
{
Class1.tt = new string[] { zlzm_zlid, zlsm };
Class1.hasdo = "yes";
this.Close();
}
else
{
MessageBox.Show("修改失败!");
}
}
}
}
以上是修改代码