F_MST_012003.cs 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156
  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是条形码时
  1239. else if (Convert.ToInt32(ItemStyle.Barcode) == System.Convert.ToInt32(dataRowView["ItemStyle"]))
  1240. {
  1241. TextItem textItem = lbxInvoice.NewItem(ItemType.Barcode, 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. // 当Item是二维码时
  1261. else if (Convert.ToInt32(ItemStyle.QRCode) == System.Convert.ToInt32(dataRowView["ItemStyle"]))
  1262. {
  1263. TextItem textItem = lbxInvoice.NewItem(ItemType.QRcode, false) as TextItem;
  1264. if (textItem != null)
  1265. {
  1266. textItem.DataMember = dataRowView["ControlCode"].ToString();
  1267. textItem.DisplayValue = dataRowView["ItemSample"].ToString();
  1268. textItem.ItemCode = dataRowView["ItemCode"].ToString();
  1269. textItem.TextItemName = dataRowView["ItemName"].ToString();
  1270. textItem.ItemSample = dataRowView["ItemSample"].ToString();
  1271. textItem.ItemStyle = (ItemStyle)System.Convert.ToInt32(dataRowView["ItemStyle"]);
  1272. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["LayoutItemID"].Value = textItem.ID;
  1273. // 增加票据项目编码
  1274. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["ItemCode"].Value = dataRowView["ItemCode"].ToString();
  1275. textItem.ShowItemPropertyDialog();
  1276. }
  1277. else
  1278. {
  1279. dgvText.Rows.RemoveAt(e.RowIndex);
  1280. }
  1281. }
  1282. else
  1283. {
  1284. TextItem textItem = lbxInvoice.NewItem(ItemType.Text, false) as TextItem;
  1285. if (textItem != null)
  1286. {
  1287. textItem.DataMember = dataRowView["ControlCode"].ToString();
  1288. textItem.DisplayValue = dataRowView["ItemSample"].ToString();
  1289. textItem.ItemCode = dataRowView["ItemCode"].ToString();
  1290. textItem.TextItemName = dataRowView["ItemName"].ToString();
  1291. textItem.ItemSample = dataRowView["ItemSample"].ToString();
  1292. textItem.ItemStyle = (ItemStyle)System.Convert.ToInt32(dataRowView["ItemStyle"]);
  1293. if (textItem.ItemStyle == ItemStyle.Date)
  1294. {
  1295. textItem.Format = "yyyy-MM-dd";
  1296. textItem.Culture = "en-US";
  1297. }
  1298. else if (textItem.ItemStyle == ItemStyle.Sign)
  1299. {
  1300. textItem.Format = "√";
  1301. }
  1302. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["LayoutItemID"].Value = textItem.ID;
  1303. // 增加票据项目编码
  1304. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["ItemCode"].Value = dataRowView["ItemCode"].ToString();
  1305. textItem.ShowItemPropertyDialog();
  1306. }
  1307. else
  1308. {
  1309. dgvText.Rows.RemoveAt(e.RowIndex);
  1310. }
  1311. }
  1312. }
  1313. }
  1314. catch (Exception ex)
  1315. {
  1316. // 对异常进行共通处理
  1317. ExceptionManager.HandleEventException(this.ToString(),
  1318. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1319. }
  1320. }
  1321. /// <summary>
  1322. /// 改变文本grid选择状态
  1323. /// </summary>
  1324. /// <param name="sender"></param>
  1325. /// <param name="e"></param>
  1326. private void dgvText_SelectionChanged(object sender, EventArgs e)
  1327. {
  1328. try
  1329. {
  1330. if (this._layoutSelectionChanging || this.lbxInvoice.ItemSelectionChanging)
  1331. {
  1332. return;
  1333. }
  1334. this._layoutSelectionChanging = true;
  1335. // 取消选择
  1336. if (this.dgvText.SelectedRows.Count == 0
  1337. || (this.dgvText.SelectedRows.Count == 1
  1338. && this.dgvText.SelectedRows[0].IsNewRow))
  1339. {
  1340. this.lbxInvoice.ClearSelection();
  1341. this._layoutSelectionChanging = false;
  1342. return;
  1343. }
  1344. foreach (DataGridViewRow row in dgvText.SelectedRows)
  1345. {
  1346. if (!row.IsNewRow)
  1347. {
  1348. int itemID = System.Convert.ToInt32(row.Cells["LayoutItemID"].Value);
  1349. if (0 < itemID)
  1350. {
  1351. LayoutItem layoutItem = this.lbxInvoice.GetItem(itemID);
  1352. if (layoutItem != null)
  1353. {
  1354. this.lbxInvoice.SelectItemSingle(layoutItem, row.Selected);
  1355. }
  1356. }
  1357. }
  1358. }
  1359. this._layoutSelectionChanging = false;
  1360. }
  1361. catch (Exception ex)
  1362. {
  1363. this._layoutSelectionChanging = false;
  1364. // 对异常进行共通处理
  1365. ExceptionManager.HandleEventException(this.ToString(),
  1366. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1367. }
  1368. }
  1369. /// <summary>
  1370. /// 删除文本grid中的一行
  1371. /// </summary>
  1372. /// <param name="sender"></param>
  1373. /// <param name="e"></param>
  1374. private void dgvText_UserDeletingRow(object sender, System.Windows.Forms.DataGridViewRowCancelEventArgs e)
  1375. {
  1376. try
  1377. {
  1378. C_DataGridView dataGridView = sender as C_DataGridView;
  1379. int itemID = System.Convert.ToInt32(e.Row.Cells["LayoutItemID"].Value);
  1380. DataRowView dataRowView = e.Row.DataBoundItem as DataRowView;
  1381. if (0 < itemID)
  1382. {
  1383. if (4 == System.Convert.ToInt32(dataRowView["ItemStyle"]))
  1384. {
  1385. TotalTextItem totalTextItem = this.lbxInvoice.GetItem(itemID) as TotalTextItem;
  1386. this.lbxInvoice.DeletetItem(totalTextItem);
  1387. }
  1388. else
  1389. {
  1390. TextItem textItem = this.lbxInvoice.GetItem(itemID) as TextItem;
  1391. this.lbxInvoice.DeletetItem(textItem);
  1392. }
  1393. }
  1394. }
  1395. catch (Exception ex)
  1396. {
  1397. // 对异常进行共通处理
  1398. ExceptionManager.HandleEventException(this.ToString(),
  1399. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1400. }
  1401. }
  1402. /// <summary>
  1403. /// 列表DataGridView项目选择内容之后事件
  1404. /// </summary>
  1405. /// <param name="sender"></param>
  1406. /// <param name="e"></param>
  1407. private void dgvDetail_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1408. {
  1409. try
  1410. {
  1411. if (this.dgvDetail == null || this.dgvDetail.CurrentCell == null
  1412. || !string.IsNullOrEmpty(this.dgvDetail.Rows[this.dgvDetail
  1413. .CurrentCell.RowIndex].Cells["LayoutGridItemID"].Value + ""))
  1414. {
  1415. return;
  1416. }
  1417. TextItem textItem = lbxInvoice.NewItem(ItemType.Text, false) as TextItem;
  1418. if (textItem != null)
  1419. {
  1420. DataRowView dataRowView = (this.dgvDetail.EditingControl as ComboBox).SelectedItem as DataRowView;
  1421. this.dgvDetail.Rows[this.dgvDetail.CurrentCell.RowIndex].Cells["LayoutGridItemID"].Value = textItem.ID;
  1422. // 增加票据项目编码
  1423. this.dgvDetail.Rows[this.dgvDetail.CurrentCell.RowIndex].Cells["ItemCodeDetail"].Value
  1424. = dataRowView["ItemCode"].ToString();
  1425. }
  1426. else
  1427. {
  1428. dgvText.Rows.RemoveAt(e.RowIndex);
  1429. }
  1430. }
  1431. catch (Exception ex)
  1432. {
  1433. // 对异常进行共通处理
  1434. ExceptionManager.HandleEventException(this.ToString(),
  1435. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1436. }
  1437. }
  1438. /// <summary>
  1439. /// 列表项目DataGridView项目获得焦点事件
  1440. /// </summary>
  1441. /// <param name="sender"></param>
  1442. /// <param name="e"></param>
  1443. private void dgvDetail_CellEnter(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
  1444. {
  1445. try
  1446. {
  1447. C_DataGridView dataGridView = sender as C_DataGridView;
  1448. if (dataGridView != null && !dataGridView.Rows[dataGridView.CurrentCell.RowIndex].IsNewRow)
  1449. {
  1450. dataGridView.CurrentRow.ReadOnly = true;
  1451. }
  1452. }
  1453. catch (Exception ex)
  1454. {
  1455. // 对异常进行共通处理
  1456. ExceptionManager.HandleEventException(this.ToString(),
  1457. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1458. }
  1459. }
  1460. /// <summary>
  1461. /// 列表项目DataGridView项目选择内容之后事件
  1462. /// </summary>
  1463. /// <param name="sender"></param>
  1464. /// <param name="e"></param>
  1465. private void dgvDetail_CellValidated(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
  1466. {
  1467. try
  1468. {
  1469. // 取得当前DataGridView的当前单元格
  1470. C_DataGridView dataGridView = sender as C_DataGridView;
  1471. // 当前单元格是新建单元格
  1472. if (!dataGridView.CurrentCell.ReadOnly)
  1473. {
  1474. ComboBox comboBox = dataGridView.EditingControl as ComboBox;
  1475. if (comboBox == null || comboBox.SelectedIndex < 0)
  1476. {
  1477. return;
  1478. }
  1479. // 取得当前行的信息
  1480. DataRowView dataRowView = (dataGridView.EditingControl as ComboBox).SelectedItem as DataRowView;
  1481. Dongke.WinForm.Controls.InvoiceLayout.GridItem gridItem = this.lbxInvoice.OneGridItem;
  1482. // 如果当前选中的项目中没有Grid,则自动生成一个新的Grid
  1483. if (gridItem == null)
  1484. {
  1485. gridItem = this.lbxInvoice.NewItem(ItemType.Grid, false) as Dongke.WinForm.Controls.InvoiceLayout.GridItem;
  1486. }
  1487. // 生成新的Grid之后,赋值,在票据控件上显示
  1488. if (gridItem != null)
  1489. {
  1490. GridItemColumn gridItemColumn
  1491. = new GridItemColumn(gridItem.Columns.GeNewColumnName(), dataRowView["ItemName"].ToString());
  1492. gridItemColumn.DataPropertyName = dataRowView["ControlCode"].ToString();
  1493. gridItemColumn.DisplayValue = dataRowView["ItemSample"].ToString();
  1494. gridItemColumn.ItemStyle = (ItemStyle)System.Convert.ToInt32(dataRowView["ItemStyle"]);
  1495. if (gridItemColumn.ItemStyle == ItemStyle.Date)
  1496. {
  1497. gridItemColumn.Format = "yyyy/MM/dd";
  1498. gridItemColumn.Culture = "en-US";
  1499. }
  1500. else if (gridItemColumn.ItemStyle == ItemStyle.Sign)
  1501. {
  1502. gridItemColumn.Format = "√";
  1503. }
  1504. else if (gridItemColumn.ItemStyle == ItemStyle.Barcode)
  1505. {
  1506. gridItemColumn.PicColumn = true;
  1507. }
  1508. gridItem.Columns.Add(gridItemColumn);
  1509. dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["LayoutGridItemID"].Value = gridItemColumn.ID;
  1510. this.lbxInvoice.Refresh();
  1511. }
  1512. }
  1513. }
  1514. catch (Exception ex)
  1515. {
  1516. // 对异常进行共通处理
  1517. ExceptionManager.HandleEventException(this.ToString(),
  1518. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1519. }
  1520. }
  1521. /// <summary>
  1522. /// 改变列表grid选择状态
  1523. /// </summary>
  1524. /// <param name="sender"></param>
  1525. /// <param name="e"></param>
  1526. private void dgvDetail_SelectionChanged(object sender, EventArgs e)
  1527. {
  1528. try
  1529. {
  1530. if (this._layoutSelectionChanging || this.lbxInvoice.ItemSelectionChanging)
  1531. {
  1532. return;
  1533. }
  1534. this._layoutSelectionChanging = true;
  1535. // 取消选择
  1536. if (this.dgvDetail.SelectedRows.Count == 0 || this.lbxInvoice.OneGridItem == null)
  1537. {
  1538. this.lbxInvoice.ClearSelection();
  1539. this._layoutSelectionChanging = false;
  1540. return;
  1541. }
  1542. this.lbxInvoice.SelectItemSingle(this.lbxInvoice.OneGridItem, true);
  1543. this._layoutSelectionChanging = false;
  1544. }
  1545. catch (Exception ex)
  1546. {
  1547. this._layoutSelectionChanging = false;
  1548. // 对异常进行共通处理
  1549. ExceptionManager.HandleEventException(this.ToString(),
  1550. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1551. }
  1552. }
  1553. /// <summary>
  1554. /// 删除列表grid中的一行
  1555. /// </summary>
  1556. /// <param name="sender"></param>
  1557. /// <param name="e"></param>
  1558. private void dgvDetail_UserDeletingRow(object sender, System.Windows.Forms.DataGridViewRowCancelEventArgs e)
  1559. {
  1560. try
  1561. {
  1562. if (this.lbxInvoice.OneGridItem == null)
  1563. {
  1564. return;
  1565. }
  1566. int itemID = System.Convert.ToInt32(e.Row.Cells["LayoutGridItemID"].Value);
  1567. if (0 < itemID)
  1568. {
  1569. this.lbxInvoice.OneGridItem.Columns.RemoveAtByID(itemID);
  1570. }
  1571. }
  1572. catch (Exception ex)
  1573. {
  1574. // 对异常进行共通处理
  1575. ExceptionManager.HandleEventException(this.ToString(),
  1576. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1577. }
  1578. }
  1579. #endregion
  1580. #endregion
  1581. #region 私有方法/函数
  1582. /// <summary>
  1583. /// 初始化LayoutBox样式及数据
  1584. /// </summary>
  1585. private void InitLayoutBoxStyle()
  1586. {
  1587. // 编辑的状况下加载票据格式数据
  1588. if (this._invoiceLayoutID == 0)
  1589. {
  1590. this.lbxInvoice.SetPaperAreaSize(_paperWidth, _paperHeight);
  1591. }
  1592. this.txtInvoiceSize.Text = string.Format("{0:0}mm×{1:0}mm",
  1593. lbxInvoice.PaperWidth,
  1594. lbxInvoice.PaperHeight);
  1595. }
  1596. /// <summary>
  1597. /// 只有当票据选择了一个以上的项目该功能才可用
  1598. /// </summary>
  1599. /// <param name="status">可用/不可用</param>
  1600. private void SetLayoutBoxFunctionButtonStatus()
  1601. {
  1602. // 复制、剪切、删除
  1603. this.tsmiCut.Enabled = (this.lbxInvoice.SelectedItems.Count > 0);
  1604. this.tsmiCopy.Enabled = this.tsmiCut.Enabled;
  1605. this.tsmiDelete.Enabled = this.tsmiCut.Enabled;
  1606. this.tsbtnCut.Enabled = this.tsmiCut.Enabled;
  1607. this.tsbtnCopy.Enabled = this.tsmiCut.Enabled;
  1608. this.tsbtnDelete.Enabled = this.tsmiCut.Enabled;
  1609. // 详细或者移动
  1610. this.tsmiDetail.Enabled = (this.lbxInvoice.SelectedItems.Count == 1);
  1611. this.tsbtnDetail.Enabled = this.tsmiDetail.Enabled;
  1612. this.tsmiFrontMost.Enabled = this.tsmiDetail.Enabled;
  1613. this.tsmiFront.Enabled = this.tsmiDetail.Enabled;
  1614. this.tsmiBack.Enabled = this.tsmiDetail.Enabled;
  1615. this.tsmiBackMost.Enabled = this.tsmiDetail.Enabled;
  1616. this.tsbtnMoveTop.Enabled = this.tsmiDetail.Enabled;
  1617. this.tsbtnMoveFront.Enabled = this.tsmiDetail.Enabled;
  1618. this.tsbtnMoveUnder.Enabled = this.tsmiDetail.Enabled;
  1619. this.tsbtnMoveBottom.Enabled = this.tsmiDetail.Enabled;
  1620. // 对齐按钮或者菜单
  1621. this.tsbtnAlignmentLeft.Enabled = (this.lbxInvoice.SelectedItems.Count > 1);
  1622. this.tsbtnAlignmentLeft.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1623. this.tsbtnAlignmentCenter.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1624. this.tsbtnAlignmentRight.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1625. this.tsbtnAlignmentTop.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1626. this.tsbtnAlignmentMiddle.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1627. this.tsbtnAlignmentBottom.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1628. this.tsmiAlignmentLeft.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1629. this.tsmiAlignmentCenter.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1630. this.tsmiAlignmentRight.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1631. this.tsmiAlignmentTop.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1632. this.tsmiAlignmentMiddle.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1633. this.tsmiAlignmentBottom.Enabled = this.tsbtnAlignmentLeft.Enabled;
  1634. // 粘贴按钮或者菜单
  1635. this.tsmiPaste.Enabled = Clipboard.ContainsData(this.lbxInvoice.ClipboardFormat.Name);
  1636. this.tsbtnPaste.Enabled = Clipboard.ContainsData(this.lbxInvoice.ClipboardFormat.Name);
  1637. }
  1638. /// <summary>
  1639. /// 为票据设定的项目列表赋值
  1640. /// </summary>
  1641. private void SetLayoutGridDataSource()
  1642. {
  1643. try
  1644. {
  1645. ServiceResultEntity sre = GetInvoiceData();
  1646. DataSet LayoutDataSet = sre.Data;
  1647. if (LayoutDataSet != null && LayoutDataSet.Tables.Count > 1)
  1648. {
  1649. _invoiceLayoutDataTable = LayoutDataSet.Tables[0];
  1650. //DataTable tempTable = LayoutDataSet.Tables[1].Clone();
  1651. //DataTable tempDetailTable = LayoutDataSet.Tables[1].Clone();
  1652. //// 文本数据赋值
  1653. //DataRow[] invoiceItemRow = LayoutDataSet.Tables[1].Copy().Select("ItemType = 0");
  1654. //for (int i = 0; i < invoiceItemRow.Length; i++)
  1655. //{
  1656. // tempTable.ImportRow(invoiceItemRow[i]);
  1657. //}
  1658. this.dgvText.DataSource = LayoutDataSet.Tables[1];
  1659. //// 列表项目赋值
  1660. //invoiceItemRow = LayoutDataSet.Tables[1].Copy().Select("ItemType = 1");
  1661. //for (int i = 0; i < invoiceItemRow.Length; i++)
  1662. //{
  1663. // tempDetailTable.ImportRow(invoiceItemRow[i]);
  1664. //}
  1665. //this.dgvDetail.DataSource = tempDetailTable;
  1666. // 编辑的状况下加载票据格式数据
  1667. if (this._invoiceLayoutID != 0)
  1668. {
  1669. if (1 == LayoutDataSet.Tables[0].Rows.Count)
  1670. {
  1671. this.txtGoodsType.Text = LayoutDataSet.Tables[0].Rows[0]["goodstypename"].ToString() + "【" + LayoutDataSet.Tables[0].Rows[0]["goodstypecode"].ToString() + "】";
  1672. this.txtInvoiceName.Text = LayoutDataSet.Tables[0].Rows[0]["LayoutName"].ToString();
  1673. this.Text = string.Format(F_MST_012001.TITLE_F_MST_012002_EDIT, this.txtInvoiceName.Text.Trim());
  1674. this.txtRemarks.Text = LayoutDataSet.Tables[0].Rows[0]["Remarks"].ToString();
  1675. this.txtLogo.Text = LayoutDataSet.Tables[0].Rows[0]["LogoName"].ToString();
  1676. this._goodstypeid = Convert.ToInt32(LayoutDataSet.Tables[0].Rows[0]["goodstypeid"]);
  1677. this._goodstypeCode = LayoutDataSet.Tables[0].Rows[0]["goodstypecode"].ToString();
  1678. this._goodstypeName = LayoutDataSet.Tables[0].Rows[0]["goodstypename"].ToString();
  1679. object objLogoID = LayoutDataSet.Tables[0].Rows[0]["logoid"];
  1680. if (objLogoID != null && objLogoID != DBNull.Value)
  1681. {
  1682. this._logoid = Convert.ToInt32(objLogoID);
  1683. }
  1684. else
  1685. {
  1686. this._logoid = null;
  1687. }
  1688. byte[] bytes = LayoutDataSet.Tables[0].Rows[0]["LayoutData"] as byte[];
  1689. if (bytes != null)
  1690. {
  1691. this.lbxInvoice.ReadLayout(bytes);
  1692. }
  1693. }
  1694. this.tsbtnSaveAs.Enabled = true;
  1695. this.tsmiSaveAs.Enabled = true;
  1696. }
  1697. else
  1698. {
  1699. this.tsbtnSaveAs.Enabled = false;
  1700. this.tsmiSaveAs.Enabled = false;
  1701. }
  1702. }
  1703. }
  1704. catch (Exception ex)
  1705. {
  1706. throw ex;
  1707. }
  1708. }
  1709. /// <summary>
  1710. /// 设定保存票据主信息的DataTable
  1711. /// </summary>
  1712. /// <param name="saveDataSet"></param>
  1713. private void SetSaveLayoutData(ref DataSet saveDataSet, int layoutID)
  1714. {
  1715. try
  1716. {
  1717. DataTable layout = _invoiceLayoutDataTable.Copy();
  1718. byte[] bytes = this.lbxInvoice.WriteLayout();
  1719. if (0 < layoutID)
  1720. {
  1721. if (layout != null && layout.Rows.Count > 0)
  1722. {
  1723. // 新建后转成编辑模式,但是数据源中无id
  1724. layout.Rows[0]["layoutid"] = layoutID;
  1725. if (bytes != null)
  1726. {
  1727. layout.Rows[0]["LayoutData"] = bytes;
  1728. }
  1729. layout.Rows[0]["Width"] = lbxInvoice.PaperWidth;
  1730. layout.Rows[0]["Height"] = lbxInvoice.PaperHeight;
  1731. }
  1732. }
  1733. else
  1734. {
  1735. DataRow tempDataRow = layout.NewRow();
  1736. tempDataRow["layoutid"] = 0;
  1737. tempDataRow["LayoutName"] = this.txtInvoiceName.Text.Trim();
  1738. if (bytes != null)
  1739. {
  1740. tempDataRow["LayoutData"] = bytes;
  1741. }
  1742. tempDataRow["logoid"] = (this._logoid.HasValue ? (object)this._logoid.Value : DBNull.Value);
  1743. tempDataRow["goodstypeid"] = this._goodstypeid;
  1744. tempDataRow["goodstypecode"] = this._goodstypeCode;
  1745. tempDataRow["goodstypename"] = this._goodstypeName;
  1746. tempDataRow["Width"] = lbxInvoice.PaperWidth;
  1747. tempDataRow["Height"] = lbxInvoice.PaperHeight;
  1748. tempDataRow["Remarks"] = this.txtRemarks.Text.Trim();
  1749. //xuwei add 2019-11-20
  1750. tempDataRow["PrintType"] = this._printType;
  1751. layout.Rows.Clear();
  1752. layout.Rows.Add(tempDataRow);
  1753. }
  1754. saveDataSet.Tables.Add(layout);
  1755. }
  1756. catch (Exception ex)
  1757. {
  1758. throw ex;
  1759. }
  1760. }
  1761. /// <summary>
  1762. /// 另存为时,设定保存票据主信息的DataTable
  1763. /// </summary>
  1764. /// <param name="saveDataSet"></param>
  1765. private void SetSaveAsLayoutData(ref DataSet saveDataSet, int layoutID)
  1766. {
  1767. try
  1768. {
  1769. byte[] bytes = this.lbxInvoice.WriteLayout();
  1770. _invoiceLayoutDataTable.Rows[0]["InvoiceLayoutName"] = this.txtInvoiceName.Text.Trim();
  1771. if (bytes != null)
  1772. {
  1773. _invoiceLayoutDataTable.Rows[0]["InvoiceLayoutData"] = bytes;
  1774. }
  1775. //_invoiceLayoutDataTable.Rows[0]["InvoiceCode"] = this.cbxInvoiceType.SelectedValue;
  1776. //_invoiceLayoutDataTable.Rows[0]["OrganizationID"] = this.sbxOrganization.SearchedValue;
  1777. //_invoiceLayoutDataTable.Rows[0]["OrganizationCode"] = this.OrganizationCode;
  1778. //_invoiceLayoutDataTable.Rows[0]["OrganizationName"] = this.sbxOrganization.Text;
  1779. //_invoiceLayoutDataTable.Rows[0]["Width"] = lbxInvoice.PaperWidth;
  1780. //_invoiceLayoutDataTable.Rows[0]["Height"] = lbxInvoice.PaperHeight;
  1781. saveDataSet.Tables.Add(_invoiceLayoutDataTable.Copy());
  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 SetSaveLayoutItemData(ref DataSet saveDataSet)
  1793. {
  1794. try
  1795. {
  1796. DataTable textDataTable = (DataTable)this.dgvText.DataSource;
  1797. //DataTable itemDataTable = (DataTable)this.dgvDetail.DataSource;
  1798. //DataTable tempDataTable = textDataTable.Clone();
  1799. //for (int i = 0; i < textDataTable.Rows.Count; i++)
  1800. //{
  1801. // if (textDataTable.Rows[i].RowState == DataRowState.Deleted
  1802. // || textDataTable.Rows[i].RowState == DataRowState.Detached)
  1803. // {
  1804. // continue;
  1805. // }
  1806. // textDataTable.Rows[i]["ItemType"] = 0;
  1807. //}
  1808. //for (int i = 0; i < itemDataTable.Rows.Count; i++)
  1809. //{
  1810. // if (itemDataTable.Rows[i].RowState == DataRowState.Deleted
  1811. // || itemDataTable.Rows[i].RowState == DataRowState.Detached)
  1812. // {
  1813. // continue;
  1814. // }
  1815. // itemDataTable.Rows[i]["ItemType"] = 1;
  1816. //}
  1817. //DataRow[] invoiceItemRow = textDataTable.Copy().Select("ItemType = 0");
  1818. //for (int i = 0; i < invoiceItemRow.Length; i++)
  1819. //{
  1820. // tempDataTable.ImportRow(invoiceItemRow[i]);
  1821. //}
  1822. //invoiceItemRow = itemDataTable.Copy().Select("ItemType = 1");
  1823. //for (int i = 0; i < invoiceItemRow.Length; i++)
  1824. //{
  1825. // tempDataTable.ImportRow(invoiceItemRow[i]);
  1826. //}
  1827. saveDataSet.Tables.Add(textDataTable.Copy());
  1828. }
  1829. catch (Exception ex)
  1830. {
  1831. throw ex;
  1832. }
  1833. }
  1834. /// <summary>
  1835. /// 根据票据格式ID取得票据数据及票据项目数据
  1836. /// </summary>
  1837. /// <returns></returns>
  1838. private ServiceResultEntity GetInvoiceData()
  1839. {
  1840. try
  1841. {
  1842. this._clientRequestEntity = new ClientRequestEntity();
  1843. this._clientRequestEntity.NameSpace = "InvoiceLayout";
  1844. this._clientRequestEntity.Name = "GetBarCodePrintLayout";
  1845. this._clientRequestEntity.Properties["LayoutID"] = _invoiceLayoutID;
  1846. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  1847. }
  1848. catch (Exception ex)
  1849. {
  1850. throw ex;
  1851. }
  1852. }
  1853. /// <summary>
  1854. /// 保存新建票据数据
  1855. /// </summary>
  1856. /// <returns>
  1857. /// 0:保存失败
  1858. /// 其他:保存成功返回新建票据ID
  1859. /// </returns>
  1860. private ServiceResultEntity SaveAddLayoutData()
  1861. {
  1862. try
  1863. {
  1864. this._clientRequestEntity = new ClientRequestEntity();
  1865. this._clientRequestEntity.NameSpace = "InvoiceLayout";
  1866. this._clientRequestEntity.Name = "SaveAddBarCodePrintLayoutData";
  1867. this._clientRequestEntity.Data = _saveData;
  1868. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  1869. }
  1870. catch (Exception ex)
  1871. {
  1872. throw ex;
  1873. }
  1874. }
  1875. /// <summary>
  1876. /// 保存编辑票据数据
  1877. /// </summary>
  1878. /// <returns>更新数据时影响的行数</returns>
  1879. private ServiceResultEntity SaveEditLayoutData()
  1880. {
  1881. try
  1882. {
  1883. this._clientRequestEntity = new ClientRequestEntity();
  1884. this._clientRequestEntity.NameSpace = "InvoiceLayout";
  1885. this._clientRequestEntity.Name = "SaveEditBarCodePrintLayoutData";
  1886. this._clientRequestEntity.Data = _saveData;
  1887. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  1888. }
  1889. catch (Exception ex)
  1890. {
  1891. throw ex;
  1892. }
  1893. }
  1894. #endregion
  1895. private void tsmiBarcode_Click(object sender, EventArgs e)
  1896. {
  1897. try
  1898. {
  1899. TextItem newTextItem = this.lbxInvoice.NewItem(ItemType.Barcode, true) as TextItem;
  1900. if (newTextItem != null)
  1901. {
  1902. newTextItem.DataMember = string.Empty;
  1903. }
  1904. }
  1905. catch (Exception ex)
  1906. {
  1907. // 对异常进行共通处理
  1908. ExceptionManager.HandleEventException(this.ToString(),
  1909. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1910. }
  1911. }
  1912. private void tsmiQRcode_Click(object sender, EventArgs e)
  1913. {
  1914. try
  1915. {
  1916. TextItem newTextItem = this.lbxInvoice.NewItem(ItemType.QRcode, true) as TextItem;
  1917. if (newTextItem != null)
  1918. {
  1919. newTextItem.DataMember = string.Empty;
  1920. }
  1921. }
  1922. catch (Exception ex)
  1923. {
  1924. // 对异常进行共通处理
  1925. ExceptionManager.HandleEventException(this.ToString(),
  1926. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1927. }
  1928. }
  1929. private void F_MST_012003_Load(object sender, EventArgs e)
  1930. {
  1931. try
  1932. {
  1933. // 加载打印项目
  1934. //controlDataSource = this.GetMSTSourse2().Data.Tables[0];
  1935. ClientRequestEntity cre = new ClientRequestEntity();
  1936. cre.NameSpace = "InvoiceLayout";
  1937. cre.Name = "GetBarCodePrintItem";
  1938. ServiceResultEntity sre = SystemModuleProxy.Service.DoBarCodePrint(cre);
  1939. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
  1940. {
  1941. this.InvoiceItemName.DataSource = sre.Data.Tables[0];
  1942. this.InvoiceItemName.DisplayMember = "ItemName";
  1943. this.InvoiceItemName.ValueMember = "ItemCode";
  1944. }
  1945. // 为票据设定的项目列表赋值
  1946. this.dgvText.AutoGenerateColumns = false;
  1947. this.dgvDetail.AutoGenerateColumns = false;
  1948. this.SetLayoutGridDataSource();
  1949. // LayoutBox赋值
  1950. this.InitLayoutBoxStyle();
  1951. // 设置票据功能按钮状态
  1952. this.SetLayoutBoxFunctionButtonStatus();
  1953. }
  1954. catch (Exception ex)
  1955. {
  1956. // 对异常进行共通处理
  1957. ExceptionManager.HandleEventException(this.ToString(),
  1958. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1959. }
  1960. }
  1961. private void lbxInvoice_UserDeletedItem(object sender, WinForm.Controls.InvoiceLayout.ItemChangedEventArgs e)
  1962. {
  1963. try
  1964. {
  1965. if (e.Item.ItemType == ItemType.Text ||
  1966. e.Item.ItemType == ItemType.Barcode ||
  1967. e.Item.ItemType == ItemType.QRcode)
  1968. {
  1969. TextItem textItem = e.Item as TextItem;
  1970. if (textItem != null
  1971. && !string.IsNullOrEmpty(textItem.DataMember))
  1972. {
  1973. DataTable layoutItem = this.dgvText.DataSource as DataTable;
  1974. DataRow[] drLayoutItems = layoutItem.Select("LayoutItemID = " + e.Item.ID);
  1975. if (drLayoutItems != null && 0 < drLayoutItems.Length)
  1976. {
  1977. drLayoutItems[0].Delete();
  1978. }
  1979. }
  1980. }
  1981. else if (e.Item.ItemType == ItemType.TotalText)
  1982. {
  1983. TotalTextItem totalTextItem = e.Item as TotalTextItem;
  1984. if (totalTextItem != null)
  1985. {
  1986. DataTable layoutItem = this.dgvText.DataSource as DataTable;
  1987. DataRow[] drLayoutItems = layoutItem.Select("LayoutItemID = " + e.Item.ID);
  1988. if (drLayoutItems != null && 0 < drLayoutItems.Length)
  1989. {
  1990. drLayoutItems[0].Delete();
  1991. }
  1992. }
  1993. }
  1994. else if (e.Item.ItemType == ItemType.Grid)
  1995. {
  1996. DataTable layoutItem = this.dgvDetail.DataSource as DataTable;
  1997. DataRow[] drLayoutItems = layoutItem.Select();
  1998. foreach (DataRow dr in drLayoutItems)
  1999. {
  2000. dr.Delete();
  2001. }
  2002. }
  2003. }
  2004. catch (Exception ex)
  2005. {
  2006. // 对异常进行共通处理
  2007. ExceptionManager.HandleEventException(this.ToString(),
  2008. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  2009. }
  2010. }
  2011. private void tsbtnPrintPreview_Click(object sender, EventArgs e)
  2012. {
  2013. F_MST_012005 frm012005 = new F_MST_012005();
  2014. frm012005.LayoutName = this.txtInvoiceName.Text;
  2015. frm012005.PageSizeName = this.txtInvoiceSize.Text;
  2016. frm012005.GoodsTypeName = this.txtGoodsType.Text;
  2017. frm012005.Remarks = this.txtRemarks.Text;
  2018. frm012005.LayoutData = this.lbxInvoice.WriteLayout();
  2019. frm012005.LogoName = this.txtLogo.Text;
  2020. frm012005.ShowDialog();
  2021. }
  2022. }
  2023. }