| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Drawing.Printing;
- using System.IO;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Security.Cryptography;
- using System.Text;
- using System.Windows.Forms;
- using Microsoft.VisualBasic;
- using Microsoft.VisualBasic.CompilerServices;
- namespace Dongke.IBOSS.PRD.Framework.Controls {
- [StandardModule]
- internal sealed class Module1
- {
- public const string G_CustomDefinedPaperName = "[自定义纸张]";
- public static Ruler G_ruler = new Ruler();
- public static bool G_CancelDocument = false;
- public static bool G_CancelExportDGVToExcel = false;
- public static bool G_CancelPrint = false;
- private static byte[] G_mykey = new byte[24]
- {
- 10, 32, 53, 24, 53, 23, 88, 223, 99, 10,
- 33, 62, 64, 76, 68, 98, 13, 131, 93, 33,
- 15, 56, 13, 13
- };
- private static byte[] G_myiv = new byte[8] { 13, 56, 87, 13, 98, 53, 80, 32 };
- [DllImport("kernel32", CharSet = CharSet.Ansi, EntryPoint = "GetPrivateProfileStringA", ExactSpelling = true, SetLastError = true)]
- 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);
- [DllImport("kernel32", CharSet = CharSet.Ansi, EntryPoint = "WritePrivateProfileStringA", ExactSpelling = true, SetLastError = true)]
- 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);
- public static void CopyTreeView(TreeView s, ref TreeView d, bool isaddrowname)
- {
- d.Nodes.Clear();
- if (s == null)
- {
- d = null;
- return;
- }
- d.StateImageList = s.StateImageList;
- d.ImageList = s.ImageList;
- d.ImageIndex = s.ImageIndex;
- if (Operators.CompareString(s.ImageKey, "", TextCompare: false) != 0)
- {
- d.ImageKey = s.ImageKey;
- }
- d.CheckBoxes = s.CheckBoxes;
- d.LineColor = s.LineColor;
- d.Font = (Font)s.Font.Clone();
- d.ForeColor = s.ForeColor;
- int num = 0;
- checked
- {
- int num2 = s.Nodes.Count - 1;
- for (int i = num; i <= num2; i++)
- {
- TreeNode d2 = d.Nodes.Add(s.Nodes[i].Text);
- d2.Checked = s.Nodes[i].Checked;
- d2.ImageIndex = s.Nodes[i].ImageIndex;
- if (Operators.CompareString(s.Nodes[i].ImageKey, "", TextCompare: false) != 0)
- {
- d2.ImageKey = s.Nodes[i].ImageKey;
- }
- d2.StateImageIndex = s.Nodes[i].StateImageIndex;
- if (Operators.CompareString(s.Nodes[i].StateImageKey, "", TextCompare: false) != 0)
- {
- d2.StateImageKey = s.Nodes[i].StateImageKey;
- }
- d2.ForeColor = s.Nodes[i].ForeColor;
- d2.BackColor = s.Nodes[i].BackColor;
- if (s.Nodes[i].NodeFont != null)
- {
- d2.NodeFont = (Font)s.Nodes[i].NodeFont.Clone();
- }
- CopyNodes(s.Nodes[i], ref d2);
- }
- if (isaddrowname)
- {
- d.Nodes.Insert(0, "行号");
- }
- }
- }
- private static void CopyNodes(TreeNode s, ref TreeNode d)
- {
- if (s == null)
- {
- return;
- }
- int num = 0;
- checked
- {
- int num2 = s.Nodes.Count - 1;
- for (int i = num; i <= num2; i++)
- {
- TreeNode d2 = d.Nodes.Add(s.Nodes[i].Text);
- d2.Checked = s.Nodes[i].Checked;
- d2.ImageIndex = s.Nodes[i].ImageIndex;
- if (Operators.CompareString(s.Nodes[i].ImageKey, "", TextCompare: false) != 0)
- {
- d2.ImageKey = s.Nodes[i].ImageKey;
- }
- d2.StateImageIndex = s.Nodes[i].StateImageIndex;
- if (Operators.CompareString(s.Nodes[i].StateImageKey, "", TextCompare: false) != 0)
- {
- d2.StateImageKey = s.Nodes[i].StateImageKey;
- }
- d2.ForeColor = s.Nodes[i].ForeColor;
- d2.BackColor = s.Nodes[i].BackColor;
- if (s.Nodes[i].NodeFont != null)
- {
- d2.NodeFont = (Font)s.Nodes[i].NodeFont.Clone();
- }
- CopyNodes(s.Nodes[i], ref d2);
- }
- }
- }
- public static string GetINI(string Section, string AppName, string lpDefault, string FileName)
- {
- string source = "";
- source = Strings.LSet(source, 256);
- GetPrivateProfileString(ref Section, ref AppName, ref lpDefault, ref source, Strings.Len(source), ref FileName);
- string expression = Strings.Trim(Strings.Left(source, checked(Strings.InStr(source, "\0") - 1)));
- expression = Strings.Replace(expression, "&<br>&", "\r\n");
- if (expression == null)
- {
- expression = "";
- }
- return expression;
- }
- public static long WriteINI(string Section, string AppName, string lpDefault, string FileName)
- {
- lpDefault = Strings.Replace(lpDefault, "\r\n", "&<br>&");
- if (lpDefault == null)
- {
- lpDefault = "";
- }
- return WritePrivateProfileString(ref Section, ref AppName, ref lpDefault, ref FileName);
- }
- public static string ConvertFontToString(Font myfont)
- {
- FontConverter fontConverter = new FontConverter();
- return fontConverter.ConvertToString(myfont);
- }
- public static string ConvertColorToString(Color mycolor)
- {
- ColorConverter colorConverter = new ColorConverter();
- return colorConverter.ConvertToString(mycolor);
- }
- public static Color ConvertStringToColor(string pp)
- {
- ColorConverter colorConverter = new ColorConverter();
- try
- {
- object obj = colorConverter.ConvertFromString(pp);
- Color black = Color.Black;
- return (obj != null) ? ((Color)obj) : black;
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- Color result = Color.FromArgb(0);
- ProjectData.ClearProjectError();
- return result;
- }
- }
- public static Font ConvertStringToFont(string pp)
- {
- FontConverter fontConverter = new FontConverter();
- Font result;
- if (Operators.CompareString(pp, "(无)", TextCompare: false) == 0)
- {
- result = null;
- }
- else
- {
- try
- {
- Font font = (Font)fontConverter.ConvertFromString(pp);
- result = font;
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- result = null;
- ProjectData.ClearProjectError();
- }
- }
- return result;
- }
- public static void CopyDataGridView(DataGridView sdv, DataGridView ddv, bool IsAddRowHeaderColumn)
- {
- CopyDataGridView(sdv, ddv);
- if (!IsAddRowHeaderColumn)
- {
- return;
- }
- checked
- {
- try
- {
- if (ddv.Columns.Count <= 0)
- {
- return;
- }
- DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
- dataGridViewTextBoxColumn.HeaderCell = (DataGridViewColumnHeaderCell)sdv.TopLeftHeaderCell.Clone();
- if (sdv.TopLeftHeaderCell.HasStyle)
- {
- dataGridViewTextBoxColumn.HeaderCell.Style = sdv.TopLeftHeaderCell.Style.Clone();
- }
- dataGridViewTextBoxColumn.Width = sdv.RowHeadersWidth;
- if (Operators.CompareString(dataGridViewTextBoxColumn.Name ?? "", "", TextCompare: false) == 0)
- {
- dataGridViewTextBoxColumn.Name = "行标题";
- }
- dataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
- ddv.Columns.Insert(0, dataGridViewTextBoxColumn);
- int rowCount = ddv.RowCount;
- int num = 0;
- int num2 = rowCount - 1;
- for (int i = num; i <= num2; i++)
- {
- ddv.Rows[i].Cells[0].Value = Conversions.ToString(sdv.Rows[i].HeaderCell.FormattedValue) ?? "";
- if (sdv.Rows[i].HeaderCell.Style.Font != null)
- {
- ddv.Rows[i].Cells[0].Style.Font = (Font)sdv.Rows[i].HeaderCell.Style.Font.Clone();
- }
- else if (sdv.RowHeadersDefaultCellStyle.Font != null)
- {
- ddv.Rows[i].Cells[0].Style.Font = (Font)sdv.RowHeadersDefaultCellStyle.Font.Clone();
- }
- if (sdv.Rows[i].HeaderCell.Style.Alignment != 0)
- {
- ddv.Rows[i].Cells[0].Style.Alignment = sdv.Rows[i].HeaderCell.Style.Alignment;
- }
- else
- {
- ddv.Rows[i].Cells[0].Style.Alignment = sdv.RowHeadersDefaultCellStyle.Alignment;
- }
- if (sdv.Rows[i].HeaderCell.Style.ForeColor.ToArgb() != 0)
- {
- ddv.Rows[i].Cells[0].Style.ForeColor = sdv.Rows[i].HeaderCell.Style.ForeColor;
- }
- else if (sdv.RowHeadersDefaultCellStyle.ForeColor.ToArgb() != 0)
- {
- ddv.Rows[i].Cells[0].Style.ForeColor = sdv.RowHeadersDefaultCellStyle.ForeColor;
- }
- if (sdv.Rows[i].HeaderCell.Style.BackColor.ToArgb() != 0)
- {
- ddv.Rows[i].Cells[0].Style.BackColor = sdv.Rows[i].HeaderCell.Style.BackColor;
- }
- else if (sdv.RowHeadersDefaultCellStyle.BackColor.ToArgb() != 0)
- {
- ddv.Rows[i].Cells[0].Style.BackColor = sdv.RowHeadersDefaultCellStyle.BackColor;
- }
- if (sdv.Rows[i].HeaderCell.Style.WrapMode != 0)
- {
- ddv.Rows[i].Cells[0].Style.WrapMode = sdv.Rows[i].HeaderCell.Style.WrapMode;
- }
- else if (sdv.RowHeadersDefaultCellStyle.WrapMode != 0)
- {
- ddv.Rows[i].Cells[0].Style.WrapMode = sdv.RowHeadersDefaultCellStyle.WrapMode;
- }
- }
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- }
- }
- public static void CopyDataGridViewShowStatus(DataGridView sdv, DataGridView ddv, bool isprintrowheadercolumn)
- {
- progress2 progress3 = new progress2();
- progress3.Show();
- progress3.Label1.Text = "正在复制数据……请稍侯";
- Application.DoEvents();
- CopyDataGridView(sdv, ddv, isprintrowheadercolumn);
- progress3.Close();
- progress3.Dispose();
- }
- public static void CopyDataGridViewShowStatus(DataGridView sdv, DataGridView ddv, int fromrow, int torow, bool isprintrowheadercolumn)
- {
- progress2 progress3 = new progress2();
- progress3.Show();
- progress3.Label1.Text = "正在复制数据……请稍侯";
- Application.DoEvents();
- CopyDataGridView(sdv, ddv, fromrow, torow, isprintrowheadercolumn);
- progress3.Close();
- progress3.Dispose();
- }
- public static void MyMsgBox(string ss)
- {
- }
- public static void CopyDataGridView(DataGridView sdv, DataGridView ddv)
- {
- if (sdv == null || ddv == null)
- {
- return;
- }
- if (sdv.Equals(ddv))
- {
- MyMsgBox("在CopyDataGridView函数中发现要复制的DGV与目标DGV完全一样");
- return;
- }
- ddv.AllowUserToAddRows = false;
- while (ddv.ColumnCount >= 1)
- {
- ddv.Columns.RemoveAt(0);
- }
- ddv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
- ddv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
- int columnCount = sdv.ColumnCount;
- int num = 0;
- checked
- {
- int num2 = columnCount - 1;
- for (int i = num; i <= num2; i++)
- {
- if (Operators.CompareString(Versioned.TypeName(sdv.Columns[i]), "DataGridViewComboBoxColumn", TextCompare: false) == 0)
- {
- DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
- try
- {
- dataGridViewTextBoxColumn.DefaultCellStyle = sdv.Columns[i].DefaultCellStyle.Clone();
- dataGridViewTextBoxColumn.AutoSizeMode = sdv.Columns[i].AutoSizeMode;
- dataGridViewTextBoxColumn.DisplayIndex = sdv.Columns[i].DisplayIndex;
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- try
- {
- dataGridViewTextBoxColumn.HeaderCell = (DataGridViewColumnHeaderCell)sdv.Columns[i].HeaderCell.Clone();
- dataGridViewTextBoxColumn.HeaderText = sdv.Columns[i].HeaderText;
- dataGridViewTextBoxColumn.MinimumWidth = sdv.Columns[i].MinimumWidth;
- dataGridViewTextBoxColumn.Resizable = sdv.Columns[i].Resizable;
- }
- catch (Exception projectError2)
- {
- ProjectData.SetProjectError(projectError2);
- ProjectData.ClearProjectError();
- }
- try
- {
- dataGridViewTextBoxColumn.Name = sdv.Columns[i].Name;
- dataGridViewTextBoxColumn.Tag = RuntimeHelpers.GetObjectValue(sdv.Columns[i].Tag);
- dataGridViewTextBoxColumn.Visible = sdv.Columns[i].Visible;
- try
- {
- if (Operators.CompareString(Conversions.ToString(dataGridViewTextBoxColumn.Tag), "不打印", TextCompare: false) == 0)
- {
- dataGridViewTextBoxColumn.Visible = false;
- }
- }
- catch (Exception projectError3)
- {
- ProjectData.SetProjectError(projectError3);
- ProjectData.ClearProjectError();
- }
- dataGridViewTextBoxColumn.Width = sdv.Columns[i].Width;
- }
- catch (Exception projectError4)
- {
- ProjectData.SetProjectError(projectError4);
- ProjectData.ClearProjectError();
- }
- ddv.Columns.Add(dataGridViewTextBoxColumn);
- }
- else
- {
- DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)sdv.Columns[i].Clone();
- dataGridViewColumn.Frozen = false;
- try
- {
- if (Operators.CompareString(Conversions.ToString(dataGridViewColumn.Tag), "不打印", TextCompare: false) == 0)
- {
- dataGridViewColumn.Visible = false;
- }
- }
- catch (Exception projectError5)
- {
- ProjectData.SetProjectError(projectError5);
- ProjectData.ClearProjectError();
- }
- ddv.Columns.Add(dataGridViewColumn);
- }
- try
- {
- ddv.Columns[i].ValueType = sdv.Columns[i].ValueType;
- }
- catch (Exception projectError6)
- {
- ProjectData.SetProjectError(projectError6);
- ProjectData.ClearProjectError();
- }
- if (Operators.CompareString(ddv.Columns[i].Name ?? "", "", TextCompare: false) == 0)
- {
- ddv.Columns[i].Name = "第" + Conversions.ToString(i) + "列名";
- }
- ddv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
- ddv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
- }
- int[] array = new int[sdv.ColumnCount - 1 + 1];
- int[] array2 = new int[sdv.ColumnCount - 1 + 1];
- int num3 = 0;
- int num4 = sdv.ColumnCount - 1;
- for (int j = num3; j <= num4; j++)
- {
- array[j] = j;
- array2[j] = sdv.Columns[j].DisplayIndex;
- }
- Array.Sort(array2, array);
- int num5 = 0;
- int num6 = sdv.ColumnCount - 1;
- for (int k = num5; k <= num6; k++)
- {
- ddv.Columns[array[k]].DisplayIndex = sdv.Columns[array[k]].DisplayIndex;
- }
- ddv.ColumnHeadersHeightSizeMode = sdv.ColumnHeadersHeightSizeMode;
- ddv.ColumnHeadersHeight = sdv.ColumnHeadersHeight;
- ddv.ColumnHeadersVisible = sdv.ColumnHeadersVisible;
- if (sdv.RowCount <= 0)
- {
- return;
- }
- int num7 = sdv.RowCount;
- if (sdv.AllowUserToAddRows && IsNullLastRow(sdv))
- {
- num7--;
- }
- ddv.RowCount = num7;
- ddv.AlternatingRowsDefaultCellStyle = sdv.AlternatingRowsDefaultCellStyle.Clone();
- ddv.DefaultCellStyle = sdv.DefaultCellStyle.Clone();
- ddv.RowsDefaultCellStyle = sdv.RowsDefaultCellStyle.Clone();
- ddv.ColumnHeadersDefaultCellStyle = sdv.ColumnHeadersDefaultCellStyle.Clone();
- int num8 = 0;
- int num9 = sdv.ColumnCount - 1;
- for (int l = num8; l <= num9; l++)
- {
- if (sdv.Columns[l].HasDefaultCellStyle)
- {
- ddv.Columns[l].DefaultCellStyle = sdv.Columns[l].DefaultCellStyle.Clone();
- }
- }
- columnCount = ddv.Columns.Count - 1;
- string[] array3 = new string[columnCount + 1];
- int num10 = 0;
- int num11 = columnCount;
- for (int m = num10; m <= num11; m++)
- {
- array3[m] = Versioned.TypeName(sdv.Columns[m]);
- }
- int num12 = 0;
- int num13 = num7 - 1;
- for (int n = num12; n <= num13; n++)
- {
- int num14 = 0;
- int num15 = columnCount;
- for (int num16 = num14; num16 <= num15; num16++)
- {
- if (Operators.CompareString(array3[num16], "DataGridViewImageColumn", TextCompare: false) == 0)
- {
- ddv.Rows[n].Cells[num16].Value = RuntimeHelpers.GetObjectValue(sdv.Rows[n].Cells[num16].Value);
- if (ddv.Rows[n].Cells[num16].Value != null)
- {
- try
- {
- DataGridViewImageCell dataGridViewImageCell = (DataGridViewImageCell)ddv.Rows[n].Cells[num16];
- dataGridViewImageCell.ImageLayout = ((DataGridViewImageCell)sdv.Rows[n].Cells[num16]).ImageLayout;
- }
- catch (Exception projectError7)
- {
- ProjectData.SetProjectError(projectError7);
- ProjectData.ClearProjectError();
- }
- }
- }
- else
- {
- ddv.Rows[n].Cells[num16].Value = Conversions.ToString(sdv.Rows[n].Cells[num16].FormattedValue) ?? "";
- }
- if (sdv.Rows[n].Cells[num16].HasStyle)
- {
- ddv.Rows[n].Cells[num16].Style = sdv.Rows[n].Cells[num16].Style.Clone();
- }
- try
- {
- ddv.Rows[n].Cells[num16].Tag = RuntimeHelpers.GetObjectValue(sdv.Rows[n].Cells[num16].Tag);
- }
- catch (Exception projectError8)
- {
- ProjectData.SetProjectError(projectError8);
- ProjectData.ClearProjectError();
- }
- }
- ddv.Rows[n].Height = sdv.Rows[n].Height;
- ddv.Rows[n].Visible = sdv.Rows[n].Visible;
- if (sdv.Rows[n].HasDefaultCellStyle)
- {
- ddv.Rows[n].DefaultCellStyle = sdv.Rows[n].DefaultCellStyle.Clone();
- }
- try
- {
- ddv.Rows[n].Tag = RuntimeHelpers.GetObjectValue(sdv.Rows[n].Tag);
- }
- catch (Exception projectError9)
- {
- ProjectData.SetProjectError(projectError9);
- ProjectData.ClearProjectError();
- }
- }
- ddv.GridColor = sdv.GridColor;
- ddv.Name = sdv.Name;
- }
- }
- public static void CopyDataGridView(DataGridView sdv, DataGridView ddv, int fromrow, int torow, bool isprintrowheadercolumn)
- {
- if (sdv == null || ddv == null)
- {
- return;
- }
- if (sdv.Equals(ddv))
- {
- MyMsgBox("在CopyDataGridView函数中发现要复制的DGV与目标DGV完全一样");
- return;
- }
- if (fromrow < 0)
- {
- fromrow = 0;
- }
- if (torow > checked(sdv.RowCount - 1) || torow < fromrow)
- {
- torow = checked(sdv.RowCount - 1);
- }
- ddv.AllowUserToAddRows = false;
- while (ddv.ColumnCount >= 1)
- {
- ddv.Columns.RemoveAt(0);
- }
- ddv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
- ddv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
- int num = 0;
- checked
- {
- int num2 = sdv.ColumnCount - 1;
- for (int i = num; i <= num2; i++)
- {
- if (Operators.CompareString(Versioned.TypeName(sdv.Columns[i]), "DataGridViewComboBoxColumn", TextCompare: false) == 0)
- {
- DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
- try
- {
- dataGridViewTextBoxColumn.DefaultCellStyle = sdv.Columns[i].DefaultCellStyle.Clone();
- dataGridViewTextBoxColumn.AutoSizeMode = sdv.Columns[i].AutoSizeMode;
- dataGridViewTextBoxColumn.DisplayIndex = sdv.Columns[i].DisplayIndex;
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- try
- {
- dataGridViewTextBoxColumn.HeaderCell = (DataGridViewColumnHeaderCell)sdv.Columns[i].HeaderCell.Clone();
- dataGridViewTextBoxColumn.HeaderText = sdv.Columns[i].HeaderText;
- dataGridViewTextBoxColumn.MinimumWidth = sdv.Columns[i].MinimumWidth;
- dataGridViewTextBoxColumn.Resizable = sdv.Columns[i].Resizable;
- }
- catch (Exception projectError2)
- {
- ProjectData.SetProjectError(projectError2);
- ProjectData.ClearProjectError();
- }
- try
- {
- dataGridViewTextBoxColumn.Name = sdv.Columns[i].Name;
- dataGridViewTextBoxColumn.Tag = RuntimeHelpers.GetObjectValue(sdv.Columns[i].Tag);
- dataGridViewTextBoxColumn.Visible = sdv.Columns[i].Visible;
- try
- {
- if (Operators.CompareString(Conversions.ToString(dataGridViewTextBoxColumn.Tag), "不打印", TextCompare: false) == 0)
- {
- dataGridViewTextBoxColumn.Visible = false;
- }
- }
- catch (Exception projectError3)
- {
- ProjectData.SetProjectError(projectError3);
- ProjectData.ClearProjectError();
- }
- dataGridViewTextBoxColumn.Width = sdv.Columns[i].Width;
- }
- catch (Exception projectError4)
- {
- ProjectData.SetProjectError(projectError4);
- ProjectData.ClearProjectError();
- }
- ddv.Columns.Add(dataGridViewTextBoxColumn);
- }
- else
- {
- DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)sdv.Columns[i].Clone();
- dataGridViewColumn.Frozen = false;
- try
- {
- if (Operators.CompareString(Conversions.ToString(dataGridViewColumn.Tag), "不打印", TextCompare: false) == 0)
- {
- dataGridViewColumn.Visible = false;
- }
- }
- catch (Exception projectError5)
- {
- ProjectData.SetProjectError(projectError5);
- ProjectData.ClearProjectError();
- }
- ddv.Columns.Add(dataGridViewColumn);
- }
- try
- {
- ddv.Columns[i].ValueType = sdv.Columns[i].ValueType;
- }
- catch (Exception projectError6)
- {
- ProjectData.SetProjectError(projectError6);
- ProjectData.ClearProjectError();
- }
- if (Operators.CompareString(ddv.Columns[i].Name ?? "", "", TextCompare: false) == 0)
- {
- ddv.Columns[i].Name = "第" + Conversions.ToString(i) + "列名";
- }
- ddv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
- ddv.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
- }
- int[] array = new int[sdv.ColumnCount - 1 + 1];
- int[] array2 = new int[sdv.ColumnCount - 1 + 1];
- int num3 = 0;
- int num4 = sdv.ColumnCount - 1;
- for (int j = num3; j <= num4; j++)
- {
- array[j] = j;
- array2[j] = sdv.Columns[j].DisplayIndex;
- }
- Array.Sort(array2, array);
- int num5 = 0;
- int num6 = sdv.ColumnCount - 1;
- for (int k = num5; k <= num6; k++)
- {
- ddv.Columns[array[k]].DisplayIndex = sdv.Columns[array[k]].DisplayIndex;
- }
- ddv.ColumnHeadersHeightSizeMode = sdv.ColumnHeadersHeightSizeMode;
- ddv.ColumnHeadersHeight = sdv.ColumnHeadersHeight;
- ddv.ColumnHeadersVisible = sdv.ColumnHeadersVisible;
- if (sdv.RowCount <= 0)
- {
- return;
- }
- int rowCount = torow - fromrow + 1;
- ddv.RowCount = rowCount;
- ddv.AlternatingRowsDefaultCellStyle = sdv.AlternatingRowsDefaultCellStyle.Clone();
- ddv.DefaultCellStyle = sdv.DefaultCellStyle.Clone();
- ddv.RowsDefaultCellStyle = sdv.RowsDefaultCellStyle.Clone();
- ddv.ColumnHeadersDefaultCellStyle = sdv.ColumnHeadersDefaultCellStyle.Clone();
- int num7 = 0;
- int num8 = sdv.ColumnCount - 1;
- for (int l = num7; l <= num8; l++)
- {
- if (sdv.Columns[l].HasDefaultCellStyle)
- {
- ddv.Columns[l].DefaultCellStyle = sdv.Columns[l].DefaultCellStyle.Clone();
- }
- }
- int num9 = fromrow;
- int num10 = torow;
- for (int m = num9; m <= num10; m++)
- {
- int num11 = 0;
- int num12 = ddv.Columns.Count - 1;
- for (int n = num11; n <= num12; n++)
- {
- if (Operators.CompareString(Versioned.TypeName(sdv.Columns[n]), "DataGridViewImageColumn", TextCompare: false) == 0)
- {
- ddv.Rows[m - fromrow].Cells[n].Value = RuntimeHelpers.GetObjectValue(sdv.Rows[m].Cells[n].Value);
- if (ddv.Rows[m - fromrow].Cells[n].Value != null)
- {
- try
- {
- DataGridViewImageCell dataGridViewImageCell = (DataGridViewImageCell)ddv.Rows[m - fromrow].Cells[n];
- dataGridViewImageCell.ImageLayout = ((DataGridViewImageCell)sdv.Rows[m].Cells[n]).ImageLayout;
- }
- catch (Exception projectError7)
- {
- ProjectData.SetProjectError(projectError7);
- ProjectData.ClearProjectError();
- }
- }
- }
- else
- {
- ddv.Rows[m - fromrow].Cells[n].Value = Conversions.ToString(sdv.Rows[m].Cells[n].FormattedValue) ?? "";
- }
- if (sdv.Rows[m].Cells[n].HasStyle)
- {
- ddv.Rows[m - fromrow].Cells[n].Style = sdv.Rows[m].Cells[n].Style.Clone();
- }
- try
- {
- ddv.Rows[m - fromrow].Cells[n].Tag = RuntimeHelpers.GetObjectValue(sdv.Rows[m].Cells[n].Tag);
- }
- catch (Exception projectError8)
- {
- ProjectData.SetProjectError(projectError8);
- ProjectData.ClearProjectError();
- }
- }
- ddv.Rows[m - fromrow].Height = sdv.Rows[m].Height;
- ddv.Rows[m - fromrow].Visible = sdv.Rows[m].Visible;
- if (sdv.Rows[m].HasDefaultCellStyle)
- {
- ddv.Rows[m - fromrow].DefaultCellStyle = sdv.Rows[m].DefaultCellStyle.Clone();
- }
- try
- {
- ddv.Rows[m - fromrow].Tag = RuntimeHelpers.GetObjectValue(sdv.Rows[m].Tag);
- }
- catch (Exception projectError9)
- {
- ProjectData.SetProjectError(projectError9);
- ProjectData.ClearProjectError();
- }
- }
- ddv.GridColor = sdv.GridColor;
- ddv.Name = sdv.Name;
- if (!isprintrowheadercolumn)
- {
- return;
- }
- try
- {
- if (ddv.Columns.Count <= 0)
- {
- return;
- }
- DataGridViewTextBoxColumn dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
- dataGridViewTextBoxColumn2.HeaderCell = (DataGridViewColumnHeaderCell)sdv.TopLeftHeaderCell.Clone();
- if (sdv.TopLeftHeaderCell.HasStyle)
- {
- dataGridViewTextBoxColumn2.HeaderCell.Style = sdv.TopLeftHeaderCell.Style.Clone();
- }
- dataGridViewTextBoxColumn2.Width = sdv.RowHeadersWidth;
- if (Operators.CompareString(dataGridViewTextBoxColumn2.Name ?? "", "", TextCompare: false) == 0)
- {
- dataGridViewTextBoxColumn2.Name = "平平自创";
- }
- dataGridViewTextBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
- ddv.Columns.Insert(0, dataGridViewTextBoxColumn2);
- rowCount = ddv.RowCount;
- int num13 = fromrow;
- int num14 = torow;
- for (int num15 = num13; num15 <= num14; num15++)
- {
- ddv.Rows[num15 - fromrow].Cells[0].Value = Conversions.ToString(sdv.Rows[num15].HeaderCell.FormattedValue) ?? "";
- if (sdv.Rows[num15].HeaderCell.Style.Font != null)
- {
- ddv.Rows[num15 - fromrow].Cells[0].Style.Font = (Font)sdv.Rows[num15].HeaderCell.Style.Font.Clone();
- }
- else if (sdv.RowHeadersDefaultCellStyle.Font != null)
- {
- ddv.Rows[num15 - fromrow].Cells[0].Style.Font = (Font)sdv.RowHeadersDefaultCellStyle.Font.Clone();
- }
- if (sdv.Rows[num15].HeaderCell.Style.Alignment != 0)
- {
- ddv.Rows[num15 - fromrow].Cells[0].Style.Alignment = sdv.Rows[num15].HeaderCell.Style.Alignment;
- }
- else
- {
- ddv.Rows[num15 - fromrow].Cells[0].Style.Alignment = sdv.RowHeadersDefaultCellStyle.Alignment;
- }
- if (sdv.Rows[num15].HeaderCell.Style.ForeColor.ToArgb() != 0)
- {
- ddv.Rows[num15 - fromrow].Cells[0].Style.ForeColor = sdv.Rows[num15].HeaderCell.Style.ForeColor;
- }
- else if (sdv.RowHeadersDefaultCellStyle.ForeColor.ToArgb() != 0)
- {
- ddv.Rows[num15 - fromrow].Cells[0].Style.ForeColor = sdv.RowHeadersDefaultCellStyle.ForeColor;
- }
- if (sdv.Rows[num15].HeaderCell.Style.BackColor.ToArgb() != 0)
- {
- ddv.Rows[num15 - fromrow].Cells[0].Style.BackColor = sdv.Rows[num15].HeaderCell.Style.BackColor;
- }
- else if (sdv.RowHeadersDefaultCellStyle.BackColor.ToArgb() != 0)
- {
- ddv.Rows[num15 - fromrow].Cells[0].Style.BackColor = sdv.RowHeadersDefaultCellStyle.BackColor;
- }
- if (sdv.Rows[num15].HeaderCell.Style.WrapMode != 0)
- {
- ddv.Rows[num15 - fromrow].Cells[0].Style.WrapMode = sdv.Rows[num15].HeaderCell.Style.WrapMode;
- }
- else if (sdv.RowHeadersDefaultCellStyle.WrapMode != 0)
- {
- ddv.Rows[num15 - fromrow].Cells[0].Style.WrapMode = sdv.RowHeadersDefaultCellStyle.WrapMode;
- }
- }
- }
- catch (Exception projectError10)
- {
- ProjectData.SetProjectError(projectError10);
- ProjectData.ClearProjectError();
- }
- }
- }
- public static void DelDGVAllUnvisibleCols(DataGridView dgv)
- {
- if (dgv == null)
- {
- return;
- }
- checked
- {
- try
- {
- int columnCount = dgv.ColumnCount;
- for (int i = columnCount - 1; i >= 0; i += -1)
- {
- if (!dgv.Columns[i].Visible)
- {
- dgv.Columns.RemoveAt(i);
- }
- }
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- }
- }
- public static void AddDGVRowID(DataGridView dgv)
- {
- if (dgv.Columns.Count <= 0)
- {
- return;
- }
- DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
- dataGridViewTextBoxColumn.HeaderText = "行号";
- dataGridViewTextBoxColumn.DefaultCellStyle = dgv.DefaultCellStyle.Clone();
- dataGridViewTextBoxColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- dataGridViewTextBoxColumn.Width = 40;
- dataGridViewTextBoxColumn.Name = "游平自创";
- try
- {
- dgv.Columns.Insert(0, dataGridViewTextBoxColumn);
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- dataGridViewTextBoxColumn.Frozen = true;
- dgv.Columns.Insert(0, dataGridViewTextBoxColumn);
- ProjectData.ClearProjectError();
- }
- checked
- {
- try
- {
- int num = 1;
- int num2 = 0;
- int num3 = dgv.RowCount - 1;
- for (int i = num2; i <= num3; i++)
- {
- if (dgv.Rows[i].Visible)
- {
- dgv.Rows[i].Cells[0].Value = Conversions.ToString(num);
- num++;
- }
- }
- }
- catch (Exception projectError2)
- {
- ProjectData.SetProjectError(projectError2);
- ProjectData.ClearProjectError();
- }
- }
- }
- public static int GetDGVVisibleRows(DataGridView dgv)
- {
- if (dgv == null)
- {
- return 0;
- }
- int num = 0;
- int num2 = 0;
- checked
- {
- int num3 = dgv.RowCount - 1;
- for (int i = num2; i <= num3; i++)
- {
- if (dgv.Rows[i].Visible)
- {
- num++;
- }
- }
- return num;
- }
- }
- public static bool IsNullLastRow(DataGridView dgv)
- {
- checked
- {
- bool result;
- if (dgv == null)
- {
- result = false;
- }
- else if (dgv.RowCount <= 0)
- {
- result = false;
- }
- else
- {
- int index = dgv.RowCount - 1;
- bool flag = true;
- try
- {
- int num = 0;
- int num2 = dgv.ColumnCount - 1;
- for (int i = num; i <= num2; i++)
- {
- if (Operators.CompareString(Versioned.TypeName(dgv.Columns[i]), "DataGridViewImageColumn", TextCompare: false) != 0 && Operators.ConditionalCompareObjectNotEqual(Operators.ConcatenateObject(dgv.Rows[index].Cells[i].Value, ""), "", TextCompare: false))
- {
- flag = false;
- break;
- }
- }
- result = (flag ? true : false);
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- result = false;
- ProjectData.ClearProjectError();
- }
- }
- return result;
- }
- }
- public static void SetDGVSelectedRowsVisible(DataGridView sdgv, DataGridView ddgv, int baserows)
- {
- checked
- {
- if (sdgv != null && ddgv != null)
- {
- int num = 0;
- int num2 = ddgv.Rows.Count - 1;
- for (int i = num; i <= num2; i++)
- {
- ddgv.Rows[i].Visible = false;
- }
- List<int> dGVSelectedRows = GetDGVSelectedRows(sdgv);
- int num3 = 0;
- int num4 = dGVSelectedRows.Count - 1;
- for (int j = num3; j <= num4; j++)
- {
- ddgv.Rows[dGVSelectedRows[j] - baserows].Visible = true;
- }
- }
- }
- }
- public static void SetDGVSelectedColumnsVisible(DataGridView sdgv, DataGridView ddgv)
- {
- if (sdgv == null || ddgv == null)
- {
- return;
- }
- checked
- {
- bool[] array = new bool[sdgv.Columns.Count - 1 + 1];
- int num = 0;
- int num2 = sdgv.Columns.Count - 1;
- for (int i = num; i <= num2; i++)
- {
- array[i] = false;
- }
- List<int> dGVSelectedCols = GetDGVSelectedCols(sdgv);
- int num3 = 0;
- int num4 = dGVSelectedCols.Count - 1;
- for (int j = num3; j <= num4; j++)
- {
- array[dGVSelectedCols[j]] = true;
- }
- int num5 = 0;
- int num6 = ddgv.Columns.Count - 1;
- for (int k = num5; k <= num6; k++)
- {
- if (!array[k])
- {
- ddgv.Columns[k].Visible = false;
- }
- }
- }
- }
- public static List<int> GetDGVSelectedCols(DataGridView dgv)
- {
- if (dgv == null)
- {
- return null;
- }
- if (dgv.SelectedCells.Count <= 0)
- {
- return null;
- }
- checked
- {
- int num = dgv.RowCount - 1;
- int num2 = dgv.ColumnCount - 1;
- List<int> list = new List<int>();
- int num3 = 0;
- int num4 = num2;
- for (int i = num3; i <= num4; i++)
- {
- if (!dgv.Columns[i].Visible)
- {
- continue;
- }
- int num5 = 0;
- int num6 = num;
- for (int j = num5; j <= num6; j++)
- {
- if (dgv.Rows[j].Cells[i].Selected)
- {
- list.Add(i);
- break;
- }
- }
- }
- return list;
- }
- }
- public static List<int> GetDGVSelectedRows(DataGridView dgv)
- {
- if (dgv == null)
- {
- return null;
- }
- if (dgv.SelectedCells.Count <= 0)
- {
- return null;
- }
- checked
- {
- int num = dgv.RowCount - 1;
- int num2 = dgv.ColumnCount - 1;
- List<int> list = new List<int>();
- int num3 = 0;
- int num4 = num;
- for (int i = num3; i <= num4; i++)
- {
- if (!dgv.Rows[i].Visible)
- {
- continue;
- }
- int num5 = 0;
- int num6 = num2;
- for (int j = num5; j <= num6; j++)
- {
- if (dgv.Rows[i].Cells[j].Selected)
- {
- list.Add(i);
- break;
- }
- }
- }
- return list;
- }
- }
- public static void SetDGVSelectedRowsAndColumnsVisible(DataGridView sdgv, DataGridView ddgv, int baserows)
- {
- SetDGVSelectedRowsVisible(sdgv, ddgv, baserows);
- SetDGVSelectedColumnsVisible(sdgv, ddgv);
- }
- public static int GetDGVSelectedMinRowIndex(DataGridView dgv)
- {
- if (dgv == null)
- {
- return -1;
- }
- if (dgv.RowCount <= 0)
- {
- return -1;
- }
- if (dgv.SelectedCells.Count <= 0)
- {
- return -1;
- }
- checked
- {
- int num = dgv.RowCount - 1;
- int num2 = dgv.ColumnCount - 1;
- int num3 = 0;
- int num4 = num;
- for (int i = num3; i <= num4; i++)
- {
- int num5 = 0;
- int num6 = num2;
- for (int j = num5; j <= num6; j++)
- {
- if (dgv.Rows[i].Cells[j].Selected)
- {
- return i;
- }
- }
- }
- return -1;
- }
- }
- public static int GetDGVSelectedMaxRowIndex(DataGridView dgv)
- {
- if (dgv == null)
- {
- return -1;
- }
- if (dgv.RowCount <= 0)
- {
- return -1;
- }
- if (dgv.SelectedCells.Count <= 0)
- {
- return -1;
- }
- checked
- {
- int num = dgv.RowCount - 1;
- int num2 = dgv.ColumnCount - 1;
- for (int i = num; i >= 0; i += -1)
- {
- int num3 = 0;
- int num4 = num2;
- for (int j = num3; j <= num4; j++)
- {
- if (dgv.Rows[i].Cells[j].Selected)
- {
- return i;
- }
- }
- }
- return -1;
- }
- }
- public static DataGridView ConvertDataGridToDGV(DataGrid myd, bool autoresizewidth, bool autoresizeheight)
- {
- DataGridView dataGridView = new DataGridView();
- int count = myd.BindingContext[RuntimeHelpers.GetObjectValue(myd.DataSource), myd.DataMember].Count;
- if (count <= 0)
- {
- return null;
- }
- int num = 0;
- checked
- {
- try
- {
- while (true)
- {
- Conversions.ToString(myd[0, num]);
- num++;
- }
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- int num2 = 0;
- int num3 = count - 1;
- for (int i = num2; i <= num3; i++)
- {
- int num4 = 0;
- int num5 = num - 1;
- for (int j = num4; j <= num5; j++)
- {
- }
- }
- if (num <= 0)
- {
- return null;
- }
- dataGridView.RowCount = count;
- dataGridView.ColumnCount = num;
- if (myd.TableStyles.Count <= 0)
- {
- DataGridTableStyle table = new DataGridTableStyle((CurrencyManager)myd.BindingContext[RuntimeHelpers.GetObjectValue(myd.DataSource), myd.DataMember]);
- myd.TableStyles.Add(table);
- }
- int num6 = 0;
- int num7 = num - 1;
- for (int k = num6; k <= num7; k++)
- {
- dataGridView.Columns[k].HeaderText = myd.TableStyles[0].GridColumnStyles[k].HeaderText ?? "";
- dataGridView.Columns[k].DefaultCellStyle.Alignment = ConvertAlignment(myd.TableStyles[0].GridColumnStyles[k].Alignment);
- dataGridView.Columns[k].Width = myd.TableStyles[0].GridColumnStyles[k].Width;
- }
- dataGridView.ColumnHeadersDefaultCellStyle.Font = myd.HeaderFont;
- dataGridView.ColumnHeadersDefaultCellStyle.ForeColor = myd.HeaderForeColor;
- dataGridView.ColumnHeadersDefaultCellStyle.BackColor = myd.HeaderBackColor;
- int num8 = 0;
- int num9 = count - 1;
- for (int l = num8; l <= num9; l++)
- {
- int num10 = 0;
- int num11 = num - 1;
- for (int m = num10; m <= num11; m++)
- {
- dataGridView.Rows[l].Cells[m].Value = Operators.ConcatenateObject(myd[l, m], "");
- }
- }
- dataGridView.RowHeadersWidth = myd.RowHeaderWidth;
- dataGridView.AlternatingRowsDefaultCellStyle.BackColor = myd.AlternatingBackColor;
- dataGridView.DefaultCellStyle.BackColor = myd.BackColor;
- dataGridView.DefaultCellStyle.Font = myd.Font;
- dataGridView.DefaultCellStyle.ForeColor = myd.ForeColor;
- dataGridView.GridColor = myd.GridLineColor;
- int num12 = 0;
- int num13 = num - 1;
- for (int n = num12; n <= num13; n++)
- {
- dataGridView.Columns[n].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
- }
- if (autoresizewidth)
- {
- dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
- }
- if (autoresizeheight)
- {
- dataGridView.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCells);
- }
- return dataGridView;
- }
- }
- private static DataGridViewContentAlignment ConvertAlignment(HorizontalAlignment ss)
- {
- DataGridViewContentAlignment result;
- switch (ss)
- {
- case HorizontalAlignment.Left:
- result = DataGridViewContentAlignment.MiddleLeft;
- break;
- case HorizontalAlignment.Right:
- result = DataGridViewContentAlignment.MiddleRight;
- break;
- case HorizontalAlignment.Center:
- result = DataGridViewContentAlignment.MiddleCenter;
- break;
- default:
- result = DataGridViewContentAlignment.MiddleLeft;
- break;
- }
- return result;
- }
- private static bool IsColumNameExists(DataGridView dd, string tt)
- {
- if (dd == null)
- {
- return false;
- }
- if (Operators.CompareString(tt ?? "", "", TextCompare: false) == 0)
- {
- return false;
- }
- string[] array = Strings.Split(tt, ";");
- int num = 0;
- checked
- {
- int num2 = array.Length - 1;
- for (int i = num; i <= num2; i++)
- {
- try
- {
- _ = dd.Columns[array[i]].DisplayIndex;
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- bool result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- }
- return true;
- }
- }
- public static void CreateHz(DataGridView dgv, int srows, string myhzcolumns, Font hzfont, Color hzforecolor, Color hzbackcolor, StringAlignment SumNumberAlign)
- {
- if (dgv.AllowUserToAddRows)
- {
- dgv.AllowUserToAddRows = false;
- }
- checked
- {
- if (dgv.RowCount > srows)
- {
- dgv.Rows.RemoveAt(dgv.RowCount - 1);
- }
- if (!IsColumNameExists(dgv, myhzcolumns))
- {
- myhzcolumns = "";
- }
- if (Operators.CompareString(myhzcolumns ?? "", "", TextCompare: false) == 0)
- {
- return;
- }
- string[] array = Strings.Split(myhzcolumns, ";");
- if (array.Length < 1)
- {
- return;
- }
- if (dgv.RowCount == srows)
- {
- dgv.Rows.Add();
- }
- decimal num = 0m;
- int num2 = 0;
- int num3 = array.Length - 1;
- string text;
- for (int i = num2; i <= num3; i++)
- {
- num = 0m;
- try
- {
- int num4 = 0;
- int num5 = srows - 1;
- for (int j = num4; j <= num5; j++)
- {
- if (dgv.Rows[j].Visible)
- {
- text = Conversions.ToString(dgv.Rows[j].Cells[array[i]].Value);
- if (Versioned.IsNumeric(text))
- {
- num = decimal.Add(num, Conversions.ToDecimal(text));
- }
- }
- }
- if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[i]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
- {
- dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = false;
- }
- else if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[i]]), "DataGridViewImageColumn", TextCompare: false) == 0)
- {
- dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = null;
- }
- else if (decimal.Compare(new decimal(Convert.ToInt64(num)), num) == 0)
- {
- dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = Conversions.ToString(num);
- }
- else
- {
- dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = Conversions.ToString(num);
- }
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[i]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
- {
- dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = false;
- }
- else if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[i]]), "DataGridViewImageColumn", TextCompare: false) == 0)
- {
- dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = null;
- }
- else
- {
- dgv.Rows[dgv.RowCount - 1].Cells[array[i]].Value = "";
- }
- ProjectData.ClearProjectError();
- }
- }
- if (hzfont != null)
- {
- dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.Font = hzfont;
- }
- if (hzforecolor.ToArgb() != 0)
- {
- dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.ForeColor = hzforecolor;
- }
- if (hzbackcolor.ToArgb() != 0)
- {
- dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.BackColor = hzbackcolor;
- }
- text = GetDGVFirstColumnName(dgv);
- if (Operators.CompareString(text, "", TextCompare: false) != 0)
- {
- dgv.Rows[dgv.RowCount - 1].Cells[text].Value = "总计";
- }
- dgv.Rows[dgv.RowCount - 1].Cells[text].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
- switch (SumNumberAlign)
- {
- case StringAlignment.Near:
- dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
- break;
- case StringAlignment.Center:
- dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- break;
- case StringAlignment.Far:
- dgv.Rows[dgv.RowCount - 1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
- break;
- }
- }
- }
- public static void CreateFzHz(DataGridView dgv, string groupcolumn, string myhzcolumns, Font hzfont, Color hzforecolor, Color hzbackcolor, bool addrowid, bool addrowidnew, StringAlignment SumNumberAlign)
- {
- if (dgv.AllowUserToAddRows)
- {
- dgv.AllowUserToAddRows = false;
- }
- if (addrowid)
- {
- AddDGVRowID(dgv);
- }
- groupcolumn = groupcolumn ?? "";
- if (Operators.CompareString(groupcolumn, "", TextCompare: false) == 0)
- {
- return;
- }
- string[] array = Strings.Split(myhzcolumns, ";");
- if (array.Length < 1)
- {
- return;
- }
- int num = 1;
- int fromrow = 0;
- if (Operators.CompareString(Versioned.TypeName(dgv.Columns[groupcolumn]), "DataGridViewImageColumn", TextCompare: false) == 0)
- {
- return;
- }
- string left = Conversions.ToString(dgv.Rows[0].Cells[groupcolumn].FormattedValue) ?? "";
- checked
- {
- if (dgv.Rows[0].Visible && addrowid)
- {
- dgv.Rows[0].Cells[0].Value = Conversions.ToString(num);
- num++;
- }
- int num2 = dgv.RowCount;
- if (!IsColumNameExists(dgv, myhzcolumns))
- {
- myhzcolumns = "";
- }
- if (Operators.CompareString(myhzcolumns ?? "", "", TextCompare: false) != 0)
- {
- num2--;
- }
- for (int i = 1; i <= num2 - 1; i++)
- {
- if (Operators.CompareString(left, Conversions.ToString(dgv.Rows[i].Cells[groupcolumn].FormattedValue) ?? "", TextCompare: false) != 0)
- {
- left = Conversions.ToString(dgv.Rows[i].Cells[groupcolumn].FormattedValue) ?? "";
- if (addrowidnew)
- {
- num = 1;
- }
- int torow = i - 1;
- if (CreateHzRow(dgv, groupcolumn, myhzcolumns, hzfont, hzforecolor, hzbackcolor, fromrow, torow, SumNumberAlign))
- {
- num2 = dgv.RowCount;
- num2--;
- fromrow = i + 1;
- i++;
- }
- else
- {
- fromrow = i;
- }
- }
- if (dgv.Rows[i].Visible && addrowid)
- {
- dgv.Rows[i].Cells[0].Value = Conversions.ToString(num);
- num++;
- }
- }
- if (Operators.CompareString(myhzcolumns ?? "", "", TextCompare: false) == 0)
- {
- CreateHzRow(dgv, groupcolumn, myhzcolumns, hzfont, hzforecolor, hzbackcolor, fromrow, dgv.RowCount - 1, SumNumberAlign);
- }
- else
- {
- CreateHzRow(dgv, groupcolumn, myhzcolumns, hzfont, hzforecolor, hzbackcolor, fromrow, dgv.RowCount - 1 - 1, SumNumberAlign);
- }
- }
- }
- private static bool CreateHzRow(DataGridView dgv, string groupcolumn, string myhzcolumns, Font hzfont, Color hzforecolor, Color hzbackcolor, int fromrow, int torow, StringAlignment SumNumberAlign)
- {
- checked
- {
- int num = torow + 1;
- decimal num2 = 0m;
- if (Operators.CompareString(myhzcolumns ?? "", "", TextCompare: false) == 0)
- {
- dgv.Rows[torow].Cells[groupcolumn].Tag = "分组";
- return false;
- }
- string[] array = Strings.Split(myhzcolumns, ";");
- if (array.Length < 1)
- {
- return false;
- }
- int num3 = 0;
- for (int i = fromrow; i <= torow; i++)
- {
- if (dgv.Rows[i].Visible)
- {
- num3++;
- }
- }
- if (num3 == 0)
- {
- return false;
- }
- if (num >= dgv.RowCount)
- {
- dgv.Rows.Add();
- }
- else
- {
- dgv.Rows.Insert(num);
- }
- int num4 = 0;
- int num5 = array.Length - 1;
- string text;
- for (int j = num4; j <= num5; j++)
- {
- num2 = 0m;
- try
- {
- for (int k = fromrow; k <= torow; k++)
- {
- if (dgv.Rows[k].Visible)
- {
- text = Conversions.ToString(dgv.Rows[k].Cells[array[j]].Value);
- if (Versioned.IsNumeric(text))
- {
- num2 = decimal.Add(num2, Conversions.ToDecimal(text));
- }
- }
- }
- if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[j]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
- {
- dgv.Rows[num].Cells[array[j]].Value = false;
- }
- else if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[j]]), "DataGridViewImageColumn", TextCompare: false) == 0)
- {
- dgv.Rows[num].Cells[array[j]].Value = null;
- }
- else if (decimal.Compare(new decimal(Convert.ToInt64(num2)), num2) == 0)
- {
- dgv.Rows[num].Cells[array[j]].Value = Conversions.ToString(num2);
- }
- else
- {
- dgv.Rows[num].Cells[array[j]].Value = Conversions.ToString(num2);
- }
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[j]]), "DataGridViewCheckBoxColumn", TextCompare: false) == 0)
- {
- dgv.Rows[num].Cells[array[j]].Value = false;
- }
- else if (Operators.CompareString(Versioned.TypeName(dgv.Columns[array[j]]), "DataGridViewImageColumn", TextCompare: false) == 0)
- {
- dgv.Rows[num].Cells[array[j]].Value = null;
- }
- else
- {
- dgv.Rows[num].Cells[array[j]].Value = "";
- }
- ProjectData.ClearProjectError();
- }
- }
- if (hzfont != null)
- {
- dgv.Rows[num].DefaultCellStyle.Font = hzfont;
- }
- if (hzforecolor.ToArgb() != 0)
- {
- dgv.Rows[num].DefaultCellStyle.ForeColor = hzforecolor;
- }
- if (hzbackcolor.ToArgb() != 0)
- {
- dgv.Rows[num].DefaultCellStyle.BackColor = hzbackcolor;
- }
- dgv.Rows[num].Cells[groupcolumn].Value = RuntimeHelpers.GetObjectValue(dgv.Rows[fromrow].Cells[groupcolumn].Value);
- dgv.Rows[num].Cells[groupcolumn].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
- text = GetDGVFirstColumnName(dgv);
- if (Operators.CompareString(text, "", TextCompare: false) != 0)
- {
- dgv.Rows[num].Cells[text].Value = "小计";
- }
- dgv.Rows[num].Cells[text].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
- dgv.Rows[num].Cells[groupcolumn].Tag = "分组";
- switch (SumNumberAlign)
- {
- case StringAlignment.Near:
- dgv.Rows[num].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
- break;
- case StringAlignment.Center:
- dgv.Rows[num].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- break;
- case StringAlignment.Far:
- dgv.Rows[num].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
- break;
- }
- return true;
- }
- }
- public static string GetDGVFirstColumnName(DataGridView dgv)
- {
- string result = "";
- int num = -1;
- int num2 = 0;
- checked
- {
- int num3 = dgv.ColumnCount - 1;
- for (int i = num2; i <= num3; i++)
- {
- if (num == -1)
- {
- if (dgv.Columns[i].Visible)
- {
- num = dgv.Columns[i].DisplayIndex;
- result = dgv.Columns[i].Name;
- }
- }
- else if (dgv.Columns[i].Visible && dgv.Columns[i].DisplayIndex < num)
- {
- num = dgv.Columns[i].DisplayIndex;
- result = dgv.Columns[i].Name;
- }
- }
- return result;
- }
- }
- public static bool IsHzColumn(string myhzcolumns, string columname)
- {
- if (Operators.CompareString(myhzcolumns, "", TextCompare: false) == 0 || myhzcolumns == null)
- {
- return false;
- }
- string[] array = Strings.Split(myhzcolumns, ";");
- if (array.Length <= 0)
- {
- return false;
- }
- int num = 0;
- checked
- {
- int num2 = array.Length - 1;
- for (int i = num; i <= num2; i++)
- {
- if (Operators.CompareString(array[i], columname, TextCompare: false) == 0)
- {
- return true;
- }
- }
- return false;
- }
- }
- public static bool IsValidPrinterName(string printername)
- {
- bool result = false;
- try
- {
- IEnumerator enumerator = PrinterSettings.InstalledPrinters.GetEnumerator();
- while (enumerator.MoveNext())
- {
- string str = Conversions.ToString(enumerator.Current);
- str = Strings.Trim(str);
- if (Operators.CompareString(printername.ToLower(), str.ToLower(), TextCompare: false) == 0)
- {
- result = true;
- break;
- }
- }
- }
- finally
- {
- IEnumerator enumerator2 = null;
- if (enumerator2 is IDisposable)
- {
- (enumerator2 as IDisposable).Dispose();
- }
- }
- return result;
- }
- public static void CreatePaper(string printername, string papername, int width, int height)
- {
- PrinterSettings printerSettings = new PrinterSettings();
- if (!IsValidPrinterName(printername))
- {
- printername = printerSettings.PrinterName;
- }
- PaperSize printForm = definepaper.GetPrintForm(printername, papername);
- if (printForm != null)
- {
- 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))))
- {
- definepaper.SetPrintForm(printername, papername, width, height);
- }
- }
- else
- {
- definepaper.SetPrintForm(printername, papername, width, height);
- }
- }
- public static bool IsValidPaper(string printername, string papername)
- {
- PrinterSettings printerSettings = new PrinterSettings();
- if (!IsValidPrinterName(printername))
- {
- printername = printerSettings.PrinterName;
- }
- return definepaper.GetPrintForm(printername, papername) != null;
- }
- public static int ConvertPixlsToTwips(float x, bool isx)
- {
- float num = (float)((double)G_ruler.ConvertToMM(x, isx) * 56.7);
- return checked((int)Math.Round(num));
- }
- public static float ConvertTwipsToPixls(float x, bool isx)
- {
- _ = (double)x / 56.7;
- return (float)((double)G_ruler.ConvertFromMM(x, isx) * 5.67);
- }
- public static float ConvertInchToCm(float xx)
- {
- return (float)((double)xx * 2.54);
- }
- public static float ConvertInchToMm(float xx)
- {
- return (float)((double)xx * 25.4);
- }
- public static float ConvertCmToInch(float xx)
- {
- return (float)((double)xx / 2.54);
- }
- public static float ConvertMmToInch(float xx)
- {
- return (float)((double)xx / 25.4);
- }
- public static string ConvertImageToString(string picturefile)
- {
- checked
- {
- string result;
- try
- {
- FileStream fileStream = new FileStream(picturefile, FileMode.Open, FileAccess.Read, FileShare.Read);
- byte[] array = new byte[(int)(fileStream.Length - 1) + 1];
- fileStream.Read(array, 0, (int)fileStream.Length);
- fileStream.Close();
- result = Convert.ToBase64String(array);
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- result = "";
- ProjectData.ClearProjectError();
- }
- return result;
- }
- }
- public static string ConvertImageToString(Image img)
- {
- string result;
- if (img == null)
- {
- result = "";
- }
- else
- {
- try
- {
- string tempFileName = MyProject.Computer.FileSystem.GetTempFileName();
- img.Save(tempFileName, ImageFormat.Png);
- string text = ConvertImageToString(tempFileName);
- try
- {
- MyProject.Computer.FileSystem.DeleteFile(tempFileName);
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- result = text;
- }
- catch (Exception projectError2)
- {
- ProjectData.SetProjectError(projectError2);
- result = "";
- ProjectData.ClearProjectError();
- }
- }
- return result;
- }
- public static Image ConvertStringToImage(string picturestring)
- {
- Image result;
- if (Operators.CompareString(picturestring ?? "", "", TextCompare: false) == 0)
- {
- result = null;
- }
- else
- {
- try
- {
- byte[] buffer = Convert.FromBase64String(picturestring);
- MemoryStream stream = new MemoryStream(buffer);
- result = Image.FromStream(stream);
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- result = null;
- ProjectData.ClearProjectError();
- }
- }
- return result;
- }
- public static string ConvertIcoToString(Icon img)
- {
- checked
- {
- string result;
- try
- {
- MemoryStream memoryStream = new MemoryStream();
- img.Save(memoryStream);
- memoryStream.Position = 0L;
- byte[] array = new byte[(int)(memoryStream.Length - 1) + 1];
- memoryStream.Read(array, 0, (int)memoryStream.Length);
- memoryStream.Close();
- result = Convert.ToBase64String(array);
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- result = "";
- ProjectData.ClearProjectError();
- }
- return result;
- }
- }
- public static Icon ConvertStringToIcon(string picturestring)
- {
- Icon result;
- if (Operators.CompareString(picturestring ?? "", "", TextCompare: false) == 0)
- {
- result = null;
- }
- else
- {
- try
- {
- byte[] buffer = Convert.FromBase64String(picturestring);
- MemoryStream stream = new MemoryStream(buffer);
- result = new Icon(stream);
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- result = null;
- ProjectData.ClearProjectError();
- }
- }
- return result;
- }
- private static DataGridView ConvertListViewToDGV2(ListView lv)
- {
- if (lv == null)
- {
- return null;
- }
- DataGridView dataGridView = new DataGridView();
- dataGridView.AllowUserToAddRows = false;
- dataGridView.RowCount = lv.Items.Count;
- dataGridView.ColumnCount = lv.Columns.Count;
- try
- {
- dataGridView.DefaultCellStyle.Font = (Font)lv.Font.Clone();
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- dataGridView.ForeColor = lv.ForeColor;
- dataGridView.DefaultCellStyle.ForeColor = lv.ForeColor;
- int num = 0;
- checked
- {
- int num2 = lv.Columns.Count - 1;
- for (int i = num; i <= num2; i++)
- {
- dataGridView.Columns[i].HeaderText = lv.Columns[i].Text;
- try
- {
- dataGridView.Columns[i].DefaultCellStyle.Font = (Font)lv.Font.Clone();
- }
- catch (Exception projectError2)
- {
- ProjectData.SetProjectError(projectError2);
- ProjectData.ClearProjectError();
- }
- dataGridView.Columns[i].Width = lv.Columns[i].Width;
- dataGridView.Columns[i].DisplayIndex = lv.Columns[i].DisplayIndex;
- }
- int num3 = 0;
- int num4 = lv.Items.Count - 1;
- for (int j = num3; j <= num4; j++)
- {
- CopyListViewItemToDGV(lv, lv.Items[j], dataGridView.Rows[j]);
- }
- return dataGridView;
- }
- }
- public static DataGridView ConvertListViewToDGV(ListView lv)
- {
- if (lv == null)
- {
- return null;
- }
- if (!lv.ShowGroups)
- {
- return ConvertListViewToDGV2(lv);
- }
- DataGridView dataGridView = new DataGridView();
- dataGridView.ColumnCount = lv.Columns.Count;
- dataGridView.AllowUserToAddRows = false;
- try
- {
- dataGridView.DefaultCellStyle.Font = (Font)lv.Font.Clone();
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- dataGridView.ForeColor = lv.ForeColor;
- dataGridView.DefaultCellStyle.ForeColor = lv.ForeColor;
- int num = 0;
- checked
- {
- int num2 = lv.Columns.Count - 1;
- for (int i = num; i <= num2; i++)
- {
- dataGridView.Columns[i].HeaderText = lv.Columns[i].Text;
- try
- {
- dataGridView.Columns[i].DefaultCellStyle.Font = (Font)lv.Font.Clone();
- }
- catch (Exception projectError2)
- {
- ProjectData.SetProjectError(projectError2);
- ProjectData.ClearProjectError();
- }
- dataGridView.Columns[i].Width = lv.Columns[i].Width;
- dataGridView.Columns[i].DisplayIndex = lv.Columns[i].DisplayIndex;
- }
- bool flag = false;
- int num3 = 0;
- int num4 = lv.Items.Count - 1;
- for (int j = num3; j <= num4; j++)
- {
- if (lv.Items[j].Group == null)
- {
- flag = true;
- break;
- }
- }
- if (flag)
- {
- dataGridView.RowCount++;
- DataGridViewRow currow = dataGridView.Rows[dataGridView.RowCount - 1];
- CopyListViewGroutItemToDGV(lv, "Default", HorizontalAlignment.Left, currow);
- int num5 = 0;
- int num6 = lv.Items.Count - 1;
- for (int k = num5; k <= num6; k++)
- {
- if (lv.Items[k].Group == null)
- {
- dataGridView.RowCount++;
- currow = dataGridView.Rows[dataGridView.RowCount - 1];
- CopyListViewItemToDGV(lv, lv.Items[k], currow);
- }
- }
- }
- int num7 = 0;
- int num8 = lv.Groups.Count - 1;
- for (int l = num7; l <= num8; l++)
- {
- if (lv.Groups[l].Items.Count > 0)
- {
- dataGridView.RowCount++;
- DataGridViewRow currow2 = dataGridView.Rows[dataGridView.RowCount - 1];
- CopyListViewGroutItemToDGV(lv, lv.Groups[l].Header, lv.Groups[l].HeaderAlignment, currow2);
- int num9 = 0;
- int num10 = lv.Groups[l].Items.Count - 1;
- for (int m = num9; m <= num10; m++)
- {
- dataGridView.RowCount++;
- currow2 = dataGridView.Rows[dataGridView.RowCount - 1];
- CopyListViewItemToDGV(lv, lv.Groups[l].Items[m], currow2);
- }
- }
- }
- return dataGridView;
- }
- }
- private static void CopyListViewGroutItemToDGV(ListView lv, string mygroupname, HorizontalAlignment alg, DataGridViewRow currow)
- {
- try
- {
- currow.DefaultCellStyle.Font = new Font(lv.Font, FontStyle.Bold);
- currow.DefaultCellStyle.ForeColor = Color.Black;
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- switch (alg)
- {
- case HorizontalAlignment.Right:
- currow.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
- break;
- case HorizontalAlignment.Center:
- currow.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
- break;
- default:
- currow.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
- break;
- }
- int num = 0;
- checked
- {
- int num2 = lv.Columns.Count - 1;
- for (int i = num; i <= num2; i++)
- {
- currow.Cells[i].Value = mygroupname;
- currow.Cells[i].Tag = "水平合并";
- }
- }
- }
- private static void CopyListViewItemToDGV(ListView lv, ListViewItem myitem, DataGridViewRow myrow)
- {
- string text = myitem.Text;
- if (lv.CheckBoxes)
- {
- text = ((!myitem.Checked) ? ("□ " + text) : ("■ " + text));
- }
- myrow.Cells[0].Value = text;
- try
- {
- myrow.Cells[0].Style.Font = (Font)myitem.Font.Clone();
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- myrow.Cells[0].Style.ForeColor = myitem.ForeColor;
- myrow.Cells[0].Style.BackColor = myitem.BackColor;
- try
- {
- myrow.DefaultCellStyle.Font = (Font)myitem.Font.Clone();
- }
- catch (Exception projectError2)
- {
- ProjectData.SetProjectError(projectError2);
- ProjectData.ClearProjectError();
- }
- myrow.DefaultCellStyle.BackColor = myitem.BackColor;
- myrow.DefaultCellStyle.ForeColor = myitem.ForeColor;
- int num = 1;
- checked
- {
- int num2 = lv.Columns.Count - 1;
- for (int i = num; i <= num2; i++)
- {
- if (i >= myitem.SubItems.Count)
- {
- continue;
- }
- myrow.Cells[i].Value = myitem.SubItems[i].Text;
- if (!myitem.UseItemStyleForSubItems)
- {
- try
- {
- myrow.Cells[i].Style.Font = (Font)myitem.SubItems[i].Font.Clone();
- }
- catch (Exception projectError3)
- {
- ProjectData.SetProjectError(projectError3);
- ProjectData.ClearProjectError();
- }
- myrow.Cells[i].Style.ForeColor = myitem.SubItems[i].ForeColor;
- myrow.Cells[i].Style.BackColor = myitem.SubItems[i].BackColor;
- }
- }
- }
- }
- public static string SaveHashTableAsString(Hashtable hh)
- {
- string text = "\u0003";
- string text2 = "\a";
- if (hh == null)
- {
- return "";
- }
- string[,] array = mbsjmodule.ParaseVar(hh);
- string text3 = "";
- if (array == null)
- {
- return "";
- }
- int num = 0;
- checked
- {
- int num2 = array.GetLength(0) - 1;
- for (int i = num; i <= num2; i++)
- {
- text3 = ((i != 0) ? (text3 + text + array[i, 0] + text2 + array[i, 1]) : (array[i, 0] + text2 + array[i, 1]));
- }
- return text3;
- }
- }
- public static Hashtable RestoreHashTableFromString(string ss)
- {
- if (Operators.CompareString(ss, "", TextCompare: false) == 0)
- {
- return null;
- }
- string delimiter = "\u0003";
- string delimiter2 = "\a";
- string[] array = Strings.Split(ss, delimiter);
- Hashtable hashtable = new Hashtable();
- int num = 0;
- checked
- {
- int num2 = array.Length - 1;
- for (int i = num; i <= num2; i++)
- {
- string[] array2 = Strings.Split(array[i], delimiter2);
- hashtable.Add(array2[0], array2[1]);
- }
- return hashtable;
- }
- }
- public static Font GetDGVHeaderFont(DataGridViewColumn mycolumn)
- {
- DataGridView dataGridView = mycolumn.DataGridView;
- if (mycolumn.HeaderCell.Style.Font != null)
- {
- return mycolumn.HeaderCell.Style.Font;
- }
- if (dataGridView.ColumnHeadersDefaultCellStyle.Font == null)
- {
- return dataGridView.DefaultCellStyle.Font;
- }
- return dataGridView.ColumnHeadersDefaultCellStyle.Font;
- }
- public static Color GetDGVHeaderForeColor(DataGridViewColumn mycolumn)
- {
- DataGridView dataGridView = mycolumn.DataGridView;
- if (mycolumn.HeaderCell.Style.ForeColor.ToArgb() == 0)
- {
- if (dataGridView.ColumnHeadersDefaultCellStyle.ForeColor.ToArgb() == 0)
- {
- return dataGridView.DefaultCellStyle.ForeColor;
- }
- return dataGridView.ColumnHeadersDefaultCellStyle.ForeColor;
- }
- return mycolumn.HeaderCell.Style.ForeColor;
- }
- public static bool GetDGVHeaderMulline(DataGridViewColumn mycolumn)
- {
- DataGridView dataGridView = mycolumn.DataGridView;
- if (mycolumn.HeaderCell.Style.WrapMode == DataGridViewTriState.NotSet)
- {
- if (dataGridView.ColumnHeadersDefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
- {
- return GetMulline(dataGridView.DefaultCellStyle.WrapMode);
- }
- return GetMulline(dataGridView.ColumnHeadersDefaultCellStyle.WrapMode);
- }
- return GetMulline(mycolumn.HeaderCell.Style.WrapMode);
- }
- public static Color GetDGVHeaderBackColor(DataGridViewColumn mycolumn)
- {
- DataGridView dataGridView = mycolumn.DataGridView;
- if (mycolumn.HeaderCell.Style.BackColor.ToArgb() == 0)
- {
- if (dataGridView.ColumnHeadersDefaultCellStyle.BackColor.ToArgb() == 0)
- {
- return dataGridView.DefaultCellStyle.BackColor;
- }
- return dataGridView.ColumnHeadersDefaultCellStyle.BackColor;
- }
- return mycolumn.HeaderCell.Style.BackColor;
- }
- public static Font GetDGVCellFont(DataGridViewCell mycell)
- {
- DataGridView dataGridView = mycell.DataGridView;
- int rowIndex = mycell.RowIndex;
- DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
- DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
- Font result;
- try
- {
- 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)))));
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- result = dataGridView.DefaultCellStyle.Font;
- ProjectData.ClearProjectError();
- }
- dataGridView = null;
- return result;
- }
- public static Color GetDGVCellForeColor(DataGridViewCell mycell)
- {
- DataGridView dataGridView = mycell.DataGridView;
- int rowIndex = mycell.RowIndex;
- DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
- DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
- if (dataGridViewRow.Cells[dataGridViewColumn.Index].Style.ForeColor.ToArgb() == 0)
- {
- if (dataGridViewRow.DefaultCellStyle.ForeColor.ToArgb() == 0)
- {
- if (checked(rowIndex + 1) % 2 == 0)
- {
- if (dataGridView.AlternatingRowsDefaultCellStyle.ForeColor.ToArgb() == 0)
- {
- if (dataGridView.RowsDefaultCellStyle.ForeColor.ToArgb() == 0)
- {
- if (dataGridViewColumn.DefaultCellStyle.ForeColor.ToArgb() == 0)
- {
- return dataGridView.DefaultCellStyle.ForeColor;
- }
- return dataGridViewColumn.DefaultCellStyle.ForeColor;
- }
- return dataGridView.RowsDefaultCellStyle.ForeColor;
- }
- return dataGridView.AlternatingRowsDefaultCellStyle.ForeColor;
- }
- if (dataGridView.RowsDefaultCellStyle.ForeColor.ToArgb() == 0)
- {
- if (dataGridViewColumn.DefaultCellStyle.ForeColor.ToArgb() == 0)
- {
- return dataGridView.DefaultCellStyle.ForeColor;
- }
- return dataGridViewColumn.DefaultCellStyle.ForeColor;
- }
- return dataGridView.RowsDefaultCellStyle.ForeColor;
- }
- return dataGridViewRow.DefaultCellStyle.ForeColor;
- }
- return dataGridViewRow.Cells[dataGridViewColumn.Index].Style.ForeColor;
- }
- public static Color GetDGVCellBackColor(DataGridViewCell mycell)
- {
- DataGridView dataGridView = mycell.DataGridView;
- int rowIndex = mycell.RowIndex;
- DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
- DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
- if (dataGridViewRow.Cells[dataGridViewColumn.Index].Style.BackColor.ToArgb() == 0)
- {
- if (dataGridViewRow.DefaultCellStyle.BackColor.ToArgb() == 0)
- {
- if (checked(rowIndex + 1) % 2 == 0)
- {
- if (dataGridView.AlternatingRowsDefaultCellStyle.BackColor.ToArgb() == 0)
- {
- if (dataGridView.RowsDefaultCellStyle.BackColor.ToArgb() == 0)
- {
- if (dataGridViewColumn.DefaultCellStyle.BackColor.ToArgb() == 0)
- {
- return dataGridView.DefaultCellStyle.BackColor;
- }
- return dataGridViewColumn.DefaultCellStyle.BackColor;
- }
- return dataGridView.RowsDefaultCellStyle.BackColor;
- }
- return dataGridView.AlternatingRowsDefaultCellStyle.BackColor;
- }
- if (dataGridView.RowsDefaultCellStyle.BackColor.ToArgb() == 0)
- {
- if (dataGridViewColumn.DefaultCellStyle.BackColor.ToArgb() == 0)
- {
- return dataGridView.DefaultCellStyle.BackColor;
- }
- return dataGridViewColumn.DefaultCellStyle.BackColor;
- }
- return dataGridView.RowsDefaultCellStyle.BackColor;
- }
- return dataGridViewRow.DefaultCellStyle.BackColor;
- }
- return dataGridViewRow.Cells[dataGridViewColumn.Index].Style.BackColor;
- }
- public static bool GetDGVCellMulline(DataGridViewCell mycell)
- {
- DataGridView dataGridView = mycell.DataGridView;
- int rowIndex = mycell.RowIndex;
- DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
- DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
- if (dataGridViewRow.Cells[dataGridViewColumn.Index].Style.WrapMode == DataGridViewTriState.NotSet)
- {
- if (dataGridViewRow.DefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
- {
- if (checked(rowIndex + 1) % 2 == 0)
- {
- if (dataGridView.AlternatingRowsDefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
- {
- if (dataGridView.RowsDefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
- {
- if (dataGridViewColumn.DefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
- {
- return GetMulline(dataGridView.DefaultCellStyle.WrapMode);
- }
- return GetMulline(dataGridViewColumn.DefaultCellStyle.WrapMode);
- }
- return GetMulline(dataGridView.RowsDefaultCellStyle.WrapMode);
- }
- return GetMulline(dataGridView.AlternatingRowsDefaultCellStyle.WrapMode);
- }
- if (dataGridView.RowsDefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
- {
- if (dataGridViewColumn.DefaultCellStyle.WrapMode == DataGridViewTriState.NotSet)
- {
- return GetMulline(dataGridView.DefaultCellStyle.WrapMode);
- }
- return GetMulline(dataGridViewColumn.DefaultCellStyle.WrapMode);
- }
- return GetMulline(dataGridView.RowsDefaultCellStyle.WrapMode);
- }
- return GetMulline(dataGridViewRow.DefaultCellStyle.WrapMode);
- }
- return GetMulline(dataGridViewRow.Cells[dataGridViewColumn.Index].Style.WrapMode);
- }
- public static Margins GetDGVCellPadding(DataGridViewCell mycell)
- {
- Margins margins = new Margins();
- DataGridView dataGridView = mycell.DataGridView;
- int rowIndex = mycell.RowIndex;
- DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
- DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
- if (dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Padding.All == 0)
- {
- if (dataGridViewRow.DefaultCellStyle.Padding.All == 0)
- {
- if (checked(rowIndex + 1) % 2 == 0)
- {
- if (dataGridView.AlternatingRowsDefaultCellStyle.Padding.All == 0)
- {
- if (dataGridView.RowsDefaultCellStyle.Padding.All == 0)
- {
- if (dataGridViewColumn.DefaultCellStyle.Padding.All == 0)
- {
- margins.Left = dataGridView.DefaultCellStyle.Padding.Left;
- margins.Top = dataGridView.DefaultCellStyle.Padding.Top;
- margins.Right = dataGridView.DefaultCellStyle.Padding.Right;
- margins.Bottom = dataGridView.DefaultCellStyle.Padding.Bottom;
- }
- else
- {
- margins.Left = dataGridViewColumn.DefaultCellStyle.Padding.Left;
- margins.Top = dataGridViewColumn.DefaultCellStyle.Padding.Top;
- margins.Right = dataGridViewColumn.DefaultCellStyle.Padding.Right;
- margins.Bottom = dataGridViewColumn.DefaultCellStyle.Padding.Bottom;
- }
- }
- else
- {
- margins.Left = dataGridView.RowsDefaultCellStyle.Padding.Left;
- margins.Top = dataGridView.RowsDefaultCellStyle.Padding.Top;
- margins.Right = dataGridView.RowsDefaultCellStyle.Padding.Right;
- margins.Bottom = dataGridView.RowsDefaultCellStyle.Padding.Bottom;
- }
- }
- else
- {
- margins.Left = dataGridView.AlternatingRowsDefaultCellStyle.Padding.Left;
- margins.Top = dataGridView.AlternatingRowsDefaultCellStyle.Padding.Top;
- margins.Right = dataGridView.AlternatingRowsDefaultCellStyle.Padding.Right;
- margins.Bottom = dataGridView.AlternatingRowsDefaultCellStyle.Padding.Bottom;
- }
- }
- else if (dataGridView.RowsDefaultCellStyle.Padding.All == 0)
- {
- if (dataGridViewColumn.DefaultCellStyle.Padding.All == 0)
- {
- margins.Left = dataGridView.DefaultCellStyle.Padding.Left;
- margins.Top = dataGridView.DefaultCellStyle.Padding.Top;
- margins.Right = dataGridView.DefaultCellStyle.Padding.Right;
- margins.Bottom = dataGridView.DefaultCellStyle.Padding.Bottom;
- }
- else
- {
- margins.Left = dataGridViewColumn.DefaultCellStyle.Padding.Left;
- margins.Top = dataGridViewColumn.DefaultCellStyle.Padding.Top;
- margins.Right = dataGridViewColumn.DefaultCellStyle.Padding.Right;
- margins.Bottom = dataGridViewColumn.DefaultCellStyle.Padding.Bottom;
- }
- }
- else
- {
- margins.Left = dataGridView.RowsDefaultCellStyle.Padding.Left;
- margins.Top = dataGridView.RowsDefaultCellStyle.Padding.Top;
- margins.Right = dataGridView.RowsDefaultCellStyle.Padding.Right;
- margins.Bottom = dataGridView.RowsDefaultCellStyle.Padding.Bottom;
- }
- }
- else
- {
- margins.Left = dataGridViewRow.DefaultCellStyle.Padding.Left;
- margins.Top = dataGridViewRow.DefaultCellStyle.Padding.Top;
- margins.Right = dataGridViewRow.DefaultCellStyle.Padding.Right;
- margins.Bottom = dataGridViewRow.DefaultCellStyle.Padding.Bottom;
- }
- }
- else
- {
- margins.Left = dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Padding.Left;
- margins.Top = dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Padding.Top;
- margins.Right = dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Padding.Right;
- margins.Bottom = dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Padding.Bottom;
- }
- return margins;
- }
- public static DataGridViewCellStyle GetDGVCellStyle(DataGridViewCell mycell)
- {
- DataGridView dataGridView = mycell.DataGridView;
- int rowIndex = mycell.RowIndex;
- DataGridViewRow dataGridViewRow = dataGridView.Rows[mycell.RowIndex];
- DataGridViewColumn dataGridViewColumn = dataGridView.Columns[mycell.ColumnIndex];
- if (dataGridViewRow.Cells[dataGridViewColumn.Index].Style.Alignment == DataGridViewContentAlignment.NotSet)
- {
- if (dataGridViewRow.DefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
- {
- if (checked(rowIndex + 1) % 2 == 0)
- {
- if (dataGridView.AlternatingRowsDefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
- {
- if (dataGridView.RowsDefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
- {
- if (dataGridViewColumn.DefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
- {
- return dataGridView.DefaultCellStyle;
- }
- return dataGridViewColumn.DefaultCellStyle;
- }
- return dataGridView.RowsDefaultCellStyle;
- }
- return dataGridView.AlternatingRowsDefaultCellStyle;
- }
- if (dataGridView.RowsDefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
- {
- if (dataGridViewColumn.DefaultCellStyle.Alignment == DataGridViewContentAlignment.NotSet)
- {
- return dataGridView.DefaultCellStyle;
- }
- return dataGridViewColumn.DefaultCellStyle;
- }
- return dataGridView.RowsDefaultCellStyle;
- }
- return dataGridViewRow.DefaultCellStyle;
- }
- return dataGridViewRow.Cells[dataGridViewColumn.Index].Style;
- }
- public static StringAlignment GetHAlignment(DataGridViewContentAlignment mytt)
- {
- switch (mytt)
- {
- default:
- return StringAlignment.Near;
- case DataGridViewContentAlignment.TopRight:
- case DataGridViewContentAlignment.MiddleRight:
- case DataGridViewContentAlignment.BottomRight:
- return StringAlignment.Far;
- case DataGridViewContentAlignment.NotSet:
- case DataGridViewContentAlignment.TopLeft:
- case DataGridViewContentAlignment.MiddleLeft:
- case DataGridViewContentAlignment.BottomLeft:
- return StringAlignment.Near;
- case DataGridViewContentAlignment.TopCenter:
- case DataGridViewContentAlignment.MiddleCenter:
- case DataGridViewContentAlignment.BottomCenter:
- return StringAlignment.Center;
- }
- }
- public static StringAlignment GetVAlignment(DataGridViewContentAlignment mytt, bool IsDGVCellValignmentCenter)
- {
- if (IsDGVCellValignmentCenter)
- {
- return StringAlignment.Center;
- }
- switch (mytt)
- {
- default:
- return StringAlignment.Center;
- case DataGridViewContentAlignment.NotSet:
- case DataGridViewContentAlignment.TopLeft:
- case DataGridViewContentAlignment.TopCenter:
- case DataGridViewContentAlignment.TopRight:
- return StringAlignment.Near;
- case DataGridViewContentAlignment.MiddleLeft:
- case DataGridViewContentAlignment.MiddleCenter:
- case DataGridViewContentAlignment.MiddleRight:
- return StringAlignment.Center;
- case DataGridViewContentAlignment.BottomLeft:
- case DataGridViewContentAlignment.BottomCenter:
- case DataGridViewContentAlignment.BottomRight:
- return StringAlignment.Far;
- }
- }
- public static bool GetMulline(DataGridViewTriState mytt)
- {
- switch (mytt)
- {
- case DataGridViewTriState.NotSet:
- case DataGridViewTriState.False:
- return false;
- default:
- return true;
- }
- }
- public static Font GetDGVColumnHeaderFont(DataGridView dgv, string colname)
- {
- if (dgv == null)
- {
- return null;
- }
- DataGridViewColumn dataGridViewColumn;
- try
- {
- dataGridViewColumn = dgv.Columns[colname];
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- Font result = null;
- ProjectData.ClearProjectError();
- return result;
- }
- if (dataGridViewColumn == null)
- {
- return null;
- }
- return (dataGridViewColumn.HeaderCell.Style.Font != null) ? dataGridViewColumn.HeaderCell.Style.Font : ((dgv.ColumnHeadersDefaultCellStyle.Font != null) ? dgv.ColumnHeadersDefaultCellStyle.Font : dgv.DefaultCellStyle.Font);
- }
- public static Color GetDGVColumnHeaderForeColor(DataGridView dgv, string colname)
- {
- if (dgv == null)
- {
- return Color.Black;
- }
- DataGridViewColumn dataGridViewColumn;
- try
- {
- dataGridViewColumn = dgv.Columns[colname];
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- Color black = Color.Black;
- ProjectData.ClearProjectError();
- return black;
- }
- if (dataGridViewColumn == null)
- {
- return Color.Black;
- }
- return (dataGridViewColumn.HeaderCell.Style.ForeColor.ToArgb() != 0) ? dataGridViewColumn.HeaderCell.Style.ForeColor : ((dgv.ColumnHeadersDefaultCellStyle.ForeColor.ToArgb() != 0) ? dgv.ColumnHeadersDefaultCellStyle.ForeColor : dgv.DefaultCellStyle.ForeColor);
- }
- public static Color GetDGVColumnHeaderBackColor(DataGridView dgv, string colname)
- {
- if (dgv == null)
- {
- return Color.White;
- }
- DataGridViewColumn dataGridViewColumn;
- try
- {
- dataGridViewColumn = dgv.Columns[colname];
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- Color white = Color.White;
- ProjectData.ClearProjectError();
- return white;
- }
- if (dataGridViewColumn == null)
- {
- return Color.White;
- }
- return (dataGridViewColumn.HeaderCell.Style.BackColor.ToArgb() != 0) ? dataGridViewColumn.HeaderCell.Style.BackColor : ((dgv.ColumnHeadersDefaultCellStyle.BackColor.ToArgb() != 0) ? dgv.ColumnHeadersDefaultCellStyle.BackColor : dgv.DefaultCellStyle.BackColor);
- }
- public static Font GetDGVColumnFont(DataGridView dgv, string colname)
- {
- if (dgv == null)
- {
- return null;
- }
- DataGridViewColumn dataGridViewColumn;
- try
- {
- dataGridViewColumn = dgv.Columns[colname];
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- Font result = null;
- ProjectData.ClearProjectError();
- return result;
- }
- if (dataGridViewColumn == null)
- {
- return null;
- }
- return (dgv.RowsDefaultCellStyle.Font != null) ? dgv.RowsDefaultCellStyle.Font : ((dataGridViewColumn.DefaultCellStyle.Font != null) ? dataGridViewColumn.DefaultCellStyle.Font : dgv.DefaultCellStyle.Font);
- }
- public static Color GetDGVColumnForeColor(DataGridView dgv, string colname)
- {
- if (dgv == null)
- {
- return Color.Black;
- }
- DataGridViewColumn dataGridViewColumn;
- try
- {
- dataGridViewColumn = dgv.Columns[colname];
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- Color black = Color.Black;
- ProjectData.ClearProjectError();
- return black;
- }
- if (dataGridViewColumn == null)
- {
- return Color.Black;
- }
- return (dgv.RowsDefaultCellStyle.ForeColor.ToArgb() != 0) ? dgv.RowsDefaultCellStyle.ForeColor : ((dataGridViewColumn.DefaultCellStyle.ForeColor.ToArgb() != 0) ? dataGridViewColumn.DefaultCellStyle.ForeColor : dgv.DefaultCellStyle.ForeColor);
- }
- public static Color GetDGVColumnBackColor(DataGridView dgv, string colname)
- {
- if (dgv == null)
- {
- return Color.Black;
- }
- DataGridViewColumn dataGridViewColumn;
- try
- {
- dataGridViewColumn = dgv.Columns[colname];
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- Color black = Color.Black;
- ProjectData.ClearProjectError();
- return black;
- }
- if (dataGridViewColumn == null)
- {
- return Color.Black;
- }
- return (dgv.RowsDefaultCellStyle.BackColor.ToArgb() != 0) ? dgv.RowsDefaultCellStyle.BackColor : ((dataGridViewColumn.DefaultCellStyle.BackColor.ToArgb() != 0) ? dataGridViewColumn.DefaultCellStyle.BackColor : dgv.DefaultCellStyle.BackColor);
- }
- public static bool GetDGVColumnMulLine(DataGridView dgv, string colname)
- {
- if (dgv == null)
- {
- return false;
- }
- DataGridViewColumn dataGridViewColumn;
- try
- {
- dataGridViewColumn = dgv.Columns[colname];
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- bool result = false;
- ProjectData.ClearProjectError();
- return result;
- }
- if (dataGridViewColumn == null)
- {
- return false;
- }
- return (dgv.RowsDefaultCellStyle.WrapMode != 0) ? GetMulline(dgv.RowsDefaultCellStyle.WrapMode) : ((dataGridViewColumn.DefaultCellStyle.WrapMode != 0) ? GetMulline(dataGridViewColumn.DefaultCellStyle.WrapMode) : GetMulline(dgv.DefaultCellStyle.WrapMode));
- }
- public static ContentAlignment GetDGVColumnAlignment(DataGridView dgv, string colname)
- {
- if (dgv == null)
- {
- return ContentAlignment.MiddleLeft;
- }
- DataGridViewColumn dataGridViewColumn;
- try
- {
- dataGridViewColumn = dgv.Columns[colname];
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ContentAlignment result1 = ContentAlignment.MiddleLeft;
- ProjectData.ClearProjectError();
- return result1;
- }
- if (dataGridViewColumn == null)
- {
- return ContentAlignment.MiddleLeft;
- }
- DataGridViewCellStyle dataGridViewCellStyle = ((dgv.RowsDefaultCellStyle.Alignment != 0) ? dgv.RowsDefaultCellStyle : ((dataGridViewColumn.DefaultCellStyle.Alignment != 0) ? dataGridViewColumn.DefaultCellStyle : dgv.DefaultCellStyle));
- ContentAlignment result;
- DataGridViewContentAlignment alignment = dataGridViewCellStyle.Alignment;
- if (alignment == DataGridViewContentAlignment.BottomCenter)
- {
- result = ContentAlignment.BottomCenter;
- }
- else if (alignment == DataGridViewContentAlignment.BottomLeft)
- {
- result = ContentAlignment.BottomLeft;
- }
- else if (alignment == DataGridViewContentAlignment.BottomRight)
- {
- result = ContentAlignment.BottomRight;
- }
- else if (alignment == DataGridViewContentAlignment.MiddleCenter)
- {
- result = ContentAlignment.MiddleCenter;
- }
- else if (alignment == DataGridViewContentAlignment.MiddleLeft)
- {
- result = ContentAlignment.MiddleLeft;
- }
- else if (alignment == DataGridViewContentAlignment.MiddleRight)
- {
- result = ContentAlignment.MiddleRight;
- }
- else if (alignment == DataGridViewContentAlignment.NotSet)
- {
- result = ContentAlignment.MiddleLeft;
- }
- else if (alignment == DataGridViewContentAlignment.TopCenter)
- {
- result = ContentAlignment.TopCenter;
- }
- else if (alignment == DataGridViewContentAlignment.TopLeft)
- {
- result = ContentAlignment.TopLeft;
- }
- else if (alignment == DataGridViewContentAlignment.TopRight)
- {
- result = ContentAlignment.TopRight;
- }
- else
- {
- result = ContentAlignment.MiddleLeft;
- }
- return result;
- }
- public static string EncryptionString(string ss)
- {
- byte[] bytes = Encoding.Unicode.GetBytes(ss);
- MemoryStream memoryStream = new MemoryStream();
- CryptoStream cryptoStream = new CryptoStream(memoryStream, new TripleDESCryptoServiceProvider
- {
- Key = G_mykey,
- IV = G_myiv
- }.CreateEncryptor(), CryptoStreamMode.Write);
- cryptoStream.Write(bytes, 0, bytes.Length);
- cryptoStream.Close();
- string result = Convert.ToBase64String(memoryStream.ToArray());
- memoryStream.Dispose();
- return result;
- }
- public static string DecryptionString(string ss)
- {
- TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider();
- MemoryStream memoryStream = new MemoryStream();
- tripleDESCryptoServiceProvider.Key = G_mykey;
- tripleDESCryptoServiceProvider.IV = G_myiv;
- CryptoStream cryptoStream = new CryptoStream(memoryStream, tripleDESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write);
- byte[] array = Convert.FromBase64String(ss);
- cryptoStream.Write(array, 0, array.Length);
- cryptoStream.Close();
- string @string = Encoding.Unicode.GetString(memoryStream.ToArray());
- memoryStream.Dispose();
- return @string;
- }
- public static Bitmap getDGVCheckBoxCellImage(DataGridViewCell dgvcell, Color mybkcolor)
- {
- Bitmap result;
- if (dgvcell == null)
- {
- result = null;
- }
- else
- {
- CheckBox checkBox = new CheckBox();
- Control control = checkBox;
- Size size = new Size(14, 14);
- control.Size = size;
- checkBox.BackColor = mybkcolor;
- if (dgvcell.FormattedValue != null)
- {
- if (Operators.CompareString(Versioned.TypeName(RuntimeHelpers.GetObjectValue(dgvcell.FormattedValue)), "Boolean", TextCompare: false) == 0)
- {
- if (Conversions.ToBoolean(dgvcell.FormattedValue))
- {
- checkBox.Checked = true;
- }
- else
- {
- checkBox.Checked = false;
- }
- }
- else
- {
- switch (Conversions.ToInteger(dgvcell.FormattedValue))
- {
- case 0:
- checkBox.Checked = false;
- break;
- case 1:
- checkBox.Checked = true;
- break;
- default:
- checkBox.CheckState = CheckState.Indeterminate;
- break;
- }
- }
- }
- else
- {
- checkBox.Checked = false;
- }
- try
- {
- Bitmap bitmap = new Bitmap(14, 14);
- Graphics graphics = Graphics.FromImage(bitmap);
- Brush brush = new SolidBrush(mybkcolor);
- Graphics graphics2 = graphics;
- Brush brush2 = brush;
- Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
- graphics2.FillRectangle(brush2, rect);
- if (bitmap.Height < checkBox.Height)
- {
- checkBox.Height = bitmap.Height;
- }
- if (bitmap.Width < checkBox.Width)
- {
- checkBox.Width = bitmap.Width;
- }
- Control control2 = checkBox;
- Bitmap bitmap2 = bitmap;
- 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));
- control2.DrawToBitmap(bitmap2, rect);
- graphics.Dispose();
- checkBox.Dispose();
- result = bitmap;
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- result = null;
- ProjectData.ClearProjectError();
- }
- }
- return result;
- }
- }
- }
|