F_MST_012003.cs 85 KB

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