F_MST_013002.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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.ComponentModel;
  14. using System.Data;
  15. using System.Drawing.Printing;
  16. using System.Reflection;
  17. using System.Windows.Forms;
  18. using Dongke.IBOSS.PRD.Basics.BaseResources;
  19. using Dongke.IBOSS.PRD.Client.CommonModule;
  20. using Dongke.IBOSS.PRD.WCF.DataModels;
  21. using Dongke.IBOSS.PRD.WCF.Proxys;
  22. using Dongke.WinForm.Controls;
  23. namespace Dongke.IBOSS.PRD.Client.Controls
  24. {
  25. public partial class F_MST_013002 : DKFormBase
  26. {
  27. #region 成员变量
  28. //private string _invoiceLayoutID; // 票据设置ID
  29. private static DataTable _paperSizes; // 纸张尺寸一览
  30. private int _indexA4 = -1;
  31. private bool _isSizeChanged = false;
  32. private bool _allowChangeSize = false;
  33. private List<int> _invoiceLayoutIDList; // 新建票据ID列表
  34. private ClientRequestEntity _clientRequestEntity = null; // 查询条件实体
  35. #endregion
  36. #region 构造函数
  37. public F_MST_013002()
  38. {
  39. InitializeComponent();
  40. dgrdPaperSize.AutoGenerateColumns = false;
  41. InitializePaperSize();
  42. dgrdPaperSize.ClearSelection();
  43. this._allowChangeSize = true;
  44. // 设定按钮文本及窗体文本
  45. this.btnSave.Text = ButtonText.BTN_OK;
  46. this.btnCancel.Text = ButtonText.BTN_CANCEL;
  47. this.Text = F_MST_013001.TITLE_F_MST_013001_ADD;
  48. //if (this.FormType == WinForm.Controls.FormType.Add)
  49. //{
  50. // this.ActiveControl = this.cbxInvoiceType;
  51. //}
  52. //else
  53. //{
  54. // this.Text = F_MST_013001.TITLE_F_MST_013001_EDIT;
  55. //}
  56. //this._invoiceLayoutID = base.FormCode;
  57. }
  58. #endregion
  59. #region 属性
  60. /// <summary>
  61. /// 纸张的宽(mm)
  62. /// </summary>
  63. [DefaultValue(210)]
  64. public float PaperWidth
  65. {
  66. get
  67. {
  68. return System.Convert.ToSingle(numerWidth.Value);
  69. }
  70. set
  71. {
  72. decimal d = System.Convert.ToDecimal(value);
  73. if (d < numerWidth.Minimum)
  74. {
  75. d = numerWidth.Minimum;
  76. }
  77. else if (numerWidth.Maximum < d)
  78. {
  79. d = numerWidth.Maximum;
  80. }
  81. if (numerWidth.Value != d)
  82. {
  83. _isSizeChanged = true;
  84. numerWidth.Value = d;
  85. }
  86. }
  87. }
  88. /// <summary>
  89. /// 纸张的高(mm)
  90. /// </summary>
  91. [DefaultValue(297)]
  92. public float PaperHeight
  93. {
  94. get
  95. {
  96. return System.Convert.ToSingle(numerHeight.Value);
  97. }
  98. set
  99. {
  100. decimal d = System.Convert.ToDecimal(value);
  101. if (d < numerHeight.Minimum)
  102. {
  103. d = numerHeight.Minimum;
  104. }
  105. else if (numerHeight.Maximum < d)
  106. {
  107. d = numerHeight.Maximum;
  108. }
  109. if (numerHeight.Value != d)
  110. {
  111. _isSizeChanged = true;
  112. numerHeight.Value = d;
  113. }
  114. }
  115. }
  116. /// <summary>
  117. /// 新建票据ID集合
  118. /// </summary>
  119. public List<int> InvoiceLayoutIDList
  120. {
  121. get
  122. {
  123. return _invoiceLayoutIDList;
  124. }
  125. set
  126. {
  127. _invoiceLayoutIDList = value;
  128. }
  129. }
  130. #endregion
  131. #region 控件事件
  132. private bool _canChangedText = true;
  133. private void txtInvoiceName_TextChanged(object sender, EventArgs e)
  134. {
  135. this._canChangedText = false;
  136. }
  137. /// <summary>
  138. /// 列表的选择项发生改变事件
  139. /// </summary>
  140. /// <param name="sender"></param>
  141. /// <param name="e"></param>
  142. private void dgrdPaperSize_SelectionChanged(object sender, System.EventArgs e)
  143. {
  144. if (dgrdPaperSize.CurrentRow != null && _allowChangeSize
  145. && 0 < dgrdPaperSize.SelectedRows.Count)
  146. {
  147. PaperHeight =
  148. System.Convert.ToSingle(dgrdPaperSize.CurrentRow.Cells["colHeight"].Value);
  149. PaperWidth =
  150. System.Convert.ToSingle(dgrdPaperSize.CurrentRow.Cells["colWidth"].Value);
  151. }
  152. }
  153. /// <summary>
  154. /// 列表失去焦点事件
  155. /// </summary>
  156. /// <param name="sender"></param>
  157. /// <param name="e"></param>
  158. private void dgrdPaperSize_Leave(object sender, System.EventArgs e)
  159. {
  160. dgrdPaperSize.ClearSelection();
  161. }
  162. /// <summary>
  163. ///
  164. /// </summary>
  165. /// <param name="sender"></param>
  166. /// <param name="e"></param>
  167. private void btnOK_Click(object sender, System.EventArgs e)
  168. {
  169. try
  170. {
  171. // 判断票据名称输入是否正确
  172. if (string.IsNullOrEmpty(this.txtInvoiceName.Text.Trim()))
  173. {
  174. MessageBox.Show(string.Format("{0}是必须输入项目,请输入{0}。", "标签名称"), this.Text,
  175. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  176. this.txtInvoiceName.Focus();
  177. return;
  178. }
  179. // 判断系统是否存在相同的票据
  180. bool isExistSameInvoice = this.IsExistInvoice();
  181. // 存在相同的票据
  182. if (isExistSameInvoice)
  183. {
  184. MessageBox.Show(string.Format("不允许进行该操作,原因:{0}。", "在该产品类别中已存在标签模板"), this.Text,
  185. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  186. this.scbGoodsType.Focus();
  187. return;
  188. }
  189. //object objLogoID = this.ftcLogo.SelectedValue;
  190. //int? logoid = null;
  191. //if (objLogoID != null && objLogoID != DBNull.Value)
  192. //{
  193. // logoid = Convert.ToInt32(objLogoID);
  194. //}
  195. // 给票据编辑画面赋值,并打开
  196. F_MST_013003 frmINV0301 = new F_MST_013003(scbGoodsType.SearchedPKMember,
  197. scbGoodsType.SearchedValue + "",
  198. scbGoodsType.SearchedText,
  199. null,
  200. null,
  201. this.PaperWidth,
  202. this.PaperHeight,
  203. this.txtInvoiceName.Text.Trim(),
  204. this.txtRemark.Text.Trim());
  205. this.Hide();
  206. DialogResult dialogresult = frmINV0301.ShowDialog();
  207. if (DialogResult.OK == dialogresult)
  208. {
  209. this.DialogResult = DialogResult.OK;
  210. }
  211. else
  212. {
  213. this.DialogResult = DialogResult.Cancel;
  214. }
  215. this.Close();
  216. }
  217. catch (Exception ex)
  218. {
  219. // 对异常进行共通处理
  220. ExceptionManager.HandleEventException(this.ToString(),
  221. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  222. }
  223. }
  224. /// <summary>
  225. ///
  226. /// </summary>
  227. /// <param name="sender"></param>
  228. /// <param name="e"></param>
  229. private void btnCancel_Click(object sender, System.EventArgs e)
  230. {
  231. this.DialogResult = DialogResult.Cancel;
  232. this.Close();
  233. }
  234. /// <summary>
  235. /// 画面打开
  236. /// </summary>
  237. /// <param name="sender"></param>
  238. /// <param name="e"></param>
  239. private void F_MST_013002_Load(object sender, EventArgs e)
  240. {
  241. //try
  242. //{
  243. // DataSet logoInfo = SystemModuleProxy.Service.GetLogoInfo();
  244. // if (logoInfo != null && logoInfo.Tables.Count > 0)
  245. // {
  246. // this.ftcLogo.DataSource = logoInfo.Tables[0];
  247. // this.ftcLogo.DisplayMember = "LogoNameCode";
  248. // this.ftcLogo.ValueMember = "LogoID";
  249. // }
  250. //}
  251. //catch (Exception ex)
  252. //{
  253. // // 对异常进行共通处理
  254. // ExceptionManager.HandleEventException(this.ToString(),
  255. // MethodBase.GetCurrentMethod().Name, this.Text, ex);
  256. //}
  257. }
  258. #endregion
  259. #region 重写方法
  260. #endregion
  261. #region 私有方法/函数
  262. /// <summary>
  263. /// 根据本机的打印机取得纸张的信息
  264. /// </summary>
  265. private void InitializePaperSize()
  266. {
  267. if (_paperSizes == null)
  268. {
  269. _paperSizes = new DataTable();
  270. _paperSizes.TableName = "PaperSizes";
  271. _paperSizes.Columns.Add("SizeName", typeof(string));
  272. _paperSizes.Columns.Add("Width", typeof(float));
  273. _paperSizes.Columns.Add("Height", typeof(float));
  274. }
  275. else
  276. {
  277. _paperSizes.Clear();
  278. }
  279. float height = 0;
  280. float width = 0;
  281. int index = 0;
  282. PrintDocument pd = new PrintDocument();
  283. foreach (PaperSize ps in pd.PrinterSettings.PaperSizes)
  284. {
  285. DataRow dataRow = _paperSizes.NewRow();
  286. height = Dongke.IBOSS.PRD.Basics.Library.Utility.Inch100ToMillimeter(ps.Height);
  287. width = Dongke.IBOSS.PRD.Basics.Library.Utility.Inch100ToMillimeter(ps.Width);
  288. dataRow[0] = string.Format("{0} {1:0}mm×{2:0}mm", ps.PaperName, width, height);
  289. dataRow[1] = Math.Round(width);
  290. dataRow[2] = Math.Round(height);
  291. _paperSizes.Rows.Add(dataRow);
  292. if (ps.PaperName.StartsWith("A4") && 210.0f.Equals(dataRow[1]) && 297.0f.Equals(dataRow[2]) && _indexA4 < 0)
  293. {
  294. _indexA4 = index;
  295. }
  296. index++;
  297. }
  298. dgrdPaperSize.DataSource = _paperSizes;
  299. }
  300. /// <summary>
  301. /// 判断系统是否存在相同的票据
  302. /// </summary>
  303. /// <returns>
  304. /// false:不存在
  305. /// true:存在
  306. /// </returns>
  307. private bool IsExistInvoice()
  308. {
  309. try
  310. {
  311. int? goodsTypeID = Convert.ToInt32(scbGoodsType.SearchedItem["GoodsTypeID"]);
  312. //if (!goodsTypeID.HasValue)
  313. //{
  314. // return true;
  315. //}
  316. //if (this.ftcLogo.SelectedValue == null)
  317. //{
  318. // return true;
  319. //}
  320. this._clientRequestEntity = new ClientRequestEntity();
  321. this._clientRequestEntity.NameSpace = "MouldLableLayout";
  322. this._clientRequestEntity.Name = "IsExistMouldLablePrintLayout";
  323. this._clientRequestEntity.Properties["GoodsTypeID"] = goodsTypeID;
  324. //this._clientRequestEntity.Properties["LogoID"] = this.ftcLogo.SelectedValue;
  325. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  326. {
  327. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  328. }
  329. );
  330. return Convert.ToBoolean(sre.Result);
  331. }
  332. catch (Exception ex)
  333. {
  334. throw ex;
  335. }
  336. }
  337. #endregion
  338. }
  339. }