F_MST_012002.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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 + "】" + ddlPrintType.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 + "】" + ddlPrintType.Text;
  156. this._canChangedText = true;
  157. }
  158. }
  159. //xuwei add 2019-11-20 增加 打印类型 并拼合名称
  160. private void ddlPrintType_SelectedIndexChanged(object sender, EventArgs e)
  161. {
  162. if (this._canChangedText)
  163. {
  164. this.txtInvoiceName.Text = this.scbGoodsType.Text
  165. + "【" + this.ftcLogo.Text + "】" + ddlPrintType.Text;
  166. this._canChangedText = true;
  167. }
  168. }
  169. /// <summary>
  170. /// 列表的选择项发生改变事件
  171. /// </summary>
  172. /// <param name="sender"></param>
  173. /// <param name="e"></param>
  174. private void dgrdPaperSize_SelectionChanged(object sender, System.EventArgs e)
  175. {
  176. if (dgrdPaperSize.CurrentRow != null && _allowChangeSize
  177. && 0 < dgrdPaperSize.SelectedRows.Count)
  178. {
  179. PaperHeight =
  180. System.Convert.ToSingle(dgrdPaperSize.CurrentRow.Cells["colHeight"].Value);
  181. PaperWidth =
  182. System.Convert.ToSingle(dgrdPaperSize.CurrentRow.Cells["colWidth"].Value);
  183. }
  184. }
  185. /// <summary>
  186. /// 列表失去焦点事件
  187. /// </summary>
  188. /// <param name="sender"></param>
  189. /// <param name="e"></param>
  190. private void dgrdPaperSize_Leave(object sender, System.EventArgs e)
  191. {
  192. dgrdPaperSize.ClearSelection();
  193. }
  194. /// <summary>
  195. ///
  196. /// </summary>
  197. /// <param name="sender"></param>
  198. /// <param name="e"></param>
  199. private void btnOK_Click(object sender, System.EventArgs e)
  200. {
  201. try
  202. {
  203. // 判断票据类型输入是否正确
  204. if ("".Equals(this.scbGoodsType.Text.Trim()))
  205. {
  206. MessageBox.Show(string.Format("{0}是必须输入项目,请输入{0}。", "产品类别"), this.Text,
  207. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  208. this.scbGoodsType.Focus();
  209. return;
  210. }
  211. //// 判断票据类型输入是否正确
  212. //if (this.ftcLogo.SelectedValue == null)
  213. //{
  214. // MessageBox.Show(string.Format("{0}是必须输入项目,请输入{0}。", "产品商标"), this.Text,
  215. // MessageBoxButtons.OK, MessageBoxIcon.Warning);
  216. // this.ftcLogo.Focus();
  217. // return;
  218. //}
  219. // 判断票据名称输入是否正确
  220. if (string.IsNullOrEmpty(this.txtInvoiceName.Text.Trim()))
  221. {
  222. MessageBox.Show(string.Format("{0}是必须输入项目,请输入{0}。", "模板名称"), this.Text,
  223. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  224. this.txtInvoiceName.Focus();
  225. return;
  226. }
  227. // 判断系统是否存在相同的票据
  228. bool isExistSameInvoice = this.IsExistInvoice();
  229. // 存在相同的票据
  230. if (isExistSameInvoice)
  231. {
  232. MessageBox.Show(string.Format("不允许进行该操作,原因:{0}。", "在该产品类别和商标中已存在打印模板"), this.Text,
  233. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  234. this.scbGoodsType.Focus();
  235. return;
  236. }
  237. object objLogoID = this.ftcLogo.SelectedValue;
  238. int? logoid = null;
  239. if (objLogoID != null && objLogoID != DBNull.Value)
  240. {
  241. logoid = Convert.ToInt32(objLogoID);
  242. }
  243. // 给票据编辑画面赋值,并打开
  244. //xuwei modify 2019-11-20
  245. F_MST_012003 frmINV0301 = new F_MST_012003(scbGoodsType.SearchedPKMember,
  246. scbGoodsType.SearchedValue + "",
  247. scbGoodsType.SearchedText,
  248. logoid,
  249. this.ftcLogo.Text,
  250. this.PaperWidth,
  251. this.PaperHeight,
  252. this.txtInvoiceName.Text.Trim(),
  253. Convert.ToInt32(this.ddlPrintType.SelectedValue),
  254. this.txtRemark.Text.Trim());
  255. this.Hide();
  256. DialogResult dialogresult = frmINV0301.ShowDialog();
  257. if (DialogResult.OK == dialogresult)
  258. {
  259. this.DialogResult = DialogResult.OK;
  260. }
  261. else
  262. {
  263. this.DialogResult = DialogResult.Cancel;
  264. }
  265. this.Close();
  266. }
  267. catch (Exception ex)
  268. {
  269. // 对异常进行共通处理
  270. ExceptionManager.HandleEventException(this.ToString(),
  271. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  272. }
  273. }
  274. /// <summary>
  275. ///
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. private void btnCancel_Click(object sender, System.EventArgs e)
  280. {
  281. this.DialogResult = DialogResult.Cancel;
  282. this.Close();
  283. }
  284. /// <summary>
  285. /// 画面打开
  286. /// </summary>
  287. /// <param name="sender"></param>
  288. /// <param name="e"></param>
  289. private void F_MST_012002_Load(object sender, EventArgs e)
  290. {
  291. try
  292. {
  293. //加载 打印类型 xuwei begin 2019-11-20
  294. this.ddlPrintType.DisplayMember = "PRINTTYPENAME";
  295. this.ddlPrintType.ValueMember = "PRINTTYPEID";
  296. ClientRequestEntity ptCre = new ClientRequestEntity();
  297. ptCre.NameSpace = "PrintInfo";
  298. ptCre.Name = "GetPrintType";
  299. DataTable dtPrintType = SystemModuleProxy.Service.DoBarCodePrint(ptCre).Data.Tables[0];
  300. this.ddlPrintType.DataSource = dtPrintType;
  301. //加载 打印类型 xuwei end
  302. DataSet logoInfo = SystemModuleProxy.Service.GetLogoInfo();
  303. if (logoInfo != null && logoInfo.Tables.Count > 0)
  304. {
  305. this.ftcLogo.DataSource = logoInfo.Tables[0];
  306. this.ftcLogo.DisplayMember = "LogoNameCode";
  307. this.ftcLogo.ValueMember = "LogoID";
  308. }
  309. }
  310. catch (Exception ex)
  311. {
  312. // 对异常进行共通处理
  313. ExceptionManager.HandleEventException(this.ToString(),
  314. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  315. }
  316. }
  317. #endregion
  318. #region 重写方法
  319. #endregion
  320. #region 私有方法/函数
  321. /// <summary>
  322. /// 根据本机的打印机取得纸张的信息
  323. /// </summary>
  324. private void InitializePaperSize()
  325. {
  326. if (_paperSizes == null)
  327. {
  328. _paperSizes = new DataTable();
  329. _paperSizes.TableName = "PaperSizes";
  330. _paperSizes.Columns.Add("SizeName", typeof(string));
  331. _paperSizes.Columns.Add("Width", typeof(float));
  332. _paperSizes.Columns.Add("Height", typeof(float));
  333. }
  334. else
  335. {
  336. _paperSizes.Clear();
  337. }
  338. float height = 0;
  339. float width = 0;
  340. int index = 0;
  341. PrintDocument pd = new PrintDocument();
  342. foreach (PaperSize ps in pd.PrinterSettings.PaperSizes)
  343. {
  344. DataRow dataRow = _paperSizes.NewRow();
  345. height = Dongke.IBOSS.PRD.Basics.Library.Utility.Inch100ToMillimeter(ps.Height);
  346. width = Dongke.IBOSS.PRD.Basics.Library.Utility.Inch100ToMillimeter(ps.Width);
  347. dataRow[0] = string.Format("{0} {1:0}mm×{2:0}mm", ps.PaperName, width, height);
  348. dataRow[1] = Math.Round(width);
  349. dataRow[2] = Math.Round(height);
  350. _paperSizes.Rows.Add(dataRow);
  351. if (ps.PaperName.StartsWith("A4") && 210.0f.Equals(dataRow[1]) && 297.0f.Equals(dataRow[2]) && _indexA4 < 0)
  352. {
  353. _indexA4 = index;
  354. }
  355. index++;
  356. }
  357. dgrdPaperSize.DataSource = _paperSizes;
  358. }
  359. /// <summary>
  360. /// 判断系统是否存在相同的票据
  361. /// </summary>
  362. /// <returns>
  363. /// false:不存在
  364. /// true:存在
  365. /// </returns>
  366. private bool IsExistInvoice()
  367. {
  368. try
  369. {
  370. int? goodsTypeID = Convert.ToInt32(scbGoodsType.SearchedItem["GoodsTypeID"]);
  371. if (!goodsTypeID.HasValue)
  372. {
  373. return true;
  374. }
  375. //if (this.ftcLogo.SelectedValue == null)
  376. //{
  377. // return true;
  378. //}
  379. this._clientRequestEntity = new ClientRequestEntity();
  380. this._clientRequestEntity.NameSpace = "InvoiceLayout";
  381. this._clientRequestEntity.Name = "IsExistBarCodePrintLayout";
  382. this._clientRequestEntity.Properties["GoodsTypeID"] = goodsTypeID.Value;
  383. this._clientRequestEntity.Properties["LogoID"] = this.ftcLogo.SelectedValue;
  384. //xuwei add 2019-11-20
  385. this._clientRequestEntity.Properties["PrintType"] = this.ddlPrintType.SelectedValue;
  386. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  387. {
  388. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  389. }
  390. );
  391. return Convert.ToBoolean(sre.Result);
  392. }
  393. catch (Exception ex)
  394. {
  395. throw ex;
  396. }
  397. }
  398. #endregion
  399. }
  400. }