先按添加按钮,出现第一个图来添加参数,确认后在第三幅图的datagridview上显示出来。(删除时要用材料特性ID做条件)
问题:第二图没问题(string tabText = System.Guid.NewGuid().ToString("N") + DateTime.Now.ToString("yyyyMMddHHmmss");随机生成的ID)
第三图中材料特性ID只显示了前面的数字
部分程序如下
private void btntianjia_Click(object sender, EventArgs e)
{
string btnName = btntianjia.Text;
main1.form1.toolOperation.Text = "正在加载窗体,请稍等...";
main1.form1.toolOperation.Font = new Font(main1.form1.toolOperation.Font, FontStyle.Bold);
main1.form1.toolOperation.ForeColor = Color.FromArgb(254, 67, 101);
Application.DoEvents();
Addcailiaoquxian form = new Addcailiaoquxian();
Addcailiaoquxian.form1.BtnName = btnName;
form.Show();
main1.form1.toolOperation.Text = "";
}
Addcailiaoquxian窗口的
private void btnAdd_Click(object sender, EventArgs e)
{
string dbPath = @"D:\历年高考分数.db";
if (btnName == "添加")
{
string sq = @"Data Source=" + dbPath;
m = new SQLiteConnection(sq);
m.Open();
string sql = "select * from sqlite_master where type='table' and name ='特性'";
SQLiteCommand command = new SQLiteCommand(sql, m);//
m.Close();
AddcailiaoPara1(dbPath, "特性");
Guanlicailiaoquxian.form1.LoadcailiaoPara();
DialogResult result = MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
public void AddcailiaoPara1(string dbPath, string tableName)
{
string yinsu = "";
if (radioButton2.Checked == true) { yinsu = "紫外线"; }
else if (radioButton1.Checked == true) { yinsu = "温度、振动"; }
string tabText = System.Guid.NewGuid().ToString("N") + DateTime.Now.ToString("yyyyMMddHHmmss");
string str = "'" + txtName.Text + "'," + "'" + txtyunxinglicheng.Text + "'," + "'" + txtyingdu.Text + "'," + "'" + txtladuanshenchanglv.Text + "'," + "'" + txtlashenqiangdu.Text + "'," + "'" + yinsu + "'," + "'" + tabText + "'";
string sq = @"Data Source=" + dbPath;
m = new SQLiteConnection(sq);
m.Open();
string sql = "insert into " + tableName + " (传感器型号,运行里程,硬度,拉伸强度,拉断伸长率,因素,材料特性ID) values (" + str + ")";
SQLiteCommand command = new SQLiteCommand(sql, m);
command.ExecuteNonQuery();
m.Close();
}
删除使用的
for (int i = 0; i < Eachcailiao.Rows.Count; i++)
{
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)Eachcailiao.Rows[i].Cells[0];
Boolean flag = Convert.ToBoolean(checkCell.Value);
if (flag == true)
{
string dbPath = @"D:\历年高考分数.db";
string sq = @"Data Source=" + dbPath;
SQLiteConnection m = new SQLiteConnection(sq);
m.Open();
string sql = "delete from 特性 where 材料特性ID='" + Eachcailiao.Rows[i].Cells[7].Value + "'";
SQLiteCommand command = new SQLiteCommand(sql, m);
command.ExecuteNonQuery();
m.Close();
}
}