DataGridViewEc.cs 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Drawing;
  8. using System.Windows.Forms;
  9. using System.Text.RegularExpressions;
  10. using System.Data;
  11. using System.Collections;
  12. using LYFZ;
  13. using System.IO;
  14. using Newtonsoft.Json;
  15. namespace LYFZ.ComponentLibrary
  16. {
  17. public partial class DataGridViewEc : DataGridView
  18. {
  19. #region 属性
  20. /// <summary>
  21. /// 行首收缩图标
  22. /// </summary>
  23. private Image m_imgExpand;
  24. /// <summary>
  25. /// 行首展开图片
  26. /// </summary>
  27. private Image m_imgCollapse;
  28. /// <summary>
  29. /// 行首图片宽度(默认15)
  30. /// </summary>
  31. private int m_nImageWidth;
  32. /// <summary>
  33. /// 行首图片高度(默认15)
  34. /// </summary>
  35. private int m_nImageHeight;
  36. /// <summary>
  37. /// Ord_ViceOrderCount 展开参数 \r\n
  38. /// Ord_ViceOrderCount 的值要大于多少才能可以展开 \r\n
  39. /// 建议设置 0或1
  40. /// </summary>
  41. private int _vicecount = 1;
  42. /// <summary>
  43. /// 展开参数
  44. /// </summary>
  45. [
  46. Category("ViceCount"),
  47. Description("Ord_ViceOrderCount 展开参数 \r\n Ord_ViceOrderCount 的值要大于多少才能可以展开, 建议设置 0或1"),
  48. Bindable(true)
  49. ]
  50. public int ViceCount
  51. {
  52. get
  53. {
  54. return _vicecount;
  55. }
  56. set
  57. {
  58. _vicecount = value;
  59. }
  60. }
  61. /// <summary>
  62. /// 行首收缩图标
  63. /// </summary>
  64. [
  65. Category("CollapseDataGridViewProperties"),
  66. Description("行首收缩图标"),
  67. Bindable(true)
  68. ]
  69. public Image ImgExpand
  70. {
  71. get
  72. {
  73. return this.m_imgExpand;
  74. }
  75. set
  76. {
  77. this.m_imgExpand = value;
  78. }
  79. }
  80. /// <summary>
  81. /// 行首展开图片
  82. /// </summary>
  83. [
  84. Category("CollapseDataGridViewProperties"),
  85. Description("行首展开图片"),
  86. Bindable(true)
  87. ]
  88. public Image ImgCollapse
  89. {
  90. get
  91. {
  92. return this.m_imgCollapse;
  93. }
  94. set
  95. {
  96. this.m_imgCollapse = value;
  97. }
  98. }
  99. /// <summary>
  100. /// 行首图片宽度
  101. /// </summary>
  102. [
  103. Category("CollapseDataGridViewProperties"),
  104. Description("行首图片宽度"),
  105. Bindable(true)
  106. ]
  107. public int ImageWidth
  108. {
  109. get
  110. {
  111. return this.m_nImageWidth;
  112. }
  113. set
  114. {
  115. this.m_nImageWidth = value;
  116. }
  117. }
  118. /// <summary>
  119. /// 行首图片高度
  120. /// </summary>
  121. [
  122. Category("CollapseDataGridViewProperties"),
  123. Description("行首图片高度"),
  124. Bindable(true)
  125. ]
  126. public int ImageHeight
  127. {
  128. get
  129. {
  130. return this.m_nImageHeight;
  131. }
  132. set
  133. {
  134. this.m_nImageHeight = value;
  135. }
  136. }
  137. private int _dgvColumnHeadersHeight = 24;
  138. /// <summary>
  139. /// 列表的高度
  140. /// </summary>
  141. [
  142. Category("CollapseDataGridViewProperties"),
  143. Description("列表的高度"),
  144. Bindable(true)
  145. ]
  146. public int dgvColumnHeadersHeight
  147. {
  148. get
  149. {
  150. return _dgvColumnHeadersHeight;
  151. }
  152. set
  153. {
  154. _dgvColumnHeadersHeight = value;
  155. }
  156. }
  157. /// <summary>
  158. /// DataGridViewEc边框颜色
  159. /// </summary>
  160. [
  161. Category("CollapseDataGridViewProperties"),
  162. Description("DataGridViewEc边框颜色"),
  163. Bindable(true)
  164. ]
  165. public static System.Drawing.Color DataGridViewExBorderColor
  166. {
  167. get
  168. {
  169. return System.Drawing.Color.FromArgb(174, 168, 168);
  170. }
  171. }
  172. /// <summary>
  173. /// DataGridViewEc奇数行的背景颜色
  174. /// </summary>
  175. [
  176. Category("CollapseDataGridViewProperties"),
  177. Description("DataGridViewEc奇数行的背景颜色"),
  178. Bindable(true)
  179. ]
  180. public System.Drawing.Color DataGridViewRowsBackColor_Single()
  181. {
  182. return System.Drawing.Color.PowderBlue;
  183. }
  184. /// <summary>
  185. /// DataGridViewEc偶数行的背景颜色
  186. /// </summary>
  187. [
  188. Category("CollapseDataGridViewProperties"),
  189. Description("DataGridViewEc偶数行的背景颜色"),
  190. Bindable(true)
  191. ]
  192. public System.Drawing.Color DataGridViewRowsBackColor_Double()
  193. {
  194. return System.Drawing.Color.PapayaWhip;
  195. }
  196. private bool _isAutomaticDrawSingleOrDoubleRow = false;
  197. /// <summary>
  198. /// 自动绘单双行
  199. /// </summary>
  200. [
  201. Category("CollapseDataGridViewProperties"),
  202. Description("自动绘单双行"),
  203. Bindable(true)
  204. ]
  205. public bool IsAutomaticDrawSingleOrDoubleRow
  206. {
  207. get
  208. {
  209. return _isAutomaticDrawSingleOrDoubleRow;
  210. }
  211. set
  212. {
  213. _isAutomaticDrawSingleOrDoubleRow = value;
  214. }
  215. }
  216. private bool _isShowSerialNumber = false;
  217. /// <summary>
  218. /// 是否显示列标头自动增长序号
  219. /// </summary>
  220. [
  221. Category("CollapseDataGridViewProperties"),
  222. Description("是否显示列标头自动增长序号"),
  223. Bindable(true)
  224. ]
  225. public bool IsShowSerialNumber
  226. {
  227. get
  228. {
  229. return _isShowSerialNumber;
  230. }
  231. set
  232. {
  233. _isShowSerialNumber = value;
  234. }
  235. }
  236. private string _dgvGuidName;
  237. /// <summary>
  238. /// 当前列表所在全站里的唯一ID
  239. /// </summary>
  240. [
  241. Category("CollapseDataGridViewProperties"),
  242. Description("当前列表所在全站里的唯一ID"),
  243. Bindable(true)
  244. ]
  245. public string dgvGuidName
  246. {
  247. get
  248. {
  249. return _dgvGuidName;
  250. }
  251. set
  252. {
  253. _dgvGuidName = value;
  254. }
  255. }
  256. private string _dgvUserEmployeeID;
  257. /// <summary>
  258. /// 当前所登录者的ID
  259. /// </summary>
  260. [
  261. Category("CollapseDataGridViewProperties"),
  262. Description("当前所登录者的ID"),
  263. Bindable(true)
  264. ]
  265. public string dgvUserEmployeeID
  266. {
  267. get
  268. {
  269. return _dgvUserEmployeeID;
  270. }
  271. set
  272. {
  273. _dgvUserEmployeeID = value;
  274. }
  275. }
  276. private string _dgvFixedHideColumn = "";
  277. /// <summary>
  278. /// 固定隐藏列
  279. /// </summary>
  280. [
  281. Category("CollapseDataGridViewProperties"),
  282. Description("固定隐藏列"),
  283. Bindable(true)
  284. ]
  285. public string dgvFixedHideColumn
  286. {
  287. get
  288. {
  289. return _dgvFixedHideColumn;
  290. }
  291. set
  292. {
  293. _dgvFixedHideColumn = value;
  294. }
  295. }
  296. private string _dgvCurrentHideColumn;
  297. /// <summary>
  298. /// 当前列表隐藏的列标题 (无效)
  299. /// </summary>
  300. [
  301. Category("CollapseDataGridViewProperties"),
  302. Description("当前列表隐藏的列标题"),
  303. Bindable(true)
  304. ]
  305. public string dgvCurrentHideColumn
  306. {
  307. get
  308. {
  309. return _dgvCurrentHideColumn;
  310. }
  311. set
  312. {
  313. _dgvCurrentHideColumn = value;
  314. }
  315. }
  316. private string _dgvCurrentColumnWidth = "";
  317. /// <summary>
  318. /// 当前列表隐藏的列标题
  319. /// </summary>
  320. [
  321. Category("CollapseDataGridViewProperties"),
  322. Description("当前列表隐藏的列标题"),
  323. Bindable(true)
  324. ]
  325. public string dgvCurrentColumnWidth
  326. {
  327. get
  328. {
  329. return _dgvCurrentColumnWidth;
  330. }
  331. set
  332. {
  333. _dgvCurrentColumnWidth = value;
  334. }
  335. }
  336. private bool _IsSortMode = false;
  337. /// <summary>
  338. /// 点击列表头,是否要进行排序
  339. /// </summary>
  340. [
  341. Category("CollapseDataGridViewProperties"),
  342. Description("点击列表头,是否要进行排序"),
  343. Bindable(true)
  344. ]
  345. public bool IsSortMode
  346. {
  347. get
  348. {
  349. return _IsSortMode;
  350. }
  351. set
  352. {
  353. _IsSortMode = value;
  354. }
  355. }
  356. private string _dgvCurrentColumnOriginalSet = "";
  357. /// <summary>
  358. /// 当前列表原来的列标题(用于还原初始设置)
  359. /// </summary>
  360. [
  361. Category("CollapseDataGridViewProperties"),
  362. Description("当前列表原来的列标题(用于还原初始设置)"),
  363. Bindable(true)
  364. ]
  365. public string dgvCurrentColumnOriginalSet
  366. {
  367. get
  368. {
  369. return _dgvCurrentColumnOriginalSet;
  370. }
  371. set
  372. {
  373. _dgvCurrentColumnOriginalSet = value;
  374. }
  375. }
  376. private bool _isCompleteBonding = false;
  377. /// <summary>
  378. /// 是否绑定完成
  379. /// </summary>
  380. [
  381. Category("CollapseDataGridViewProperties"),
  382. Description("是否绑定完成"),
  383. Bindable(true)
  384. ]
  385. public bool IsCompleteBonding
  386. {
  387. get
  388. {
  389. return _isCompleteBonding;
  390. }
  391. set
  392. {
  393. _isCompleteBonding = value;
  394. }
  395. }
  396. /// <summary>
  397. /// 版本号
  398. /// </summary>
  399. private string StrVersionNumber
  400. {
  401. get
  402. {
  403. string strVersionNumber = LYFZ.DAL.DAL_GridViewDisplayIndex.StrVersionNumber;
  404. if ( string.IsNullOrEmpty(strVersionNumber) )
  405. {
  406. MessageBoxCustom.Show("系统有损坏,获取版本号失败!");
  407. }
  408. if ( strVersionNumber == null )
  409. {
  410. strVersionNumber = "";
  411. }
  412. return strVersionNumber;
  413. }
  414. }
  415. bool _isCopyCellValue = true;
  416. /// <summary>
  417. /// 是否能复制单元格的Value值
  418. /// </summary>
  419. [
  420. Category("CollapseDataGridViewProperties"),
  421. Description("是否能复制单元格的Value值"),
  422. Bindable(true)
  423. ]
  424. public bool IsCopyCellValue
  425. {
  426. get
  427. {
  428. return _isCopyCellValue;
  429. }
  430. set
  431. {
  432. _isCopyCellValue = value;
  433. }
  434. }
  435. bool _isSortedRedraw = true;
  436. /// <summary>
  437. /// 是否能复制单元格的Value值
  438. /// </summary>
  439. [
  440. Category("CollapseDataGridViewProperties"),
  441. Description("点击列排序后是否重绘单双行"),
  442. Bindable(true)
  443. ]
  444. public bool IsSortedRedraw
  445. {
  446. get
  447. {
  448. return _isSortedRedraw;
  449. }
  450. set
  451. {
  452. _isSortedRedraw = value;
  453. }
  454. }
  455. public delegate void BindDataSourceRows( DataGridViewRow dgvr, DataGridViewCell cell, DataGridViewRowCollection Rows );
  456. public delegate void BindFilterColumnDataHandler();
  457. public event BindFilterColumnDataHandler BindFilterColumnDataEvent;
  458. /// <summary>
  459. /// 获取当前列表的列标题名
  460. /// </summary>
  461. /// <returns></returns>
  462. public string dgvSetColumnName()
  463. {
  464. if ( !string.IsNullOrEmpty(this.dgvGuidName) && this.AllowUserToOrderColumns )
  465. {
  466. LYFZ.Model.Model_GridViewDisplayIndex model = LYFZ.DAL.DAL_GridViewDisplayIndex.GetGridViewDisplayIndexModel(this.dgvUserEmployeeID, this.dgvGuidName);
  467. if ( model.ID > 0 )
  468. {
  469. string StrColumnName = "";
  470. string StrColumnWidth = "";
  471. if ( !string.IsNullOrEmpty(model.DisplayIndexValue.Trim()) )
  472. {
  473. Dictionary<string, string> dictDataDisplay = LYFZ.DAL.DAL_GridViewDisplayIndex.GetListColumnDisplayValue(model.DisplayIndexValue.Trim());
  474. List<string> listOriginalColumn = new List<string>(this.dgvCurrentColumnOriginalSet.Trim().Split(','));
  475. #region 判断版本不是最新时,则修改
  476. if ( StrVersionNumber.Trim() != model.VerNumber.Trim() )
  477. {
  478. if ( !string.IsNullOrEmpty(model.DisplayIndexValue.Trim()) )
  479. {
  480. Dictionary<string, string> dictNewDat = new Dictionary<string, string>();
  481. foreach ( var item in dictDataDisplay )
  482. {
  483. if ( listOriginalColumn.Contains(item.Key.ToString().Trim()) )
  484. {
  485. dictNewDat.Add(item.Key.ToString().Trim(), item.Value.Trim());
  486. }
  487. }
  488. string StrUpdateNewValue = "";
  489. foreach ( var item in dictNewDat )
  490. {
  491. StrUpdateNewValue += item.Key.ToString().Trim() + ":" + item.Value.ToString().Trim();
  492. }
  493. if ( !string.IsNullOrEmpty(StrUpdateNewValue) )
  494. {
  495. this.Update_GridViewDisplayIndex(StrUpdateNewValue);
  496. }
  497. dictDataDisplay = new Dictionary<string, string>();
  498. dictDataDisplay = dictNewDat;
  499. }
  500. }
  501. #endregion
  502. foreach ( var item in dictDataDisplay )
  503. {
  504. StrColumnName += item.Key.ToString().Trim() + ",";
  505. StrColumnWidth += item.Value.ToString().Trim() + ",";
  506. }
  507. }
  508. this.dgvCurrentColumnWidth = StrColumnWidth.TrimEnd(',');
  509. return StrColumnName.TrimEnd(',');
  510. }
  511. else
  512. {
  513. this.ColumnOriginalSet();
  514. return LYFZ.DAL.DAL_GridViewDisplayIndex.GetStringColumns(this.dgvUserEmployeeID, this.dgvGuidName);
  515. }
  516. }
  517. return "";
  518. }
  519. public void BindFilterColumnData()
  520. {
  521. if ( BindFilterColumnDataEvent != null )
  522. {
  523. BindFilterColumnDataEvent();
  524. }
  525. }
  526. /// <summary>
  527. /// 重置为默认
  528. /// </summary>
  529. /// <returns></returns>
  530. public bool ColumnOriginalSet()
  531. {
  532. string StrValue = "";
  533. List<string> listOriginalColumn = new List<string>(this.dgvCurrentColumnOriginalSet.Trim().Split(','));
  534. List<string> listHideColumn = new List<string>(this.dgvFixedHideColumn.Trim().Split(','));
  535. for ( int i = 0; i < listOriginalColumn.Count; i++ )
  536. {
  537. if ( !string.IsNullOrEmpty(listOriginalColumn[i].Trim()) )
  538. {
  539. if ( !listHideColumn.Contains(listOriginalColumn[i].Trim()) )
  540. {
  541. StrValue += listOriginalColumn[i].Trim() + ":100|";
  542. }
  543. }
  544. }
  545. if ( !string.IsNullOrEmpty(StrValue) )
  546. {
  547. return this.Update_GridViewDisplayIndex(StrValue);
  548. }
  549. return false;
  550. }
  551. /// <summary>
  552. /// 存储当前列表显示数据的列标题名称
  553. /// </summary>
  554. public Dictionary<string, string> dictShowColumName = new Dictionary<string, string>();
  555. #endregion
  556. #region 定义构造
  557. public DataGridViewEc() : base()
  558. {
  559. try
  560. {
  561. // 开启双缓冲;
  562. this.SetStyle(ControlStyles.DoubleBuffer, true);
  563. this.SetStyle(ControlStyles.UserPaint, true);
  564. this.SetStyle(ControlStyles.ResizeRedraw, true);
  565. // 更新双缓冲到样式中;
  566. this.UpdateStyles();
  567. this.Paint += DataGridViewEc_Paint;
  568. this.RowsAdded += DataGridViewEc_RowsAdded;
  569. this.RowStateChanged += DataGridViewEc_RowStateChanged;
  570. this.ColumnWidthChanged += DataGridViewEc_ColumnWidthChanged;
  571. this.ColumnDisplayIndexChanged += DataGridViewEc_ColumnDisplayIndexChanged;
  572. this.Resize += DataGridViewEc_Resize;
  573. this.BackgroundColor = Color.White;
  574. this.CellMouseDown += DataGridViewEc_CellMouseDown;
  575. this.Sorted += DataGridViewEc_Sorted;
  576. this.KeyDown += DataGridViewEc_KeyDown;
  577. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
  578. dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;//211, 223, 240
  579. dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  580. dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White; //标题文字色
  581. dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  582. dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  583. dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(43, 108, 150);//标题背景色
  584. this.EnableHeadersVisualStyles = false;
  585. this.GridColor = System.Drawing.SystemColors.GradientInactiveCaption;
  586. this.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
  587. this.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
  588. this.AllowUserToAddRows = false;
  589. this.AllowUserToDeleteRows = false;
  590. this.AllowUserToResizeRows = false;
  591. this.RowHeadersVisible = true;
  592. this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  593. this.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
  594. this.m_nImageHeight = 15;
  595. this.m_nImageWidth = 15;
  596. this.ImgExpand = global::LYFZ.ComponentLibrary.Properties.Resources.Expand;
  597. this.ImgCollapse = global::LYFZ.ComponentLibrary.Properties.Resources.Collapse;
  598. //隐藏行标题黑色箭头
  599. this.RowHeadersDefaultCellStyle.Padding = new Padding(this.RowHeadersWidth);
  600. this.RowHeadersWidth = 25;
  601. this.ColumnHeadersHeight = this.dgvColumnHeadersHeight;
  602. }
  603. catch { }
  604. }
  605. /// <summary>
  606. /// 设置要隐藏的手机号字段名
  607. /// </summary>
  608. void SetHidePhoneCellsName()
  609. {
  610. if ( this.Columns != null )
  611. {
  612. HidePhoneFindList.Clear();
  613. for ( int i = 0; i < this.Columns.Count; i++ )
  614. {
  615. DataGridViewColumn Column = this.Columns[i];
  616. if ( DataGridViewEx.HidePhoneCellsNameList.Contains(Column.Name) || DataGridViewEx.HidePhoneCellsNameList.Contains(Column.HeaderText) )
  617. {
  618. this.HidePhoneFindList.Add(Column.Name);
  619. }
  620. }
  621. }
  622. }
  623. /// <summary>
  624. /// string[] HidePhoneFinds = "客户电话,电话,固定电话,介绍人电话,手机号码,本人手机,老公手机".Split(',');
  625. /// </summary>
  626. List<string> HidePhoneFindList = new List<string>();
  627. /// <summary>
  628. ///
  629. /// </summary>
  630. /// <param name="sender"></param>
  631. /// <param name="e"></param>
  632. void DataGridViewEc_RowsAdded( object sender, DataGridViewRowsAddedEventArgs e )
  633. {
  634. if ( DataGridViewEx.HidePhoneCellsNameList.Count > 0 )
  635. {
  636. if ( e.RowIndex == 0 )
  637. {
  638. this.SetHidePhoneCellsName();
  639. }
  640. if ( LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherPermissionsSet, LYFZ.CustomAttributes.OperatingAuthority.ProhibitViewCustomerPhoneNumber) && !LYFZ.BLL.BLL_ErpUser.IsAdministrator() && DataGridViewEx.HidePhoneCellsNameList.Count > 0 )
  641. {
  642. try
  643. {
  644. foreach ( string HidePhoneCellsName in HidePhoneFindList )
  645. {
  646. this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Tag = this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value;
  647. //_dataTable.Rows[e.RowIndex][HidePhoneCellsName] = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
  648. this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
  649. }
  650. }
  651. catch (Exception ex){ }
  652. }
  653. }
  654. }
  655. /// <summary>
  656. /// 控件大小发生变化
  657. /// </summary>
  658. /// <param name="sender"></param>
  659. /// <param name="e"></param>
  660. void DataGridViewEc_Resize( object sender, EventArgs e )
  661. {
  662. this.FillLastColumn(this.IsAddNullColumns);
  663. }
  664. /// <summary>
  665. /// 列表标题宽度发变化问题
  666. /// </summary>
  667. /// <param name="sender"></param>
  668. /// <param name="e"></param>
  669. void DataGridViewEc_ColumnWidthChanged( object sender, DataGridViewColumnEventArgs e )
  670. {
  671. this.SetColumnModel();
  672. }
  673. /// <summary>
  674. /// 列表标题顺序发变化问题
  675. /// </summary>
  676. /// <param name="sender"></param>
  677. /// <param name="e"></param>
  678. void DataGridViewEc_ColumnDisplayIndexChanged( object sender, DataGridViewColumnEventArgs e )
  679. {
  680. this.SetColumnModel();
  681. }
  682. /// <summary>
  683. /// 进入修改列变化
  684. /// </summary>
  685. public void SetColumnModel()
  686. {
  687. if ( !string.IsNullOrEmpty(this.dgvGuidName) && this.IsCompleteBonding )
  688. {
  689. string StrValue = "";
  690. for ( int i = 0; i < this.Columns.Count; i++ )
  691. {
  692. for ( int j = 0; j < this.Columns.Count; j++ )
  693. {
  694. if ( this.Columns[j].DisplayIndex == i )
  695. {
  696. if ( this.Columns[j].Name.Trim() != this.FillColumnsNullName )
  697. {
  698. if ( Columns[j].Name.IndexOf('/') != -1 )
  699. StrValue += "[" + this.Columns[j].Name.Trim() + "]:" + this.Columns[j].Width + "|";
  700. else
  701. StrValue += this.Columns[j].Name.Trim() + ":" + this.Columns[j].Width + "|";
  702. }
  703. break;
  704. }
  705. }
  706. }
  707. this.Update_GridViewDisplayIndex(StrValue);
  708. }
  709. }
  710. /// <summary>
  711. /// 修改列标头显示数据
  712. /// </summary>
  713. /// <param name="StrValue"></param>
  714. /// <returns></returns>
  715. bool Update_GridViewDisplayIndex( string StrValue )
  716. {
  717. return LYFZ.DAL.DAL_GridViewDisplayIndex.UpdateGridViewDisplayIndexModel(this.dgvUserEmployeeID, this.dgvGuidName, StrValue, this.StrVersionNumber);
  718. }
  719. /// <summary>
  720. /// 给单双行绘不同的背景颜色
  721. /// </summary>
  722. /// <param name="sender"></param>
  723. /// <param name="e"></param>
  724. void DataGridViewEc_RowStateChanged( object sender, DataGridViewRowStateChangedEventArgs e )
  725. {
  726. if ( IsAutomaticDrawSingleOrDoubleRow )
  727. {
  728. if ( this.Rows.Count != 0 )
  729. {
  730. for ( int i = 0; i < this.Rows.Count; )
  731. {
  732. this.Rows[i].DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
  733. i += 2;
  734. }
  735. }
  736. if ( this.Rows.Count != 0 )
  737. {
  738. for ( int i = 1; i < this.Rows.Count; )
  739. {
  740. this.Rows[i].DefaultCellStyle.BackColor = this.DataGridViewRowsBackColor_Double();
  741. i += 2;
  742. }
  743. }
  744. }
  745. }
  746. /// <summary>
  747. /// 重绘控件
  748. /// </summary>
  749. /// <param name="sender"></param>
  750. /// <param name="e"></param>
  751. void DataGridViewEc_Paint( object sender, PaintEventArgs e )
  752. {
  753. try
  754. {
  755. Pen p = new Pen(DataGridViewExBorderColor);
  756. e.Graphics.DrawRectangle(p, new Rectangle(0, 0, this.Width - 1, this.Height - 1));
  757. }
  758. catch { }
  759. }
  760. public ContextMenuStripEx conMenu = new ContextMenuStripEx();
  761. #region 2017-03-18 杨云奕 右键也选中行内容
  762. void MouseRightSelectSingleRow( int RowIndex )
  763. {
  764. foreach ( DataGridViewRow row in this.Rows )
  765. {
  766. row.Selected = false;
  767. }
  768. this.Rows[RowIndex].Selected = true;
  769. }
  770. #endregion
  771. /// <summary>
  772. /// 右键复制字段
  773. /// </summary>
  774. /// <param name="sender"></param>
  775. /// <param name="e"></param>
  776. void DataGridViewEc_CellMouseDown( object sender, DataGridViewCellMouseEventArgs e )
  777. {
  778. if ( this.Rows.Count > 0 )
  779. {
  780. if ( this.CurrentRow != null )
  781. {
  782. if ( e.ColumnIndex >= 0 && e.RowIndex >= 0 )
  783. {
  784. if ( e.Button == System.Windows.Forms.MouseButtons.Right )
  785. {
  786. /* #region 2017-03-18 杨云奕 右键也选中行内容
  787. MouseRightSelectSingleRow(e.RowIndex);
  788. #endregion
  789. */
  790. this.conMenu.Items.Clear();
  791. if ( IsCopyCellValue )
  792. {
  793. // conMenu.Show(MousePosition.X, MousePosition.Y);//弹出操作菜单
  794. conMenu.ItemClicked -= conMenu_ItemClicked;
  795. conMenu.ItemClicked += conMenu_ItemClicked;
  796. ToolStripMenuItem item = new ToolStripMenuItem();
  797. item.Text = "复制" + this.Columns[e.ColumnIndex].HeaderText;
  798. item.Tag = this.CurrentRow.Index + "|" + e.ColumnIndex;
  799. item.Name = "复制列";
  800. conMenu.Items.Add(item);
  801. }
  802. if ( LYFZ.ComponentLibrary.DataGridViewEx.HidePhoneCellsNameList.Contains(this.Columns[e.ColumnIndex].HeaderText.Trim()) )
  803. {
  804. if ( LYFZ.BLL.OtherCommonModel.GetUserCanViewPhoneCount(LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID) > 0 )
  805. {
  806. // conMenu.Show(MousePosition.X, MousePosition.Y);//弹出操作菜单
  807. conMenu.ItemClicked -= conMenu_ItemClicked;
  808. conMenu.ItemClicked += conMenu_ItemClicked;
  809. ToolStripMenuItem item = new ToolStripMenuItem();
  810. item.Text = "查看完整" + this.Columns[e.ColumnIndex].HeaderText;
  811. item.Tag = this.CurrentRow.Index + "|" + e.ColumnIndex;
  812. item.Name = "查看列";
  813. conMenu.Items.Add(item);
  814. }
  815. }
  816. if ( conMenu.Items.Count > 0 )
  817. {
  818. conMenu.Show(MousePosition.X, MousePosition.Y);//弹出操作菜单
  819. }
  820. }
  821. }
  822. else if ( e.RowIndex == -1 )
  823. {
  824. if ( this.SelectedRows.Count > 3 )
  825. {
  826. if ( e.Button == System.Windows.Forms.MouseButtons.Right )
  827. {
  828. try
  829. {
  830. decimal decAoumnt = 0;
  831. for ( int i = 0; i < this.Rows.Count; i++ )
  832. {
  833. decAoumnt += Convert.ToDecimal(this.Rows[i].Cells[e.ColumnIndex].Value);
  834. }
  835. MessageBoxCustom.Show(decAoumnt.ToString().Trim());
  836. }
  837. catch { }
  838. }
  839. }
  840. }
  841. }
  842. }
  843. }
  844. /// <summary>
  845. /// 排序完成后
  846. /// </summary>
  847. /// <param name="sender"></param>
  848. /// <param name="e"></param>
  849. void DataGridViewEc_Sorted( object sender, EventArgs e )
  850. {
  851. if ( this.IsSortedRedraw )
  852. {
  853. int RowUniqueMark = 0;
  854. for ( int i = 0; i < this.Rows.Count; i++ )
  855. {
  856. if ( (RowUniqueMark % 2) > 0 )
  857. {
  858. this.Rows[i].DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Double();
  859. }
  860. else
  861. {
  862. this.Rows[i].DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
  863. }
  864. RowUniqueMark++;
  865. }
  866. }
  867. }
  868. public delegate void DataGridView_ConMenu_ItemClicked( object sender, ToolStripItemClickedEventArgs e );
  869. /// <summary>
  870. /// 用event 关键字声明事件对象
  871. /// </summary>
  872. [Category("控件扩展事件"), Description("列表右击显示菜单事件")]
  873. public event DataGridView_ConMenu_ItemClicked DataGridViewConMenu_ItemClicked;
  874. void conMenu_ItemClicked( object sender, ToolStripItemClickedEventArgs e )
  875. {
  876. ToolStripItem item = e.ClickedItem;
  877. if ( !string.IsNullOrEmpty(item.Name) && item.Name.Trim() == "复制列" )
  878. {
  879. if ( !string.IsNullOrEmpty(item.Text.Trim()) && item.Tag != null )
  880. {
  881. string[] StrTag = item.Tag.ToString().Trim().Split('|');
  882. Clipboard.SetDataObject(this.Rows[Convert.ToInt32(StrTag[0])].Cells[Convert.ToInt32(StrTag[1])].Value.ToString().Trim());
  883. }
  884. }
  885. else if ( !string.IsNullOrEmpty(item.Name) && item.Name.Trim() == "查看列" )
  886. {
  887. if ( !string.IsNullOrEmpty(item.Text.Trim()) && item.Tag != null )
  888. {
  889. string[] StrTag = item.Tag.ToString().Trim().Split('|');
  890. if ( LYFZ.BLL.OtherCommonModel.UserCanViewPhoneCount == -2 )
  891. {
  892. DataTable dt = new LYFZ.BLL.BLL_ErpOrder().GetView_Custom("tb_ErpUser", StrWhere: "User_EmployeeID='" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID + "'", ShowColumnName: "User_LookPhoneQuantity").Tables[0];
  893. if ( dt.Rows.Count > 0 )
  894. {
  895. LYFZ.BLL.OtherCommonModel.UserCanViewPhoneCount = Convert.ToInt32(dt.Rows[0]["User_LookPhoneQuantity"]);
  896. }
  897. else
  898. {
  899. LYFZ.BLL.OtherCommonModel.UserCanViewPhoneCount = 0;
  900. }
  901. }
  902. LYFZ.ComponentLibrary.frmFullPhoneNumber frm = new frmFullPhoneNumber();
  903. frm.StrUserNumber = LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID;
  904. frm.StrPhone = this.Rows[Convert.ToInt32(StrTag[0])].Cells[Convert.ToInt32(StrTag[1])].Tag.ToString().Trim();
  905. frm.ShowDialog();
  906. }
  907. }
  908. else
  909. {
  910. if ( this.DataGridViewConMenu_ItemClicked != null )
  911. {
  912. this.DataGridViewConMenu_ItemClicked(sender, e);
  913. }
  914. }
  915. }
  916. /// <summary>
  917. ///
  918. /// </summary>
  919. /// <param name="sender"></param>
  920. /// <param name="e"></param>
  921. void DataGridViewEc_KeyDown( object sender, KeyEventArgs e )
  922. {
  923. if ( e.KeyData == (Keys.Control | Keys.C) )
  924. {
  925. e.Handled = true;
  926. }
  927. }
  928. #endregion
  929. #region 公共方法
  930. Font ft9 = new Font("宋体", 10);
  931. /// <summary>
  932. /// 重写OnRowPostPaint()方法,以在折叠行前加上状态标识
  933. /// </summary>
  934. /// <param name="e"></param>
  935. protected override void OnRowPostPaint( DataGridViewRowPostPaintEventArgs e )
  936. {
  937. //base.OnRowPostPaint(e);
  938. try
  939. {
  940. //IsShowSerialNumber = true;
  941. this.ColumnHeadersHeight = this.dgvColumnHeadersHeight;
  942. this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  943. DataGridViewRow row = this.Rows[e.RowIndex];
  944. if ( this.Columns.Contains("Ord_ViceOrderCount") )
  945. {
  946. if ( Convert.ToInt32(this.Rows[e.RowIndex].Cells["Ord_ViceOrderCount"].Value) > ViceCount && this.RowHeadersVisible )
  947. {
  948. Rectangle rect = new Rectangle(e.RowBounds.Location.X + 4, e.RowBounds.Location.Y + 4, this.m_nImageWidth, this.m_nImageHeight);
  949. Image img = null;
  950. string HeaderCellValue = row.HeaderCell.Value.ToString().Trim().Split('_')[1].Trim();
  951. if ( HeaderCellValue == "Collapse" )
  952. {
  953. img = this.ImgCollapse;
  954. }
  955. else
  956. {
  957. img = this.ImgExpand;
  958. }
  959. e.Graphics.DrawImage(img, rect);
  960. }
  961. }
  962. else if ( IsShowSerialNumber )
  963. {
  964. string HeaderCellValue = (e.RowIndex + 1).ToString();
  965. int w = this.RowHeadersWidth;
  966. int FtWidth = Convert.ToInt32(e.Graphics.MeasureString(HeaderCellValue, ft9).Width);
  967. Rectangle rect = new Rectangle(e.RowBounds.Location.X + (w / 2 - FtWidth / 2 - 1), e.RowBounds.Location.Y + 5, w, this.Height);
  968. e.Graphics.DrawString(HeaderCellValue, ft9, Brushes.Black, rect);
  969. }
  970. if(row.Tag!=null&& row.Tag.ToString()== "Sign")
  971. {
  972. string HeaderCellValue = "*";
  973. int w = this.RowHeadersWidth;
  974. int FtWidth = Convert.ToInt32(e.Graphics.MeasureString(HeaderCellValue, ft9).Width);
  975. Rectangle rect = new Rectangle(e.RowBounds.Location.X + (w / 2 - FtWidth / 2 - 1), e.RowBounds.Location.Y + 5, w, this.Height);
  976. e.Graphics.DrawString(HeaderCellValue, ft9, Brushes.Black, rect);
  977. }
  978. }
  979. catch { }
  980. }
  981. /// <summary>
  982. /// 点击
  983. /// </summary>
  984. /// <param name="e"></param>
  985. protected override void OnRowHeaderMouseClick( DataGridViewCellMouseEventArgs e )
  986. {
  987. try
  988. {
  989. DataGridViewRow row = this.Rows[e.RowIndex];
  990. if ( row.Index >= 0 )
  991. {
  992. this.CRowsIndex = e.RowIndex;
  993. EventExpandCollapse expColl = new EventExpandCollapse();
  994. expColl.CRows = this.Rows;
  995. expColl.OnRowHeaderMouseClick = e;
  996. if ( row.HeaderCell.Value != null )
  997. {
  998. if ( row.HeaderCell.Value.ToString().Trim().IndexOf('_') != -1 )
  999. {
  1000. string HeaderCellValue_0 = row.HeaderCell.Value.ToString().Trim().Split('_')[0].Trim();
  1001. string HeaderCellValue = row.HeaderCell.Value.ToString().Trim().Split('_')[1].Trim();
  1002. if ( HeaderCellValue == "Collapse" )
  1003. {
  1004. expColl.ExpandOrCollapse = false;
  1005. row.HeaderCell.Value = HeaderCellValue_0 + "_" + "Expand";
  1006. row.HeaderCell.ToolTipText = "点击展开";
  1007. //string HeaderCellValue = row.HeaderCell.Value.ToString().Trim().Split('_')[0].Trim();
  1008. for ( int i = 0; i < this.Rows.Count; i++ )
  1009. {
  1010. if ( "Vice" + HeaderCellValue_0 == this.Rows[i].HeaderCell.Value.ToString().Trim() )
  1011. {
  1012. this.Rows[i].Visible = false;
  1013. }
  1014. }
  1015. }
  1016. //点击进行展开
  1017. else
  1018. {
  1019. expColl.ExpandOrCollapse = true;
  1020. row.HeaderCell.Value = HeaderCellValue_0 + "_" + "Collapse";
  1021. row.HeaderCell.ToolTipText = "点击折叠";
  1022. if ( EventRowExpandCollapse != null )
  1023. {
  1024. this.EventRowExpandCollapse(expColl);
  1025. }
  1026. }
  1027. }
  1028. }
  1029. }
  1030. try
  1031. {
  1032. base.OnRowHeaderMouseClick(e);
  1033. }
  1034. catch
  1035. {
  1036. }
  1037. }
  1038. catch { }
  1039. }
  1040. /// <summary>
  1041. /// 当前选中行
  1042. /// </summary>
  1043. private int CRowsIndex;
  1044. /// <summary>
  1045. /// 子集子数据的绑定
  1046. /// </summary>
  1047. /// <param name="Vicetbl"></param>
  1048. public void DataSourceVice( DataTable Vicetbl )
  1049. {
  1050. try
  1051. {
  1052. if ( Convert.ToBoolean(this.Rows[CRowsIndex].HeaderCell.Tag) == true )
  1053. {
  1054. if ( Vicetbl.Rows.Count > 0 )
  1055. {
  1056. for ( int i = 0; i < Vicetbl.Rows.Count; i++ )
  1057. {
  1058. try
  1059. {
  1060. DataGridViewRow dgvr = new DataGridViewRow();
  1061. dgvr.HeaderCell.Value = "Vice" + this.Rows[CRowsIndex].HeaderCell.Value.ToString().Trim().Split('_')[0].Trim();
  1062. dgvr.DefaultCellStyle.BackColor = this.Rows[CRowsIndex].DefaultCellStyle.BackColor;
  1063. dgvr.Height = 25;
  1064. DataGridViewCell cell = null;
  1065. for ( int j = 0; j < Vicetbl.Columns.Count; j++ )
  1066. {
  1067. cell = new DataGridViewTextBoxCell();
  1068. cell.Value = Vicetbl.Rows[i][Vicetbl.Columns[j].ToString().Trim()].ToString().Trim();
  1069. dgvr.Cells.Add(cell);
  1070. }
  1071. int NewCRowsIndex = (CRowsIndex + i + 1);
  1072. this.Rows.InsertRange(NewCRowsIndex, dgvr);
  1073. }
  1074. catch { break; }
  1075. }
  1076. this.Rows[CRowsIndex].HeaderCell.Tag = false;
  1077. }
  1078. }
  1079. else
  1080. {
  1081. this.DataContractRows();
  1082. }
  1083. }
  1084. catch { }
  1085. }
  1086. private string _strValueNullColumn = "";
  1087. /// <summary>
  1088. /// 固定默认要为空的副级字段
  1089. /// </summary>
  1090. [Browsable(false)]
  1091. public string StrValueNullColumn
  1092. {
  1093. get
  1094. {
  1095. return _strValueNullColumn;
  1096. }
  1097. set
  1098. {
  1099. _strValueNullColumn = value;
  1100. }
  1101. }
  1102. private string _strSecondStageNull = "";
  1103. /// <summary>
  1104. /// 固定默认要为空的副级字段(为第三二级要为空的字段)
  1105. /// </summary>
  1106. [Browsable(false)]
  1107. public string StrSecondStageNull
  1108. {
  1109. get
  1110. {
  1111. return _strSecondStageNull;
  1112. }
  1113. set
  1114. {
  1115. _strSecondStageNull = value;
  1116. }
  1117. }
  1118. public string DgvValueFiledNull = "";
  1119. /// <summary>
  1120. /// 子集子数据的绑定
  1121. /// </summary>
  1122. /// <param name="Vicetbl"></param>
  1123. public void DataSourceViceRow( DataRow[] dtRow )
  1124. {
  1125. try
  1126. {
  1127. if ( Convert.ToBoolean(this.Rows[CRowsIndex].HeaderCell.Tag) == true )
  1128. {
  1129. this.DataExpandRows(dtRow);
  1130. }
  1131. else
  1132. {
  1133. this.DataContractRows();
  1134. }
  1135. }
  1136. catch { }
  1137. }
  1138. /// <summary>
  1139. /// 展开行
  1140. /// </summary>
  1141. void DataExpandRows( DataRow[] dtRow )
  1142. {
  1143. DataRow dtrow = dtRow[0];
  1144. if ( dtRow.Length > 0 )
  1145. {
  1146. string[] strValueNull = DgvValueFiledNull.Split(',');
  1147. for ( int i = 0; i < dtRow.Length; i++ )
  1148. {
  1149. try
  1150. {
  1151. DataGridViewRow dgvr = new DataGridViewRow();
  1152. dgvr.HeaderCell.Value = "Vice" + this.Rows[CRowsIndex].HeaderCell.Value.ToString().Trim().Split('_')[0].Trim();
  1153. dgvr.DefaultCellStyle.BackColor = this.Rows[CRowsIndex].DefaultCellStyle.BackColor;
  1154. dgvr.Height = 25;
  1155. DataGridViewCell cell = null;
  1156. for ( int j = 0; j < dtrow.Table.Columns.Count; j++ )
  1157. {
  1158. bool Isbl = true;
  1159. for ( int k = 0; k < strValueNull.Length; k++ )
  1160. {
  1161. if ( dtrow.Table.Columns[j].ColumnName.Trim() == strValueNull[k].ToString().Trim() )
  1162. {
  1163. Isbl = false;
  1164. break;
  1165. }
  1166. }
  1167. cell = new DataGridViewTextBoxCell();
  1168. if ( Isbl )
  1169. {
  1170. cell.Value = dtRow[i][dtrow.Table.Columns[j].ColumnName.Trim()].ToString().Trim();
  1171. }
  1172. else
  1173. {
  1174. string StrValues = "";
  1175. if ( dtrow.Table.Columns[j].ColumnName.Trim() == "订单号" )
  1176. {
  1177. if ( dtrow.Table.Columns.Contains("取件状态") )
  1178. {
  1179. if ( dtRow[i]["取件状态"].ToString().Trim() == "OK" )
  1180. {
  1181. StrValues = "(取件OK)";
  1182. }
  1183. }
  1184. if ( dtrow.Table.Columns.Contains("订单类型") )
  1185. {
  1186. if ( dtRow[i]["订单类型"].ToString().Trim() != LYFZ.EnumPublic.OrderType.儿童订单.ToString().Trim() )
  1187. {
  1188. StrValues = "";
  1189. }
  1190. }
  1191. }
  1192. cell.Value = StrValues;
  1193. }
  1194. dgvr.Cells.Add(cell);
  1195. }
  1196. int NewCRowsIndex = (CRowsIndex + i + 1);
  1197. this.Rows.InsertRange(NewCRowsIndex, dgvr);
  1198. }
  1199. catch { break; }
  1200. }
  1201. this.Rows[CRowsIndex].HeaderCell.Tag = false;
  1202. }
  1203. }
  1204. /// <summary>
  1205. /// 收缩行
  1206. /// </summary>
  1207. void DataContractRows()
  1208. {
  1209. string HeaderCellValue = this.Rows[CRowsIndex].HeaderCell.Value.ToString().Trim().Split('_')[0].Trim();
  1210. for ( int i = 0; i < this.Rows.Count; i++ )
  1211. {
  1212. if ( "Vice" + HeaderCellValue == this.Rows[i].HeaderCell.Value.ToString().Trim() )
  1213. {
  1214. this.Rows[i].Visible = true;
  1215. }
  1216. }
  1217. }
  1218. /// <summary>
  1219. /// 添加带展开/折叠的行
  1220. /// </summary>
  1221. /// <param name="dtRow"></param>
  1222. void AddExpandDataGridViewRows( DataRow dtRow, int rowI )
  1223. {
  1224. DataGridViewRow dgvr = new DataGridViewRow();
  1225. if ( (rowI % 2) > 0 )
  1226. {
  1227. dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Double();
  1228. }
  1229. else
  1230. {
  1231. dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
  1232. }
  1233. dgvr.HeaderCell.Tag = true;
  1234. dgvr.HeaderCell.Value = rowI + "_Expand";
  1235. dgvr.HeaderCell.ToolTipText = "点击展开";
  1236. dgvr.Height = 25;
  1237. DataGridViewCell cell = null;
  1238. for ( int j = 0; j < this.Columns.Count; j++ )
  1239. {
  1240. cell = new DataGridViewTextBoxCell();
  1241. if ( this.Columns[j].Name.ToString().Trim() == "订单号" )
  1242. {
  1243. string StrValues = dtRow[this.Columns[j].Name.ToString().Trim()].ToString().Trim();
  1244. if ( this.Columns.Contains("取件状态") )
  1245. {
  1246. if ( dtRow["取件状态"].ToString().Trim() == "OK" )
  1247. {
  1248. StrValues += "(取件OK)";
  1249. }
  1250. }
  1251. cell.Value = StrValues;
  1252. }
  1253. else
  1254. {
  1255. cell.Value = dtRow[this.Columns[j].Name.ToString().Trim()].ToString().Trim();
  1256. }
  1257. dgvr.Cells.Add(cell);
  1258. }
  1259. this.Rows.Add(dgvr);
  1260. }
  1261. /// <summary>
  1262. /// 主数据的绑定 拍照订单
  1263. /// </summary>
  1264. /// <param name="dt"></param>
  1265. public void DataSourceMain( DataTable dt, string strHideField = "" )
  1266. {
  1267. try
  1268. {
  1269. this.IsCompleteBonding = false;
  1270. this.Rows.Clear();
  1271. this.DataColumns(dt.Columns, strHideField: strHideField);
  1272. #region 处理行内容
  1273. // 行的唯一标识
  1274. int RowUniqueMark = 1;
  1275. AddExpandDataGridViewRows(dt.Rows[0], 0);
  1276. for ( int i = 1; i < dt.Rows.Count; i++ )
  1277. {
  1278. if ( dt.Rows[i]["Ord_Number"].ToString().Trim() != dt.Rows[i - 1]["Ord_Number"].ToString().Trim() )
  1279. {
  1280. AddExpandDataGridViewRows(dt.Rows[i], RowUniqueMark);
  1281. RowUniqueMark++;
  1282. }
  1283. else
  1284. {
  1285. //for (int j = 0; j < this.Rows.Count; j++)
  1286. for ( int j = this.Rows.Count - 1; j >= 0; j-- )
  1287. {
  1288. if ( dt.Rows[i]["Ord_Number"].ToString().Trim() == this.Rows[j].Cells["Ord_Number"].Value.ToString().Trim() )
  1289. {
  1290. this.Rows[j].Cells["Ord_ViceOrderCount"].Value = Convert.ToInt32(this.Rows[j].Cells["Ord_ViceOrderCount"].Value) + 1;
  1291. }
  1292. else
  1293. {
  1294. break;
  1295. }
  1296. }
  1297. }
  1298. }
  1299. #endregion
  1300. this.IsCompleteBonding = true;
  1301. }
  1302. catch
  1303. {
  1304. }
  1305. }
  1306. /// <summary>
  1307. /// 只绑定列
  1308. /// </summary>
  1309. /// <param name="StrColumns"></param>
  1310. /// <param name="strHideField"></param>
  1311. public void DataColumns( string StrColumns, string strHideField = "" )
  1312. {
  1313. this.IsCompleteBonding = false;
  1314. if ( StrColumns != "" )
  1315. {
  1316. this.Columns.Clear();
  1317. this.Rows.Clear();
  1318. DataGridViewTextBoxColumn column = null;
  1319. List<string> listColumn = new List<string>(StrColumns.Split(','));
  1320. List<string> listHideField = new List<string>(strHideField.Split(','));
  1321. for ( int i = 0; i < listColumn.Count; i++ )
  1322. {
  1323. column = new DataGridViewTextBoxColumn();
  1324. column.ReadOnly = true;
  1325. column.Name = listColumn[i].Trim();
  1326. column.HeaderText = listColumn[i].Trim();
  1327. if ( listHideField.Contains(listColumn[i].Trim()) )
  1328. {
  1329. column.Visible = false;
  1330. }
  1331. if ( IsSortMode )
  1332. {
  1333. column.SortMode = DataGridViewColumnSortMode.Automatic;
  1334. }
  1335. this.Columns.Add(column);
  1336. }
  1337. this.ColumnHeadersHeight = this.dgvColumnHeadersHeight;
  1338. this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  1339. }
  1340. }
  1341. /// <summary>
  1342. /// 绑定列
  1343. /// </summary>
  1344. /// <param name="DataColumn"></param>
  1345. public void DataColumns( DataColumnCollection DataColumns, string strHideField = "" )
  1346. {
  1347. this.IsCompleteBonding = false;
  1348. this.Columns.Clear();
  1349. if ( DataColumns.Count > 0 )
  1350. {
  1351. DataGridViewTextBoxColumn column = null;
  1352. List<string> listHideField = new List<string>(strHideField.Split(','));
  1353. if ( !string.IsNullOrEmpty(this.dgvUserEmployeeID) && !string.IsNullOrEmpty(this.dgvGuidName) && this.dictShowColumName.Count > 0 )
  1354. {
  1355. string strKey = "";
  1356. for ( int i = 0; i < DataColumns.Count; i++ )
  1357. {
  1358. #if IGNORE
  1359. if (dictShowColumName.Keys.Contains(DataColumns[i].ToString().Trim()))
  1360. {
  1361. column = new DataGridViewColumn();
  1362. column.ReadOnly = true;
  1363. column.Name = DataColumns[i].ToString().Trim();
  1364. column.HeaderText = DataColumns[i].ToString().Trim();
  1365. column.Width = Convert.ToInt32(dictShowColumName[DataColumns[i].ToString().Trim()].Trim());
  1366. if (listHideField.Contains(DataColumns[i].ToString().Trim()))
  1367. { column.Visible = false; }
  1368. if (IsSortMode)
  1369. { column.SortMode = DataGridViewColumnSortMode.Automatic; }
  1370. this.Columns.Add(column);
  1371. }
  1372. #else
  1373. bool bExist = false;
  1374. foreach ( var e in dictShowColumName )
  1375. {
  1376. strKey = e.Key;
  1377. if ( e.Key.TrimStart('[').TrimEnd(']') == DataColumns[i].ToString().Trim() )
  1378. {
  1379. bExist = true;
  1380. break;
  1381. }
  1382. }
  1383. if ( bExist )
  1384. {
  1385. column = new DataGridViewTextBoxColumn();
  1386. column.ReadOnly = true;
  1387. column.Name = DataColumns[i].ToString().Trim();
  1388. column.HeaderText = DataColumns[i].ToString().Trim();
  1389. column.Width = Convert.ToInt32(dictShowColumName[strKey].Trim());
  1390. if ( listHideField.Contains(DataColumns[i].ToString().Trim()) )
  1391. {
  1392. column.Visible = false;
  1393. }
  1394. if ( IsSortMode )
  1395. {
  1396. column.SortMode = DataGridViewColumnSortMode.Automatic;
  1397. }
  1398. this.Columns.Add(column);
  1399. }
  1400. #endif
  1401. }
  1402. }
  1403. else
  1404. {
  1405. for ( int i = 0; i < DataColumns.Count; i++ )
  1406. {
  1407. column = new DataGridViewTextBoxColumn();
  1408. column.ReadOnly = true;
  1409. column.Name = DataColumns[i].ToString().Trim();
  1410. column.HeaderText = DataColumns[i].ToString().Trim();
  1411. if ( listHideField.Contains(DataColumns[i].ToString().Trim()) )
  1412. {
  1413. column.Visible = false;
  1414. }
  1415. if ( IsSortMode )
  1416. {
  1417. column.SortMode = DataGridViewColumnSortMode.Automatic;
  1418. }
  1419. this.Columns.Add(column);
  1420. }
  1421. }
  1422. }
  1423. this.IsCompleteBonding = true;
  1424. }
  1425. /// <summary>
  1426. /// 绑定行
  1427. /// </summary>
  1428. public void DataRows( DataTable dt, int DataSourceTopCount = -1 )
  1429. {
  1430. // 行的唯一标识
  1431. float RowUniqueMark = 0;
  1432. int forRowCount = dt.Rows.Count;
  1433. if ( DataSourceTopCount != -1 )
  1434. {
  1435. if ( dt.Rows.Count > DataSourceTopCount )
  1436. forRowCount = DataSourceTopCount;
  1437. }
  1438. for ( int i = 0; i < forRowCount; i++ )
  1439. {
  1440. DataGridViewRow dgvr = new DataGridViewRow();
  1441. if ( (RowUniqueMark % 2) > 0 )
  1442. dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Double();
  1443. else
  1444. dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
  1445. dgvr.HeaderCell.Tag = true;
  1446. dgvr.Height = 25;
  1447. DataGridViewCell cell = null;
  1448. for ( int j = 0; j < dt.Columns.Count; j++ )
  1449. {
  1450. cell = new DataGridViewTextBoxCell();
  1451. cell.Value = dt.Rows[i][dt.Columns[j].ToString().Trim()].ToString().Trim();
  1452. dgvr.Cells.Add(cell);
  1453. }
  1454. this.Rows.Add(dgvr);
  1455. RowUniqueMark++;
  1456. }
  1457. }
  1458. /// <summary>
  1459. /// 主数据的绑定,列名可能与DataTable中的列名不同
  1460. /// </summary>
  1461. /// <param name="dt">数据源</param>
  1462. /// <param name="strHideField">要隐藏的字段</param>
  1463. /// <param name="IsBindColumns">是否要绑定列</param>
  1464. /// <param name="ColumnAsName">数据源的列名As重命名的列名串</param>
  1465. public new void DataSource( DataTable dt, string strHideField = "", bool IsBindColumns = true, string ColumnAsName = "", bool IsClearRows = true, int DataSourceTopCount = -1 )
  1466. {
  1467. UseVirtualMode(dt, strHideField, IsBindColumns, ColumnAsName, IsClearRows, DataSourceTopCount);
  1468. return;
  1469. try
  1470. {
  1471. this.IsCompleteBonding = false;
  1472. if ( IsClearRows )
  1473. this.Rows.Clear();
  1474. if ( IsBindColumns )
  1475. {
  1476. if ( !string.IsNullOrEmpty(ColumnAsName) )
  1477. this.DataColumns(ColumnAsName, strHideField: strHideField);
  1478. else
  1479. this.DataColumns(dt.Columns, strHideField: strHideField);
  1480. }
  1481. this.DataRows(dt, DataSourceTopCount);
  1482. this.IsCompleteBonding = true;
  1483. }
  1484. catch
  1485. {
  1486. }
  1487. }
  1488. /// <summary>
  1489. /// 数据绑定
  1490. /// </summary>
  1491. /// <param name="dtRow"></param>
  1492. /// <param name="IsClearRows"></param>
  1493. public new void DataSource( DataRow[] dtRow, bool IsClearRows = false )
  1494. {
  1495. if ( IsClearRows )
  1496. {
  1497. this.Rows.Clear();
  1498. }
  1499. for ( int i = 0; i < dtRow.Length; i++ )
  1500. {
  1501. DataGridViewRow dgvr = new DataGridViewRow();
  1502. if ( (i % 2) > 0 )
  1503. {
  1504. dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Double();
  1505. }
  1506. else
  1507. {
  1508. dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
  1509. }
  1510. DataGridViewCell cell = null;
  1511. for ( int j = 0; j < dtRow[0].Table.Columns.Count; j++ )
  1512. {
  1513. cell = new DataGridViewTextBoxCell();
  1514. cell.Value = dtRow[i][j].ToString().Trim();
  1515. dgvr.Cells.Add(cell);
  1516. }
  1517. this.Rows.Add(dgvr);
  1518. }
  1519. }
  1520. public new void DataSource(DataTable dt, DataTable signRemark = null)
  1521. {
  1522. if (signRemark != null)
  1523. {
  1524. _SignRemark = signRemark;
  1525. }
  1526. UseVirtualMode(dt);
  1527. return;
  1528. }
  1529. /// <summary>
  1530. /// 数据绑定(通常用于订单流程的绑定)
  1531. /// </summary>
  1532. /// <param name="dt"></param>
  1533. /// <param name="StrColumnValueNull"></param>
  1534. /// <param name="strHideField"></param>
  1535. public new void DataSource( DataTable dt)
  1536. {
  1537. UseVirtualMode(dt);
  1538. return;
  1539. this.IsCompleteBonding = false;
  1540. this.Rows.Clear();
  1541. this.DataColumns(dt.Columns, this.dgvFixedHideColumn.Trim());
  1542. DataGridViewRow dgvr = null;
  1543. DataGridViewCell cell = null;
  1544. List<string> listContainsNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
  1545. Color CurrentColor = this.DataGridViewRowsBackColor_Single();
  1546. for ( int i = 0; i < dt.Rows.Count; i++ )
  1547. {
  1548. dgvr = new DataGridViewRow();
  1549. dgvr.Height = 25;
  1550. if ( i == 0 )
  1551. {
  1552. CurrentColor = this.DataGridViewRowsBackColor_Single();
  1553. for ( int j = 0; j < this.Columns.Count; j++ )
  1554. {
  1555. cell = new DataGridViewTextBoxCell();
  1556. cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
  1557. dgvr.Cells.Add(cell);
  1558. }
  1559. }
  1560. else
  1561. {
  1562. if ( dt.Rows[i]["Ord_Number"].Equals(dt.Rows[i - 1]["Ord_Number"]) )
  1563. {
  1564. for ( int j = 0; j < this.Columns.Count; j++ )
  1565. {
  1566. cell = new DataGridViewTextBoxCell();
  1567. if ( listContainsNullColumn.Contains(this.Columns[j].Name.Trim()) )
  1568. {
  1569. cell.Value = "";
  1570. }
  1571. else
  1572. {
  1573. cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
  1574. }
  1575. dgvr.Cells.Add(cell);
  1576. }
  1577. }
  1578. else
  1579. {
  1580. if ( CurrentColor == this.DataGridViewRowsBackColor_Single() )
  1581. {
  1582. CurrentColor = this.DataGridViewRowsBackColor_Double();
  1583. }
  1584. else
  1585. {
  1586. CurrentColor = this.DataGridViewRowsBackColor_Single();
  1587. }
  1588. for ( int j = 0; j < this.Columns.Count; j++ )
  1589. {
  1590. cell = new DataGridViewTextBoxCell();
  1591. cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
  1592. dgvr.Cells.Add(cell);
  1593. }
  1594. }
  1595. }
  1596. dgvr.DefaultCellStyle.BackColor = CurrentColor;
  1597. this.Rows.Add(dgvr);
  1598. }
  1599. this.IsCompleteBonding = true;
  1600. }
  1601. public new void DataSource( DataColumnCollection DataColumns )
  1602. {
  1603. this.IsCompleteBonding = false;
  1604. this.Rows.Clear();
  1605. this.DataColumns(DataColumns, this.dgvFixedHideColumn.Trim());
  1606. List<string> listContainsNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
  1607. Color CurrentColor = this.DataGridViewRowsBackColor_Single();
  1608. }
  1609. /// <summary>
  1610. /// 数据绑定(通常用于订单流程的绑定)
  1611. /// </summary>
  1612. /// <param name="dt"></param>
  1613. /// <param name="StrColumnValueNull"></param>
  1614. /// <param name="strHideField"></param>
  1615. public new void DataSource(DataTable dt, DataTable remarkDt, string StrSecondStageNull)
  1616. {
  1617. if (remarkDt != null)
  1618. {
  1619. _SignRemark = remarkDt;
  1620. }
  1621. UseVirtualMode(dt, StrSecondStageNull);
  1622. return;
  1623. }
  1624. /// <summary>
  1625. /// 数据绑定(通常用于订单流程的绑定)
  1626. /// </summary>
  1627. /// <param name="dt"></param>
  1628. /// <param name="StrColumnValueNull"></param>
  1629. /// <param name="strHideField"></param>
  1630. public new void DataSource( DataTable dt, string StrSecondStageNull )
  1631. {
  1632. UseVirtualMode(dt, StrSecondStageNull);
  1633. return;
  1634. this.IsCompleteBonding = false;
  1635. this.Rows.Clear();
  1636. this.DataColumns(dt.Columns, this.dgvFixedHideColumn.Trim());
  1637. DataGridViewRow dgvr = null;
  1638. DataGridViewCell cell = null;
  1639. List<string> listContainsNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
  1640. List<string> listSecondStageNullColumn = new List<string>(StrSecondStageNull.Split(','));
  1641. Color CurrentColor = this.DataGridViewRowsBackColor_Single();
  1642. for ( int i = 0; i < dt.Rows.Count; i++ )
  1643. {
  1644. dgvr = new DataGridViewRow();
  1645. dgvr.Height = 25;
  1646. if ( i == 0 )
  1647. {
  1648. CurrentColor = this.DataGridViewRowsBackColor_Single();
  1649. for ( int j = 0; j < this.Columns.Count; j++ )
  1650. {
  1651. cell = new DataGridViewTextBoxCell();
  1652. cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
  1653. dgvr.Cells.Add(cell);
  1654. }
  1655. }
  1656. else
  1657. {
  1658. if ( dt.Rows[i]["Ord_Number"].Equals(dt.Rows[i - 1]["Ord_Number"]) )
  1659. {
  1660. for ( int j = 0; j < this.Columns.Count; j++ )
  1661. {
  1662. cell = new DataGridViewTextBoxCell();
  1663. if ( listContainsNullColumn.Contains(this.Columns[j].Name.Trim()) )
  1664. {
  1665. cell.Value = "";
  1666. }
  1667. else
  1668. {
  1669. bool IsFind = false;
  1670. if ( dt.Columns.Contains("拍摄名称") )
  1671. {
  1672. if ( dt.Rows[i]["拍摄名称"].Equals(dt.Rows[i - 1]["拍摄名称"]) )
  1673. {
  1674. IsFind = listSecondStageNullColumn.Contains(this.Columns[j].Name.Trim());
  1675. }
  1676. }
  1677. if ( IsFind )
  1678. {
  1679. cell.Value = "";
  1680. }
  1681. else
  1682. {
  1683. cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
  1684. }
  1685. }
  1686. dgvr.Cells.Add(cell);
  1687. }
  1688. }
  1689. else
  1690. {
  1691. if ( CurrentColor == this.DataGridViewRowsBackColor_Single() )
  1692. {
  1693. CurrentColor = this.DataGridViewRowsBackColor_Double();
  1694. }
  1695. else
  1696. {
  1697. CurrentColor = this.DataGridViewRowsBackColor_Single();
  1698. }
  1699. for ( int j = 0; j < this.Columns.Count; j++ )
  1700. {
  1701. cell = new DataGridViewTextBoxCell();
  1702. cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
  1703. dgvr.Cells.Add(cell);
  1704. }
  1705. }
  1706. }
  1707. dgvr.DefaultCellStyle.BackColor = CurrentColor;
  1708. this.Rows.Add(dgvr);
  1709. }
  1710. this.IsCompleteBonding = true;
  1711. }
  1712. #region ############------------------------ VirtualMode模式 ------------------------############
  1713. // 数据绑定的类型;
  1714. int nBindingDataType = 0;
  1715. // 最多显示数据集的前xxx行;
  1716. int nDataSourceTopCount = 0;
  1717. // 数据集;
  1718. public DataTable _dataTable = new DataTable();
  1719. /// <summary>
  1720. /// 订单备注标记
  1721. /// </summary>
  1722. DataTable _SignRemark = new DataTable();
  1723. // 当多行订单号相同时, 第一行以外其他行不显示的列字段;
  1724. List<string> _listNullColumn = new List<string>();
  1725. //
  1726. List<string> _listSecondStageNullColumn = new List<string>();
  1727. /// <summary>
  1728. /// 初始化列头字段;
  1729. /// </summary>
  1730. /// <param name="strColumns"></param>
  1731. /// <param name="strHideField"></param>
  1732. public void InitColumns( string strColumns /*逗号分隔*/, string strHideFields = ""/*逗号分隔*/)
  1733. {
  1734. DataGridViewTextBoxColumn column = null;
  1735. if ( !string.IsNullOrEmpty(strColumns) )
  1736. {
  1737. // 有必须的话, 清空之前的列头信息;
  1738. this.Rows.Clear();
  1739. this.Columns.Clear();
  1740. this.IsCompleteBonding = false;
  1741. List<string> listColumns = strColumns.Split(',').ToList();
  1742. List<string> listHideFields = strHideFields.Split(',').ToList();
  1743. for ( int i = 0; i < listColumns.Count; i++ )
  1744. {
  1745. column = new DataGridViewTextBoxColumn();
  1746. column.ReadOnly = true;
  1747. column.Name = listColumns[i].Trim();
  1748. column.HeaderText = listColumns[i].Trim();
  1749. // 是否有隐藏列;
  1750. if ( listHideFields.Contains(listColumns[i].Trim()) )
  1751. column.Visible = false;
  1752. // 是否排序;
  1753. if ( this.IsSortMode )
  1754. column.SortMode = DataGridViewColumnSortMode.Automatic;
  1755. this.Columns.Add(column);
  1756. }
  1757. this.ColumnHeadersHeight = this.dgvColumnHeadersHeight;
  1758. this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  1759. this.IsCompleteBonding = true;
  1760. }
  1761. }
  1762. public void UseVirtualMode( DataTable dataTable )
  1763. {
  1764. try
  1765. {
  1766. Debug.Write("\n虚拟模式0\n");
  1767. // 参数校验;
  1768. if ( dataTable == null /*|| dataTable.Rows.Count == 0*/)
  1769. return;
  1770. // 清空之前的列和行;
  1771. if ( _dataTable != null )
  1772. _dataTable = null;
  1773. this.Rows.Clear();
  1774. this.Columns.Clear();
  1775. // 保存数据集;
  1776. _dataTable = dataTable;
  1777. // 绑定列(注:绑定列,必须在Virtual=true之前);
  1778. this.DataColumns(_dataTable.Columns, this.dgvFixedHideColumn.Trim());
  1779. // 开启虚拟模式;
  1780. this.VirtualMode = true;
  1781. // 设置总行数;
  1782. this.RowCount = _dataTable.Rows.Count;
  1783. // 获取同订单不显示的列字段;
  1784. _listNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
  1785. // 设置类型;
  1786. nBindingDataType = 0;
  1787. // 绑定单元格显示事件;
  1788. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded0;
  1789. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded1;
  1790. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded2;
  1791. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded3;
  1792. this.CellValueNeeded += DataGridViewEc_CellValueNeeded0;
  1793. }
  1794. catch ( Exception e )
  1795. {
  1796. }
  1797. }
  1798. public void UseVirtualMode(DataTable dataTable, DataTable remarkDt, string strSecondStageNull)
  1799. {
  1800. if(remarkDt!=null)
  1801. {
  1802. _SignRemark = remarkDt;
  1803. }
  1804. UseVirtualMode(dataTable, strSecondStageNull);
  1805. }
  1806. public void UseVirtualMode( DataTable dataTable, string strSecondStageNull )
  1807. {
  1808. try
  1809. {
  1810. Debug.Write("\n虚拟模式1\n");
  1811. // 参数校验;
  1812. if ( dataTable == null /*|| dataTable.Rows.Count == 0*/)
  1813. return;
  1814. // 清空之前的列和行;
  1815. if ( _dataTable != null )
  1816. _dataTable = null;
  1817. this.Rows.Clear();
  1818. this.Columns.Clear();
  1819. // 保存数据集;
  1820. _dataTable = dataTable;
  1821. // 绑定列(注:绑定列,必须在Virtual=true之前);
  1822. this.DataColumns(_dataTable.Columns, this.dgvFixedHideColumn.Trim());
  1823. // 开启虚拟模式;
  1824. this.VirtualMode = true;
  1825. // 设置总行数;
  1826. this.RowCount = _dataTable.Rows.Count;
  1827. // 获取同订单不显示的列字段;
  1828. _listNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
  1829. _listSecondStageNullColumn = new List<string>(StrSecondStageNull.Split(','));
  1830. // 设置类型;
  1831. nBindingDataType = 1;
  1832. // 绑定单元格显示事件;
  1833. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded0;
  1834. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded1;
  1835. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded2;
  1836. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded3;
  1837. this.CellValueNeeded += DataGridViewEc_CellValueNeeded1;
  1838. }
  1839. catch ( Exception e )
  1840. {
  1841. }
  1842. }
  1843. public void UseVirtualMode( DataTable dataTable, string strHideField = "", bool IsBindColumns = true, string ColumnAsName = "", bool IsClearRows = true, int DataSourceTopCount = -1 )
  1844. {
  1845. try
  1846. {
  1847. Debug.Write("\n虚拟模式2\n");
  1848. // 参数校验;
  1849. if ( dataTable == null /*|| dataTable.Rows.Count == 0*/)
  1850. return;
  1851. // 清空之前的列和行;
  1852. if ( _dataTable != null )
  1853. _dataTable = null;
  1854. this.Rows.Clear();
  1855. if ( IsBindColumns )
  1856. this.Columns.Clear();
  1857. // 保存数据集;
  1858. _dataTable = dataTable;
  1859. // 初始化列(绑定列(注:绑定列,必须在Virtual=true之前));
  1860. if ( IsBindColumns )
  1861. {
  1862. if ( !string.IsNullOrEmpty(ColumnAsName) )
  1863. this.InitColumns(ColumnAsName, strHideFields: strHideField);
  1864. else
  1865. this.DataColumns(_dataTable.Columns, strHideField: strHideField);
  1866. }
  1867. // 开启虚拟模式;
  1868. this.VirtualMode = true;
  1869. // 设置总行数;
  1870. this.RowCount = _dataTable.Rows.Count;
  1871. // 获取同订单不显示的列字段;
  1872. _listNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
  1873. _listSecondStageNullColumn = new List<string>(StrSecondStageNull.Split(','));
  1874. // 设置类型;
  1875. nBindingDataType = 2;
  1876. // 显示行数;
  1877. nDataSourceTopCount = DataSourceTopCount;
  1878. if ( DataSourceTopCount == -1 )
  1879. nDataSourceTopCount = _dataTable.Rows.Count;
  1880. // 绑定单元格显示事件;
  1881. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded0;
  1882. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded1;
  1883. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded2;
  1884. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded3;
  1885. this.CellValueNeeded += DataGridViewEc_CellValueNeeded2;
  1886. }
  1887. catch ( Exception e )
  1888. {
  1889. }
  1890. }
  1891. public void UseVirtualMode( DataTable dataTable, bool IsClearRows = false )
  1892. {
  1893. try
  1894. {
  1895. Debug.Write("\n虚拟模式3\n");
  1896. // 参数校验;
  1897. if ( dataTable == null /*|| dataTable.Rows.Count == 0*/ )
  1898. return;
  1899. // 清空之前的行;
  1900. if ( _dataTable != null )
  1901. _dataTable = null;
  1902. if ( IsClearRows )
  1903. this.Rows.Clear();
  1904. // 保存数据集;
  1905. _dataTable = dataTable;
  1906. // 开启虚拟模式;
  1907. this.VirtualMode = true;
  1908. // 设置总行数;
  1909. this.RowCount = _dataTable.Rows.Count;
  1910. // 设置类型;
  1911. nBindingDataType = 3;
  1912. // 绑定单元格显示事件;
  1913. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded0;
  1914. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded1;
  1915. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded2;
  1916. this.CellValueNeeded -= DataGridViewEc_CellValueNeeded3;
  1917. this.CellValueNeeded += DataGridViewEc_CellValueNeeded3;
  1918. }
  1919. catch ( Exception e )
  1920. {
  1921. }
  1922. }
  1923. /// <summary>
  1924. /// 设置备注便签描述
  1925. /// </summary>
  1926. /// <param name="dgrCurrent"></param>
  1927. private void SetDataRowSign(DataGridViewRow dgrCurrent,int RowIndex)
  1928. {
  1929. if (this.Columns.Contains("Ordv_ViceNumber") && this._SignRemark.Rows.Count > 0)
  1930. {
  1931. if (dgrCurrent.Tag == null)
  1932. {
  1933. List<DataRow> drSignRemarks = this._SignRemark.AsEnumerable().Where(p => p.Field<string>("Ordrr_ViceNumber") == _dataTable.Rows[RowIndex]["Ordv_ViceNumber"].ToString()).ToList();
  1934. if (drSignRemarks.Count > 0)
  1935. {
  1936. dgrCurrent.Tag = "Sign";
  1937. }
  1938. }
  1939. }
  1940. }
  1941. // 事件0;
  1942. private void DataGridViewEc_CellValueNeeded0( object sender, DataGridViewCellValueEventArgs e )
  1943. {
  1944. // 参数校验;
  1945. if ( _dataTable == null || _dataTable.Rows.Count == 0 || _dataTable.Rows.Count == e.RowIndex )
  1946. return;
  1947. // 当前行;
  1948. DataGridViewRow dgrCurrent = this.Rows[e.RowIndex];
  1949. SetDataRowSign(dgrCurrent,e.RowIndex);
  1950. // 设置行高;
  1951. //dgrCurrent.Height = 25;
  1952. if ( e.RowIndex != 0 && _dataTable.Rows[e.RowIndex]["Ord_Number"].Equals(_dataTable.Rows[e.RowIndex - 1]["Ord_Number"]) )
  1953. {// 同一订单的;
  1954. // 上一行颜色;
  1955. DataGridViewRow dgrLast = this.Rows[e.RowIndex - 1];
  1956. if ( dgrCurrent.DefaultCellStyle.BackColor != dgrLast.DefaultCellStyle.BackColor )
  1957. dgrCurrent.DefaultCellStyle.BackColor = dgrLast.DefaultCellStyle.BackColor;
  1958. // 如果是不显示的列字段, 退出;
  1959. if ( _listNullColumn.Contains(this.Columns[e.ColumnIndex].Name.Trim()) )
  1960. return;
  1961. if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
  1962. e.Value = _dataTable.Rows[e.RowIndex][this.Columns[e.ColumnIndex].Name.Trim()].ToString();
  1963. }
  1964. else
  1965. {// 下一订单的;
  1966. if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
  1967. e.Value = _dataTable.Rows[e.RowIndex][this.Columns[e.ColumnIndex].Name.Trim()].ToString();
  1968. Color checkColor = System.Drawing.Color.YellowGreen;
  1969. if (this.Columns.Contains("ord_AutoColor"))
  1970. {
  1971. if(dgrCurrent.Tag != null)
  1972. {
  1973. dynamic dyObj = dgrCurrent.Tag;
  1974. checkColor = Color.FromArgb(Convert.ToInt32(dyObj.A), Convert.ToInt32(dyObj.R), Convert.ToInt32(dyObj.G), Convert.ToInt32(dyObj.B));
  1975. }
  1976. }
  1977. // 如果是黄色, 直接退出(外部着色);
  1978. if ( dgrCurrent.DefaultCellStyle.BackColor == checkColor)
  1979. return;
  1980. // 订单行是否更色;
  1981. if ( e.RowIndex != 0 )
  1982. {// 非第一行;
  1983. DataGridViewRow dgrLast = this.Rows[e.RowIndex - 1];
  1984. if ( dgrLast.DefaultCellStyle.BackColor == System.Drawing.Color.PowderBlue )
  1985. dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PapayaWhip;
  1986. else
  1987. dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
  1988. }
  1989. else
  1990. {// 第一行时;
  1991. dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
  1992. }
  1993. // 如果包含"欠款"字段,变色;
  1994. if ( this.Columns.Contains("欠款") )
  1995. {
  1996. if (!string.IsNullOrEmpty(Convert.ToString(e.Value)))
  1997. {
  1998. if (this.Columns[e.ColumnIndex].Name.Trim() == "欠款" && Convert.ToDecimal(e.Value) > 0)
  1999. dgrCurrent.DefaultCellStyle.ForeColor = Color.Red;
  2000. }
  2001. }
  2002. }
  2003. // 如果包含'重拍'字段,变色;
  2004. if ( this.Columns.Contains("Ord_Class") )
  2005. {
  2006. if ( this.Columns[e.ColumnIndex].Name.Trim().ToLower() == "ord_class" && e.Value.ToString().Trim() == "0" )
  2007. dgrCurrent.DefaultCellStyle.ForeColor = Color.Red;
  2008. }
  2009. // 如果包含'重拍'字段,变色;
  2010. if ( this.Columns.Contains("拍摄状态") )
  2011. {
  2012. if ( this.Columns[e.ColumnIndex].Name.Trim() == "拍摄状态" && e.Value.ToString().Trim() == "重拍" )
  2013. dgrCurrent.DefaultCellStyle.ForeColor = Color.Coral;
  2014. }
  2015. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherPermissionsSet, LYFZ.CustomAttributes.OperatingAuthority.ProhibitViewCustomerPhoneNumber) && !LYFZ.BLL.BLL_ErpUser.IsAdministrator() && DataGridViewEx.HidePhoneCellsNameList.Count > 0)
  2016. {
  2017. try
  2018. {
  2019. foreach (string HidePhoneCellsName in HidePhoneFindList)
  2020. {
  2021. if (this.Columns[e.ColumnIndex].Name.Contains(HidePhoneCellsName))
  2022. {
  2023. //e. = this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value;
  2024. //_dataTable.Rows[e.RowIndex][HidePhoneCellsName] = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
  2025. e.Value = LYFZ.Command.Command_Validate.HidePhone(e.Value);
  2026. }
  2027. }
  2028. }
  2029. catch (Exception ex) { }
  2030. }
  2031. }
  2032. // 事件1;
  2033. private void DataGridViewEc_CellValueNeeded1( object sender, DataGridViewCellValueEventArgs e )
  2034. {
  2035. // 参数校验;
  2036. if ( _dataTable == null || _dataTable.Rows.Count == 0 || _dataTable.Rows.Count == e.RowIndex )
  2037. return;
  2038. // 当前行;
  2039. DataGridViewRow dgrCurrent = this.Rows[e.RowIndex];
  2040. SetDataRowSign(dgrCurrent, e.RowIndex);
  2041. // 设置行高;
  2042. //dgrCurrent.Height = 25;
  2043. if ( e.RowIndex != 0 && _dataTable.Rows[e.RowIndex]["Ord_Number"].Equals(_dataTable.Rows[e.RowIndex - 1]["Ord_Number"]) )
  2044. {// 同一订单的;
  2045. // 上一行颜色;
  2046. DataGridViewRow dgrLast = this.Rows[e.RowIndex - 1];
  2047. if ( dgrCurrent.DefaultCellStyle.BackColor.IsEmpty )
  2048. dgrCurrent.DefaultCellStyle.BackColor = dgrLast.DefaultCellStyle.BackColor;
  2049. // 如果是不显示的列字段, 退出;
  2050. if ( _listNullColumn.Contains(this.Columns[e.ColumnIndex].Name.Trim()) )
  2051. return;
  2052. if ( _dataTable.Columns.Contains("拍摄名称") &&
  2053. _dataTable.Rows[e.RowIndex]["拍摄名称"].Equals(_dataTable.Rows[e.RowIndex - 1]["拍摄名称"]) &&
  2054. _listSecondStageNullColumn.Contains(this.Columns[e.ColumnIndex].Name.Trim()) )
  2055. {
  2056. return;
  2057. }
  2058. if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
  2059. e.Value = _dataTable.Rows[e.RowIndex][this.Columns[e.ColumnIndex].Name.Trim()].ToString();
  2060. }
  2061. else
  2062. {// 下一订单的;
  2063. if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
  2064. e.Value = _dataTable.Rows[e.RowIndex][this.Columns[e.ColumnIndex].Name.Trim()].ToString();
  2065. // 订单行是否更色;
  2066. if ( e.RowIndex != 0 )
  2067. {// 非第一行;
  2068. DataGridViewRow dgrLast = this.Rows[e.RowIndex - 1];
  2069. if ( dgrLast.DefaultCellStyle.BackColor == System.Drawing.Color.PowderBlue )
  2070. dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PapayaWhip;
  2071. else
  2072. dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
  2073. }
  2074. else
  2075. {// 第一行时;
  2076. dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
  2077. }
  2078. // 如果包含"欠款"字段,变色并且保留两位小数;
  2079. if ( this.Columns.Contains("欠款") )
  2080. {
  2081. if ( this.Columns[e.ColumnIndex].Name.Trim() == "欠款" )
  2082. {
  2083. e.Value = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(e.Value);
  2084. // 欠款红色;
  2085. if ( Convert.ToDecimal(e.Value) > 0 )
  2086. dgrCurrent.DefaultCellStyle.ForeColor = Color.Red;
  2087. }
  2088. }
  2089. // 如果包含"加挑金额"字段,保留两位小数;
  2090. if ( this.Columns.Contains("加挑金额") )
  2091. {
  2092. if ( this.Columns[e.ColumnIndex].Name.Trim() == "加挑金额" )
  2093. e.Value = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(e.Value);
  2094. }
  2095. }
  2096. if (this.Columns.Contains("ord_AutoColor"))
  2097. {
  2098. if (dgrCurrent.Tag != null)
  2099. {
  2100. dynamic dyObj = dgrCurrent.Tag;
  2101. Color checkColor = Color.FromArgb(Convert.ToInt32(dyObj.A), Convert.ToInt32(dyObj.R), Convert.ToInt32(dyObj.G), Convert.ToInt32(dyObj.B));
  2102. dgrCurrent.DefaultCellStyle.BackColor = checkColor;
  2103. }
  2104. }
  2105. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherPermissionsSet, LYFZ.CustomAttributes.OperatingAuthority.ProhibitViewCustomerPhoneNumber) && !LYFZ.BLL.BLL_ErpUser.IsAdministrator() && DataGridViewEx.HidePhoneCellsNameList.Count > 0)
  2106. {
  2107. try
  2108. {
  2109. foreach (string HidePhoneCellsName in HidePhoneFindList)
  2110. {
  2111. if (this.Columns[e.ColumnIndex].Name.Contains(HidePhoneCellsName))
  2112. {
  2113. //e. = this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value;
  2114. //_dataTable.Rows[e.RowIndex][HidePhoneCellsName] = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
  2115. e.Value = LYFZ.Command.Command_Validate.HidePhone(e.Value);
  2116. }
  2117. }
  2118. }
  2119. catch (Exception ex) { }
  2120. }
  2121. }
  2122. // 事件2;
  2123. private void DataGridViewEc_CellValueNeeded2( object sender, DataGridViewCellValueEventArgs e )
  2124. {
  2125. // 参数校验;
  2126. if ( _dataTable == null ||
  2127. _dataTable.Rows.Count == 0 ||
  2128. _dataTable.Rows.Count == e.RowIndex ||
  2129. e.RowIndex > nDataSourceTopCount )
  2130. return;
  2131. if(e.Value==null)
  2132. {
  2133. e.Value = "";
  2134. }
  2135. // 当前行;
  2136. DataGridViewRow dgrCurrent = this.Rows[e.RowIndex];
  2137. SetDataRowSign(dgrCurrent, e.RowIndex);
  2138. if ( dgrCurrent.DefaultCellStyle.BackColor.IsEmpty )
  2139. dgrCurrent.DefaultCellStyle.BackColor = (e.RowIndex % 2 == 0) ? System.Drawing.Color.PapayaWhip : System.Drawing.Color.PowderBlue;
  2140. // StrIsAddColumnsNull不是_dataTable中的列,是手动加进去的(何意义??);
  2141. if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
  2142. e.Value = _dataTable.Rows[e.RowIndex][_dataTable.Columns[e.ColumnIndex].ToString().Trim()].ToString();
  2143. // 如果包含"欠款"字段,变色;
  2144. if ( this.Columns.Contains("欠款") )
  2145. {
  2146. if ( this.Columns[e.ColumnIndex].Name.Trim() == "欠款" && Convert.ToDecimal(e.Value) > 0 )
  2147. dgrCurrent.DefaultCellStyle.ForeColor = Color.Red;
  2148. }
  2149. // 如果是医院跟踪系统,处理以下内容;
  2150. if ( this.Columns.Contains("生日类型") && this.Columns.Contains("宝宝性别") )
  2151. {
  2152. if ( this.Columns[e.ColumnIndex].Name.Trim() == "生日类型" && e.Value.ToString() == "预产期" )
  2153. dgrCurrent.Cells["宝宝性别"].Value = "";
  2154. }
  2155. if (this.Columns.Contains("ord_AutoColor"))
  2156. {
  2157. if (this.Columns[e.ColumnIndex].Name.Trim() == "ord_AutoColor" && e.Value != null && e.Value.ToString().Trim() != "")
  2158. {
  2159. dynamic dyObj = JsonConvert.DeserializeObject(e.Value.ToString().Trim());
  2160. dgrCurrent.DefaultCellStyle.BackColor = Color.FromArgb(Convert.ToInt32(dyObj.A), Convert.ToInt32(dyObj.R), Convert.ToInt32(dyObj.G), Convert.ToInt32(dyObj.B));
  2161. }
  2162. }
  2163. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherPermissionsSet, LYFZ.CustomAttributes.OperatingAuthority.ProhibitViewCustomerPhoneNumber) && !LYFZ.BLL.BLL_ErpUser.IsAdministrator() && DataGridViewEx.HidePhoneCellsNameList.Count > 0)
  2164. {
  2165. try
  2166. {
  2167. foreach (string HidePhoneCellsName in HidePhoneFindList)
  2168. {
  2169. if (this.Columns[e.ColumnIndex].Name.Contains(HidePhoneCellsName))
  2170. {
  2171. //e. = this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value;
  2172. //_dataTable.Rows[e.RowIndex][HidePhoneCellsName] = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
  2173. e.Value = LYFZ.Command.Command_Validate.HidePhone(e.Value);
  2174. }
  2175. }
  2176. }
  2177. catch (Exception ex) { }
  2178. }
  2179. }
  2180. // 事件3;
  2181. private void DataGridViewEc_CellValueNeeded3( object sender, DataGridViewCellValueEventArgs e )
  2182. {
  2183. // 参数校验;
  2184. if ( _dataTable == null || _dataTable.Rows.Count == 0 || _dataTable.Rows.Count == e.RowIndex )
  2185. return;
  2186. // 当前行;
  2187. DataGridViewRow dgrCurrent = this.Rows[e.RowIndex];
  2188. SetDataRowSign(dgrCurrent, e.RowIndex);
  2189. if ( dgrCurrent.DefaultCellStyle.BackColor.IsEmpty )
  2190. dgrCurrent.DefaultCellStyle.BackColor = (e.RowIndex % 2 == 0) ? System.Drawing.Color.PapayaWhip : System.Drawing.Color.PowderBlue;
  2191. // StrIsAddColumnsNull不是_dataTable中的列,是手动加进去的(何意义??);
  2192. if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
  2193. e.Value = _dataTable.Rows[e.RowIndex][e.ColumnIndex];
  2194. if (this.Columns.Contains("ord_AutoColor"))
  2195. {
  2196. if (this.Columns[e.ColumnIndex].Name.Trim() == "ord_AutoColor" && e.Value != null && e.Value.ToString().Trim() != "")
  2197. {
  2198. dynamic dyObj = JsonConvert.DeserializeObject(e.Value.ToString().Trim());
  2199. dgrCurrent.DefaultCellStyle.BackColor = Color.FromArgb(Convert.ToInt32(dyObj.A), Convert.ToInt32(dyObj.R), Convert.ToInt32(dyObj.G), Convert.ToInt32(dyObj.B));
  2200. }
  2201. }
  2202. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherPermissionsSet, LYFZ.CustomAttributes.OperatingAuthority.ProhibitViewCustomerPhoneNumber) && !LYFZ.BLL.BLL_ErpUser.IsAdministrator() && DataGridViewEx.HidePhoneCellsNameList.Count > 0)
  2203. {
  2204. try
  2205. {
  2206. foreach (string HidePhoneCellsName in HidePhoneFindList)
  2207. {
  2208. if (this.Columns[e.ColumnIndex].Name.Contains(HidePhoneCellsName))
  2209. {
  2210. //e. = this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value;
  2211. //_dataTable.Rows[e.RowIndex][HidePhoneCellsName] = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
  2212. e.Value = LYFZ.Command.Command_Validate.HidePhone(e.Value);
  2213. }
  2214. }
  2215. }
  2216. catch (Exception ex) { }
  2217. }
  2218. }
  2219. #endregion
  2220. /// <summary>
  2221. /// 获取固定指定为空的数据
  2222. /// </summary>
  2223. /// <param name="strColumnName"></param>
  2224. /// <param name="strRowsValue"></param>
  2225. /// <returns></returns>
  2226. public string GetRowsValue( string strColumnName, string strRowsValue )
  2227. {
  2228. switch ( strColumnName )
  2229. {
  2230. case "客户姓名":
  2231. case "客户性别":
  2232. case "客户电话":
  2233. strRowsValue = Convert.ToString("");
  2234. break;
  2235. }
  2236. return strRowsValue;
  2237. }
  2238. #region 老客户绑定
  2239. /// <summary>
  2240. /// 老客户绑定
  2241. /// </summary>
  2242. /// <param name="dt"></param>
  2243. /// <param name="strHideField"></param>
  2244. public void DataClientSource( DataTable dt, string strHideField = "" )
  2245. {
  2246. try
  2247. {
  2248. this.IsCompleteBonding = false;
  2249. this.Rows.Clear();
  2250. this.DataColumns(dt.Columns, strHideField: strHideField);
  2251. this.DataClientSourceRows(dt);
  2252. this.IsCompleteBonding = true;
  2253. }
  2254. catch
  2255. {
  2256. }
  2257. }
  2258. /// <summary>
  2259. /// 绑定行
  2260. /// </summary>
  2261. public void DataClientSourceRows( DataTable dt, int DataSourceTopCount = -1 )
  2262. {
  2263. // 行的唯一标识
  2264. float RowUniqueMark = 0;
  2265. int forRowCount = dt.Rows.Count;
  2266. if ( DataSourceTopCount != -1 )
  2267. {
  2268. if ( dt.Rows.Count > DataSourceTopCount )
  2269. {
  2270. forRowCount = DataSourceTopCount;
  2271. }
  2272. }
  2273. for ( int i = 0; i < forRowCount; i++ )
  2274. {
  2275. DataGridViewRow dgvr = new DataGridViewRow();
  2276. if ( (RowUniqueMark % 2) > 0 )
  2277. {
  2278. dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Double();
  2279. }
  2280. else
  2281. {
  2282. dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
  2283. }
  2284. dgvr.HeaderCell.Tag = true;
  2285. dgvr.Height = 25;
  2286. DataGridViewCell cell = null;
  2287. for ( int j = 0; j < dt.Columns.Count; j++ )
  2288. {
  2289. cell = new DataGridViewTextBoxCell();
  2290. cell.Value = dt.Rows[i][dt.Columns[j].ToString().Trim()].ToString().Trim();
  2291. dgvr.Cells.Add(cell);
  2292. }
  2293. if ( this.Columns.Contains("Ord_ViceOrderCount") )
  2294. {
  2295. if ( Convert.ToInt32(dt.Rows[i]["Ord_ViceOrderCount"]) > 1 )
  2296. {
  2297. dgvr.HeaderCell.Tag = true;
  2298. dgvr.HeaderCell.Value = i + "_Expand";
  2299. dgvr.HeaderCell.ToolTipText = "点击展开";
  2300. }
  2301. else
  2302. {
  2303. dgvr.HeaderCell.Tag = false;
  2304. dgvr.HeaderCell.Value = i + "_" + "Collapse";
  2305. dgvr.HeaderCell.ToolTipText = "点击折叠";
  2306. }
  2307. }
  2308. this.Rows.Add(dgvr);
  2309. RowUniqueMark++;
  2310. }
  2311. }
  2312. /// <summary>
  2313. /// 老客户绑定子集子数据的绑定
  2314. /// </summary>
  2315. /// <param name="Vicetbl"></param>
  2316. public void DataClientSourceViceRow( DataRow[] dtRow )
  2317. {
  2318. try
  2319. {
  2320. if ( Convert.ToBoolean(this.Rows[CRowsIndex].HeaderCell.Tag) )
  2321. {
  2322. this.DataExpandRows(dtRow);
  2323. }
  2324. else
  2325. {
  2326. this.DataContractRows();
  2327. }
  2328. }
  2329. catch { }
  2330. }
  2331. #endregion
  2332. private bool _isAddNullColumns;
  2333. /// <summary>
  2334. /// false:为用最后一列填充,true:为新增一个空列来填充后面空白
  2335. /// </summary>
  2336. private bool IsAddNullColumns
  2337. {
  2338. get
  2339. {
  2340. return _isAddNullColumns;
  2341. }
  2342. set
  2343. {
  2344. _isAddNullColumns = value;
  2345. }
  2346. }
  2347. /// <summary>
  2348. /// 填充最后列的列名
  2349. /// </summary>
  2350. public string FillColumnsNullName = "StrIsAddColumnsNull";
  2351. /// <summary>
  2352. /// 填充最后列
  2353. /// </summary>
  2354. /// <param name="isAddNullColumns">false:为用最后一列填充,true:为新增一个空列来填充后面空白</param>
  2355. public void FillLastColumn( bool isAddNullColumns = false )
  2356. {
  2357. if ( this.Columns.Count > 0 )
  2358. {
  2359. this.IsAddNullColumns = isAddNullColumns;
  2360. if ( !isAddNullColumns )
  2361. {
  2362. int dgvWidth = 0;
  2363. for ( int i = 0; i < this.Columns.Count; i++ )
  2364. {
  2365. if ( this.Columns[i].Visible )
  2366. {
  2367. dgvWidth += this.Columns[i].Width;
  2368. }
  2369. }
  2370. if ( dgvWidth < this.Width )
  2371. {
  2372. if ( this.RowHeadersVisible )
  2373. {
  2374. dgvWidth += this.RowHeadersWidth;
  2375. }
  2376. this.Columns[this.Columns.Count - 1].Width = this.Width - dgvWidth + this.Columns[this.Columns.Count - 1].Width - 5;
  2377. }
  2378. else
  2379. {
  2380. this.Columns[this.Columns.Count - 1].Width = 100;
  2381. }
  2382. }
  2383. else
  2384. {
  2385. bool IsFind = true;
  2386. for ( int i = 0; i < this.Columns.Count; i++ )
  2387. {
  2388. if ( this.Columns[i].Name.Trim() == FillColumnsNullName )
  2389. {
  2390. IsFind = false;
  2391. break;
  2392. }
  2393. }
  2394. if ( IsFind )
  2395. {
  2396. DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
  2397. column.ReadOnly = true;
  2398. column.Name = FillColumnsNullName;
  2399. column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
  2400. column.HeaderText = "";
  2401. this.Columns.Add(column);
  2402. }
  2403. }
  2404. }
  2405. }
  2406. #endregion
  2407. #region 列标头点击解发事件事件
  2408. /// <summary>
  2409. /// 申明委托
  2410. /// </summary>
  2411. /// <param name="e"></param>
  2412. /// <returns></returns>
  2413. public delegate void EventExpandCollapseHandler( EventExpandCollapse e );
  2414. /// <summary>
  2415. /// PrintSingle事件
  2416. /// </summary>
  2417. public event EventExpandCollapseHandler EventRowExpandCollapse;
  2418. /// <summary>
  2419. /// EventSelectPhotoPrint 选片打开事件对象
  2420. /// </summary>
  2421. public class EventExpandCollapse : EventArgs
  2422. {
  2423. bool _expandOrCollapse = true;
  2424. /// <summary>
  2425. /// true为展开 false 为折叠
  2426. /// </summary>
  2427. public bool ExpandOrCollapse
  2428. {
  2429. get
  2430. {
  2431. return _expandOrCollapse;
  2432. }
  2433. set
  2434. {
  2435. _expandOrCollapse = value;
  2436. }
  2437. }
  2438. DataGridViewCellMouseEventArgs onRowHeaderMouseClick;
  2439. public DataGridViewCellMouseEventArgs OnRowHeaderMouseClick
  2440. {
  2441. get
  2442. {
  2443. return onRowHeaderMouseClick;
  2444. }
  2445. set
  2446. {
  2447. onRowHeaderMouseClick = value;
  2448. }
  2449. }
  2450. DataGridViewRowCollection cRows;
  2451. /// <summary>
  2452. /// 当前行
  2453. /// </summary>
  2454. public DataGridViewRowCollection CRows
  2455. {
  2456. get
  2457. {
  2458. return cRows;
  2459. }
  2460. set
  2461. {
  2462. cRows = value;
  2463. }
  2464. }
  2465. public EventExpandCollapse()
  2466. {
  2467. }
  2468. }
  2469. #endregion
  2470. /// <summary>
  2471. /// 导出数据
  2472. /// </summary>
  2473. public void ExportDataTable( string StrFileName = "" )
  2474. {
  2475. DataTable NewTable = this.ToDataTable();
  2476. SaveFileDialog saveFile = new SaveFileDialog();
  2477. saveFile.FileName = StrFileName;
  2478. saveFile.Title = "导出数据报表文件";
  2479. saveFile.Filter = "EXECL文件(*.xls) |*.xls |文本文件(*.txt) |*.txt |所有文件(*.*) |*.*";
  2480. saveFile.FilterIndex = 1;
  2481. DialogResult drst = saveFile.ShowDialog();
  2482. if ( drst == DialogResult.No || drst == DialogResult.Cancel || drst == DialogResult.No || drst == DialogResult.Abort )
  2483. {
  2484. return;
  2485. }
  2486. LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  2487. {
  2488. try
  2489. {
  2490. if (LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(saveFile.FileName.Trim(), NewTable, null, backgroundWorker))
  2491. {
  2492. MessageBoxCustom.Show("数据导出成功!");
  2493. }
  2494. else
  2495. {
  2496. MessageBoxCustom.Show("数据导出失败!");
  2497. }
  2498. }
  2499. catch (Exception ex)
  2500. {
  2501. MessageBoxCustom.Show(String.Format("导出数据出错:{0}", ex.Message));
  2502. }
  2503. });
  2504. //if ( LYFZ.Command.Command_ExportExcel.DataTable2Sheet(saveFile.FileName.Trim(), NewTable, "Sheet1", IsCoveredExistingFile: true) )
  2505. //{
  2506. // MessageBoxCustom.Show("导出成功!");
  2507. //}
  2508. //else
  2509. //{
  2510. // MessageBoxCustom.Show("导出失败!");
  2511. //}
  2512. }
  2513. /// <summary>
  2514. /// 导出数据
  2515. /// </summary>
  2516. public void ExportDataTable( DataTable NewTable, string StrFileName = "" )
  2517. {
  2518. SaveFileDialog saveFile = new SaveFileDialog();
  2519. saveFile.FileName = StrFileName;
  2520. saveFile.Title = "导出数据报表文件";
  2521. saveFile.Filter = "EXECL文件(*.xls) |*.xls |文本文件(*.txt) |*.txt |所有文件(*.*) |*.*";
  2522. saveFile.FilterIndex = 1;
  2523. DialogResult drst = saveFile.ShowDialog();
  2524. if ( drst == DialogResult.No || drst == DialogResult.Cancel || drst == DialogResult.No || drst == DialogResult.Abort )
  2525. {
  2526. return;
  2527. }
  2528. LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  2529. {
  2530. try
  2531. {
  2532. if (LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(saveFile.FileName.Trim(), NewTable, null, backgroundWorker))
  2533. {
  2534. MessageBoxCustom.Show("数据导出成功!");
  2535. }
  2536. else
  2537. {
  2538. MessageBoxCustom.Show("数据导出失败!");
  2539. }
  2540. }
  2541. catch (Exception ex)
  2542. {
  2543. MessageBoxCustom.Show(String.Format("导出数据出错:{0}", ex.Message));
  2544. }
  2545. });
  2546. //if ( LYFZ.Command.Command_ExportExcel.DataTable2Sheet(saveFile.FileName.Trim(), NewTable, "Sheet1", IsCoveredExistingFile: true) )
  2547. //{
  2548. // MessageBoxCustom.Show("导出成功!");
  2549. //}
  2550. //else
  2551. //{
  2552. // MessageBoxCustom.Show("导出失败!");
  2553. //}
  2554. }
  2555. /// <summary>
  2556. /// 将本列表数据转成DataTable
  2557. /// </summary>
  2558. public DataTable ToDataTable( bool IsShowVisible = false )
  2559. {
  2560. DataTable NewTable = new DataTable();
  2561. for ( int i = 0; i < this.Columns.Count; i++ )
  2562. {
  2563. if ( !string.IsNullOrEmpty(this.Columns[i].HeaderText.Trim()) )
  2564. {
  2565. if ( !IsShowVisible )
  2566. {
  2567. if ( !this.Columns[i].Visible )
  2568. {
  2569. continue;
  2570. }
  2571. }
  2572. NewTable.Columns.Add(this.Columns[i].HeaderText.Trim(), typeof(string));
  2573. }
  2574. }
  2575. for ( int i = 0; i < this.Rows.Count; i++ )
  2576. {
  2577. DataRow newRow = NewTable.NewRow();
  2578. for ( int j = 0; j < this.Columns.Count; j++ )
  2579. {
  2580. if ( !string.IsNullOrEmpty(this.Columns[j].HeaderText.Trim()) )
  2581. {
  2582. if ( !IsShowVisible )
  2583. {
  2584. if ( !this.Columns[j].Visible )
  2585. {
  2586. continue;
  2587. }
  2588. }
  2589. if ( this.Rows[i].Cells[this.Columns[j].HeaderText.Trim()].Value != null )
  2590. newRow[this.Columns[j].HeaderText.Trim()] = this.Rows[i].Cells[this.Columns[j].HeaderText.Trim()].Value.ToString().Trim();
  2591. }
  2592. }
  2593. NewTable.Rows.Add(newRow);
  2594. }
  2595. return NewTable;
  2596. }
  2597. protected override void CreateHandle()
  2598. {
  2599. if ( !IsHandleCreated )
  2600. {
  2601. try
  2602. {
  2603. base.CreateHandle();
  2604. }
  2605. catch { }
  2606. finally
  2607. {
  2608. if ( !IsHandleCreated )
  2609. {
  2610. base.RecreateHandle();
  2611. }
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }