F_MST_012002.cs 13 KB

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