AnalyzedOrderFinanceOutlayFormMain.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. namespace LYFZ.Software.MainBusiness.DecisionAssistant
  10. {
  11. public partial class AnalyzedOrderFinanceOutlayFormMain : LYFZ.Software.UI.DecisionAssistant.AnalyzedOrderFinanceOutlayFormMain
  12. {
  13. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  14. public AnalyzedOrderFinanceOutlayFormMain()
  15. {
  16. this.Load += AnalyzedOrderFinanceOutlayFormMain_Load;
  17. this.Shown += AnalyzedOrderFinanceOutlayFormMain_Shown;
  18. this.chkComparedStartUp.Click += chkComparedStartUp_Click;
  19. this.btnQuery.Click += btnQuery_Click;
  20. this.btnQueryCompared.Click += btnQueryCompared_Click;
  21. this.btnSaveAs.Click += btnSaveAs_Click;
  22. this.btnCloseed.Click += btnCloseed_Click;
  23. this.Resize += AnalyzedOrderFinanceOutlayFormMain_Resize;
  24. }
  25. /// <summary>
  26. /// 窗体加载事件
  27. /// </summary>
  28. /// <param name="sender"></param>
  29. /// <param name="e"></param>
  30. void AnalyzedOrderFinanceOutlayFormMain_Load(object sender, EventArgs e)
  31. {
  32. this.numYear.Value = SDateTime.Now.Year;
  33. this.numYearCompared.Value = SDateTime.Now.Year - 1;
  34. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_SystemCategory("BFAGBGBAEJBACEEHJ", this.cmbtreevItmes, IsFirstNodeNull: true, IsFirstNodeName: "全部");
  35. this.cmbtreevItmes.TextFindTag("全部");
  36. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindGroupStoreName(this.cmbtreevStoreName, StrGroupKeyCode: "stA10", StrKeyCode: "stA20", IsShowAllText: false);
  37. this.panelQueryCompared.Visible = false;
  38. }
  39. /// <summary>
  40. /// 窗体加载事件
  41. /// </summary>
  42. /// <param name="sender"></param>
  43. /// <param name="e"></param>
  44. void AnalyzedOrderFinanceOutlayFormMain_Shown(object sender, EventArgs e)
  45. {
  46. bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(VersionControl.VersionFunctionEnum.决策助手年财务支出);
  47. if (!b)
  48. {
  49. this.Close();
  50. return;
  51. }
  52. this.PublicFunctionRows();
  53. }
  54. /// <summary>
  55. /// 启用对比
  56. /// </summary>
  57. /// <param name="sender"></param>
  58. /// <param name="e"></param>
  59. void chkComparedStartUp_Click(object sender, EventArgs e)
  60. {
  61. if (this.chkComparedStartUp.Checked)
  62. {
  63. this.panelCloseed.Visible = false;
  64. this.panelSaveAs.Visible = false;
  65. this.panelEx4.Visible = true;
  66. this.panelQueryCompared.Visible = true;
  67. this.panelSaveAs.Visible = true;
  68. this.panelCloseed.Visible = true;
  69. if (!string.IsNullOrEmpty(this.numYear.Value.ToString().Trim()) && !string.IsNullOrEmpty(this.numYearCompared.Value.ToString().Trim()))
  70. { this.PublicFunctionRows(); }
  71. else
  72. { return; }
  73. }
  74. else
  75. {
  76. this.panelQueryCompared.Visible = false;
  77. this.panelEx4.Visible = false;
  78. }
  79. }
  80. /// <summary>
  81. /// 查询
  82. /// </summary>
  83. /// <param name="sender"></param>
  84. /// <param name="e"></param>
  85. void btnQuery_Click(object sender, EventArgs e)
  86. {
  87. this.PublicFunctionRows();
  88. }
  89. /// <summary>
  90. /// 查询对比
  91. /// </summary>
  92. /// <param name="sender"></param>
  93. /// <param name="e"></param>
  94. void btnQueryCompared_Click(object sender, EventArgs e)
  95. {
  96. this.PublicFunctionRows();
  97. }
  98. /// <summary>
  99. /// 另存为
  100. /// </summary>
  101. /// <param name="sender"></param>
  102. /// <param name="e"></param>
  103. void btnSaveAs_Click(object sender, EventArgs e)
  104. {
  105. Bitmap bitmap = new Bitmap(this.panelEx5.Width, this.panelEx5.Height);
  106. this.panelEx5.DrawToBitmap(bitmap, new Rectangle(0, 0, this.panelEx5.Width, this.panelEx5.Height));
  107. string StrYearValue = this.numYear.Value.ToString().Trim();
  108. string StrYearValueDb = this.numYearCompared.Value.ToString().Trim();
  109. string StrItemText = this.cmbtreevItmes.Text.Trim().Trim();
  110. if (StrItemText.Trim() == "全部")
  111. { StrItemText = ""; }
  112. string StrFilleName = StrYearValue + "年" + StrItemText + " 财务支出总览";
  113. if (this.chkComparedStartUp.Checked)
  114. { StrFilleName = StrYearValue + "年 与 " + StrYearValueDb + "年 财务支出总览"; }
  115. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.DownloadSaveAs(bitmap, StrFilleName: "AAA");
  116. }
  117. /// <summary>
  118. /// 关闭
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. void btnCloseed_Click(object sender, EventArgs e)
  123. {
  124. this.Close();
  125. }
  126. /// <summary>
  127. /// 窗体大小 发生变化
  128. /// </summary>
  129. /// <param name="sender"></param>
  130. /// <param name="e"></param>
  131. void AnalyzedOrderFinanceOutlayFormMain_Resize(object sender, EventArgs e)
  132. {
  133. switch (this.panelCloseed.Location.Y)
  134. {
  135. case 1: this.flowLayoutPanel1.Height = 35; break;
  136. case 35: this.flowLayoutPanel1.Height = 70; break;
  137. }
  138. }
  139. /// <summary>
  140. /// 创建行
  141. /// </summary>
  142. void PublicFunctionRows()
  143. {
  144. if (this.chkComparedStartUp.Checked)
  145. {
  146. if (Convert.ToInt32(this.numYearCompared.Value.ToString().Trim()) >= Convert.ToInt32(this.numYear.Value.ToString().Trim()))
  147. { MessageBoxCustom.Show("对比后的年份不能大于对比前的年份"); return; }
  148. }
  149. this.AnalyzedOrderFinanceOutlayFormMain_Resize(this, null);
  150. this.panelEx5.Controls.Clear();
  151. if ((this.panelEx3.Width - 6) > 930)
  152. {
  153. this.panelEx5.Size = new Size(this.panelEx3.Width - 6, this.panelEx3.Height - 6);
  154. }
  155. Bitmap newBmp = new Bitmap(this.panelEx5.Width, this.panelEx5.Height);
  156. Graphics g = Graphics.FromImage(newBmp);
  157. Font ft15 = new Font("微软雅黑", 15);
  158. Font ft12b = new Font("微软雅黑", 11, FontStyle.Bold);
  159. Font ft12 = new Font("微软雅黑", 10);
  160. string StrYearValue = this.numYear.Value.ToString().Trim();
  161. string StrYearValueDb = this.numYearCompared.Value.ToString().Trim();
  162. string StrItemText = this.cmbtreevItmes.Text.Trim().Trim();
  163. if (StrItemText.Trim() == "全部")
  164. { StrItemText = ""; }
  165. int BitmapWidth = this.panelEx5.Width;
  166. LYFZ.ComponentLibrary.PanelEx panel = null;
  167. LYFZ.ComponentLibrary.LabelEx label = null;
  168. int Location_X = 40;
  169. int Location_Y = this.panelEx5.Height - 50;
  170. int SingleWidht = (this.panelEx5.Width - 110) / 11;
  171. #region 标题
  172. label = new ComponentLibrary.LabelEx();
  173. label.Font = new Font("微软雅黑", 15);
  174. if (this.chkComparedStartUp.Checked)
  175. { label.Text = StrYearValue + "年 与 " + StrYearValueDb + "年 " + StrItemText + "财务支出分析"; }
  176. else
  177. { label.Text = StrYearValue + "年" + StrItemText + "财务支出对比分析"; }
  178. SizeF sizef = g.MeasureString(label.Text.Trim(), ft15);
  179. int FtHeigth = Convert.ToInt32(sizef.Height);
  180. int FtWidth = Convert.ToInt32(sizef.Width) + 1;
  181. label.Width = 300;
  182. label.Location = new Point((this.panelEx5.Width - FtWidth) / 2, 30);
  183. this.panelEx5.Controls.Add(label);
  184. #endregion
  185. string StrTimeStrat = StrYearValue + "-01-01";
  186. string StrTimeEnd = Convert.ToDateTime(StrTimeStrat).AddYears(1).ToString("yyyy-MM-dd");
  187. string StrTimeStratDb = StrYearValueDb + "-01-01";
  188. string StrTimeEndDb = Convert.ToDateTime(StrTimeStratDb).AddYears(1).ToString("yyyy-MM-dd");
  189. string StrWhere = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Oiae_IEDatetime", StrTimeStrat, StrTimeEnd, DateAddDays: 0);
  190. StrWhere += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetGroupQueryWhere(this.cmbtreevStoreName, "Oiae_DividedShop");
  191. if (!string.IsNullOrEmpty(StrItemText) && StrItemText.Trim() != "全部")
  192. { StrWhere += " And Oiae_ProjectName = '" + StrItemText + "'"; }
  193. string ExecuteSql = "select Sum(Oiae_Money) AS 金额,CONVERT(varchar(7),dbo.fn_CheckDateTime(Oiae_IEDatetime), 120) AS 月份 from tb_ErpOtherIncomeAndExpenses where Oiae_Type = '财务支出' " + StrWhere + " Group By CONVERT(varchar(7),dbo.fn_CheckDateTime(Oiae_IEDatetime), 120);";
  194. if (this.chkComparedStartUp.Checked)
  195. {
  196. StrWhere = LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Oiae_IEDatetime", StrTimeStratDb, StrTimeEndDb, DateAddDays: 0) + "";
  197. StrWhere += LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetGroupQueryWhere(this.cmbtreevStoreName, "Oiae_DividedShop");
  198. ExecuteSql += "select Sum(Oiae_Money) AS 金额,CONVERT(varchar(7),dbo.fn_CheckDateTime(Oiae_IEDatetime), 120) AS 月份 from tb_ErpOtherIncomeAndExpenses where Oiae_Type = '财务支出' " + StrWhere + " Group By CONVERT(varchar(7),dbo.fn_CheckDateTime(Oiae_IEDatetime), 120);";
  199. }
  200. DataSet dsData = orbll.GetView_Custom(ExecuteSql);
  201. DataTable dtOrderCount = dsData.Tables["ds"];
  202. DataTable dtOrderCountCompared = dsData.Tables["ds1"];
  203. decimal MaxAmount = 0;
  204. for (int i = 0; i < dtOrderCount.Rows.Count; i++)
  205. {
  206. if (Convert.ToDecimal(dtOrderCount.Rows[i]["金额"]) > MaxAmount)
  207. { MaxAmount = Convert.ToDecimal(dtOrderCount.Rows[i]["金额"]); }
  208. }
  209. if (this.chkComparedStartUp.Checked)
  210. {
  211. for (int i = 0; i < dtOrderCountCompared.Rows.Count; i++)
  212. {
  213. if (Convert.ToDecimal(dtOrderCountCompared.Rows[i]["金额"]) > MaxAmount)
  214. { MaxAmount = Convert.ToDecimal(dtOrderCountCompared.Rows[i]["金额"]); }
  215. }
  216. }
  217. float WidthRatio = 0;
  218. if (float.Parse(MaxAmount.ToString()) > 0)
  219. { WidthRatio = (Location_Y - 100) / float.Parse(MaxAmount.ToString()); }
  220. if (!this.chkComparedStartUp.Checked)
  221. {
  222. #region 不启用对比
  223. for (int i = 1; i <= 12; i++)
  224. {
  225. string StrMonth = StrYearValue + "-" + i.ToString("d2");
  226. DataRow[] dtRow = dtOrderCount.Select("月份 = '" + StrMonth + "'");
  227. decimal decAmount = 0;
  228. int intValue = 0;
  229. if (dtRow.Length > 0)
  230. {
  231. intValue = Convert.ToInt32(WidthRatio * float.Parse(dtRow[0]["金额"].ToString().Trim()));
  232. decAmount = Convert.ToDecimal(dtRow[0]["金额"]);
  233. }
  234. panel = new ComponentLibrary.PanelEx();
  235. panel.BackColor = Color.Red;
  236. panel.Tag = StrYearValue + "-" + i.ToString("d2");
  237. panel.Size = new Size(20, intValue);
  238. panel.Location = new Point(Location_X, Location_Y - panel.Height);
  239. panel.MouseDoubleClick += panel_MouseDoubleClick;
  240. this.panelEx5.Controls.Add(panel);
  241. sizef = g.MeasureString(i + "月", ft12b);
  242. FtHeigth = Convert.ToInt32(sizef.Height);
  243. FtWidth = Convert.ToInt32(sizef.Width) + 4;
  244. label = new ComponentLibrary.LabelEx();
  245. label.Tag = StrYearValue + "-" + i.ToString("d2");
  246. label.Font = ft12b;
  247. label.Text = i + "月";
  248. label.Size = new System.Drawing.Size(FtWidth, FtHeigth);
  249. label.Location = new Point(panel.Location.X + panel.Width / 2 - FtWidth / 2, panel.Location.Y + panel.Height + 5);
  250. label.Click += label_MouseDoubleClick;
  251. this.panelEx5.Controls.Add(label);
  252. sizef = g.MeasureString(LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(decAmount), ft12);
  253. FtHeigth = Convert.ToInt32(sizef.Height);
  254. FtWidth = Convert.ToInt32(sizef.Width) + 10;
  255. label = new ComponentLibrary.LabelEx();
  256. label.Tag = StrYearValue + "-" + i.ToString("d2");
  257. label.Font = ft12;
  258. label.Text = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(decAmount);
  259. label.Size = new System.Drawing.Size(FtWidth, FtHeigth);
  260. label.Location = new Point(panel.Location.X + 10 - (FtWidth / 2), panel.Location.Y - FtHeigth - 5);
  261. label.MouseDoubleClick += label_MouseDoubleClick;
  262. this.panelEx5.Controls.Add(label);
  263. Location_X += SingleWidht;
  264. }
  265. #endregion
  266. }
  267. else
  268. {
  269. #region 启用对比
  270. for (int i = 1; i <= 12; i++)
  271. {
  272. string StrMonth = StrYearValue + "-" + i.ToString("d2");
  273. DataRow[] dtRow = dtOrderCount.Select("月份 = '" + StrMonth + "'");
  274. string StrMonth2 = StrYearValueDb + "-" + i.ToString("d2");
  275. DataRow[] dtRow2 = dtOrderCountCompared.Select("月份 = '" + StrMonth2 + "'");
  276. decimal decAmount = 0;
  277. int intValue = 0;
  278. if (dtRow.Length > 0)
  279. {
  280. intValue = Convert.ToInt32(WidthRatio * float.Parse(dtRow[0]["金额"].ToString().Trim()));
  281. decAmount = Convert.ToDecimal(dtRow[0]["金额"]);
  282. }
  283. decimal decAmount2 = 0;
  284. int intValue2 = 0;
  285. if (dtRow2.Length > 0)
  286. {
  287. intValue2 = Convert.ToInt32(WidthRatio * float.Parse(dtRow2[0]["金额"].ToString().Trim()));
  288. decAmount2 = Convert.ToDecimal(dtRow2[0]["金额"]);
  289. }
  290. panel = new ComponentLibrary.PanelEx();
  291. panel.BackColor = Color.Red;
  292. panel.Tag = StrYearValue + "-" + i.ToString("d2") + "|" + StrYearValueDb + "-" + i.ToString("d2");
  293. panel.Size = new Size(20, intValue);
  294. panel.Location = new Point(Location_X, Location_Y - panel.Height);
  295. panel.MouseDoubleClick += panel_MouseDoubleClick;
  296. this.panelEx5.Controls.Add(panel);
  297. int panelLocationX = panel.Location.X;
  298. sizef = g.MeasureString(i + "月", ft12b);
  299. FtHeigth = Convert.ToInt32(sizef.Height);
  300. FtWidth = Convert.ToInt32(sizef.Width) + 4;
  301. label = new ComponentLibrary.LabelEx();
  302. label.BackColor = Color.Transparent;
  303. label.Tag = StrYearValue + "-" + i.ToString("d2") + "|" + StrYearValueDb + "-" + i.ToString("d2");
  304. label.Font = ft12b;
  305. label.Text = i + "月";
  306. label.Size = new System.Drawing.Size(FtWidth, FtHeigth);
  307. //label.Location = new Point(panel.Location.X - LessWidth, panel.Location.Y + panel.Height + 5);
  308. label.Location = new Point(panel.Location.X + panel.Width - FtWidth / 2, panel.Location.Y + panel.Height + 5);
  309. label.Click += label_MouseDoubleClick;
  310. this.panelEx5.Controls.Add(label);
  311. if (decAmount != 0)
  312. {
  313. sizef = g.MeasureString(LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(decAmount), ft12);
  314. FtHeigth = Convert.ToInt32(sizef.Height);
  315. FtWidth = Convert.ToInt32(sizef.Width) + 1;
  316. label = new ComponentLibrary.LabelEx();
  317. label.BackColor = Color.Transparent;
  318. label.Tag = StrYearValue + "-" + i.ToString("d2") + "|" + StrYearValueDb + "-" + i.ToString("d2");
  319. label.Font = ft12;
  320. label.ForeColor = Color.Red;
  321. label.Size = new System.Drawing.Size(FtWidth, FtHeigth);
  322. label.Text = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(decAmount);
  323. label.Location = new Point(panel.Location.X - FtWidth / 2, panel.Location.Y - FtHeigth);
  324. label.MouseDoubleClick += label_MouseDoubleClick;
  325. this.panelEx5.Controls.Add(label);
  326. }
  327. panel = new ComponentLibrary.PanelEx();
  328. panel.BackColor = Color.Blue;
  329. panel.Tag = StrYearValue + "-" + i.ToString("d2") + "|" + StrYearValueDb + "-" + i.ToString("d2");
  330. panel.Size = new Size(20, intValue2);
  331. panel.Location = new Point(panelLocationX + panel.Width, Location_Y - panel.Height);
  332. panel.MouseDoubleClick += panel_MouseDoubleClick;
  333. this.panelEx5.Controls.Add(panel);
  334. if (decAmount2 != 0)
  335. {
  336. sizef = g.MeasureString(LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(decAmount2), ft12);
  337. FtHeigth = Convert.ToInt32(sizef.Height);
  338. label = new ComponentLibrary.LabelEx();
  339. label.Tag = StrYearValue + "-" + i.ToString("d2") + "|" + StrYearValueDb + "-" + i.ToString("d2");
  340. label.Font = ft12;
  341. label.ForeColor = Color.Blue;
  342. label.Size = new System.Drawing.Size(FtWidth, FtHeigth);
  343. label.Text = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(decAmount2);
  344. label.Location = new Point(panel.Location.X, panel.Location.Y - FtHeigth - 18);
  345. label.MouseDoubleClick += label_MouseDoubleClick;
  346. label.BackColor = Color.Transparent;
  347. this.panelEx5.Controls.Add(label);
  348. }
  349. Location_X += SingleWidht;
  350. }
  351. #endregion
  352. }
  353. }
  354. /// <summary>
  355. /// 双击柱状
  356. /// </summary>
  357. /// <param name="sender"></param>
  358. /// <param name="e"></param>
  359. void panel_MouseDoubleClick(object sender, EventArgs e)
  360. {
  361. LYFZ.ComponentLibrary.PanelEx panel = (LYFZ.ComponentLibrary.PanelEx)sender;
  362. if (panel.Tag != null)
  363. { this.DoubleClickGoForm(panel.Tag.ToString().Trim()); }
  364. }
  365. /// <summary>
  366. /// 双击月份、金额
  367. /// </summary>
  368. /// <param name="sender"></param>
  369. /// <param name="e"></param>
  370. void label_MouseDoubleClick(object sender, EventArgs e)
  371. {
  372. LYFZ.ComponentLibrary.LabelEx lable = (LYFZ.ComponentLibrary.LabelEx)sender;
  373. if (lable.Tag != null)
  374. { this.DoubleClickGoForm(lable.Tag.ToString().Trim()); }
  375. }
  376. /// <summary>
  377. /// 双击跳转到详情
  378. /// </summary>
  379. /// <param name="StrValue"></param>
  380. void DoubleClickGoForm(string StrValue)
  381. {
  382. LYFZ.Software.MainBusiness.DecisionAssistant.AnalyzedOrderFinanceOutlayDetailFormMain frm = new AnalyzedOrderFinanceOutlayDetailFormMain();
  383. frm.StrGoFormDateTime = StrValue;
  384. frm.StrStoreName = this.cmbtreevStoreName.Tag.ToString().Trim();
  385. frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  386. frm.Location = new Point(LYFZ.EnumPublic.FormLocation_X, LYFZ.EnumPublic.FormLocation_Y);
  387. frm.Size = new Size(LYFZ.EnumPublic.FormSize_Width, LYFZ.EnumPublic.FormSize_Height);
  388. frm.Show();
  389. }
  390. }
  391. }