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 NBFormSearch : Form { public string dbMeter = ConfigurationManager.AppSettings["NBMeter"]; IDbProvider dbHelper { get { var DbDefine = DbFactoryProvider.GetProvider(CurrentDbType.SqlServer, dbMeter); return DbDefine; } } public delegate void SetListViewData(string sql,string type,string start,string end); public event SetListViewData FillListView; public NBFormSearch() { InitializeComponent(); } private void FormSearch_Load(object sender, EventArgs e) { var sql = "Select * From RMRS_AreaInfo where CompanyId = '55519224-9195-4fe5-81f4-2d08070bd95d'"; 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]["AreaName"].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 RMRS_BldgInfo Where AreaID=" + area.ID + " Order by REPlicate('0',(4-len(BldgNo)))+BldgNo"; 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]["BldgName"].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 RMRS_ApmtInfo Where BldgID=" + bldg.ID+ " Order by REPlicate('0',(4-len(ApmtNo)))+ApmtNo"; 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]["ApmtName"].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 RMRS_RoomInfo Where ApmtID=" + apmt.ID+ " Order By REPlicate('0',(4-len(RoomNo)))+RoomNo"; 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]["RoomName"].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 V_MeterInfoAll Where 1=1 and CompanyID = '55519224-9195-4fe5-81f4-2d08070bd95d'"; 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 RoomID=" + room.ID; } else { sql += " And ApmtID=" + apmt.ID; } } else { sql += " And BldgID=" + bldg.ID; } } else { sql += " And AreaID=" + area.ID; } } string type = "1"; sql += " Order by AreaId,REPlicate('0',(4-len(BldgID)))+BldgID,REPlicate('0',(4-len(ApmtID)))+ApmtID,REPlicate('0',(4-len(RoomID)))+RoomID,UserNo,表编号"; 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; } } } }