F_MST_012002.cs 11 KB

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