using DataUpload.Model; using RDIFramework.Utilities; using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace DataUpload { public partial class FormSearch : Form { public string dbMeter = ConfigurationManager.AppSettings["DBMeter"]; IDbProvider dbHelper { get { var DbDefine = DbFactoryProvider.GetProvider(CurrentDbType.Access, dbMeter); return DbDefine; } } public delegate void SetListViewData(string sql,string type,string start,string end); public event SetListViewData FillListView; public FormSearch() { InitializeComponent(); } private void FormSearch_Load(object sender, EventArgs e) { var sql = "Select * From Bsc_AreaInfo"; DataTable dt = dbHelper.Fill(sql); Area area = new Area() { ID=0, Name="所有小区" }; this.cbbArea.Items.Clear(); this.cbbArea.DisplayMember = "Name"; this.cbbArea.ValueMember = "ID"; this.cbbArea.Items.Add(area); for (int i = 0; i < dt.Rows.Count; i++) { Area item = new Area() { ID=Convert.ToInt32(dt.Rows[i]["AreaId"].ToString()), Name=dt.Rows[i]["小区名称"].ToString() }; this.cbbArea.Items.Add(item); } this.cbbArea.SelectedIndex = 0; } private void cbbArea_SelectedIndexChanged(object sender, EventArgs e) { this.cbbBldg.Items.Clear(); this.cbbBldg.DisplayMember = "Name"; this.cbbBldg.ValueMember = "ID"; Area area = (Area)this.cbbArea.SelectedItem; Bldg bldg = new Bldg() { ID=0, Name="所有楼宇" }; this.cbbBldg.Items.Add(bldg); if (area.ID == 0) { } else { var sql = "Select * From Bsc_BldgInfo Where AreaNo=" + area.ID+ " Order by Right('0000' + [楼宇编号], 4)"; DataTable dt = dbHelper.Fill(sql); for (int i = 0; i < dt.Rows.Count; i++) { Bldg item = new Bldg() { ID=Convert.ToInt32(dt.Rows[i]["BldgID"].ToString()), Name=dt.Rows[i]["楼宇编号"].ToString()+dt.Rows[i]["楼宇名称"].ToString() }; this.cbbBldg.Items.Add(item); } } this.cbbBldg.SelectedIndex = 0; } private void cbbBldg_SelectedIndexChanged(object sender, EventArgs e) { this.cbbApmt.Items.Clear(); this.cbbApmt.DisplayMember = "Name"; this.cbbApmt.ValueMember = "ID"; Bldg bldg = (Bldg)this.cbbBldg.SelectedItem; Apmt apmt = new Apmt() { ID = 0, Name = "所有单元" }; this.cbbApmt.Items.Add(apmt); if (bldg.ID == 0) { } else { var sql = "Select * From Bsc_ApmtInfo Where BldgNo=" + bldg.ID+ " Order by Right('0000' + [单元编号], 4)"; DataTable dt = dbHelper.Fill(sql); for (int i = 0; i < dt.Rows.Count; i++) { Apmt item = new Apmt() { ID = Convert.ToInt32(dt.Rows[i]["ApmtID"].ToString()), Name = dt.Rows[i]["单元编号"].ToString() + dt.Rows[i]["单元名称"].ToString() }; this.cbbApmt.Items.Add(item); } } this.cbbApmt.SelectedIndex = 0; } private void cbbApmt_SelectedIndexChanged(object sender, EventArgs e) { this.cbbRoom.Items.Clear(); this.cbbRoom.DisplayMember = "Name"; this.cbbRoom.ValueMember = "ID"; Apmt apmt = (Apmt)this.cbbApmt.SelectedItem; Room room = new Room() { ID = 0, Name = "所有单元" }; this.cbbRoom.Items.Add(room); if (apmt.ID == 0) { } else { var sql = "Select * From Bsc_RoomInfo Where ApmtNo=" + apmt.ID+ " Order By Right('0000' + [门牌编号], 4)"; DataTable dt = dbHelper.Fill(sql); for (int i = 0; i < dt.Rows.Count; i++) { Room item = new Room() { ID = Convert.ToInt32(dt.Rows[i]["RoomID"].ToString()), Name = dt.Rows[i]["门牌编号"].ToString() + dt.Rows[i]["门牌名称"].ToString() }; this.cbbRoom.Items.Add(item); } } this.cbbRoom.SelectedIndex = 0; } private void btnOK_Click(object sender, EventArgs e) { this.btnOK.Enabled = false; var sql = "Select * From View_MeterList Where 1=1 and userNo is not null and userNo <> '' and 表地址 is not null and 表地址 <> '' "; Room room = (Room)this.cbbRoom.SelectedItem; Apmt apmt = (Apmt)this.cbbApmt.SelectedItem; Bldg bldg = (Bldg)this.cbbBldg.SelectedItem; Area area = (Area)this.cbbArea.SelectedItem; if (area.ID != 0) { if (bldg.ID != 0) { if (apmt.ID != 0) { if (room.ID != 0) { sql += " And RoomNo=" + room.ID; } else { sql += " And ApmtNo=" + apmt.ID; } } else { sql += " And BldgNo=" + bldg.ID; } } else { sql += " And AreaNo=" + area.ID; } } string type = "1"; sql += " Order by 小区名称,Right('0000' + [楼宇编号], 4),Right('0000' + [单元编号], 4),Right('0000' + [门牌编号], 4),UserNo,MeterID"; string start, end; if (FillListView != null) { MyParam myParam = new MyParam() { SQL = sql, Type = type }; this.Close(); //new Thread(new ParameterizedThreadStart(LoadData)).Start(myParam); FillListView(myParam.SQL, myParam.Type, myParam.Start, myParam.End); } } private void LoadData(object obj) { MyParam p = obj as MyParam; FillListView(p.SQL, p.Type, p.Start, p.End); } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } private class MyParam { public string SQL { get; set; } public string Type { get; set; } public string Start { get; set; } public string End { get; set; } } } }