123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Text.RegularExpressions;
- using System.Data;
- using System.Collections;
- using LYFZ;
- using System.IO;
- using Newtonsoft.Json;
- namespace LYFZ.ComponentLibrary
- {
- public partial class DataGridViewEc : DataGridView
- {
- #region 属性
- /// <summary>
- /// 行首收缩图标
- /// </summary>
- private Image m_imgExpand;
- /// <summary>
- /// 行首展开图片
- /// </summary>
- private Image m_imgCollapse;
- /// <summary>
- /// 行首图片宽度(默认15)
- /// </summary>
- private int m_nImageWidth;
- /// <summary>
- /// 行首图片高度(默认15)
- /// </summary>
- private int m_nImageHeight;
- /// <summary>
- /// Ord_ViceOrderCount 展开参数 \r\n
- /// Ord_ViceOrderCount 的值要大于多少才能可以展开 \r\n
- /// 建议设置 0或1
- /// </summary>
- private int _vicecount = 1;
- /// <summary>
- /// 展开参数
- /// </summary>
- [
- Category("ViceCount"),
- Description("Ord_ViceOrderCount 展开参数 \r\n Ord_ViceOrderCount 的值要大于多少才能可以展开, 建议设置 0或1"),
- Bindable(true)
- ]
- public int ViceCount
- {
- get
- {
- return _vicecount;
- }
- set
- {
- _vicecount = value;
- }
- }
- /// <summary>
- /// 行首收缩图标
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("行首收缩图标"),
- Bindable(true)
- ]
- public Image ImgExpand
- {
- get
- {
- return this.m_imgExpand;
- }
- set
- {
- this.m_imgExpand = value;
- }
- }
- /// <summary>
- /// 行首展开图片
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("行首展开图片"),
- Bindable(true)
- ]
- public Image ImgCollapse
- {
- get
- {
- return this.m_imgCollapse;
- }
- set
- {
- this.m_imgCollapse = value;
- }
- }
- /// <summary>
- /// 行首图片宽度
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("行首图片宽度"),
- Bindable(true)
- ]
- public int ImageWidth
- {
- get
- {
- return this.m_nImageWidth;
- }
- set
- {
- this.m_nImageWidth = value;
- }
- }
- /// <summary>
- /// 行首图片高度
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("行首图片高度"),
- Bindable(true)
- ]
- public int ImageHeight
- {
- get
- {
- return this.m_nImageHeight;
- }
- set
- {
- this.m_nImageHeight = value;
- }
- }
- private int _dgvColumnHeadersHeight = 24;
- /// <summary>
- /// 列表的高度
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("列表的高度"),
- Bindable(true)
- ]
- public int dgvColumnHeadersHeight
- {
- get
- {
- return _dgvColumnHeadersHeight;
- }
- set
- {
- _dgvColumnHeadersHeight = value;
- }
- }
- /// <summary>
- /// DataGridViewEc边框颜色
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("DataGridViewEc边框颜色"),
- Bindable(true)
- ]
- public static System.Drawing.Color DataGridViewExBorderColor
- {
- get
- {
- return System.Drawing.Color.FromArgb(174, 168, 168);
- }
- }
- /// <summary>
- /// DataGridViewEc奇数行的背景颜色
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("DataGridViewEc奇数行的背景颜色"),
- Bindable(true)
- ]
- public System.Drawing.Color DataGridViewRowsBackColor_Single()
- {
- return System.Drawing.Color.PowderBlue;
- }
- /// <summary>
- /// DataGridViewEc偶数行的背景颜色
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("DataGridViewEc偶数行的背景颜色"),
- Bindable(true)
- ]
- public System.Drawing.Color DataGridViewRowsBackColor_Double()
- {
- return System.Drawing.Color.PapayaWhip;
- }
- private bool _isAutomaticDrawSingleOrDoubleRow = false;
- /// <summary>
- /// 自动绘单双行
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("自动绘单双行"),
- Bindable(true)
- ]
- public bool IsAutomaticDrawSingleOrDoubleRow
- {
- get
- {
- return _isAutomaticDrawSingleOrDoubleRow;
- }
- set
- {
- _isAutomaticDrawSingleOrDoubleRow = value;
- }
- }
- private bool _isShowSerialNumber = false;
- /// <summary>
- /// 是否显示列标头自动增长序号
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("是否显示列标头自动增长序号"),
- Bindable(true)
- ]
- public bool IsShowSerialNumber
- {
- get
- {
- return _isShowSerialNumber;
- }
- set
- {
- _isShowSerialNumber = value;
- }
- }
- private string _dgvGuidName;
- /// <summary>
- /// 当前列表所在全站里的唯一ID
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("当前列表所在全站里的唯一ID"),
- Bindable(true)
- ]
- public string dgvGuidName
- {
- get
- {
- return _dgvGuidName;
- }
- set
- {
- _dgvGuidName = value;
- }
- }
- private string _dgvUserEmployeeID;
- /// <summary>
- /// 当前所登录者的ID
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("当前所登录者的ID"),
- Bindable(true)
- ]
- public string dgvUserEmployeeID
- {
- get
- {
- return _dgvUserEmployeeID;
- }
- set
- {
- _dgvUserEmployeeID = value;
- }
- }
- private string _dgvFixedHideColumn = "";
- /// <summary>
- /// 固定隐藏列
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("固定隐藏列"),
- Bindable(true)
- ]
- public string dgvFixedHideColumn
- {
- get
- {
- return _dgvFixedHideColumn;
- }
- set
- {
- _dgvFixedHideColumn = value;
- }
- }
- private string _dgvCurrentHideColumn;
- /// <summary>
- /// 当前列表隐藏的列标题 (无效)
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("当前列表隐藏的列标题"),
- Bindable(true)
- ]
- public string dgvCurrentHideColumn
- {
- get
- {
- return _dgvCurrentHideColumn;
- }
- set
- {
- _dgvCurrentHideColumn = value;
- }
- }
- private string _dgvCurrentColumnWidth = "";
- /// <summary>
- /// 当前列表隐藏的列标题
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("当前列表隐藏的列标题"),
- Bindable(true)
- ]
- public string dgvCurrentColumnWidth
- {
- get
- {
- return _dgvCurrentColumnWidth;
- }
- set
- {
- _dgvCurrentColumnWidth = value;
- }
- }
- private bool _IsSortMode = false;
- /// <summary>
- /// 点击列表头,是否要进行排序
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("点击列表头,是否要进行排序"),
- Bindable(true)
- ]
- public bool IsSortMode
- {
- get
- {
- return _IsSortMode;
- }
- set
- {
- _IsSortMode = value;
- }
- }
- private string _dgvCurrentColumnOriginalSet = "";
- /// <summary>
- /// 当前列表原来的列标题(用于还原初始设置)
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("当前列表原来的列标题(用于还原初始设置)"),
- Bindable(true)
- ]
- public string dgvCurrentColumnOriginalSet
- {
- get
- {
- return _dgvCurrentColumnOriginalSet;
- }
- set
- {
- _dgvCurrentColumnOriginalSet = value;
- }
- }
- private bool _isCompleteBonding = false;
- /// <summary>
- /// 是否绑定完成
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("是否绑定完成"),
- Bindable(true)
- ]
- public bool IsCompleteBonding
- {
- get
- {
- return _isCompleteBonding;
- }
- set
- {
- _isCompleteBonding = value;
- }
- }
- /// <summary>
- /// 版本号
- /// </summary>
- private string StrVersionNumber
- {
- get
- {
- string strVersionNumber = LYFZ.DAL.DAL_GridViewDisplayIndex.StrVersionNumber;
- if ( string.IsNullOrEmpty(strVersionNumber) )
- {
- MessageBoxCustom.Show("系统有损坏,获取版本号失败!");
- }
- if ( strVersionNumber == null )
- {
- strVersionNumber = "";
- }
- return strVersionNumber;
- }
- }
- bool _isCopyCellValue = true;
- /// <summary>
- /// 是否能复制单元格的Value值
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("是否能复制单元格的Value值"),
- Bindable(true)
- ]
- public bool IsCopyCellValue
- {
- get
- {
- return _isCopyCellValue;
- }
- set
- {
- _isCopyCellValue = value;
- }
- }
- bool _isSortedRedraw = true;
- /// <summary>
- /// 是否能复制单元格的Value值
- /// </summary>
- [
- Category("CollapseDataGridViewProperties"),
- Description("点击列排序后是否重绘单双行"),
- Bindable(true)
- ]
- public bool IsSortedRedraw
- {
- get
- {
- return _isSortedRedraw;
- }
- set
- {
- _isSortedRedraw = value;
- }
- }
- public delegate void BindDataSourceRows( DataGridViewRow dgvr, DataGridViewCell cell, DataGridViewRowCollection Rows );
- public delegate void BindFilterColumnDataHandler();
- public event BindFilterColumnDataHandler BindFilterColumnDataEvent;
- /// <summary>
- /// 获取当前列表的列标题名
- /// </summary>
- /// <returns></returns>
- public string dgvSetColumnName()
- {
- if ( !string.IsNullOrEmpty(this.dgvGuidName) && this.AllowUserToOrderColumns )
- {
- LYFZ.Model.Model_GridViewDisplayIndex model = LYFZ.DAL.DAL_GridViewDisplayIndex.GetGridViewDisplayIndexModel(this.dgvUserEmployeeID, this.dgvGuidName);
- if ( model.ID > 0 )
- {
- string StrColumnName = "";
- string StrColumnWidth = "";
- if ( !string.IsNullOrEmpty(model.DisplayIndexValue.Trim()) )
- {
- Dictionary<string, string> dictDataDisplay = LYFZ.DAL.DAL_GridViewDisplayIndex.GetListColumnDisplayValue(model.DisplayIndexValue.Trim());
- List<string> listOriginalColumn = new List<string>(this.dgvCurrentColumnOriginalSet.Trim().Split(','));
- #region 判断版本不是最新时,则修改
- if ( StrVersionNumber.Trim() != model.VerNumber.Trim() )
- {
- if ( !string.IsNullOrEmpty(model.DisplayIndexValue.Trim()) )
- {
- Dictionary<string, string> dictNewDat = new Dictionary<string, string>();
- foreach ( var item in dictDataDisplay )
- {
- if ( listOriginalColumn.Contains(item.Key.ToString().Trim()) )
- {
- dictNewDat.Add(item.Key.ToString().Trim(), item.Value.Trim());
- }
- }
- string StrUpdateNewValue = "";
- foreach ( var item in dictNewDat )
- {
- StrUpdateNewValue += item.Key.ToString().Trim() + ":" + item.Value.ToString().Trim();
- }
- if ( !string.IsNullOrEmpty(StrUpdateNewValue) )
- {
- this.Update_GridViewDisplayIndex(StrUpdateNewValue);
- }
- dictDataDisplay = new Dictionary<string, string>();
- dictDataDisplay = dictNewDat;
- }
- }
- #endregion
- foreach ( var item in dictDataDisplay )
- {
- StrColumnName += item.Key.ToString().Trim() + ",";
- StrColumnWidth += item.Value.ToString().Trim() + ",";
- }
- }
- this.dgvCurrentColumnWidth = StrColumnWidth.TrimEnd(',');
- return StrColumnName.TrimEnd(',');
- }
- else
- {
- this.ColumnOriginalSet();
- return LYFZ.DAL.DAL_GridViewDisplayIndex.GetStringColumns(this.dgvUserEmployeeID, this.dgvGuidName);
- }
- }
- return "";
- }
- public void BindFilterColumnData()
- {
- if ( BindFilterColumnDataEvent != null )
- {
- BindFilterColumnDataEvent();
- }
- }
- /// <summary>
- /// 重置为默认
- /// </summary>
- /// <returns></returns>
- public bool ColumnOriginalSet()
- {
- string StrValue = "";
- List<string> listOriginalColumn = new List<string>(this.dgvCurrentColumnOriginalSet.Trim().Split(','));
- List<string> listHideColumn = new List<string>(this.dgvFixedHideColumn.Trim().Split(','));
- for ( int i = 0; i < listOriginalColumn.Count; i++ )
- {
- if ( !string.IsNullOrEmpty(listOriginalColumn[i].Trim()) )
- {
- if ( !listHideColumn.Contains(listOriginalColumn[i].Trim()) )
- {
- StrValue += listOriginalColumn[i].Trim() + ":100|";
- }
- }
- }
- if ( !string.IsNullOrEmpty(StrValue) )
- {
- return this.Update_GridViewDisplayIndex(StrValue);
- }
- return false;
- }
- /// <summary>
- /// 存储当前列表显示数据的列标题名称
- /// </summary>
- public Dictionary<string, string> dictShowColumName = new Dictionary<string, string>();
- #endregion
- #region 定义构造
- public DataGridViewEc() : base()
- {
- try
- {
- // 开启双缓冲;
- this.SetStyle(ControlStyles.DoubleBuffer, true);
- this.SetStyle(ControlStyles.UserPaint, true);
- this.SetStyle(ControlStyles.ResizeRedraw, true);
- // 更新双缓冲到样式中;
- this.UpdateStyles();
- this.Paint += DataGridViewEc_Paint;
- this.RowsAdded += DataGridViewEc_RowsAdded;
- this.RowStateChanged += DataGridViewEc_RowStateChanged;
- this.ColumnWidthChanged += DataGridViewEc_ColumnWidthChanged;
- this.ColumnDisplayIndexChanged += DataGridViewEc_ColumnDisplayIndexChanged;
- this.Resize += DataGridViewEc_Resize;
- this.BackgroundColor = Color.White;
- this.CellMouseDown += DataGridViewEc_CellMouseDown;
- this.Sorted += DataGridViewEc_Sorted;
- this.KeyDown += DataGridViewEc_KeyDown;
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
- dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;//211, 223, 240
- dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White; //标题文字色
- dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
- dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
- dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(43, 108, 150);//标题背景色
- this.EnableHeadersVisualStyles = false;
- this.GridColor = System.Drawing.SystemColors.GradientInactiveCaption;
- this.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
- this.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
- this.AllowUserToAddRows = false;
- this.AllowUserToDeleteRows = false;
- this.AllowUserToResizeRows = false;
- this.RowHeadersVisible = true;
- this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
- this.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
- this.m_nImageHeight = 15;
- this.m_nImageWidth = 15;
- this.ImgExpand = global::LYFZ.ComponentLibrary.Properties.Resources.Expand;
- this.ImgCollapse = global::LYFZ.ComponentLibrary.Properties.Resources.Collapse;
- //隐藏行标题黑色箭头
- this.RowHeadersDefaultCellStyle.Padding = new Padding(this.RowHeadersWidth);
- this.RowHeadersWidth = 25;
- this.ColumnHeadersHeight = this.dgvColumnHeadersHeight;
- }
- catch { }
- }
- /// <summary>
- /// 设置要隐藏的手机号字段名
- /// </summary>
- void SetHidePhoneCellsName()
- {
- if ( this.Columns != null )
- {
- HidePhoneFindList.Clear();
- for ( int i = 0; i < this.Columns.Count; i++ )
- {
- DataGridViewColumn Column = this.Columns[i];
- if ( DataGridViewEx.HidePhoneCellsNameList.Contains(Column.Name) || DataGridViewEx.HidePhoneCellsNameList.Contains(Column.HeaderText) )
- {
- this.HidePhoneFindList.Add(Column.Name);
- }
- }
- }
- }
- /// <summary>
- /// string[] HidePhoneFinds = "客户电话,电话,固定电话,介绍人电话,手机号码,本人手机,老公手机".Split(',');
- /// </summary>
- List<string> HidePhoneFindList = new List<string>();
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DataGridViewEc_RowsAdded( object sender, DataGridViewRowsAddedEventArgs e )
- {
- if ( DataGridViewEx.HidePhoneCellsNameList.Count > 0 )
- {
- if ( e.RowIndex == 0 )
- {
- this.SetHidePhoneCellsName();
- }
- if ( LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherPermissionsSet, LYFZ.CustomAttributes.OperatingAuthority.ProhibitViewCustomerPhoneNumber) && !LYFZ.BLL.BLL_ErpUser.IsAdministrator() && DataGridViewEx.HidePhoneCellsNameList.Count > 0 )
- {
- try
- {
- foreach ( string HidePhoneCellsName in HidePhoneFindList )
- {
- this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Tag = this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value;
- //_dataTable.Rows[e.RowIndex][HidePhoneCellsName] = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
- this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
-
- }
- }
- catch (Exception ex){ }
- }
- }
- }
- /// <summary>
- /// 控件大小发生变化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DataGridViewEc_Resize( object sender, EventArgs e )
- {
- this.FillLastColumn(this.IsAddNullColumns);
- }
- /// <summary>
- /// 列表标题宽度发变化问题
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DataGridViewEc_ColumnWidthChanged( object sender, DataGridViewColumnEventArgs e )
- {
- this.SetColumnModel();
- }
- /// <summary>
- /// 列表标题顺序发变化问题
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DataGridViewEc_ColumnDisplayIndexChanged( object sender, DataGridViewColumnEventArgs e )
- {
- this.SetColumnModel();
- }
- /// <summary>
- /// 进入修改列变化
- /// </summary>
- public void SetColumnModel()
- {
- if ( !string.IsNullOrEmpty(this.dgvGuidName) && this.IsCompleteBonding )
- {
- string StrValue = "";
- for ( int i = 0; i < this.Columns.Count; i++ )
- {
- for ( int j = 0; j < this.Columns.Count; j++ )
- {
- if ( this.Columns[j].DisplayIndex == i )
- {
- if ( this.Columns[j].Name.Trim() != this.FillColumnsNullName )
- {
- if ( Columns[j].Name.IndexOf('/') != -1 )
- StrValue += "[" + this.Columns[j].Name.Trim() + "]:" + this.Columns[j].Width + "|";
- else
- StrValue += this.Columns[j].Name.Trim() + ":" + this.Columns[j].Width + "|";
- }
- break;
- }
- }
- }
- this.Update_GridViewDisplayIndex(StrValue);
- }
- }
- /// <summary>
- /// 修改列标头显示数据
- /// </summary>
- /// <param name="StrValue"></param>
- /// <returns></returns>
- bool Update_GridViewDisplayIndex( string StrValue )
- {
- return LYFZ.DAL.DAL_GridViewDisplayIndex.UpdateGridViewDisplayIndexModel(this.dgvUserEmployeeID, this.dgvGuidName, StrValue, this.StrVersionNumber);
- }
- /// <summary>
- /// 给单双行绘不同的背景颜色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DataGridViewEc_RowStateChanged( object sender, DataGridViewRowStateChangedEventArgs e )
- {
- if ( IsAutomaticDrawSingleOrDoubleRow )
- {
- if ( this.Rows.Count != 0 )
- {
- for ( int i = 0; i < this.Rows.Count; )
- {
- this.Rows[i].DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
- i += 2;
- }
- }
- if ( this.Rows.Count != 0 )
- {
- for ( int i = 1; i < this.Rows.Count; )
- {
- this.Rows[i].DefaultCellStyle.BackColor = this.DataGridViewRowsBackColor_Double();
- i += 2;
- }
- }
- }
- }
- /// <summary>
- /// 重绘控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DataGridViewEc_Paint( object sender, PaintEventArgs e )
- {
- try
- {
- Pen p = new Pen(DataGridViewExBorderColor);
- e.Graphics.DrawRectangle(p, new Rectangle(0, 0, this.Width - 1, this.Height - 1));
- }
- catch { }
- }
- public ContextMenuStripEx conMenu = new ContextMenuStripEx();
- #region 2017-03-18 杨云奕 右键也选中行内容
- void MouseRightSelectSingleRow( int RowIndex )
- {
- foreach ( DataGridViewRow row in this.Rows )
- {
- row.Selected = false;
- }
- this.Rows[RowIndex].Selected = true;
- }
- #endregion
- /// <summary>
- /// 右键复制字段
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DataGridViewEc_CellMouseDown( object sender, DataGridViewCellMouseEventArgs e )
- {
- if ( this.Rows.Count > 0 )
- {
- if ( this.CurrentRow != null )
- {
- if ( e.ColumnIndex >= 0 && e.RowIndex >= 0 )
- {
- if ( e.Button == System.Windows.Forms.MouseButtons.Right )
- {
- /* #region 2017-03-18 杨云奕 右键也选中行内容
- MouseRightSelectSingleRow(e.RowIndex);
- #endregion
- */
- this.conMenu.Items.Clear();
- if ( IsCopyCellValue )
- {
- // conMenu.Show(MousePosition.X, MousePosition.Y);//弹出操作菜单
- conMenu.ItemClicked -= conMenu_ItemClicked;
- conMenu.ItemClicked += conMenu_ItemClicked;
- ToolStripMenuItem item = new ToolStripMenuItem();
- item.Text = "复制" + this.Columns[e.ColumnIndex].HeaderText;
- item.Tag = this.CurrentRow.Index + "|" + e.ColumnIndex;
- item.Name = "复制列";
- conMenu.Items.Add(item);
- }
- if ( LYFZ.ComponentLibrary.DataGridViewEx.HidePhoneCellsNameList.Contains(this.Columns[e.ColumnIndex].HeaderText.Trim()) )
- {
- if ( LYFZ.BLL.OtherCommonModel.GetUserCanViewPhoneCount(LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID) > 0 )
- {
- // conMenu.Show(MousePosition.X, MousePosition.Y);//弹出操作菜单
- conMenu.ItemClicked -= conMenu_ItemClicked;
- conMenu.ItemClicked += conMenu_ItemClicked;
- ToolStripMenuItem item = new ToolStripMenuItem();
- item.Text = "查看完整" + this.Columns[e.ColumnIndex].HeaderText;
- item.Tag = this.CurrentRow.Index + "|" + e.ColumnIndex;
- item.Name = "查看列";
- conMenu.Items.Add(item);
- }
- }
- if ( conMenu.Items.Count > 0 )
- {
- conMenu.Show(MousePosition.X, MousePosition.Y);//弹出操作菜单
- }
- }
- }
- else if ( e.RowIndex == -1 )
- {
- if ( this.SelectedRows.Count > 3 )
- {
- if ( e.Button == System.Windows.Forms.MouseButtons.Right )
- {
- try
- {
- decimal decAoumnt = 0;
- for ( int i = 0; i < this.Rows.Count; i++ )
- {
- decAoumnt += Convert.ToDecimal(this.Rows[i].Cells[e.ColumnIndex].Value);
- }
- MessageBoxCustom.Show(decAoumnt.ToString().Trim());
- }
- catch { }
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 排序完成后
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DataGridViewEc_Sorted( object sender, EventArgs e )
- {
- if ( this.IsSortedRedraw )
- {
- int RowUniqueMark = 0;
- for ( int i = 0; i < this.Rows.Count; i++ )
- {
- if ( (RowUniqueMark % 2) > 0 )
- {
- this.Rows[i].DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Double();
- }
- else
- {
- this.Rows[i].DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
- }
- RowUniqueMark++;
- }
- }
- }
- public delegate void DataGridView_ConMenu_ItemClicked( object sender, ToolStripItemClickedEventArgs e );
- /// <summary>
- /// 用event 关键字声明事件对象
- /// </summary>
- [Category("控件扩展事件"), Description("列表右击显示菜单事件")]
- public event DataGridView_ConMenu_ItemClicked DataGridViewConMenu_ItemClicked;
- void conMenu_ItemClicked( object sender, ToolStripItemClickedEventArgs e )
- {
- ToolStripItem item = e.ClickedItem;
- if ( !string.IsNullOrEmpty(item.Name) && item.Name.Trim() == "复制列" )
- {
- if ( !string.IsNullOrEmpty(item.Text.Trim()) && item.Tag != null )
- {
- string[] StrTag = item.Tag.ToString().Trim().Split('|');
- Clipboard.SetDataObject(this.Rows[Convert.ToInt32(StrTag[0])].Cells[Convert.ToInt32(StrTag[1])].Value.ToString().Trim());
- }
- }
- else if ( !string.IsNullOrEmpty(item.Name) && item.Name.Trim() == "查看列" )
- {
- if ( !string.IsNullOrEmpty(item.Text.Trim()) && item.Tag != null )
- {
- string[] StrTag = item.Tag.ToString().Trim().Split('|');
- if ( LYFZ.BLL.OtherCommonModel.UserCanViewPhoneCount == -2 )
- {
- DataTable dt = new LYFZ.BLL.BLL_ErpOrder().GetView_Custom("tb_ErpUser", StrWhere: "User_EmployeeID='" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID + "'", ShowColumnName: "User_LookPhoneQuantity").Tables[0];
- if ( dt.Rows.Count > 0 )
- {
- LYFZ.BLL.OtherCommonModel.UserCanViewPhoneCount = Convert.ToInt32(dt.Rows[0]["User_LookPhoneQuantity"]);
- }
- else
- {
- LYFZ.BLL.OtherCommonModel.UserCanViewPhoneCount = 0;
- }
- }
- LYFZ.ComponentLibrary.frmFullPhoneNumber frm = new frmFullPhoneNumber();
- frm.StrUserNumber = LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID;
- frm.StrPhone = this.Rows[Convert.ToInt32(StrTag[0])].Cells[Convert.ToInt32(StrTag[1])].Tag.ToString().Trim();
- frm.ShowDialog();
- }
- }
- else
- {
- if ( this.DataGridViewConMenu_ItemClicked != null )
- {
- this.DataGridViewConMenu_ItemClicked(sender, e);
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DataGridViewEc_KeyDown( object sender, KeyEventArgs e )
- {
- if ( e.KeyData == (Keys.Control | Keys.C) )
- {
- e.Handled = true;
- }
- }
- #endregion
- #region 公共方法
- Font ft9 = new Font("宋体", 10);
- /// <summary>
- /// 重写OnRowPostPaint()方法,以在折叠行前加上状态标识
- /// </summary>
- /// <param name="e"></param>
- protected override void OnRowPostPaint( DataGridViewRowPostPaintEventArgs e )
- {
- //base.OnRowPostPaint(e);
- try
- {
- //IsShowSerialNumber = true;
- this.ColumnHeadersHeight = this.dgvColumnHeadersHeight;
- this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- DataGridViewRow row = this.Rows[e.RowIndex];
- if ( this.Columns.Contains("Ord_ViceOrderCount") )
- {
- if ( Convert.ToInt32(this.Rows[e.RowIndex].Cells["Ord_ViceOrderCount"].Value) > ViceCount && this.RowHeadersVisible )
- {
- Rectangle rect = new Rectangle(e.RowBounds.Location.X + 4, e.RowBounds.Location.Y + 4, this.m_nImageWidth, this.m_nImageHeight);
- Image img = null;
- string HeaderCellValue = row.HeaderCell.Value.ToString().Trim().Split('_')[1].Trim();
- if ( HeaderCellValue == "Collapse" )
- {
- img = this.ImgCollapse;
- }
- else
- {
- img = this.ImgExpand;
- }
- e.Graphics.DrawImage(img, rect);
- }
- }
- else if ( IsShowSerialNumber )
- {
- string HeaderCellValue = (e.RowIndex + 1).ToString();
- int w = this.RowHeadersWidth;
- int FtWidth = Convert.ToInt32(e.Graphics.MeasureString(HeaderCellValue, ft9).Width);
- Rectangle rect = new Rectangle(e.RowBounds.Location.X + (w / 2 - FtWidth / 2 - 1), e.RowBounds.Location.Y + 5, w, this.Height);
- e.Graphics.DrawString(HeaderCellValue, ft9, Brushes.Black, rect);
- }
- if(row.Tag!=null&& row.Tag.ToString()== "Sign")
- {
- string HeaderCellValue = "*";
- int w = this.RowHeadersWidth;
- int FtWidth = Convert.ToInt32(e.Graphics.MeasureString(HeaderCellValue, ft9).Width);
- Rectangle rect = new Rectangle(e.RowBounds.Location.X + (w / 2 - FtWidth / 2 - 1), e.RowBounds.Location.Y + 5, w, this.Height);
- e.Graphics.DrawString(HeaderCellValue, ft9, Brushes.Black, rect);
- }
- }
- catch { }
- }
- /// <summary>
- /// 点击
- /// </summary>
- /// <param name="e"></param>
- protected override void OnRowHeaderMouseClick( DataGridViewCellMouseEventArgs e )
- {
- try
- {
- DataGridViewRow row = this.Rows[e.RowIndex];
- if ( row.Index >= 0 )
- {
- this.CRowsIndex = e.RowIndex;
- EventExpandCollapse expColl = new EventExpandCollapse();
- expColl.CRows = this.Rows;
- expColl.OnRowHeaderMouseClick = e;
- if ( row.HeaderCell.Value != null )
- {
- if ( row.HeaderCell.Value.ToString().Trim().IndexOf('_') != -1 )
- {
- string HeaderCellValue_0 = row.HeaderCell.Value.ToString().Trim().Split('_')[0].Trim();
- string HeaderCellValue = row.HeaderCell.Value.ToString().Trim().Split('_')[1].Trim();
- if ( HeaderCellValue == "Collapse" )
- {
- expColl.ExpandOrCollapse = false;
- row.HeaderCell.Value = HeaderCellValue_0 + "_" + "Expand";
- row.HeaderCell.ToolTipText = "点击展开";
- //string HeaderCellValue = row.HeaderCell.Value.ToString().Trim().Split('_')[0].Trim();
- for ( int i = 0; i < this.Rows.Count; i++ )
- {
- if ( "Vice" + HeaderCellValue_0 == this.Rows[i].HeaderCell.Value.ToString().Trim() )
- {
- this.Rows[i].Visible = false;
- }
- }
- }
- //点击进行展开
- else
- {
- expColl.ExpandOrCollapse = true;
- row.HeaderCell.Value = HeaderCellValue_0 + "_" + "Collapse";
- row.HeaderCell.ToolTipText = "点击折叠";
- if ( EventRowExpandCollapse != null )
- {
- this.EventRowExpandCollapse(expColl);
- }
- }
- }
- }
- }
- try
- {
- base.OnRowHeaderMouseClick(e);
- }
- catch
- {
- }
- }
- catch { }
- }
- /// <summary>
- /// 当前选中行
- /// </summary>
- private int CRowsIndex;
- /// <summary>
- /// 子集子数据的绑定
- /// </summary>
- /// <param name="Vicetbl"></param>
- public void DataSourceVice( DataTable Vicetbl )
- {
- try
- {
- if ( Convert.ToBoolean(this.Rows[CRowsIndex].HeaderCell.Tag) == true )
- {
- if ( Vicetbl.Rows.Count > 0 )
- {
- for ( int i = 0; i < Vicetbl.Rows.Count; i++ )
- {
- try
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- dgvr.HeaderCell.Value = "Vice" + this.Rows[CRowsIndex].HeaderCell.Value.ToString().Trim().Split('_')[0].Trim();
- dgvr.DefaultCellStyle.BackColor = this.Rows[CRowsIndex].DefaultCellStyle.BackColor;
- dgvr.Height = 25;
- DataGridViewCell cell = null;
- for ( int j = 0; j < Vicetbl.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = Vicetbl.Rows[i][Vicetbl.Columns[j].ToString().Trim()].ToString().Trim();
- dgvr.Cells.Add(cell);
- }
- int NewCRowsIndex = (CRowsIndex + i + 1);
- this.Rows.InsertRange(NewCRowsIndex, dgvr);
- }
- catch { break; }
- }
- this.Rows[CRowsIndex].HeaderCell.Tag = false;
- }
- }
- else
- {
- this.DataContractRows();
- }
- }
- catch { }
- }
- private string _strValueNullColumn = "";
- /// <summary>
- /// 固定默认要为空的副级字段
- /// </summary>
- [Browsable(false)]
- public string StrValueNullColumn
- {
- get
- {
- return _strValueNullColumn;
- }
- set
- {
- _strValueNullColumn = value;
- }
- }
- private string _strSecondStageNull = "";
- /// <summary>
- /// 固定默认要为空的副级字段(为第三二级要为空的字段)
- /// </summary>
- [Browsable(false)]
- public string StrSecondStageNull
- {
- get
- {
- return _strSecondStageNull;
- }
- set
- {
- _strSecondStageNull = value;
- }
- }
- public string DgvValueFiledNull = "";
- /// <summary>
- /// 子集子数据的绑定
- /// </summary>
- /// <param name="Vicetbl"></param>
- public void DataSourceViceRow( DataRow[] dtRow )
- {
- try
- {
- if ( Convert.ToBoolean(this.Rows[CRowsIndex].HeaderCell.Tag) == true )
- {
- this.DataExpandRows(dtRow);
- }
- else
- {
- this.DataContractRows();
- }
- }
- catch { }
- }
- /// <summary>
- /// 展开行
- /// </summary>
- void DataExpandRows( DataRow[] dtRow )
- {
- DataRow dtrow = dtRow[0];
- if ( dtRow.Length > 0 )
- {
- string[] strValueNull = DgvValueFiledNull.Split(',');
- for ( int i = 0; i < dtRow.Length; i++ )
- {
- try
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- dgvr.HeaderCell.Value = "Vice" + this.Rows[CRowsIndex].HeaderCell.Value.ToString().Trim().Split('_')[0].Trim();
- dgvr.DefaultCellStyle.BackColor = this.Rows[CRowsIndex].DefaultCellStyle.BackColor;
- dgvr.Height = 25;
- DataGridViewCell cell = null;
- for ( int j = 0; j < dtrow.Table.Columns.Count; j++ )
- {
- bool Isbl = true;
- for ( int k = 0; k < strValueNull.Length; k++ )
- {
- if ( dtrow.Table.Columns[j].ColumnName.Trim() == strValueNull[k].ToString().Trim() )
- {
- Isbl = false;
- break;
- }
- }
- cell = new DataGridViewTextBoxCell();
- if ( Isbl )
- {
- cell.Value = dtRow[i][dtrow.Table.Columns[j].ColumnName.Trim()].ToString().Trim();
- }
- else
- {
- string StrValues = "";
- if ( dtrow.Table.Columns[j].ColumnName.Trim() == "订单号" )
- {
- if ( dtrow.Table.Columns.Contains("取件状态") )
- {
- if ( dtRow[i]["取件状态"].ToString().Trim() == "OK" )
- {
- StrValues = "(取件OK)";
- }
- }
- if ( dtrow.Table.Columns.Contains("订单类型") )
- {
- if ( dtRow[i]["订单类型"].ToString().Trim() != LYFZ.EnumPublic.OrderType.儿童订单.ToString().Trim() )
- {
- StrValues = "";
- }
- }
- }
- cell.Value = StrValues;
- }
- dgvr.Cells.Add(cell);
- }
- int NewCRowsIndex = (CRowsIndex + i + 1);
- this.Rows.InsertRange(NewCRowsIndex, dgvr);
- }
- catch { break; }
- }
- this.Rows[CRowsIndex].HeaderCell.Tag = false;
- }
- }
- /// <summary>
- /// 收缩行
- /// </summary>
- void DataContractRows()
- {
- string HeaderCellValue = this.Rows[CRowsIndex].HeaderCell.Value.ToString().Trim().Split('_')[0].Trim();
- for ( int i = 0; i < this.Rows.Count; i++ )
- {
- if ( "Vice" + HeaderCellValue == this.Rows[i].HeaderCell.Value.ToString().Trim() )
- {
- this.Rows[i].Visible = true;
- }
- }
- }
- /// <summary>
- /// 添加带展开/折叠的行
- /// </summary>
- /// <param name="dtRow"></param>
- void AddExpandDataGridViewRows( DataRow dtRow, int rowI )
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- if ( (rowI % 2) > 0 )
- {
- dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Double();
- }
- else
- {
- dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
- }
- dgvr.HeaderCell.Tag = true;
- dgvr.HeaderCell.Value = rowI + "_Expand";
- dgvr.HeaderCell.ToolTipText = "点击展开";
- dgvr.Height = 25;
- DataGridViewCell cell = null;
- for ( int j = 0; j < this.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- if ( this.Columns[j].Name.ToString().Trim() == "订单号" )
- {
- string StrValues = dtRow[this.Columns[j].Name.ToString().Trim()].ToString().Trim();
- if ( this.Columns.Contains("取件状态") )
- {
- if ( dtRow["取件状态"].ToString().Trim() == "OK" )
- {
- StrValues += "(取件OK)";
- }
- }
- cell.Value = StrValues;
- }
- else
- {
- cell.Value = dtRow[this.Columns[j].Name.ToString().Trim()].ToString().Trim();
- }
- dgvr.Cells.Add(cell);
- }
- this.Rows.Add(dgvr);
- }
- /// <summary>
- /// 主数据的绑定 拍照订单
- /// </summary>
- /// <param name="dt"></param>
- public void DataSourceMain( DataTable dt, string strHideField = "" )
- {
- try
- {
- this.IsCompleteBonding = false;
- this.Rows.Clear();
- this.DataColumns(dt.Columns, strHideField: strHideField);
- #region 处理行内容
- // 行的唯一标识
- int RowUniqueMark = 1;
- AddExpandDataGridViewRows(dt.Rows[0], 0);
- for ( int i = 1; i < dt.Rows.Count; i++ )
- {
- if ( dt.Rows[i]["Ord_Number"].ToString().Trim() != dt.Rows[i - 1]["Ord_Number"].ToString().Trim() )
- {
- AddExpandDataGridViewRows(dt.Rows[i], RowUniqueMark);
- RowUniqueMark++;
- }
- else
- {
- //for (int j = 0; j < this.Rows.Count; j++)
- for ( int j = this.Rows.Count - 1; j >= 0; j-- )
- {
- if ( dt.Rows[i]["Ord_Number"].ToString().Trim() == this.Rows[j].Cells["Ord_Number"].Value.ToString().Trim() )
- {
- this.Rows[j].Cells["Ord_ViceOrderCount"].Value = Convert.ToInt32(this.Rows[j].Cells["Ord_ViceOrderCount"].Value) + 1;
- }
- else
- {
- break;
- }
- }
- }
- }
- #endregion
- this.IsCompleteBonding = true;
- }
- catch
- {
- }
- }
- /// <summary>
- /// 只绑定列
- /// </summary>
- /// <param name="StrColumns"></param>
- /// <param name="strHideField"></param>
- public void DataColumns( string StrColumns, string strHideField = "" )
- {
- this.IsCompleteBonding = false;
- if ( StrColumns != "" )
- {
- this.Columns.Clear();
- this.Rows.Clear();
- DataGridViewTextBoxColumn column = null;
- List<string> listColumn = new List<string>(StrColumns.Split(','));
- List<string> listHideField = new List<string>(strHideField.Split(','));
- for ( int i = 0; i < listColumn.Count; i++ )
- {
- column = new DataGridViewTextBoxColumn();
- column.ReadOnly = true;
- column.Name = listColumn[i].Trim();
- column.HeaderText = listColumn[i].Trim();
- if ( listHideField.Contains(listColumn[i].Trim()) )
- {
- column.Visible = false;
- }
- if ( IsSortMode )
- {
- column.SortMode = DataGridViewColumnSortMode.Automatic;
- }
- this.Columns.Add(column);
- }
- this.ColumnHeadersHeight = this.dgvColumnHeadersHeight;
- this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- }
- }
- /// <summary>
- /// 绑定列
- /// </summary>
- /// <param name="DataColumn"></param>
- public void DataColumns( DataColumnCollection DataColumns, string strHideField = "" )
- {
- this.IsCompleteBonding = false;
- this.Columns.Clear();
- if ( DataColumns.Count > 0 )
- {
- DataGridViewTextBoxColumn column = null;
- List<string> listHideField = new List<string>(strHideField.Split(','));
- if ( !string.IsNullOrEmpty(this.dgvUserEmployeeID) && !string.IsNullOrEmpty(this.dgvGuidName) && this.dictShowColumName.Count > 0 )
- {
- string strKey = "";
- for ( int i = 0; i < DataColumns.Count; i++ )
- {
- #if IGNORE
- if (dictShowColumName.Keys.Contains(DataColumns[i].ToString().Trim()))
- {
- column = new DataGridViewColumn();
- column.ReadOnly = true;
- column.Name = DataColumns[i].ToString().Trim();
- column.HeaderText = DataColumns[i].ToString().Trim();
- column.Width = Convert.ToInt32(dictShowColumName[DataColumns[i].ToString().Trim()].Trim());
- if (listHideField.Contains(DataColumns[i].ToString().Trim()))
- { column.Visible = false; }
- if (IsSortMode)
- { column.SortMode = DataGridViewColumnSortMode.Automatic; }
- this.Columns.Add(column);
- }
- #else
- bool bExist = false;
- foreach ( var e in dictShowColumName )
- {
- strKey = e.Key;
- if ( e.Key.TrimStart('[').TrimEnd(']') == DataColumns[i].ToString().Trim() )
- {
- bExist = true;
- break;
- }
- }
- if ( bExist )
- {
- column = new DataGridViewTextBoxColumn();
- column.ReadOnly = true;
- column.Name = DataColumns[i].ToString().Trim();
- column.HeaderText = DataColumns[i].ToString().Trim();
- column.Width = Convert.ToInt32(dictShowColumName[strKey].Trim());
- if ( listHideField.Contains(DataColumns[i].ToString().Trim()) )
- {
- column.Visible = false;
- }
- if ( IsSortMode )
- {
- column.SortMode = DataGridViewColumnSortMode.Automatic;
- }
- this.Columns.Add(column);
- }
- #endif
- }
- }
- else
- {
- for ( int i = 0; i < DataColumns.Count; i++ )
- {
- column = new DataGridViewTextBoxColumn();
- column.ReadOnly = true;
- column.Name = DataColumns[i].ToString().Trim();
- column.HeaderText = DataColumns[i].ToString().Trim();
- if ( listHideField.Contains(DataColumns[i].ToString().Trim()) )
- {
- column.Visible = false;
- }
- if ( IsSortMode )
- {
- column.SortMode = DataGridViewColumnSortMode.Automatic;
- }
- this.Columns.Add(column);
- }
- }
- }
- this.IsCompleteBonding = true;
- }
- /// <summary>
- /// 绑定行
- /// </summary>
- public void DataRows( DataTable dt, int DataSourceTopCount = -1 )
- {
- // 行的唯一标识
- float RowUniqueMark = 0;
- int forRowCount = dt.Rows.Count;
- if ( DataSourceTopCount != -1 )
- {
- if ( dt.Rows.Count > DataSourceTopCount )
- forRowCount = DataSourceTopCount;
- }
- for ( int i = 0; i < forRowCount; i++ )
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- if ( (RowUniqueMark % 2) > 0 )
- dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Double();
- else
- dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
- dgvr.HeaderCell.Tag = true;
- dgvr.Height = 25;
- DataGridViewCell cell = null;
- for ( int j = 0; j < dt.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i][dt.Columns[j].ToString().Trim()].ToString().Trim();
- dgvr.Cells.Add(cell);
- }
- this.Rows.Add(dgvr);
- RowUniqueMark++;
- }
- }
- /// <summary>
- /// 主数据的绑定,列名可能与DataTable中的列名不同
- /// </summary>
- /// <param name="dt">数据源</param>
- /// <param name="strHideField">要隐藏的字段</param>
- /// <param name="IsBindColumns">是否要绑定列</param>
- /// <param name="ColumnAsName">数据源的列名As重命名的列名串</param>
- public new void DataSource( DataTable dt, string strHideField = "", bool IsBindColumns = true, string ColumnAsName = "", bool IsClearRows = true, int DataSourceTopCount = -1 )
- {
- UseVirtualMode(dt, strHideField, IsBindColumns, ColumnAsName, IsClearRows, DataSourceTopCount);
- return;
- try
- {
- this.IsCompleteBonding = false;
- if ( IsClearRows )
- this.Rows.Clear();
- if ( IsBindColumns )
- {
- if ( !string.IsNullOrEmpty(ColumnAsName) )
- this.DataColumns(ColumnAsName, strHideField: strHideField);
- else
- this.DataColumns(dt.Columns, strHideField: strHideField);
- }
- this.DataRows(dt, DataSourceTopCount);
- this.IsCompleteBonding = true;
- }
- catch
- {
- }
- }
- /// <summary>
- /// 数据绑定
- /// </summary>
- /// <param name="dtRow"></param>
- /// <param name="IsClearRows"></param>
- public new void DataSource( DataRow[] dtRow, bool IsClearRows = false )
- {
- if ( IsClearRows )
- {
- this.Rows.Clear();
- }
- for ( int i = 0; i < dtRow.Length; i++ )
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- if ( (i % 2) > 0 )
- {
- dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Double();
- }
- else
- {
- dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
- }
- DataGridViewCell cell = null;
- for ( int j = 0; j < dtRow[0].Table.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = dtRow[i][j].ToString().Trim();
- dgvr.Cells.Add(cell);
- }
- this.Rows.Add(dgvr);
- }
- }
- public new void DataSource(DataTable dt, DataTable signRemark = null)
- {
- if (signRemark != null)
- {
- _SignRemark = signRemark;
- }
- UseVirtualMode(dt);
- return;
- }
- /// <summary>
- /// 数据绑定(通常用于订单流程的绑定)
- /// </summary>
- /// <param name="dt"></param>
- /// <param name="StrColumnValueNull"></param>
- /// <param name="strHideField"></param>
- public new void DataSource( DataTable dt)
- {
-
- UseVirtualMode(dt);
- return;
- this.IsCompleteBonding = false;
- this.Rows.Clear();
- this.DataColumns(dt.Columns, this.dgvFixedHideColumn.Trim());
- DataGridViewRow dgvr = null;
- DataGridViewCell cell = null;
- List<string> listContainsNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
- Color CurrentColor = this.DataGridViewRowsBackColor_Single();
- for ( int i = 0; i < dt.Rows.Count; i++ )
- {
- dgvr = new DataGridViewRow();
- dgvr.Height = 25;
- if ( i == 0 )
- {
- CurrentColor = this.DataGridViewRowsBackColor_Single();
- for ( int j = 0; j < this.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
- dgvr.Cells.Add(cell);
- }
- }
- else
- {
- if ( dt.Rows[i]["Ord_Number"].Equals(dt.Rows[i - 1]["Ord_Number"]) )
- {
- for ( int j = 0; j < this.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- if ( listContainsNullColumn.Contains(this.Columns[j].Name.Trim()) )
- {
- cell.Value = "";
- }
- else
- {
- cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
- }
- dgvr.Cells.Add(cell);
- }
- }
- else
- {
- if ( CurrentColor == this.DataGridViewRowsBackColor_Single() )
- {
- CurrentColor = this.DataGridViewRowsBackColor_Double();
- }
- else
- {
- CurrentColor = this.DataGridViewRowsBackColor_Single();
- }
- for ( int j = 0; j < this.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
- dgvr.Cells.Add(cell);
- }
- }
- }
- dgvr.DefaultCellStyle.BackColor = CurrentColor;
- this.Rows.Add(dgvr);
- }
- this.IsCompleteBonding = true;
- }
- public new void DataSource( DataColumnCollection DataColumns )
- {
- this.IsCompleteBonding = false;
- this.Rows.Clear();
- this.DataColumns(DataColumns, this.dgvFixedHideColumn.Trim());
- List<string> listContainsNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
- Color CurrentColor = this.DataGridViewRowsBackColor_Single();
- }
- /// <summary>
- /// 数据绑定(通常用于订单流程的绑定)
- /// </summary>
- /// <param name="dt"></param>
- /// <param name="StrColumnValueNull"></param>
- /// <param name="strHideField"></param>
- public new void DataSource(DataTable dt, DataTable remarkDt, string StrSecondStageNull)
- {
- if (remarkDt != null)
- {
- _SignRemark = remarkDt;
- }
- UseVirtualMode(dt, StrSecondStageNull);
- return;
- }
- /// <summary>
- /// 数据绑定(通常用于订单流程的绑定)
- /// </summary>
- /// <param name="dt"></param>
- /// <param name="StrColumnValueNull"></param>
- /// <param name="strHideField"></param>
- public new void DataSource( DataTable dt, string StrSecondStageNull )
- {
- UseVirtualMode(dt, StrSecondStageNull);
- return;
- this.IsCompleteBonding = false;
- this.Rows.Clear();
- this.DataColumns(dt.Columns, this.dgvFixedHideColumn.Trim());
- DataGridViewRow dgvr = null;
- DataGridViewCell cell = null;
- List<string> listContainsNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
- List<string> listSecondStageNullColumn = new List<string>(StrSecondStageNull.Split(','));
- Color CurrentColor = this.DataGridViewRowsBackColor_Single();
- for ( int i = 0; i < dt.Rows.Count; i++ )
- {
- dgvr = new DataGridViewRow();
- dgvr.Height = 25;
- if ( i == 0 )
- {
- CurrentColor = this.DataGridViewRowsBackColor_Single();
- for ( int j = 0; j < this.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
- dgvr.Cells.Add(cell);
- }
- }
- else
- {
- if ( dt.Rows[i]["Ord_Number"].Equals(dt.Rows[i - 1]["Ord_Number"]) )
- {
- for ( int j = 0; j < this.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- if ( listContainsNullColumn.Contains(this.Columns[j].Name.Trim()) )
- {
- cell.Value = "";
- }
- else
- {
- bool IsFind = false;
- if ( dt.Columns.Contains("拍摄名称") )
- {
- if ( dt.Rows[i]["拍摄名称"].Equals(dt.Rows[i - 1]["拍摄名称"]) )
- {
- IsFind = listSecondStageNullColumn.Contains(this.Columns[j].Name.Trim());
- }
- }
- if ( IsFind )
- {
- cell.Value = "";
- }
- else
- {
- cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
- }
- }
- dgvr.Cells.Add(cell);
- }
- }
- else
- {
- if ( CurrentColor == this.DataGridViewRowsBackColor_Single() )
- {
- CurrentColor = this.DataGridViewRowsBackColor_Double();
- }
- else
- {
- CurrentColor = this.DataGridViewRowsBackColor_Single();
- }
- for ( int j = 0; j < this.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i][this.Columns[j].Name.Trim()].ToString().Trim();
- dgvr.Cells.Add(cell);
- }
- }
- }
- dgvr.DefaultCellStyle.BackColor = CurrentColor;
- this.Rows.Add(dgvr);
- }
- this.IsCompleteBonding = true;
- }
- #region ############------------------------ VirtualMode模式 ------------------------############
- // 数据绑定的类型;
- int nBindingDataType = 0;
- // 最多显示数据集的前xxx行;
- int nDataSourceTopCount = 0;
- // 数据集;
- public DataTable _dataTable = new DataTable();
- /// <summary>
- /// 订单备注标记
- /// </summary>
- DataTable _SignRemark = new DataTable();
- // 当多行订单号相同时, 第一行以外其他行不显示的列字段;
- List<string> _listNullColumn = new List<string>();
- //
- List<string> _listSecondStageNullColumn = new List<string>();
- /// <summary>
- /// 初始化列头字段;
- /// </summary>
- /// <param name="strColumns"></param>
- /// <param name="strHideField"></param>
- public void InitColumns( string strColumns /*逗号分隔*/, string strHideFields = ""/*逗号分隔*/)
- {
- DataGridViewTextBoxColumn column = null;
- if ( !string.IsNullOrEmpty(strColumns) )
- {
- // 有必须的话, 清空之前的列头信息;
- this.Rows.Clear();
- this.Columns.Clear();
- this.IsCompleteBonding = false;
- List<string> listColumns = strColumns.Split(',').ToList();
- List<string> listHideFields = strHideFields.Split(',').ToList();
- for ( int i = 0; i < listColumns.Count; i++ )
- {
- column = new DataGridViewTextBoxColumn();
- column.ReadOnly = true;
- column.Name = listColumns[i].Trim();
- column.HeaderText = listColumns[i].Trim();
- // 是否有隐藏列;
- if ( listHideFields.Contains(listColumns[i].Trim()) )
- column.Visible = false;
- // 是否排序;
- if ( this.IsSortMode )
- column.SortMode = DataGridViewColumnSortMode.Automatic;
- this.Columns.Add(column);
- }
- this.ColumnHeadersHeight = this.dgvColumnHeadersHeight;
- this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- this.IsCompleteBonding = true;
- }
- }
- public void UseVirtualMode( DataTable dataTable )
- {
- try
- {
- Debug.Write("\n虚拟模式0\n");
- // 参数校验;
- if ( dataTable == null /*|| dataTable.Rows.Count == 0*/)
- return;
- // 清空之前的列和行;
- if ( _dataTable != null )
- _dataTable = null;
- this.Rows.Clear();
- this.Columns.Clear();
- // 保存数据集;
- _dataTable = dataTable;
- // 绑定列(注:绑定列,必须在Virtual=true之前);
- this.DataColumns(_dataTable.Columns, this.dgvFixedHideColumn.Trim());
- // 开启虚拟模式;
- this.VirtualMode = true;
- // 设置总行数;
- this.RowCount = _dataTable.Rows.Count;
- // 获取同订单不显示的列字段;
- _listNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
- // 设置类型;
- nBindingDataType = 0;
- // 绑定单元格显示事件;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded0;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded1;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded2;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded3;
- this.CellValueNeeded += DataGridViewEc_CellValueNeeded0;
- }
- catch ( Exception e )
- {
- }
- }
- public void UseVirtualMode(DataTable dataTable, DataTable remarkDt, string strSecondStageNull)
- {
- if(remarkDt!=null)
- {
- _SignRemark = remarkDt;
- }
-
- UseVirtualMode(dataTable, strSecondStageNull);
- }
- public void UseVirtualMode( DataTable dataTable, string strSecondStageNull )
- {
- try
- {
- Debug.Write("\n虚拟模式1\n");
- // 参数校验;
- if ( dataTable == null /*|| dataTable.Rows.Count == 0*/)
- return;
- // 清空之前的列和行;
- if ( _dataTable != null )
- _dataTable = null;
- this.Rows.Clear();
- this.Columns.Clear();
- // 保存数据集;
- _dataTable = dataTable;
- // 绑定列(注:绑定列,必须在Virtual=true之前);
- this.DataColumns(_dataTable.Columns, this.dgvFixedHideColumn.Trim());
- // 开启虚拟模式;
- this.VirtualMode = true;
- // 设置总行数;
- this.RowCount = _dataTable.Rows.Count;
- // 获取同订单不显示的列字段;
- _listNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
- _listSecondStageNullColumn = new List<string>(StrSecondStageNull.Split(','));
- // 设置类型;
- nBindingDataType = 1;
- // 绑定单元格显示事件;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded0;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded1;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded2;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded3;
- this.CellValueNeeded += DataGridViewEc_CellValueNeeded1;
- }
- catch ( Exception e )
- {
- }
- }
- public void UseVirtualMode( DataTable dataTable, string strHideField = "", bool IsBindColumns = true, string ColumnAsName = "", bool IsClearRows = true, int DataSourceTopCount = -1 )
- {
- try
- {
- Debug.Write("\n虚拟模式2\n");
- // 参数校验;
- if ( dataTable == null /*|| dataTable.Rows.Count == 0*/)
- return;
- // 清空之前的列和行;
- if ( _dataTable != null )
- _dataTable = null;
- this.Rows.Clear();
- if ( IsBindColumns )
- this.Columns.Clear();
- // 保存数据集;
- _dataTable = dataTable;
- // 初始化列(绑定列(注:绑定列,必须在Virtual=true之前));
- if ( IsBindColumns )
- {
- if ( !string.IsNullOrEmpty(ColumnAsName) )
- this.InitColumns(ColumnAsName, strHideFields: strHideField);
- else
- this.DataColumns(_dataTable.Columns, strHideField: strHideField);
- }
- // 开启虚拟模式;
- this.VirtualMode = true;
- // 设置总行数;
- this.RowCount = _dataTable.Rows.Count;
- // 获取同订单不显示的列字段;
- _listNullColumn = new List<string>(this.StrValueNullColumn.Split(','));
- _listSecondStageNullColumn = new List<string>(StrSecondStageNull.Split(','));
- // 设置类型;
- nBindingDataType = 2;
- // 显示行数;
- nDataSourceTopCount = DataSourceTopCount;
- if ( DataSourceTopCount == -1 )
- nDataSourceTopCount = _dataTable.Rows.Count;
- // 绑定单元格显示事件;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded0;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded1;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded2;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded3;
- this.CellValueNeeded += DataGridViewEc_CellValueNeeded2;
- }
- catch ( Exception e )
- {
- }
- }
- public void UseVirtualMode( DataTable dataTable, bool IsClearRows = false )
- {
- try
- {
- Debug.Write("\n虚拟模式3\n");
- // 参数校验;
- if ( dataTable == null /*|| dataTable.Rows.Count == 0*/ )
- return;
- // 清空之前的行;
- if ( _dataTable != null )
- _dataTable = null;
- if ( IsClearRows )
- this.Rows.Clear();
- // 保存数据集;
- _dataTable = dataTable;
- // 开启虚拟模式;
- this.VirtualMode = true;
- // 设置总行数;
- this.RowCount = _dataTable.Rows.Count;
- // 设置类型;
- nBindingDataType = 3;
- // 绑定单元格显示事件;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded0;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded1;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded2;
- this.CellValueNeeded -= DataGridViewEc_CellValueNeeded3;
- this.CellValueNeeded += DataGridViewEc_CellValueNeeded3;
- }
- catch ( Exception e )
- {
- }
- }
- /// <summary>
- /// 设置备注便签描述
- /// </summary>
- /// <param name="dgrCurrent"></param>
- private void SetDataRowSign(DataGridViewRow dgrCurrent,int RowIndex)
- {
- if (this.Columns.Contains("Ordv_ViceNumber") && this._SignRemark.Rows.Count > 0)
- {
- if (dgrCurrent.Tag == null)
- {
- List<DataRow> drSignRemarks = this._SignRemark.AsEnumerable().Where(p => p.Field<string>("Ordrr_ViceNumber") == _dataTable.Rows[RowIndex]["Ordv_ViceNumber"].ToString()).ToList();
- if (drSignRemarks.Count > 0)
- {
- dgrCurrent.Tag = "Sign";
- }
- }
- }
- }
- // 事件0;
- private void DataGridViewEc_CellValueNeeded0( object sender, DataGridViewCellValueEventArgs e )
- {
- // 参数校验;
- if ( _dataTable == null || _dataTable.Rows.Count == 0 || _dataTable.Rows.Count == e.RowIndex )
- return;
- // 当前行;
- DataGridViewRow dgrCurrent = this.Rows[e.RowIndex];
- SetDataRowSign(dgrCurrent,e.RowIndex);
- // 设置行高;
- //dgrCurrent.Height = 25;
- if ( e.RowIndex != 0 && _dataTable.Rows[e.RowIndex]["Ord_Number"].Equals(_dataTable.Rows[e.RowIndex - 1]["Ord_Number"]) )
- {// 同一订单的;
- // 上一行颜色;
- DataGridViewRow dgrLast = this.Rows[e.RowIndex - 1];
- if ( dgrCurrent.DefaultCellStyle.BackColor != dgrLast.DefaultCellStyle.BackColor )
- dgrCurrent.DefaultCellStyle.BackColor = dgrLast.DefaultCellStyle.BackColor;
- // 如果是不显示的列字段, 退出;
- if ( _listNullColumn.Contains(this.Columns[e.ColumnIndex].Name.Trim()) )
- return;
- if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
- e.Value = _dataTable.Rows[e.RowIndex][this.Columns[e.ColumnIndex].Name.Trim()].ToString();
- }
- else
- {// 下一订单的;
- if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
- e.Value = _dataTable.Rows[e.RowIndex][this.Columns[e.ColumnIndex].Name.Trim()].ToString();
- Color checkColor = System.Drawing.Color.YellowGreen;
- if (this.Columns.Contains("ord_AutoColor"))
- {
- if(dgrCurrent.Tag != null)
- {
- dynamic dyObj = dgrCurrent.Tag;
- checkColor = Color.FromArgb(Convert.ToInt32(dyObj.A), Convert.ToInt32(dyObj.R), Convert.ToInt32(dyObj.G), Convert.ToInt32(dyObj.B));
- }
-
-
- }
- // 如果是黄色, 直接退出(外部着色);
- if ( dgrCurrent.DefaultCellStyle.BackColor == checkColor)
- return;
- // 订单行是否更色;
- if ( e.RowIndex != 0 )
- {// 非第一行;
- DataGridViewRow dgrLast = this.Rows[e.RowIndex - 1];
- if ( dgrLast.DefaultCellStyle.BackColor == System.Drawing.Color.PowderBlue )
- dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PapayaWhip;
- else
- dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
- }
- else
- {// 第一行时;
- dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
- }
- // 如果包含"欠款"字段,变色;
- if ( this.Columns.Contains("欠款") )
- {
- if (!string.IsNullOrEmpty(Convert.ToString(e.Value)))
- {
- if (this.Columns[e.ColumnIndex].Name.Trim() == "欠款" && Convert.ToDecimal(e.Value) > 0)
- dgrCurrent.DefaultCellStyle.ForeColor = Color.Red;
- }
- }
- }
- // 如果包含'重拍'字段,变色;
- if ( this.Columns.Contains("Ord_Class") )
- {
- if ( this.Columns[e.ColumnIndex].Name.Trim().ToLower() == "ord_class" && e.Value.ToString().Trim() == "0" )
- dgrCurrent.DefaultCellStyle.ForeColor = Color.Red;
- }
- // 如果包含'重拍'字段,变色;
- if ( this.Columns.Contains("拍摄状态") )
- {
- if ( this.Columns[e.ColumnIndex].Name.Trim() == "拍摄状态" && e.Value.ToString().Trim() == "重拍" )
- dgrCurrent.DefaultCellStyle.ForeColor = Color.Coral;
- }
-
- if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherPermissionsSet, LYFZ.CustomAttributes.OperatingAuthority.ProhibitViewCustomerPhoneNumber) && !LYFZ.BLL.BLL_ErpUser.IsAdministrator() && DataGridViewEx.HidePhoneCellsNameList.Count > 0)
- {
- try
- {
- foreach (string HidePhoneCellsName in HidePhoneFindList)
- {
- if (this.Columns[e.ColumnIndex].Name.Contains(HidePhoneCellsName))
- {
- //e. = this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value;
- //_dataTable.Rows[e.RowIndex][HidePhoneCellsName] = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
- e.Value = LYFZ.Command.Command_Validate.HidePhone(e.Value);
- }
- }
- }
- catch (Exception ex) { }
- }
- }
- // 事件1;
- private void DataGridViewEc_CellValueNeeded1( object sender, DataGridViewCellValueEventArgs e )
- {
- // 参数校验;
- if ( _dataTable == null || _dataTable.Rows.Count == 0 || _dataTable.Rows.Count == e.RowIndex )
- return;
- // 当前行;
- DataGridViewRow dgrCurrent = this.Rows[e.RowIndex];
- SetDataRowSign(dgrCurrent, e.RowIndex);
- // 设置行高;
- //dgrCurrent.Height = 25;
- if ( e.RowIndex != 0 && _dataTable.Rows[e.RowIndex]["Ord_Number"].Equals(_dataTable.Rows[e.RowIndex - 1]["Ord_Number"]) )
- {// 同一订单的;
- // 上一行颜色;
- DataGridViewRow dgrLast = this.Rows[e.RowIndex - 1];
- if ( dgrCurrent.DefaultCellStyle.BackColor.IsEmpty )
- dgrCurrent.DefaultCellStyle.BackColor = dgrLast.DefaultCellStyle.BackColor;
- // 如果是不显示的列字段, 退出;
- if ( _listNullColumn.Contains(this.Columns[e.ColumnIndex].Name.Trim()) )
- return;
- if ( _dataTable.Columns.Contains("拍摄名称") &&
- _dataTable.Rows[e.RowIndex]["拍摄名称"].Equals(_dataTable.Rows[e.RowIndex - 1]["拍摄名称"]) &&
- _listSecondStageNullColumn.Contains(this.Columns[e.ColumnIndex].Name.Trim()) )
- {
- return;
- }
- if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
- e.Value = _dataTable.Rows[e.RowIndex][this.Columns[e.ColumnIndex].Name.Trim()].ToString();
- }
- else
- {// 下一订单的;
- if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
- e.Value = _dataTable.Rows[e.RowIndex][this.Columns[e.ColumnIndex].Name.Trim()].ToString();
- // 订单行是否更色;
- if ( e.RowIndex != 0 )
- {// 非第一行;
- DataGridViewRow dgrLast = this.Rows[e.RowIndex - 1];
- if ( dgrLast.DefaultCellStyle.BackColor == System.Drawing.Color.PowderBlue )
- dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PapayaWhip;
- else
- dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
- }
- else
- {// 第一行时;
- dgrCurrent.DefaultCellStyle.BackColor = System.Drawing.Color.PowderBlue;
- }
- // 如果包含"欠款"字段,变色并且保留两位小数;
- if ( this.Columns.Contains("欠款") )
- {
- if ( this.Columns[e.ColumnIndex].Name.Trim() == "欠款" )
- {
- e.Value = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(e.Value);
- // 欠款红色;
- if ( Convert.ToDecimal(e.Value) > 0 )
- dgrCurrent.DefaultCellStyle.ForeColor = Color.Red;
- }
- }
- // 如果包含"加挑金额"字段,保留两位小数;
- if ( this.Columns.Contains("加挑金额") )
- {
- if ( this.Columns[e.ColumnIndex].Name.Trim() == "加挑金额" )
- e.Value = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(e.Value);
- }
- }
- if (this.Columns.Contains("ord_AutoColor"))
- {
- if (dgrCurrent.Tag != null)
- {
- dynamic dyObj = dgrCurrent.Tag;
- Color checkColor = Color.FromArgb(Convert.ToInt32(dyObj.A), Convert.ToInt32(dyObj.R), Convert.ToInt32(dyObj.G), Convert.ToInt32(dyObj.B));
- dgrCurrent.DefaultCellStyle.BackColor = checkColor;
- }
- }
- if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherPermissionsSet, LYFZ.CustomAttributes.OperatingAuthority.ProhibitViewCustomerPhoneNumber) && !LYFZ.BLL.BLL_ErpUser.IsAdministrator() && DataGridViewEx.HidePhoneCellsNameList.Count > 0)
- {
- try
- {
- foreach (string HidePhoneCellsName in HidePhoneFindList)
- {
- if (this.Columns[e.ColumnIndex].Name.Contains(HidePhoneCellsName))
- {
- //e. = this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value;
- //_dataTable.Rows[e.RowIndex][HidePhoneCellsName] = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
- e.Value = LYFZ.Command.Command_Validate.HidePhone(e.Value);
- }
- }
- }
- catch (Exception ex) { }
- }
- }
- // 事件2;
- private void DataGridViewEc_CellValueNeeded2( object sender, DataGridViewCellValueEventArgs e )
- {
- // 参数校验;
- if ( _dataTable == null ||
- _dataTable.Rows.Count == 0 ||
- _dataTable.Rows.Count == e.RowIndex ||
- e.RowIndex > nDataSourceTopCount )
- return;
- if(e.Value==null)
- {
- e.Value = "";
- }
- // 当前行;
- DataGridViewRow dgrCurrent = this.Rows[e.RowIndex];
- SetDataRowSign(dgrCurrent, e.RowIndex);
- if ( dgrCurrent.DefaultCellStyle.BackColor.IsEmpty )
- dgrCurrent.DefaultCellStyle.BackColor = (e.RowIndex % 2 == 0) ? System.Drawing.Color.PapayaWhip : System.Drawing.Color.PowderBlue;
- // StrIsAddColumnsNull不是_dataTable中的列,是手动加进去的(何意义??);
- if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
- e.Value = _dataTable.Rows[e.RowIndex][_dataTable.Columns[e.ColumnIndex].ToString().Trim()].ToString();
- // 如果包含"欠款"字段,变色;
- if ( this.Columns.Contains("欠款") )
- {
- if ( this.Columns[e.ColumnIndex].Name.Trim() == "欠款" && Convert.ToDecimal(e.Value) > 0 )
- dgrCurrent.DefaultCellStyle.ForeColor = Color.Red;
- }
- // 如果是医院跟踪系统,处理以下内容;
- if ( this.Columns.Contains("生日类型") && this.Columns.Contains("宝宝性别") )
- {
- if ( this.Columns[e.ColumnIndex].Name.Trim() == "生日类型" && e.Value.ToString() == "预产期" )
- dgrCurrent.Cells["宝宝性别"].Value = "";
- }
- if (this.Columns.Contains("ord_AutoColor"))
- {
- if (this.Columns[e.ColumnIndex].Name.Trim() == "ord_AutoColor" && e.Value != null && e.Value.ToString().Trim() != "")
- {
- dynamic dyObj = JsonConvert.DeserializeObject(e.Value.ToString().Trim());
- dgrCurrent.DefaultCellStyle.BackColor = Color.FromArgb(Convert.ToInt32(dyObj.A), Convert.ToInt32(dyObj.R), Convert.ToInt32(dyObj.G), Convert.ToInt32(dyObj.B));
- }
- }
- if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherPermissionsSet, LYFZ.CustomAttributes.OperatingAuthority.ProhibitViewCustomerPhoneNumber) && !LYFZ.BLL.BLL_ErpUser.IsAdministrator() && DataGridViewEx.HidePhoneCellsNameList.Count > 0)
- {
- try
- {
- foreach (string HidePhoneCellsName in HidePhoneFindList)
- {
- if (this.Columns[e.ColumnIndex].Name.Contains(HidePhoneCellsName))
- {
- //e. = this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value;
- //_dataTable.Rows[e.RowIndex][HidePhoneCellsName] = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
- e.Value = LYFZ.Command.Command_Validate.HidePhone(e.Value);
- }
- }
- }
- catch (Exception ex) { }
- }
- }
- // 事件3;
- private void DataGridViewEc_CellValueNeeded3( object sender, DataGridViewCellValueEventArgs e )
- {
- // 参数校验;
- if ( _dataTable == null || _dataTable.Rows.Count == 0 || _dataTable.Rows.Count == e.RowIndex )
- return;
- // 当前行;
- DataGridViewRow dgrCurrent = this.Rows[e.RowIndex];
- SetDataRowSign(dgrCurrent, e.RowIndex);
- if ( dgrCurrent.DefaultCellStyle.BackColor.IsEmpty )
- dgrCurrent.DefaultCellStyle.BackColor = (e.RowIndex % 2 == 0) ? System.Drawing.Color.PapayaWhip : System.Drawing.Color.PowderBlue;
- // StrIsAddColumnsNull不是_dataTable中的列,是手动加进去的(何意义??);
- if ( this.Columns[e.ColumnIndex].Name.Trim() != "StrIsAddColumnsNull" )
- e.Value = _dataTable.Rows[e.RowIndex][e.ColumnIndex];
- if (this.Columns.Contains("ord_AutoColor"))
- {
- if (this.Columns[e.ColumnIndex].Name.Trim() == "ord_AutoColor" && e.Value != null && e.Value.ToString().Trim() != "")
- {
- dynamic dyObj = JsonConvert.DeserializeObject(e.Value.ToString().Trim());
- dgrCurrent.DefaultCellStyle.BackColor = Color.FromArgb(Convert.ToInt32(dyObj.A), Convert.ToInt32(dyObj.R), Convert.ToInt32(dyObj.G), Convert.ToInt32(dyObj.B));
- }
- }
- if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OtherPermissionsSet, LYFZ.CustomAttributes.OperatingAuthority.ProhibitViewCustomerPhoneNumber) && !LYFZ.BLL.BLL_ErpUser.IsAdministrator() && DataGridViewEx.HidePhoneCellsNameList.Count > 0)
- {
- try
- {
- foreach (string HidePhoneCellsName in HidePhoneFindList)
- {
- if (this.Columns[e.ColumnIndex].Name.Contains(HidePhoneCellsName))
- {
- //e. = this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value;
- //_dataTable.Rows[e.RowIndex][HidePhoneCellsName] = LYFZ.Command.Command_Validate.HidePhone(this.Rows[e.RowIndex].Cells[HidePhoneCellsName].Value);
- e.Value = LYFZ.Command.Command_Validate.HidePhone(e.Value);
- }
- }
- }
- catch (Exception ex) { }
- }
- }
- #endregion
- /// <summary>
- /// 获取固定指定为空的数据
- /// </summary>
- /// <param name="strColumnName"></param>
- /// <param name="strRowsValue"></param>
- /// <returns></returns>
- public string GetRowsValue( string strColumnName, string strRowsValue )
- {
- switch ( strColumnName )
- {
- case "客户姓名":
- case "客户性别":
- case "客户电话":
- strRowsValue = Convert.ToString("");
- break;
- }
- return strRowsValue;
- }
- #region 老客户绑定
- /// <summary>
- /// 老客户绑定
- /// </summary>
- /// <param name="dt"></param>
- /// <param name="strHideField"></param>
- public void DataClientSource( DataTable dt, string strHideField = "" )
- {
- try
- {
- this.IsCompleteBonding = false;
- this.Rows.Clear();
- this.DataColumns(dt.Columns, strHideField: strHideField);
- this.DataClientSourceRows(dt);
- this.IsCompleteBonding = true;
- }
- catch
- {
- }
- }
- /// <summary>
- /// 绑定行
- /// </summary>
- public void DataClientSourceRows( DataTable dt, int DataSourceTopCount = -1 )
- {
- // 行的唯一标识
- float RowUniqueMark = 0;
- int forRowCount = dt.Rows.Count;
- if ( DataSourceTopCount != -1 )
- {
- if ( dt.Rows.Count > DataSourceTopCount )
- {
- forRowCount = DataSourceTopCount;
- }
- }
- for ( int i = 0; i < forRowCount; i++ )
- {
- DataGridViewRow dgvr = new DataGridViewRow();
- if ( (RowUniqueMark % 2) > 0 )
- {
- dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Double();
- }
- else
- {
- dgvr.DefaultCellStyle.BackColor = DataGridViewRowsBackColor_Single();
- }
- dgvr.HeaderCell.Tag = true;
- dgvr.Height = 25;
- DataGridViewCell cell = null;
- for ( int j = 0; j < dt.Columns.Count; j++ )
- {
- cell = new DataGridViewTextBoxCell();
- cell.Value = dt.Rows[i][dt.Columns[j].ToString().Trim()].ToString().Trim();
- dgvr.Cells.Add(cell);
- }
- if ( this.Columns.Contains("Ord_ViceOrderCount") )
- {
- if ( Convert.ToInt32(dt.Rows[i]["Ord_ViceOrderCount"]) > 1 )
- {
- dgvr.HeaderCell.Tag = true;
- dgvr.HeaderCell.Value = i + "_Expand";
- dgvr.HeaderCell.ToolTipText = "点击展开";
- }
- else
- {
- dgvr.HeaderCell.Tag = false;
- dgvr.HeaderCell.Value = i + "_" + "Collapse";
- dgvr.HeaderCell.ToolTipText = "点击折叠";
- }
- }
- this.Rows.Add(dgvr);
- RowUniqueMark++;
- }
- }
- /// <summary>
- /// 老客户绑定子集子数据的绑定
- /// </summary>
- /// <param name="Vicetbl"></param>
- public void DataClientSourceViceRow( DataRow[] dtRow )
- {
- try
- {
- if ( Convert.ToBoolean(this.Rows[CRowsIndex].HeaderCell.Tag) )
- {
- this.DataExpandRows(dtRow);
- }
- else
- {
- this.DataContractRows();
- }
- }
- catch { }
- }
- #endregion
- private bool _isAddNullColumns;
- /// <summary>
- /// false:为用最后一列填充,true:为新增一个空列来填充后面空白
- /// </summary>
- private bool IsAddNullColumns
- {
- get
- {
- return _isAddNullColumns;
- }
- set
- {
- _isAddNullColumns = value;
- }
- }
- /// <summary>
- /// 填充最后列的列名
- /// </summary>
- public string FillColumnsNullName = "StrIsAddColumnsNull";
- /// <summary>
- /// 填充最后列
- /// </summary>
- /// <param name="isAddNullColumns">false:为用最后一列填充,true:为新增一个空列来填充后面空白</param>
- public void FillLastColumn( bool isAddNullColumns = false )
- {
- if ( this.Columns.Count > 0 )
- {
- this.IsAddNullColumns = isAddNullColumns;
- if ( !isAddNullColumns )
- {
- int dgvWidth = 0;
- for ( int i = 0; i < this.Columns.Count; i++ )
- {
- if ( this.Columns[i].Visible )
- {
- dgvWidth += this.Columns[i].Width;
- }
- }
- if ( dgvWidth < this.Width )
- {
- if ( this.RowHeadersVisible )
- {
- dgvWidth += this.RowHeadersWidth;
- }
- this.Columns[this.Columns.Count - 1].Width = this.Width - dgvWidth + this.Columns[this.Columns.Count - 1].Width - 5;
- }
- else
- {
- this.Columns[this.Columns.Count - 1].Width = 100;
- }
- }
- else
- {
- bool IsFind = true;
- for ( int i = 0; i < this.Columns.Count; i++ )
- {
- if ( this.Columns[i].Name.Trim() == FillColumnsNullName )
- {
- IsFind = false;
- break;
- }
- }
- if ( IsFind )
- {
- DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
- column.ReadOnly = true;
- column.Name = FillColumnsNullName;
- column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- column.HeaderText = "";
- this.Columns.Add(column);
- }
- }
- }
- }
- #endregion
- #region 列标头点击解发事件事件
- /// <summary>
- /// 申明委托
- /// </summary>
- /// <param name="e"></param>
- /// <returns></returns>
- public delegate void EventExpandCollapseHandler( EventExpandCollapse e );
- /// <summary>
- /// PrintSingle事件
- /// </summary>
- public event EventExpandCollapseHandler EventRowExpandCollapse;
- /// <summary>
- /// EventSelectPhotoPrint 选片打开事件对象
- /// </summary>
- public class EventExpandCollapse : EventArgs
- {
- bool _expandOrCollapse = true;
- /// <summary>
- /// true为展开 false 为折叠
- /// </summary>
- public bool ExpandOrCollapse
- {
- get
- {
- return _expandOrCollapse;
- }
- set
- {
- _expandOrCollapse = value;
- }
- }
- DataGridViewCellMouseEventArgs onRowHeaderMouseClick;
- public DataGridViewCellMouseEventArgs OnRowHeaderMouseClick
- {
- get
- {
- return onRowHeaderMouseClick;
- }
- set
- {
- onRowHeaderMouseClick = value;
- }
- }
- DataGridViewRowCollection cRows;
- /// <summary>
- /// 当前行
- /// </summary>
- public DataGridViewRowCollection CRows
- {
- get
- {
- return cRows;
- }
- set
- {
- cRows = value;
- }
- }
- public EventExpandCollapse()
- {
- }
- }
- #endregion
- /// <summary>
- /// 导出数据
- /// </summary>
- public void ExportDataTable( string StrFileName = "" )
- {
- DataTable NewTable = this.ToDataTable();
- SaveFileDialog saveFile = new SaveFileDialog();
- saveFile.FileName = StrFileName;
- saveFile.Title = "导出数据报表文件";
- saveFile.Filter = "EXECL文件(*.xls) |*.xls |文本文件(*.txt) |*.txt |所有文件(*.*) |*.*";
- saveFile.FilterIndex = 1;
- DialogResult drst = saveFile.ShowDialog();
- if ( drst == DialogResult.No || drst == DialogResult.Cancel || drst == DialogResult.No || drst == DialogResult.Abort )
- {
- return;
- }
- LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
- {
- try
- {
- if (LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(saveFile.FileName.Trim(), NewTable, null, backgroundWorker))
- {
- MessageBoxCustom.Show("数据导出成功!");
- }
- else
- {
- MessageBoxCustom.Show("数据导出失败!");
- }
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(String.Format("导出数据出错:{0}", ex.Message));
- }
- });
- //if ( LYFZ.Command.Command_ExportExcel.DataTable2Sheet(saveFile.FileName.Trim(), NewTable, "Sheet1", IsCoveredExistingFile: true) )
- //{
- // MessageBoxCustom.Show("导出成功!");
- //}
- //else
- //{
- // MessageBoxCustom.Show("导出失败!");
- //}
- }
- /// <summary>
- /// 导出数据
- /// </summary>
- public void ExportDataTable( DataTable NewTable, string StrFileName = "" )
- {
- SaveFileDialog saveFile = new SaveFileDialog();
- saveFile.FileName = StrFileName;
- saveFile.Title = "导出数据报表文件";
- saveFile.Filter = "EXECL文件(*.xls) |*.xls |文本文件(*.txt) |*.txt |所有文件(*.*) |*.*";
- saveFile.FilterIndex = 1;
- DialogResult drst = saveFile.ShowDialog();
- if ( drst == DialogResult.No || drst == DialogResult.Cancel || drst == DialogResult.No || drst == DialogResult.Abort )
- {
- return;
- }
- LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
- {
- try
- {
- if (LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(saveFile.FileName.Trim(), NewTable, null, backgroundWorker))
- {
- MessageBoxCustom.Show("数据导出成功!");
- }
- else
- {
- MessageBoxCustom.Show("数据导出失败!");
- }
- }
- catch (Exception ex)
- {
- MessageBoxCustom.Show(String.Format("导出数据出错:{0}", ex.Message));
- }
- });
- //if ( LYFZ.Command.Command_ExportExcel.DataTable2Sheet(saveFile.FileName.Trim(), NewTable, "Sheet1", IsCoveredExistingFile: true) )
- //{
- // MessageBoxCustom.Show("导出成功!");
- //}
- //else
- //{
- // MessageBoxCustom.Show("导出失败!");
- //}
- }
- /// <summary>
- /// 将本列表数据转成DataTable
- /// </summary>
- public DataTable ToDataTable( bool IsShowVisible = false )
- {
- DataTable NewTable = new DataTable();
- for ( int i = 0; i < this.Columns.Count; i++ )
- {
- if ( !string.IsNullOrEmpty(this.Columns[i].HeaderText.Trim()) )
- {
- if ( !IsShowVisible )
- {
- if ( !this.Columns[i].Visible )
- {
- continue;
- }
- }
- NewTable.Columns.Add(this.Columns[i].HeaderText.Trim(), typeof(string));
- }
- }
- for ( int i = 0; i < this.Rows.Count; i++ )
- {
- DataRow newRow = NewTable.NewRow();
- for ( int j = 0; j < this.Columns.Count; j++ )
- {
- if ( !string.IsNullOrEmpty(this.Columns[j].HeaderText.Trim()) )
- {
- if ( !IsShowVisible )
- {
- if ( !this.Columns[j].Visible )
- {
- continue;
- }
- }
- if ( this.Rows[i].Cells[this.Columns[j].HeaderText.Trim()].Value != null )
- newRow[this.Columns[j].HeaderText.Trim()] = this.Rows[i].Cells[this.Columns[j].HeaderText.Trim()].Value.ToString().Trim();
- }
- }
- NewTable.Rows.Add(newRow);
- }
- return NewTable;
- }
- protected override void CreateHandle()
- {
- if ( !IsHandleCreated )
- {
- try
- {
- base.CreateHandle();
- }
- catch { }
- finally
- {
- if ( !IsHandleCreated )
- {
- base.RecreateHandle();
- }
- }
- }
- }
- }
- }
|