private void RepoSpareListForm_Load(object sender, EventArgs e) { setDateTimePickerEmpty(dtpStartTime); setDateTimePickerEmpty(dtpEndTime); List <RepoSpareTool> list = new RepoSpareToolService().getAllRepoSpareTools(); if (list == null) { return; } BindData2Grid(list); }
private void btnSearch_Click(object sender, EventArgs e) { List <RepoSpareTool> list = new List <RepoSpareTool>(); if (!chkAddTime.Checked && !chkModel.Checked) { list = new RepoSpareToolService().getAllRepoSpareTools(); } else { string sql = "select * from RepoSpareTool where 1=1"; if (chkAddTime.Checked) { if (dtpStartTime.Text != "" && dtpEndTime.Text != "") { sql += " and Time>'" + dtpStartTime.Text + "' and Time<'" + dtpEndTime.Text + "'"; } else { MessageBox.Show("时间选择不对,请重新选择", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (chkModel.Checked) { if (comboBox1.Text != "") { sql += " and SpareToolModel='" + comboBox1.Text + "'"; } else { MessageBox.Show("故障原因未选择", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } list = new RepoSpareToolService().getRepoSpareToolBySql(sql); } if (list == null) { dataGridView1.DataSource = new List <RepoSpareTool>(); MessageBox.Show("记录不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } BindData2Grid(list); }