/// <summary> /// 项目编辑 /// </summary> private void 编辑EToolStripMenuItem_Click(object sender, EventArgs e) { // 录入准备 prepareForEdit(true, false, null, true, false, false, false, false, false, false, false, editType.editPro, "项目信息"); #region 建立表格样式 dgv_editpro.Columns.Add("proInfo", "项目信息"); dgv_editpro.Columns.Add("content", "内容"); dgv_editpro.Columns[0].DefaultCellStyle = new DataGridViewCellStyle() { BackColor = Color.Gray }; dgv_editpro.Columns[0].ReadOnly = true; dgv_editpro.Columns[0].Width = 150; dgv_editpro.Columns[1].Width = 500; dgv_editpro.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable; dgv_editpro.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; //添加行 dgv_editpro.Rows.Add(7); setCell(0, 0, "坐标系统(国际ID)"); setCell(1, 0, "地址"); setCell(2, 0, "委托单位"); setCell(3, 0, "地质基本情况"); setCell(4, 0, "设计基本情况"); setCell(5, 0, "备注"); setCell(6, 0, "监测点位布置图"); setCell(6, 1, "双击编辑点位图"); dgv_editpro.Rows[6].Cells[1].ReadOnly = true; dgv_editpro.Rows[6].Cells[1].Style = new DataGridViewCellStyle() { BackColor = Color.Silver }; #endregion #region 读出数据 try { login.conn.Open(); //先读出除图片外的数据 SqlDataAdapter sda = new SqlDataAdapter("select coord,address,firstParty,geology,design,remark from fpPros where ID='" + proID + "'", login.conn); DataTable dt = new DataTable(); sda.Fill(dt); for (int i = 0; i < dt.Columns.Count; i++) { setCell(i, 1, dt.Rows[0][i]); } } catch (Exception exc) { throw exc; } finally { login.conn.Close(); } #endregion #region 设定双击单元格事件 CellDoubleClick += (object o, DataGridViewCellEventArgs ea) => { if (ea.ColumnIndex == 1 && ea.RowIndex == 6) { //双击图片单元格后读出image并传递到photoViewer photoViewer pv = new photoViewer(); pv.proID = proID; pv.Show(); } }; #endregion #region 设定保存事件 save += (object o, EventArgs ea) => { if (isSave) return; try { //从表中读取数据 string[] content = new string[6]; for (int i = 0; i < content.Length; i++) { content[i] = dgv_editpro.Rows[i].Cells[1].Value.ToString(); } //保存数据 login.conn.Open(); SqlCommand sc = new SqlCommand("update fpPros set coord='" + content[0] + "',address='" + content[1] + "',firstParty='" + content[2] + "',geology='" + content[3] + "',design='" + content[4] + "',remark='" + content[5] + "' where ID='" + proID + "'", login.conn); sc.ExecuteNonQuery(); setSaveState(true); //刷新视图 //login.conn.Close(); //编辑EToolStripMenuItem_Click(sender, e); } catch (Exception exc) { throw exc; } finally { login.conn.Close(); } }; #endregion }
/// <summary> /// 点击了图片地址 /// </summary> private void lb_addpro_photoUrl_Click(object sender, EventArgs e) { if (photoUrl != null && photoUrl != "") { photoViewer pv = new photoViewer(); pv.photoUrl = photoUrl; pv.Show(); } }