调出菜单跟谁鼠标
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2 || e.ColumnIndex == 3)
{
return;
}
this.cms.Visible = true;
this.cms.Show(this, new Point(Cursor.Position.X - this.Left - 5, Cursor.Position.Y - this.Top - 10));
}
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;
using System.Drawing.Imaging;
namespace labnsgl
{
public partial class ndshjh : Form
{
private string ndshjh_nsid;
public ndshjh(String nsid)
{
InitializeComponent();
ndshjh_nsid = nsid;
}
private void DataBind()
{
string sql = "select jhid,nsid,ys1,ys2,tb1,tb2,tb3,tb4,tb5,tb6,tb7,tb8,tb9,tb10,tb11,tb12 from lab_nsjh where nsid='" + ndshjh_nsid + "'";
SqlDataAdapter sda = new SqlDataAdapter(sql, alluse.Class1.conn1);
DataSet ds = new DataSet();
sda.Fill(ds, "lab_nsjh");
this.dataGridView1.DataSource = ds.Tables["lab_nsjh"];
}
private void ndshjh_Load(object sender, EventArgs e)
{
DataBind();
}
private void bt_save_Click(object sender, EventArgs e)
{
string jhid = this.dataGridView1.CurrentRow.Cells["jhid"].Value.ToString();
string ys1 = this.dataGridView1.CurrentRow.Cells["ys1"].Value.ToString();
string ys2 = this.dataGridView1.CurrentRow.Cells["ys2"].Value.ToString();
string mysql = "update lab_nsjh set nsid='" + ndshjh_nsid + "',ys1='" + ys1 + "',ys2='" + ys2 + "' where jhid='" + jhid + "'";
SqlCommand mycmd = new SqlCommand(mysql, alluse.Class1.conn1);
mycmd.ExecuteNonQuery();
if (this.dataGridView1.CurrentRow.Cells["tb1"].Tag != null)
{
string mysql1 = "update lab_nsjh set tb1=@img1 where jhid='" + jhid + "'";
SqlCommand mycmd1 = new SqlCommand(mysql1, alluse.Class1.conn1);
SqlParameter prm1 = new SqlParameter("@img1", SqlDbType.Image);
MemoryStream ms1 = new MemoryStream();
System.Drawing.Image img1 = System.Drawing.Image.FromFile(Application.StartupPath + "//picture//" + this.dataGridView1.CurrentRow.Cells["tb1"].Tag.ToString());
img1.Save(ms1, System.Drawing.Imaging.ImageFormat.Jpeg);
prm1.Value = ms1.GetBuffer();
mycmd1.Parameters.Add(prm1);
mycmd1.ExecuteNonQuery();
}
if (this.dataGridView1.CurrentRow.Cells["tb2"].Tag != null)
{
string mysql2 = "update lab_nsjh set tb2=@img2 where jhid='" + jhid + "'";
SqlCommand mycmd2 = new SqlCommand(mysql2, alluse.Class1.conn1);
SqlParameter prm2 = new SqlParameter("@img2", SqlDbType.Image);
MemoryStream ms2 = new MemoryStream();
System.Drawing.Image img2 = System.Drawing.Image.FromFile(Application.StartupPath + "//picture//" + this.dataGridView1.CurrentRow.Cells["tb2"].Tag.ToString());
img2.Save(ms2, System.Drawing.Imaging.ImageFormat.Jpeg);
prm2.Value = ms2.GetBuffer();
mycmd2.Parameters.Add(prm2);
mycmd2.ExecuteNonQuery();
}
if (this.dataGridView1.CurrentRow.Cells["tb3"].Tag != null)
{
string mysql3 = "update lab_nsjh set tb3=@img3 where jhid='" + jhid + "'";
SqlCommand mycmd3 = new SqlCommand(mysql3, alluse.Class1.conn1);
SqlParameter prm3 = new SqlParameter("@img3", SqlDbType.Image);
MemoryStream ms3 = new MemoryStream();
System.Drawing.Image img3 = System.Drawing.Image.FromFile(Application.StartupPath + "//picture//" + this.dataGridView1.CurrentRow.Cells["tb3"].Tag.ToString());
img3.Save(ms3, System.Drawing.Imaging.ImageFormat.Jpeg);
prm3.Value = ms3.GetBuffer();
mycmd3.Parameters.Add(prm3);
mycmd3.ExecuteNonQuery();
}
if (this.dataGridView1.CurrentRow.Cells["tb4"].Tag !