FrmCustReceivableQuery.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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.Windows.Forms;
  9. using Infragistics.Win.UltraWinGrid;
  10. namespace Core.StlMes.Client.Sale.SaleFundMgt.FundUI.UIFrm
  11. {
  12. public partial class FrmCustReceivableQuery : FrmFundBase
  13. {
  14. public FrmCustReceivableQuery()
  15. {
  16. InitializeComponent();
  17. }
  18. private DataSet dsOne = new DataSet();
  19. private DataSet dsTwo = new DataSet();
  20. private DataSet dsThree = new DataSet();
  21. FundBLL.ValueList.PubValueList PubValueList = null;
  22. private void FrmCustReceivableQuery_Load(object sender, EventArgs e)
  23. {
  24. this.checkBox1.Checked = true;
  25. this.dateTimePicker2.Format = DateTimePickerFormat.Custom;
  26. this.dateTimePicker2.CustomFormat = "yyyyMM";
  27. PubValueList = new Core.StlMes.Client.Sale.SaleFundMgt.FundBLL.ValueList.PubValueList(this.ob);
  28. dsOne = base.GetDataSetByColumnName(GetDataOneStruct(), null, GetColumnCaption());
  29. this.ultraGrid1.DataSource = dsOne;
  30. dsTwo = base.GetDataSetByColumnName(this.GetDataTwoStruct(), null, GetColumnCaption());
  31. this.ultraGrid2.DataSource = dsTwo;
  32. dsThree = base.GetDataSetByColumnName(this.GetDataThreeStruct(), null, GetColumnCaption());
  33. this.ultraGrid2.DataSource = dsThree;
  34. // this.ultraGrid3.DataSource = dsThree;
  35. base.SetGridStyle(ref this.ultraGrid1, ref this.ultraGrid2);
  36. HIddenColumn();
  37. Init();
  38. }
  39. private void Init()
  40. {
  41. try
  42. {
  43. this.ultraGrid1.DisplayLayout.Bands[0].Columns["BUYERCODE"].ValueList
  44. = PubValueList.GetCustomerInfo();
  45. }
  46. catch
  47. { }
  48. foreach (string s in GetNumberFormatColumn())
  49. {
  50. try
  51. {
  52. string input = "-nn,nnn,nnn.nnnn";
  53. if (s == "WEIGHT")
  54. {
  55. input = "-nn,nnn,nnn.nnn";
  56. }
  57. try
  58. { this.ultraGrid1.DisplayLayout.Bands[0].Columns[s].MaskInput = input; }
  59. catch
  60. { }
  61. try
  62. {
  63. this.ultraGrid2.DisplayLayout.Bands[0].Columns[s].MaskInput = input;
  64. }
  65. catch
  66. { }
  67. }
  68. catch
  69. {
  70. }
  71. }
  72. /*
  73. hs.Add("BUYERCODE", 180);
  74. hs.Add("PREMONEY", 80);
  75. hs.Add("CURMONEY", 80);
  76. hs.Add("CUR_RECEIVE_MONEY", 80);
  77. hs.Add("DE_MONEY", 90);
  78. hs.Add("SALE_AREA_DESC", 80);
  79. hs.Add("MONEY", 80);
  80. hs.Add("PACTNO", 100);
  81. hs.Add("WEIGHT", 80);
  82. */
  83. }
  84. private string[] GetNumberFormatColumn()
  85. {
  86. return new string[] { "PREMONEY", "CURMONEY", "CUR_RECEIVE_MONEY", "MONEY", "WEIGHT" };
  87. }
  88. private void HIddenColumn()
  89. {
  90. try
  91. {
  92. this.ultraGrid1.DisplayLayout.Bands[0].Columns["BALANCESUBJECT"].Hidden = true;
  93. this.ultraGrid2.DisplayLayout.Bands[0].Columns["BALANCESUBJECT"].Hidden = true;
  94. this.ultraGrid2.DisplayLayout.Bands[0].Columns["BUYERCODE"].Hidden = true;
  95. //this.ultraGrid3.DisplayLayout.Bands[0].Columns["BALANCESUBJECT"].Hidden = true;
  96. //this.ultraGrid3.DisplayLayout.Bands[0].Columns["BUYERCODE"].Hidden = true;
  97. //this.ultraGrid3.DisplayLayout.Bands[0].Columns["SALE_AREA_DESC"].Hidden = true;
  98. }
  99. catch
  100. { }
  101. }
  102. public override void ToolBar_Click(object sender, string ToolbarKey)
  103. {
  104. if (ToolbarKey == "Query")
  105. {
  106. this.Query();
  107. }
  108. if (ToolbarKey == "Close")
  109. {
  110. this.Close();
  111. }
  112. if (ToolbarKey == "Export")
  113. {
  114. Core.StlMes.Client.Sale.Util.UtilUltraGrid.ExportGridDataToExcel(this.Text, this.ultraGrid1);
  115. }
  116. }
  117. private string month = "201509";
  118. private DataSet dsInvoice = null;
  119. private void Query()
  120. {
  121. this.month = this.dateTimePicker2.Value.ToString("yyyyMM");
  122. DataSet ds = this.GetDataSetOne();
  123. DeleteZeroRecords(ref ds);
  124. Core.StlMes.Client.Sale.Util.UtilDataSet.SetDataSetByMergeSameColumnName(ref dsOne, ds);
  125. }
  126. private void DeleteZeroRecords(ref DataSet ds)
  127. {
  128. if(ds == null ||ds.Tables.Count == 0|| ds.Tables[0].Rows.Count == 0)
  129. {
  130. return;
  131. }
  132. foreach(DataRow dr in ds.Tables[0].Rows)
  133. {
  134. if (Core.StlMes.Client.Sale.Util.ConverObject.ConvertToDouble(dr["PREMONEY"]) == 0
  135. && Core.StlMes.Client.Sale.Util.ConverObject.ConvertToDouble(dr["CURMONEY"]) == 0
  136. && Core.StlMes.Client.Sale.Util.ConverObject.ConvertToDouble(dr["CUR_RECEIVE_MONEY"]) == 0
  137. && Core.StlMes.Client.Sale.Util.ConverObject.ConvertToDouble(dr["DE_MONEY"]) == 0
  138. )
  139. {
  140. dr.Delete();
  141. }
  142. }
  143. ds.AcceptChanges();
  144. }
  145. private void QueryTwo()
  146. {
  147. this.dsTwo.Clear();
  148. this.dsThree.Clear();
  149. Infragistics.Win.UltraWinGrid.UltraGridRow ugr = null;
  150. if (this.ultraGrid1.Rows.Count == 0)
  151. return;
  152. if (this.ultraGrid1.Rows.Count == 1)
  153. ugr = this.ultraGrid1.Rows[0];
  154. else
  155. ugr = this.ultraGrid1.ActiveRow;
  156. if (ugr == null)
  157. return;
  158. string balancesubjct = ugr.Cells["BALANCESUBJECT"].Value.ToString();
  159. string buyercode = ugr.Cells["BUYERCODE"].Value.ToString();
  160. DataSet ds = this.GetDataSetTwo(balancesubjct, buyercode);
  161. Core.StlMes.Client.Sale.Util.UtilDataSet.SetDataSetByMergeSameColumnName(ref dsTwo, ds);
  162. }
  163. private void QueryThree()
  164. {
  165. this.dsThree.Clear();
  166. Infragistics.Win.UltraWinGrid.UltraGridRow ugr = null;
  167. if (this.ultraGrid2.Rows.Count == 0)
  168. return;
  169. if (this.ultraGrid2.Rows.Count == 1)
  170. ugr = this.ultraGrid2.Rows[0];
  171. else
  172. ugr = this.ultraGrid2.ActiveRow;
  173. if (ugr == null)
  174. return;
  175. string balancesubjct = ugr.Cells["BALANCESUBJECT"].Value.ToString();
  176. string buyercode = ugr.Cells["BUYERCODE"].Value.ToString();
  177. string saleareadesc= ugr.Cells["SALE_AREA_DESC"].Value.ToString();
  178. DataSet ds = this.GetDataSetThree(balancesubjct, buyercode,saleareadesc);
  179. Core.StlMes.Client.Sale.Util.UtilDataSet.SetDataSetByMergeSameColumnName(ref dsThree, ds);
  180. }
  181. private void QueryThreeF()
  182. {
  183. this.dsThree.Clear();
  184. Infragistics.Win.UltraWinGrid.UltraGridRow ugr = null;
  185. if (this.ultraGrid1.Rows.Count == 0)
  186. return;
  187. if (this.ultraGrid1.Rows.Count == 1)
  188. ugr = this.ultraGrid1.Rows[0];
  189. else
  190. ugr = this.ultraGrid1.ActiveRow;
  191. if (ugr == null)
  192. return;
  193. string balancesubjct = ugr.Cells["BALANCESUBJECT"].Value.ToString();
  194. string buyercode = ugr.Cells["BUYERCODE"].Value.ToString();
  195. string saleareadesc = ugr.Cells["SECONDACCOUNT"].Value.ToString();
  196. DataSet ds = this.GetDataSetThree(balancesubjct, buyercode, saleareadesc);
  197. Core.StlMes.Client.Sale.Util.UtilDataSet.SetDataSetByMergeSameColumnName(ref dsThree, ds);
  198. }
  199. private DataSet GetDataSetThree(string balancesubject, string buyercode,string sale_area)
  200. {
  201. string sql = @"select sum(a.weight) weight,
  202. sum(a.money) money,
  203. a.sale_area_desc,
  204. a.forecorpcode BALANCESUBJECT, a.buyercode,a.ord_no pactno
  205. from slm_balanceinfo a
  206. where a.balancestatus = '3'
  207. and a.invoicedate >= to_date('{3}', 'yyyymm')
  208. and a.invoicedate < last_day(to_date('{3}', 'yyyymm')) + 1
  209. and a.buyercode = '{0}' and forecorpcode = '{1}' and sale_area_desc = '{2}'
  210. group by a.sale_area_desc, a.forecorpcode, a.buyercode,a.ord_no";
  211. sql = string.Format(sql,buyercode,balancesubject,sale_area,this.month);
  212. DataSet ds = base.ExecuteReader(sql);
  213. return ds;
  214. }
  215. private DataSet GetDataSetTwo(string balancesubject,string buyercode)
  216. {
  217. string sql = @"select sum(a.weight) weight,
  218. sum(a.money) money,
  219. a.sale_area_desc , a.forecorpcode balancesubject, a.buyercode
  220. from slm_balanceinfo a
  221. where a.balancestatus = '3'
  222. and a.invoicedate >= to_date('{2}', 'yyyymm')
  223. and a.invoicedate < last_day(to_date('{2}', 'yyyymm')) + 1
  224. and a.buyercode = '{0}' and forecorpcode = '{1}'
  225. group by a.sale_area_desc, a.forecorpcode, a.buyercode";
  226. sql = string.Format(sql, buyercode, balancesubject, this.month);
  227. DataSet ds = base.ExecuteReader(sql);
  228. return ds;
  229. }
  230. private DataSet GetDataSetOne()
  231. {
  232. string sql = @" with t as (
  233. select b.balancesubject,
  234. b.buyercode,
  235. a.secondaccount,
  236. sum(case
  237. when a.inouttime < {1} then
  238. a.inoutmoney
  239. else
  240. 0
  241. end) inoutmoney,
  242. sum(case
  243. when a.inouttime >= {1} and a.inouttime < {2} then
  244. a.inoutmoney
  245. else
  246. 0
  247. end) curmoney
  248. from sel_fund_cust_account b
  249. left join sel_fund_cust_fundinout a on b.balancesubject =
  250. a.balancesubject
  251. and b.buyercode = a.buyercode
  252. where 1 = 1
  253. group by a.balancesubject, a.buyercode,b.balancesubject,
  254. b.buyercode, a.secondaccount
  255. ),
  256. b as
  257. (select sum(case
  258. when a.invoicedate < to_date('{0}', 'yyyymm') then
  259. a.weight
  260. else
  261. 0
  262. end) tolweight,
  263. sum(case
  264. when a.invoicedate < to_date('{0}', 'yyyymm') then
  265. a.money
  266. else
  267. 0
  268. end) tolmoney,
  269. sum(case
  270. when a.invoicedate >= to_date('{0}', 'yyyymm') and
  271. a.invoicedate < last_day(to_date('{0}', 'yyyymm')) + 1 then
  272. a.weight
  273. else
  274. 0
  275. end) curtolweight,
  276. sum(case
  277. when a.invoicedate >= to_date('{0}', 'yyyymm') and
  278. a.invoicedate < last_day(to_date('{0}', 'yyyymm')) + 1 then
  279. a.money
  280. else
  281. 0
  282. end) curtolmoney,
  283. a.ord_no,
  284. a.sale_area_desc,
  285. a.forecorpcode,
  286. a.buyercode
  287. from slm_balanceinfo a
  288. where a.balancestatus = '3'
  289. group by a.ord_no, a.sale_area_desc, a.forecorpcode, a.buyercode)
  290. select t.balancesubject,t.buyercode,t.secondaccount,nvl(t.inoutmoney,0) - nvl(b.tolmoney,0) premoney,nvl(t.curmoney,0)curmoney,
  291. nvl(b.curtolmoney,0) cur_receive_money ,
  292. nvl(t.inoutmoney,0) - nvl(b.tolmoney,0) + nvl(t.curmoney,0) - nvl(b.curtolmoney,0) de_money
  293. from t
  294. left join b
  295. on t.balancesubject = b.forecorpcode
  296. and t.buyercode = b.buyercode and t.secondaccount = b.sale_area_desc ";
  297. sql = string.Format(sql, this.month, string.Format(" to_date('{0}','yyyymm')", this.month), string.Format(" last_day(to_date('{0}','yyyymm')) + 1", this.month));
  298. DataSet ds = base.ExecuteReader(sql);
  299. return ds;
  300. }
  301. private System.Collections.Hashtable GetColumnCaption()
  302. {
  303. System.Collections.Hashtable hs = new System.Collections.Hashtable();
  304. hs.Add("BUYERCODE","结算单位");
  305. hs.Add("PREMONEY", "上月余款");
  306. hs.Add("CURMONEY", "本月回款");
  307. hs.Add("CUR_RECEIVE_MONEY", "本月应收");
  308. hs.Add("DE_MONEY", "差额");
  309. hs.Add("SALE_AREA_DESC", "销售区域");
  310. hs.Add("MONEY", "金额");
  311. hs.Add("PACTNO", "合同号");
  312. hs.Add("WEIGHT", "重量");
  313. hs.Add("SECONDACCOUNT", "二级帐户");
  314. return hs;
  315. }
  316. protected override List<string> GetNumberColumn()
  317. {
  318. return new List<string>(new string[]{
  319. "CURMONEY",
  320. "PREMONEY",
  321. "CUR_RECEIVE_MONEY",
  322. "DE_MONEY",
  323. "WEIGHT",
  324. "MONEY"
  325. });
  326. }
  327. protected override List<string> GetNumberTypeColulmn()
  328. {
  329. return new List<string>(new string[]{
  330. "CURMONEY",
  331. "PREMONEY",
  332. "CUR_RECEIVE_MONEY",
  333. "DE_MONEY",
  334. "WEIGHT",
  335. "MONEY"
  336. });
  337. }
  338. protected override System.Collections.Hashtable GetGridColumnLength()
  339. {
  340. System.Collections.Hashtable hs = new System.Collections.Hashtable();
  341. hs.Add("BUYERCODE", 180);
  342. hs.Add("PREMONEY", 80);
  343. hs.Add("CURMONEY", 80);
  344. hs.Add("CUR_RECEIVE_MONEY", 80);
  345. hs.Add("DE_MONEY", 90);
  346. hs.Add("SALE_AREA_DESC", 80);
  347. hs.Add("MONEY", 80);
  348. hs.Add("PACTNO", 100);
  349. hs.Add("WEIGHT", 80);
  350. return hs;
  351. }
  352. private string[] GetDataOneStruct()
  353. {
  354. return new string[]
  355. {
  356. "BALANCESUBJECT",
  357. "BUYERCODE",
  358. "SECONDACCOUNT",
  359. "PREMONEY",
  360. "CURMONEY",
  361. "CUR_RECEIVE_MONEY",
  362. "DE_MONEY"
  363. };
  364. }
  365. private string[] GetDataTwoStruct()
  366. {
  367. return new string[]
  368. {
  369. "BALANCESUBJECT",
  370. "BUYERCODE",
  371. "SALE_AREA_DESC",
  372. "MONEY"
  373. };
  374. }
  375. private string[] GetDataThreeStruct()
  376. {
  377. return new string[]
  378. {
  379. "BALANCESUBJECT",
  380. "BUYERCODE",
  381. "SALE_AREA_DESC",
  382. "PACTNO",
  383. "WEIGHT",
  384. "MONEY"
  385. };
  386. }
  387. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  388. {
  389. }
  390. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  391. {
  392. this.QueryThreeF();
  393. }
  394. private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
  395. {
  396. this.QueryThree();
  397. }
  398. }
  399. }