Module1.cs 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Drawing.Imaging;
  6. using System.Drawing.Printing;
  7. using System.IO;
  8. using System.Runtime.CompilerServices;
  9. using System.Runtime.InteropServices;
  10. using System.Security.Cryptography;
  11. using System.Text;
  12. using System.Windows.Forms;
  13. using Microsoft.VisualBasic;
  14. using Microsoft.VisualBasic.CompilerServices;
  15. namespace Dongke.IBOSS.PRD.Framework.Controls {
  16. [StandardModule]
  17. internal sealed class Module1
  18. {
  19. public const string G_CustomDefinedPaperName = "[自定义纸张]";
  20. public static Ruler G_ruler = new Ruler();
  21. public static bool G_CancelDocument = false;
  22. public static bool G_CancelExportDGVToExcel = false;
  23. public static bool G_CancelPrint = false;
  24. private static byte[] G_mykey = new byte[24]
  25. {
  26. 10, 32, 53, 24, 53, 23, 88, 223, 99, 10,
  27. 33, 62, 64, 76, 68, 98, 13, 131, 93, 33,
  28. 15, 56, 13, 13
  29. };
  30. private static byte[] G_myiv = new byte[8] { 13, 56, 87, 13, 98, 53, 80, 32 };
  31. [DllImport("kernel32", CharSet = CharSet.Ansi, EntryPoint = "GetPrivateProfileStringA", ExactSpelling = true, SetLastError = true)]
  32. private static extern int GetPrivateProfileString([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpApplicationName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpKeyName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpDefault, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpReturnedString, int nSize, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpFileName);
  33. [DllImport("kernel32", CharSet = CharSet.Ansi, EntryPoint = "WritePrivateProfileStringA", ExactSpelling = true, SetLastError = true)]
  34. private static extern int WritePrivateProfileString([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpApplicationName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpKeyName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpString, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpFileName);
  35. public static void CopyTreeView(TreeView s, ref TreeView d, bool isaddrowname)
  36. {
  37. d.Nodes.Clear();
  38. if (s == null)
  39. {
  40. d = null;
  41. return;
  42. }
  43. d.StateImageList = s.StateImageList;
  44. d.ImageList = s.ImageList;
  45. d.ImageIndex = s.ImageIndex;
  46. if (Operators.CompareString(s.ImageKey, "", TextCompare: false) != 0)
  47. {
  48. d.ImageKey = s.ImageKey;
  49. }
  50. d.CheckBoxes = s.CheckBoxes;
  51. d.LineColor = s.LineColor;
  52. d.Font = (Font)s.Font.Clone();
  53. d.ForeColor = s.ForeColor;
  54. int num = 0;
  55. checked
  56. {
  57. int num2 = s.Nodes.Count - 1;
  58. for (int i = num; i <= num2; i++)
  59. {
  60. TreeNode d2 = d.Nodes.Add(s.Nodes[i].Text);
  61. d2.Checked = s.Nodes[i].Checked;
  62. d2.ImageIndex = s.Nodes[i].ImageIndex;
  63. if (Operators.CompareString(s.Nodes[i].ImageKey, "", TextCompare: false) != 0)
  64. {
  65. d2.ImageKey = s.Nodes[i].ImageKey;
  66. }
  67. d2.StateImageIndex = s.Nodes[i].StateImageIndex;
  68. if (Operators.CompareString(s.Nodes[i].StateImageKey, "", TextCompare: false) != 0)
  69. {
  70. d2.StateImageKey = s.Nodes[i].StateImageKey;
  71. }
  72. d2.ForeColor = s.Nodes[i].ForeColor;
  73. d2.BackColor = s.Nodes[i].BackColor;
  74. if (s.Nodes[i].NodeFont != null)
  75. {
  76. d2.NodeFont = (Font)s.Nodes[i].NodeFont.Clone();
  77. }
  78. CopyNodes(s.Nodes[i], ref d2);
  79. }
  80. if (isaddrowname)
  81. {
  82. d.Nodes.Insert(0, "行号");
  83. }
  84. }
  85. }
  86. private static void CopyNodes(TreeNode s, ref TreeNode d)
  87. {
  88. if (s == null)
  89. {
  90. return;
  91. }
  92. int num = 0;
  93. checked
  94. {
  95. int num2 = s.Nodes.Count - 1;
  96. for (int i = num; i <= num2; i++)
  97. {
  98. TreeNode d2 = d.Nodes.Add(s.Nodes[i].Text);
  99. d2.Checked = s.Nodes[i].Checked;
  100. d2.ImageIndex = s.Nodes[i].ImageIndex;
  101. if (Operators.CompareString(s.Nodes[i].ImageKey, "", TextCompare: false) != 0)
  102. {
  103. d2.ImageKey = s.Nodes[i].ImageKey;
  104. }
  105. d2.StateImageIndex = s.Nodes[i].StateImageIndex;
  106. if (Operators.CompareString(s.Nodes[i].StateImageKey, "", TextCompare: false) != 0)
  107. {
  108. d2.StateImageKey = s.Nodes[i].StateImageKey;
  109. }
  110. d2.ForeColor = s.Nodes[i].ForeColor;
  111. d2.BackColor = s.Nodes[i].BackColor;
  112. if (s.Nodes[i].NodeFont != null)
  113. {
  114. d2.NodeFont = (Font)s.Nodes[i].NodeFont.Clone();
  115. }
  116. CopyNodes(s.Nodes[i], ref d2);
  117. }
  118. }
  119. }
  120. public static string GetINI(string Section, string AppName, string lpDefault, string FileName)
  121. {
  122. string source = "";
  123. source = Strings.LSet(source, 256);
  124. GetPrivateProfileString(ref Section, ref AppName, ref lpDefault, ref source, Strings.Len(source), ref FileName);
  125. string expression = Strings.Trim(Strings.Left(source, checked(Strings.InStr(source, "\0") - 1)));
  126. expression = Strings.Replace(expression, "&<br>&", "\r\n");
  127. if (expression == null)
  128. {
  129. expression = "";
  130. }
  131. return expression;
  132. }
  133. public static long WriteINI(string Section, string AppName, string lpDefault, string FileName)
  134. {
  135. lpDefault = Strings.Replace(lpDefault, "\r\n", "&<br>&");
  136. if (lpDefault == null)
  137. {
  138. lpDefault = "";
  139. }
  140. return WritePrivateProfileString(ref Section, ref AppName, ref lpDefault, ref FileName);
  141. }
  142. public static string ConvertFontToString(Font myfont)
  143. {
  144. FontConverter fontConverter = new FontConverter();
  145. return fontConverter.ConvertToString(myfont);
  146. }
  147. public static string ConvertColorToString(Color mycolor)
  148. {
  149. ColorConverter colorConverter = new ColorConverter();
  150. return colorConverter.ConvertToString(mycolor);
  151. }
  152. public static Color ConvertStringToColor(string pp)
  153. {
  154. ColorConverter colorConverter = new ColorConverter();
  155. try
  156. {
  157. object obj = colorConverter.ConvertFromString(pp);
  158. Color black = Color.Black;
  159. return (obj != null) ? ((Color)obj) : black;
  160. }
  161. catch (Exception projectError)
  162. {
  163. ProjectData.SetProjectError(projectError);
  164. Color result = Color.FromArgb(0);
  165. ProjectData.ClearProjectError();
  166. return result;
  167. }
  168. }
  169. public static Font ConvertStringToFont(string pp)
  170. {
  171. FontConverter fontConverter = new FontConverter();
  172. Font result;
  173. if (Operators.CompareString(pp, "(无)", TextCompare: false) == 0)
  174. {
  175. result = null;
  176. }
  177. else
  178. {
  179. try
  180. {
  181. Font font = (Font)fontConverter.ConvertFromString(pp);
  182. result = font;
  183. }
  184. catch (Exception projectError)
  185. {
  186. ProjectData.SetProjectError(projectError);
  187. result = null;
  188. ProjectData.ClearProjectError();
  189. }
  190. }
  191. return result;
  192. }
  193. public static void CopyDataGridView(DataGridView sdv, DataGridView ddv, bool IsAddRowHeaderColumn)
  194. {
  195. CopyDataGridView(sdv, ddv);
  196. if (!IsAddRowHeaderColumn)
  197. {
  198. return;
  199. }
  200. checked
  201. {
  202. try
  203. {
  204. if (ddv.Columns.Count <= 0)
  205. {
  206. return;
  207. }
  208. DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
  209. dataGridViewTextBoxColumn.HeaderCell = (DataGridViewColumnHeaderCell)sdv.TopLeftHeaderCell.Clone();
  210. if (sdv.TopLeftHeaderCell.HasStyle)
  211. {
  212. dataGridViewTextBoxColumn.HeaderCell.Style = sdv.TopLeftHeaderCell.Style.Clone();
  213. }
  214. dataGridViewTextBoxColumn.Width = sdv.RowHeadersWidth;
  215. if (Operators.CompareString(dataGridViewTextBoxColumn.Name ?? "", "", TextCompare: false) == 0)
  216. {
  217. dataGridViewTextBoxColumn.Name = "行标题";
  218. }
  219. dataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
  220. ddv.Columns.Insert(0, dataGridViewTextBoxColumn);
  221. int rowCount = ddv.RowCount;
  222. int num = 0;
  223. int num2 = rowCount - 1;
  224. for (int i = num; i <= num2; i++)
  225. {
  226. ddv.Rows[i].Cells[0].Value = Conversions.ToString(sdv.Rows[i].HeaderCell.FormattedValue) ?? "";
  227. if (sdv.Rows[i].HeaderCell.Style.Font != null)
  228. {
  229. ddv.Rows[i].Cells[0].Style.Font = (Font)sdv.Rows[i].HeaderCell.Style.Font.Clone();
  230. }
  231. else if (sdv.RowHeadersDefaultCellStyle.Font != null)
  232. {
  233. ddv.Rows[i].Cells[0].Style.Font = (Font)sdv.RowHeadersDefaultCellStyle.Font.Clone();
  234. }
  235. if (sdv.Rows[i].HeaderCell.Style.Alignment != 0)
  236. {
  237. ddv.Rows[i].Cells[0].Style.Alignment = sdv.Rows[i].HeaderCell.Style.Alignment;
  238. }
  239. else
  240. {
  241. ddv.Rows[i].Cells[0].Style.Alignment = sdv.RowHeadersDefaultCellStyle.Alignment;
  242. }
  243. if (sdv.Rows[i].HeaderCell.Style.ForeColor.ToArgb() != 0)
  244. {
  245. ddv.Rows[i].Cells[0].Style.ForeColor = sdv.Rows[i].HeaderCell.Style.ForeColor;
  246. }
  247. else if (sdv.RowHeadersDefaultCellStyle.ForeColor.ToArgb() != 0)
  248. {
  249. ddv.Rows[i].Cells[0].Style.ForeColor = sdv.RowHeadersDefaultCellStyle.ForeColor;
  250. }
  251. if (sdv.Rows[i].HeaderCell.Style.BackColor.ToArgb() != 0)
  252. {
  253. ddv.Rows[i].Cells[0].Style.BackColor = sdv.Rows[i].HeaderCell.Style.BackColor;
  254. }
  255. else if (sdv.RowHeadersDefaultCellStyle.BackColor.ToArgb() != 0)
  256. {
  257. ddv.Rows[i].Cells[0].Style.BackColor = sdv.RowHeadersDefaultCellStyle.BackColor;
  258. }
  259. if (sdv.Rows[i].HeaderCell.Style.WrapMode != 0)
  260. {
  261. ddv.Rows[i].Cells[0].Style.WrapMode = sdv.Rows[i].HeaderCell.Style.WrapMode;
  262. }
  263. else if (sdv.RowHeadersDefaultCellStyle.WrapMode != 0)
  264. {
  265. ddv.Rows[i].Cells[0].Style.WrapMode = sdv.RowHeadersDefaultCellStyle.WrapMode;
  266. }
  267. }
  268. }
  269. catch (Exception projectError)
  270. {
  271. ProjectData.SetProjectError(projectError);
  272. ProjectData.ClearProjectError();
  273. }
  274. }
  275. }
  276. public static void CopyDataGridViewShowStatus(DataGridView sdv, DataGridView ddv, bool isprintrowheadercolumn)
  277. {
  278. progress2 progress3 = new progress2();
  279. progress3.Show();
  280. progress3.Label1.Text = "正在复制数据……请稍侯";
  281. Application.DoEvents();
  282. CopyDataGridView(sdv, ddv, isprintrowheadercolumn);
  283. progress3.Close();
  284. progress3.Dispose();
  285. }
  286. public static void CopyDataGridViewShowStatus(DataGridView sdv, DataGridView ddv, int fromrow, int torow, bool isprintrowheadercolumn)
  287. {
  288. progress2 progress3 = new progress2();
  289. progress3.Show();
  290. progress3.Label1.Text = "正在复制数据……请稍侯";
  291. Application.DoEvents();
  292. CopyDataGridView(sdv, ddv, fromrow, torow, isprintrowheadercolumn);
  293. progress3.Close();
  294. progress3.Dispose();
  295. }
  296. public static void MyMsgBox(string ss)
  297. {
  298. }
  299. public static void CopyDataGridView(DataGridView sdv, DataGridView ddv)
  300. {
  301. if (sdv == null || ddv == null)
  302. {
  303. return;
  304. }
  305. if (sdv.Equals(ddv))
  306. {
  307. MyMsgBox("在CopyDataGridView函数中发现要复制的DGV与目标DGV完全一样");
  308. return;
  309. }
  310. ddv.AllowUserToAddRows = false;
  311. while (ddv.ColumnCount >= 1)
  312. {
  313. ddv.Columns.RemoveAt(0);
  314. }
  315. ddv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
  316. ddv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
  317. int columnCount = sdv.ColumnCount;
  318. int num = 0;
  319. checked
  320. {
  321. int num2 = columnCount - 1;
  322. for (int i = num; i <= num2; i++)
  323. {
  324. if (Operators.CompareString(Versioned.TypeName(sdv.Columns[i]), "DataGridViewComboBoxColumn", TextCompare: false) == 0)
  325. {
  326. DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
  327. try
  328. {
  329. dataGridViewTextBoxColumn.DefaultCellStyle = sdv.Columns[i].DefaultCellStyle.Clone();
  330. dataGridViewTextBoxColumn.AutoSizeMode = sdv.Columns[i].AutoSizeMode;
  331. dataGridViewTextBoxColumn.DisplayIndex = sdv.Columns[i].DisplayIndex;
  332. }
  333. catch (Exception projectError)
  334. {
  335. ProjectData.SetProjectError(projectError);
  336. ProjectData.ClearProjectError();
  337. }
  338. try
  339. {
  340. dataGridViewTextBoxColumn.HeaderCell = (DataGridViewColumnHeaderCell)sdv.Columns[i].HeaderCell.Clone();
  341. dataGridViewTextBoxColumn.HeaderText = sdv.Columns[i].HeaderText;
  342. dataGridViewTextBoxColumn.MinimumWidth = sdv.Columns[i].MinimumWidth;
  343. dataGridViewTextBoxColumn.Resizable = sdv.Columns[i].Resizable;
  344. }
  345. catch (Exception projectError2)
  346. {
  347. ProjectData.SetProjectError(projectError2);
  348. ProjectData.ClearProjectError();
  349. }
  350. try
  351. {
  352. dataGridViewTextBoxColumn.Name = sdv.Columns[i].Name;
  353. dataGridViewTextBoxColumn.Tag = RuntimeHelpers.GetObjectValue(sdv.Columns[i].Tag);
  354. dataGridViewTextBoxColumn.Visible = sdv.Columns[i].Visible;
  355. try
  356. {
  357. if (Operators.CompareString(Conversions.ToString(dataGridViewTextBoxColumn.Tag), "不打印", TextCompare: false) == 0)
  358. {
  359. dataGridViewTextBoxColumn.Visible = false;
  360. }
  361. }
  362. catch (Exception projectError3)
  363. {
  364. ProjectData.SetProjectError(projectError3);
  365. ProjectData.ClearProjectError();
  366. }
  367. dataGridViewTextBoxColumn.Width = sdv.Columns[i].Width;
  368. }
  369. catch (Exception projectError4)
  370. {
  371. ProjectData.SetProjectError(projectError4);
  372. ProjectData.ClearProjectError();
  373. }
  374. ddv.Columns.Add(dataGridViewTextBoxColumn);
  375. }
  376. else
  377. {
  378. DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)sdv.Columns[i].Clone();
  379. dataGridViewColumn.Frozen = false;
  380. try
  381. {
  382. if (Operators.CompareString(Conversions.ToString(dataGridViewColumn.Tag), "不打印", TextCompare: false) == 0)
  383. {
  384. dataGridViewColumn.Visible = false;
  385. }
  386. }
  387. catch (Exception projectError5)
  388. {
  389. ProjectData.SetProjectError(projectError5);
  390. ProjectData.ClearProjectError();
  391. }
  392. ddv.Columns.Add(dataGridViewColumn);
  393. }
  394. try
  395. {
  396. ddv.Columns[i].ValueType = sdv.Columns[i].ValueType;
  397. }
  398. catch (Exception projectError6)
  399. {
  400. ProjectData.SetProjectError(projectError6);
  401. ProjectData.ClearProjectError();
  402. }
  403. if (Operators.CompareString(ddv.Columns[i].Name ?? "", "", TextCompare: false) == 0)
  404. {
  405. ddv.Columns[i].Name = "第" + Conversions.ToString(i) + "列名";
  406. }
  407. ddv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  408. ddv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
  409. }
  410. int[] array = new int[sdv.ColumnCount - 1 + 1];
  411. int[] array2 = new int[sdv.ColumnCount - 1 + 1];
  412. int num3 = 0;
  413. int num4 = sdv.ColumnCount - 1;
  414. for (int j = num3; j <= num4; j++)
  415. {
  416. array[j] = j;
  417. array2[j] = sdv.Columns[j].DisplayIndex;
  418. }
  419. Array.Sort(array2, array);
  420. int num5 = 0;
  421. int num6 = sdv.ColumnCount - 1;
  422. for (int k = num5; k <= num6; k++)
  423. {
  424. ddv.Columns[array[k]].DisplayIndex = sdv.Columns[array[k]].DisplayIndex;
  425. }
  426. ddv.ColumnHeadersHeightSizeMode = sdv.ColumnHeadersHeightSizeMode;
  427. ddv.ColumnHeadersHeight = sdv.ColumnHeadersHeight;
  428. ddv.ColumnHeadersVisible = sdv.ColumnHeadersVisible;
  429. if (sdv.RowCount <= 0)
  430. {
  431. return;
  432. }
  433. int num7 = sdv.RowCount;
  434. if (sdv.AllowUserToAddRows && IsNullLastRow(sdv))
  435. {
  436. num7--;
  437. }
  438. ddv.RowCount = num7;
  439. ddv.AlternatingRowsDefaultCellStyle = sdv.AlternatingRowsDefaultCellStyle.Clone();
  440. ddv.DefaultCellStyle = sdv.DefaultCellStyle.Clone();
  441. ddv.RowsDefaultCellStyle = sdv.RowsDefaultCellStyle.Clone();
  442. ddv.ColumnHeadersDefaultCellStyle = sdv.ColumnHeadersDefaultCellStyle.Clone();
  443. int num8 = 0;
  444. int num9 = sdv.ColumnCount - 1;
  445. for (int l = num8; l <= num9; l++)
  446. {
  447. if (sdv.Columns[l].HasDefaultCellStyle)
  448. {
  449. ddv.Columns[l].DefaultCellStyle = sdv.Columns[l].DefaultCellStyle.Clone();
  450. }
  451. }
  452. columnCount = ddv.Columns.Count - 1;
  453. string[] array3 = new string[columnCount + 1];
  454. int num10 = 0;
  455. int num11 = columnCount;
  456. for (int m = num10; m <= num11; m++)
  457. {
  458. array3[m] = Versioned.TypeName(sdv.Columns[m]);
  459. }
  460. int num12 = 0;
  461. int num13 = num7 - 1;
  462. for (int n = num12; n <= num13; n++)
  463. {
  464. int num14 = 0;
  465. int num15 = columnCount;
  466. for (int num16 = num14; num16 <= num15; num16++)
  467. {
  468. if (Operators.CompareString(array3[num16], "DataGridViewImageColumn", TextCompare: false) == 0)
  469. {
  470. ddv.Rows[n].Cells[num16].Value = RuntimeHelpers.GetObjectValue(sdv.Rows[n].Cells[num16].Value);
  471. if (ddv.Rows[n].Cells[num16].Value != null)
  472. {
  473. try
  474. {
  475. DataGridViewImageCell dataGridViewImageCell = (DataGridViewImageCell)ddv.Rows[n].Cells[num16];
  476. dataGridViewImageCell.ImageLayout = ((DataGridViewImageCell)sdv.Rows[n].Cells[num16]).ImageLayout;
  477. }
  478. catch (Exception projectError7)
  479. {
  480. ProjectData.SetProjectError(projectError7);
  481. ProjectData.ClearProjectError();
  482. }
  483. }
  484. }
  485. else
  486. {
  487. ddv.Rows[n].Cells[num16].Value = Conversions.ToString(sdv.Rows[n].Cells[num16].FormattedValue) ?? "";
  488. }
  489. if (sdv.Rows[n].Cells[num16].HasStyle)
  490. {
  491. ddv.Rows[n].Cells[num16].Style = sdv.Rows[n].Cells[num16].Style.Clone();
  492. }
  493. try
  494. {
  495. ddv.Rows[n].Cells[num16].Tag = RuntimeHelpers.GetObjectValue(sdv.Rows[n].Cells[num16].Tag);
  496. }
  497. catch (Exception projectError8)
  498. {
  499. ProjectData.SetProjectError(projectError8);
  500. ProjectData.ClearProjectError();
  501. }
  502. }
  503. ddv.Rows[n].Height = sdv.Rows[n].Height;
  504. ddv.Rows[n].Visible = sdv.Rows[n].Visible;
  505. if (sdv.Rows[n].HasDefaultCellStyle)
  506. {
  507. ddv.Rows[n].DefaultCellStyle = sdv.Rows[n].DefaultCellStyle.Clone();
  508. }
  509. try
  510. {
  511. ddv.Rows[n].Tag = RuntimeHelpers.GetObjectValue(sdv.Rows[n].Tag);
  512. }
  513. catch (Exception projectError9)
  514. {
  515. ProjectData.SetProjectError(projectError9);
  516. ProjectData.ClearProjectError();
  517. }
  518. }
  519. ddv.GridColor = sdv.GridColor;
  520. ddv.Name = sdv.Name;
  521. }
  522. }
  523. public static void CopyDataGridView(DataGridView sdv, DataGridView ddv, int fromrow, int torow, bool isprintrowheadercolumn)
  524. {
  525. if (sdv == null || ddv == null)
  526. {
  527. return;
  528. }
  529. if (sdv.Equals(ddv))
  530. {
  531. MyMsgBox("在CopyDataGridView函数中发现要复制的DGV与目标DGV完全一样");
  532. return;
  533. }
  534. if (fromrow < 0)
  535. {
  536. fromrow = 0;
  537. }
  538. if (torow > checked(sdv.RowCount - 1) || torow < fromrow)
  539. {
  540. torow = checked(sdv.RowCount - 1);
  541. }
  542. ddv.AllowUserToAddRows = false;
  543. while (ddv.ColumnCount >= 1)
  544. {
  545. ddv.Columns.RemoveAt(0);
  546. }
  547. ddv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
  548. ddv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
  549. int num = 0;
  550. checked
  551. {
  552. int num2 = sdv.ColumnCount - 1;
  553. for (int i = num; i <= num2; i++)
  554. {
  555. if (Operators.CompareString(Versioned.TypeName(sdv.Columns[i]), "DataGridViewComboBoxColumn", TextCompare: false) == 0)
  556. {
  557. DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
  558. try
  559. {
  560. dataGridViewTextBoxColumn.DefaultCellStyle = sdv.Columns[i].DefaultCellStyle.Clone();
  561. dataGridViewTextBoxColumn.AutoSizeMode = sdv.Columns[i].AutoSizeMode;
  562. dataGridViewTextBoxColumn.DisplayIndex = sdv.Columns[i].DisplayIndex;
  563. }
  564. catch (Exception projectError)
  565. {
  566. ProjectData.SetProjectError(projectError);
  567. ProjectData.ClearProjectError();
  568. }
  569. try
  570. {
  571. dataGridViewTextBoxColumn.HeaderCell = (DataGridViewColumnHeaderCell)sdv.Columns[i].HeaderCell.Clone();
  572. dataGridViewTextBoxColumn.HeaderText = sdv.Columns[i].HeaderText;
  573. dataGridViewTextBoxColumn.MinimumWidth = sdv.Columns[i].MinimumWidth;
  574. dataGridViewTextBoxColumn.Resizable = sdv.Columns[i].Resizable;
  575. }
  576. catch (Exception projectError2)
  577. {
  578. ProjectData.SetProjectError(projectError2);
  579. ProjectData.ClearProjectError();
  580. }
  581. try
  582. {
  583. dataGridViewTextBoxColumn.Name = sdv.Columns[i].Name;
  584. dataGridViewTextBoxColumn.Tag = RuntimeHelpers.GetObjectValue(sdv.Columns[i].Tag);
  585. dataGridViewTextBoxColumn.Visible = sdv.Columns[i].Visible;
  586. try
  587. {
  588. if (Operators.CompareString(Conversions.ToString(dataGridViewTextBoxColumn.Tag), "不打印", TextCompare: false) == 0)
  589. {
  590. dataGridViewTextBoxColumn.Visible = false;
  591. }
  592. }
  593. catch (Exception projectError3)
  594. {
  595. ProjectData.SetProjectError(projectError3);
  596. ProjectData.ClearProjectError();
  597. }
  598. dataGridViewTextBoxColumn.Width = sdv.Columns[i].Width;
  599. }
  600. catch (Exception projectError4)
  601. {
  602. ProjectData.SetProjectError(projectError4);
  603. ProjectData.ClearProjectError();
  604. }
  605. ddv.Columns.Add(dataGridViewTextBoxColumn);
  606. }
  607. else
  608. {
  609. DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)sdv.Columns[i].Clone();
  610. dataGridViewColumn.Frozen = false;
  611. try
  612. {
  613. if (Operators.CompareString(Conversions.ToString(dataGridViewColumn.Tag), "不打印", TextCompare: false) == 0)
  614. {
  615. dataGridViewColumn.Visible = false;
  616. }
  617. }
  618. catch (Exception projectError5)
  619. {
  620. ProjectData.SetProjectError(projectError5);
  621. ProjectData.ClearProjectError();
  622. }
  623. ddv.Columns.Add(dataGridViewColumn);
  624. }
  625. try
  626. {
  627. ddv.Columns[i].ValueType = sdv.Columns[i].ValueType;
  628. }
  629. catch (Exception projectError6)
  630. {
  631. ProjectData.SetProjectError(projectError6);
  632. ProjectData.ClearProjectError();
  633. }
  634. if (Operators.CompareString(ddv.Columns[i].Name ?? "", "", TextCompare: false) == 0)
  635. {
  636. ddv.Columns[i].Name = "第" + Conversions.ToString(i) + "列名";
  637. }
  638. ddv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  639. ddv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
  640. }
  641. int[] array = new int[sdv.ColumnCount - 1 + 1];
  642. int[] array2 = new int[sdv.ColumnCount - 1 + 1];
  643. int num3 = 0;
  644. int num4 = sdv.ColumnCount - 1;
  645. for (int j = num3; j <= num4; j++)
  646. {
  647. array[j] = j;
  648. array2[j] = sdv.Columns[j].DisplayIndex;
  649. }
  650. Array.Sort(array2, array);
  651. int num5 = 0;
  652. int num6 = sdv.ColumnCount - 1;
  653. for (int k = num5; k <= num6; k++)
  654. {
  655. ddv.Columns[array[k]].DisplayIndex = sdv.Columns[array[k]].DisplayIndex;
  656. }
  657. ddv.ColumnHeadersHeightSizeMode = sdv.ColumnHeadersHeightSizeMode;
  658. ddv.ColumnHeadersHeight = sdv.ColumnHeadersHeight;
  659. ddv.ColumnHeadersVisible = sdv.ColumnHeadersVisible;
  660. if (sdv.RowCount <= 0)
  661. {
  662. return;
  663. }
  664. int rowCount = torow - fromrow + 1;
  665. ddv.RowCount = rowCount;
  666. ddv.AlternatingRowsDefaultCellStyle = sdv.AlternatingRowsDefaultCellStyle.Clone();
  667. ddv.DefaultCellStyle = sdv.DefaultCellStyle.Clone();
  668. ddv.RowsDefaultCellStyle = sdv.RowsDefaultCellStyle.Clone();
  669. ddv.ColumnHeadersDefaultCellStyle = sdv.ColumnHeadersDefaultCellStyle.Clone();
  670. int num7 = 0;
  671. int num8 = sdv.ColumnCount - 1;
  672. for (int l = num7; l <= num8; l++)
  673. {
  674. if (sdv.Columns[l].HasDefaultCellStyle)
  675. {
  676. ddv.Columns[l].DefaultCellStyle = sdv.Columns[l].DefaultCellStyle.Clone();
  677. }
  678. }
  679. int num9 = fromrow;
  680. int num10 = torow;
  681. for (int m = num9; m <= num10; m++)
  682. {
  683. int num11 = 0;
  684. int num12 = ddv.Columns.Count - 1;
  685. for (int n = num11; n <= num12; n++)
  686. {
  687. if (Operators.CompareString(Versioned.TypeName(sdv.Columns[n]), "DataGridViewImageColumn", TextCompare: false) == 0)
  688. {
  689. ddv.Rows[m - fromrow].Cells[n].Value = RuntimeHelpers.GetObjectValue(sdv.Rows[m].Cells[n].Value);
  690. if (ddv.Rows[m - fromrow].Cells[n].Value != null)
  691. {
  692. try
  693. {
  694. DataGridViewImageCell dataGridViewImageCell = (DataGridViewImageCell)ddv.Rows[m - fromrow].Cells[n];
  695. dataGridViewImageCell.ImageLayout = ((DataGridViewImageCell)sdv.Rows[m].Cells[n]).ImageLayout;
  696. }
  697. catch (Exception projectError7)
  698. {
  699. ProjectData.SetProjectError(projectError7);
  700. ProjectData.ClearProjectError();
  701. }
  702. }
  703. }
  704. else
  705. {
  706. ddv.Rows[m - fromrow].Cells[n].Value = Conversions.ToString(sdv.Rows[m].Cells[n].FormattedValue) ?? "";
  707. }
  708. if (sdv.Rows[m].Cells[n].HasStyle)
  709. {
  710. ddv.Rows[m - fromrow].Cells[n].Style = sdv.Rows[m].Cells[n].Style.Clone();
  711. }
  712. try
  713. {
  714. ddv.Rows[m - fromrow].Cells[n].Tag = RuntimeHelpers.GetObjectValue(sdv.Rows[m].Cells[n].Tag);
  715. }
  716. catch (Exception projectError8)
  717. {
  718. ProjectData.SetProjectError(projectError8);
  719. ProjectData.ClearProjectError();
  720. }
  721. }
  722. ddv.Rows[m - fromrow].Height = sdv.Rows[m].Height;
  723. ddv.Rows[m - fromrow].Visible = sdv.Rows[m].Visible;
  724. if (sdv.Rows[m].HasDefaultCellStyle)
  725. {
  726. ddv.Rows[m - fromrow].DefaultCellStyle = sdv.Rows[m].DefaultCellStyle.Clone();
  727. }
  728. try
  729. {
  730. ddv.Rows[m - fromrow].Tag = RuntimeHelpers.GetObjectValue(sdv.Rows[m].Tag);
  731. }
  732. catch (Exception projectError9)
  733. {
  734. ProjectData.SetProjectError(projectError9);
  735. ProjectData.ClearProjectError();
  736. }
  737. }
  738. ddv.GridColor = sdv.GridColor;
  739. ddv.Name = sdv.Name;
  740. if (!isprintrowheadercolumn)
  741. {
  742. return;
  743. }
  744. try
  745. {
  746. if (ddv.Columns.Count <= 0)
  747. {
  748. return;
  749. }
  750. DataGridViewTextBoxColumn dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
  751. dataGridViewTextBoxColumn2.HeaderCell = (DataGridViewColumnHeaderCell)sdv.TopLeftHeaderCell.Clone();
  752. if (sdv.TopLeftHeaderCell.HasStyle)
  753. {
  754. dataGridViewTextBoxColumn2.HeaderCell.Style = sdv.TopLeftHeaderCell.Style.Clone();
  755. }
  756. dataGridViewTextBoxColumn2.Width = sdv.RowHeadersWidth;
  757. if (Operators.CompareString(dataGridViewTextBoxColumn2.Name ?? "", "", TextCompare: false) == 0)
  758. {
  759. dataGridViewTextBoxColumn2.Name = "平平自创";
  760. }
  761. dataGridViewTextBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
  762. ddv.Columns.Insert(0, dataGridViewTextBoxColumn2);
  763. rowCount = ddv.RowCount;
  764. int num13 = fromrow;
  765. int num14 = torow;
  766. for (int num15 = num13; num15 <= num14; num15++)
  767. {
  768. ddv.Rows[num15 - fromrow].Cells[0].Value = Conversions.ToString(sdv.Rows[num15].HeaderCell.FormattedValue) ?? "";
  769. if (sdv.Rows[num15].HeaderCell.Style.Font != null)
  770. {
  771. ddv.Rows[num15 - fromrow].Cells[0].Style.Font = (Font)sdv.Rows[num15].HeaderCell.Style.Font.Clone();
  772. }
  773. else if (sdv.RowHeadersDefaultCellStyle.Font != null)
  774. {
  775. ddv.Rows[num15 - fromrow].Cells[0].Style.Font = (Font)sdv.RowHeadersDefaultCellStyle.Font.Clone();
  776. }
  777. if (sdv.Rows[num15].HeaderCell.Style.Alignment != 0)
  778. {
  779. ddv.Rows[num15 - fromrow].Cells[0].Style.Alignment = sdv.Rows[num15].HeaderCell.Style.Alignment;
  780. }
  781. else
  782. {
  783. ddv.Rows[num15 - fromrow].Cells[0].Style.Alignment = sdv.RowHeadersDefaultCellStyle.Alignment;
  784. }
  785. if (sdv.Rows[num15].HeaderCell.Style.ForeColor.ToArgb() != 0)
  786. {
  787. ddv.Rows[num15 - fromrow].Cells[0].Style.ForeColor = sdv.Rows[num15].HeaderCell.Style.ForeColor;
  788. }
  789. else if (sdv.RowHeadersDefaultCellStyle.ForeColor.ToArgb() != 0)
  790. {
  791. ddv.Rows[num15 - fromrow].Cells[0].Style.ForeColor = sdv.RowHeadersDefaultCellStyle.ForeColor;
  792. }
  793. if (sdv.Rows[num15].HeaderCell.Style.BackColor.ToArgb() != 0)
  794. {
  795. ddv.Rows[num15 - fromrow].Cells[0].Style.BackColor = sdv.Rows[num15].HeaderCell.Style.BackColor;
  796. }
  797. else if (sdv.RowHeadersDefaultCellStyle.BackColor.ToArgb() != 0)
  798. {
  799. ddv.Rows[num15 - fromrow].Cells[0].Style.BackColor = sdv.RowHeadersDefaultCellStyle.BackColor;
  800. }
  801. if (sdv.Rows[num15].HeaderCell.Style.WrapMode != 0)
  802. {
  803. ddv.Rows[num15 - fromrow].Cells[0].Style.WrapMode = sdv.Rows[num15].HeaderCell.Style.WrapMode;
  804. }
  805. else if (sdv.RowHeadersDefaultCellStyle.WrapMode != 0)
  806. {
  807. ddv.Rows[num15 - fromrow].Cells[0].Style.WrapMode = sdv.RowHeadersDefaultCellStyle.WrapMode;
  808. }
  809. }
  810. }
  811. catch (Exception projectError10)
  812. {
  813. ProjectData.SetProjectError(projectError10);
  814. ProjectData.ClearProjectError();
  815. }
  816. }
  817. }
  818. public static void DelDGVAllUnvisibleCols(DataGridView dgv)
  819. {
  820. if (dgv == null)
  821. {
  822. return;
  823. }
  824. checked
  825. {
  826. try
  827. {
  828. int columnCount = dgv.ColumnCount;
  829. for (int i = columnCount - 1; i >= 0; i += -1)
  830. {
  831. if (!dgv.Columns[i].Visible)
  832. {
  833. dgv.Columns.RemoveAt(i);
  834. }
  835. }
  836. }
  837. catch (Exception projectError)
  838. {
  839. ProjectData.SetProjectError(projectError);
  840. ProjectData.ClearProjectError();
  841. }
  842. }
  843. }
  844. public static void AddDGVRowID(DataGridView dgv)
  845. {
  846. if (dgv.Columns.Count <= 0)
  847. {
  848. return;
  849. }
  850. DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
  851. dataGridViewTextBoxColumn.HeaderText = "行号";
  852. dataGridViewTextBoxColumn.DefaultCellStyle = dgv.DefaultCellStyle.Clone();
  853. dataGridViewTextBoxColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  854. dataGridViewTextBoxColumn.Width = 40;
  855. dataGridViewTextBoxColumn.Name = "游平自创";
  856. try
  857. {
  858. dgv.Columns.Insert(0, dataGridViewTextBoxColumn);
  859. }
  860. catch (Exception projectError)
  861. {
  862. ProjectData.SetProjectError(projectError);
  863. dataGridViewTextBoxColumn.Frozen = true;
  864. dgv.Columns.Insert(0, dataGridViewTextBoxColumn);
  865. ProjectData.ClearProjectError();
  866. }
  867. checked
  868. {
  869. try
  870. {
  871. int num = 1;
  872. int num2 = 0;
  873. int num3 = dgv.RowCount - 1;
  874. for (int i = num2; i <= num3; i++)
  875. {
  876. if (dgv.Rows[i].Visible)
  877. {
  878. dgv.Rows[i].Cells[0].Value = Conversions.ToString(num);
  879. num++;
  880. }
  881. }
  882. }
  883. catch (Exception projectError2)
  884. {
  885. ProjectData.SetProjectError(projectError2);
  886. ProjectData.ClearProjectError();
  887. }
  888. }
  889. }
  890. public static int GetDGVVisibleRows(DataGridView dgv)
  891. {
  892. if (dgv == null)
  893. {
  894. return 0;
  895. }
  896. int num = 0;
  897. int num2 = 0;
  898. checked
  899. {
  900. int num3 = dgv.RowCount - 1;
  901. for (int i = num2; i <= num3; i++)
  902. {
  903. if (dgv.Rows[i].Visible)
  904. {
  905. num++;
  906. }
  907. }
  908. return num;
  909. }
  910. }
  911. public static bool IsNullLastRow(DataGridView dgv)
  912. {
  913. checked
  914. {
  915. bool result;
  916. if (dgv == null)
  917. {
  918. result = false;
  919. }
  920. else if (dgv.RowCount <= 0)
  921. {
  922. result = false;
  923. }
  924. else
  925. {
  926. int index = dgv.RowCount - 1;
  927. bool flag = true;
  928. try
  929. {
  930. int num = 0;
  931. int num2 = dgv.ColumnCount - 1;
  932. for (int i = num; i <= num2; i++)
  933. {
  934. if (Operators.CompareString(Versioned.TypeName(dgv.Columns[i]), "DataGridViewImageColumn", TextCompare: false) != 0 && Operators.ConditionalCompareObjectNotEqual(Operators.ConcatenateObject(dgv.Rows[index].Cells[i].Value, ""), "", TextCompare: false))
  935. {
  936. flag = false;
  937. break;
  938. }
  939. }
  940. result = (flag ? true : false);
  941. }
  942. catch (Exception projectError)
  943. {
  944. ProjectData.SetProjectError(projectError);
  945. result = false;
  946. ProjectData.ClearProjectError();
  947. }
  948. }
  949. return result;
  950. }
  951. }
  952. public static void SetDGVSelectedRowsVisible(DataGridView sdgv, DataGridView ddgv, int baserows)
  953. {
  954. checked
  955. {
  956. if (sdgv != null && ddgv != null)
  957. {
  958. int num = 0;
  959. int num2 = ddgv.Rows.Count - 1;
  960. for (int i = num; i <= num2; i++)
  961. {
  962. ddgv.Rows[i].Visible = false;
  963. }
  964. List<int> dGVSelectedRows = GetDGVSelectedRows(sdgv);
  965. int num3 = 0;
  966. int num4 = dGVSelectedRows.Count - 1;
  967. for (int j = num3; j <= num4; j++)
  968. {
  969. ddgv.Rows[dGVSelectedRows[j] - baserows].Visible = true;
  970. }
  971. }
  972. }
  973. }
  974. public static void SetDGVSelectedColumnsVisible(DataGridView sdgv, DataGridView ddgv)
  975. {
  976. if (sdgv == null || ddgv == null)
  977. {
  978. return;
  979. }
  980. checked
  981. {
  982. bool[] array = new bool[sdgv.Columns.Count - 1 + 1];
  983. int num = 0;
  984. int num2 = sdgv.Columns.Count - 1;
  985. for (int i = num; i <= num2; i++)
  986. {
  987. array[i] = false;
  988. }
  989. List<int> dGVSelectedCols = GetDGVSelectedCols(sdgv);
  990. int num3 = 0;
  991. int num4 = dGVSelectedCols.Count - 1;
  992. for (int j = num3; j <= num4; j++)
  993. {
  994. array[dGVSelectedCols[j]] = true;
  995. }
  996. int num5 = 0;
  997. int num6 = ddgv.Columns.Count - 1;
  998. for (int k = num5; k <= num6; k++)
  999. {
  1000. if (!array[k])
  1001. {
  1002. ddgv.Columns[k].Visible = false;
  1003. }
  1004. }
  1005. }
  1006. }
  1007. public static List<int> GetDGVSelectedCols(DataGridView dgv)
  1008. {
  1009. if (dgv == null)
  1010. {
  1011. return null;
  1012. }
  1013. if (dgv.SelectedCells.Count <= 0)
  1014. {
  1015. return null;
  1016. }
  1017. checked
  1018. {
  1019. int num = dgv.RowCount - 1;
  1020. int num2 = dgv.ColumnCount - 1;
  1021. List<int> list = new List<int>();
  1022. int num3 = 0;
  1023. int num4 = num2;
  1024. for (int i = num3; i <= num4; i++)
  1025. {
  1026. if (!dgv.Columns[i].Visible)
  1027. {
  1028. continue;
  1029. }
  1030. int num5 = 0;
  1031. int num6 = num;
  1032. for (int j = num5; j <= num6; j++)
  1033. {
  1034. if (dgv.Rows[j].Cells[i].Selected)
  1035. {
  1036. list.Add(i);
  1037. break;
  1038. }
  1039. }
  1040. }
  1041. return list;
  1042. }
  1043. }
  1044. public static List<int> GetDGVSelectedRows(DataGridView dgv)
  1045. {
  1046. if (dgv == null)
  1047. {
  1048. return null;
  1049. }
  1050. if (dgv.SelectedCells.Count <= 0)
  1051. {
  1052. return null;
  1053. }
  1054. checked
  1055. {
  1056. int num = dgv.RowCount - 1;
  1057. int num2 = dgv.ColumnCount - 1;
  1058. List<int> list = new List<int>();
  1059. int num3 = 0;
  1060. int num4 = num;
  1061. for (int i = num3; i <= num4; i++)
  1062. {
  1063. if (!dgv.Rows[i].Visible)
  1064. {
  1065. continue;
  1066. }
  1067. int num5 = 0;
  1068. int num6 = num2;
  1069. for (int j = num5; j <= num6; j++)
  1070. {
  1071. if (dgv.Rows[i].Cells[j].Selected)
  1072. {
  1073. list.Add(i);
  1074. break;
  1075. }
  1076. }
  1077. }
  1078. return list;
  1079. }
  1080. }
  1081. public static void SetDGVSelectedRowsAndColumnsVisible(DataGridView sdgv, DataGridView ddgv, int baserows)
  1082. {
  1083. SetDGVSelectedRowsVisible(sdgv, ddgv, baserows);
  1084. SetDGVSelectedColumnsVisible(sdgv, ddgv);
  1085. }
  1086. public static int GetDGVSelectedMinRowIndex(DataGridView dgv)
  1087. {
  1088. if (dgv == null)
  1089. {
  1090. return -1;
  1091. }
  1092. if (dgv.RowCount <= 0)
  1093. {
  1094. return -1;
  1095. }
  1096. if (dgv.SelectedCells.Count <= 0)
  1097. {
  1098. return -1;
  1099. }
  1100. checked
  1101. {
  1102. int num = dgv.RowCount - 1;
  1103. int num2 = dgv.ColumnCount - 1;
  1104. int num3 = 0;
  1105. int num4 = num;
  1106. for (int i = num3; i <= num4; i++)
  1107. {
  1108. int num5 = 0;
  1109. int num6 = num2;
  1110. for (int j = num5; j <= num6; j++)
  1111. {
  1112. if (dgv.Rows[i].Cells[j].Selected)
  1113. {
  1114. return i;
  1115. }
  1116. }
  1117. }
  1118. return -1;
  1119. }
  1120. }
  1121. public static int GetDGVSelectedMaxRowIndex(DataGridView dgv)
  1122. {
  1123. if (dgv == null)
  1124. {
  1125. return -1;
  1126. }
  1127. if (dgv.RowCount <= 0)
  1128. {
  1129. return -1;
  1130. }
  1131. if (dgv.SelectedCells.Count <= 0)
  1132. {
  1133. return -1;
  1134. }
  1135. checked
  1136. {
  1137. int num = dgv.RowCount - 1;
  1138. int num2 = dgv.ColumnCount - 1;
  1139. for (int i = num; i >= 0; i += -1)
  1140. {
  1141. int num3 = 0;
  1142. int num4 = num2;
  1143. for (int j = num3; j <= num4; j++)
  1144. {
  1145. if (dgv.Rows[i].Cells[j].Selected)
  1146. {
  1147. return i;
  1148. }
  1149. }
  1150. }
  1151. return -1;
  1152. }
  1153. }
  1154. public static DataGridView ConvertDataGridToDGV(DataGrid myd, bool autoresizewidth, bool autoresizeheight)
  1155. {
  1156. DataGridView dataGridView = new DataGridView();
  1157. int count = myd.BindingContext[RuntimeHelpers.GetObjectValue(myd.DataSource), myd.DataMember].Count;
  1158. if (count <= 0)
  1159. {
  1160. return null;
  1161. }
  1162. int num = 0;
  1163. checked
  1164. {
  1165. try
  1166. {
  1167. while (true)
  1168. {
  1169. Conversions.ToString(myd[0, num]);
  1170. num++;
  1171. }
  1172. }
  1173. catch (Exception projectError)
  1174. {
  1175. ProjectData.SetProjectError(projectError);
  1176. ProjectData.ClearProjectError();
  1177. }
  1178. int num2 = 0;
  1179. int num3 = count - 1;
  1180. for (int i = num2; i <= num3; i++)
  1181. {
  1182. int num4 = 0;
  1183. int num5 = num - 1;
  1184. for (int j = num4; j <= num5; j++)
  1185. {
  1186. }
  1187. }
  1188. if (num <= 0)
  1189. {
  1190. return null;
  1191. }
  1192. dataGridView.RowCount = count;
  1193. dataGridView.ColumnCount = num;
  1194. if (myd.TableStyles.Count <= 0)
  1195. {
  1196. DataGridTableStyle table = new DataGridTableStyle((CurrencyManager)myd.BindingContext[RuntimeHelpers.GetObjectValue(myd.DataSource), myd.DataMember]);
  1197. myd.TableStyles.Add(table);
  1198. }
  1199. int num6 = 0;
  1200. int num7 = num - 1;
  1201. for (int k = num6; k <= num7; k++)
  1202. {
  1203. dataGridView.Columns[k].HeaderText = myd.TableStyles[0].GridColumnStyles[k].HeaderText ?? "";
  1204. dataGridView.Columns[k].DefaultCellStyle.Alignment = ConvertAlignment(myd.TableStyles[0].GridColumnStyles[k].Alignment);
  1205. dataGridView.Columns[k].Width = myd.TableStyles[0].GridColumnStyles[k].Width;
  1206. }
  1207. dataGridView.ColumnHeadersDefaultCellStyle.Font = myd.HeaderFont;
  1208. dataGridView.ColumnHeadersDefaultCellStyle.ForeColor = myd.HeaderForeColor;
  1209. dataGridView.ColumnHeadersDefaultCellStyle.BackColor = myd.HeaderBackColor;
  1210. int num8 = 0;
  1211. int num9 = count - 1;
  1212. for (int l = num8; l <= num9; l++)
  1213. {
  1214. int num10 = 0;
  1215. int num11 = num - 1;
  1216. for (int m = num10; m <= num11; m++)
  1217. {
  1218. dataGridView.Rows[l].Cells[m].Value = Operators.ConcatenateObject(myd[l, m], "");
  1219. }
  1220. }
  1221. dataGridView.RowHeadersWidth = myd.RowHeaderWidth;
  1222. dataGridView.AlternatingRowsDefaultCellStyle.BackColor = myd.AlternatingBackColor;
  1223. dataGridView.DefaultCellStyle.BackColor = myd.BackColor;
  1224. dataGridView.DefaultCellStyle.Font = myd.Font;
  1225. dataGridView.DefaultCellStyle.ForeColor = myd.ForeColor;
  1226. dataGridView.GridColor = myd.GridLineColor;
  1227. int num12 = 0;
  1228. int num13 = num - 1;
  1229. for (int n = num12; n <= num13; n++)
  1230. {
  1231. dataGridView.Columns[n].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
  1232. }
  1233. if (autoresizewidth)
  1234. {
  1235. dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  1236. }
  1237. if (autoresizeheight)
  1238. {
  1239. dataGridView.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCells);
  1240. }
  1241. return dataGridView;
  1242. }
  1243. }
  1244. private static DataGridViewContentAlignment ConvertAlignment(HorizontalAlignment ss)
  1245. {
  1246. DataGridViewContentAlignment result;
  1247. switch (ss)
  1248. {
  1249. case HorizontalAlignment.Left:
  1250. result = DataGridViewContentAlignment.MiddleLeft;
  1251. break;
  1252. case HorizontalAlignment.Right:
  1253. result = DataGridViewContentAlignment.MiddleRight;
  1254. break;
  1255. case HorizontalAlignment.Center:
  1256. result = DataGridViewContentAlignment.MiddleCenter;
  1257. break;
  1258. default:
  1259. result = DataGridViewContentAlignment.MiddleLeft;
  1260. break;
  1261. }
  1262. return result;
  1263. }
  1264. private static bool IsColumNameExists(DataGridView dd, string tt)
  1265. {
  1266. if (dd == null)
  1267. {
  1268. return false;
  1269. }
  1270. if (Operators.CompareString(tt ?? "", "", TextCompare: false) == 0)
  1271. {
  1272. return false;
  1273. }
  1274. string[] array = Strings.Split(tt, ";");
  1275. int num = 0;
  1276. checked
  1277. {
  1278. int num2 = array.Length - 1;
  1279. for (int i = num; i <= num2; i++)
  1280. {
  1281. try
  1282. {
  1283. _ = dd.Columns[array[i]].DisplayIndex;
  1284. }
  1285. catch (Exception projectError)
  1286. {
  1287. ProjectData.SetProjectError(projectError);
  1288. bool result = false;
  1289. ProjectData.ClearProjectError();
  1290. return result;
  1291. }
  1292. }
  1293. return true;
  1294. }
  1295. }
  1296. public static void CreateHz(DataGridView dgv, int srows, string myhzcolumns, Font hzfont, Color hzforecolor, Color hzbackcolor, StringAlignment SumNumberAlign)
  1297. {
  1298. if (dgv.AllowUserToAddRows)
  1299. {
  1300. dgv.AllowUserToAddRows = false;
  1301. }
  1302. checked
  1303. {
  1304. if (dgv.RowCount > srows)
  1305. {
  1306. dgv.Rows.RemoveAt(dgv.RowCount - 1);
  1307. }
  1308. if (!IsColumNameExists(dgv, myhzcolumns))
  1309. {
  1310. myhzcolumns = "";
  1311. }
  1312. if (Operators.CompareString(myhzcolumns ?? "", "", TextCompare: false) == 0)
  1313. {
  1314. return;
  1315. }
  1316. string[] array = Strings.Split(myhzcolumns, ";");
  1317. if (array.Length < 1)
  1318. {
  1319. return;
  1320. }
  1321. if (dgv.RowCount == srows)
  1322. {
  1323. dgv.Rows.Add();
  1324. }
  1325. decimal num = 0m;
  1326. int num2 = 0;
  1327. int num3 = array.Length - 1;
  1328. string text;
  1329. for (int i = num2; i <= num3; i++)
  1330. {
  1331. num = 0m;
  1332. try
  1333. {
  1334. int num4 = 0;
  1335. int num5 = srows - 1;
  1336. for (int j = num4; j <= num5; j++)
  1337. {
  1338. if (dgv.Rows[j].Visible)
  1339. {
  1340. text = Conversions.ToString(dgv.Rows[j].Cells[array[i]].Value);
  1341. if (Versioned.IsNumeric(text))
  1342. {
  1343. num = decimal.Add(num, Conversions.ToDecimal(text));
  1344. }
  1345. }
  1346. }
  1347. if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[i]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
  1348. {
  1349. dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = false;
  1350. }
  1351. else if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[i]]), "DataGridViewImageColumn", TextCompare: false) == 0)
  1352. {
  1353. dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = null;
  1354. }
  1355. else if (decimal.Compare(new decimal(Convert.ToInt64(num)), num) == 0)
  1356. {
  1357. dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = Conversions.ToString(num);
  1358. }
  1359. else
  1360. {
  1361. dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = Conversions.ToString(num);
  1362. }
  1363. }
  1364. catch (Exception projectError)
  1365. {
  1366. ProjectData.SetProjectError(projectError);
  1367. if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[i]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
  1368. {
  1369. dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = false;
  1370. }
  1371. else if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[i]]), "DataGridViewImageColumn", TextCompare: false) == 0)
  1372. {
  1373. dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = null;
  1374. }
  1375. else
  1376. {
  1377. dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = "";
  1378. }
  1379. ProjectData.ClearProjectError();
  1380. }
  1381. }
  1382. if (hzfont != null)
  1383. {
  1384. dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.Font = hzfont;
  1385. }
  1386. if (hzforecolor.ToArgb() != 0)
  1387. {
  1388. dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.ForeColor = hzforecolor;
  1389. }
  1390. if (hzbackcolor.ToArgb() != 0)
  1391. {
  1392. dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.BackColor = hzbackcolor;
  1393. }
  1394. text = GetDGVFirstColumnName(dgv);
  1395. if (Operators.CompareString(text, "", TextCompare: false) != 0)
  1396. {
  1397. dgv.Rows[dgv.RowCount - 1].Cells[text].Value = "总计";
  1398. }
  1399. dgv.Rows[dgv.RowCount - 1].Cells[text].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  1400. switch (SumNumberAlign)
  1401. {
  1402. case StringAlignment.Near:
  1403. dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
  1404. break;
  1405. case StringAlignment.Center:
  1406. dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  1407. break;
  1408. case StringAlignment.Far:
  1409. dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
  1410. break;
  1411. }
  1412. }
  1413. }
  1414. public static void CreateFzHz(DataGridView dgv, string groupcolumn, string myhzcolumns, Font hzfont, Color hzforecolor, Color hzbackcolor, bool addrowid, bool addrowidnew, StringAlignment SumNumberAlign)
  1415. {
  1416. if (dgv.AllowUserToAddRows)
  1417. {
  1418. dgv.AllowUserToAddRows = false;
  1419. }
  1420. if (addrowid)
  1421. {
  1422. AddDGVRowID(dgv);
  1423. }
  1424. groupcolumn = groupcolumn ?? "";
  1425. if (Operators.CompareString(groupcolumn, "", TextCompare: false) == 0)
  1426. {
  1427. return;
  1428. }
  1429. string[] array = Strings.Split(myhzcolumns, ";");
  1430. if (array.Length < 1)
  1431. {
  1432. return;
  1433. }
  1434. int num = 1;
  1435. int fromrow = 0;
  1436. if (Operators.CompareString(Versioned.TypeName(dgv.Columns[groupcolumn]), "DataGridViewImageColumn", TextCompare: false) == 0)
  1437. {
  1438. return;
  1439. }
  1440. string left = Conversions.ToString(dgv.Rows[0].Cells[groupcolumn].FormattedValue) ?? "";
  1441. checked
  1442. {
  1443. if (dgv.Rows[0].Visible && addrowid)
  1444. {
  1445. dgv.Rows[0].Cells[0].Value = Conversions.ToString(num);
  1446. num++;
  1447. }
  1448. int num2 = dgv.RowCount;
  1449. if (!IsColumNameExists(dgv, myhzcolumns))
  1450. {
  1451. myhzcolumns = "";
  1452. }
  1453. if (Operators.CompareString(myhzcolumns ?? "", "", TextCompare: false) != 0)
  1454. {
  1455. num2--;
  1456. }
  1457. for (int i = 1; i <= num2 - 1; i++)
  1458. {
  1459. if (Operators.CompareString(left, Conversions.ToString(dgv.Rows[i].Cells[groupcolumn].FormattedValue) ?? "", TextCompare: false) != 0)
  1460. {
  1461. left = Conversions.ToString(dgv.Rows[i].Cells[groupcolumn].FormattedValue) ?? "";
  1462. if (addrowidnew)
  1463. {
  1464. num = 1;
  1465. }
  1466. int torow = i - 1;
  1467. if (CreateHzRow(dgv, groupcolumn, myhzcolumns, hzfont, hzforecolor, hzbackcolor, fromrow, torow, SumNumberAlign))
  1468. {
  1469. num2 = dgv.RowCount;
  1470. num2--;
  1471. fromrow = i + 1;
  1472. i++;
  1473. }
  1474. else
  1475. {
  1476. fromrow = i;
  1477. }
  1478. }
  1479. if (dgv.Rows[i].Visible && addrowid)
  1480. {
  1481. dgv.Rows[i].Cells[0].Value = Conversions.ToString(num);
  1482. num++;
  1483. }
  1484. }
  1485. if (Operators.CompareString(myhzcolumns ?? "", "", TextCompare: false) == 0)
  1486. {
  1487. CreateHzRow(dgv, groupcolumn, myhzcolumns, hzfont, hzforecolor, hzbackcolor, fromrow, dgv.RowCount - 1, SumNumberAlign);
  1488. }
  1489. else
  1490. {
  1491. CreateHzRow(dgv, groupcolumn, myhzcolumns, hzfont, hzforecolor, hzbackcolor, fromrow, dgv.RowCount - 1 - 1, SumNumberAlign);
  1492. }
  1493. }
  1494. }
  1495. private static bool CreateHzRow(DataGridView dgv, string groupcolumn, string myhzcolumns, Font hzfont, Color hzforecolor, Color hzbackcolor, int fromrow, int torow, StringAlignment SumNumberAlign)
  1496. {
  1497. checked
  1498. {
  1499. int num = torow + 1;
  1500. decimal num2 = 0m;
  1501. if (Operators.CompareString(myhzcolumns ?? "", "", TextCompare: false) == 0)
  1502. {
  1503. dgv.Rows[torow].Cells[groupcolumn].Tag = "分组";
  1504. return false;
  1505. }
  1506. string[] array = Strings.Split(myhzcolumns, ";");
  1507. if (array.Length < 1)
  1508. {
  1509. return false;
  1510. }
  1511. int num3 = 0;
  1512. for (int i = fromrow; i <= torow; i++)
  1513. {
  1514. if (dgv.Rows[i].Visible)
  1515. {
  1516. num3++;
  1517. }
  1518. }
  1519. if (num3 == 0)
  1520. {
  1521. return false;
  1522. }
  1523. if (num >= dgv.RowCount)
  1524. {
  1525. dgv.Rows.Add();
  1526. }
  1527. else
  1528. {
  1529. dgv.Rows.Insert(num);
  1530. }
  1531. int num4 = 0;
  1532. int num5 = array.Length - 1;
  1533. string text;
  1534. for (int j = num4; j <= num5; j++)
  1535. {
  1536. num2 = 0m;
  1537. try
  1538. {
  1539. for (int k = fromrow; k <= torow; k++)
  1540. {
  1541. if (dgv.Rows[k].Visible)
  1542. {
  1543. text = Conversions.ToString(dgv.Rows[k].Cells[array[j]].Value);
  1544. if (Versioned.IsNumeric(text))
  1545. {
  1546. num2 = decimal.Add(num2, Conversions.ToDecimal(text));
  1547. }
  1548. }
  1549. }
  1550. if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[j]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
  1551. {
  1552. dgv.Rows[num].Cells[array[j]].Value = false;
  1553. }
  1554. else if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[j]]), "DataGridViewImageColumn", TextCompare: false) == 0)
  1555. {
  1556. dgv.Rows[num].Cells[array[j]].Value = null;
  1557. }
  1558. else if (decimal.Compare(new decimal(Convert.ToInt64(num2)), num2) == 0)
  1559. {
  1560. dgv.Rows[num].Cells[array[j]].Value = Conversions.ToString(num2);
  1561. }
  1562. else
  1563. {
  1564. dgv.Rows[num].Cells[array[j]].Value = Conversions.ToString(num2);
  1565. }
  1566. }
  1567. catch (Exception projectError)
  1568. {
  1569. ProjectData.SetProjectError(projectError);
  1570. if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[j]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
  1571. {
  1572. dgv.Rows[num].Cells[array[j]].Value = false;
  1573. }
  1574. else if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[j]]), "DataGridViewImageColumn", TextCompare: false) == 0)
  1575. {
  1576. dgv.Rows[num].Cells[array[j]].Value = null;
  1577. }
  1578. else
  1579. {
  1580. dgv.Rows[num].Cells[array[j]].Value = "";
  1581. }
  1582. ProjectData.ClearProjectError();
  1583. }
  1584. }
  1585. if (hzfont != null)
  1586. {
  1587. dgv.Rows[num].DefaultCellStyle.Font = hzfont;
  1588. }
  1589. if (hzforecolor.ToArgb() != 0)
  1590. {
  1591. dgv.Rows[num].DefaultCellStyle.ForeColor = hzforecolor;
  1592. }
  1593. if (hzbackcolor.ToArgb() != 0)
  1594. {
  1595. dgv.Rows[num].DefaultCellStyle.BackColor = hzbackcolor;
  1596. }
  1597. dgv.Rows[num].Cells[groupcolumn].Value = RuntimeHelpers.GetObjectValue(dgv.Rows[fromrow].Cells[groupcolumn].Value);
  1598. dgv.Rows[num].Cells[groupcolumn].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  1599. text = GetDGVFirstColumnName(dgv);
  1600. if (Operators.CompareString(text, "", TextCompare: false) != 0)
  1601. {
  1602. dgv.Rows[num].Cells[text].Value = "小计";
  1603. }
  1604. dgv.Rows[num].Cells[text].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
  1605. dgv.Rows[num].Cells[groupcolumn].Tag = "分组";
  1606. switch (SumNumberAlign)
  1607. {
  1608. case StringAlignment.Near:
  1609. dgv.Rows[num].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
  1610. break;
  1611. case StringAlignment.Center:
  1612. dgv.Rows[num].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  1613. break;
  1614. case StringAlignment.Far:
  1615. dgv.Rows[num].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
  1616. break;
  1617. }
  1618. return true;
  1619. }
  1620. }
  1621. public static string GetDGVFirstColumnName(DataGridView dgv)
  1622. {
  1623. string result = "";
  1624. int num = -1;
  1625. int num2 = 0;
  1626. checked
  1627. {
  1628. int num3 = dgv.ColumnCount - 1;
  1629. for (int i = num2; i <= num3; i++)
  1630. {
  1631. if (num == -1)
  1632. {
  1633. if (dgv.Columns[i].Visible)
  1634. {
  1635. num = dgv.Columns[i].DisplayIndex;
  1636. result = dgv.Columns[i].Name;
  1637. }
  1638. }
  1639. else if (dgv.Columns[i].Visible && dgv.Columns[i].DisplayIndex < num)
  1640. {
  1641. num = dgv.Columns[i].DisplayIndex;
  1642. result = dgv.Columns[i].Name;
  1643. }
  1644. }
  1645. return result;
  1646. }
  1647. }
  1648. public static bool IsHzColumn(string myhzcolumns, string columname)
  1649. {
  1650. if (Operators.CompareString(myhzcolumns, "", TextCompare: false) == 0 || myhzcolumns == null)
  1651. {
  1652. return false;
  1653. }
  1654. string[] array = Strings.Split(myhzcolumns, ";");
  1655. if (array.Length <= 0)
  1656. {
  1657. return false;
  1658. }
  1659. int num = 0;
  1660. checked
  1661. {
  1662. int num2 = array.Length - 1;
  1663. for (int i = num; i <= num2; i++)
  1664. {
  1665. if (Operators.CompareString(array[i], columname, TextCompare: false) == 0)
  1666. {
  1667. return true;
  1668. }
  1669. }
  1670. return false;
  1671. }
  1672. }
  1673. public static bool IsValidPrinterName(string printername)
  1674. {
  1675. bool result = false;
  1676. try
  1677. {
  1678. IEnumerator enumerator = PrinterSettings.InstalledPrinters.GetEnumerator();
  1679. while (enumerator.MoveNext())
  1680. {
  1681. string str = Conversions.ToString(enumerator.Current);
  1682. str = Strings.Trim(str);
  1683. if (Operators.CompareString(printername.ToLower(), str.ToLower(), TextCompare: false) == 0)
  1684. {
  1685. result = true;
  1686. break;
  1687. }
  1688. }
  1689. }
  1690. finally
  1691. {
  1692. IEnumerator enumerator2 = null;
  1693. if (enumerator2 is IDisposable)
  1694. {
  1695. (enumerator2 as IDisposable).Dispose();
  1696. }
  1697. }
  1698. return result;
  1699. }
  1700. public static void CreatePaper(string printername, string papername, int width, int height)
  1701. {
  1702. PrinterSettings printerSettings = new PrinterSettings();
  1703. if (!IsValidPrinterName(printername))
  1704. {
  1705. printername = printerSettings.PrinterName;
  1706. }
  1707. PaperSize printForm = definepaper.GetPrintForm(printername, papername);
  1708. if (printForm != null)
  1709. {
  1710. if (checked((printForm.Width != (int)Math.Round(Convert.ToDouble(decimal.Multiply(new decimal(width), 10m)) / 2.54)) | (printForm.Height != (int)Math.Round(Convert.ToDouble(decimal.Multiply(new decimal(height), 10m)) / 2.54))))
  1711. {
  1712. definepaper.SetPrintForm(printername, papername, width, height);
  1713. }
  1714. }
  1715. else
  1716. {
  1717. definepaper.SetPrintForm(printername, papername, width, height);
  1718. }
  1719. }
  1720. public static bool IsValidPaper(string printername, string papername)
  1721. {
  1722. PrinterSettings printerSettings = new PrinterSettings();
  1723. if (!IsValidPrinterName(printername))
  1724. {
  1725. printername = printerSettings.PrinterName;
  1726. }
  1727. return definepaper.GetPrintForm(printername, papername) != null;
  1728. }
  1729. public static int ConvertPixlsToTwips(float x, bool isx)
  1730. {
  1731. float num = (float)((double)G_ruler.ConvertToMM(x, isx) * 56.7);
  1732. return checked((int)Math.Round(num));
  1733. }
  1734. public static float ConvertTwipsToPixls(float x, bool isx)
  1735. {
  1736. _ = (double)x / 56.7;
  1737. return (float)((double)G_ruler.ConvertFromMM(x, isx) * 5.67);
  1738. }
  1739. public static float ConvertInchToCm(float xx)
  1740. {
  1741. return (float)((double)xx * 2.54);
  1742. }
  1743. public static float ConvertInchToMm(float xx)
  1744. {
  1745. return (float)((double)xx * 25.4);
  1746. }
  1747. public static float ConvertCmToInch(float xx)
  1748. {
  1749. return (float)((double)xx / 2.54);
  1750. }
  1751. public static float ConvertMmToInch(float xx)
  1752. {
  1753. return (float)((double)xx / 25.4);
  1754. }
  1755. public static string ConvertImageToString(string picturefile)
  1756. {
  1757. checked
  1758. {
  1759. string result;
  1760. try
  1761. {
  1762. FileStream fileStream = new FileStream(picturefile, FileMode.Open, FileAccess.Read, FileShare.Read);
  1763. byte[] array = new byte[(int)(fileStream.Length - 1) + 1];
  1764. fileStream.Read(array, 0, (int)fileStream.Length);
  1765. fileStream.Close();
  1766. result = Convert.ToBase64String(array);
  1767. }
  1768. catch (Exception projectError)
  1769. {
  1770. ProjectData.SetProjectError(projectError);
  1771. result = "";
  1772. ProjectData.ClearProjectError();
  1773. }
  1774. return result;
  1775. }
  1776. }
  1777. public static string ConvertImageToString(Image img)
  1778. {
  1779. string result;
  1780. if (img == null)
  1781. {
  1782. result = "";
  1783. }
  1784. else
  1785. {
  1786. try
  1787. {
  1788. string tempFileName = MyProject.Computer.FileSystem.GetTempFileName();
  1789. img.Save(tempFileName, ImageFormat.Png);
  1790. string text = ConvertImageToString(tempFileName);
  1791. try
  1792. {
  1793. MyProject.Computer.FileSystem.DeleteFile(tempFileName);
  1794. }
  1795. catch (Exception projectError)
  1796. {
  1797. ProjectData.SetProjectError(projectError);
  1798. ProjectData.ClearProjectError();
  1799. }
  1800. result = text;
  1801. }
  1802. catch (Exception projectError2)
  1803. {
  1804. ProjectData.SetProjectError(projectError2);
  1805. result = "";
  1806. ProjectData.ClearProjectError();
  1807. }
  1808. }
  1809. return result;
  1810. }
  1811. public static Image ConvertStringToImage(string picturestring)
  1812. {
  1813. Image result;
  1814. if (Operators.CompareString(picturestring ?? "", "", TextCompare: false) == 0)
  1815. {
  1816. result = null;
  1817. }
  1818. else
  1819. {
  1820. try
  1821. {
  1822. byte[] buffer = Convert.FromBase64String(picturestring);
  1823. MemoryStream stream = new MemoryStream(buffer);
  1824. result = Image.FromStream(stream);
  1825. }
  1826. catch (Exception projectError)
  1827. {
  1828. ProjectData.SetProjectError(projectError);
  1829. result = null;
  1830. ProjectData.ClearProjectError();
  1831. }
  1832. }
  1833. return result;
  1834. }
  1835. public static string ConvertIcoToString(Icon img)
  1836. {
  1837. checked
  1838. {
  1839. string result;
  1840. try
  1841. {
  1842. MemoryStream memoryStream = new MemoryStream();
  1843. img.Save(memoryStream);
  1844. memoryStream.Position = 0L;
  1845. byte[] array = new byte[(int)(memoryStream.Length - 1) + 1];
  1846. memoryStream.Read(array, 0, (int)memoryStream.Length);
  1847. memoryStream.Close();
  1848. result = Convert.ToBase64String(array);
  1849. }
  1850. catch (Exception projectError)
  1851. {
  1852. ProjectData.SetProjectError(projectError);
  1853. result = "";
  1854. ProjectData.ClearProjectError();
  1855. }
  1856. return result;
  1857. }
  1858. }
  1859. public static Icon ConvertStringToIcon(string picturestring)
  1860. {
  1861. Icon result;
  1862. if (Operators.CompareString(picturestring ?? "", "", TextCompare: false) == 0)
  1863. {
  1864. result = null;
  1865. }
  1866. else
  1867. {
  1868. try
  1869. {
  1870. byte[] buffer = Convert.FromBase64String(picturestring);
  1871. MemoryStream stream = new MemoryStream(buffer);
  1872. result = new Icon(stream);
  1873. }
  1874. catch (Exception projectError)
  1875. {
  1876. ProjectData.SetProjectError(projectError);
  1877. result = null;
  1878. ProjectData.ClearProjectError();
  1879. }
  1880. }
  1881. return result;
  1882. }
  1883. private static DataGridView ConvertListViewToDGV2(ListView lv)
  1884. {
  1885. if (lv == null)
  1886. {
  1887. return null;
  1888. }
  1889. DataGridView dataGridView = new DataGridView();
  1890. dataGridView.AllowUserToAddRows = false;
  1891. dataGridView.RowCount = lv.Items.Count;
  1892. dataGridView.ColumnCount = lv.Columns.Count;
  1893. try
  1894. {
  1895. dataGridView.DefaultCellStyle.Font = (Font)lv.Font.Clone();
  1896. }
  1897. catch (Exception projectError)
  1898. {
  1899. ProjectData.SetProjectError(projectError);
  1900. ProjectData.ClearProjectError();
  1901. }
  1902. dataGridView.ForeColor = lv.ForeColor;
  1903. dataGridView.DefaultCellStyle.ForeColor = lv.ForeColor;
  1904. int num = 0;
  1905. checked
  1906. {
  1907. int num2 = lv.Columns.Count - 1;
  1908. for (int i = num; i <= num2; i++)
  1909. {
  1910. dataGridView.Columns[i].HeaderText = lv.Columns[i].Text;
  1911. try
  1912. {
  1913. dataGridView.Columns[i].DefaultCellStyle.Font = (Font)lv.Font.Clone();
  1914. }
  1915. catch (Exception projectError2)
  1916. {
  1917. ProjectData.SetProjectError(projectError2);
  1918. ProjectData.ClearProjectError();
  1919. }
  1920. dataGridView.Columns[i].Width = lv.Columns[i].Width;
  1921. dataGridView.Columns[i].DisplayIndex = lv.Columns[i].DisplayIndex;
  1922. }
  1923. int num3 = 0;
  1924. int num4 = lv.Items.Count - 1;
  1925. for (int j = num3; j <= num4; j++)
  1926. {
  1927. CopyListViewItemToDGV(lv, lv.Items[j], dataGridView.Rows[j]);
  1928. }
  1929. return dataGridView;
  1930. }
  1931. }
  1932. public static DataGridView ConvertListViewToDGV(ListView lv)
  1933. {
  1934. if (lv == null)
  1935. {
  1936. return null;
  1937. }
  1938. if (!lv.ShowGroups)
  1939. {
  1940. return ConvertListViewToDGV2(lv);
  1941. }
  1942. DataGridView dataGridView = new DataGridView();
  1943. dataGridView.ColumnCount = lv.Columns.Count;
  1944. dataGridView.AllowUserToAddRows = false;
  1945. try
  1946. {
  1947. dataGridView.DefaultCellStyle.Font = (Font)lv.Font.Clone();
  1948. }
  1949. catch (Exception projectError)
  1950. {
  1951. ProjectData.SetProjectError(projectError);
  1952. ProjectData.ClearProjectError();
  1953. }
  1954. dataGridView.ForeColor = lv.ForeColor;
  1955. dataGridView.DefaultCellStyle.ForeColor = lv.ForeColor;
  1956. int num = 0;
  1957. checked
  1958. {
  1959. int num2 = lv.Columns.Count - 1;
  1960. for (int i = num; i <= num2; i++)
  1961. {
  1962. dataGridView.Columns[i].HeaderText = lv.Columns[i].Text;
  1963. try
  1964. {
  1965. dataGridView.Columns[i].DefaultCellStyle.Font = (Font)lv.Font.Clone();
  1966. }
  1967. catch (Exception projectError2)
  1968. {
  1969. ProjectData.SetProjectError(projectError2);
  1970. ProjectData.ClearProjectError();
  1971. }
  1972. dataGridView.Columns[i].Width = lv.Columns[i].Width;
  1973. dataGridView.Columns[i].DisplayIndex = lv.Columns[i].DisplayIndex;
  1974. }
  1975. bool flag = false;
  1976. int num3 = 0;
  1977. int num4 = lv.Items.Count - 1;
  1978. for (int j = num3; j <= num4; j++)
  1979. {
  1980. if (lv.Items[j].Group == null)
  1981. {
  1982. flag = true;
  1983. break;
  1984. }
  1985. }
  1986. if (flag)
  1987. {
  1988. dataGridView.RowCount++;
  1989. DataGridViewRow currow = dataGridView.Rows[dataGridView.RowCount - 1];
  1990. CopyListViewGroutItemToDGV(lv, "Default", HorizontalAlignment.Left, currow);
  1991. int num5 = 0;
  1992. int num6 = lv.Items.Count - 1;
  1993. for (int k = num5; k <= num6; k++)
  1994. {
  1995. if (lv.Items[k].Group == null)
  1996. {
  1997. dataGridView.RowCount++;
  1998. currow = dataGridView.Rows[dataGridView.RowCount - 1];
  1999. CopyListViewItemToDGV(lv, lv.Items[k], currow);
  2000. }
  2001. }
  2002. }
  2003. int num7 = 0;
  2004. int num8 = lv.Groups.Count - 1;
  2005. for (int l = num7; l <= num8; l++)
  2006. {
  2007. if (lv.Groups[l].Items.Count > 0)
  2008. {
  2009. dataGridView.RowCount++;
  2010. DataGridViewRow currow2 = dataGridView.Rows[dataGridView.RowCount - 1];
  2011. CopyListViewGroutItemToDGV(lv, lv.Groups[l].Header, lv.Groups[l].HeaderAlignment, currow2);
  2012. int num9 = 0;
  2013. int num10 = lv.Groups[l].Items.Count - 1;
  2014. for (int m = num9; m <= num10; m++)
  2015. {
  2016. dataGridView.RowCount++;
  2017. currow2 = dataGridView.Rows[dataGridView.RowCount - 1];
  2018. CopyListViewItemToDGV(lv, lv.Groups[l].Items[m], currow2);
  2019. }
  2020. }
  2021. }
  2022. return dataGridView;
  2023. }
  2024. }
  2025. private static void CopyListViewGroutItemToDGV(ListView lv, string mygroupname, HorizontalAlignment alg, DataGridViewRow currow)
  2026. {
  2027. try
  2028. {
  2029. currow.DefaultCellStyle.Font = new Font(lv.Font, FontStyle.Bold);
  2030. currow.DefaultCellStyle.ForeColor = Color.Black;
  2031. }
  2032. catch (Exception projectError)
  2033. {
  2034. ProjectData.SetProjectError(projectError);
  2035. ProjectData.ClearProjectError();
  2036. }
  2037. switch (alg)
  2038. {
  2039. case HorizontalAlignment.Right:
  2040. currow.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
  2041. break;
  2042. case HorizontalAlignment.Center:
  2043. currow.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  2044. break;
  2045. default:
  2046. currow.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
  2047. break;
  2048. }
  2049. int num = 0;
  2050. checked
  2051. {
  2052. int num2 = lv.Columns.Count - 1;
  2053. for (int i = num; i <= num2; i++)
  2054. {
  2055. currow.Cells[i].Value = mygroupname;
  2056. currow.Cells[i].Tag = "水平合并";
  2057. }
  2058. }
  2059. }
  2060. private static void CopyListViewItemToDGV(ListView lv, ListViewItem myitem, DataGridViewRow myrow)
  2061. {
  2062. string text = myitem.Text;
  2063. if (lv.CheckBoxes)
  2064. {
  2065. text = ((!myitem.Checked) ? ("□ " + text) : ("■ " + text));
  2066. }
  2067. myrow.Cells[0].Value = text;
  2068. try
  2069. {
  2070. myrow.Cells[0].Style.Font = (Font)myitem.Font.Clone();
  2071. }
  2072. catch (Exception projectError)
  2073. {
  2074. ProjectData.SetProjectError(projectError);
  2075. ProjectData.ClearProjectError();
  2076. }
  2077. myrow.Cells[0].Style.ForeColor = myitem.ForeColor;
  2078. myrow.Cells[0].Style.BackColor = myitem.BackColor;
  2079. try
  2080. {
  2081. myrow.DefaultCellStyle.Font = (Font)myitem.Font.Clone();
  2082. }
  2083. catch (Exception projectError2)
  2084. {
  2085. ProjectData.SetProjectError(projectError2);
  2086. ProjectData.ClearProjectError();
  2087. }
  2088. myrow.DefaultCellStyle.BackColor = myitem.BackColor;
  2089. myrow.DefaultCellStyle.ForeColor = myitem.ForeColor;
  2090. int num = 1;
  2091. checked
  2092. {
  2093. int num2 = lv.Columns.Count - 1;
  2094. for (int i = num; i <= num2; i++)
  2095. {
  2096. if (i >= myitem.SubItems.Count)
  2097. {
  2098. continue;
  2099. }
  2100. myrow.Cells[i].Value = myitem.SubItems[i].Text;
  2101. if (!myitem.UseItemStyleForSubItems)
  2102. {
  2103. try
  2104. {
  2105. myrow.Cells[i].Style.Font = (Font)myitem.SubItems[i].Font.Clone();
  2106. }
  2107. catch (Exception projectError3)
  2108. {
  2109. ProjectData.SetProjectError(projectError3);
  2110. ProjectData.ClearProjectError();
  2111. }
  2112. myrow.Cells[i].Style.ForeColor = myitem.SubItems[i].ForeColor;
  2113. myrow.Cells[i].Style.BackColor = myitem.SubItems[i].BackColor;
  2114. }
  2115. }
  2116. }
  2117. }
  2118. public static string SaveHashTableAsString(Hashtable hh)
  2119. {
  2120. string text = "\u0003";
  2121. string text2 = "\a";
  2122. if (hh == null)
  2123. {
  2124. return "";
  2125. }
  2126. string[,] array = mbsjmodule.ParaseVar(hh);
  2127. string text3 = "";
  2128. if (array == null)
  2129. {
  2130. return "";
  2131. }
  2132. int num = 0;
  2133. checked
  2134. {
  2135. int num2 = array.GetLength(0) - 1;
  2136. for (int i = num; i <= num2; i++)
  2137. {
  2138. text3 = ((i != 0) ? (text3 + text + array[i, 0] + text2 + array[i, 1]) : (array[i, 0] + text2 + array[i, 1]));
  2139. }
  2140. return text3;
  2141. }
  2142. }
  2143. public static Hashtable RestoreHashTableFromString(string ss)
  2144. {
  2145. if (Operators.CompareString(ss, "", TextCompare: false) == 0)
  2146. {
  2147. return null;
  2148. }
  2149. string delimiter = "\u0003";
  2150. string delimiter2 = "\a";
  2151. string[] array = Strings.Split(ss, delimiter);
  2152. Hashtable hashtable = new Hashtable();
  2153. int num = 0;
  2154. checked
  2155. {
  2156. int num2 = array.Length - 1;
  2157. for (int i = num; i <= num2; i++)
  2158. {
  2159. string[] array2 = Strings.Split(array[i], delimiter2);
  2160. hashtable.Add(array2[0], array2[1]);
  2161. }
  2162. return hashtable;
  2163. }
  2164. }
  2165. public static Font GetDGVHeaderFont(DataGridViewColumn mycolumn)
  2166. {
  2167. DataGridView dataGridView = mycolumn.DataGridView;
  2168. if (mycolumn.HeaderCell.Style.Font != null)
  2169. {
  2170. return mycolumn.HeaderCell.Style.Font;
  2171. }
  2172. if (dataGridView.ColumnHeadersDefaultCellStyle.Font == null)
  2173. {
  2174. return dataGridView.DefaultCellStyle.Font;
  2175. }
  2176. return dataGridView.ColumnHeadersDefaultCellStyle.Font;
  2177. }
  2178. public static Color GetDGVHeaderForeColor(DataGridViewColumn mycolumn)
  2179. {
  2180. DataGridView dataGridView = mycolumn.DataGridView;
  2181. if (mycolumn.HeaderCell.Style.ForeColor.ToArgb() == 0)
  2182. {
  2183. if (dataGridView.ColumnHeadersDefaultCellStyle.ForeColor.ToArgb() == 0)
  2184. {
  2185. return dataGridView.DefaultCellStyle.ForeColor;
  2186. }
  2187. return dataGridView.ColumnHeadersDefaultCellStyle.ForeColor;
  2188. }
  2189. return mycolumn.HeaderCell.Style.ForeColor;
  2190. }
  2191. public static bool GetDGVHeaderMulline(DataGridViewColumn mycolumn)
  2192. {
  2193. DataGridView dataGridView = mycolumn.DataGridView;
  2194. if (mycolumn.HeaderCell.Style.WrapMode == DataGridViewTriState.NotSet)
  2195. {
  2196. if (dataGridView.ColumnHeadersDefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
  2197. {
  2198. return GetMulline(dataGridView.DefaultCellStyle.WrapMode);
  2199. }
  2200. return GetMulline(dataGridView.ColumnHeadersDefaultCellStyle.WrapMode);
  2201. }
  2202. return GetMulline(mycolumn.HeaderCell.Style.WrapMode);
  2203. }
  2204. public static Color GetDGVHeaderBackColor(DataGridViewColumn mycolumn)
  2205. {
  2206. DataGridView dataGridView = mycolumn.DataGridView;
  2207. if (mycolumn.HeaderCell.Style.BackColor.ToArgb() == 0)
  2208. {
  2209. if (dataGridView.ColumnHeadersDefaultCellStyle.BackColor.ToArgb() == 0)
  2210. {
  2211. return dataGridView.DefaultCellStyle.BackColor;
  2212. }
  2213. return dataGridView.ColumnHeadersDefaultCellStyle.BackColor;
  2214. }
  2215. return mycolumn.HeaderCell.Style.BackColor;
  2216. }
  2217. public static Font GetDGVCellFont(DataGridViewCell mycell)
  2218. {
  2219. DataGridView dataGridView = mycell.DataGridView;
  2220. int rowIndex = mycell.RowIndex;
  2221. DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
  2222. DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
  2223. Font result;
  2224. try
  2225. {
  2226. result = ((dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Font != null) ? dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Font : ((dataGridViewRow.DefaultCellStyle.Font != null) ? dataGridViewRow.DefaultCellStyle.Font : ((checked(rowIndex + 1) % 2 == 0) ? ((dataGridView.AlternatingRowsDefaultCellStyle.Font != null) ? dataGridView.AlternatingRowsDefaultCellStyle.Font : ((dataGridView.RowsDefaultCellStyle.Font != null) ? dataGridView.RowsDefaultCellStyle.Font : ((dataGridViewColumn.DefaultCellStyle.Font != null) ? dataGridViewColumn.DefaultCellStyle.Font : dataGridView.DefaultCellStyle.Font))) : ((dataGridView.RowsDefaultCellStyle.Font != null) ? dataGridView.RowsDefaultCellStyle.Font : ((dataGridViewColumn.DefaultCellStyle.Font != null) ? dataGridViewColumn.DefaultCellStyle.Font : dataGridView.DefaultCellStyle.Font)))));
  2227. }
  2228. catch (Exception projectError)
  2229. {
  2230. ProjectData.SetProjectError(projectError);
  2231. result = dataGridView.DefaultCellStyle.Font;
  2232. ProjectData.ClearProjectError();
  2233. }
  2234. dataGridView = null;
  2235. return result;
  2236. }
  2237. public static Color GetDGVCellForeColor(DataGridViewCell mycell)
  2238. {
  2239. DataGridView dataGridView = mycell.DataGridView;
  2240. int rowIndex = mycell.RowIndex;
  2241. DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
  2242. DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
  2243. if (dataGridViewRow.Cells[dataGridViewColumn.Index].Style.ForeColor.ToArgb() == 0)
  2244. {
  2245. if (dataGridViewRow.DefaultCellStyle.ForeColor.ToArgb() == 0)
  2246. {
  2247. if (checked(rowIndex + 1) % 2 == 0)
  2248. {
  2249. if (dataGridView.AlternatingRowsDefaultCellStyle.ForeColor.ToArgb() == 0)
  2250. {
  2251. if (dataGridView.RowsDefaultCellStyle.ForeColor.ToArgb() == 0)
  2252. {
  2253. if (dataGridViewColumn.DefaultCellStyle.ForeColor.ToArgb() == 0)
  2254. {
  2255. return dataGridView.DefaultCellStyle.ForeColor;
  2256. }
  2257. return dataGridViewColumn.DefaultCellStyle.ForeColor;
  2258. }
  2259. return dataGridView.RowsDefaultCellStyle.ForeColor;
  2260. }
  2261. return dataGridView.AlternatingRowsDefaultCellStyle.ForeColor;
  2262. }
  2263. if (dataGridView.RowsDefaultCellStyle.ForeColor.ToArgb() == 0)
  2264. {
  2265. if (dataGridViewColumn.DefaultCellStyle.ForeColor.ToArgb() == 0)
  2266. {
  2267. return dataGridView.DefaultCellStyle.ForeColor;
  2268. }
  2269. return dataGridViewColumn.DefaultCellStyle.ForeColor;
  2270. }
  2271. return dataGridView.RowsDefaultCellStyle.ForeColor;
  2272. }
  2273. return dataGridViewRow.DefaultCellStyle.ForeColor;
  2274. }
  2275. return dataGridViewRow.Cells[dataGridViewColumn.Index].Style.ForeColor;
  2276. }
  2277. public static Color GetDGVCellBackColor(DataGridViewCell mycell)
  2278. {
  2279. DataGridView dataGridView = mycell.DataGridView;
  2280. int rowIndex = mycell.RowIndex;
  2281. DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
  2282. DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
  2283. if (dataGridViewRow.Cells[dataGridViewColumn.Index].Style.BackColor.ToArgb() == 0)
  2284. {
  2285. if (dataGridViewRow.DefaultCellStyle.BackColor.ToArgb() == 0)
  2286. {
  2287. if (checked(rowIndex + 1) % 2 == 0)
  2288. {
  2289. if (dataGridView.AlternatingRowsDefaultCellStyle.BackColor.ToArgb() == 0)
  2290. {
  2291. if (dataGridView.RowsDefaultCellStyle.BackColor.ToArgb() == 0)
  2292. {
  2293. if (dataGridViewColumn.DefaultCellStyle.BackColor.ToArgb() == 0)
  2294. {
  2295. return dataGridView.DefaultCellStyle.BackColor;
  2296. }
  2297. return dataGridViewColumn.DefaultCellStyle.BackColor;
  2298. }
  2299. return dataGridView.RowsDefaultCellStyle.BackColor;
  2300. }
  2301. return dataGridView.AlternatingRowsDefaultCellStyle.BackColor;
  2302. }
  2303. if (dataGridView.RowsDefaultCellStyle.BackColor.ToArgb() == 0)
  2304. {
  2305. if (dataGridViewColumn.DefaultCellStyle.BackColor.ToArgb() == 0)
  2306. {
  2307. return dataGridView.DefaultCellStyle.BackColor;
  2308. }
  2309. return dataGridViewColumn.DefaultCellStyle.BackColor;
  2310. }
  2311. return dataGridView.RowsDefaultCellStyle.BackColor;
  2312. }
  2313. return dataGridViewRow.DefaultCellStyle.BackColor;
  2314. }
  2315. return dataGridViewRow.Cells[dataGridViewColumn.Index].Style.BackColor;
  2316. }
  2317. public static bool GetDGVCellMulline(DataGridViewCell mycell)
  2318. {
  2319. DataGridView dataGridView = mycell.DataGridView;
  2320. int rowIndex = mycell.RowIndex;
  2321. DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
  2322. DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
  2323. if (dataGridViewRow.Cells[dataGridViewColumn.Index].Style.WrapMode == DataGridViewTriState.NotSet)
  2324. {
  2325. if (dataGridViewRow.DefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
  2326. {
  2327. if (checked(rowIndex + 1) % 2 == 0)
  2328. {
  2329. if (dataGridView.AlternatingRowsDefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
  2330. {
  2331. if (dataGridView.RowsDefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
  2332. {
  2333. if (dataGridViewColumn.DefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
  2334. {
  2335. return GetMulline(dataGridView.DefaultCellStyle.WrapMode);
  2336. }
  2337. return GetMulline(dataGridViewColumn.DefaultCellStyle.WrapMode);
  2338. }
  2339. return GetMulline(dataGridView.RowsDefaultCellStyle.WrapMode);
  2340. }
  2341. return GetMulline(dataGridView.AlternatingRowsDefaultCellStyle.WrapMode);
  2342. }
  2343. if (dataGridView.RowsDefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
  2344. {
  2345. if (dataGridViewColumn.DefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
  2346. {
  2347. return GetMulline(dataGridView.DefaultCellStyle.WrapMode);
  2348. }
  2349. return GetMulline(dataGridViewColumn.DefaultCellStyle.WrapMode);
  2350. }
  2351. return GetMulline(dataGridView.RowsDefaultCellStyle.WrapMode);
  2352. }
  2353. return GetMulline(dataGridViewRow.DefaultCellStyle.WrapMode);
  2354. }
  2355. return GetMulline(dataGridViewRow.Cells[dataGridViewColumn.Index].Style.WrapMode);
  2356. }
  2357. public static Margins GetDGVCellPadding(DataGridViewCell mycell)
  2358. {
  2359. Margins margins = new Margins();
  2360. DataGridView dataGridView = mycell.DataGridView;
  2361. int rowIndex = mycell.RowIndex;
  2362. DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
  2363. DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
  2364. if (dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Padding.All == 0)
  2365. {
  2366. if (dataGridViewRow.DefaultCellStyle.Padding.All == 0)
  2367. {
  2368. if (checked(rowIndex + 1) % 2 == 0)
  2369. {
  2370. if (dataGridView.AlternatingRowsDefaultCellStyle.Padding.All == 0)
  2371. {
  2372. if (dataGridView.RowsDefaultCellStyle.Padding.All == 0)
  2373. {
  2374. if (dataGridViewColumn.DefaultCellStyle.Padding.All == 0)
  2375. {
  2376. margins.Left = dataGridView.DefaultCellStyle.Padding.Left;
  2377. margins.Top = dataGridView.DefaultCellStyle.Padding.Top;
  2378. margins.Right = dataGridView.DefaultCellStyle.Padding.Right;
  2379. margins.Bottom = dataGridView.DefaultCellStyle.Padding.Bottom;
  2380. }
  2381. else
  2382. {
  2383. margins.Left = dataGridViewColumn.DefaultCellStyle.Padding.Left;
  2384. margins.Top = dataGridViewColumn.DefaultCellStyle.Padding.Top;
  2385. margins.Right = dataGridViewColumn.DefaultCellStyle.Padding.Right;
  2386. margins.Bottom = dataGridViewColumn.DefaultCellStyle.Padding.Bottom;
  2387. }
  2388. }
  2389. else
  2390. {
  2391. margins.Left = dataGridView.RowsDefaultCellStyle.Padding.Left;
  2392. margins.Top = dataGridView.RowsDefaultCellStyle.Padding.Top;
  2393. margins.Right = dataGridView.RowsDefaultCellStyle.Padding.Right;
  2394. margins.Bottom = dataGridView.RowsDefaultCellStyle.Padding.Bottom;
  2395. }
  2396. }
  2397. else
  2398. {
  2399. margins.Left = dataGridView.AlternatingRowsDefaultCellStyle.Padding.Left;
  2400. margins.Top = dataGridView.AlternatingRowsDefaultCellStyle.Padding.Top;
  2401. margins.Right = dataGridView.AlternatingRowsDefaultCellStyle.Padding.Right;
  2402. margins.Bottom = dataGridView.AlternatingRowsDefaultCellStyle.Padding.Bottom;
  2403. }
  2404. }
  2405. else if (dataGridView.RowsDefaultCellStyle.Padding.All == 0)
  2406. {
  2407. if (dataGridViewColumn.DefaultCellStyle.Padding.All == 0)
  2408. {
  2409. margins.Left = dataGridView.DefaultCellStyle.Padding.Left;
  2410. margins.Top = dataGridView.DefaultCellStyle.Padding.Top;
  2411. margins.Right = dataGridView.DefaultCellStyle.Padding.Right;
  2412. margins.Bottom = dataGridView.DefaultCellStyle.Padding.Bottom;
  2413. }
  2414. else
  2415. {
  2416. margins.Left = dataGridViewColumn.DefaultCellStyle.Padding.Left;
  2417. margins.Top = dataGridViewColumn.DefaultCellStyle.Padding.Top;
  2418. margins.Right = dataGridViewColumn.DefaultCellStyle.Padding.Right;
  2419. margins.Bottom = dataGridViewColumn.DefaultCellStyle.Padding.Bottom;
  2420. }
  2421. }
  2422. else
  2423. {
  2424. margins.Left = dataGridView.RowsDefaultCellStyle.Padding.Left;
  2425. margins.Top = dataGridView.RowsDefaultCellStyle.Padding.Top;
  2426. margins.Right = dataGridView.RowsDefaultCellStyle.Padding.Right;
  2427. margins.Bottom = dataGridView.RowsDefaultCellStyle.Padding.Bottom;
  2428. }
  2429. }
  2430. else
  2431. {
  2432. margins.Left = dataGridViewRow.DefaultCellStyle.Padding.Left;
  2433. margins.Top = dataGridViewRow.DefaultCellStyle.Padding.Top;
  2434. margins.Right = dataGridViewRow.DefaultCellStyle.Padding.Right;
  2435. margins.Bottom = dataGridViewRow.DefaultCellStyle.Padding.Bottom;
  2436. }
  2437. }
  2438. else
  2439. {
  2440. margins.Left = dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Padding.Left;
  2441. margins.Top = dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Padding.Top;
  2442. margins.Right = dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Padding.Right;
  2443. margins.Bottom = dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Padding.Bottom;
  2444. }
  2445. return margins;
  2446. }
  2447. public static DataGridViewCellStyle GetDGVCellStyle(DataGridViewCell mycell)
  2448. {
  2449. DataGridView dataGridView = mycell.DataGridView;
  2450. int rowIndex = mycell.RowIndex;
  2451. DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
  2452. DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
  2453. if (dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Alignment == DataGridViewContentAlignment.NotSet)
  2454. {
  2455. if (dataGridViewRow.DefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
  2456. {
  2457. if (checked(rowIndex + 1) % 2 == 0)
  2458. {
  2459. if (dataGridView.AlternatingRowsDefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
  2460. {
  2461. if (dataGridView.RowsDefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
  2462. {
  2463. if (dataGridViewColumn.DefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
  2464. {
  2465. return dataGridView.DefaultCellStyle;
  2466. }
  2467. return dataGridViewColumn.DefaultCellStyle;
  2468. }
  2469. return dataGridView.RowsDefaultCellStyle;
  2470. }
  2471. return dataGridView.AlternatingRowsDefaultCellStyle;
  2472. }
  2473. if (dataGridView.RowsDefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
  2474. {
  2475. if (dataGridViewColumn.DefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
  2476. {
  2477. return dataGridView.DefaultCellStyle;
  2478. }
  2479. return dataGridViewColumn.DefaultCellStyle;
  2480. }
  2481. return dataGridView.RowsDefaultCellStyle;
  2482. }
  2483. return dataGridViewRow.DefaultCellStyle;
  2484. }
  2485. return dataGridViewRow.Cells[dataGridViewColumn.Index].Style;
  2486. }
  2487. public static StringAlignment GetHAlignment(DataGridViewContentAlignment mytt)
  2488. {
  2489. switch (mytt)
  2490. {
  2491. default:
  2492. return StringAlignment.Near;
  2493. case DataGridViewContentAlignment.TopRight:
  2494. case DataGridViewContentAlignment.MiddleRight:
  2495. case DataGridViewContentAlignment.BottomRight:
  2496. return StringAlignment.Far;
  2497. case DataGridViewContentAlignment.NotSet:
  2498. case DataGridViewContentAlignment.TopLeft:
  2499. case DataGridViewContentAlignment.MiddleLeft:
  2500. case DataGridViewContentAlignment.BottomLeft:
  2501. return StringAlignment.Near;
  2502. case DataGridViewContentAlignment.TopCenter:
  2503. case DataGridViewContentAlignment.MiddleCenter:
  2504. case DataGridViewContentAlignment.BottomCenter:
  2505. return StringAlignment.Center;
  2506. }
  2507. }
  2508. public static StringAlignment GetVAlignment(DataGridViewContentAlignment mytt, bool IsDGVCellValignmentCenter)
  2509. {
  2510. if (IsDGVCellValignmentCenter)
  2511. {
  2512. return StringAlignment.Center;
  2513. }
  2514. switch (mytt)
  2515. {
  2516. default:
  2517. return StringAlignment.Center;
  2518. case DataGridViewContentAlignment.NotSet:
  2519. case DataGridViewContentAlignment.TopLeft:
  2520. case DataGridViewContentAlignment.TopCenter:
  2521. case DataGridViewContentAlignment.TopRight:
  2522. return StringAlignment.Near;
  2523. case DataGridViewContentAlignment.MiddleLeft:
  2524. case DataGridViewContentAlignment.MiddleCenter:
  2525. case DataGridViewContentAlignment.MiddleRight:
  2526. return StringAlignment.Center;
  2527. case DataGridViewContentAlignment.BottomLeft:
  2528. case DataGridViewContentAlignment.BottomCenter:
  2529. case DataGridViewContentAlignment.BottomRight:
  2530. return StringAlignment.Far;
  2531. }
  2532. }
  2533. public static bool GetMulline(DataGridViewTriState mytt)
  2534. {
  2535. switch (mytt)
  2536. {
  2537. case DataGridViewTriState.NotSet:
  2538. case DataGridViewTriState.False:
  2539. return false;
  2540. default:
  2541. return true;
  2542. }
  2543. }
  2544. public static Font GetDGVColumnHeaderFont(DataGridView dgv, string colname)
  2545. {
  2546. if (dgv == null)
  2547. {
  2548. return null;
  2549. }
  2550. DataGridViewColumn dataGridViewColumn;
  2551. try
  2552. {
  2553. dataGridViewColumn = dgv.Columns[colname];
  2554. }
  2555. catch (Exception projectError)
  2556. {
  2557. ProjectData.SetProjectError(projectError);
  2558. Font result = null;
  2559. ProjectData.ClearProjectError();
  2560. return result;
  2561. }
  2562. if (dataGridViewColumn == null)
  2563. {
  2564. return null;
  2565. }
  2566. return (dataGridViewColumn.HeaderCell.Style.Font != null) ? dataGridViewColumn.HeaderCell.Style.Font : ((dgv.ColumnHeadersDefaultCellStyle.Font != null) ? dgv.ColumnHeadersDefaultCellStyle.Font : dgv.DefaultCellStyle.Font);
  2567. }
  2568. public static Color GetDGVColumnHeaderForeColor(DataGridView dgv, string colname)
  2569. {
  2570. if (dgv == null)
  2571. {
  2572. return Color.Black;
  2573. }
  2574. DataGridViewColumn dataGridViewColumn;
  2575. try
  2576. {
  2577. dataGridViewColumn = dgv.Columns[colname];
  2578. }
  2579. catch (Exception projectError)
  2580. {
  2581. ProjectData.SetProjectError(projectError);
  2582. Color black = Color.Black;
  2583. ProjectData.ClearProjectError();
  2584. return black;
  2585. }
  2586. if (dataGridViewColumn == null)
  2587. {
  2588. return Color.Black;
  2589. }
  2590. return (dataGridViewColumn.HeaderCell.Style.ForeColor.ToArgb() != 0) ? dataGridViewColumn.HeaderCell.Style.ForeColor : ((dgv.ColumnHeadersDefaultCellStyle.ForeColor.ToArgb() != 0) ? dgv.ColumnHeadersDefaultCellStyle.ForeColor : dgv.DefaultCellStyle.ForeColor);
  2591. }
  2592. public static Color GetDGVColumnHeaderBackColor(DataGridView dgv, string colname)
  2593. {
  2594. if (dgv == null)
  2595. {
  2596. return Color.White;
  2597. }
  2598. DataGridViewColumn dataGridViewColumn;
  2599. try
  2600. {
  2601. dataGridViewColumn = dgv.Columns[colname];
  2602. }
  2603. catch (Exception projectError)
  2604. {
  2605. ProjectData.SetProjectError(projectError);
  2606. Color white = Color.White;
  2607. ProjectData.ClearProjectError();
  2608. return white;
  2609. }
  2610. if (dataGridViewColumn == null)
  2611. {
  2612. return Color.White;
  2613. }
  2614. return (dataGridViewColumn.HeaderCell.Style.BackColor.ToArgb() != 0) ? dataGridViewColumn.HeaderCell.Style.BackColor : ((dgv.ColumnHeadersDefaultCellStyle.BackColor.ToArgb() != 0) ? dgv.ColumnHeadersDefaultCellStyle.BackColor : dgv.DefaultCellStyle.BackColor);
  2615. }
  2616. public static Font GetDGVColumnFont(DataGridView dgv, string colname)
  2617. {
  2618. if (dgv == null)
  2619. {
  2620. return null;
  2621. }
  2622. DataGridViewColumn dataGridViewColumn;
  2623. try
  2624. {
  2625. dataGridViewColumn = dgv.Columns[colname];
  2626. }
  2627. catch (Exception projectError)
  2628. {
  2629. ProjectData.SetProjectError(projectError);
  2630. Font result = null;
  2631. ProjectData.ClearProjectError();
  2632. return result;
  2633. }
  2634. if (dataGridViewColumn == null)
  2635. {
  2636. return null;
  2637. }
  2638. return (dgv.RowsDefaultCellStyle.Font != null) ? dgv.RowsDefaultCellStyle.Font : ((dataGridViewColumn.DefaultCellStyle.Font != null) ? dataGridViewColumn.DefaultCellStyle.Font : dgv.DefaultCellStyle.Font);
  2639. }
  2640. public static Color GetDGVColumnForeColor(DataGridView dgv, string colname)
  2641. {
  2642. if (dgv == null)
  2643. {
  2644. return Color.Black;
  2645. }
  2646. DataGridViewColumn dataGridViewColumn;
  2647. try
  2648. {
  2649. dataGridViewColumn = dgv.Columns[colname];
  2650. }
  2651. catch (Exception projectError)
  2652. {
  2653. ProjectData.SetProjectError(projectError);
  2654. Color black = Color.Black;
  2655. ProjectData.ClearProjectError();
  2656. return black;
  2657. }
  2658. if (dataGridViewColumn == null)
  2659. {
  2660. return Color.Black;
  2661. }
  2662. return (dgv.RowsDefaultCellStyle.ForeColor.ToArgb() != 0) ? dgv.RowsDefaultCellStyle.ForeColor : ((dataGridViewColumn.DefaultCellStyle.ForeColor.ToArgb() != 0) ? dataGridViewColumn.DefaultCellStyle.ForeColor : dgv.DefaultCellStyle.ForeColor);
  2663. }
  2664. public static Color GetDGVColumnBackColor(DataGridView dgv, string colname)
  2665. {
  2666. if (dgv == null)
  2667. {
  2668. return Color.Black;
  2669. }
  2670. DataGridViewColumn dataGridViewColumn;
  2671. try
  2672. {
  2673. dataGridViewColumn = dgv.Columns[colname];
  2674. }
  2675. catch (Exception projectError)
  2676. {
  2677. ProjectData.SetProjectError(projectError);
  2678. Color black = Color.Black;
  2679. ProjectData.ClearProjectError();
  2680. return black;
  2681. }
  2682. if (dataGridViewColumn == null)
  2683. {
  2684. return Color.Black;
  2685. }
  2686. return (dgv.RowsDefaultCellStyle.BackColor.ToArgb() != 0) ? dgv.RowsDefaultCellStyle.BackColor : ((dataGridViewColumn.DefaultCellStyle.BackColor.ToArgb() != 0) ? dataGridViewColumn.DefaultCellStyle.BackColor : dgv.DefaultCellStyle.BackColor);
  2687. }
  2688. public static bool GetDGVColumnMulLine(DataGridView dgv, string colname)
  2689. {
  2690. if (dgv == null)
  2691. {
  2692. return false;
  2693. }
  2694. DataGridViewColumn dataGridViewColumn;
  2695. try
  2696. {
  2697. dataGridViewColumn = dgv.Columns[colname];
  2698. }
  2699. catch (Exception projectError)
  2700. {
  2701. ProjectData.SetProjectError(projectError);
  2702. bool result = false;
  2703. ProjectData.ClearProjectError();
  2704. return result;
  2705. }
  2706. if (dataGridViewColumn == null)
  2707. {
  2708. return false;
  2709. }
  2710. return (dgv.RowsDefaultCellStyle.WrapMode != 0) ? GetMulline(dgv.RowsDefaultCellStyle.WrapMode) : ((dataGridViewColumn.DefaultCellStyle.WrapMode != 0) ? GetMulline(dataGridViewColumn.DefaultCellStyle.WrapMode) : GetMulline(dgv.DefaultCellStyle.WrapMode));
  2711. }
  2712. public static ContentAlignment GetDGVColumnAlignment(DataGridView dgv, string colname)
  2713. {
  2714. if (dgv == null)
  2715. {
  2716. return ContentAlignment.MiddleLeft;
  2717. }
  2718. DataGridViewColumn dataGridViewColumn;
  2719. try
  2720. {
  2721. dataGridViewColumn = dgv.Columns[colname];
  2722. }
  2723. catch (Exception projectError)
  2724. {
  2725. ProjectData.SetProjectError(projectError);
  2726. ContentAlignment result1 = ContentAlignment.MiddleLeft;
  2727. ProjectData.ClearProjectError();
  2728. return result1;
  2729. }
  2730. if (dataGridViewColumn == null)
  2731. {
  2732. return ContentAlignment.MiddleLeft;
  2733. }
  2734. DataGridViewCellStyle dataGridViewCellStyle = ((dgv.RowsDefaultCellStyle.Alignment != 0) ? dgv.RowsDefaultCellStyle : ((dataGridViewColumn.DefaultCellStyle.Alignment != 0) ? dataGridViewColumn.DefaultCellStyle : dgv.DefaultCellStyle));
  2735. ContentAlignment result;
  2736. DataGridViewContentAlignment alignment = dataGridViewCellStyle.Alignment;
  2737. if (alignment == DataGridViewContentAlignment.BottomCenter)
  2738. {
  2739. result = ContentAlignment.BottomCenter;
  2740. }
  2741. else if (alignment == DataGridViewContentAlignment.BottomLeft)
  2742. {
  2743. result = ContentAlignment.BottomLeft;
  2744. }
  2745. else if (alignment == DataGridViewContentAlignment.BottomRight)
  2746. {
  2747. result = ContentAlignment.BottomRight;
  2748. }
  2749. else if (alignment == DataGridViewContentAlignment.MiddleCenter)
  2750. {
  2751. result = ContentAlignment.MiddleCenter;
  2752. }
  2753. else if (alignment == DataGridViewContentAlignment.MiddleLeft)
  2754. {
  2755. result = ContentAlignment.MiddleLeft;
  2756. }
  2757. else if (alignment == DataGridViewContentAlignment.MiddleRight)
  2758. {
  2759. result = ContentAlignment.MiddleRight;
  2760. }
  2761. else if (alignment == DataGridViewContentAlignment.NotSet)
  2762. {
  2763. result = ContentAlignment.MiddleLeft;
  2764. }
  2765. else if (alignment == DataGridViewContentAlignment.TopCenter)
  2766. {
  2767. result = ContentAlignment.TopCenter;
  2768. }
  2769. else if (alignment == DataGridViewContentAlignment.TopLeft)
  2770. {
  2771. result = ContentAlignment.TopLeft;
  2772. }
  2773. else if (alignment == DataGridViewContentAlignment.TopRight)
  2774. {
  2775. result = ContentAlignment.TopRight;
  2776. }
  2777. else
  2778. {
  2779. result = ContentAlignment.MiddleLeft;
  2780. }
  2781. return result;
  2782. }
  2783. public static string EncryptionString(string ss)
  2784. {
  2785. byte[] bytes = Encoding.Unicode.GetBytes(ss);
  2786. MemoryStream memoryStream = new MemoryStream();
  2787. CryptoStream cryptoStream = new CryptoStream(memoryStream, new TripleDESCryptoServiceProvider
  2788. {
  2789. Key = G_mykey,
  2790. IV = G_myiv
  2791. }.CreateEncryptor(), CryptoStreamMode.Write);
  2792. cryptoStream.Write(bytes, 0, bytes.Length);
  2793. cryptoStream.Close();
  2794. string result = Convert.ToBase64String(memoryStream.ToArray());
  2795. memoryStream.Dispose();
  2796. return result;
  2797. }
  2798. public static string DecryptionString(string ss)
  2799. {
  2800. TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider();
  2801. MemoryStream memoryStream = new MemoryStream();
  2802. tripleDESCryptoServiceProvider.Key = G_mykey;
  2803. tripleDESCryptoServiceProvider.IV = G_myiv;
  2804. CryptoStream cryptoStream = new CryptoStream(memoryStream, tripleDESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write);
  2805. byte[] array = Convert.FromBase64String(ss);
  2806. cryptoStream.Write(array, 0, array.Length);
  2807. cryptoStream.Close();
  2808. string @string = Encoding.Unicode.GetString(memoryStream.ToArray());
  2809. memoryStream.Dispose();
  2810. return @string;
  2811. }
  2812. public static Bitmap getDGVCheckBoxCellImage(DataGridViewCell dgvcell, Color mybkcolor)
  2813. {
  2814. Bitmap result;
  2815. if (dgvcell == null)
  2816. {
  2817. result = null;
  2818. }
  2819. else
  2820. {
  2821. CheckBox checkBox = new CheckBox();
  2822. Control control = checkBox;
  2823. Size size = new Size(14, 14);
  2824. control.Size = size;
  2825. checkBox.BackColor = mybkcolor;
  2826. if (dgvcell.FormattedValue != null)
  2827. {
  2828. if (Operators.CompareString(Versioned.TypeName(RuntimeHelpers.GetObjectValue(dgvcell.FormattedValue)), "Boolean", TextCompare: false) == 0)
  2829. {
  2830. if (Conversions.ToBoolean(dgvcell.FormattedValue))
  2831. {
  2832. checkBox.Checked = true;
  2833. }
  2834. else
  2835. {
  2836. checkBox.Checked = false;
  2837. }
  2838. }
  2839. else
  2840. {
  2841. switch (Conversions.ToInteger(dgvcell.FormattedValue))
  2842. {
  2843. case 0:
  2844. checkBox.Checked = false;
  2845. break;
  2846. case 1:
  2847. checkBox.Checked = true;
  2848. break;
  2849. default:
  2850. checkBox.CheckState = CheckState.Indeterminate;
  2851. break;
  2852. }
  2853. }
  2854. }
  2855. else
  2856. {
  2857. checkBox.Checked = false;
  2858. }
  2859. try
  2860. {
  2861. Bitmap bitmap = new Bitmap(14, 14);
  2862. Graphics graphics = Graphics.FromImage(bitmap);
  2863. Brush brush = new SolidBrush(mybkcolor);
  2864. Graphics graphics2 = graphics;
  2865. Brush brush2 = brush;
  2866. Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
  2867. graphics2.FillRectangle(brush2, rect);
  2868. if (bitmap.Height < checkBox.Height)
  2869. {
  2870. checkBox.Height = bitmap.Height;
  2871. }
  2872. if (bitmap.Width < checkBox.Width)
  2873. {
  2874. checkBox.Width = bitmap.Width;
  2875. }
  2876. Control control2 = checkBox;
  2877. Bitmap bitmap2 = bitmap;
  2878. rect = checked(new Rectangle((int)Math.Round((double)(bitmap.Width - checkBox.Width) / 2.0), (int)Math.Round((double)(bitmap.Height - checkBox.Height) / 2.0), checkBox.Width, checkBox.Height));
  2879. control2.DrawToBitmap(bitmap2, rect);
  2880. graphics.Dispose();
  2881. checkBox.Dispose();
  2882. result = bitmap;
  2883. }
  2884. catch (Exception projectError)
  2885. {
  2886. ProjectData.SetProjectError(projectError);
  2887. result = null;
  2888. ProjectData.ClearProjectError();
  2889. }
  2890. }
  2891. return result;
  2892. }
  2893. }
  2894. }