PageRenderTime 68ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Components/BP.Web.Controls30/CTL/DDL.cs

#
C# | 1583 lines | 1189 code | 145 blank | 249 comment | 153 complexity | 87e1e349ae57f832ab64f7dad8fce589 MD5 | raw file
Possible License(s): AGPL-3.0
  1. using System;
  2. using System.Data;
  3. using System.Web.UI.WebControls;
  4. using BP.DA;
  5. using BP.En;
  6. using System.Drawing ;
  7. using BP ;
  8. using BP.Sys;
  9. using System.ComponentModel;
  10. namespace BP.Web.Controls
  11. {
  12. /// <summary>
  13. /// BPListBox 的摘要说明。
  14. /// </summary>
  15. [System.Drawing.ToolboxBitmap(typeof(System.Web.UI.WebControls.DropDownList))]
  16. public class DDL:System.Web.UI.WebControls.DropDownList
  17. {
  18. #region 处理showtype
  19. /// <summary>
  20. /// 关联的Key .
  21. /// </summary>
  22. public string SelfEnsRefKey
  23. {
  24. get
  25. {
  26. return (string)ViewState["EnsKey"];
  27. }
  28. set
  29. {
  30. ViewState["EnsKey"]=value;
  31. }
  32. }
  33. /// <summary>
  34. /// 关联的Text
  35. /// </summary>
  36. public string SelfEnsRefKeyText
  37. {
  38. get
  39. {
  40. return (string)ViewState["SelfEnsRefKeyText"];
  41. }
  42. set
  43. {
  44. ViewState["SelfEnsRefKeyText"]=value;
  45. }
  46. }
  47. public void BindThisYearMonth()
  48. {
  49. string year=DataType.CurrentYear ;
  50. int i = 0;
  51. this.Items.Clear();
  52. while (i < 12)
  53. {
  54. i++;
  55. string val = year + "-" + i.ToString().PadLeft(2, '0');
  56. this.Items.Add(new ListItem(val, val));
  57. }
  58. int myyear= int.Parse(year)+1;
  59. year =myyear.ToString();
  60. i = 0;
  61. while (i < 12)
  62. {
  63. i++;
  64. string val=year+"-"+i.ToString().PadLeft(2 , '0' ) ;
  65. this.Items.Add( new ListItem( val,val ) );
  66. }
  67. }
  68. public void BindEntities(Entities ens, string refkey, string reftext, bool isShowKey)
  69. {
  70. this.Items.Clear();
  71. foreach (Entity en in ens)
  72. {
  73. if (isShowKey)
  74. this.Items.Add(new ListItem(en.GetValStringByKey(refkey) + " " + en.GetValStringByKey(reftext), en.GetValStringByKey(refkey)));
  75. else
  76. this.Items.Add(new ListItem(en.GetValStringByKey(reftext), en.GetValStringByKey(refkey)));
  77. }
  78. }
  79. public void BindEntities(Entities ens, string refkey, string reftext,bool isShowKey, AddAllLocation where)
  80. {
  81. this.Items.Clear();
  82. if (where==AddAllLocation.Top || where==AddAllLocation.TopAndEnd )
  83. {
  84. ListItem li = new ListItem("-=全部=-","all") ;
  85. this.Items.Add(li);
  86. }
  87. foreach(Entity en in ens)
  88. {
  89. if (isShowKey)
  90. this.Items.Add(new ListItem(en.GetValStringByKey(refkey)+" "+en.GetValStringByKey(reftext), en.GetValStringByKey(refkey)) ) ;
  91. else
  92. this.Items.Add(new ListItem( en.GetValStringByKey(reftext), en.GetValStringByKey(refkey)) ) ;
  93. }
  94. if (where==AddAllLocation.End || where==AddAllLocation.TopAndEnd )
  95. {
  96. ListItem li = new ListItem("-=全部=-","all") ;
  97. this.Items.Add(li);
  98. //this.Items.
  99. }
  100. }
  101. private DDLShowType _ShowType=DDLShowType.None;
  102. public DDLShowType SelfShowType
  103. {
  104. get
  105. {
  106. return _ShowType;
  107. }
  108. set
  109. {
  110. this._ShowType=value;
  111. }
  112. }
  113. /// <summary>
  114. /// BindBindSysEnum
  115. /// </summary>
  116. /// <param name="enumKey"></param>
  117. public void BindSysEnum(string enumKey)
  118. {
  119. SelfBindSysEnum(enumKey);
  120. }
  121. public void BindSysEnum(string enumKey, int selecVal)
  122. {
  123. this.SelfDefaultVal=selecVal.ToString();
  124. SelfBindSysEnum(enumKey);
  125. }
  126. public void BindSysEnum(string key, bool isShowKey, AddAllLocation alllocal)
  127. {
  128. Sys.SysEnums ens = new BP.Sys.SysEnums(key);
  129. this.Items.Clear();
  130. if (alllocal == AddAllLocation.TopAndEnd
  131. || alllocal == AddAllLocation.Top
  132. || alllocal == AddAllLocation.TopAndEndWithMVal)
  133. this.Items.Add(new ListItem(">>", "all"));
  134. foreach (SysEnum en in ens)
  135. {
  136. if (this.SelfIsShowVal)
  137. {
  138. this.Items.Add(new ListItem(en.IntKey + " " + en.Lab, en.IntKey.ToString()));
  139. }
  140. else
  141. {
  142. ListItem li = new ListItem(en.Lab + en.Style, en.IntKey.ToString());
  143. li.Attributes.CssStyle.Add("style", "color:" + en.Style);
  144. li.Attributes.Add("color", en.Style);
  145. li.Attributes.Add("style", "color:" + en.Style);
  146. this.Items.Add(li);
  147. }
  148. }
  149. if (alllocal == AddAllLocation.TopAndEndWithMVal && this.Items.Count >= 4)
  150. {
  151. ListItem liMvals = new ListItem("*多项组合..", "mvals");
  152. liMvals.Attributes.CssStyle.Add("style", "color:green");
  153. liMvals.Attributes.Add("color", "green");
  154. liMvals.Attributes.Add("style", "color:green");
  155. this.Items.Add(liMvals); //new ListItem("*指定选项...", "mvals"));
  156. }
  157. if (alllocal == AddAllLocation.TopAndEnd
  158. || alllocal == AddAllLocation.End
  159. || alllocal == AddAllLocation.TopAndEndWithMVal)
  160. this.Items.Add(new ListItem("-=全部=-", "all"));
  161. }
  162. public void SelfBindSysEnum()
  163. {
  164. this.SelfBindSysEnum(this.SelfBindKey.Trim());
  165. }
  166. /// <summary>
  167. /// 按照enum
  168. /// </summary>
  169. public void SelfBindSysEnum(string enumKey)
  170. {
  171. this.Items.Clear();
  172. if (this.Enabled)
  173. {
  174. SysEnums ens = new SysEnums(enumKey);
  175. foreach(SysEnum en in ens)
  176. {
  177. if (this.SelfIsShowVal)
  178. {
  179. this.Items.Add(new ListItem(en.IntKey+" "+en.Lab, en.IntKey.ToString() ));
  180. }
  181. else
  182. {
  183. ListItem li = new ListItem( en.Lab , en.IntKey.ToString() );
  184. li.Attributes.Add("color",en.Style);
  185. li.Attributes.CssStyle.Add("color",en.Style);
  186. //li.Attributes.Add("onclick","alert('hello')");
  187. this.Items.Add(li );
  188. }
  189. }
  190. this.SetSelectItem(this.SelfDefaultVal) ;
  191. }
  192. else
  193. {
  194. this.Items.Add( new ListItem(this.SelfDefaultText,this.SelfDefaultVal) ) ;
  195. }
  196. }
  197. public void SelfBind(string key)
  198. {
  199. this.SelfBindKey=key;
  200. this.Items.Clear();
  201. this.SelfBind();
  202. }
  203. public void SelfBind()
  204. {
  205. switch (this.SelfShowType)
  206. {
  207. case DDLShowType.Boolean:
  208. this.Items.Add(new ListItem("是", "1"));
  209. this.Items.Add(new ListItem("否", "0"));
  210. break;
  211. case DDLShowType.Gender:
  212. this.Items.Add(new ListItem("男", "1"));
  213. this.Items.Add(new ListItem("女", "0"));
  214. break;
  215. // case DDLShowType.Year:
  216. // this.BindYear();
  217. // break;
  218. // case DDLShowType.Month:
  219. // this.BindMonth();
  220. // break;
  221. // case DDLShowType.Quarter:
  222. // this.BindQuarter();
  223. // break;
  224. // case DDLShowType.Day:
  225. // this.BindDay();
  226. // break;
  227. case DDLShowType.SysEnum: /// 枚举类型
  228. SelfBindSysEnum();
  229. break;
  230. case DDLShowType.Self: /// 枚举类型
  231. SelfBindSysEnum();
  232. break;
  233. case DDLShowType.BindTable: /// 于Table Bind .
  234. this.SelfBindTable();
  235. break;
  236. case DDLShowType.Ens: /// 于实体。
  237. this.SelfBindEns();
  238. break;
  239. }
  240. //if (this.SelfAddAllLocation == AddAllLocation.TopAndEnd)
  241. // this.Items.Add(new ListItem("-=全部=-", "all"));
  242. if (this.SelfDefaultVal != null && this.SelfDefaultVal.Length > 0)
  243. this.SetSelectItem(this.SelfDefaultVal);
  244. // if (this.Enabled==false)
  245. // this.BackColor=Color.FromName("#E4E3E6");
  246. }
  247. #endregion
  248. public void Bind(DataTable dt, string val, string text)
  249. {
  250. if (this.Items.Count >= dt.Rows.Count)
  251. {
  252. bool isHave = false;
  253. foreach (ListItem li in this.Items)
  254. {
  255. isHave = false;
  256. foreach (DataRow dr in dt.Rows)
  257. {
  258. if (dr[val].ToString() == li.Value)
  259. {
  260. isHave = true;
  261. break;
  262. }
  263. }
  264. //if (isHave==false)
  265. // li.Attributes["display"] = "none";
  266. //else
  267. // li.Attributes["visibility"] = "false";
  268. if (isHave)
  269. li.Attributes["visibility"] = "true";
  270. else
  271. li.Attributes["visibility"] = "false";
  272. }
  273. }
  274. else
  275. {
  276. foreach (DataRow dr in dt.Rows)
  277. {
  278. this.Items.Add(new ListItem(dr[text].ToString(), dr[val].ToString()));
  279. }
  280. }
  281. }
  282. public void SetSelectItemByIndex(int index)
  283. {
  284. foreach(ListItem li in this.Items)
  285. {
  286. li.Selected=false;
  287. }
  288. int i=0 ;
  289. foreach(ListItem li in this.Items)
  290. {
  291. if (i==index)
  292. {
  293. li.Selected=true;
  294. }
  295. i++;
  296. }
  297. }
  298. #region 处理BindKey
  299. /// <summary>
  300. /// -==全部==- 显示位置。
  301. /// </summary>
  302. private AddAllLocation _SelfAddAllLocation=AddAllLocation.None ;
  303. /// <summary>
  304. /// -==全部==- 显示位置。
  305. /// </summary>
  306. public AddAllLocation SelfAddAllLocation
  307. {
  308. get
  309. {
  310. return _SelfAddAllLocation;
  311. }
  312. set
  313. {
  314. _SelfAddAllLocation=value;
  315. }
  316. }
  317. /// <summary>
  318. /// 要bind的key.
  319. /// 这里有3种情况。
  320. /// 1,枚举类型的。
  321. /// 2,Table类型的。
  322. /// 3,实体类型的。
  323. /// 只有对于2,3两种类型的SelfRefKey, SelfRefText.才有意义。
  324. /// </summary>
  325. public string SelfBindKey
  326. {
  327. get
  328. {
  329. return (string)ViewState["SelfBindKey"];
  330. }
  331. set
  332. {
  333. ViewState["SelfBindKey"]=value;
  334. }
  335. }
  336. public string AppPath
  337. {
  338. get
  339. {
  340. return (string)ViewState["AppPath"];
  341. }
  342. set
  343. {
  344. ViewState["AppPath"]=value;
  345. }
  346. }
  347. /// <summary>
  348. /// 为attr , 设置的属性
  349. /// </summary>
  350. private Entities HisFKEns=null;
  351. /// <summary>
  352. /// 默认值
  353. /// </summary>
  354. public string SelfDefaultVal
  355. {
  356. get
  357. {
  358. return (string)ViewState["SelfDefaultVal"];
  359. }
  360. set
  361. {
  362. ViewState["SelfDefaultVal"]=value;
  363. }
  364. }
  365. /// <summary>
  366. /// 默认Text
  367. /// </summary>
  368. public string SelfDefaultText
  369. {
  370. get
  371. {
  372. return (string)ViewState["SelfDefaultText"];
  373. }
  374. set
  375. {
  376. ViewState["SelfDefaultText"]=value;
  377. }
  378. }
  379. /// <summary>
  380. /// 要不要显示 Bind 的值.
  381. /// </summary>
  382. public bool SelfIsShowVal
  383. {
  384. get
  385. {
  386. try
  387. {
  388. return (bool)ViewState["SelfIsShowVal"];
  389. }
  390. catch
  391. {
  392. return false;
  393. }
  394. }
  395. set
  396. {
  397. ViewState["SelfIsShowVal"]=value;
  398. }
  399. }
  400. /// <summary>
  401. /// 用到了DDL 于 Ens 定义的帮定
  402. /// </summary>
  403. private void SelfBindEns()
  404. {
  405. if (this.SelfBindKey == "")
  406. throw new Exception("@没有设定它的Key.");
  407. if (this.SelfAddAllLocation == AddAllLocation.Top || this.SelfAddAllLocation == AddAllLocation.TopAndEnd)
  408. this.Items.Add(new ListItem("-=全部=-", "all"));
  409. if (this.Enabled == true)
  410. {
  411. Entities ens = this.HisFKEns;
  412. ens.RetrieveAll();
  413. //}
  414. this.BindEntities(ens, this.SelfEnsRefKey, this.SelfEnsRefKeyText);
  415. }
  416. else
  417. {
  418. this.Items.Add(new ListItem(this.SelfDefaultText, this.SelfDefaultVal));
  419. }
  420. if (this.SelfAddAllLocation == AddAllLocation.End || this.SelfAddAllLocation == AddAllLocation.TopAndEnd)
  421. this.Items.Add(new ListItem("-=全部=-", "all"));
  422. }
  423. /// <summary>
  424. /// DDLDataHelp 用到了DDL自己定义的帮定。
  425. /// </summary>
  426. private void SelfBindTable()
  427. {
  428. if (this.SelfBindKey=="")
  429. return ;
  430. /*
  431. DDLDataHelp en = new DDLDataHelp(this.SelfBindKey);
  432. string sql = "SELECT TOP 100 "+en.NoCol+" , "+en.NameCol+" FROM "+en.RefTable ;
  433. DataTable dt = DBAccess.RunSQLReturnTable(sql);
  434. string name, val;
  435. foreach(DataRow dr in dt.Rows)
  436. {
  437. if (this.SelfIsShowVal)
  438. {
  439. name=dr[0].ToString()+" "+dr[1].ToString() ;
  440. val=dr[0].ToString().Trim() ;
  441. }
  442. else
  443. {
  444. name=dr[0].ToString().Trim()+" "+dr[1].ToString() ;
  445. val=dr[0].ToString().Trim() ;
  446. }
  447. ListItem li = new ListItem(name,val);
  448. this.Items.Add(li);
  449. }
  450. /// 判断它是不是要求双击事件。
  451. if (en.FK_TBDataHelp.Trim().Length==0)
  452. this.DealRightKey(en.FK_TBDataHelp) ;
  453. */
  454. }
  455. private void DealRightKey(string TBDataHelpKey)
  456. {
  457. /*
  458. DataHelp en = new DataHelp(TBDataHelpKey) ;
  459. string script , url ;
  460. string appPath =this.Page.Request.ApplicationPath;
  461. this.Font.Bold=false;
  462. this.BorderStyle=System.Web.UI.WebControls.BorderStyle.Groove;
  463. //this.Width=Unit.Pixel(150);
  464. this.ForeColor=Color.FromName("#006699");
  465. url =appPath+"/Comm/DataHelp.htm?"+appPath+en.FileUrl;
  466. script=" if ( event.button != 2) return; val=window.showModalDialog('"+url+"','','dialogHeight: "+en.Height+"px; dialogWidth: "+en.Width+"px; dialogTop: 100px; dialogLeft: 100px; center: no; help: no'); if ( val==undefined) return ; "+this.ClientID+".value=val ; ";
  467. this.Attributes["onmousedown"]=script;
  468. //this.ToolTip=en.ToolTip;
  469. */
  470. }
  471. private void TBInit(object sender, System.EventArgs e)
  472. {
  473. this.SelfBind();
  474. return;
  475. /* 可以保留如下代码。 */
  476. //if (this.Enabled)
  477. //{
  478. // //url =appPath+"/Comm/DataHelp.htm?"+appPath+"/Comm/HelperOfTB.aspx?EnsName="+this.EnsName+"&AttrKey="+this.AttrKey ;
  479. // //script=" if ( event.button != 2) return; str="+this.ClientID+".value;str= window.showModalDialog('"+url+"&Key=\'+str, '','dialogHeight: 500px; dialogWidth:850px; dialogTop: 100px; dialogLeft: 100px; center: no; help: no'); if ( str==undefined) return ; "+this.ClientID+".value=str ; ";
  480. // // this.Attributes["onmousedown"]=script;
  481. // //string appPath =this.Page.Request.ApplicationPath;
  482. // //string url=appPath+"/Comm/DataHelp.htm?"+appPath+"/Comm/HelperOfDDL.aspx?EnsName="+attr.UIBindKey+"&RefKey="+attr.UIRefKeyValue+"&RefText="+attr.UIRefKeyText;
  483. // //string script=" if ( event.button != 2 ) return; str="+this.ClientID+".DataTextField; str= window.showModalDialog('"+url+"&Key=\'+str , '','dialogHeight: 500px; dialogWidth:800px; dialogTop: 100px; dialogLeft: 100px; center: no; help: no'); if ( str==undefined) return ; "+this.ClientID+".DataTextField=str ; ";
  484. // //string script=" if ( event.button != 2 ) return; window.showModalDialog('"+url+"' , '','dialogHeight: 500px; dialogWidth:800px; dialogTop: 100px; dialogLeft: 100px; center: no; help: no'); SetDDLVal('"+this.ClientID+"',str ) ; ";
  485. // if (this.SelfBindKey != null)
  486. // {
  487. // this.Attributes["onmousedown"] = " if ( event.button != 2 ) return; HalperOfDDL('" + this.AppPath + "','" + this.SelfBindKey + "','" + this.SelfEnsRefKey + "','" + this.SelfEnsRefKeyText + "','" + this.ClientID.ToString() + "' )";
  488. // }
  489. //}
  490. //this.SelfBind();
  491. }
  492. #endregion
  493. /// <summary>
  494. /// new ddl
  495. /// </summary>
  496. /// <param name="attr">属性</param>
  497. /// <param name="DefaultVal">DefaultVal</param>
  498. /// <param name="DefaultText">DefaultText</param>
  499. /// <param name="enable">enable</param>
  500. public DDL(Attr attr, string DefaultVal, string DefaultText, bool enable, string appPath)
  501. {
  502. this.AppPath =appPath;
  503. this.ID="DDL_"+attr.Key;
  504. this.BorderStyle=BorderStyle.None;
  505. this.CssClass="DDL"+WebUser.Style;
  506. this.SelfDefaultText = DefaultText;
  507. this.SelfDefaultVal = DefaultVal;
  508. this.Enabled =enable;
  509. this.SelfShowType = attr.UIDDLShowType;
  510. this.SelfBindKey=attr.UIBindKey;
  511. this.SelfEnsRefKey =attr.UIRefKeyValue;
  512. this.SelfEnsRefKeyText =attr.UIRefKeyText;
  513. this.HisFKEns = attr.HisFKEns;
  514. this.SelfIsShowVal = false; ///不让显示编号
  515. //this.PreRender +=new System.EventHandler(this.DDLPreRender);
  516. this.Init += new System.EventHandler(this.TBInit);
  517. }
  518. public void LoadMapAttr(Attr attr)
  519. {
  520. this.ID = "DDL_" + attr.Key;
  521. // this.AppPath = BP.SystemConfig.AppName;
  522. this.BorderStyle = BorderStyle.None;
  523. this.SelfDefaultText = attr.UIRefKeyText;
  524. this.SelfDefaultVal = attr.UIRefKeyValue;
  525. this.Enabled = attr.UIIsReadonly;
  526. if (attr.MyDataType == DataType.AppInt)
  527. this.SelfShowType = DDLShowType.SysEnum;
  528. else
  529. this.SelfShowType = DDLShowType.Ens;
  530. this.HisFKEns = attr.HisFKEns;
  531. this.SelfBindKey = attr.UIBindKey;
  532. this.SelfEnsRefKey = attr.UIRefKeyValue;
  533. this.SelfEnsRefKeyText = attr.UIRefKeyText;
  534. this.SelfIsShowVal = false; ///不让显示编号
  535. this.Init += new System.EventHandler(this.TBInit);
  536. }
  537. public DDL(Attr attr, string DefaultVal, string DefaultText, bool enable)
  538. {
  539. this.ID="DDL_"+attr.Key;
  540. this.AppPath =this.Page.Request.ApplicationPath;
  541. this.BorderStyle=BorderStyle.None;
  542. this.CssClass="DDL"+WebUser.Style;
  543. this.SelfDefaultText = DefaultText;
  544. this.SelfDefaultVal = DefaultVal;
  545. this.Enabled =enable;
  546. this.SelfShowType = attr.UIDDLShowType;
  547. this.SelfBindKey=attr.UIBindKey;
  548. this.SelfEnsRefKey =attr.UIRefKeyValue;
  549. this.SelfEnsRefKeyText =attr.UIRefKeyText;
  550. this.HisFKEns = attr.HisFKEns;
  551. this.SelfIsShowVal = false; ///不让显示编号
  552. //this.PreRender +=new System.EventHandler(this.DDLPreRender);
  553. this.Init += new System.EventHandler(this.TBInit);
  554. }
  555. public void LoadMapAttr(MapAttr attr)
  556. {
  557. this.ID = "DDL_" + attr.KeyOfEn;
  558. // this.AppPath = BP.SystemConfig.AppName;
  559. this.BorderStyle = BorderStyle.None;
  560. this.SelfDefaultText = attr.UIRefKeyText;
  561. this.SelfDefaultVal = attr.UIRefKey;
  562. this.Enabled = attr.UIIsEnable;
  563. if (attr.MyDataType == DataType.AppInt)
  564. {
  565. this.SelfShowType = DDLShowType.SysEnum;
  566. //SysEnums ses = new SysEnums(attr.UIBindKey);
  567. // this.BindSysEnum(attr.UIBindKey);
  568. }
  569. else
  570. {
  571. this.SelfShowType = DDLShowType.Ens;
  572. this.HisFKEns = DA.ClassFactory.GetEns(attr.UIBindKey );
  573. //this.HisFKEns.RetrieveAll();
  574. //this.BindEntities(this.HisFKEns, "No", "Name", false);
  575. }
  576. // SelfEnsRefKey
  577. this.SelfBindKey = attr.UIBindKey;
  578. this.SelfEnsRefKey = attr.UIRefKey;
  579. this.SelfEnsRefKeyText = attr.UIRefKeyText;
  580. this.SelfIsShowVal = false; ///不让显示编号
  581. ///
  582. this.Init += new System.EventHandler(this.TBInit);
  583. }
  584. public DDL(Attr attr, string defSelectVal)
  585. {
  586. this.ID = "DDL_" + attr.Key;
  587. this.SelfShowType = attr.UIDDLShowType;
  588. this.SelfBindKey = attr.UIBindKey;
  589. this.SelfEnsRefKey = attr.UIRefKeyValue;
  590. this.SelfEnsRefKeyText = attr.UIRefKeyText;
  591. this.SelfDefaultVal = defSelectVal;
  592. this.HisFKEns = attr.HisFKEns;
  593. // this.SelfAddAllLocation = AddAllLocation.Top;
  594. if (attr.UIBindKey == "BP.Port.SJs")
  595. {
  596. }
  597. else
  598. {
  599. this.SelfAddAllLocation = AddAllLocation.Top;
  600. }
  601. this.SelfIsShowVal = false; ///不让显示编号
  602. }
  603. public DDL()
  604. {
  605. //this.PreRender +=new System.EventHandler(this.DDLPreRender);
  606. this.Init += new System.EventHandler(this.TBInit);
  607. //this.Load +=new System.EventHandler(this.TBPreRender);
  608. }
  609. public void Bind(EntitiesNoName ens, string seleVal)
  610. {
  611. this.BindEntitiesNoName(ens, seleVal);
  612. }
  613. public void Bind(XML.XmlEns xmls, string key, string name)
  614. {
  615. foreach (XML.XmlEn xml in xmls)
  616. {
  617. this.Items.Add(new ListItem(xml.GetValStringByKey(name), xml.GetValStringByKey(key)));
  618. }
  619. }
  620. public void Bind(Entities ens, string key, string name)
  621. {
  622. this.Items.Clear();
  623. foreach (Entity en in ens)
  624. {
  625. this.Items.Add(new ListItem(en.GetValStringByKey(name), en.GetValStringByKey(key)));
  626. }
  627. }
  628. protected override void OnPreRender(System.EventArgs e)
  629. {
  630. if (this.SelfAddAllLocation == AddAllLocation.None)
  631. return;
  632. if (this.Items.FindByValue("all") == null)
  633. return;
  634. if (this.SelfAddAllLocation == AddAllLocation.Top || this.SelfAddAllLocation == AddAllLocation.TopAndEnd)
  635. {
  636. ListItem li = new ListItem("-=全部=-", "all");
  637. this.Items.Add(li);
  638. }
  639. if (this.SelfAddAllLocation == AddAllLocation.TopAndEnd)
  640. this.Items.Add(new ListItem("-=全部=-", "all"));
  641. base.OnPreRender(e);
  642. }
  643. #region 处理用户风格
  644. public void Style3()
  645. {
  646. this.CssClass="DDL3";
  647. /*
  648. //this.BorderColor=Color.Transparent;
  649. this.BackColor=Color.FromName("#006699");
  650. this.ForeColor=Color.White;
  651. */
  652. }
  653. public void Style2()
  654. {
  655. this.CssClass="DDL2";
  656. /*
  657. this.BorderColor=System.Drawing.Color.Transparent;
  658. this.BackColor=Color.FromName("#DEBA84");
  659. this.ForeColor=Color.Black;
  660. */
  661. }
  662. public void Style1()
  663. {
  664. this.CssClass="DDL1";
  665. //this.BorderColor=System.Drawing.Color.FromName("#DEBA84");
  666. //this.BackColor=Color.FromName("#DEBA84");
  667. //this.ForeColor=Color.Black;
  668. }
  669. #endregion
  670. /// <summary>
  671. /// OID, No, Name
  672. /// </summary>
  673. /// <param name="dt"></param>
  674. public void BindWithOIDNoNameCol(DataTable dt)
  675. {
  676. this.Items.Clear();
  677. foreach (DataRow dr in dt.Rows)
  678. {
  679. ListItem li =new ListItem(dr["No"].ToString()+" "+dr["Name"].ToString(),dr["OID"].ToString()) ;
  680. this.Items.Add(li);
  681. }
  682. }
  683. /// <summary>
  684. /// OID, Name
  685. /// </summary>
  686. /// <param name="dt"></param>
  687. public void BindWithOIDNameCol(DataTable dt)
  688. {
  689. this.Items.Clear();
  690. foreach (DataRow dr in dt.Rows)
  691. {
  692. ListItem li =new ListItem( dr["Name"].ToString(),dr["OID"].ToString()) ;
  693. this.Items.Add(li);
  694. }
  695. }
  696. /// <summary>
  697. /// OID, Name
  698. /// </summary>
  699. /// <param name="dt"></param>
  700. public void BindWithOIDNameCol(DataTable dt, string title, string selectVal)
  701. {
  702. this.Items.Clear();
  703. this.Items.Add(new ListItem("-="+title+"(全部)=-","all"));
  704. foreach (DataRow dr in dt.Rows)
  705. {
  706. ListItem li =new ListItem( dr["Name"].ToString(),dr["OID"].ToString()) ;
  707. this.Items.Add(li);
  708. }
  709. this.Items.Add(new ListItem("-="+title+"(全部)=-","all"));
  710. foreach( ListItem li in this.Items )
  711. {
  712. if (li.Value==selectVal)
  713. {
  714. li.Selected=true;
  715. break;
  716. }
  717. }
  718. }
  719. /// <summary>
  720. /// No ,Name bind
  721. /// </summary>
  722. /// <param name="dt"></param>
  723. public void BindWithNoNameCol(DataTable dt, string title)
  724. {
  725. this.Items.Clear();
  726. this.Items.Add(new ListItem("-="+title+"(全部)=-","all"));
  727. foreach (DataRow dr in dt.Rows)
  728. {
  729. ListItem li =new ListItem(dr["Name"].ToString().Trim(),dr["No"].ToString().Trim());
  730. this.Items.Add(li);
  731. }
  732. this.Items.Add(new ListItem("-="+title+"(全部)=-","all"));
  733. }
  734. /// <summary>
  735. /// No ,Name bind
  736. /// </summary>
  737. /// <param name="dt"></param>
  738. public void BindWithNoNameCol(DataTable dt )
  739. {
  740. this.Items.Clear();
  741. foreach (DataRow dr in dt.Rows)
  742. {
  743. ListItem li =new ListItem(dr["Name"].ToString().Trim(),dr["No"].ToString().Trim());
  744. this.Items.Add(li);
  745. }
  746. }
  747. public void BindWithNoNameCol(DataTable dt, string title , string selectNo)
  748. {
  749. this.Items.Clear();
  750. BindWithNoNameCol(dt,title);
  751. foreach(ListItem li in this.Items)
  752. {
  753. if (li.Value.Equals(selectNo))
  754. {
  755. li.Selected=true;
  756. break;
  757. }
  758. }
  759. }
  760. public void BindMonth(int month)
  761. {
  762. this.Items.Clear();
  763. int i = 0 ;
  764. string str="";
  765. while ( i < 12)
  766. {
  767. i++;
  768. str=i.ToString();
  769. if (str.Length==1)
  770. str="0"+str;
  771. ListItem li =new ListItem( i.ToString()+"月", str );
  772. if (i==month)
  773. li.Selected=true;
  774. this.Items.Add(li);
  775. }
  776. }
  777. public void Bindhh(int hh)
  778. {
  779. this.Items.Clear();
  780. int i = 7 ;
  781. string str="";
  782. while ( i < 20 )
  783. {
  784. i++;
  785. str=i.ToString();
  786. if (str.Length==1)
  787. str="0"+str;
  788. ListItem li =new ListItem( i.ToString()+"时", str );
  789. if (i==hh)
  790. li.Selected=true;
  791. this.Items.Add(li);
  792. }
  793. }
  794. public void BindNumFromTo(int from ,int to )
  795. {
  796. this.Items.Clear();
  797. int i = from;
  798. string str = "";
  799. while (i <= to )
  800. {
  801. i++;
  802. str = i.ToString();
  803. if (str.Length == 1)
  804. str = "0" + str;
  805. ListItem li = new ListItem(i.ToString() , str);
  806. this.Items.Add(li);
  807. }
  808. }
  809. public void Bindmm()
  810. {
  811. this.Items.Clear();
  812. int i = 0 ;
  813. string str="";
  814. while ( i < 59)
  815. {
  816. i++;
  817. str=i.ToString();
  818. if (str.Length==1)
  819. str="0"+str;
  820. ListItem li =new ListItem( i.ToString()+"分", str );
  821. this.Items.Add(li);
  822. }
  823. }
  824. public void BindQuector(int selectVal)
  825. {
  826. this.Items.Clear();
  827. this.Items.Add(new ListItem(":00","00"));
  828. this.Items.Add( new ListItem(":15","15"));
  829. this.Items.Add( new ListItem(":30","30"));
  830. this.Items.Add( new ListItem(":45","45"));
  831. this.SetSelectItem( selectVal );
  832. }
  833. public void BindWeek(int selectVal)
  834. {
  835. this.Items.Clear();
  836. this.Items.Add(new ListItem("周日","0"));
  837. this.Items.Add(new ListItem("周一","1"));
  838. this.Items.Add(new ListItem("周二","2"));
  839. this.Items.Add(new ListItem("周三","3"));
  840. this.Items.Add(new ListItem("周四","4"));
  841. this.Items.Add(new ListItem("周五","5"));
  842. this.Items.Add(new ListItem("周六","6"));
  843. this.SetSelectItem( selectVal );
  844. }
  845. public void BindDay( int day )
  846. {
  847. this.Items.Clear();
  848. int i = 0 ;
  849. string str="";
  850. while ( i < 31)
  851. {
  852. i++;
  853. str=i.ToString();
  854. if (str.Length==1)
  855. str="0"+str;
  856. ListItem li =new ListItem( i.ToString()+"日", str );
  857. if (i==day)
  858. li.Selected=true;
  859. this.Items.Add(li);
  860. }
  861. }
  862. /// <summary>
  863. /// bind month ,到当前的月份。
  864. /// </summary>
  865. public void BindMonthToThisMonth()
  866. {
  867. this.Items.Clear();
  868. int m = DateTime.Now.Month;
  869. int i = 0 ;
  870. while ( i < 12)
  871. {
  872. i++;
  873. ListItem li =new ListItem( i.ToString()+"月", i.ToString() );
  874. if (i==m)
  875. {
  876. this.Items.Add(li);
  877. li.Selected=true;
  878. break;
  879. }
  880. this.Items.Add(li);
  881. }
  882. }
  883. /// <summary>
  884. /// bind day 。
  885. /// </summary>
  886. public void BindAppDaySelectedToday()
  887. {
  888. this.Items.Clear();
  889. int m = DateTime.Now.Day ;
  890. int i = 0 ;
  891. while ( i < 31)
  892. {
  893. i++;
  894. ListItem li =new ListItem( i.ToString()+"日", i.ToString() );
  895. if (i==m)
  896. {
  897. this.Items.Add(li);
  898. li.Selected=true;
  899. continue;
  900. }
  901. this.Items.Add(li);
  902. }
  903. }
  904. /// <summary>
  905. /// 季度
  906. /// </summary>
  907. public void BindQuarter()
  908. {
  909. this.Items.Clear();
  910. this.Items.Add( new ListItem("第一季度","1"));
  911. this.Items.Add( new ListItem("第二季度","2"));
  912. this.Items.Add( new ListItem("第三季度","3"));
  913. this.Items.Add( new ListItem("第四季度","4"));
  914. int month = DateTime.Now.Month ;
  915. if (month < 4)
  916. this.SetSelectItem("1");
  917. else if (month >=4 && month < 7)
  918. {
  919. this.SetSelectItem("2");
  920. }
  921. else if (month >=8 && month < 10)
  922. {
  923. this.SetSelectItem("3");
  924. }
  925. else
  926. {
  927. this.SetSelectItem("4");
  928. }
  929. }
  930. public void BindStrs(string[] strs )
  931. {
  932. int i = -1;
  933. foreach (string s in strs)
  934. {
  935. i++;
  936. ListItem li = new ListItem(s, i.ToString());
  937. this.Items.Add(li);
  938. }
  939. }
  940. public void BindAppDay()
  941. {
  942. int i = 1;
  943. while ( i < 31)
  944. {
  945. i++;
  946. ListItem li =new ListItem( i.ToString()+"日", i.ToString() );
  947. this.Items.Add(li);
  948. }
  949. }
  950. public void BindAppDay(string selectedDay)
  951. {
  952. int i =1;
  953. int m = int.Parse(selectedDay);
  954. string str="";
  955. while ( i < 31)
  956. {
  957. i++;
  958. str=i.ToString();
  959. if (str.Length==1)
  960. str="0"+str;
  961. ListItem li =new ListItem( i.ToString()+"日", str );
  962. if (i==m)
  963. {
  964. this.Items.Add(li);
  965. continue;
  966. }
  967. this.Items.Add(li);
  968. }
  969. }
  970. public void BindMonthSelectCurrentMonth()
  971. {
  972. this.Items.Clear();
  973. int m = DateTime.Now.Month ;
  974. int i = 0 ;
  975. string str="";
  976. while ( i < 12)
  977. {
  978. i++;
  979. str=i.ToString();
  980. if (str.Length==1)
  981. str="0"+str;
  982. ListItem li =new ListItem( i.ToString()+"月", str );
  983. if (i==m)
  984. {
  985. li.Selected=true;
  986. }
  987. this.Items.Add(li);
  988. }
  989. }
  990. /// <summary>
  991. /// 月份 1 , 2,
  992. /// </summary>
  993. /// <param name="selectM"></param>
  994. public void BindMonth( string selectM)
  995. {
  996. this.Items.Clear();
  997. int i = 0 ;
  998. string str="";
  999. int m = int.Parse(selectM);
  1000. while ( i < 12)
  1001. {
  1002. i++;
  1003. str=i.ToString();
  1004. if (str.Length==1)
  1005. str="0"+str;
  1006. ListItem li =new ListItem( i.ToString()+"月", str );
  1007. if (i==m)
  1008. li.Selected=true;
  1009. this.Items.Add(li);
  1010. }
  1011. }
  1012. /// <summary>
  1013. /// bind 近三年, 默认值是当前的年
  1014. /// </summary>
  1015. public void BindYearMonth(int nearM)
  1016. {
  1017. DateTime dt = System.DateTime.Now;
  1018. for (int i = 0; i <= nearM; i++)
  1019. {
  1020. this.Items.Add(new ListItem(dt.ToString("yyyy年MM月"), dt.ToString("yyyy-MM")));
  1021. dt= dt.AddMonths(-1);
  1022. i++;
  1023. }
  1024. }
  1025. /// <summary>
  1026. /// bind 近三年, 默认值是当前的年
  1027. /// </summary>
  1028. public void BindYear()
  1029. {
  1030. this.Items.Clear();
  1031. int i1 = System.DateTime.Now.Year;
  1032. int i2 = i1 - 1;
  1033. int i3 = i1 - 2;
  1034. int i4 = i1 - 3;
  1035. int i5 = i1 - 4;
  1036. this.Items.Add(new ListItem(i1.ToString() + "年", i1.ToString()));
  1037. this.Items.Add(new ListItem(i2.ToString() + "年", i2.ToString()));
  1038. this.Items.Add(new ListItem(i3.ToString() + "年", i3.ToString()));
  1039. this.Items.Add(new ListItem(i4.ToString() + "年", i4.ToString()));
  1040. this.Items.Add(new ListItem(i5.ToString() + "年", i5.ToString()));
  1041. }
  1042. /// <summary>
  1043. /// bind 近三年。
  1044. /// </summary>
  1045. /// <param name="selectYear">选择的年度</param>
  1046. public void BindYear(int selectYear)
  1047. {
  1048. this.BindYear();
  1049. foreach (ListItem li in this.Items)
  1050. {
  1051. if (li.Value.Equals(selectYear.ToString()))
  1052. {
  1053. li.Selected = true;
  1054. }
  1055. }
  1056. }
  1057. /// <summary>
  1058. /// bind 近两年的。
  1059. /// </summary>
  1060. public void BindYearNear2()
  1061. {
  1062. this.Items.Clear();
  1063. }
  1064. public void BindAppPrecent(int selectVal)
  1065. {
  1066. int i = 0;
  1067. while (true)
  1068. {
  1069. this.Items.Add(new ListItem(i.ToString() + "%", i.ToString()));
  1070. i++;
  1071. if (i == 100)
  1072. break;
  1073. }
  1074. }
  1075. public int SelectedItemIntVal
  1076. {
  1077. get
  1078. {
  1079. return int.Parse(this.SelectedItem.Value);
  1080. }
  1081. }
  1082. public string SelectedItemStringVal
  1083. {
  1084. get
  1085. {
  1086. return this.SelectedItem.Value;
  1087. }
  1088. }
  1089. #region bind 实体
  1090. public void BindEntities(Entities cateEns, string cateKey, string cateText,Entities subEns, string subKey, string subText , string refKey )
  1091. {
  1092. this.Items.Clear();
  1093. foreach(Entity en in cateEns)
  1094. {
  1095. ListItem li=new ListItem( "==="+en.GetValStringByKey(cateText)+"=====" , en.GetValStringByKey(cateKey) );
  1096. li.Attributes["background-color"]="Green";
  1097. li.Attributes["color"]="Green";
  1098. this.Items.Add(li);
  1099. foreach(Entity suben in subEns)
  1100. {
  1101. if (suben.GetValStringByKey(refKey)==en.GetValStringByKey(cateKey))
  1102. {
  1103. this.Items.Add(new ListItem( "|-"+suben.GetValStringByKey(subText) , suben.GetValStringByKey(subKey) )) ;
  1104. }
  1105. }
  1106. }
  1107. }
  1108. public void BindEntities( Entities ens, string refKey, string refText)
  1109. {
  1110. #warning 去了在2009-03-09
  1111. this.Items.Clear();
  1112. if (ens.Count == 0)
  1113. ens.RetrieveAll();
  1114. if (ens.IsGradeEntities)
  1115. {
  1116. string blank="";
  1117. foreach(Entity en in ens)
  1118. {
  1119. try
  1120. {
  1121. blank="";
  1122. blank=blank.PadLeft( en.GetValIntByKey("Grade")-1, '@' );
  1123. blank=blank.Replace("@","_");
  1124. }
  1125. catch
  1126. {
  1127. //throw new Exception("error Grade="+en.GetValIntByKey("Grade")+" No="+en.GetValStringByKey("No")+" Name"+en.GetValStringByKey("Name")+" Exception="+ex.Message );
  1128. }
  1129. this.Items.Add(new ListItem(blank+ en.GetValStringByKey(refText), en.GetValStringByKey(refKey) )) ;
  1130. }
  1131. }
  1132. else
  1133. {
  1134. foreach(Entity en in ens)
  1135. {
  1136. this.Items.Add(new ListItem( en.GetValStringByKey(refText) , en.GetValStringByKey(refKey) )) ;
  1137. }
  1138. }
  1139. }
  1140. public void BindEntities( EntitiesOIDName ens)
  1141. {
  1142. this.Items.Clear();
  1143. foreach(EntityOIDName en in ens)
  1144. {
  1145. this.Items.Add(new ListItem( en.Name,en.OID.ToString() )) ;
  1146. }
  1147. }
  1148. public void BindEntities(EntitiesNoName ens, AddAllLocation where)
  1149. {
  1150. this.Items.Clear();
  1151. if (where== AddAllLocation.Top || where== AddAllLocation.TopAndEnd)
  1152. this.Items.Add(new ListItem("全部", "all"));
  1153. foreach (EntityNoName en in ens)
  1154. {
  1155. this.Items.Add(new ListItem(en.Name, en.No));
  1156. }
  1157. if (where == AddAllLocation.End || where == AddAllLocation.TopAndEnd)
  1158. this.Items.Add(new ListItem("全部", "all"));
  1159. }
  1160. public void BindEntities(EntitiesOIDName ens, AddAllLocation where)
  1161. {
  1162. this.Items.Clear();
  1163. if (where == AddAllLocation.Top || where == AddAllLocation.TopAndEnd)
  1164. this.Items.Add(new ListItem("全部", "all"));
  1165. foreach (EntityOIDName en in ens)
  1166. this.Items.Add(new ListItem(en.Name, en.OID.ToString()));
  1167. if (where == AddAllLocation.End || where == AddAllLocation.TopAndEnd)
  1168. this.Items.Add(new ListItem("全部", "all"));
  1169. }
  1170. public void BindEntities(EntitiesNoName ens)
  1171. {
  1172. this.Items.Clear();
  1173. foreach (EntityNoName en in ens)
  1174. {
  1175. this.Items.Add(new ListItem(en.Name, en.No));
  1176. }
  1177. }
  1178. public void BindEntitiesNoName( EntitiesNoName ens,bool isShowKey)
  1179. {
  1180. this.Items.Clear();
  1181. foreach(EntityNoName en in ens)
  1182. {
  1183. ListItem li = new ListItem() ;
  1184. if (isShowKey)
  1185. {
  1186. li.Value = en.No ;
  1187. li.Text=en.No+" "+en.Name;
  1188. }
  1189. else
  1190. {
  1191. li.Value=en.No ;
  1192. li.Text=en.Name;
  1193. }
  1194. this.Items.Add( li);
  1195. }
  1196. }
  1197. public void BindEntitiesNoNameWithSelectAll(EntitiesNoName ens ,bool IsShowKey)
  1198. {
  1199. this.Items.Clear();
  1200. this.Items.Add(new ListItem("-=请选择=-","all")) ;
  1201. foreach(EntityNoName en in ens)
  1202. {
  1203. if (IsShowKey)
  1204. this.Items.Add(new ListItem(en.No+en.Name,en.No)) ;
  1205. else
  1206. this.Items.Add(new ListItem(en.Name,en.No)) ;
  1207. }
  1208. }
  1209. public void BindEntitiesNoName(EntitiesNoName ens, string selecVal)
  1210. {
  1211. this.Items.Clear();
  1212. foreach(EntityNoName en in ens)
  1213. {
  1214. this.Items.Add(new ListItem(en.Name,en.No)) ;
  1215. }
  1216. foreach (ListItem li in this.Items)
  1217. {
  1218. if (li.Value==selecVal )
  1219. li.Selected=true;
  1220. }
  1221. }
  1222. #endregion
  1223. #region app
  1224. /// <summary>
  1225. ///
  1226. /// </summary>
  1227. /// <param name="ens"></param>
  1228. public void BindEntitiesOIDName(EntitiesOIDName ens)
  1229. {
  1230. this.Items.Clear();
  1231. foreach(EntityOIDName en in ens)
  1232. {
  1233. this.Items.Add( new ListItem(en.Name,en.OID.ToString()) ) ;
  1234. }
  1235. }
  1236. public void BindEntitiesOIDName(EntitiesOIDName ens, int seleOID)
  1237. {
  1238. this.Items.Clear();
  1239. this.BindEntitiesOIDName(ens);
  1240. foreach(ListItem li in this.Items)
  1241. {
  1242. if (li.Value==seleOID.ToString())
  1243. li.Selected=true;
  1244. }
  1245. }
  1246. public void BindEntitiesNoName(EntitiesNoName ens)
  1247. {
  1248. this.Items.Clear();
  1249. foreach(EntityNoName en in ens)
  1250. {
  1251. this.Items.Add( new ListItem(en.Name, en.No ) ) ;
  1252. }
  1253. }
  1254. public void BindAppYesOrNo(int selectedVal)
  1255. {
  1256. this.Items.Clear();
  1257. this.Items.Add(new ListItem("是", "1") );
  1258. this.Items.Add(new ListItem("否", "0") );
  1259. foreach(ListItem li in this.Items)
  1260. {
  1261. if (li.Value.Equals(selectedVal.ToString()))
  1262. {
  1263. li.Selected=true;
  1264. break;
  1265. }
  1266. }
  1267. }
  1268.  
  1269. public void SetSelectItem(int val)
  1270. {
  1271. this.SetSelectItem(val.ToString() ) ;
  1272. }
  1273. public static bool SetSelectItem( DropDownList ddl, string val)
  1274. {
  1275. try
  1276. {
  1277. foreach (ListItem li in ddl.Items)
  1278. {
  1279. li.Selected = false;
  1280. }
  1281. foreach (ListItem li in ddl.Items)
  1282. {
  1283. if (li.Value == val)
  1284. {
  1285. li.Selected = true;
  1286. return true;
  1287. }
  1288. else
  1289. {
  1290. li.Selected = false;
  1291. }
  1292. }
  1293. }
  1294. catch
  1295. {
  1296. }
  1297. return false;
  1298. }
  1299. public void SetSelectItem(string val, Attr attr)
  1300. {
  1301. if (attr.UIBindKey == "BP.Port.Depts" )
  1302. {
  1303. if (val.Contains(WebUser.FK_Dept) == false)
  1304. return;
  1305. this.Items.Clear();
  1306. BP.Port.Dept detps = new BP.Port.Dept(val);
  1307. ListItem li1 = new ListItem();
  1308. li1.Text = detps.GetValStrByKey(attr.UIRefKeyText);
  1309. li1.Value = detps.GetValStrByKey(attr.UIRefKeyValue);
  1310. this.Items.Add(li1);
  1311. return;
  1312. }
  1313. if ( attr.UIBindKey == "BP.Port.Units")
  1314. {
  1315. if (val.Contains(WebUser.FK_Unit) == false)
  1316. return;
  1317. this.Items.Clear();
  1318. BP.Port.Unit units = new BP.Port.Unit(val);
  1319. ListItem li1 = new ListItem();
  1320. li1.Text = units.GetValStrByKey(attr.UIRefKeyText);
  1321. li1.Value = units.GetValStrByKey(attr.UIRefKeyValue);
  1322. this.Items.Add(li1);
  1323. return;
  1324. }
  1325. //this.SetSelectItem(val);
  1326. //return;
  1327. if (this.SetSelectItem(val))
  1328. return;
  1329. return;
  1330. // Entity en = attr.HisFKEn; // ClassFactory.GetEn(attr.UIBindKey);
  1331. // en.PKVal = val;
  1332. // en.Retrieve();
  1333. //#warning edit: 2008-06-01 en.RetrieveFromDBSources();
  1334. // ListItem li = new ListItem();
  1335. // li.Text = en.GetValStrByKey(attr.UIRefKeyText);
  1336. // li.Value = en.GetValStrByKey(attr.UIRefKeyValue);
  1337. // if (this.Items.Contains(li))
  1338. // {
  1339. // this.SetSelectItem(val);
  1340. // return;
  1341. // }
  1342. // ListItem liall = this.GetItemByText("请用更多...");
  1343. // ListItem myall = this.GetItemByVal("all");
  1344. // if (myall != null)
  1345. // {
  1346. // this.Items.Clear();
  1347. // this.Items.Add(li);
  1348. // this.Items.Add(myall);
  1349. // // this.Items.Remove(liall);
  1350. // }
  1351. // // this.Items.Add(li);
  1352. // this.SetSelectItem(val);
  1353. }
  1354. /// <summary>
  1355. /// 设置选择的值
  1356. /// </summary>
  1357. /// <param name="val"></param>
  1358. public bool SetSelectItem(string val)
  1359. {
  1360. if (val == null)
  1361. return false;
  1362. foreach (ListItem li in this.Items)
  1363. li.Selected = false;
  1364. foreach (ListItem li in this.Items)
  1365. {
  1366. if (li.Value == val)
  1367. {
  1368. li.Selected = true;
  1369. return true;
  1370. }
  1371. else
  1372. {
  1373. li.Selected = false;
  1374. }
  1375. }
  1376. return false;
  1377. }
  1378. public ListItem GetItemByVal(string val)
  1379. {
  1380. foreach (ListItem li in this.Items)
  1381. {
  1382. if (li.Value == val)
  1383. return li;
  1384. }
  1385. return null;
  1386. }
  1387. public ListItem GetItemByText(string text)
  1388. {
  1389. foreach (ListItem li in this.Items)
  1390. {
  1391. if (li.Text == text)
  1392. return li;
  1393. }
  1394. return null;
  1395. }
  1396. public void ReomveItem(string val)
  1397. {
  1398. //int i = -1 ;
  1399. for(int ii = 0 ; ii < this.Items.Count; ii++ )
  1400. {
  1401. if ( this.Items[ii].Value==val )
  1402. {
  1403. this.Items.RemoveAt(ii);
  1404. break;
  1405. }
  1406. }
  1407. }
  1408. /// <summary>
  1409. ///违规次数
  1410. /// </summary>
  1411. public void BindAppWGCS(int selected )
  1412. {
  1413. this.Items.Clear();
  1414. for(int i = 0 ; i <=12 ; i ++)
  1415. {
  1416. ListItem li = new ListItem(i.ToString(), i.ToString());
  1417. if (i ==selected )
  1418. li.Selected=true;
  1419. this.Items.Add(li);
  1420. }
  1421. }
  1422. /// <summary>
  1423. /// 降序/升序
  1424. /// </summary>
  1425. public void BindAppDESCandASC()
  1426. {
  1427. this.Items.Clear();
  1428. this.Items.Add(new ListItem("降序","DESC"));
  1429. this.Items.Add(new ListItem("升序","ASC"));
  1430. }
  1431. #endregion
  1432. }
  1433. }