FormSearch.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using DataUpload.Model;
  2. using RDIFramework.Utilities;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Configuration;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Windows.Forms;
  13. namespace DataUpload
  14. {
  15. public partial class FormSearch : Form
  16. {
  17. public string dbMeter = ConfigurationManager.AppSettings["DBMeter"];
  18. IDbProvider dbHelper
  19. {
  20. get
  21. {
  22. var DbDefine = DbFactoryProvider.GetProvider(CurrentDbType.Access, dbMeter);
  23. return DbDefine;
  24. }
  25. }
  26. public delegate void SetListViewData(string sql,string type,string start,string end);
  27. public event SetListViewData FillListView;
  28. public FormSearch()
  29. {
  30. InitializeComponent();
  31. }
  32. private void FormSearch_Load(object sender, EventArgs e)
  33. {
  34. var sql = "Select * From Bsc_AreaInfo";
  35. DataTable dt = dbHelper.Fill(sql);
  36. Area area = new Area()
  37. {
  38. ID=0,
  39. Name="所有小区"
  40. };
  41. this.cbbArea.Items.Clear();
  42. this.cbbArea.DisplayMember = "Name";
  43. this.cbbArea.ValueMember = "ID";
  44. this.cbbArea.Items.Add(area);
  45. for (int i = 0; i < dt.Rows.Count; i++)
  46. {
  47. Area item = new Area()
  48. {
  49. ID=Convert.ToInt32(dt.Rows[i]["AreaId"].ToString()),
  50. Name=dt.Rows[i]["小区名称"].ToString()
  51. };
  52. this.cbbArea.Items.Add(item);
  53. }
  54. this.cbbArea.SelectedIndex = 0;
  55. }
  56. private void cbbArea_SelectedIndexChanged(object sender, EventArgs e)
  57. {
  58. this.cbbBldg.Items.Clear();
  59. this.cbbBldg.DisplayMember = "Name";
  60. this.cbbBldg.ValueMember = "ID";
  61. Area area = (Area)this.cbbArea.SelectedItem;
  62. Bldg bldg = new Bldg()
  63. {
  64. ID=0,
  65. Name="所有楼宇"
  66. };
  67. this.cbbBldg.Items.Add(bldg);
  68. if (area.ID == 0)
  69. {
  70. }
  71. else
  72. {
  73. var sql = "Select * From Bsc_BldgInfo Where AreaNo=" + area.ID+ " Order by Right('0000' + [楼宇编号], 4)";
  74. DataTable dt = dbHelper.Fill(sql);
  75. for (int i = 0; i < dt.Rows.Count; i++)
  76. {
  77. Bldg item = new Bldg()
  78. {
  79. ID=Convert.ToInt32(dt.Rows[i]["BldgID"].ToString()),
  80. Name=dt.Rows[i]["楼宇编号"].ToString()+dt.Rows[i]["楼宇名称"].ToString()
  81. };
  82. this.cbbBldg.Items.Add(item);
  83. }
  84. }
  85. this.cbbBldg.SelectedIndex = 0;
  86. }
  87. private void cbbBldg_SelectedIndexChanged(object sender, EventArgs e)
  88. {
  89. this.cbbApmt.Items.Clear();
  90. this.cbbApmt.DisplayMember = "Name";
  91. this.cbbApmt.ValueMember = "ID";
  92. Bldg bldg = (Bldg)this.cbbBldg.SelectedItem;
  93. Apmt apmt = new Apmt()
  94. {
  95. ID = 0,
  96. Name = "所有单元"
  97. };
  98. this.cbbApmt.Items.Add(apmt);
  99. if (bldg.ID == 0)
  100. {
  101. }
  102. else
  103. {
  104. var sql = "Select * From Bsc_ApmtInfo Where BldgNo=" + bldg.ID+ " Order by Right('0000' + [单元编号], 4)";
  105. DataTable dt = dbHelper.Fill(sql);
  106. for (int i = 0; i < dt.Rows.Count; i++)
  107. {
  108. Apmt item = new Apmt()
  109. {
  110. ID = Convert.ToInt32(dt.Rows[i]["ApmtID"].ToString()),
  111. Name = dt.Rows[i]["单元编号"].ToString() + dt.Rows[i]["单元名称"].ToString()
  112. };
  113. this.cbbApmt.Items.Add(item);
  114. }
  115. }
  116. this.cbbApmt.SelectedIndex = 0;
  117. }
  118. private void cbbApmt_SelectedIndexChanged(object sender, EventArgs e)
  119. {
  120. this.cbbRoom.Items.Clear();
  121. this.cbbRoom.DisplayMember = "Name";
  122. this.cbbRoom.ValueMember = "ID";
  123. Apmt apmt = (Apmt)this.cbbApmt.SelectedItem;
  124. Room room = new Room()
  125. {
  126. ID = 0,
  127. Name = "所有单元"
  128. };
  129. this.cbbRoom.Items.Add(room);
  130. if (apmt.ID == 0)
  131. {
  132. }
  133. else
  134. {
  135. var sql = "Select * From Bsc_RoomInfo Where ApmtNo=" + apmt.ID+ " Order By Right('0000' + [门牌编号], 4)";
  136. DataTable dt = dbHelper.Fill(sql);
  137. for (int i = 0; i < dt.Rows.Count; i++)
  138. {
  139. Room item = new Room()
  140. {
  141. ID = Convert.ToInt32(dt.Rows[i]["RoomID"].ToString()),
  142. Name = dt.Rows[i]["门牌编号"].ToString() + dt.Rows[i]["门牌名称"].ToString()
  143. };
  144. this.cbbRoom.Items.Add(item);
  145. }
  146. }
  147. this.cbbRoom.SelectedIndex = 0;
  148. }
  149. private void btnOK_Click(object sender, EventArgs e)
  150. {
  151. this.btnOK.Enabled = false;
  152. var sql = "Select * From View_MeterList Where 1=1 and userNo is not null and userNo <> '' and 表地址 is not null and 表地址 <> '' ";
  153. Room room = (Room)this.cbbRoom.SelectedItem;
  154. Apmt apmt = (Apmt)this.cbbApmt.SelectedItem;
  155. Bldg bldg = (Bldg)this.cbbBldg.SelectedItem;
  156. Area area = (Area)this.cbbArea.SelectedItem;
  157. if (area.ID != 0)
  158. {
  159. if (bldg.ID != 0)
  160. {
  161. if (apmt.ID != 0)
  162. {
  163. if (room.ID != 0)
  164. {
  165. sql += " And RoomNo=" + room.ID;
  166. }
  167. else
  168. {
  169. sql += " And ApmtNo=" + apmt.ID;
  170. }
  171. }
  172. else
  173. {
  174. sql += " And BldgNo=" + bldg.ID;
  175. }
  176. }
  177. else
  178. {
  179. sql += " And AreaNo=" + area.ID;
  180. }
  181. }
  182. string type = "1";
  183. sql += " Order by 小区名称,Right('0000' + [楼宇编号], 4),Right('0000' + [单元编号], 4),Right('0000' + [门牌编号], 4),UserNo,MeterID";
  184. string start, end;
  185. if (FillListView != null)
  186. {
  187. MyParam myParam = new MyParam()
  188. {
  189. SQL = sql,
  190. Type = type
  191. };
  192. this.Close();
  193. //new Thread(new ParameterizedThreadStart(LoadData)).Start(myParam);
  194. FillListView(myParam.SQL, myParam.Type, myParam.Start, myParam.End);
  195. }
  196. }
  197. private void LoadData(object obj)
  198. {
  199. MyParam p = obj as MyParam;
  200. FillListView(p.SQL, p.Type, p.Start, p.End);
  201. }
  202. private void btnCancel_Click(object sender, EventArgs e)
  203. {
  204. this.Close();
  205. }
  206. private class MyParam
  207. {
  208. public string SQL { get; set; }
  209. public string Type { get; set; }
  210. public string Start { get; set; }
  211. public string End { get; set; }
  212. }
  213. }
  214. }