F_MST_012003.cs 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_012002.cs
  5. * 2.功能描述:新票据信息操作
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2016/02/18 1.00 新建
  9. * 周兴 2016/03/11 1.00 编辑
  10. *******************************************************************************/
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using Dongke.IBOSS.PRD.Basics.BaseResources;
  17. using Dongke.IBOSS.PRD.Client.CommonModule;
  18. using Dongke.IBOSS.PRD.WCF.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.Proxys;
  20. using Dongke.WinForm.Controls;
  21. using Dongke.WinForm.Controls.InvoiceLayout;
  22. namespace Dongke.IBOSS.PRD.Client.Controls
  23. {
  24. public partial class F_MST_012003 : DKFormBase
  25. {
  26. #region 成员变量
  27. private float _paperHeight; // Layout的纸张的高
  28. private float _paperWidth; // Layout的纸张的宽
  29. private int _goodstypeid; // 产品类别ID
  30. private string _goodstypeCode; // 产品类别编码
  31. private string _goodstypeName; // 产品类别名称
  32. private int? _logoid; // 产品商标ID
  33. private bool _zooming = false; // 缩放标识
  34. private int _invoiceLayoutID; // 票据ID
  35. private DataTable _invoiceLayoutDataTable; // 票据主信息数据
  36. private DataSet _saveData; // 保存票据数据时的数据集
  37. private bool _layoutSelectionChanging; // 选择标识
  38. private bool _isFormDataChanged = false; // 画面的数据是否有改变
  39. private ClientRequestEntity _clientRequestEntity; // 查询条件实体
  40. //private string _remarks; // 总单备注
  41. //xuwei add 2019-11-20
  42. private int? _printType; //打印类别
  43. #endregion
  44. #region 属性
  45. #endregion
  46. #region 构造函数
  47. /// <summary>
  48. /// 构造函数
  49. /// </summary>
  50. public F_MST_012003(int goodstypeID, string goodstypeCode, string goodstypeName, int? logoid, string logoname,
  51. float paperWidth, float paperHeight, string layoutName,int printType, string remarks)
  52. {
  53. InitializeComponent();
  54. this.Text = string.Format(F_MST_012001.TITLE_F_MST_012001_NEW, layoutName);
  55. this.cbxMagnification.SelectedIndex = 3;
  56. this.txtGoodsType.Text = goodstypeName + "【" + goodstypeCode + "】";
  57. this.txtLogo.Text = logoname;
  58. this.txtInvoiceName.Text = layoutName;
  59. this._paperHeight = paperHeight;
  60. this._paperWidth = paperWidth;
  61. this._invoiceLayoutID = 0;
  62. this._goodstypeid = goodstypeID;
  63. this._goodstypeCode = goodstypeCode;
  64. this._goodstypeName = goodstypeName;
  65. this._logoid = logoid;
  66. this.txtRemarks.Text = remarks;
  67. this.lbxInvoice.LayoutMode = LayoutMode.Edit;
  68. this._printType = printType;
  69. }
  70. /// <summary>
  71. /// 构造函数
  72. /// </summary>
  73. public F_MST_012003(int layoutID)
  74. {
  75. InitializeComponent();
  76. this.cbxMagnification.SelectedIndex = 3;
  77. this._invoiceLayoutID = layoutID;
  78. this.lbxInvoice.LayoutMode = LayoutMode.Edit;
  79. }
  80. #endregion
  81. #region 控件事件
  82. #region 窗体控件事件
  83. /// <summary>
  84. /// 显示比率选项发生改变事件
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void cbxMagnification_SelectedIndexChanged(object sender, System.EventArgs e)
  89. {
  90. try
  91. {
  92. _zooming = true;
  93. // 选择了全体显示
  94. if (cbxMagnification.SelectedItem.ToString().Equals("全体"))
  95. {
  96. lbxInvoice.ZoomType = ZoomType.Whole;
  97. }
  98. else
  99. {
  100. // 选择了其他选择
  101. lbxInvoice.Zoom = Convert.ToInt32(cbxMagnification.SelectedItem.ToString().Replace("%", ""));
  102. }
  103. _zooming = false;
  104. }
  105. catch (Exception ex)
  106. {
  107. _zooming = false;
  108. // 对异常进行共通处理
  109. ExceptionManager.HandleEventException(this.ToString(),
  110. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  111. }
  112. }
  113. /// <summary>
  114. /// 保存按钮按下,保存票据数据
  115. /// </summary>
  116. /// <param name="sender"></param>
  117. /// <param name="e"></param>
  118. private void tsbtnSave_Click(object sender, System.EventArgs e)
  119. {
  120. try
  121. {
  122. _saveData = new DataSet();
  123. // 更新票据主信息的DataTable
  124. this.SetSaveLayoutData(ref _saveData, this._invoiceLayoutID);
  125. // 组成票据项目信息的DataTable
  126. this.SetSaveLayoutItemData(ref _saveData);
  127. // 新建票据的情况
  128. if (this._invoiceLayoutID == 0)
  129. {
  130. ServiceResultEntity result = this.DoAsync<ServiceResultEntity>(() =>
  131. {
  132. return this.SaveAddLayoutData();
  133. });
  134. int invoiceLayoutID = Convert.ToInt32(result.Result);
  135. if (invoiceLayoutID > 0)
  136. {
  137. MessageBox.Show(string.Format("{0}的{1}操作成功完成了。", "新建条码打印格式", "保存"),
  138. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  139. // 新建成功后,将画面修改成编辑状态
  140. this._invoiceLayoutID = invoiceLayoutID;
  141. this.Text = string.Format(F_MST_012001.TITLE_F_MST_012002_EDIT, this.txtInvoiceName.Text.Trim());
  142. this._invoiceLayoutDataTable = _saveData.Tables[0];
  143. this.tsbtnSaveAs.Enabled = true;
  144. this.tsmiSaveAs.Enabled = true;
  145. }
  146. else
  147. {
  148. MessageBox.Show(string.Format("{0}的{1}操作没有更新任何数据,请确认该数据是否存在。", "新建条码打印", "保存"),
  149. this.Text,
  150. MessageBoxButtons.OK,
  151. MessageBoxIcon.Warning);
  152. }
  153. }
  154. else
  155. {
  156. ServiceResultEntity result = this.DoAsync<ServiceResultEntity>(() =>
  157. {
  158. return this.SaveEditLayoutData();
  159. });
  160. int returnAffectRows = Convert.ToInt32(result.Result);
  161. if (returnAffectRows > 0)
  162. {
  163. MessageBox.Show(string.Format("{0}的{1}操作成功完成了。", "编辑条码打印格式", "保存"),
  164. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  165. }
  166. else
  167. {
  168. MessageBox.Show(string.Format("{0}的{1}操作没有更新任何数据,请确认该数据是否存在。", "编辑条码打印", "保存"),
  169. this.Text,
  170. MessageBoxButtons.OK,
  171. MessageBoxIcon.Warning);
  172. }
  173. }
  174. this.lbxInvoice.AcceptChange();
  175. _isFormDataChanged = true;
  176. }
  177. catch (Exception ex)
  178. {
  179. // 对异常进行共通处理
  180. ExceptionManager.HandleEventException(this.ToString(),
  181. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  182. }
  183. }
  184. /// <summary>
  185. /// 保存菜单按钮,保存票据
  186. /// </summary>
  187. /// <param name="sender"></param>
  188. /// <param name="e"></param>
  189. private void tsmiSave_Click(object sender, System.EventArgs e)
  190. {
  191. this.tsbtnSave_Click(sender, e);
  192. }
  193. /// <summary>
  194. /// 另存为按钮按下,另存票据数据
  195. /// </summary>
  196. /// <param name="sender"></param>
  197. /// <param name="e"></param>
  198. private void tsbtnSaveAs_Click(object sender, System.EventArgs e)
  199. {
  200. try
  201. {
  202. F_MST_012004 frmINV0302 = new F_MST_012004();
  203. frmINV0302.LayoutName = this.txtInvoiceName.Text.Trim();
  204. frmINV0302.Remarks = this.txtRemarks.Text.Trim();
  205. frmINV0302.GoodsTypeID = this._goodstypeid;
  206. frmINV0302.GoodsTypeCode = this._goodstypeCode;
  207. frmINV0302.GoodsTypeName = this._goodstypeName;
  208. frmINV0302.LogoID = this._logoid;
  209. frmINV0302.LogoName = this.txtLogo.Text;
  210. //xuwei add 2019-11-20
  211. frmINV0302.PrintType = this._printType;
  212. frmINV0302.FromForm = 1;
  213. DialogResult dialogResult = frmINV0302.ShowDialog();
  214. if (DialogResult.OK == dialogResult)
  215. {
  216. // 将另存为页面信息传递到本页面
  217. this.txtInvoiceName.Text = frmINV0302.LayoutName;
  218. this.txtRemarks.Text = frmINV0302.Remarks;
  219. this._goodstypeid = frmINV0302.GoodsTypeID;
  220. this._goodstypeCode = frmINV0302.GoodsTypeCode;
  221. this._goodstypeName = frmINV0302.GoodsTypeName;
  222. this.txtGoodsType.Text = _goodstypeName + "【" + _goodstypeCode + "】";
  223. this._logoid = frmINV0302.LogoID;
  224. this.txtLogo.Text = frmINV0302.LogoName;
  225. //xuwei add 2019-11-20
  226. this._printType = frmINV0302.PrintType;
  227. _saveData = new DataSet();
  228. // 更新票据主信息的DataTable
  229. this.SetSaveLayoutData(ref _saveData, 0);
  230. // 组成票据项目信息的DataTable
  231. this.SetSaveLayoutItemData(ref _saveData);
  232. // 另存票据的情况
  233. ServiceResultEntity result = this.DoAsync<ServiceResultEntity>(() =>
  234. {
  235. return this.SaveAddLayoutData();
  236. });
  237. int invoiceLayoutID = Convert.ToInt32(result.Result);
  238. if (invoiceLayoutID > 0)
  239. {
  240. // 将窗体标题修改成另存为的标题
  241. MessageBox.Show(string.Format("{0}的{1}操作成功完成了。", "另存条码打印格式", "保存"),
  242. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  243. // 新建成功后,将画面修改成编辑状态
  244. this._invoiceLayoutID = invoiceLayoutID;
  245. this.Text = string.Format(F_MST_012001.TITLE_F_MST_012002_EDIT, this.txtInvoiceName.Text.Trim());
  246. this._invoiceLayoutDataTable = _saveData.Tables[0];
  247. }
  248. else
  249. {
  250. MessageBox.Show(string.Format("{0}的{1}操作没有更新任何数据,请确认该数据是否存在。", "另存条码打印格式", "保存"),
  251. this.Text,
  252. MessageBoxButtons.OK,
  253. MessageBoxIcon.Warning);
  254. }
  255. this.lbxInvoice.AcceptChange();
  256. _isFormDataChanged = true;
  257. }
  258. }
  259. catch (Exception ex)
  260. {
  261. // 对异常进行共通处理
  262. ExceptionManager.HandleEventException(this.ToString(),
  263. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  264. }
  265. }
  266. /// <summary>
  267. /// 另存为菜单按下,另存票据数据
  268. /// </summary>
  269. /// <param name="sender"></param>
  270. /// <param name="e"></param>
  271. private void tsmiSaveAs_Click(object sender, System.EventArgs e)
  272. {
  273. this.tsbtnSaveAs_Click(sender, e);
  274. }
  275. /// <summary>
  276. /// 关闭菜单按钮按下,关闭页面
  277. /// </summary>
  278. /// <param name="sender"></param>
  279. /// <param name="e"></param>
  280. private void tsmiClose_Click(object sender, System.EventArgs e)
  281. {
  282. this.Close();
  283. }
  284. /// <summary>
  285. /// 窗体关闭时检测页面是否有变动,提示保存
  286. /// </summary>
  287. /// <param name="sender"></param>
  288. /// <param name="e"></param>
  289. private void F_INV_0301_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
  290. {
  291. try
  292. {
  293. // 新建票据时,关闭窗体设置窗体的DialogResult属性
  294. if (this._invoiceLayoutID == 0)
  295. {
  296. // 提示是否保存数据
  297. DialogResult dialogResult = MessageBox.Show("当前页面的数据有过更改,请确认需要保存吗?", this.Text,
  298. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  299. if (DialogResult.Yes == dialogResult)
  300. {
  301. // 保存数据
  302. tsbtnSave_Click(sender, e);
  303. this.DialogResult = DialogResult.OK;
  304. }
  305. else if (DialogResult.Cancel == dialogResult)
  306. {
  307. e.Cancel = true;
  308. }
  309. else
  310. {
  311. if (_isFormDataChanged)
  312. {
  313. this.DialogResult = DialogResult.OK;
  314. }
  315. else
  316. {
  317. this.DialogResult = DialogResult.Cancel;
  318. }
  319. }
  320. }
  321. // 编辑票据
  322. else
  323. {
  324. _saveData = new DataSet();
  325. if (this.lbxInvoice.Dirty)
  326. {
  327. // 提示是否保存数据
  328. DialogResult dialogResult = MessageBox.Show("当前页面的数据有过更改,请确认需要保存吗?", this.Text,
  329. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  330. if (DialogResult.Yes == dialogResult)
  331. {
  332. // 保存数据
  333. tsbtnSave_Click(sender, e);
  334. this.DialogResult = DialogResult.OK;
  335. }
  336. else if (DialogResult.Cancel == dialogResult)
  337. {
  338. e.Cancel = true;
  339. }
  340. else
  341. {
  342. if (_isFormDataChanged)
  343. {
  344. this.DialogResult = DialogResult.OK;
  345. }
  346. else
  347. {
  348. this.DialogResult = DialogResult.Cancel;
  349. }
  350. }
  351. }
  352. }
  353. }
  354. catch (Exception ex)
  355. {
  356. // 对异常进行共通处理
  357. ExceptionManager.HandleEventException(this.ToString(),
  358. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  359. }
  360. }
  361. #endregion
  362. #region 票据功能按钮事件
  363. /// <summary>
  364. /// 剪切按钮按下,剪切项目
  365. /// </summary>
  366. /// <param name="sender"></param>
  367. /// <param name="e"></param>
  368. private void tsbtnCut_Click(object sender, EventArgs e)
  369. {
  370. this.lbxInvoice.CutItem();
  371. }
  372. /// <summary>
  373. /// 剪切菜单按下,剪切项目
  374. /// </summary>
  375. /// <param name="sender"></param>
  376. /// <param name="e"></param>
  377. private void tsmiCut_Click(object sender, EventArgs e)
  378. {
  379. this.lbxInvoice.CutItem();
  380. }
  381. /// <summary>
  382. /// 复制按钮按下,复制项目
  383. /// </summary>
  384. /// <param name="sender"></param>
  385. /// <param name="e"></param>
  386. private void tsbtnCopy_Click(object sender, EventArgs e)
  387. {
  388. this.lbxInvoice.CopyItem();
  389. }
  390. /// <summary>
  391. /// 复制菜单按下,复制项目
  392. /// </summary>
  393. /// <param name="sender"></param>
  394. /// <param name="e"></param>
  395. private void tsmiCopy_Click(object sender, EventArgs e)
  396. {
  397. this.lbxInvoice.CopyItem();
  398. }
  399. /// <summary>
  400. /// 粘贴按钮按下,粘贴项目
  401. /// </summary>
  402. /// <param name="sender"></param>
  403. /// <param name="e"></param>
  404. private void tsbtnPaste_Click(object sender, EventArgs e)
  405. {
  406. this.lbxInvoice.PasteItem();
  407. }
  408. /// <summary>
  409. /// 粘贴菜单按下,粘贴项目
  410. /// </summary>
  411. /// <param name="sender"></param>
  412. /// <param name="e"></param>
  413. private void tsmiPaste_Click(object sender, EventArgs e)
  414. {
  415. this.lbxInvoice.PasteItem();
  416. }
  417. /// <summary>
  418. /// 删除按钮按下,删除项目
  419. /// </summary>
  420. /// <param name="sender"></param>
  421. /// <param name="e"></param>
  422. private void tsbtnDelete_Click(object sender, EventArgs e)
  423. {
  424. this.lbxInvoice.DeleteItem();
  425. }
  426. /// <summary>
  427. /// 删除菜单按钮,删除项目
  428. /// </summary>
  429. /// <param name="sender"></param>
  430. /// <param name="e"></param>
  431. private void tsmiDelete_Click(object sender, EventArgs e)
  432. {
  433. this.lbxInvoice.DeleteItem();
  434. }
  435. /// <summary>
  436. /// 固定文字按钮按下,新建固定文字
  437. /// </summary>
  438. /// <param name="sender"></param>
  439. /// <param name="e"></param>
  440. private void tsbtnNewTextItem_Click(object sender, EventArgs e)
  441. {
  442. try
  443. {
  444. TextItem newTextItem = this.lbxInvoice.NewItem(ItemType.Text, true) as TextItem;
  445. if (newTextItem != null)
  446. {
  447. newTextItem.DataMember = string.Empty;
  448. }
  449. }
  450. catch (Exception ex)
  451. {
  452. // 对异常进行共通处理
  453. ExceptionManager.HandleEventException(this.ToString(),
  454. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  455. }
  456. }
  457. /// <summary>
  458. /// 固定文字菜单按下,新建固定文字
  459. /// </summary>
  460. /// <param name="sender"></param>
  461. /// <param name="e"></param>
  462. private void tsmiCharacter_Click(object sender, EventArgs e)
  463. {
  464. this.tsbtnNewTextItem_Click(sender, e);
  465. }
  466. /// <summary>
  467. /// 表格按钮按下,新建表格
  468. /// </summary>
  469. /// <param name="sender"></param>
  470. /// <param name="e"></param>
  471. private void tsbtnDataGrid_Click(object sender, EventArgs e)
  472. {
  473. try
  474. {
  475. if (this.lbxInvoice.OneGridItem != null)
  476. {
  477. MessageBox.Show("票据中已经存在一个表格了\r\n\r\n*一个票据中只能有一个格", this.Text,
  478. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  479. this.lbxInvoice.SelectItemSingle(this.lbxInvoice.OneGridItem, true);
  480. return;
  481. }
  482. this.lbxInvoice.NewItem(ItemType.Grid, true);
  483. }
  484. catch (Exception ex)
  485. {
  486. // 对异常进行共通处理
  487. ExceptionManager.HandleEventException(this.ToString(),
  488. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  489. }
  490. }
  491. /// <summary>
  492. /// 表格菜单按钮,新建表格
  493. /// </summary>
  494. /// <param name="sender"></param>
  495. /// <param name="e"></param>
  496. private void tsmiTable_Click(object sender, EventArgs e)
  497. {
  498. this.tsbtnDataGrid_Click(sender, e);
  499. }
  500. /// <summary>
  501. /// 固定列按钮按下,新建列
  502. /// </summary>
  503. /// <param name="sender"></param>
  504. /// <param name="e"></param>
  505. private void tsbtnAddGridColumn_Click(object sender, EventArgs e)
  506. {
  507. try
  508. {
  509. if (this.lbxInvoice.OneGridItem == null)
  510. {
  511. this.lbxInvoice.NewItem(ItemType.Grid, false);
  512. }
  513. string name = this.lbxInvoice.OneGridItem.Columns.GeNewColumnName();
  514. this.lbxInvoice.OneGridItem.Columns.Add(name, name);
  515. this.lbxInvoice.Refresh();
  516. }
  517. catch (Exception ex)
  518. {
  519. // 对异常进行共通处理
  520. ExceptionManager.HandleEventException(this.ToString(),
  521. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  522. }
  523. }
  524. /// <summary>
  525. /// 固定列菜单按下,新建列
  526. /// </summary>
  527. /// <param name="sender"></param>
  528. /// <param name="e"></param>
  529. private void tsmiColumn_Click(object sender, EventArgs e)
  530. {
  531. this.tsbtnAddGridColumn_Click(sender, e);
  532. }
  533. /// <summary>
  534. /// 添加图片按钮按下,添加图片项目
  535. /// </summary>
  536. /// <param name="sender"></param>
  537. /// <param name="e"></param>
  538. private void tsbtnAddImage_Click(object sender, EventArgs e)
  539. {
  540. try
  541. {
  542. this.lbxInvoice.NewItem(ItemType.Image, true);
  543. }
  544. catch (Exception ex)
  545. {
  546. // 对异常进行共通处理
  547. ExceptionManager.HandleEventException(this.ToString(),
  548. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  549. }
  550. }
  551. /// <summary>
  552. /// 添加图片菜单按下,添加图片项目
  553. /// </summary>
  554. /// <param name="sender"></param>
  555. /// <param name="e"></param>
  556. private void tsmiImage_Click(object sender, EventArgs e)
  557. {
  558. this.tsbtnAddImage_Click(sender, e);
  559. }
  560. /// <summary>
  561. /// 页码按钮按下,添加页码项目
  562. /// </summary>
  563. /// <param name="sender"></param>
  564. /// <param name="e"></param>
  565. private void tsbtnPageNumber_Click(object sender, EventArgs e)
  566. {
  567. try
  568. {
  569. this.lbxInvoice.NewItem(ItemType.PageNum, true);
  570. }
  571. catch (Exception ex)
  572. {
  573. // 对异常进行共通处理
  574. ExceptionManager.HandleEventException(this.ToString(),
  575. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  576. }
  577. }
  578. /// <summary>
  579. /// 页码菜单按下,,添加页码项目
  580. /// </summary>
  581. /// <param name="sender"></param>
  582. /// <param name="e"></param>
  583. private void tsmiPageNumber_Click(object sender, EventArgs e)
  584. {
  585. this.tsbtnPageNumber_Click(sender, e);
  586. }
  587. /// <summary>
  588. /// 金额按钮按下,添加金额项目
  589. /// </summary>
  590. /// <param name="sender"></param>
  591. /// <param name="e"></param>
  592. private void tsbtnAddAmount_Click(object sender, EventArgs e)
  593. {
  594. try
  595. {
  596. TotalTextItem textItem
  597. = this.lbxInvoice.NewItem(ItemType.TotalText, false) as TotalTextItem;
  598. textItem.ShowItemPropertyDialog();
  599. }
  600. catch (Exception ex)
  601. {
  602. // 对异常进行共通处理
  603. ExceptionManager.HandleEventException(this.ToString(),
  604. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  605. }
  606. }
  607. /// <summary>
  608. /// 金额菜单按下,添加金额项目
  609. /// </summary>
  610. /// <param name="sender"></param>
  611. /// <param name="e"></param>
  612. private void tsmiMoney_Click(object sender, EventArgs e)
  613. {
  614. this.tsbtnAddAmount_Click(sender, e);
  615. }
  616. /// <summary>
  617. /// 纸张尺寸按钮按下,调整纸张尺寸
  618. /// </summary>
  619. /// <param name="sender"></param>
  620. /// <param name="e"></param>
  621. private void tsbtnPaperSize_Click(object sender, EventArgs e)
  622. {
  623. try
  624. {
  625. this.lbxInvoice.ShowPaperPropertyDialog();
  626. }
  627. catch (Exception ex)
  628. {
  629. // 对异常进行共通处理
  630. ExceptionManager.HandleEventException(this.ToString(),
  631. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  632. }
  633. }
  634. /// <summary>
  635. /// 纸张尺寸菜单按下,调整纸张尺寸
  636. /// </summary>
  637. /// <param name="sender"></param>
  638. /// <param name="e"></param>
  639. private void tsmiPaperSize_Click(object sender, EventArgs e)
  640. {
  641. this.tsbtnPaperSize_Click(sender, e);
  642. }
  643. /// <summary>
  644. /// 背景图片按钮按下,添加背景图片
  645. /// </summary>
  646. /// <param name="sender"></param>
  647. /// <param name="e"></param>
  648. private void tsbtnBackgroundImage_Click(object sender, EventArgs e)
  649. {
  650. try
  651. {
  652. this.lbxInvoice.ShowBackgroundSettingDialog();
  653. }
  654. catch (Exception ex)
  655. {
  656. // 对异常进行共通处理
  657. ExceptionManager.HandleEventException(this.ToString(),
  658. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  659. }
  660. }
  661. /// <summary>
  662. /// 背景图片菜单按下,添加背景图片
  663. /// </summary>
  664. /// <param name="sender"></param>
  665. /// <param name="e"></param>
  666. private void tsmiBackgroundImage_Click(object sender, EventArgs e)
  667. {
  668. this.tsbtnBackgroundImage_Click(sender, e);
  669. }
  670. /// <summary>
  671. /// 矩形按钮按下,新建矩形项目
  672. /// </summary>
  673. /// <param name="sender"></param>
  674. /// <param name="e"></param>
  675. private void tsbtnRectangle_Click(object sender, EventArgs e)
  676. {
  677. try
  678. {
  679. this.lbxInvoice.NewItem(ItemType.Rectangle, true);
  680. }
  681. catch (Exception ex)
  682. {
  683. // 对异常进行共通处理
  684. ExceptionManager.HandleEventException(this.ToString(),
  685. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  686. }
  687. }
  688. /// <summary>
  689. /// 矩形菜单按下,新建矩形项目
  690. /// </summary>
  691. /// <param name="sender"></param>
  692. /// <param name="e"></param>
  693. private void tsmiRectangle_Click(object sender, EventArgs e)
  694. {
  695. this.tsbtnRectangle_Click(sender, e);
  696. }
  697. /// <summary>
  698. /// 椭圆按钮按下,新建椭圆项目
  699. /// </summary>
  700. /// <param name="sender"></param>
  701. /// <param name="e"></param>
  702. private void tsbtnCircle_Click(object sender, EventArgs e)
  703. {
  704. try
  705. {
  706. this.lbxInvoice.NewItem(ItemType.Ellipse, true);
  707. }
  708. catch (Exception ex)
  709. {
  710. // 对异常进行共通处理
  711. ExceptionManager.HandleEventException(this.ToString(),
  712. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  713. }
  714. }
  715. /// <summary>
  716. /// 椭圆菜单按下,新建椭圆项目
  717. /// </summary>
  718. /// <param name="sender"></param>
  719. /// <param name="e"></param>
  720. private void tsmiCircular_Click(object sender, EventArgs e)
  721. {
  722. this.tsbtnCircle_Click(sender, e);
  723. }
  724. /// <summary>
  725. /// 项目水平左对齐
  726. /// </summary>
  727. /// <param name="sender"></param>
  728. /// <param name="e"></param>
  729. private void tsbtnAlignmentLeft_Click(object sender, EventArgs e)
  730. {
  731. this.lbxInvoice.ArrangeItemsLeft();
  732. }
  733. /// <summary>
  734. /// 项目水平左对齐
  735. /// </summary>
  736. /// <param name="sender"></param>
  737. /// <param name="e"></param>
  738. private void tsmiAlignmentLeft_Click(object sender, EventArgs e)
  739. {
  740. this.lbxInvoice.ArrangeItemsLeft();
  741. }
  742. /// <summary>
  743. /// 水平居中对齐
  744. /// </summary>
  745. /// <param name="sender"></param>
  746. /// <param name="e"></param>
  747. private void tsbtnAlignmentCenter_Click(object sender, EventArgs e)
  748. {
  749. this.lbxInvoice.ArrangeItemsHorizontalCenter();
  750. }
  751. /// <summary>
  752. /// 水平居中对齐
  753. /// </summary>
  754. /// <param name="sender"></param>
  755. /// <param name="e"></param>
  756. private void tsmiAlignmentCenter_Click(object sender, EventArgs e)
  757. {
  758. this.lbxInvoice.ArrangeItemsHorizontalCenter();
  759. }
  760. /// <summary>
  761. /// 水平右对齐
  762. /// </summary>
  763. /// <param name="sender"></param>
  764. /// <param name="e"></param>
  765. private void tsbtnAlignmentRight_Click(object sender, EventArgs e)
  766. {
  767. this.lbxInvoice.ArrangeItemsRight();
  768. }
  769. /// <summary>
  770. /// 水平右对齐
  771. /// </summary>
  772. /// <param name="sender"></param>
  773. /// <param name="e"></param>
  774. private void tsmiAlignmentRight_Click(object sender, EventArgs e)
  775. {
  776. this.lbxInvoice.ArrangeItemsRight();
  777. }
  778. /// <summary>
  779. /// 垂直顶端对齐
  780. /// </summary>
  781. /// <param name="sender"></param>
  782. /// <param name="e"></param>
  783. private void tsbtnAlignmentTop_Click(object sender, EventArgs e)
  784. {
  785. this.lbxInvoice.ArrangeItemsTop();
  786. }
  787. /// <summary>
  788. /// 垂直顶端对齐
  789. /// </summary>
  790. /// <param name="sender"></param>
  791. /// <param name="e"></param>
  792. private void tsmiAlignmentTop_Click(object sender, EventArgs e)
  793. {
  794. this.lbxInvoice.ArrangeItemsTop();
  795. }
  796. /// <summary>
  797. /// 垂直居中对齐
  798. /// </summary>
  799. /// <param name="sender"></param>
  800. /// <param name="e"></param>
  801. private void tsbtnAlignmentMiddle_Click(object sender, EventArgs e)
  802. {
  803. this.lbxInvoice.ArrangeItemsVerticalCenter();
  804. }
  805. /// <summary>
  806. /// 垂直居中对齐
  807. /// </summary>
  808. /// <param name="sender"></param>
  809. /// <param name="e"></param>
  810. private void tsmiAlignmentMiddle_Click(object sender, EventArgs e)
  811. {
  812. this.lbxInvoice.ArrangeItemsVerticalCenter();
  813. }
  814. /// <summary>
  815. /// 垂直底端对齐
  816. /// </summary>
  817. /// <param name="sender"></param>
  818. /// <param name="e"></param>
  819. private void tsbtnAlignmentBottom_Click(object sender, EventArgs e)
  820. {
  821. this.lbxInvoice.ArrangeItemsBottom();
  822. }
  823. /// <summary>
  824. /// 垂直底端对齐
  825. /// </summary>
  826. /// <param name="sender"></param>
  827. /// <param name="e"></param>
  828. private void tsmiAlignmentBottom_Click(object sender, EventArgs e)
  829. {
  830. this.lbxInvoice.ArrangeItemsBottom();
  831. }
  832. /// <summary>
  833. /// 置于顶层
  834. /// </summary>
  835. /// <param name="sender"></param>
  836. /// <param name="e"></param>
  837. private void tsbtnMoveTop_Click(object sender, EventArgs e)
  838. {
  839. this.lbxInvoice.ChangeItemsOrderForemost();
  840. }
  841. /// <summary>
  842. /// 置于顶层
  843. /// </summary>
  844. /// <param name="sender"></param>
  845. /// <param name="e"></param>
  846. private void tsmiFrontMost_Click(object sender, EventArgs e)
  847. {
  848. this.lbxInvoice.ChangeItemsOrderForemost();
  849. }
  850. /// <summary>
  851. /// 上移一层
  852. /// </summary>
  853. /// <param name="sender"></param>
  854. /// <param name="e"></param>
  855. private void tsbtnMoveFront_Click(object sender, EventArgs e)
  856. {
  857. this.lbxInvoice.ChangeItemsOrderFront();
  858. }
  859. /// <summary>
  860. /// 上移一层
  861. /// </summary>
  862. /// <param name="sender"></param>
  863. /// <param name="e"></param>
  864. private void tsmiFront_Click(object sender, EventArgs e)
  865. {
  866. this.lbxInvoice.ChangeItemsOrderFront();
  867. }
  868. /// <summary>
  869. /// 下移一层
  870. /// </summary>
  871. /// <param name="sender"></param>
  872. /// <param name="e"></param>
  873. private void tsbtnMoveUnder_Click(object sender, EventArgs e)
  874. {
  875. this.lbxInvoice.ChangeItemsOrderBack();
  876. }
  877. /// <summary>
  878. /// 下移一层
  879. /// </summary>
  880. /// <param name="sender"></param>
  881. /// <param name="e"></param>
  882. private void tsmiBack_Click(object sender, EventArgs e)
  883. {
  884. this.lbxInvoice.ChangeItemsOrderBack();
  885. }
  886. /// <summary>
  887. /// 置于底层
  888. /// </summary>
  889. /// <param name="sender"></param>
  890. /// <param name="e"></param>
  891. private void tsbtnMoveBottom_Click(object sender, EventArgs e)
  892. {
  893. this.lbxInvoice.ChangeItemsOrderAftermost();
  894. }
  895. /// <summary>
  896. /// 置于底层
  897. /// </summary>
  898. /// <param name="sender"></param>
  899. /// <param name="e"></param>
  900. private void tsmiBackMost_Click(object sender, EventArgs e)
  901. {
  902. this.lbxInvoice.ChangeItemsOrderAftermost();
  903. }
  904. /// <summary>
  905. /// 详细按钮按下,查看项目详细信息
  906. /// </summary>
  907. /// <param name="sender"></param>
  908. /// <param name="e"></param>
  909. private void tsbtnDetail_Click(object sender, EventArgs e)
  910. {
  911. try
  912. {
  913. this.lbxInvoice.ShowItemPropertyDialog();
  914. }
  915. catch (Exception ex)
  916. {
  917. // 对异常进行共通处理
  918. ExceptionManager.HandleEventException(this.ToString(),
  919. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  920. }
  921. }
  922. /// <summary>
  923. /// 详细菜单按下,查看项目详细信息
  924. /// </summary>
  925. /// <param name="sender"></param>
  926. /// <param name="e"></param>
  927. private void tsmiDetail_Click(object sender, EventArgs e)
  928. {
  929. this.tsbtnDetail_Click(sender, e);
  930. }
  931. #endregion
  932. #region 票据控件事件
  933. /// <summary>
  934. /// 票据显示比率改变
  935. /// </summary>
  936. /// <param name="sender"></param>
  937. /// <param name="e"></param>
  938. private void lbxInvoice_ZoomChanged(object sender, EventArgs e)
  939. {
  940. if (!_zooming)
  941. {
  942. if (lbxInvoice.ZoomType == ZoomType.Whole)
  943. {
  944. cbxMagnification.SelectedIndex = 0;
  945. }
  946. else if (lbxInvoice.Zoom == 500)
  947. {
  948. cbxMagnification.SelectedIndex = 1;
  949. }
  950. else if (lbxInvoice.Zoom == 200)
  951. {
  952. cbxMagnification.SelectedIndex = 2;
  953. }
  954. else if (lbxInvoice.Zoom == 100)
  955. {
  956. cbxMagnification.SelectedIndex = 3;
  957. }
  958. else if (lbxInvoice.Zoom == 75)
  959. {
  960. cbxMagnification.SelectedIndex = 4;
  961. }
  962. else if (lbxInvoice.Zoom == 50)
  963. {
  964. cbxMagnification.SelectedIndex = 5;
  965. }
  966. else if (lbxInvoice.Zoom == 33)
  967. {
  968. cbxMagnification.SelectedIndex = 6;
  969. }
  970. else if (lbxInvoice.Zoom == 25)
  971. {
  972. cbxMagnification.SelectedIndex = 7;
  973. }
  974. else if (lbxInvoice.Zoom == 10)
  975. {
  976. cbxMagnification.SelectedIndex = 8;
  977. }
  978. }
  979. }
  980. /// <summary>
  981. /// 票据纸张尺寸改变
  982. /// </summary>
  983. /// <param name="sender"></param>
  984. /// <param name="e"></param>
  985. private void lbxInvoice_PaperSizeChanged(object sender, EventArgs e)
  986. {
  987. this.txtInvoiceSize.Text = string.Format("{0:0.0}mm×{1:0.0}mm",
  988. lbxInvoice.PaperWidth,
  989. lbxInvoice.PaperHeight);
  990. }
  991. /// <summary>
  992. /// layoutbox控件中项目的选择状态改变
  993. /// </summary>
  994. /// <param name="sender"></param>
  995. /// <param name="e"></param>
  996. private void lbxInvoice_UserSelectionChanged(object sender, EventArgs e)
  997. {
  998. try
  999. {
  1000. if (this._layoutSelectionChanging)
  1001. {
  1002. return;
  1003. }
  1004. this._layoutSelectionChanging = true;
  1005. if (this.lbxInvoice.SelectedItems.Count == 0)
  1006. {
  1007. dgvText.ClearSelection();
  1008. dgvDetail.ClearSelection();
  1009. this._layoutSelectionChanging = false;
  1010. return;
  1011. }
  1012. int textItemID = -1;
  1013. foreach (LayoutItem item in this.lbxInvoice.SelectedItems)
  1014. {
  1015. if (item.ItemType == ItemType.Text ||
  1016. item.ItemType == ItemType.QRcode ||
  1017. item.ItemType == ItemType.Barcode)
  1018. {
  1019. TextItem textItem = item as TextItem;
  1020. if (textItem != null
  1021. )
  1022. {
  1023. textItemID = textItem.ID;
  1024. break;
  1025. }
  1026. }
  1027. else if (item.ItemType == ItemType.TotalText)
  1028. {
  1029. TotalTextItem totalTextItem = item as TotalTextItem;
  1030. if (totalTextItem != null
  1031. )
  1032. {
  1033. textItemID = totalTextItem.ID;
  1034. break;
  1035. }
  1036. }
  1037. }
  1038. if (0 < textItemID)
  1039. {
  1040. int itemID = 0;
  1041. foreach (DataGridViewRow row in this.dgvText.Rows)
  1042. {
  1043. if (!row.IsNewRow)
  1044. {
  1045. itemID = System.Convert.ToInt32(row.Cells["LayoutItemID"].Value);
  1046. if (0 < itemID && textItemID == itemID)
  1047. {
  1048. dgvText.CurrentCell = row.Cells[0];
  1049. break;
  1050. }
  1051. else
  1052. {
  1053. //row.Selected = false;
  1054. }
  1055. }
  1056. else
  1057. {
  1058. //row.Selected = false;
  1059. }
  1060. }
  1061. }
  1062. else
  1063. {
  1064. dgvText.ClearSelection();
  1065. }
  1066. this._layoutSelectionChanging = false;
  1067. }
  1068. catch (Exception ex)
  1069. {
  1070. // 对异常进行共通处理
  1071. ExceptionManager.HandleEventException(this.ToString(),
  1072. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1073. }
  1074. }
  1075. /// <summary>
  1076. /// 改变layoutbox控件中项目的选择状态
  1077. /// </summary>
  1078. /// <param name="sender"></param>
  1079. /// <param name="e"></param>
  1080. private void lbxInvoice_ItemSelectionChanged(object sender, ItemSelectionChangedEventArgs e)
  1081. {
  1082. this.SetLayoutBoxFunctionButtonStatus();
  1083. }
  1084. /// <summary>
  1085. /// 改变layoutbox控件中项目的属性
  1086. /// </summary>
  1087. /// <param name="sender"></param>
  1088. /// <param name="e"></param>
  1089. private void lbxInvoice_ItemChanged(object sender, Dongke.WinForm.Controls.InvoiceLayout.ItemChangedEventArgs e)
  1090. {
  1091. try
  1092. {
  1093. if (e.ChangedType == ItemChangeType.Modified
  1094. && e.Item.ItemType == ItemType.Grid
  1095. && "Columns".Equals(e.Property))
  1096. {
  1097. DataTable layoutItem = this.dgvDetail.DataSource as DataTable;
  1098. DataRow[] drLayoutItems = layoutItem.Select();
  1099. Dongke.WinForm.Controls.InvoiceLayout.GridItem gridItem = e.Item as Dongke.WinForm.Controls.InvoiceLayout.GridItem;
  1100. foreach (DataRow dr in drLayoutItems)
  1101. {
  1102. int colID = Convert.ToInt32(dr["LayoutItemID"]);
  1103. if (!gridItem.Columns.Contains(colID))
  1104. {
  1105. dr.Delete();
  1106. }
  1107. }
  1108. }
  1109. else if (e.ChangedType == ItemChangeType.Deleted
  1110. && e.Item.ItemType == ItemType.Grid)
  1111. {
  1112. DataTable layoutItem = this.dgvDetail.DataSource as DataTable;
  1113. DataRow[] drLayoutItems = layoutItem.Select();
  1114. foreach (DataRow dr in drLayoutItems)
  1115. {
  1116. dr.Delete();
  1117. }
  1118. }
  1119. }
  1120. catch (Exception ex)
  1121. {
  1122. // 对异常进行共通处理
  1123. ExceptionManager.HandleEventException(this.ToString(),
  1124. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1125. }
  1126. }
  1127. /// <summary>
  1128. /// 向layoutbox控件中添加项目
  1129. /// </summary>
  1130. /// <param name="sender"></param>
  1131. /// <param name="e"></param>
  1132. private void lbxInvoice_UserAddedItem(object sender, Dongke.WinForm.Controls.InvoiceLayout.ItemChangedEventArgs e)
  1133. {
  1134. try
  1135. {
  1136. if (e.Item.ItemType == ItemType.Text)
  1137. {
  1138. TextItem textItem = e.Item as TextItem;
  1139. if (textItem != null && !string.IsNullOrEmpty(textItem.ItemCode))
  1140. {
  1141. DataTable layoutItem = this.dgvText.DataSource as DataTable;
  1142. DataRow drLayoutItem = layoutItem.NewRow();
  1143. drLayoutItem["LayoutItemID"] = e.Item.ID;
  1144. drLayoutItem["ItemCode"] = textItem.ItemCode;
  1145. layoutItem.Rows.Add(drLayoutItem);
  1146. }
  1147. }
  1148. else if (e.Item.ItemType == ItemType.TotalText)
  1149. {
  1150. TotalTextItem totalTextItem = e.Item as TotalTextItem;
  1151. if (totalTextItem != null && !string.IsNullOrWhiteSpace(totalTextItem.ItemCode))
  1152. {
  1153. DataTable layoutItem = this.dgvText.DataSource as DataTable;
  1154. DataRow drLayoutItem = layoutItem.NewRow();
  1155. drLayoutItem["LayoutItemID"] = e.Item.ID;
  1156. drLayoutItem["ItemCode"] = totalTextItem.ItemCode;
  1157. layoutItem.Rows.Add(drLayoutItem);
  1158. }
  1159. }
  1160. }
  1161. catch (Exception ex)
  1162. {
  1163. // 对异常进行共通处理
  1164. ExceptionManager.HandleEventException(this.ToString(),
  1165. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1166. }
  1167. }
  1168. #endregion
  1169. #region 票据项目事件
  1170. /// <summary>
  1171. /// 文本项目DataGridView项目获得焦点事件
  1172. /// </summary>
  1173. /// <param name="sender"></param>
  1174. /// <param name="e"></param>
  1175. private void dgvText_CellEnter(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
  1176. {
  1177. try
  1178. {
  1179. C_DataGridView dataGridView = sender as C_DataGridView;
  1180. if (dataGridView != null && !dataGridView.Rows[dataGridView.CurrentCell.RowIndex].IsNewRow)
  1181. {
  1182. dataGridView.CurrentRow.ReadOnly = true;
  1183. }
  1184. }
  1185. catch (Exception ex)
  1186. {
  1187. // 对异常进行共通处理
  1188. ExceptionManager.HandleEventException(this.ToString(),
  1189. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1190. }
  1191. }
  1192. /// <summary>
  1193. /// 文本项目DataGridView项目选择内容之后事件
  1194. /// </summary>
  1195. /// <param name="sender"></param>
  1196. /// <param name="e"></param>
  1197. private void dgvText_CellValueChanged(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
  1198. {
  1199. try
  1200. {
  1201. C_DataGridView dataGridView = sender as C_DataGridView;
  1202. if (dataGridView == null || dataGridView.CurrentCell == null
  1203. || !string.IsNullOrEmpty(dataGridView.Rows[dataGridView
  1204. .CurrentCell.RowIndex].Cells["LayoutItemID"].Value + ""))
  1205. {
  1206. return;
  1207. }
  1208. if (!dataGridView.CurrentCell.ReadOnly)
  1209. {
  1210. ComboBox comboBox = dataGridView.EditingControl as ComboBox;
  1211. if (comboBox == null || comboBox.SelectedIndex < 0)
  1212. {
  1213. return;
  1214. }
  1215. DataRowView dataRowView = (dataGridView.EditingControl as ComboBox).SelectedItem as DataRowView;
  1216. // 当Item是金额时,使用金额TotalTextItem
  1217. if (Convert.ToInt32(ItemStyle.TotalText) == System.Convert.ToInt32(dataRowView["ItemStyle"]))
  1218. {
  1219. TotalTextItem totalTextItem = this.lbxInvoice.NewItem(ItemType.TotalText, false) as TotalTextItem;
  1220. if (totalTextItem != null)
  1221. {
  1222. totalTextItem.DataMember = dataRowView["ControlCode"].ToString();
  1223. totalTextItem.DisplayValue = dataRowView["ItemSample"].ToString();
  1224. totalTextItem.ItemCode = dataRowView["ItemCode"].ToString();
  1225. totalTextItem.TextItemName = dataRowView["ItemName"].ToString();
  1226. totalTextItem.ItemSample = dataRowView["ItemSample"].ToString();
  1227. totalTextItem.ItemStyle = (ItemStyle)System.Convert.ToInt32(dataRowView["ItemStyle"]);
  1228. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["LayoutItemID"].Value = totalTextItem.ID;
  1229. // 增加票据项目编码
  1230. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["ItemCode"].Value = dataRowView["ItemCode"].ToString();
  1231. totalTextItem.ShowItemPropertyDialog();
  1232. }
  1233. else
  1234. {
  1235. dgvText.Rows.RemoveAt(e.RowIndex);
  1236. }
  1237. }
  1238. // 当Item是线性图时 xuwei add 2024-04-12 ===========================================
  1239. else if (Convert.ToInt32(ItemStyle.LinearGraph) == System.Convert.ToInt32(dataRowView["ItemStyle"]))
  1240. {
  1241. TextItem textItem = lbxInvoice.NewItem(ItemType.LinearGraph, false) as TextItem;
  1242. if (textItem != null)
  1243. {
  1244. textItem.DataMember = dataRowView["ControlCode"].ToString();
  1245. textItem.DisplayValue = dataRowView["ItemSample"].ToString();
  1246. textItem.ItemCode = dataRowView["ItemCode"].ToString();
  1247. textItem.TextItemName = dataRowView["ItemName"].ToString();
  1248. textItem.ItemSample = dataRowView["ItemSample"].ToString();
  1249. textItem.ItemStyle = (ItemStyle)System.Convert.ToInt32(dataRowView["ItemStyle"]);
  1250. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["LayoutItemID"].Value = textItem.ID;
  1251. // 增加票据项目编码
  1252. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["ItemCode"].Value = dataRowView["ItemCode"].ToString();
  1253. textItem.ShowItemPropertyDialog();
  1254. }
  1255. else
  1256. {
  1257. dgvText.Rows.RemoveAt(e.RowIndex);
  1258. }
  1259. }
  1260. //xuwei end =============================================
  1261. // 当Item是条形码时
  1262. else if (Convert.ToInt32(ItemStyle.Barcode) == System.Convert.ToInt32(dataRowView["ItemStyle"]))
  1263. {
  1264. TextItem textItem = lbxInvoice.NewItem(ItemType.Barcode, false) as TextItem;
  1265. if (textItem != null)
  1266. {
  1267. textItem.DataMember = dataRowView["ControlCode"].ToString();
  1268. textItem.DisplayValue = dataRowView["ItemSample"].ToString();
  1269. textItem.ItemCode = dataRowView["ItemCode"].ToString();
  1270. textItem.TextItemName = dataRowView["ItemName"].ToString();
  1271. textItem.ItemSample = dataRowView["ItemSample"].ToString();
  1272. textItem.ItemStyle = (ItemStyle)System.Convert.ToInt32(dataRowView["ItemStyle"]);
  1273. if (textItem.ItemCode == "ZWLJC")
  1274. {
  1275. textItem.BarcodeFormat = "EAN_13";
  1276. }
  1277. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["LayoutItemID"].Value = textItem.ID;
  1278. // 增加票据项目编码
  1279. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["ItemCode"].Value = dataRowView["ItemCode"].ToString();
  1280. textItem.ShowItemPropertyDialog();
  1281. }
  1282. else
  1283. {
  1284. dgvText.Rows.RemoveAt(e.RowIndex);
  1285. }
  1286. }
  1287. // 当Item是二维码时
  1288. else if (Convert.ToInt32(ItemStyle.QRCode) == System.Convert.ToInt32(dataRowView["ItemStyle"]))
  1289. {
  1290. TextItem textItem = lbxInvoice.NewItem(ItemType.QRcode, false) as TextItem;
  1291. if (textItem != null)
  1292. {
  1293. textItem.DataMember = dataRowView["ControlCode"].ToString();
  1294. textItem.DisplayValue = dataRowView["ItemSample"].ToString();
  1295. textItem.ItemCode = dataRowView["ItemCode"].ToString();
  1296. textItem.TextItemName = dataRowView["ItemName"].ToString();
  1297. textItem.ItemSample = dataRowView["ItemSample"].ToString();
  1298. textItem.ItemStyle = (ItemStyle)System.Convert.ToInt32(dataRowView["ItemStyle"]);
  1299. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["LayoutItemID"].Value = textItem.ID;
  1300. // 增加票据项目编码
  1301. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["ItemCode"].Value = dataRowView["ItemCode"].ToString();
  1302. textItem.ShowItemPropertyDialog();
  1303. }
  1304. else
  1305. {
  1306. dgvText.Rows.RemoveAt(e.RowIndex);
  1307. }
  1308. }
  1309. else
  1310. {
  1311. TextItem textItem = lbxInvoice.NewItem(ItemType.Text, false) as TextItem;
  1312. if (textItem != null)
  1313. {
  1314. textItem.DataMember = dataRowView["ControlCode"].ToString();
  1315. textItem.DisplayValue = dataRowView["ItemSample"].ToString();
  1316. textItem.ItemCode = dataRowView["ItemCode"].ToString();
  1317. textItem.TextItemName = dataRowView["ItemName"].ToString();
  1318. textItem.ItemSample = dataRowView["ItemSample"].ToString();
  1319. textItem.ItemStyle = (ItemStyle)System.Convert.ToInt32(dataRowView["ItemStyle"]);
  1320. if (textItem.ItemStyle == ItemStyle.Date)
  1321. {
  1322. textItem.Format = "yyyy-MM-dd";
  1323. textItem.Culture = "en-US";
  1324. }
  1325. else if (textItem.ItemStyle == ItemStyle.Sign)
  1326. {
  1327. textItem.Format = "√";
  1328. }
  1329. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["LayoutItemID"].Value = textItem.ID;
  1330. // 增加票据项目编码
  1331. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["ItemCode"].Value = dataRowView["ItemCode"].ToString();
  1332. textItem.ShowItemPropertyDialog();
  1333. }
  1334. else
  1335. {
  1336. dgvText.Rows.RemoveAt(e.RowIndex);
  1337. }
  1338. }
  1339. }
  1340. }
  1341. catch (Exception ex)
  1342. {
  1343. // 对异常进行共通处理
  1344. ExceptionManager.HandleEventException(this.ToString(),
  1345. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1346. }
  1347. }
  1348. /// <summary>
  1349. /// 改变文本grid选择状态
  1350. /// </summary>
  1351. /// <param name="sender"></param>
  1352. /// <param name="e"></param>
  1353. private void dgvText_SelectionChanged(object sender, EventArgs e)
  1354. {
  1355. try
  1356. {
  1357. if (this._layoutSelectionChanging || this.lbxInvoice.ItemSelectionChanging)
  1358. {
  1359. return;
  1360. }
  1361. this._layoutSelectionChanging = true;
  1362. // 取消选择
  1363. if (this.dgvText.SelectedRows.Count == 0
  1364. || (this.dgvText.SelectedRows.Count == 1
  1365. && this.dgvText.SelectedRows[0].IsNewRow))
  1366. {
  1367. this.lbxInvoice.ClearSelection();
  1368. this._layoutSelectionChanging = false;
  1369. return;
  1370. }
  1371. foreach (DataGridViewRow row in dgvText.SelectedRows)
  1372. {
  1373. if (!row.IsNewRow)
  1374. {
  1375. int itemID = System.Convert.ToInt32(row.Cells["LayoutItemID"].Value);
  1376. if (0 < itemID)
  1377. {
  1378. LayoutItem layoutItem = this.lbxInvoice.GetItem(itemID);
  1379. if (layoutItem != null)
  1380. {
  1381. this.lbxInvoice.SelectItemSingle(layoutItem, row.Selected);
  1382. }
  1383. }
  1384. }
  1385. }
  1386. this._layoutSelectionChanging = false;
  1387. }
  1388. catch (Exception ex)
  1389. {
  1390. this._layoutSelectionChanging = false;
  1391. // 对异常进行共通处理
  1392. ExceptionManager.HandleEventException(this.ToString(),
  1393. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1394. }
  1395. }
  1396. /// <summary>
  1397. /// 删除文本grid中的一行
  1398. /// </summary>
  1399. /// <param name="sender"></param>
  1400. /// <param name="e"></param>
  1401. private void dgvText_UserDeletingRow(object sender, System.Windows.Forms.DataGridViewRowCancelEventArgs e)
  1402. {
  1403. try
  1404. {
  1405. C_DataGridView dataGridView = sender as C_DataGridView;
  1406. int itemID = System.Convert.ToInt32(e.Row.Cells["LayoutItemID"].Value);
  1407. DataRowView dataRowView = e.Row.DataBoundItem as DataRowView;
  1408. if (0 < itemID)
  1409. {
  1410. if (4 == System.Convert.ToInt32(dataRowView["ItemStyle"]))
  1411. {
  1412. TotalTextItem totalTextItem = this.lbxInvoice.GetItem(itemID) as TotalTextItem;
  1413. this.lbxInvoice.DeletetItem(totalTextItem);
  1414. }
  1415. else
  1416. {
  1417. TextItem textItem = this.lbxInvoice.GetItem(itemID) as TextItem;
  1418. this.lbxInvoice.DeletetItem(textItem);
  1419. }
  1420. }
  1421. }
  1422. catch (Exception ex)
  1423. {
  1424. // 对异常进行共通处理
  1425. ExceptionManager.HandleEventException(this.ToString(),
  1426. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1427. }
  1428. }
  1429. /// <summary>
  1430. /// 列表DataGridView项目选择内容之后事件
  1431. /// </summary>
  1432. /// <param name="sender"></param>
  1433. /// <param name="e"></param>
  1434. private void dgvDetail_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1435. {
  1436. try
  1437. {
  1438. if (this.dgvDetail == null || this.dgvDetail.CurrentCell == null
  1439. || !string.IsNullOrEmpty(this.dgvDetail.Rows[this.dgvDetail
  1440. .CurrentCell.RowIndex].Cells["LayoutGridItemID"].Value + ""))
  1441. {
  1442. return;
  1443. }
  1444. TextItem textItem = lbxInvoice.NewItem(ItemType.Text, false) as TextItem;
  1445. if (textItem != null)
  1446. {
  1447. DataRowView dataRowView = (this.dgvDetail.EditingControl as ComboBox).SelectedItem as DataRowView;
  1448. this.dgvDetail.Rows[this.dgvDetail.CurrentCell.RowIndex].Cells["LayoutGridItemID"].Value = textItem.ID;
  1449. // 增加票据项目编码
  1450. this.dgvDetail.Rows[this.dgvDetail.CurrentCell.RowIndex].Cells["ItemCodeDetail"].Value
  1451. = dataRowView["ItemCode"].ToString();
  1452. }
  1453. else
  1454. {
  1455. dgvText.Rows.RemoveAt(e.RowIndex);
  1456. }
  1457. }
  1458. catch (Exception ex)
  1459. {
  1460. // 对异常进行共通处理
  1461. ExceptionManager.HandleEventException(this.ToString(),
  1462. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1463. }
  1464. }
  1465. /// <summary>
  1466. /// 列表项目DataGridView项目获得焦点事件
  1467. /// </summary>
  1468. /// <param name="sender"></param>
  1469. /// <param name="e"></param>
  1470. private void dgvDetail_CellEnter(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
  1471. {
  1472. try
  1473. {
  1474. C_DataGridView dataGridView = sender as C_DataGridView;
  1475. if (dataGridView != null && !dataGridView.Rows[dataGridView.CurrentCell.RowIndex].IsNewRow)
  1476. {
  1477. dataGridView.CurrentRow.ReadOnly = true;
  1478. }
  1479. }
  1480. catch (Exception ex)
  1481. {
  1482. // 对异常进行共通处理
  1483. ExceptionManager.HandleEventException(this.ToString(),
  1484. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1485. }
  1486. }
  1487. /// <summary>
  1488. /// 列表项目DataGridView项目选择内容之后事件
  1489. /// </summary>
  1490. /// <param name="sender"></param>
  1491. /// <param name="e"></param>
  1492. private void dgvDetail_CellValidated(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
  1493. {
  1494. try
  1495. {
  1496. // 取得当前DataGridView的当前单元格
  1497. C_DataGridView dataGridView = sender as C_DataGridView;
  1498. // 当前单元格是新建单元格
  1499. if (!dataGridView.CurrentCell.ReadOnly)
  1500. {
  1501. ComboBox comboBox = dataGridView.EditingControl as ComboBox;
  1502. if (comboBox == null || comboBox.SelectedIndex < 0)
  1503. {
  1504. return;
  1505. }
  1506. // 取得当前行的信息
  1507. DataRowView dataRowView = (dataGridView.EditingControl as ComboBox).SelectedItem as DataRowView;
  1508. Dongke.WinForm.Controls.InvoiceLayout.GridItem gridItem = this.lbxInvoice.OneGridItem;
  1509. // 如果当前选中的项目中没有Grid,则自动生成一个新的Grid
  1510. if (gridItem == null)
  1511. {
  1512. gridItem = this.lbxInvoice.NewItem(ItemType.Grid, false) as Dongke.WinForm.Controls.InvoiceLayout.GridItem;
  1513. }
  1514. // 生成新的Grid之后,赋值,在票据控件上显示
  1515. if (gridItem != null)
  1516. {
  1517. GridItemColumn gridItemColumn
  1518. = new GridItemColumn(gridItem.Columns.GeNewColumnName(), dataRowView["ItemName"].ToString());
  1519. gridItemColumn.DataPropertyName = dataRowView["ControlCode"].ToString();
  1520. gridItemColumn.DisplayValue = dataRowView["ItemSample"].ToString();
  1521. gridItemColumn.ItemStyle = (ItemStyle)System.Convert.ToInt32(dataRowView["ItemStyle"]);
  1522. if (gridItemColumn.ItemStyle == ItemStyle.Date)
  1523. {
  1524. gridItemColumn.Format = "yyyy/MM/dd";
  1525. gridItemColumn.Culture = "en-US";
  1526. }
  1527. else if (gridItemColumn.ItemStyle == ItemStyle.Sign)
  1528. {
  1529. gridItemColumn.Format = "√";
  1530. }
  1531. else if (gridItemColumn.ItemStyle == ItemStyle.Barcode)
  1532. {
  1533. gridItemColumn.PicColumn = true;
  1534. }
  1535. gridItem.Columns.Add(gridItemColumn);
  1536. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["LayoutGridItemID"].Value = gridItemColumn.ID;
  1537. this.lbxInvoice.Refresh();
  1538. }
  1539. }
  1540. }
  1541. catch (Exception ex)
  1542. {
  1543. // 对异常进行共通处理
  1544. ExceptionManager.HandleEventException(this.ToString(),
  1545. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1546. }
  1547. }
  1548. /// <summary>
  1549. /// 改变列表grid选择状态
  1550. /// </summary>
  1551. /// <param name="sender"></param>
  1552. /// <param name="e"></param>
  1553. private void dgvDetail_SelectionChanged(object sender, EventArgs e)
  1554. {
  1555. try
  1556. {
  1557. if (this._layoutSelectionChanging || this.lbxInvoice.ItemSelectionChanging)
  1558. {
  1559. return;
  1560. }
  1561. this._layoutSelectionChanging = true;
  1562. // 取消选择
  1563. if (this.dgvDetail.SelectedRows.Count == 0 || this.lbxInvoice.OneGridItem == null)
  1564. {
  1565. this.lbxInvoice.ClearSelection();
  1566. this._layoutSelectionChanging = false;
  1567. return;
  1568. }
  1569. this.lbxInvoice.SelectItemSingle(this.lbxInvoice.OneGridItem, true);
  1570. this._layoutSelectionChanging = false;
  1571. }
  1572. catch (Exception ex)
  1573. {
  1574. this._layoutSelectionChanging = false;
  1575. // 对异常进行共通处理
  1576. ExceptionManager.HandleEventException(this.ToString(),
  1577. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1578. }
  1579. }
  1580. /// <summary>
  1581. /// 删除列表grid中的一行
  1582. /// </summary>
  1583. /// <param name="sender"></param>
  1584. /// <param name="e"></param>
  1585. private void dgvDetail_UserDeletingRow(object sender, System.Windows.Forms.DataGridViewRowCancelEventArgs e)
  1586. {
  1587. try
  1588. {
  1589. if (this.lbxInvoice.OneGridItem == null)
  1590. {
  1591. return;
  1592. }
  1593. int itemID = System.Convert.ToInt32(e.Row.Cells["LayoutGridItemID"].Value);
  1594. if (0 < itemID)
  1595. {
  1596. this.lbxInvoice.OneGridItem.Columns.RemoveAtByID(itemID);
  1597. }
  1598. }
  1599. catch (Exception ex)
  1600. {
  1601. // 对异常进行共通处理
  1602. ExceptionManager.HandleEventException(this.ToString(),
  1603. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1604. }
  1605. }
  1606. #endregion
  1607. #endregion
  1608. #region 私有方法/函数
  1609. /// <summary>
  1610. /// 初始化LayoutBox样式及数据
  1611. /// </summary>
  1612. private void InitLayoutBoxStyle()
  1613. {
  1614. // 编辑的状况下加载票据格式数据
  1615. if (this._invoiceLayoutID == 0)
  1616. {
  1617. this.lbxInvoice.SetPaperAreaSize(_paperWidth, _paperHeight);
  1618. }
  1619. this.txtInvoiceSize.Text = string.Format("{0:0}mm×{1:0}mm",
  1620. lbxInvoice.PaperWidth,
  1621. lbxInvoice.PaperHeight);
  1622. }
  1623. /// <summary>
  1624. /// 只有当票据选择了一个以上的项目该功能才可用
  1625. /// </summary>
  1626. /// <param name="status">可用/不可用</param>
  1627. private void SetLayoutBoxFunctionButtonStatus()
  1628. {
  1629. // 复制、剪切、删除
  1630. this.tsmiCut.Enabled = (this.lbxInvoice.SelectedItems.Count > 0);
  1631. this.tsmiCopy.Enabled = this.tsmiCut.Enabled;
  1632. this.tsmiDelete.Enabled = this.tsmiCut.Enabled;
  1633. this.tsbtnCut.Enabled = this.tsmiCut.Enabled;
  1634. this.tsbtnCopy.Enabled = this.tsmiCut.Enabled;
  1635. this.tsbtnDelete.Enabled = this.tsmiCut.Enabled;
  1636. // 详细或者移动
  1637. this.tsmiDetail.Enabled = (this.lbxInvoice.SelectedItems.Count == 1);
  1638. this.tsbtnDetail.Enabled = this.tsmiDetail.Enabled;
  1639. this.tsmiFrontMost.Enabled = this.tsmiDetail.Enabled;
  1640. this.tsmiFront.Enabled = this.tsmiDetail.Enabled;
  1641. this.tsmiBack.Enabled = this.tsmiDetail.Enabled;
  1642. this.tsmiBackMost.Enabled = this.tsmiDetail.Enabled;
  1643. this.tsbtnMoveTop.Enabled = this.tsmiDetail.Enabled;
  1644. this.tsbtnMoveFront.Enabled = this.tsmiDetail.Enabled;
  1645. this.tsbtnMoveUnder.Enabled = this.tsmiDetail.Enabled;
  1646. this.tsbtnMoveBottom.Enabled = this.tsmiDetail.Enabled;
  1647. // 对齐按钮或者菜单
  1648. this.tsbtnAlignmentLeft.Enabled = (this.lbxInvoice.SelectedItems.Count > 1);
  1649. this.tsbtnAlignmentLeft.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1650. this.tsbtnAlignmentCenter.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1651. this.tsbtnAlignmentRight.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1652. this.tsbtnAlignmentTop.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1653. this.tsbtnAlignmentMiddle.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1654. this.tsbtnAlignmentBottom.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1655. this.tsmiAlignmentLeft.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1656. this.tsmiAlignmentCenter.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1657. this.tsmiAlignmentRight.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1658. this.tsmiAlignmentTop.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1659. this.tsmiAlignmentMiddle.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1660. this.tsmiAlignmentBottom.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1661. // 粘贴按钮或者菜单
  1662. this.tsmiPaste.Enabled = Clipboard.ContainsData(this.lbxInvoice.ClipboardFormat.Name);
  1663. this.tsbtnPaste.Enabled = Clipboard.ContainsData(this.lbxInvoice.ClipboardFormat.Name);
  1664. }
  1665. /// <summary>
  1666. /// 为票据设定的项目列表赋值
  1667. /// </summary>
  1668. private void SetLayoutGridDataSource()
  1669. {
  1670. try
  1671. {
  1672. ServiceResultEntity sre = GetInvoiceData();
  1673. DataSet LayoutDataSet = sre.Data;
  1674. if (LayoutDataSet != null && LayoutDataSet.Tables.Count > 1)
  1675. {
  1676. _invoiceLayoutDataTable = LayoutDataSet.Tables[0];
  1677. //DataTable tempTable = LayoutDataSet.Tables[1].Clone();
  1678. //DataTable tempDetailTable = LayoutDataSet.Tables[1].Clone();
  1679. //// 文本数据赋值
  1680. //DataRow[] invoiceItemRow = LayoutDataSet.Tables[1].Copy().Select("ItemType = 0");
  1681. //for (int i = 0; i < invoiceItemRow.Length; i++)
  1682. //{
  1683. // tempTable.ImportRow(invoiceItemRow[i]);
  1684. //}
  1685. this.dgvText.DataSource = LayoutDataSet.Tables[1];
  1686. //// 列表项目赋值
  1687. //invoiceItemRow = LayoutDataSet.Tables[1].Copy().Select("ItemType = 1");
  1688. //for (int i = 0; i < invoiceItemRow.Length; i++)
  1689. //{
  1690. // tempDetailTable.ImportRow(invoiceItemRow[i]);
  1691. //}
  1692. //this.dgvDetail.DataSource = tempDetailTable;
  1693. // 编辑的状况下加载票据格式数据
  1694. if (this._invoiceLayoutID != 0)
  1695. {
  1696. if (1 == LayoutDataSet.Tables[0].Rows.Count)
  1697. {
  1698. this.txtGoodsType.Text = LayoutDataSet.Tables[0].Rows[0]["goodstypename"].ToString() + "【" + LayoutDataSet.Tables[0].Rows[0]["goodstypecode"].ToString() + "】";
  1699. this.txtInvoiceName.Text = LayoutDataSet.Tables[0].Rows[0]["LayoutName"].ToString();
  1700. this.Text = string.Format(F_MST_012001.TITLE_F_MST_012002_EDIT, this.txtInvoiceName.Text.Trim());
  1701. this.txtRemarks.Text = LayoutDataSet.Tables[0].Rows[0]["Remarks"].ToString();
  1702. this.txtLogo.Text = LayoutDataSet.Tables[0].Rows[0]["LogoName"].ToString();
  1703. this._goodstypeid = Convert.ToInt32(LayoutDataSet.Tables[0].Rows[0]["goodstypeid"]);
  1704. this._goodstypeCode = LayoutDataSet.Tables[0].Rows[0]["goodstypecode"].ToString();
  1705. this._goodstypeName = LayoutDataSet.Tables[0].Rows[0]["goodstypename"].ToString();
  1706. object objLogoID = LayoutDataSet.Tables[0].Rows[0]["logoid"];
  1707. if (objLogoID != null && objLogoID != DBNull.Value)
  1708. {
  1709. this._logoid = Convert.ToInt32(objLogoID);
  1710. }
  1711. else
  1712. {
  1713. this._logoid = null;
  1714. }
  1715. byte[] bytes = LayoutDataSet.Tables[0].Rows[0]["LayoutData"] as byte[];
  1716. if (bytes != null)
  1717. {
  1718. this.lbxInvoice.ReadLayout(bytes);
  1719. }
  1720. }
  1721. this.tsbtnSaveAs.Enabled = true;
  1722. this.tsmiSaveAs.Enabled = true;
  1723. }
  1724. else
  1725. {
  1726. this.tsbtnSaveAs.Enabled = false;
  1727. this.tsmiSaveAs.Enabled = false;
  1728. }
  1729. }
  1730. }
  1731. catch (Exception ex)
  1732. {
  1733. throw ex;
  1734. }
  1735. }
  1736. /// <summary>
  1737. /// 设定保存票据主信息的DataTable
  1738. /// </summary>
  1739. /// <param name="saveDataSet"></param>
  1740. private void SetSaveLayoutData(ref DataSet saveDataSet, int layoutID)
  1741. {
  1742. try
  1743. {
  1744. DataTable layout = _invoiceLayoutDataTable.Copy();
  1745. byte[] bytes = this.lbxInvoice.WriteLayout();
  1746. if (0 < layoutID)
  1747. {
  1748. if (layout != null && layout.Rows.Count > 0)
  1749. {
  1750. // 新建后转成编辑模式,但是数据源中无id
  1751. layout.Rows[0]["layoutid"] = layoutID;
  1752. if (bytes != null)
  1753. {
  1754. layout.Rows[0]["LayoutData"] = bytes;
  1755. }
  1756. layout.Rows[0]["Width"] = lbxInvoice.PaperWidth;
  1757. layout.Rows[0]["Height"] = lbxInvoice.PaperHeight;
  1758. }
  1759. }
  1760. else
  1761. {
  1762. DataRow tempDataRow = layout.NewRow();
  1763. tempDataRow["layoutid"] = 0;
  1764. tempDataRow["LayoutName"] = this.txtInvoiceName.Text.Trim();
  1765. if (bytes != null)
  1766. {
  1767. tempDataRow["LayoutData"] = bytes;
  1768. }
  1769. tempDataRow["logoid"] = (this._logoid.HasValue ? (object)this._logoid.Value : DBNull.Value);
  1770. tempDataRow["goodstypeid"] = this._goodstypeid;
  1771. tempDataRow["goodstypecode"] = this._goodstypeCode;
  1772. tempDataRow["goodstypename"] = this._goodstypeName;
  1773. tempDataRow["Width"] = lbxInvoice.PaperWidth;
  1774. tempDataRow["Height"] = lbxInvoice.PaperHeight;
  1775. tempDataRow["Remarks"] = this.txtRemarks.Text.Trim();
  1776. //xuwei add 2019-11-20
  1777. tempDataRow["PrintType"] = this._printType;
  1778. layout.Rows.Clear();
  1779. layout.Rows.Add(tempDataRow);
  1780. }
  1781. saveDataSet.Tables.Add(layout);
  1782. }
  1783. catch (Exception ex)
  1784. {
  1785. throw ex;
  1786. }
  1787. }
  1788. /// <summary>
  1789. /// 另存为时,设定保存票据主信息的DataTable
  1790. /// </summary>
  1791. /// <param name="saveDataSet"></param>
  1792. private void SetSaveAsLayoutData(ref DataSet saveDataSet, int layoutID)
  1793. {
  1794. try
  1795. {
  1796. byte[] bytes = this.lbxInvoice.WriteLayout();
  1797. _invoiceLayoutDataTable.Rows[0]["InvoiceLayoutName"] = this.txtInvoiceName.Text.Trim();
  1798. if (bytes != null)
  1799. {
  1800. _invoiceLayoutDataTable.Rows[0]["InvoiceLayoutData"] = bytes;
  1801. }
  1802. //_invoiceLayoutDataTable.Rows[0]["InvoiceCode"] = this.cbxInvoiceType.SelectedValue;
  1803. //_invoiceLayoutDataTable.Rows[0]["OrganizationID"] = this.sbxOrganization.SearchedValue;
  1804. //_invoiceLayoutDataTable.Rows[0]["OrganizationCode"] = this.OrganizationCode;
  1805. //_invoiceLayoutDataTable.Rows[0]["OrganizationName"] = this.sbxOrganization.Text;
  1806. //_invoiceLayoutDataTable.Rows[0]["Width"] = lbxInvoice.PaperWidth;
  1807. //_invoiceLayoutDataTable.Rows[0]["Height"] = lbxInvoice.PaperHeight;
  1808. saveDataSet.Tables.Add(_invoiceLayoutDataTable.Copy());
  1809. }
  1810. catch (Exception ex)
  1811. {
  1812. throw ex;
  1813. }
  1814. }
  1815. /// <summary>
  1816. /// 设定保存票据项目的DataTable
  1817. /// </summary>
  1818. /// <param name="saveDataSet"></param>
  1819. private void SetSaveLayoutItemData(ref DataSet saveDataSet)
  1820. {
  1821. try
  1822. {
  1823. DataTable textDataTable = (DataTable)this.dgvText.DataSource;
  1824. //DataTable itemDataTable = (DataTable)this.dgvDetail.DataSource;
  1825. //DataTable tempDataTable = textDataTable.Clone();
  1826. //for (int i = 0; i < textDataTable.Rows.Count; i++)
  1827. //{
  1828. // if (textDataTable.Rows[i].RowState == DataRowState.Deleted
  1829. // || textDataTable.Rows[i].RowState == DataRowState.Detached)
  1830. // {
  1831. // continue;
  1832. // }
  1833. // textDataTable.Rows[i]["ItemType"] = 0;
  1834. //}
  1835. //for (int i = 0; i < itemDataTable.Rows.Count; i++)
  1836. //{
  1837. // if (itemDataTable.Rows[i].RowState == DataRowState.Deleted
  1838. // || itemDataTable.Rows[i].RowState == DataRowState.Detached)
  1839. // {
  1840. // continue;
  1841. // }
  1842. // itemDataTable.Rows[i]["ItemType"] = 1;
  1843. //}
  1844. //DataRow[] invoiceItemRow = textDataTable.Copy().Select("ItemType = 0");
  1845. //for (int i = 0; i < invoiceItemRow.Length; i++)
  1846. //{
  1847. // tempDataTable.ImportRow(invoiceItemRow[i]);
  1848. //}
  1849. //invoiceItemRow = itemDataTable.Copy().Select("ItemType = 1");
  1850. //for (int i = 0; i < invoiceItemRow.Length; i++)
  1851. //{
  1852. // tempDataTable.ImportRow(invoiceItemRow[i]);
  1853. //}
  1854. saveDataSet.Tables.Add(textDataTable.Copy());
  1855. }
  1856. catch (Exception ex)
  1857. {
  1858. throw ex;
  1859. }
  1860. }
  1861. /// <summary>
  1862. /// 根据票据格式ID取得票据数据及票据项目数据
  1863. /// </summary>
  1864. /// <returns></returns>
  1865. private ServiceResultEntity GetInvoiceData()
  1866. {
  1867. try
  1868. {
  1869. this._clientRequestEntity = new ClientRequestEntity();
  1870. this._clientRequestEntity.NameSpace = "InvoiceLayout";
  1871. this._clientRequestEntity.Name = "GetBarCodePrintLayout";
  1872. this._clientRequestEntity.Properties["LayoutID"] = _invoiceLayoutID;
  1873. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  1874. }
  1875. catch (Exception ex)
  1876. {
  1877. throw ex;
  1878. }
  1879. }
  1880. /// <summary>
  1881. /// 保存新建票据数据
  1882. /// </summary>
  1883. /// <returns>
  1884. /// 0:保存失败
  1885. /// 其他:保存成功返回新建票据ID
  1886. /// </returns>
  1887. private ServiceResultEntity SaveAddLayoutData()
  1888. {
  1889. try
  1890. {
  1891. this._clientRequestEntity = new ClientRequestEntity();
  1892. this._clientRequestEntity.NameSpace = "InvoiceLayout";
  1893. this._clientRequestEntity.Name = "SaveAddBarCodePrintLayoutData";
  1894. this._clientRequestEntity.Data = _saveData;
  1895. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  1896. }
  1897. catch (Exception ex)
  1898. {
  1899. throw ex;
  1900. }
  1901. }
  1902. /// <summary>
  1903. /// 保存编辑票据数据
  1904. /// </summary>
  1905. /// <returns>更新数据时影响的行数</returns>
  1906. private ServiceResultEntity SaveEditLayoutData()
  1907. {
  1908. try
  1909. {
  1910. this._clientRequestEntity = new ClientRequestEntity();
  1911. this._clientRequestEntity.NameSpace = "InvoiceLayout";
  1912. this._clientRequestEntity.Name = "SaveEditBarCodePrintLayoutData";
  1913. this._clientRequestEntity.Data = _saveData;
  1914. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  1915. }
  1916. catch (Exception ex)
  1917. {
  1918. throw ex;
  1919. }
  1920. }
  1921. #endregion
  1922. private void tsmiBarcode_Click(object sender, EventArgs e)
  1923. {
  1924. try
  1925. {
  1926. TextItem newTextItem = this.lbxInvoice.NewItem(ItemType.Barcode, true) as TextItem;
  1927. if (newTextItem != null)
  1928. {
  1929. newTextItem.DataMember = string.Empty;
  1930. }
  1931. }
  1932. catch (Exception ex)
  1933. {
  1934. // 对异常进行共通处理
  1935. ExceptionManager.HandleEventException(this.ToString(),
  1936. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1937. }
  1938. }
  1939. private void tsmiQRcode_Click(object sender, EventArgs e)
  1940. {
  1941. try
  1942. {
  1943. TextItem newTextItem = this.lbxInvoice.NewItem(ItemType.QRcode, true) as TextItem;
  1944. if (newTextItem != null)
  1945. {
  1946. newTextItem.DataMember = string.Empty;
  1947. }
  1948. }
  1949. catch (Exception ex)
  1950. {
  1951. // 对异常进行共通处理
  1952. ExceptionManager.HandleEventException(this.ToString(),
  1953. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1954. }
  1955. }
  1956. private void F_MST_012003_Load(object sender, EventArgs e)
  1957. {
  1958. try
  1959. {
  1960. // 加载打印项目
  1961. //controlDataSource = this.GetMSTSourse2().Data.Tables[0];
  1962. ClientRequestEntity cre = new ClientRequestEntity();
  1963. cre.NameSpace = "InvoiceLayout";
  1964. cre.Name = "GetBarCodePrintItem";
  1965. ServiceResultEntity sre = SystemModuleProxy.Service.DoBarCodePrint(cre);
  1966. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
  1967. {
  1968. this.InvoiceItemName.DataSource = sre.Data.Tables[0];
  1969. this.InvoiceItemName.DisplayMember = "ItemName";
  1970. this.InvoiceItemName.ValueMember = "ItemCode";
  1971. }
  1972. // 为票据设定的项目列表赋值
  1973. this.dgvText.AutoGenerateColumns = false;
  1974. this.dgvDetail.AutoGenerateColumns = false;
  1975. this.SetLayoutGridDataSource();
  1976. // LayoutBox赋值
  1977. this.InitLayoutBoxStyle();
  1978. // 设置票据功能按钮状态
  1979. this.SetLayoutBoxFunctionButtonStatus();
  1980. }
  1981. catch (Exception ex)
  1982. {
  1983. // 对异常进行共通处理
  1984. ExceptionManager.HandleEventException(this.ToString(),
  1985. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1986. }
  1987. }
  1988. private void lbxInvoice_UserDeletedItem(object sender, WinForm.Controls.InvoiceLayout.ItemChangedEventArgs e)
  1989. {
  1990. try
  1991. {
  1992. if (e.Item.ItemType == ItemType.Text ||
  1993. e.Item.ItemType == ItemType.Barcode ||
  1994. e.Item.ItemType == ItemType.QRcode)
  1995. {
  1996. TextItem textItem = e.Item as TextItem;
  1997. if (textItem != null
  1998. && !string.IsNullOrEmpty(textItem.DataMember))
  1999. {
  2000. DataTable layoutItem = this.dgvText.DataSource as DataTable;
  2001. DataRow[] drLayoutItems = layoutItem.Select("LayoutItemID = " + e.Item.ID);
  2002. if (drLayoutItems != null && 0 < drLayoutItems.Length)
  2003. {
  2004. drLayoutItems[0].Delete();
  2005. }
  2006. }
  2007. }
  2008. else if (e.Item.ItemType == ItemType.TotalText)
  2009. {
  2010. TotalTextItem totalTextItem = e.Item as TotalTextItem;
  2011. if (totalTextItem != null)
  2012. {
  2013. DataTable layoutItem = this.dgvText.DataSource as DataTable;
  2014. DataRow[] drLayoutItems = layoutItem.Select("LayoutItemID = " + e.Item.ID);
  2015. if (drLayoutItems != null && 0 < drLayoutItems.Length)
  2016. {
  2017. drLayoutItems[0].Delete();
  2018. }
  2019. }
  2020. }
  2021. else if (e.Item.ItemType == ItemType.Grid)
  2022. {
  2023. DataTable layoutItem = this.dgvDetail.DataSource as DataTable;
  2024. DataRow[] drLayoutItems = layoutItem.Select();
  2025. foreach (DataRow dr in drLayoutItems)
  2026. {
  2027. dr.Delete();
  2028. }
  2029. }
  2030. }
  2031. catch (Exception ex)
  2032. {
  2033. // 对异常进行共通处理
  2034. ExceptionManager.HandleEventException(this.ToString(),
  2035. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  2036. }
  2037. }
  2038. private void tsbtnPrintPreview_Click(object sender, EventArgs e)
  2039. {
  2040. F_MST_012005 frm012005 = new F_MST_012005();
  2041. frm012005.LayoutName = this.txtInvoiceName.Text;
  2042. frm012005.PageSizeName = this.txtInvoiceSize.Text;
  2043. frm012005.GoodsTypeName = this.txtGoodsType.Text;
  2044. frm012005.Remarks = this.txtRemarks.Text;
  2045. frm012005.LayoutData = this.lbxInvoice.WriteLayout();
  2046. frm012005.LogoName = this.txtLogo.Text;
  2047. frm012005.ShowDialog();
  2048. }
  2049. }
  2050. }