private void button1_Click(object sender, EventArgs e) { sqlConnection sc = new sqlConnection(); string[] saveData = new string[] { textBox1_D_Kth.Text.Trim().ToString(), textBox2_E.Text.Trim().ToString(), textBox3_KC_max.Text.Trim().ToString(), textBox4_KC_min.Text.Trim().ToString(), textBox5_Kc.Text.Trim().ToString(), textBox1_a0.Text.Trim().ToString() }; JudgeInputText Judge = new JudgeInputText(); for (int i = 0; i < saveData.Length; i++) { if (Judge.judge(saveData[i]) == false) { MessageBox.Show("输入的内容为空或者不是数字数字,请检查!!"); return; } } sc.Save_SQL_Data(saveData, "ExpandVelocity"); double E = Convert.ToDouble(textBox2_E.Text); double D_kth = Convert.ToDouble(textBox1_D_Kth.Text), Kc = Convert.ToDouble(textBox5_Kc.Text), KCmax = Convert.ToDouble(textBox3_KC_max.Text), KCmin = Convert.ToDouble(textBox4_KC_min.Text), D_KC, D_K, R; R = KCmax / KCmin; double a0, a1; //积分上下 a0 = Convert.ToDouble(textBox1_a0.Text); a1 = (1 / Math.PI) * Math.Pow((Kc / (1.12 * KCmax)), 2); double H; //步长 double sum = 0; H = Math.Abs(a0 - a1) / 10000; D_KC = KCmax - KCmin; for (double i = 0; i < 10000; i++) { double a = a0 + H * (i + 0.5); D_K = D_KC * Math.Sqrt(Math.PI * a); double s1 = H * (Math.Pow(E, 2) / 48 * Math.Pow(D_K + D_kth, -0.5) * Math.Pow((1 / D_K - 1 / ((1 - R) * Kc)), 1.5)); sum += s1; } label1.Text = Convert.ToString(sum / 0.01) + "\n------说明-----\n:此结构还可\n承受" + Convert.ToString((int)(sum / 0.01)) + "次冲击"; }
//多条件查询 CrackInfo中信息 private void button1_Click(object sender, EventArgs e) { JudgeInputText Judge = new JudgeInputText(); if (!(Judge.judge(textBox1.Text.Trim()) || Judge.judge(textBox15.Text.Trim()) || Judge.judge(textBox16.Text) || Judge.judge(textBox3.Text))) { MessageBox.Show("输入字符为空或者非数字,请检查!"); textBox1.Text = textBox3.Text = textBox15.Text = textBox16.Text = ""; return; } if (!(Judge.judge(textBox1.Text.Trim()))) { textBox1.Text = ""; } if (!(Judge.judge(textBox15.Text.Trim()))) { textBox15.Text = ""; } if (!Judge.judge(textBox16.Text.Trim())) { textBox16.Text = ""; } if (!(Judge.judge(textBox3.Text.Trim()))) { textBox3.Text = ""; } if (conn.State != ConnectionState.Open) { conn.Close(); } try { ds = new DataSet(); conn = new SqlConnection(ConnectionString); conn.Open(); sql = "SELECT * FROM CrackInfo "; string condition = ""; if (textBox1.Text.Trim() != "") { condition = " [StartPoint X(°)] BETWEEN " + Convert.ToDouble(textBox1.Text) + "-1000 AND " + Convert.ToDouble(textBox1.Text) + "+1000"; } if (textBox15.Text.Trim() != "") { if (condition.Length > 0) { condition += "AND [StartPoint Y(°)] BETWEEN " + Convert.ToDouble(textBox15.Text) + "-1000 AND " + Convert.ToDouble(textBox15.Text) + "+1000"; } else { condition = " [StartPoint Y(°)] BETWEEN " + Convert.ToDouble(textBox15.Text) + "-1000 AND " + Convert.ToDouble(textBox15.Text) + "+1000"; } } if (textBox3.Text.Trim() != "") { if (condition.Length > 0) { condition += "AND [CrackDepth(mm)] BETWEEN " + Convert.ToDouble(textBox3.Text) + "-5 AND " + Convert.ToDouble(textBox3.Text) + "+5"; } else { condition = " [CrackDepth(mm)] BETWEEN " + Convert.ToDouble(textBox3.Text) + "-5 AND " + Convert.ToDouble(textBox3.Text) + "+5"; } } if (condition != "") { sql += " where " + condition; } da = new SqlDataAdapter(sql, conn); // 创建一个数据集对象并填充数据,然后将数据显示在DataGrid控件中 da.Fill(ds); dataGridView1.DataSource = ds.Tables[0].DefaultView; int R = dataGridView1.Rows.Count; conn.Close(); if (R == 0) { MessageBox.Show("相似裂纹数据查找无效!"); } else { MessageBox.Show("已找到相似裂纹" + R + "条!"); } this.button3.Visible = true; } catch (Exception E) { MessageBox.Show("查找数据库时发生错误:" + E.Message + "", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); } pictureBox1.Refresh(); }
//插入裂纹数据 private void button7_Click(object sender, EventArgs e) { JudgeInputText Judge = new JudgeInputText(); if (!(Judge.judge(textBox1.Text.Trim()) && Judge.judge(textBox15.Text.Trim()) && Judge.judge(textBox16.Text) && Judge.judge(textBox3.Text))) { MessageBox.Show("输入字符为空或者非数字,请检查!"); return; } var count = 0; if (conn.State != ConnectionState.Open) { conn.Close(); } if (Convert.ToDouble(textBox1.Text.Trim()) >= 7500 || Convert.ToDouble(textBox1.Text.Trim()) <= -7500 || Convert.ToDouble(textBox15.Text.Trim()) >= 7500 || Convert.ToDouble(textBox15.Text.Trim()) <= -7500) { MessageBox.Show("所输入坐标信息超出范围"); textBox1.Text = ""; textBox15.Text = ""; return; } foreach (DataGridViewRow v in dataGridView1.Rows) { if (v.Cells[0].Value != null && v.Cells[1].Value != null && v.Cells[2].Value != null && v.Cells[3].Value != null) { if (v.Cells[0].Value.ToString().Equals(textBox1.Text.Trim()) && v.Cells[1].Value.ToString().Equals(textBox15.Text.Trim()) //&& v.Cells[2].Value.ToString().Equals(textBox2.Text.Trim()) && v.Cells[2].Value.ToString().Equals(textBox3.Text.Trim()) //&& v.Cells[4].Value.ToString().Equals(textBox14.Text.Trim()) && v.Cells[3].Value.ToString().Equals(textBox16.Text.Trim())) { count++; } } } if (count >= 1) { MessageBox.Show("已存在相同数据"); return; } try { sql = "insert into CrackInfo values('" + Convert.ToDouble(textBox1.Text.Trim()).ToString() + "'," + "'" + Convert.ToDouble(textBox15.Text.Trim()).ToString() + "'," + "'" + Convert.ToDouble(textBox3.Text.Trim()).ToString() + "'," + "'" + Convert.ToDouble(textBox16.Text.Trim()).ToString() + "',0)"; conn = new SqlConnection(ConnectionString); cmd = new SqlCommand(sql, conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); MessageBox.Show("数据插入成功"); conn = new SqlConnection(ConnectionString); cmd = new SqlCommand(); ds = new DataSet(); sql = "SELECT * FROM CrackInfo ";; da = new SqlDataAdapter(sql, conn); da.Fill(ds, " CrackInfo"); this.dataGridView1.DataSource = ds.Tables[" CrackInfo"].DefaultView; } catch (Exception E) { MessageBox.Show("插入数据库时发生错误:" + E.Message + "", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); } pictureBox1.Refresh(); }