F_MST_013003.cs 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_013002.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_013003 : 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_013003(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_013001.TITLE_F_MST_013001_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_013003(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_013001.TITLE_F_MST_013002_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_013004 frmINV0302 = new F_MST_013004();
  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. if (_goodstypeid.HasValue)
  218. {
  219. this.txtGoodsType.Text = _goodstypeName + "【" + _goodstypeCode + "】";
  220. }
  221. else
  222. {
  223. this.txtGoodsType.Text = null;
  224. }
  225. this._logoid = frmINV0302.LogoID;
  226. this.txtLogo.Text = frmINV0302.LogoName;
  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_013001.TITLE_F_MST_013002_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. object objgoodstypeid = LayoutDataSet.Tables[0].Rows[0]["goodstypeid"];
  1672. if (objgoodstypeid != null && objgoodstypeid != DBNull.Value)
  1673. {
  1674. this._goodstypeid = Convert.ToInt32(objgoodstypeid);
  1675. }
  1676. else
  1677. {
  1678. this._goodstypeid = null;
  1679. }
  1680. //this._goodstypeid = Convert.ToInt32(LayoutDataSet.Tables[0].Rows[0]["goodstypeid"]);
  1681. this._goodstypeCode = LayoutDataSet.Tables[0].Rows[0]["goodstypecode"].ToString();
  1682. this._goodstypeName = LayoutDataSet.Tables[0].Rows[0]["goodstypename"].ToString();
  1683. if (this._goodstypeid.HasValue)
  1684. {
  1685. this.txtGoodsType.Text = LayoutDataSet.Tables[0].Rows[0]["goodstypename"].ToString() + "【" + LayoutDataSet.Tables[0].Rows[0]["goodstypecode"].ToString() + "】";
  1686. }
  1687. else
  1688. {
  1689. this.txtGoodsType.Text = null;
  1690. }
  1691. this.txtInvoiceName.Text = LayoutDataSet.Tables[0].Rows[0]["LayoutName"].ToString();
  1692. this.Text = string.Format(F_MST_013001.TITLE_F_MST_013002_EDIT, this.txtInvoiceName.Text.Trim());
  1693. this.txtRemarks.Text = LayoutDataSet.Tables[0].Rows[0]["Remarks"].ToString();
  1694. //this.txtLogo.Text = LayoutDataSet.Tables[0].Rows[0]["LogoName"].ToString();
  1695. //object objLogoID = LayoutDataSet.Tables[0].Rows[0]["logoid"];
  1696. //if (objLogoID != null && objLogoID != DBNull.Value)
  1697. //{
  1698. // this._logoid = Convert.ToInt32(objLogoID);
  1699. //}
  1700. //else
  1701. //{
  1702. // this._logoid = null;
  1703. //}
  1704. byte[] bytes = LayoutDataSet.Tables[0].Rows[0]["LayoutData"] as byte[];
  1705. if (bytes != null)
  1706. {
  1707. this.lbxInvoice.ReadLayout(bytes);
  1708. }
  1709. }
  1710. this.tsbtnSaveAs.Enabled = true;
  1711. this.tsmiSaveAs.Enabled = true;
  1712. }
  1713. else
  1714. {
  1715. this.tsbtnSaveAs.Enabled = false;
  1716. this.tsmiSaveAs.Enabled = false;
  1717. }
  1718. }
  1719. }
  1720. catch (Exception ex)
  1721. {
  1722. throw ex;
  1723. }
  1724. }
  1725. /// <summary>
  1726. /// 设定保存票据主信息的DataTable
  1727. /// </summary>
  1728. /// <param name="saveDataSet"></param>
  1729. private void SetSaveLayoutData(ref DataSet saveDataSet, int layoutID)
  1730. {
  1731. try
  1732. {
  1733. DataTable layout = _invoiceLayoutDataTable.Copy();
  1734. byte[] bytes = this.lbxInvoice.WriteLayout();
  1735. if (0 < layoutID)
  1736. {
  1737. if (layout != null && layout.Rows.Count > 0)
  1738. {
  1739. // 新建后转成编辑模式,但是数据源中无id
  1740. layout.Rows[0]["layoutid"] = layoutID;
  1741. if (bytes != null)
  1742. {
  1743. layout.Rows[0]["LayoutData"] = bytes;
  1744. }
  1745. layout.Rows[0]["Width"] = lbxInvoice.PaperWidth;
  1746. layout.Rows[0]["Height"] = lbxInvoice.PaperHeight;
  1747. }
  1748. }
  1749. else
  1750. {
  1751. DataRow tempDataRow = layout.NewRow();
  1752. tempDataRow["layoutid"] = 0;
  1753. tempDataRow["LayoutName"] = this.txtInvoiceName.Text.Trim();
  1754. if (bytes != null)
  1755. {
  1756. tempDataRow["LayoutData"] = bytes;
  1757. }
  1758. //tempDataRow["logoid"] = (this._logoid.HasValue ? (object)this._logoid.Value : DBNull.Value);
  1759. tempDataRow["goodstypeid"] = (this._goodstypeid.HasValue ? (object)this._goodstypeid.Value : DBNull.Value);
  1760. tempDataRow["goodstypecode"] = this._goodstypeCode;
  1761. tempDataRow["goodstypename"] = this._goodstypeName;
  1762. tempDataRow["Width"] = lbxInvoice.PaperWidth;
  1763. tempDataRow["Height"] = lbxInvoice.PaperHeight;
  1764. tempDataRow["Remarks"] = this.txtRemarks.Text.Trim();
  1765. layout.Rows.Clear();
  1766. layout.Rows.Add(tempDataRow);
  1767. }
  1768. saveDataSet.Tables.Add(layout);
  1769. }
  1770. catch (Exception ex)
  1771. {
  1772. throw ex;
  1773. }
  1774. }
  1775. /// <summary>
  1776. /// 另存为时,设定保存票据主信息的DataTable
  1777. /// </summary>
  1778. /// <param name="saveDataSet"></param>
  1779. private void SetSaveAsLayoutData(ref DataSet saveDataSet, int layoutID)
  1780. {
  1781. try
  1782. {
  1783. byte[] bytes = this.lbxInvoice.WriteLayout();
  1784. _invoiceLayoutDataTable.Rows[0]["InvoiceLayoutName"] = this.txtInvoiceName.Text.Trim();
  1785. if (bytes != null)
  1786. {
  1787. _invoiceLayoutDataTable.Rows[0]["InvoiceLayoutData"] = bytes;
  1788. }
  1789. //_invoiceLayoutDataTable.Rows[0]["InvoiceCode"] = this.cbxInvoiceType.SelectedValue;
  1790. //_invoiceLayoutDataTable.Rows[0]["OrganizationID"] = this.sbxOrganization.SearchedValue;
  1791. //_invoiceLayoutDataTable.Rows[0]["OrganizationCode"] = this.OrganizationCode;
  1792. //_invoiceLayoutDataTable.Rows[0]["OrganizationName"] = this.sbxOrganization.Text;
  1793. //_invoiceLayoutDataTable.Rows[0]["Width"] = lbxInvoice.PaperWidth;
  1794. //_invoiceLayoutDataTable.Rows[0]["Height"] = lbxInvoice.PaperHeight;
  1795. saveDataSet.Tables.Add(_invoiceLayoutDataTable.Copy());
  1796. }
  1797. catch (Exception ex)
  1798. {
  1799. throw ex;
  1800. }
  1801. }
  1802. /// <summary>
  1803. /// 设定保存票据项目的DataTable
  1804. /// </summary>
  1805. /// <param name="saveDataSet"></param>
  1806. private void SetSaveLayoutItemData(ref DataSet saveDataSet)
  1807. {
  1808. try
  1809. {
  1810. DataTable textDataTable = (DataTable)this.dgvText.DataSource;
  1811. //DataTable itemDataTable = (DataTable)this.dgvDetail.DataSource;
  1812. //DataTable tempDataTable = textDataTable.Clone();
  1813. //for (int i = 0; i < textDataTable.Rows.Count; i++)
  1814. //{
  1815. // if (textDataTable.Rows[i].RowState == DataRowState.Deleted
  1816. // || textDataTable.Rows[i].RowState == DataRowState.Detached)
  1817. // {
  1818. // continue;
  1819. // }
  1820. // textDataTable.Rows[i]["ItemType"] = 0;
  1821. //}
  1822. //for (int i = 0; i < itemDataTable.Rows.Count; i++)
  1823. //{
  1824. // if (itemDataTable.Rows[i].RowState == DataRowState.Deleted
  1825. // || itemDataTable.Rows[i].RowState == DataRowState.Detached)
  1826. // {
  1827. // continue;
  1828. // }
  1829. // itemDataTable.Rows[i]["ItemType"] = 1;
  1830. //}
  1831. //DataRow[] invoiceItemRow = textDataTable.Copy().Select("ItemType = 0");
  1832. //for (int i = 0; i < invoiceItemRow.Length; i++)
  1833. //{
  1834. // tempDataTable.ImportRow(invoiceItemRow[i]);
  1835. //}
  1836. //invoiceItemRow = itemDataTable.Copy().Select("ItemType = 1");
  1837. //for (int i = 0; i < invoiceItemRow.Length; i++)
  1838. //{
  1839. // tempDataTable.ImportRow(invoiceItemRow[i]);
  1840. //}
  1841. saveDataSet.Tables.Add(textDataTable.Copy());
  1842. }
  1843. catch (Exception ex)
  1844. {
  1845. throw ex;
  1846. }
  1847. }
  1848. /// <summary>
  1849. /// 根据票据格式ID取得票据数据及票据项目数据
  1850. /// </summary>
  1851. /// <returns></returns>
  1852. private ServiceResultEntity GetInvoiceData()
  1853. {
  1854. try
  1855. {
  1856. this._clientRequestEntity = new ClientRequestEntity();
  1857. this._clientRequestEntity.NameSpace = "MouldLableLayout";
  1858. this._clientRequestEntity.Name = "GetMouldLablePrintLayout";
  1859. this._clientRequestEntity.Properties["LayoutID"] = _invoiceLayoutID;
  1860. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  1861. }
  1862. catch (Exception ex)
  1863. {
  1864. throw ex;
  1865. }
  1866. }
  1867. /// <summary>
  1868. /// 保存新建票据数据
  1869. /// </summary>
  1870. /// <returns>
  1871. /// 0:保存失败
  1872. /// 其他:保存成功返回新建票据ID
  1873. /// </returns>
  1874. private ServiceResultEntity SaveAddLayoutData()
  1875. {
  1876. try
  1877. {
  1878. this._clientRequestEntity = new ClientRequestEntity();
  1879. this._clientRequestEntity.NameSpace = "MouldLableLayout";
  1880. this._clientRequestEntity.Name = "SaveAddMouldLablePrintLayoutData";
  1881. this._clientRequestEntity.Data = _saveData;
  1882. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  1883. }
  1884. catch (Exception ex)
  1885. {
  1886. throw ex;
  1887. }
  1888. }
  1889. /// <summary>
  1890. /// 保存编辑票据数据
  1891. /// </summary>
  1892. /// <returns>更新数据时影响的行数</returns>
  1893. private ServiceResultEntity SaveEditLayoutData()
  1894. {
  1895. try
  1896. {
  1897. this._clientRequestEntity = new ClientRequestEntity();
  1898. this._clientRequestEntity.NameSpace = "MouldLableLayout";
  1899. this._clientRequestEntity.Name = "SaveEditMouldLablePrintLayoutData";
  1900. this._clientRequestEntity.Data = _saveData;
  1901. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  1902. }
  1903. catch (Exception ex)
  1904. {
  1905. throw ex;
  1906. }
  1907. }
  1908. #endregion
  1909. private void tsmiBarcode_Click(object sender, EventArgs e)
  1910. {
  1911. try
  1912. {
  1913. TextItem newTextItem = this.lbxInvoice.NewItem(ItemType.Barcode, true) as TextItem;
  1914. if (newTextItem != null)
  1915. {
  1916. newTextItem.DataMember = string.Empty;
  1917. }
  1918. }
  1919. catch (Exception ex)
  1920. {
  1921. // 对异常进行共通处理
  1922. ExceptionManager.HandleEventException(this.ToString(),
  1923. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1924. }
  1925. }
  1926. private void tsmiQRcode_Click(object sender, EventArgs e)
  1927. {
  1928. try
  1929. {
  1930. TextItem newTextItem = this.lbxInvoice.NewItem(ItemType.QRcode, true) as TextItem;
  1931. if (newTextItem != null)
  1932. {
  1933. newTextItem.DataMember = string.Empty;
  1934. }
  1935. }
  1936. catch (Exception ex)
  1937. {
  1938. // 对异常进行共通处理
  1939. ExceptionManager.HandleEventException(this.ToString(),
  1940. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1941. }
  1942. }
  1943. private void F_MST_013003_Load(object sender, EventArgs e)
  1944. {
  1945. try
  1946. {
  1947. // 加载打印项目
  1948. //controlDataSource = this.GetMSTSourse2().Data.Tables[0];
  1949. ClientRequestEntity cre = new ClientRequestEntity();
  1950. cre.NameSpace = "MouldLableLayout";
  1951. cre.Name = "GetMouldLablePrintItem";
  1952. ServiceResultEntity sre = SystemModuleProxy.Service.DoBarCodePrint(cre);
  1953. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
  1954. {
  1955. this.InvoiceItemName.DataSource = sre.Data.Tables[0];
  1956. this.InvoiceItemName.DisplayMember = "ItemName";
  1957. this.InvoiceItemName.ValueMember = "ItemCode";
  1958. }
  1959. // 为票据设定的项目列表赋值
  1960. this.dgvText.AutoGenerateColumns = false;
  1961. this.dgvDetail.AutoGenerateColumns = false;
  1962. this.SetLayoutGridDataSource();
  1963. // LayoutBox赋值
  1964. this.InitLayoutBoxStyle();
  1965. // 设置票据功能按钮状态
  1966. this.SetLayoutBoxFunctionButtonStatus();
  1967. }
  1968. catch (Exception ex)
  1969. {
  1970. // 对异常进行共通处理
  1971. ExceptionManager.HandleEventException(this.ToString(),
  1972. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1973. }
  1974. }
  1975. private void lbxInvoice_UserDeletedItem(object sender, WinForm.Controls.InvoiceLayout.ItemChangedEventArgs e)
  1976. {
  1977. try
  1978. {
  1979. if (e.Item.ItemType == ItemType.Text ||
  1980. e.Item.ItemType == ItemType.Barcode ||
  1981. e.Item.ItemType == ItemType.QRcode)
  1982. {
  1983. TextItem textItem = e.Item as TextItem;
  1984. if (textItem != null
  1985. && !string.IsNullOrEmpty(textItem.DataMember))
  1986. {
  1987. DataTable layoutItem = this.dgvText.DataSource as DataTable;
  1988. DataRow[] drLayoutItems = layoutItem.Select("LayoutItemID = " + e.Item.ID);
  1989. if (drLayoutItems != null && 0 < drLayoutItems.Length)
  1990. {
  1991. drLayoutItems[0].Delete();
  1992. }
  1993. }
  1994. }
  1995. else if (e.Item.ItemType == ItemType.TotalText)
  1996. {
  1997. TotalTextItem totalTextItem = e.Item as TotalTextItem;
  1998. if (totalTextItem != null)
  1999. {
  2000. DataTable layoutItem = this.dgvText.DataSource as DataTable;
  2001. DataRow[] drLayoutItems = layoutItem.Select("LayoutItemID = " + e.Item.ID);
  2002. if (drLayoutItems != null && 0 < drLayoutItems.Length)
  2003. {
  2004. drLayoutItems[0].Delete();
  2005. }
  2006. }
  2007. }
  2008. else if (e.Item.ItemType == ItemType.Grid)
  2009. {
  2010. DataTable layoutItem = this.dgvDetail.DataSource as DataTable;
  2011. DataRow[] drLayoutItems = layoutItem.Select();
  2012. foreach (DataRow dr in drLayoutItems)
  2013. {
  2014. dr.Delete();
  2015. }
  2016. }
  2017. }
  2018. catch (Exception ex)
  2019. {
  2020. // 对异常进行共通处理
  2021. ExceptionManager.HandleEventException(this.ToString(),
  2022. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  2023. }
  2024. }
  2025. private void tsbtnPrintPreview_Click(object sender, EventArgs e)
  2026. {
  2027. F_MST_013005 frm012005 = new F_MST_013005();
  2028. frm012005.LayoutName = this.txtInvoiceName.Text;
  2029. frm012005.PageSizeName = this.txtInvoiceSize.Text;
  2030. frm012005.GoodsTypeName = this.txtGoodsType.Text;
  2031. frm012005.Remarks = this.txtRemarks.Text;
  2032. frm012005.LayoutData = this.lbxInvoice.WriteLayout();
  2033. frm012005.LogoName = this.txtLogo.Text;
  2034. frm012005.ShowDialog();
  2035. }
  2036. }
  2037. }