123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- 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; }
- }
- }
- }
|