AnalyzedOrderStoreOutlayFormMain.cs 20 KB

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