DlgInvoicePrint.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Collections;
  9. using System.Windows.Forms;
  10. using CoreFS.CA06;
  11. using Infragistics.Win.UltraWinGrid;
  12. using Infragistics.Win;
  13. using SaleBusiness = Core.StlMes.Client.Sale.BLL.SaleBusinessMgt;
  14. namespace Core.StlMes.Client.Sale.UI.Balance.BalanceAccount
  15. {
  16. public partial class DlgInvoicePrint : Form
  17. {
  18. private Core.StlMes.Client.Sale.BLL.SaleBusinessMgt.Balance.SlmBalanceInfo slmBalanceInfo = null;
  19. public DlgInvoicePrint(CoreFS.CA06.OpeBase ob)
  20. {
  21. this._ob = ob;
  22. InitializeComponent();
  23. }
  24. private CoreFS.CA06.OpeBase _ob = null;
  25. public List<string> listInvoiceNo = null;
  26. public Boolean isOrgInvoice = false;
  27. private int _RowCount = 0;
  28. private void DlgInvoicePrint_Load(object sender, EventArgs e)
  29. {
  30. this.MaximizeBox = false;
  31. this.ultraGrid1.DisplayLayout.Override.RowSelectors = DefaultableBoolean.False;
  32. this.ultraGrid1.DisplayLayout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.None;
  33. slmBalanceInfo = new Core.StlMes.Client.Sale.BLL.SaleBusinessMgt.Balance.SlmBalanceInfo(this._ob);
  34. if (!isOrgInvoice)
  35. this.InitData();
  36. else
  37. this.InitDataOrg();
  38. }
  39. /// <summary>
  40. /// 设置首次结算单位
  41. /// </summary>
  42. /// <returns></returns>
  43. private Hashtable GetFST_DRAWEE_UNIT()
  44. {
  45. Hashtable hs = new Hashtable();
  46. //天津钢管集团股份有限公司
  47. hs.Add("120603", new CompanyAddressAndTaxNum("天津钢管集团股份有限公司", " ", " ", " "));
  48. hs.Add("120604", new CompanyAddressAndTaxNum("天津钢管钢铁贸易有限公司", " ", " ", " "));
  49. hs.Add("120605", new CompanyAddressAndTaxNum("天津钢管国际贸易有限公司", " ", " ", " "));
  50. hs.Add("120606", new CompanyAddressAndTaxNum("天津钢管制造有限公司", " ", " ", " "));
  51. return hs;
  52. }
  53. class CompanyAddressAndTaxNum
  54. {
  55. private string _BUYERNAME = "";
  56. private string _TAXNO = "";
  57. private string _ADDRESS = "";
  58. private string _ACCOUNT = "";
  59. public CompanyAddressAndTaxNum(string buyername, string taxno, string address, string account)
  60. {
  61. this._BUYERNAME = buyername;
  62. this._TAXNO = taxno;
  63. this._ADDRESS = address;
  64. this._ACCOUNT = account;
  65. }
  66. public string BUYERNAME
  67. {
  68. get
  69. {
  70. return this._BUYERNAME;
  71. }
  72. set
  73. {
  74. this._BUYERNAME = value;
  75. }
  76. }
  77. public string TAXNO
  78. {
  79. get
  80. {
  81. return this._TAXNO;
  82. }
  83. set
  84. {
  85. this._TAXNO = value;
  86. }
  87. }
  88. public string ADDRESS
  89. {
  90. get
  91. {
  92. return this._ADDRESS;
  93. }
  94. set
  95. {
  96. this._ADDRESS = value;
  97. }
  98. }
  99. public string ACCOUNT
  100. {
  101. get
  102. {
  103. return this._ACCOUNT;
  104. }
  105. set
  106. {
  107. this._ACCOUNT = value;
  108. }
  109. }
  110. }
  111. private void InitDataOrg()
  112. {
  113. string INVOICENOZ = "INVOICENOZ";
  114. string INVOICENO = "INVOICENO";
  115. string firstInviceCmp = "FST_DRAWEE_UNIT";
  116. string firstInviceCmpValue = "";
  117. DataSet ds = this.slmBalanceInfo.GetInvoicedSlmBalanceInfoByListInvoiceNoOrg(listInvoiceNo);
  118. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  119. return;
  120. Hashtable hsCmp = GetFST_DRAWEE_UNIT();
  121. Hashtable hs = new Hashtable();
  122. Hashtable hsdetail = new Hashtable();
  123. System.Collections.Generic.List<DataRow> listrow = new System.Collections.Generic.List<DataRow>();
  124. foreach (DataRow dr in ds.Tables[0].Rows)
  125. {
  126. // string invoiceno = dr[INVOICENO].ToString();
  127. if (dr[firstInviceCmp].ToString() == "120603" || dr[firstInviceCmp].ToString() == "120604" || dr[firstInviceCmp].ToString() == "120605")
  128. {
  129. string invoicenoz = dr[INVOICENOZ].ToString();
  130. if (hs.ContainsKey(invoicenoz))
  131. {
  132. listrow = (List<DataRow>)hs[invoicenoz];
  133. hs.Remove(invoicenoz);
  134. }
  135. else
  136. {
  137. listrow = new List<DataRow>();
  138. }
  139. if (!listrow.Contains(dr))
  140. {
  141. listrow.Add(dr);
  142. }
  143. hs.Add(invoicenoz, listrow);
  144. }
  145. }
  146. Hashtable hsrows = new Hashtable();
  147. foreach (string s in hs.Keys)
  148. {
  149. listrow = (List<DataRow>)hs[s];
  150. DataRow ugrP = listrow[0];
  151. int rowIndex = 0;
  152. Infragistics.Win.UltraWinGrid.UltraGridRow ugrN = null; //新行
  153. DataRow ugrC = null;
  154. for (int j = 0; j < listrow.Count; j++)
  155. {
  156. if (j == 8) rowIndex = 0;
  157. ugrC = listrow[j];
  158. if (rowIndex == 0)
  159. {
  160. ugrN = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
  161. for (int k = 0; k < this.ultraGrid1.DisplayLayout.Bands[0].Columns.Count; k++)
  162. {
  163. ugrN.Cells[k].Value = this.ultraGrid1.DisplayLayout.Bands[0].Columns[k].DefaultCellValue;
  164. }
  165. // 首次受票人
  166. firstInviceCmpValue = ugrP[firstInviceCmp].ToString();
  167. // UnboundColumn36 buyername
  168. //UnboundColumn37 taxno
  169. // UnboundColumn38 address and phone
  170. // UnboundColumn39 bank account
  171. CompanyAddressAndTaxNum cmp = (CompanyAddressAndTaxNum)hsCmp["120606"];
  172. ugrN.Cells["UnboundColumn36"].Value = cmp.BUYERNAME;
  173. ugrN.Cells["UnboundColumn37"].Value = cmp.TAXNO;
  174. ugrN.Cells["UnboundColumn38"].Value = cmp.ADDRESS;
  175. ugrN.Cells["UnboundColumn39"].Value = cmp.ACCOUNT;
  176. if (hsCmp.Contains(ugrP["BUYERCODE"].ToString()))
  177. {
  178. CompanyAddressAndTaxNum cmp1 = (CompanyAddressAndTaxNum)hsCmp[ugrP["BUYERCODE"].ToString()];
  179. ugrN.Cells[2].Value = cmp1.BUYERNAME;
  180. ugrN.Cells[3].Value = cmp1.TAXNO;
  181. ugrN.Cells[4].Value = cmp1.ADDRESS;
  182. ugrN.Cells[5].Value = cmp1.ACCOUNT;
  183. }
  184. ugrN.Cells[0].Value = ugrC["INVOICENO"].ToString().Split('.')[0];
  185. ugrN.Cells[1].Value = System.DateTime.Today.ToShortDateString();
  186. // ugrN.Cells[2].Value = ugrP["BUYERNAME"];
  187. // ugrN.Cells[3].Value = ugrP["TAXNO"];
  188. // ugrN.Cells[4].Value = ugrP["ADDRESS"];
  189. // ugrN.Cells[5].Value = ugrP["ACCOUNT"];
  190. ugrN.Cells[74].Value = ugrC["AUDITINGPERSON"];
  191. ugrN.Cells[75].Value = ugrC["INVOICEPERSON"];
  192. ugrN.Cells[72].Value = ugrC["REMARK"];
  193. }
  194. ugrN.Cells[6 + 8 * rowIndex].Value = ugrC["CATEGORY"] + " " + ugrC["STEELCODE"];
  195. ugrN.Cells[7 + 8 * rowIndex].Value = ugrC["SPEC"];
  196. ugrN.Cells[8 + 8 * rowIndex].Value = "吨";
  197. ugrN.Cells[9 + 8 * rowIndex].Value = ugrC["WEIGHT"];
  198. ugrN.Cells[10 + 8 * rowIndex].Value = ugrC["PRICE"];
  199. ugrN.Cells[11 + 8 * rowIndex].Value = ugrC["MONEY"].ToString();
  200. // ugrN.Cells[11 + 8 * rowIndex].Value = System.Math.Round(GetNoNullDec(ugrC["MONEY"]) / 1.16, 2);
  201. // ugrN.Cells[12 + 8 * rowIndex].Value = "17%";
  202. // ugrN.Cells[13 + 8 * rowIndex].Value = ugrC["TAXMONEY"];
  203. if (rowIndex == 7 || j == listrow.Count - 1)
  204. {
  205. double fl1 = GetTotalMoney(ugrN);
  206. double fl2 = 0;
  207. double fl3 = fl1 + fl2;
  208. ugrN.Cells["UnboundColumn26"].Value = "¥" + Convert.ToString(fl1);
  209. // ugrN.Cells["UnboundColumn28"].Value = "¥" + Convert.ToString(fl2);
  210. ugrN.Cells[70].Value = "¥" + Util.ConverObject.ConvertNumberToChinese(Convert.ToString((int)(Math.Round(fl3 * 100))));
  211. ugrN.Cells[71].Value = "¥" + Convert.ToString(fl3);
  212. ugrN.Cells["UnboundColumn24"].Value = this.GetTotalWeight(ugrN);
  213. }
  214. rowIndex++;
  215. }
  216. }
  217. this.ultraGrid1.UpdateData();
  218. _RowCount = this.ultraGrid1.Rows.Count;
  219. if (this.ultraGrid1.Rows.Count > 0) this.ultraGrid1.Rows[0].Activate();
  220. this.ultraMaskedEdit2.InputMask = string.Format(@"nnn \o\f\ \{0}", _RowCount.ToString());
  221. this.ultraMaskedEdit2.Text = string.Format("1 of {0}", _RowCount.ToString());
  222. }
  223. private void InitData()
  224. {
  225. string INVOICENOZ = "INVOICENOZ";
  226. string INVOICENO = "INVOICENO";
  227. string firstInviceCmp = "FST_DRAWEE_UNIT";
  228. string firstInviceCmpValue = "";
  229. DataSet ds = this.slmBalanceInfo.GetInvoicedSlmBalanceInfoByListInvoiceNo(listInvoiceNo);
  230. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  231. return;
  232. Hashtable hsCmp = GetFST_DRAWEE_UNIT();
  233. Hashtable hs = new Hashtable();
  234. Hashtable hsdetail = new Hashtable();
  235. System.Collections.Generic.List<DataRow> listrow = new System.Collections.Generic.List<DataRow>();
  236. foreach (DataRow dr in ds.Tables[0].Rows)
  237. {
  238. // string invoiceno = dr[INVOICENO].ToString();
  239. string invoicenoz = dr[INVOICENOZ].ToString();
  240. if (hs.ContainsKey(invoicenoz))
  241. {
  242. listrow = (List<DataRow>)hs[invoicenoz];
  243. hs.Remove(invoicenoz);
  244. }
  245. else
  246. {
  247. listrow = new List<DataRow>();
  248. }
  249. if (!listrow.Contains(dr))
  250. {
  251. listrow.Add(dr);
  252. }
  253. hs.Add(invoicenoz, listrow);
  254. }
  255. Hashtable hsrows = new Hashtable();
  256. foreach (string s in hs.Keys)
  257. {
  258. listrow = (List<DataRow>)hs[s];
  259. DataRow ugrP = listrow[0];
  260. int rowIndex = 0;
  261. Infragistics.Win.UltraWinGrid.UltraGridRow ugrN = null; //新行
  262. DataRow ugrC = null;
  263. for (int j = 0; j < listrow.Count; j++)
  264. {
  265. if (j == 8) rowIndex = 0;
  266. ugrC = listrow[j];
  267. if (rowIndex == 0)
  268. {
  269. ugrN = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
  270. for (int k = 0; k < this.ultraGrid1.DisplayLayout.Bands[0].Columns.Count; k++)
  271. {
  272. ugrN.Cells[k].Value = this.ultraGrid1.DisplayLayout.Bands[0].Columns[k].DefaultCellValue;
  273. }
  274. // 首次受票人
  275. firstInviceCmpValue = ugrP[firstInviceCmp].ToString();
  276. // UnboundColumn36 buyername
  277. //UnboundColumn37 taxno
  278. // UnboundColumn38 address and phone
  279. // UnboundColumn39 bank account
  280. if (hsCmp.ContainsKey(firstInviceCmpValue))
  281. {
  282. CompanyAddressAndTaxNum cmp = (CompanyAddressAndTaxNum)hsCmp[firstInviceCmpValue];
  283. ugrN.Cells["UnboundColumn36"].Value = cmp.BUYERNAME;
  284. ugrN.Cells["UnboundColumn37"].Value = cmp.TAXNO;
  285. ugrN.Cells["UnboundColumn38"].Value = cmp.ADDRESS;
  286. ugrN.Cells["UnboundColumn39"].Value = cmp.ACCOUNT;
  287. }
  288. else
  289. {
  290. continue;
  291. }
  292. ugrN.Cells[0].Value = ugrC["INVOICENO"].ToString().Split('.')[0];
  293. ugrN.Cells[1].Value = System.DateTime.Today.ToShortDateString();
  294. ugrN.Cells[2].Value = ugrP["BUYERNAME"];
  295. ugrN.Cells[3].Value = ugrP["TAXNO"];
  296. ugrN.Cells[4].Value = ugrP["ADDRESS"];
  297. ugrN.Cells[5].Value = ugrP["ACCOUNT"];
  298. ugrN.Cells[74].Value = ugrC["AUDITINGPERSON"];
  299. ugrN.Cells[75].Value = ugrC["INVOICEPERSON"];
  300. ugrN.Cells[72].Value = ugrC["REMARK"];
  301. }
  302. ugrN.Cells[6 + 8 * rowIndex].Value = ugrC["CATEGORY"] + " " + ugrC["STEELCODE"];
  303. ugrN.Cells[7 + 8 * rowIndex].Value = ugrC["SPEC"];
  304. ugrN.Cells[8 + 8 * rowIndex].Value = "吨";
  305. ugrN.Cells[9 + 8 * rowIndex].Value = ugrC["WEIGHT"];
  306. ugrN.Cells[10 + 8 * rowIndex].Value = ugrC["PRICE"];
  307. // ugrN.Cells[11 + 8 * rowIndex].Value = System.Math.Round(GetNoNullDec(ugrC["MONEY"]) / 1.16, 2);
  308. ugrN.Cells[11 + 8 * rowIndex].Value = ugrC["MONEY"].ToString();
  309. // ugrN.Cells[12 + 8 * rowIndex].Value = "17%";
  310. // ugrN.Cells[13 + 8 * rowIndex].Value = ugrC["TAXMONEY"];
  311. if (rowIndex == 7 || j == listrow.Count - 1)
  312. {
  313. double fl1 = GetTotalMoney(ugrN);
  314. // float fl2 = GetTotalTax(fl1);
  315. double fl2 = 0;
  316. double fl3 = fl1 + fl2;
  317. ugrN.Cells["UnboundColumn26"].Value = "¥" + Convert.ToString(fl1);
  318. // ugrN.Cells["UnboundColumn28"].Value = "¥" + Convert.ToString(fl2);
  319. ugrN.Cells[70].Value = "¥" + Util.ConverObject.ConvertNumberToChinese(Convert.ToString((int)(Math.Round(fl3 * 100))));
  320. ugrN.Cells[71].Value = "¥" + Convert.ToString(fl3);
  321. ugrN.Cells["UnboundColumn24"].Value = this.GetTotalWeight(ugrN);
  322. }
  323. rowIndex++;
  324. }
  325. }
  326. this.ultraGrid1.UpdateData();
  327. _RowCount = this.ultraGrid1.Rows.Count;
  328. if (this.ultraGrid1.Rows.Count > 0) this.ultraGrid1.Rows[0].Activate();
  329. this.ultraMaskedEdit2.InputMask = string.Format(@"nnn \o\f\ \{0}", _RowCount.ToString());
  330. this.ultraMaskedEdit2.Text = string.Format("1 of {0}", _RowCount.ToString());
  331. }
  332. private float GetNoNullDec(object obj)
  333. {
  334. if (obj == null || obj == DBNull.Value) return 0;
  335. try
  336. {
  337. return Convert.ToSingle(obj);
  338. }
  339. catch
  340. {
  341. return 0;
  342. }
  343. }
  344. private double GetTotalMoney(Infragistics.Win.UltraWinGrid.UltraGridRow ugr)
  345. {
  346. double fl = 0;
  347. double fl1 = 0;
  348. for (int i = 0; i < 8; i++)
  349. {
  350. if (ugr.Cells[11 + 8 * i].Value == null) continue;
  351. try
  352. {
  353. fl1 = Convert.ToDouble(ugr.Cells[11 + 8 * i].Value);
  354. }
  355. catch
  356. {
  357. fl1 = 0;
  358. }
  359. fl += fl1;
  360. }
  361. return fl;
  362. }
  363. private float GetTotalWeight(Infragistics.Win.UltraWinGrid.UltraGridRow ugr)
  364. {
  365. float fl = 0;
  366. float fl1 = 0;
  367. for (int i = 0; i < 8; i++)
  368. {
  369. if (ugr.Cells[11 + 8 * i].Value == null) continue;
  370. try
  371. {
  372. fl1 = Convert.ToSingle(ugr.Cells[9 + 8 * i].Value);
  373. }
  374. catch
  375. {
  376. fl1 = 0;
  377. }
  378. fl += fl1;
  379. }
  380. return fl;
  381. }
  382. private float GetTotalTax(float fl)
  383. {
  384. float fl1 = (float)0.13;
  385. fl = fl * fl1;
  386. return fl;
  387. }
  388. private void Init()
  389. {
  390. Infragistics.Win.UltraWinGrid.UltraGridRow ugr = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
  391. ugr.Cells["UnboundColumn5"].Value = "开票日期";
  392. }
  393. private void button2_Click(object sender, EventArgs e)
  394. {
  395. this.Close();
  396. }
  397. private void button1_Click(object sender, EventArgs e)
  398. {
  399. this.DialogResult = DialogResult.OK;
  400. this.ultraPrintPreviewDialog1.ShowDialog();
  401. }
  402. private void ultraMaskedEdit2_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  403. {
  404. int min = (int)this.ultraMaskedEdit2.MinValue;
  405. int max = (int)this.ultraMaskedEdit2.MaxValue;
  406. int newValue = min;
  407. EditorWithMask maskEdit = e.Button.Editor as EditorWithMask;
  408. try
  409. {
  410. string maskText = maskEdit.GetText(Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw);
  411. if (!Convert.IsDBNull(maskText))
  412. newValue = int.Parse(maskText);
  413. }
  414. catch { }
  415. switch (e.Button.Key)
  416. {
  417. case "First":
  418. newValue = min;
  419. break;
  420. case "Last":
  421. newValue = max;
  422. break;
  423. case "Next":
  424. newValue++;
  425. break;
  426. case "Previous":
  427. newValue--;
  428. break;
  429. }
  430. if (newValue < 1)
  431. newValue = 1;
  432. else if (newValue > _RowCount)
  433. newValue = _RowCount;
  434. e.Button.Editor.Value = newValue;
  435. this.ultraGrid1.Rows[newValue - 1].Activate();
  436. }
  437. private void button3_Click(object sender, EventArgs e)
  438. {
  439. Util.UtilUltraGrid.ExportGridDataToExcel(this.Text, this.ultraGrid1);
  440. }
  441. }
  442. }