private void simpleButton清空_Click(object sender, EventArgs e) { MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("确定要清空吗?", "清空", messButton); if (dr == DialogResult.OK) { SqlConnection Connection; string connectionString; string decryptStr; connectionString = ConfigurationManager.ConnectionStrings["myconn"].ConnectionString; decryptStr = ConnDB.Decrypt(connectionString); Connection = new SqlConnection(decryptStr); string sql1, sql2, sql3, sql4; sql1 = "delete from COST_DAY_CALCULATE where cdate like '" + dateTimePicker1.Text.ToString() + "%' and sale_type_id =15"; sql2 = "delete from COST_MONTH_CALCULATE where cmonth ='" + dateTimePicker1.Text.ToString() + "' and sale_type_id =15"; sql3 = "delete from COST_DEPT_CALCULATE where cdate like '" + dateTimePicker1.Text.ToString() + "%' and sale_type_id =15"; sql4 = "delete from COST_DEPT_MONTH_CALCULATE where cmonth ='" + dateTimePicker1.Text.ToString() + "' and sale_type_id =15"; bool successState = false; Connection.Open(); SqlTransaction myTrans = Connection.BeginTransaction(); SqlCommand command1 = new SqlCommand(sql1, Connection, myTrans); SqlCommand command2 = new SqlCommand(sql2, Connection, myTrans); SqlCommand command3 = new SqlCommand(sql3, Connection, myTrans); SqlCommand command4 = new SqlCommand(sql4, Connection, myTrans); try { command1.ExecuteNonQuery(); command2.ExecuteNonQuery(); command3.ExecuteNonQuery(); command4.ExecuteNonQuery(); myTrans.Commit(); successState = true; } catch { myTrans.Rollback(); } finally { Connection.Close(); } if (successState) { MessageBox.Show("清空成功!"); ShowDetail(); } else { MessageBox.Show("失败!"); } } }