flowMeter/NGToolsPC/frmAddJld.cs

332 lines
10 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NGToolsPC
{
public partial class frmAddJld : Form
{
public frmAddJld()
{
MySqlCon = new System.Data.OleDb.OleDbConnection(mldPublic.strConCNG);
InitializeComponent();
}
public System.Data.OleDb.OleDbConnection MySqlCon; // VBConversions Note: Initial value cannot be assigned here since it is non-static. Assignment has been moved to the class constructors.
DataTable dtZhan;
DataTable dtJLD;
DataTable dtKh;
OleDbCommandBuilder Zhancb;
OleDbCommandBuilder Jldcb;
OleDbCommandBuilder Khcb;
System.Data.OleDb.OleDbDataAdapter ZhanDap;
System.Data.OleDb.OleDbDataAdapter JldDap;
System.Data.OleDb.OleDbDataAdapter KhDap;
string strZhanCheck;
string strZhanName;
int strKhID;
private void frmAddJld_Load(object sender, EventArgs e)
{
try
{
dtKh = new DataTable();
dtKh.Clear();
string strSQL = "select ID,客户名称,客户联系人,客户联系电话 from 客户资料 order by ID";
KhDap = new System.Data.OleDb.OleDbDataAdapter();
KhDap.SelectCommand = new OleDbCommand(strSQL, MySqlCon);
Khcb = new OleDbCommandBuilder(KhDap);
KhDap.UpdateCommand = Khcb.GetUpdateCommand();
KhDap.InsertCommand = Khcb.GetInsertCommand();
KhDap.DeleteCommand = Khcb.GetDeleteCommand();
KhDap.Fill(dtKh);
this.dataGridView3.DataSource = dtKh;
this.dataGridView3.Columns[0].Visible = false;
dataGridView3.Rows[0].Selected = true;
dataGridView3_Click(sender, e);
}
catch (Exception)
{
}
}
private void dataGridView1_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 0)
{
return;
}
int intZhanID = 0;
try
{
intZhanID = System.Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
strZhanName = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
if (intZhanID == 0)
{
return;
}
strZhanCheck = intZhanID.ToString();
//strZhanCheck = System.Convert.ToString(C1FlexGrid1.Rows[C1FlexGrid1.RowSel][1]);
string strSQL = "";
strSQL = "select ID, 厂家ID,厂家名称,仪表编号 from 仪表信息 where 厂家ID=" + System.Convert.ToString(intZhanID) + " order by ID";
dtJLD = new DataTable();
JldDap = new System.Data.OleDb.OleDbDataAdapter();
JldDap.SelectCommand = new OleDbCommand(strSQL, MySqlCon);
JldDap.Fill(dtJLD);
dataGridView2.DataSource = dtJLD;
this.dataGridView2.Columns[0].Visible = false;
this.dataGridView2.Columns[1].Visible = false;
this.dataGridView2.Columns[1].ReadOnly = true;
this.dataGridView2.Columns[2].ReadOnly = true;
Jldcb = new OleDbCommandBuilder(JldDap);
JldDap.UpdateCommand = Jldcb.GetUpdateCommand();
JldDap.InsertCommand = Jldcb.GetInsertCommand();
JldDap.DeleteCommand = Jldcb.GetDeleteCommand();
}
catch (Exception ex)
{
}
}
private void Button1_Click(object sender, EventArgs e)
{
try
{
if (dataGridView1.SelectedRows[0].Cells[1].Value.ToString() == "")
{
MessageBox.Show("厂家名称不能为空!");
return;
}
ZhanDap.Update(dtZhan);
dtZhan.Clear();
ZhanDap.Fill(dtZhan);
}
catch (Exception)
{
}
}
private void Button3_Click(object sender, EventArgs e)
{
if (dataGridView2.Rows.Count > 2)
{
MessageBox.Show("该厂家下还存在仪表,无法删除");
}
else
{
//消息框中需要显示哪些按钮,此处显示“确定”和“取消”
MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
//"确定要退出吗?"是对话框的显示信息,"退出系统"是对话框的标题
//默认情况下如MessageBox.Show("确定要退出吗?")只显示一个“确定”按钮。
DialogResult dr = MessageBox.Show("确定要删除吗?", "删除厂家", messButton);
if (dr == DialogResult.OK)//如果点击“确定”按钮
{
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
}
ZhanDap.Update(dtZhan);
dtZhan.Clear();
ZhanDap.Fill(dtZhan);
}
}
private void Button2_Click(object sender, EventArgs e)
{
try
{
if (dataGridView2.SelectedRows[0].Cells[2].Value.ToString() == "")
{
MessageBox.Show("仪表编号不能为空!");
return;
}
JldDap.Update(dtJLD);
dtJLD.Clear();
JldDap.Fill(dtJLD);
}
catch (Exception)
{
}
}
private void Button4_Click(object sender, EventArgs e)
{
if (dataGridView2.Rows.Count < 1)
{
return;
}
//消息框中需要显示哪些按钮,此处显示“确定”和“取消”
MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
//"确定要退出吗?"是对话框的显示信息,"退出系统"是对话框的标题
//默认情况下如MessageBox.Show("确定要退出吗?")只显示一个“确定”按钮。
DialogResult dr = MessageBox.Show("确定要删除吗?", "删除厂家", messButton);
if (dr == DialogResult.OK)//如果点击“确定”按钮
{
dataGridView2.Rows.Remove(dataGridView2.SelectedRows[0]);
}
JldDap.Update(dtJLD);
dtJLD.Clear();
JldDap.Fill(dtJLD);
}
private void dataGridView2_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void dataGridView2_UserAddedRow(object sender, DataGridViewRowEventArgs e)
{
dataGridView2.Rows[e.Row.Index - 1].Cells[1].Value = strZhanCheck;
dataGridView2.Rows[e.Row.Index - 1].Cells[2].Value = strZhanName;
}
private void dataGridView3_Click(object sender, EventArgs e)
{
if (dataGridView3.SelectedRows.Count == 0)
{
return;
}
try
{
strKhID = System.Convert.ToInt32(dataGridView3.SelectedRows[0].Cells[0].Value.ToString());
if (strKhID == 0)
{
return;
}
//strZhanCheck = System.Convert.ToString(C1FlexGrid1.Rows[C1FlexGrid1.RowSel][1]);
string strSQL = "";
strSQL = "select ID, 客户ID,厂家名称 from 生产厂家 where 客户ID=" + System.Convert.ToString(strKhID) + " order by ID";
dtZhan = new DataTable();
ZhanDap = new System.Data.OleDb.OleDbDataAdapter();
ZhanDap.SelectCommand = new OleDbCommand(strSQL, MySqlCon);
ZhanDap.Fill(dtZhan);
dataGridView1.DataSource = dtZhan;
this.dataGridView1.Columns[0].Visible = false; this.dataGridView1.Columns[1].Visible = false;
this.dataGridView1.Columns[1].ReadOnly = true;
dataGridView1.Rows[0].Selected = true;
dataGridView1_Click(sender, e);
Zhancb = new OleDbCommandBuilder(ZhanDap);
ZhanDap.UpdateCommand = Zhancb.GetUpdateCommand();
ZhanDap.InsertCommand = Zhancb.GetInsertCommand();
ZhanDap.DeleteCommand = Zhancb.GetDeleteCommand();
}
catch (Exception ex)
{
}
}
private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
try
{
if (dataGridView3.SelectedRows[0].Cells[1].Value.ToString() == "")
{
MessageBox.Show("客户名称不能为空!");
this.dataGridView3.DataSource = dtKh;
return;
}
KhDap.Update(dtKh);
dtKh.Clear();
KhDap.Fill(dtKh);
}
catch (Exception)
{
}
}
private void button6_Click(object sender, EventArgs e)
{
if (dataGridView1.Rows.Count > 2)
{
MessageBox.Show("该站下还存在仪表,无法删除");
}
else
{
//消息框中需要显示哪些按钮,此处显示“确定”和“取消”
MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
//"确定要退出吗?"是对话框的显示信息,"退出系统"是对话框的标题
//默认情况下如MessageBox.Show("确定要退出吗?")只显示一个“确定”按钮。
DialogResult dr = MessageBox.Show("确定要删除吗?", "删除厂家", messButton);
if (dr == DialogResult.OK)//如果点击“确定”按钮
{
dataGridView3.Rows.Remove(dataGridView3.SelectedRows[0]);
}
KhDap.Update(dtKh);
dtKh.Clear();
KhDap.Fill(dtKh);
}
}
}
}