使用DGV列获取Combox绑定所有的列为筛选条件

tech2022-12-10  85

将目标的下拉菜单数Name设定为 CBCheck 绑定的实体类操作方便

public class ComboxBind { public string DgvClName { get; set; } public string DBClName { get; set; } }

解析dgv列绑定的列明与数据,对比

List<ComboxBind> listCb = new List<ComboxBind>(); foreach (DataGridViewColumn one in DGV.Columns) { if (one.Visible == true)//显示列导入 { if (!one.HeaderText.Contains("时间")) { ComboxBind oneModle = new ComboxBind(); oneModle.DgvClName = one.HeaderText; oneModle.DBClName = one.DataPropertyName; listCb.Add(oneModle); } } } this.CBCheck.DataSource = listCb; this.CBCheck.DisplayMember = "DgvClName"; this.CBCheck.ValueMember = "DBClName";

添加seach的方法:

string Seach = $" and SendTime between '{DTBegin.Value.ToString("yyyy-MM-dd")}' and '{DTEnd.Value.AddDays(1).ToString("yyyy-MM-dd")}'"; string SeachInput = $" and {CBCheck.SelectedValue} like '%{this.skinTextBox1.Text.Trim()}%'"; Seach += SeachInput;

DAL设计语句查询的方式

public IEnumerable<MailMain> QueryList(string wheres) { string sql = $@"SELECT top 1000 * FROM [MailMain] Where 1 = 1 {wheres} order by SendTime desc ";//时间排序 return DapperDbHelper.Query<MailMain>(sql); }
最新回复(0)