F_MST_012004.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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.Data;
  13. using System.Windows.Forms;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Client.CommonModule;
  16. using Dongke.IBOSS.PRD.WCF.DataModels;
  17. using Dongke.IBOSS.PRD.WCF.Proxys;
  18. using Dongke.WinForm.Controls;
  19. namespace Dongke.IBOSS.PRD.Client.Controls
  20. {
  21. public partial class F_MST_012004 : DKFormBase
  22. {
  23. #region 成员变量
  24. private ClientRequestEntity _clientRequestEntity = null;
  25. #endregion
  26. #region 属性
  27. /// <summary>
  28. /// 打开本窗体的来源窗体
  29. /// 1:另存为
  30. /// 2:导入
  31. /// 3:编辑
  32. /// </summary>
  33. public int FromForm
  34. {
  35. get;
  36. set;
  37. }
  38. /// <summary>
  39. /// 模板ID
  40. /// </summary>
  41. public int LayoutID
  42. {
  43. get;
  44. set;
  45. }
  46. /// <summary>
  47. /// 模板名
  48. /// </summary>
  49. public string LayoutName
  50. {
  51. get;
  52. set;
  53. }
  54. /// <summary>
  55. /// 产品类别ID
  56. /// </summary>
  57. public int GoodsTypeID
  58. {
  59. get;
  60. set;
  61. }
  62. /// <summary>
  63. /// 产品类别编码
  64. /// </summary>
  65. public string GoodsTypeCode
  66. {
  67. get;
  68. set;
  69. }
  70. /// <summary>
  71. /// 产品类别名
  72. /// </summary>
  73. public string GoodsTypeName
  74. {
  75. get;
  76. set;
  77. }
  78. /// <summary>
  79. /// 产品商标ID
  80. /// </summary>
  81. public int? LogoID
  82. {
  83. get;
  84. set;
  85. }
  86. /// <summary>
  87. /// 产品商标Name
  88. /// </summary>
  89. public string LogoName
  90. {
  91. get;
  92. set;
  93. }
  94. /// <summary>
  95. /// 备注
  96. /// </summary>
  97. public string Remarks
  98. {
  99. get;
  100. set;
  101. }
  102. #endregion
  103. #region 构造函数
  104. /// <summary>
  105. /// 构造函数
  106. /// </summary>
  107. public F_MST_012004()
  108. {
  109. InitializeComponent();
  110. this.InitializeControlText();
  111. }
  112. #endregion
  113. #region 控件事件
  114. /// <summary>
  115. /// 页面加载事件
  116. /// </summary>
  117. /// <param name="sender"></param>
  118. /// <param name="e"></param>
  119. private void F_MST_012004_Load(object sender, System.EventArgs e)
  120. {
  121. try
  122. {
  123. if (1 == FromForm)
  124. {
  125. this.chkValueFlag.Checked = true;
  126. this.chkValueFlag.Visible = false;
  127. this.Text = "票据另存为...";
  128. DataSet logoInfo = SystemModuleProxy.Service.GetLogoInfo();
  129. if (logoInfo != null && logoInfo.Tables.Count > 0)
  130. {
  131. this.ftcLogo.DataSource = logoInfo.Tables[0];
  132. this.ftcLogo.DisplayMember = "LogoNameCode";
  133. this.ftcLogo.ValueMember = "LogoID";
  134. }
  135. if (this.LogoID.HasValue)
  136. {
  137. this.ftcLogo.SelectedValue = this.LogoID.Value;
  138. }
  139. else
  140. {
  141. this.ftcLogo.SelectedValue = DBNull.Value;
  142. }
  143. }
  144. else if (2 == FromForm)
  145. {
  146. this.chkValueFlag.Checked = true;
  147. this.chkValueFlag.Visible = false;
  148. this.txtInvoiceName.Text = this.LayoutName;
  149. this.Text = "导入票据";
  150. DataSet logoInfo = SystemModuleProxy.Service.GetLogoInfo();
  151. if (logoInfo != null && logoInfo.Tables.Count > 0)
  152. {
  153. this.ftcLogo.DataSource = logoInfo.Tables[0];
  154. this.ftcLogo.DisplayMember = "LogoNameCode";
  155. this.ftcLogo.ValueMember = "LogoID";
  156. }
  157. }
  158. else
  159. {
  160. this.Text = "编辑条码打印信息";
  161. this.chkValueFlag.Visible = true;
  162. DataSet logoInfo = SystemModuleProxy.Service.GetLogoInfo();
  163. if (logoInfo != null && logoInfo.Tables.Count > 0)
  164. {
  165. this.ftcLogo.DataSource = logoInfo.Tables[0];
  166. this.ftcLogo.DisplayMember = "LogoNameCode";
  167. this.ftcLogo.ValueMember = "LogoID";
  168. }
  169. ClientRequestEntity cre = new ClientRequestEntity();
  170. cre.NameSpace = "InvoiceLayout";
  171. cre.Name = "GetBarCodePrintLayoutInfo";
  172. cre.Properties["LayoutID"] = LayoutID;
  173. ServiceResultEntity sre = SystemModuleProxy.Service.DoBarCodePrint(cre);
  174. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
  175. {
  176. DataRow layout = sre.Data.Tables[0].Rows[0];
  177. //this.scbGoodsType.GoodsTypeID = Convert.ToInt32(layout["GoodsTypeID"]);
  178. //this.scbGoodsType.GoodsTypeCode = layout["GoodsTypeCode"].ToString();
  179. //this.scbGoodsType.GoodsTypeName = layout["GoodsTypeName"].ToString();
  180. this.scbGoodsType.CheckedData = sre.Data.Tables[0];
  181. this.scbGoodsType.Text = layout["GoodsTypeName"].ToString();
  182. this.txtInvoiceName.Text = layout["layoutName"].ToString();
  183. this.txtRemark.Text = layout["Remarks"].ToString();
  184. this.chkValueFlag.Checked = (layout["valueflag"].ToString() == "1");
  185. //if (this.LogoID.HasValue)
  186. //{
  187. // this.ftcLogo.SelectedValue = this.LogoID.Value;
  188. //}
  189. //else
  190. //{
  191. // this.ftcLogo.SelectedValue = DBNull.Value;
  192. //}
  193. this.ftcLogo.InitValue(layout["LogoNameCode"].ToString(), layout["LogoID"]);
  194. }
  195. }
  196. }
  197. catch (Exception ex)
  198. {
  199. // 对异常进行共通处理
  200. ExceptionManager.HandleEventException(this.ToString(),
  201. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  202. }
  203. }
  204. /// <summary>
  205. /// 确定按钮按下
  206. /// </summary>
  207. /// <param name="sender"></param>
  208. /// <param name="e"></param>
  209. private void btnOK_Click(object sender, EventArgs e)
  210. {
  211. try
  212. {
  213. // 判断票据类型输入是否正确
  214. if ("".Equals(this.scbGoodsType.Text.Trim()))
  215. {
  216. MessageBox.Show(string.Format("{0}是必须输入项目,请输入{0}。", "产品类别"), this.Text,
  217. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  218. this.scbGoodsType.Focus();
  219. return;
  220. }
  221. //// 判断票据类型输入是否正确
  222. //if (this.ftcLogo.SelectedValue == null)
  223. //{
  224. // MessageBox.Show(string.Format("{0}是必须输入项目,请输入{0}。", "产品商标"), this.Text,
  225. // MessageBoxButtons.OK, MessageBoxIcon.Warning);
  226. // this.ftcLogo.Focus();
  227. // return;
  228. //}
  229. // 判断票据名称输入是否正确
  230. if (string.IsNullOrEmpty(this.txtInvoiceName.Text.Trim()))
  231. {
  232. MessageBox.Show(string.Format("{0}是必须输入项目,请输入{0}。", "模板名称"), this.Text,
  233. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  234. this.txtInvoiceName.Focus();
  235. return;
  236. }
  237. // 判断系统是否存在相同的票据
  238. bool isExistSameInvoice = this.IsExistInvoice();
  239. // 存在相同的票据
  240. if (isExistSameInvoice)
  241. {
  242. MessageBox.Show(string.Format("不允许进行该操作,原因:{0}。", "在该产品类别和商标中已存在打印模板"), this.Text,
  243. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  244. this.scbGoodsType.Focus();
  245. return;
  246. }
  247. // 导入
  248. if (this.FromForm == 2)
  249. {
  250. }
  251. // 编辑
  252. else if (this.FromForm == 3)
  253. {
  254. ServiceResultEntity result = this.SaveEditLayout();
  255. if (result.Status == Dongke.IBOSS.PRD.Basics.BaseResources.Constant.ServiceResultStatus.Success)
  256. {
  257. MessageBox.Show(string.Format("{0}的{1}操作成功完成了。", "编辑条码打印信息", "保存"),
  258. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  259. this.DialogResult = DialogResult.OK;
  260. this.Close();
  261. }
  262. }
  263. // 另存为
  264. else
  265. {
  266. this.GoodsTypeID = scbGoodsType.SearchedPKMember;
  267. this.GoodsTypeCode = scbGoodsType.SearchedValue + "";
  268. this.GoodsTypeName = scbGoodsType.SearchedText;
  269. this.LayoutName = this.txtInvoiceName.Text.Trim();
  270. this.Remarks = this.txtRemark.Text.Trim();
  271. object objLogoID = this.ftcLogo.SelectedValue;
  272. if (objLogoID != null && objLogoID != DBNull.Value)
  273. {
  274. this.LogoID = Convert.ToInt32(objLogoID);
  275. }
  276. else
  277. {
  278. this.LogoID = null;
  279. }
  280. this.LogoName = this.ftcLogo.Text.Trim();
  281. this.DialogResult = DialogResult.OK;
  282. }
  283. }
  284. catch (Exception ex)
  285. {
  286. // 对异常进行共通处理
  287. ExceptionManager.HandleEventException(this.ToString(),
  288. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  289. }
  290. }
  291. /// <summary>
  292. /// 取消按钮按下
  293. /// </summary>
  294. /// <param name="sender"></param>
  295. /// <param name="e"></param>
  296. private void btnCancel_Click(object sender, EventArgs e)
  297. {
  298. this.DialogResult = DialogResult.Cancel;
  299. this.Close();
  300. }
  301. #endregion
  302. #region 私有方法或者函数
  303. /// <summary>
  304. /// 页面初始化给各控件文本赋值
  305. /// </summary>
  306. private void InitializeControlText()
  307. {
  308. // 设置控件的文本内容
  309. this.btnOK.Text = ButtonText.BTN_OK;
  310. this.btnCancel.Text = ButtonText.BTN_CANCEL;
  311. }
  312. /// <summary>
  313. /// 判断系统是否存在相同的票据
  314. /// </summary>
  315. /// <returns>
  316. /// false:不存在
  317. /// true:存在
  318. /// </returns>
  319. private bool IsExistInvoice()
  320. {
  321. try
  322. {
  323. int? goodsTypeID = Convert.ToInt32(scbGoodsType.SearchedItem["GoodsTypeID"]);
  324. if (!goodsTypeID.HasValue)
  325. {
  326. return true;
  327. }
  328. object value = this.ftcLogo.SelectedValue;
  329. //if (value == null)
  330. //{
  331. // return true;
  332. //}
  333. this._clientRequestEntity = new ClientRequestEntity();
  334. this._clientRequestEntity.NameSpace = "InvoiceLayout";
  335. this._clientRequestEntity.Name = "IsExistBarCodePrintLayout";
  336. this._clientRequestEntity.Properties["GoodsTypeID"] = goodsTypeID.Value;
  337. this._clientRequestEntity.Properties["layoutid"] = LayoutID;
  338. this._clientRequestEntity.Properties["LogoID"] = value;
  339. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  340. {
  341. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  342. }
  343. );
  344. return Convert.ToBoolean(sre.Result);
  345. }
  346. catch (Exception ex)
  347. {
  348. throw ex;
  349. }
  350. }
  351. /// <summary>
  352. /// 编辑新建票据数据
  353. /// </summary>
  354. /// <returns>
  355. /// 0:保存失败
  356. /// 其他:保存成功返回新建票据ID
  357. /// </returns>
  358. private ServiceResultEntity SaveEditLayout()
  359. {
  360. try
  361. {
  362. this._clientRequestEntity = new ClientRequestEntity();
  363. this._clientRequestEntity.NameSpace = "InvoiceLayout";
  364. this._clientRequestEntity.Name = "SaveEditBarCodePrintLayoutInfo";
  365. this._clientRequestEntity.Properties["LayoutID"] = LayoutID;
  366. this._clientRequestEntity.Properties["LayoutName"] = this.txtInvoiceName.Text.Trim();
  367. this._clientRequestEntity.Properties["Remarks"] = this.txtRemark.Text.Trim();
  368. this._clientRequestEntity.Properties["LogoID"] = this.ftcLogo.SelectedValue;
  369. this._clientRequestEntity.Properties["GoodsTypeID"] = scbGoodsType.SearchedPKMember;
  370. this._clientRequestEntity.Properties["GoodsTypeCode"] = scbGoodsType.SearchedValue;
  371. this._clientRequestEntity.Properties["GoodsTypeName"] = scbGoodsType.SearchedText;
  372. // 正常标识
  373. if (this.chkValueFlag.Checked)
  374. {
  375. this._clientRequestEntity.Properties["ValueFlag"] = "1";
  376. }
  377. else
  378. {
  379. this._clientRequestEntity.Properties["ValueFlag"] = "0";
  380. }
  381. // 编辑
  382. ServiceResultEntity result = this.DoAsync<ServiceResultEntity>(() =>
  383. {
  384. return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity);
  385. });
  386. return result;
  387. }
  388. catch (Exception ex)
  389. {
  390. throw ex;
  391. }
  392. }
  393. #endregion
  394. private bool _canChangedText = true;
  395. private void txtInvoiceName_TextChanged(object sender, EventArgs e)
  396. {
  397. this._canChangedText = false;
  398. }
  399. /// <summary>
  400. /// 产品类别改变事件
  401. /// </summary>
  402. /// <param name="sender"></param>
  403. /// <param name="e"></param>
  404. private void scbGoodsType_SearchedItemChanged(object sender, EventArgs e)
  405. {
  406. if (this.FromForm == 1 && this._canChangedText)
  407. {
  408. this.txtInvoiceName.Text = this.scbGoodsType.Text
  409. + "【" + this.ftcLogo.Text + "】";
  410. this._canChangedText = true;
  411. }
  412. }
  413. private void ftcLogo_SelectedIndexChanged(object sender, EventArgs e)
  414. {
  415. if (this.FromForm == 1 && this._canChangedText)
  416. {
  417. this.txtInvoiceName.Text = this.scbGoodsType.Text
  418. + "【" + this.ftcLogo.Text + "】";
  419. this._canChangedText = true;
  420. }
  421. }
  422. }
  423. }