AnalyzedEmployeePerformanceFormMain.cs 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  1. using LYFZ.Model;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. namespace LYFZ.Software.MainBusiness.DecisionAssistant
  12. {
  13. public partial class AnalyzedEmployeePerformanceFormMain : LYFZ.Software.UI.DecisionAssistant.AnalyzedEmployeePerformanceFormMain
  14. {
  15. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  16. List<ModelImagePostionAction> actionList = new List<ModelImagePostionAction>();
  17. public AnalyzedEmployeePerformanceFormMain()
  18. {
  19. this.Load += AnalyzedEmployeePerformanceFormMain_Load;
  20. this.Shown += AnalyzedEmployeePerformanceFormMain_Shown;
  21. this.PictImage.Click += PictImage_Click;
  22. this.chkComparedStartUp.Click += chkComparedStartUp_Click;
  23. this.btnQuery.Click += btnQuery_Click;
  24. this.btnQueryCompared.Click += btnQueryCompared_Click;
  25. this.dtDataTimeStart.Leave += dtDataTimeStart_Leave;
  26. this.dtDataTimeStartCompared.Leave += dtDataTimeStartCompared_Leave;
  27. //this.cmbtreevItmes.ComboBoxTree_NodeMouseClick += cmbtreevItmes_ComboBoxTree_NodeMouseClick;
  28. this.btnSaveAs.Click += btnSaveAs_Click;
  29. this.btnClose.Click += btnClose_Click;
  30. this.Resize += AnalyzedEmployeePerformanceFormMain_Resize;
  31. this.PictImage.MouseDoubleClick += PictImage_MouseDoubleClick;
  32. this.cmbtreevItmes.AfterCheck += TreeView_AfterCheck;
  33. //this.cmbtreevItmes.TreeView.NodeMouseClick += TreeView_NodeMouseClick;//TreeView_NodeMouseClick;
  34. }
  35. void TreeView_AfterCheck(object sender, TreeViewEventArgs e)
  36. {
  37. string strNode = "";
  38. foreach(TreeNode node in this.cmbtreevItmes.Nodes)
  39. {
  40. if(node.Checked)
  41. {
  42. if(strNode!="")
  43. {
  44. strNode += ",";
  45. }
  46. strNode += node.Text;
  47. }
  48. }
  49. this.cmbtreevItmes.Text = strNode;
  50. }
  51. /// <summary>
  52. /// 图片双击事件
  53. /// </summary>
  54. /// <param name="sender"></param>
  55. /// <param name="e"></param>
  56. void PictImage_MouseDoubleClick(object sender, MouseEventArgs e)
  57. {
  58. ModelImagePostionAction action = actionList.Find(p => p.MouseX <= e.Location.X && e.Location.X <= (p.MouseX + p.MouseWidth)
  59. &&
  60. p.MouseY <= e.Location.Y && e.Location.Y <= (p.MouseY + p.MouseHeight));
  61. if (action != null)
  62. {
  63. LYFZ.Software.MainBusiness.DecisionAssistant.SetSmallForm.AnalyzedOrderDetailSmallForm detailForm = new SetSmallForm.AnalyzedOrderDetailSmallForm();
  64. detailForm.BindDataGridView2(action);
  65. detailForm.ShowDialog();
  66. //MessageBox.Show("内容!");
  67. }
  68. }
  69. bool IsFristLoad = true;
  70. /// <summary>
  71. /// 窗体加载事件
  72. /// </summary>
  73. /// <param name="sender"></param>
  74. /// <param name="e"></param>
  75. void AnalyzedEmployeePerformanceFormMain_Load(object sender, EventArgs e)
  76. {
  77. this.panelComparedColor.Visible = false;
  78. this.lblComparedColor.Visible = false;
  79. this.panelCurrentColor.BackColor = Color.Red;
  80. this.panelComparedColor.BackColor = Color.Blue;
  81. this.panelPaidColor.BackColor = Color.Green;
  82. this.panelEx10.Visible = false;
  83. this.dtDataTimeStart.DateValue = SDateTime.Now.ToString("yyyy-MM") + "-01";
  84. this.dtDataTimeEnd.DateValue = Convert.ToDateTime(this.dtDataTimeStart.DateValue).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
  85. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_StoreDepartment(this.cmbtreevDepartment, true, "全部");
  86. LYFZ.BLL.BLL_ErpCompanyInfo companyBll = new BLL.BLL_ErpCompanyInfo();
  87. DataTable companyList = companyBll.GetAllList().Tables[0];
  88. List<string> sIDList = LYFZ.BLL.BLL_ErpUser.GetGroupRights("stA10", "stA19");
  89. try
  90. {
  91. foreach (DataRow dr in companyList.Rows)
  92. {
  93. if (!sIDList.Contains(dr["Company_DividedShop"].ToString()))
  94. {
  95. foreach (TreeNode node in this.cmbtreevDepartment.Nodes)
  96. {
  97. try
  98. {
  99. if (node != null)
  100. {
  101. if (dr["Company_DividedShop"].ToString() == node.Tag.ToString())
  102. {
  103. this.cmbtreevDepartment.Nodes.Remove(node);
  104. }
  105. }
  106. }
  107. catch (Exception ex)
  108. {
  109. Console.WriteLine(ex.Message);
  110. }
  111. }
  112. }
  113. }
  114. }
  115. catch (Exception ex){
  116. MessageBoxCustom.Show("加载门店数据出错:"+ex.Message);
  117. }
  118. this.cmbtreevDepartment.TextFindTag("全部");
  119. this.cmbtreevItmes.CheckBoxes = true;
  120. TreeNode root = new TreeNode();
  121. //root.Text = "全部";
  122. //root.Tag = "";
  123. //root.Name = "";
  124. //this.cmbtreevItmes.Nodes.Add(root);
  125. root = new TreeNode();
  126. root.Text = "订单前期";
  127. root.Tag = "订单前期";
  128. root.Name = "订单前期";
  129. this.cmbtreevItmes.Nodes.Add(root);
  130. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_SystemCategory("BEBACDAJDFDDEACGJ", this.cmbtreevItmes, IsFirstNodeNull: false, StrWhere: "Sc_ClassCode != 'AAAAABZ' and Sc_ClassCode!='BEBCADBFBCDFBGJHC' and Sc_ClassCode!='BEBCADBFBDDEGGABF' and Sc_ClassCode!='BEBCBFBICGDHCGBEJ' and Sc_ClassCode!='BEBCABBAAICBDHDHI' and Sc_ClassCode!='BEBCABBAAICJAAGDG' and Sc_ClassCode!='BEBCBFBICFCECBHFF'", IsClearNodes: false);
  131. //if (cmbtreevDepartment.GetNodeItem_TextToTag("门市部") == null)
  132. //{ this.cmbtreevDepartment.TextFindTag(this.cmbtreevDepartment.Nodes[0].Text.Trim()); }
  133. //else
  134. //{ this.cmbtreevDepartment.TextFindTag("门市部"); }
  135. //this.cmbtreevItmes.TextFindTag("全部");
  136. foreach (TreeNode node in this.cmbtreevItmes.Nodes)
  137. {
  138. node.Checked = true;
  139. }
  140. TreeView_AfterCheck(null, null);
  141. }
  142. /// <summary>
  143. /// 窗体加载事件
  144. /// </summary>
  145. /// <param name="sender"></param>
  146. /// <param name="e"></param>
  147. void AnalyzedEmployeePerformanceFormMain_Shown(object sender, EventArgs e)
  148. {
  149. bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(VersionControl.VersionFunctionEnum.决策助手员工业绩);
  150. if (!b)
  151. {
  152. this.Close();
  153. return;
  154. }
  155. this.PublicFunctionRows();
  156. this.IsFristLoad = false;
  157. }
  158. /// <summary>
  159. /// 图片控件点击事件
  160. /// </summary>
  161. /// <param name="sender"></param>
  162. /// <param name="e"></param>
  163. void PictImage_Click(object sender, EventArgs e)
  164. {
  165. this.PictImage.Focus();
  166. }
  167. /// <summary>
  168. /// 启用对比
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. void chkComparedStartUp_Click(object sender, EventArgs e)
  173. {
  174. if (this.chkComparedStartUp.Checked)
  175. {
  176. this.panelEx10.Visible = true;
  177. this.panelComparedColor.Visible = true;
  178. this.lblComparedColor.Visible = true;
  179. this.cbo_CheckYear.SelectedItem = (Convert.ToInt32(this.cbo_Year.Text.Replace("年", ""))-1)+"年";
  180. rdo_Day_Click(null, null);
  181. if (!string.IsNullOrEmpty(this.dtDataTimeStart.DateValue.Trim()) &&
  182. !string.IsNullOrEmpty(this.dtDataTimeEnd.DateValue.Trim()) &&
  183. !string.IsNullOrEmpty(this.dtDataTimeStartCompared.DateValue.Trim()) &&
  184. !string.IsNullOrEmpty(this.dtDateTimeEndCompared.DateValue.Trim()) &&
  185. !string.IsNullOrEmpty(this.cmbtreevDepartment.Text.Trim()) &&
  186. !string.IsNullOrEmpty(this.cmbtreevItmes.Text.Trim()))
  187. {
  188. }
  189. else
  190. {
  191. rdo_Day_Click(null, null);
  192. return;
  193. }
  194. }
  195. else
  196. {
  197. rdo_Day_Click(null, null);
  198. this.panelEx10.Visible = false;
  199. this.panelComparedColor.Visible = false;
  200. this.lblComparedColor.Visible = false;
  201. }
  202. this.PublicFunctionRows();
  203. }
  204. /// <summary>
  205. /// 查询
  206. /// </summary>
  207. /// <param name="sender"></param>
  208. /// <param name="e"></param>
  209. void btnQuery_Click(object sender, EventArgs e)
  210. {
  211. this.PublicFunctionRows();
  212. }
  213. /// <summary>
  214. /// 对比查询
  215. /// </summary>
  216. /// <param name="sender"></param>
  217. /// <param name="e"></param>
  218. void btnQueryCompared_Click(object sender, EventArgs e)
  219. {
  220. this.PublicFunctionRows();
  221. }
  222. /// <summary>
  223. /// 日期离开事件
  224. /// </summary>
  225. /// <param name="sender"></param>
  226. /// <param name="e"></param>
  227. void dtDataTimeStart_Leave(object sender, EventArgs e)
  228. {
  229. if(this.rdo_Stage.Checked)
  230. {
  231. this.dtDataTimeEnd.DateValue = Convert.ToDateTime(this.dtDataTimeStart.DateValue).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
  232. }
  233. else if(this.rdo_Day.Checked)
  234. {
  235. this.dtDataTimeEnd.DateValue = Convert.ToDateTime(this.dtDataTimeStart.DateValue).ToString("yyyy-MM-dd");
  236. }
  237. }
  238. /// <summary>
  239. /// 日期离开事件
  240. /// </summary>
  241. /// <param name="sender"></param>
  242. /// <param name="e"></param>
  243. void dtDataTimeStartCompared_Leave(object sender, EventArgs e)
  244. {
  245. if (this.rdo_Stage.Checked)
  246. {
  247. this.dtDateTimeEndCompared.DateValue = Convert.ToDateTime(this.dtDataTimeStartCompared.DateValue).AddMonths(1).AddSeconds(-1).ToString("yyyy-MM-dd");
  248. }
  249. else if (this.rdo_Day.Checked)
  250. {
  251. this.dtDateTimeEndCompared.DateValue = Convert.ToDateTime(this.dtDataTimeStartCompared.DateValue).ToString("yyyy-MM-dd");
  252. }
  253. }
  254. /// <summary>
  255. /// 项目选择事件
  256. /// </summary>
  257. /// <param name="sender"></param>
  258. /// <param name="e"></param>
  259. void cmbtreevItmes_ComboBoxTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  260. {
  261. //TreeView_AfterCheck(null, null);
  262. this.PublicFunctionRows();
  263. }
  264. /// <summary>
  265. /// 另存为
  266. /// </summary>
  267. /// <param name="sender"></param>
  268. /// <param name="e"></param>
  269. void btnSaveAs_Click(object sender, EventArgs e)
  270. {
  271. //+ this.cmbtreevItmes.Text.Trim()
  272. string StrFilleName = Convert.ToDateTime(this.dtDataTimeStart.DateValue).ToString("yyyy年MM月dd日") + " — " + Convert.ToDateTime(this.dtDataTimeEnd.DateValue).ToString("yyyy年MM月dd日") + " " + this.cmbtreevDepartment.Text.Trim() + "分析表";
  273. if (this.chkComparedStartUp.Checked)
  274. { StrFilleName = this.dtDataTimeStart.DateValue.Trim() + "—" + this.dtDataTimeEnd.DateValue.Trim() + " 与 " + this.dtDataTimeStartCompared.DateValue.Trim() + "—" + this.dtDateTimeEndCompared.DateValue.Trim() + " " + this.cmbtreevDepartment.Text.Trim() + "分析表"; }
  275. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.DownloadSaveAs(this.PictImage.Image, StrFilleName: StrFilleName);
  276. }
  277. /// <summary>
  278. /// 关闭
  279. /// </summary>
  280. /// <param name="sender"></param>
  281. /// <param name="e"></param>
  282. void btnClose_Click(object sender, EventArgs e)
  283. {
  284. this.Close();
  285. }
  286. /// <summary>
  287. /// 窗体大小发生变化
  288. /// </summary>
  289. /// <param name="sender"></param>
  290. /// <param name="e"></param>
  291. void AnalyzedEmployeePerformanceFormMain_Resize(object sender, EventArgs e)
  292. {
  293. if (this.IsFristLoad)
  294. {
  295. this.panelEx1.Width = this.Width - 10;
  296. this.panelEx1.Height = this.Height - 60;
  297. }
  298. }
  299. void SetPostionData(string ordType, string columType, Rectangle rectangle, string where, string startTime, string endTime)
  300. {
  301. ModelImagePostionAction actionModel = null;
  302. string SqlSelect = @"";
  303. string StrItemName = this.cmbtreevItmes.Text.Trim();
  304. string sqlWhere = " " + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("CreateDateTime", startTime, endTime, ConnectWord: "");
  305. if (StrItemName != "全部")
  306. { sqlWhere += " And 项目 in ('" + string.Join("','",StrItemName.Split(',')) + "') "; }
  307. string TwoSaleOrderSql = "";
  308. TwoSaleOrderSql =
  309. @"select
  310. Tsorder_Number as 订单号,
  311. Tsorder_Money as 套系金额,
  312. Tsorder_Name as 项目内容,
  313. Tsorder_OpenSingle as OrdersPerson,
  314. Pay_AmountOf as 实收金额
  315. from
  316. Vw_TwoSalesOrder left join tb_erpPayment on tb_erpPayment.pay_ordNumber = Vw_TwoSalesOrder.Tsorder_Number
  317. where
  318. " + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Tsorder_CreateDatetime", startTime, endTime, ConnectWord: "") +
  319. (StrItemName != "全部" ? " and Tsorder_Name = '" + StrItemName + "' " : "") + " and Tsorder_OpenSingle = '" + columType + "' " +
  320. @" ;
  321. ";
  322. SqlSelect = "with tt AS \r\n" +
  323. "( \r\n" +
  324. "select ord_Number, SeriesPrice,OrdersPerson,CreateDateTime,项目,实收金额,客户名称, 联系电话,套系名称, \r\n" +
  325. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else \r\n" +
  326. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then SeriesPrice else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) end) end as 主门市金额,\r\n" +
  327. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else \r\n" +
  328. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) end) end as 副门市金额,\r\n" +
  329. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else \r\n" +
  330. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 实收金额 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) end) end as 主门市实收,\r\n" +
  331. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else \r\n" +
  332. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) end) end as 副门市实收,\r\n" +
  333. "(case LEFT(OrdersPerson,charindex(',',OrdersPerson,1)) when '' then OrdersPerson else LEFT(OrdersPerson,charindex(',',OrdersPerson,1)-1) end)as '主门市' \r\n" +
  334. "from (\r\n" +
  335. "select ord_Number, Ord_SeriesPrice AS SeriesPrice,Ord_CreateDateTime AS CreateDateTime,'订单前期' AS 项目,\r\n" +
  336. "(select stuff((select ',' + OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as OrdersPerson,\r\n" +
  337. "isnull((select Sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category in ('全款','预约收款','预约补款') And Pay_OrdNumber = Ord_Number),0) AS 实收金额,Cus_Name as '客户名称',Cus_Telephone as '联系电话',Ord_SeriesName as '套系名称' \r\n" +
  338. "from tb_ErpOrder inner join tempTB_AggregationCustomer on GP_OrderNumber=Ord_Number where ord_class=1) AS t \r\n" +
  339. "UNION ALL \r\n" +
  340. "select Plu_OrdNumber as ord_Number , SeriesPrice,OrdersPerson,CreateDateTime,项目,实收金额,客户名称, 联系电话,套系名称,\r\n" +
  341. "(case (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',',''))))) when 0 then SeriesPrice else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) end) as 主门市金额,\r\n" +
  342. "(case (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',',''))))) when 0 then 0 else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) end) as 副门市金额,\r\n" +
  343. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 实收金额 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) end) as 主门市实收,\r\n" +
  344. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) end) as 副门市实收,\r\n" +
  345. "(case LEFT(Plu_OpenSingle,charindex(',',Plu_OpenSingle,1)) when '' then Plu_OpenSingle else LEFT(Plu_OpenSingle,charindex(',',Plu_OpenSingle,1)-1) end)as '主门市' \r\n" +
  346. "from (\r\n" +
  347. "select Plu_OrdNumber, Plu_Amount AS SeriesPrice,Plu_OpenSingle AS OrdersPerson,Plu_CreateTime AS CreateDateTime,Sc_ClassName AS 项目,Plu_OpenSingle,\r\n" +
  348. "isnull((select Sum(Pay_AmountOf) from tb_ErpPayment where Pay_PlusPickNumber = Plu_Number And Pay_OrdNumber = Plu_OrdNumber),0) AS 实收金额,Cus_Name as '客户名称',Cus_Telephone as '联系电话',Ord_SeriesName as '套系名称'\r\n " +
  349. "from tb_ErpPlusPickItems left join tb_ErpOrder on Plu_OrdNumber = ord_Number inner join tempTB_AggregationCustomer on GP_OrderNumber=Ord_Number Left Join tb_ErpSystemCategory on Sc_ClassCode = Plu_TwoPinsCategory) AS t \r\n" +
  350. ")\r\n" +
  351. "select ord_Number as 订单号,SeriesPrice as 套系金额,项目 as 项目内容,实收金额,主门市金额,副门市金额,主门市实收,副门市实收,OrdersPerson,套系名称,联系电话,客户名称 from tt \r\n";
  352. sqlWhere += " and OrdersPerson like '%" + columType + "%' ";
  353. actionModel = new ModelImagePostionAction()
  354. {
  355. OrdType = ordType,
  356. ColumType = columType,
  357. MouseX = rectangle.X,
  358. MouseY = rectangle.Y,
  359. MouseWidth = rectangle.Width,
  360. MouseHeight = rectangle.Height,
  361. SqlData = SqlSelect + " where " + sqlWhere + ";" + TwoSaleOrderSql,
  362. };
  363. actionModel.OrdTitle = this.UcNavigationTool.LabTitle;
  364. if (actionModel != null)
  365. {
  366. actionList.Add(actionModel);
  367. }
  368. }
  369. /// <summary>
  370. /// 创建行
  371. /// </summary>
  372. private void PublicFunctionRows()
  373. {
  374. actionList.Clear();
  375. #region 处理数据前判断
  376. if (this.chkComparedStartUp.Checked)
  377. {
  378. if (string.IsNullOrEmpty(this.dtDataTimeStart.DateValue.Trim()) && string.IsNullOrEmpty(this.dtDataTimeEnd.DateValue.Trim()))
  379. { MessageBoxCustom.Show("对比前时间段不能为空"); return; }
  380. if (Convert.ToDateTime(this.dtDataTimeEnd.DateValue) < Convert.ToDateTime(this.dtDataTimeStart.DateValue))
  381. { MessageBoxCustom.Show("对比前开始日期不能大于结束日期"); return; }
  382. if (string.IsNullOrEmpty(this.dtDataTimeStartCompared.DateValue.Trim()) && string.IsNullOrEmpty(this.dtDateTimeEndCompared.DateValue.Trim()))
  383. { MessageBoxCustom.Show("对比后时间段不能为空"); return; }
  384. if (Convert.ToDateTime(this.dtDateTimeEndCompared.DateValue) < Convert.ToDateTime(this.dtDataTimeStartCompared.DateValue))
  385. { MessageBoxCustom.Show("对比后开始日期不能大于结束日期"); return; }
  386. if (Convert.ToDateTime(this.dtDateTimeEndCompared.DateValue.Trim()) > Convert.ToDateTime(this.dtDataTimeStart.DateValue.Trim()))
  387. { MessageBoxCustom.Show("对比后的结束日期不能大于对比前的开始日期"); return; }
  388. }
  389. else
  390. {
  391. if (string.IsNullOrEmpty(this.dtDataTimeStart.DateValue.Trim()) && string.IsNullOrEmpty(this.dtDataTimeEnd.DateValue.Trim()))
  392. { MessageBoxCustom.Show("时间段不能为空"); return; }
  393. if (Convert.ToDateTime(this.dtDataTimeEnd.DateValue) < Convert.ToDateTime(this.dtDataTimeStart.DateValue))
  394. { MessageBoxCustom.Show("开始日期不能大于结束日期"); return; }
  395. }
  396. //if (string.IsNullOrEmpty(this.cmbtreevDepartment.Tag.ToString().Trim()))
  397. //{ MessageBoxCustom.Show("部门不能为空"); return; }
  398. if (string.IsNullOrEmpty(this.cmbtreevItmes.Text.Trim()))
  399. { MessageBoxCustom.Show("项目不能为空"); return; }
  400. this.IsFristLoad = true;
  401. this.AnalyzedEmployeePerformanceFormMain_Resize(this, null);
  402. this.IsFristLoad = false;
  403. #endregion
  404. this.actionList.Clear();
  405. Brush b = Brushes.Black;
  406. Pen p = new Pen(Brushes.Black, 1);
  407. Font ft12 = new Font("微软雅黑", 12);
  408. Font ft11 = new Font("微软雅黑", 11);
  409. Font ft15 = new Font("微软雅黑", 15);
  410. #region 数据连接获取数据
  411. string StrTimeStrat = this.dtDataTimeStart.DateValue.Trim();
  412. string StrTimeEnd = this.dtDataTimeEnd.DateValue.Trim();
  413. string StrTimeStratDb = this.dtDataTimeStartCompared.DateValue.Trim();
  414. string StrTimeEndDb = this.dtDateTimeEndCompared.DateValue.Trim();
  415. string StrItemName = this.cmbtreevItmes.Text.Trim();
  416. string StrWhere = "where " + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("CreateDateTime", StrTimeStrat, StrTimeEnd, ConnectWord: "");
  417. if (StrItemName != "全部")
  418. { StrWhere += " And 项目 in ('" + string.Join("','", StrItemName.Split(',')) + "') "; }
  419. string TwoSaleOrderSql = "";
  420. TwoSaleOrderSql =
  421. @"select
  422. Tsorder_OpenSingle as EmployeeID,
  423. sum(Tsorder_Money) as Price,
  424. sum(Pay_AmountOf) as PayPrice
  425. from
  426. Vw_TwoSalesOrder left join tb_erpPayment on tb_erpPayment.pay_ordNumber = Vw_TwoSalesOrder.Tsorder_Number
  427. where
  428. " + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Tsorder_CreateDatetime", StrTimeStrat, StrTimeEnd, ConnectWord: "") +
  429. (StrItemName != "全部" ? " and Tsorder_Name = '" + StrItemName + "' " : "") +
  430. @" group by Tsorder_OpenSingle ;
  431. ";
  432. string ExecuteSql = "with tt AS " +
  433. "( " +
  434. "select SeriesPrice,OrdersPerson,CreateDateTime,项目,实收金额,'订单' as 类型," +
  435. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else "+
  436. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then SeriesPrice else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) end) end as 主门市金额," +
  437. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else "+
  438. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) end) end as 副门市金额," +
  439. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else "+
  440. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 实收金额 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) end) end as 主门市实收,"+
  441. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else "+
  442. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) end) end as 副门市实收," +
  443. "(case LEFT(OrdersPerson,charindex(',',OrdersPerson,1)) when '' then OrdersPerson else LEFT(OrdersPerson,charindex(',',OrdersPerson,1)-1) end)as '主门市' " +
  444. "from (" +
  445. "select Ord_SeriesPrice AS SeriesPrice,Ord_CreateDateTime AS CreateDateTime,'订单前期' AS 项目," +
  446. "(select stuff((select ',' + OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as OrdersPerson," +
  447. "isnull((select Sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category in ('全款','预约收款','预约补款') And Pay_OrdNumber = Ord_Number),0) AS 实收金额 " +
  448. "from tb_ErpOrder where ord_class=1) AS t " +
  449. "UNION ALL " +
  450. "select SeriesPrice,OrdersPerson,CreateDateTime,项目,实收金额,'加挑' as 类型," +
  451. "(case (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',',''))))) when 0 then SeriesPrice else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) end) as 主门市金额," +
  452. "(case (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',',''))))) when 0 then 0 else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) end) as 副门市金额," +
  453. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 实收金额 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) end) as 主门市实收," +
  454. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) end) as 副门市实收," +
  455. "(case LEFT(Plu_OpenSingle,charindex(',',Plu_OpenSingle,1)) when '' then Plu_OpenSingle else LEFT(Plu_OpenSingle,charindex(',',Plu_OpenSingle,1)-1) end)as '主门市' " +
  456. "from (" +
  457. "select Plu_Amount AS SeriesPrice,Plu_OpenSingle AS OrdersPerson,Plu_CreateTime AS CreateDateTime,Sc_ClassName AS 项目,Plu_OpenSingle," +
  458. "isnull((select Sum(Pay_AmountOf) from tb_ErpPayment where Pay_PlusPickNumber = Plu_Number And Pay_OrdNumber = Plu_OrdNumber and Plu_TwoPinsCategory = Pay_TwoPinsCategory),0) AS 实收金额 " +
  459. "from tb_ErpPlusPickItems Left Join tb_ErpSystemCategory on Sc_ClassCode = Plu_TwoPinsCategory) AS t " +
  460. @" union all
  461. select
  462. SeriesPrice,Tsorder_OpenSingle,CreateDateTime, 项目,实收金额,'二销' as 类型,
  463. (case (len(rtrim(ltrim(Tsorder_OpenSingle))) - len(rtrim(ltrim(replace(Tsorder_OpenSingle,',',''))))) when 0 then SeriesPrice
  464. else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') *
  465. (len(rtrim(ltrim(Tsorder_OpenSingle))) - len(rtrim(ltrim(replace(Tsorder_OpenSingle,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') as numeric(9,2)) end) as 主门市金额,
  466. (case (len(rtrim(ltrim(Tsorder_OpenSingle))) - len(rtrim(ltrim(replace(Tsorder_OpenSingle,',',''))))) when 0 then 0 else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') +
  467. (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') * (len(rtrim(ltrim(Tsorder_OpenSingle))) - len(rtrim(ltrim(replace(Tsorder_OpenSingle,',','')))))) ) *
  468. (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') as numeric(9,2)) end) as 副门市金额,
  469. (case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 实收金额 else
  470. cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') +
  471. (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) *
  472. (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') as numeric(9,2)) end) as 主门市实收,
  473. (case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else
  474. cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') *
  475. (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') as numeric(9,2)) end) as 副门市实收,
  476. (case LEFT(Tsorder_OpenSingle,charindex(',',Tsorder_OpenSingle,1)) when '' then Tsorder_OpenSingle else LEFT(Tsorder_OpenSingle,charindex(',',Tsorder_OpenSingle,1)-1) end)as '主门市'
  477. from (select Tsorder_Money AS SeriesPrice,Tsorder_OpenSingle AS OrdersPerson,Tsorder_CreateDatetime AS CreateDateTime,Tsorder_CategoryName AS 项目,Tsorder_OpenSingle,isnull((select Sum(Pay_AmountOf) from tb_ErpPayment where Pay_OrdNumber = Tsorder_Number and Tsorder_Category = Pay_TwoPinsCategory),0) AS 实收金额
  478. from Vw_TwoSalesOrder ) AS t " +
  479. ")" +
  480. "select * from tt " + StrWhere + "; ";
  481. if (this.chkComparedStartUp.Checked)
  482. {
  483. string StrTimeStratCompared = this.dtDataTimeStartCompared.DateValue.Trim();
  484. string StrTimeEndCompared = this.dtDateTimeEndCompared.DateValue.Trim();
  485. StrWhere = "where " + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("CreateDateTime", StrTimeStratCompared, StrTimeEndCompared, ConnectWord: "");
  486. if (StrItemName != "全部")
  487. { StrWhere += " And 项目 = '" + StrItemName + "'"; }
  488. TwoSaleOrderSql +=
  489. @"select
  490. Tsorder_OpenSingle as EmployeeID,
  491. sum(Tsorder_Money) as Price,
  492. sum(Pay_AmountOf) as PayPrice
  493. from
  494. Vw_TwoSalesOrder left join tb_erpPayment on tb_erpPayment.pay_ordNumber = Vw_TwoSalesOrder.Tsorder_Number
  495. where
  496. " + LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.GetDateTime("Tsorder_CreateDatetime", StrTimeStratCompared, StrTimeEndCompared, ConnectWord: "") +
  497. (StrItemName != "全部" ? " and Tsorder_Name = '" + StrItemName + "' " : "") +
  498. @" group by Tsorder_OpenSingle ;
  499. ";
  500. ExecuteSql += "with tt AS " +
  501. "( " +
  502. "select SeriesPrice,OrdersPerson,CreateDateTime,项目,实收金额,'订单' as 类型, " +
  503. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else "+
  504. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then SeriesPrice else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) end) end as 主门市金额," +
  505. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else "+
  506. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) end) end as 副门市金额," +
  507. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else "+
  508. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 实收金额 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') as numeric(9,2)) end) end as 主门市实收,"+
  509. "case ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion')) when 0 then 0 else "+
  510. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainStoreProportion') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyStoreProportion') as numeric(9,2)) end) end as 副门市实收," +
  511. "(case LEFT(OrdersPerson,charindex(',',OrdersPerson,1)) when '' then OrdersPerson else LEFT(OrdersPerson,charindex(',',OrdersPerson,1)-1) end)as '主门市' " +
  512. "from (" +
  513. "select Ord_SeriesPrice AS SeriesPrice,Ord_CreateDateTime AS CreateDateTime,'订单前期' AS 项目," +
  514. "(select stuff((select ',' + OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as OrdersPerson," +
  515. "isnull((select Sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category in ('全款','预约收款','预约补款') And Pay_OrdNumber = Ord_Number),0) AS 实收金额 " +
  516. "from tb_ErpOrder where ord_class=1) AS t " +
  517. "UNION ALL " +
  518. "select SeriesPrice,OrdersPerson,CreateDateTime,项目,实收金额,'加挑' as 类型," +
  519. "(case (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',',''))))) when 0 then SeriesPrice else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') * (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') as numeric(9,2)) end) as 主门市金额," +
  520. "(case (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',',''))))) when 0 then 0 else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') * (len(rtrim(ltrim(Plu_OpenSingle))) - len(rtrim(ltrim(replace(Plu_OpenSingle,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') as numeric(9,2)) end) as 副门市金额," +
  521. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 实收金额 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') as numeric(9,2)) end) as 主门市实收," +
  522. "(case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') as numeric(9,2)) end) as 副门市实收," +
  523. "(case LEFT(Plu_OpenSingle,charindex(',',Plu_OpenSingle,1)) when '' then Plu_OpenSingle else LEFT(Plu_OpenSingle,charindex(',',Plu_OpenSingle,1)-1) end)as '主门市' " +
  524. "from (" +
  525. "select Plu_Amount AS SeriesPrice,Plu_OpenSingle AS OrdersPerson,Plu_CreateTime AS CreateDateTime,Sc_ClassName AS 项目,Plu_OpenSingle," +
  526. "isnull((select Sum(Pay_AmountOf) from tb_ErpPayment where Pay_PlusPickNumber = Plu_Number And Pay_OrdNumber = Plu_OrdNumber and Plu_TwoPinsCategory = Pay_TwoPinsCategory),0) AS 实收金额 " +
  527. "from tb_ErpPlusPickItems Left Join tb_ErpSystemCategory on Sc_ClassCode = Plu_TwoPinsCategory) AS t " +
  528. @" union all
  529. select
  530. SeriesPrice,Tsorder_OpenSingle,CreateDateTime, 项目,实收金额,'二销' as 类型,
  531. (case (len(rtrim(ltrim(Tsorder_OpenSingle))) - len(rtrim(ltrim(replace(Tsorder_OpenSingle,',',''))))) when 0 then SeriesPrice
  532. else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') *
  533. (len(rtrim(ltrim(Tsorder_OpenSingle))) - len(rtrim(ltrim(replace(Tsorder_OpenSingle,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') as numeric(9,2)) end) as 主门市金额,
  534. (case (len(rtrim(ltrim(Tsorder_OpenSingle))) - len(rtrim(ltrim(replace(Tsorder_OpenSingle,',',''))))) when 0 then 0 else cast((SeriesPrice / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') +
  535. (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') * (len(rtrim(ltrim(Tsorder_OpenSingle))) - len(rtrim(ltrim(replace(Tsorder_OpenSingle,',','')))))) ) *
  536. (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') as numeric(9,2)) end) as 副门市金额,
  537. (case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 实收金额 else
  538. cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') +
  539. (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') * (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) *
  540. (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') as numeric(9,2)) end) as 主门市实收,
  541. (case (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',',''))))) when 0 then 0 else
  542. cast((实收金额 / ((select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='MainLaterOtherTwoSales') + (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') *
  543. (len(rtrim(ltrim(OrdersPerson))) - len(rtrim(ltrim(replace(OrdersPerson,',','')))))) ) * (select Cp_Proportion from tb_ErpCommissionPercentage where Cp_ProportionCode='DeputyLaterOtherTwoSales') as numeric(9,2)) end) as 副门市实收,
  544. (case LEFT(Tsorder_OpenSingle,charindex(',',Tsorder_OpenSingle,1)) when '' then Tsorder_OpenSingle else LEFT(Tsorder_OpenSingle,charindex(',',Tsorder_OpenSingle,1)-1) end)as '主门市'
  545. from (select Tsorder_Money AS SeriesPrice,Tsorder_OpenSingle AS OrdersPerson,Tsorder_CreateDatetime AS CreateDateTime,Tsorder_CategoryName AS 项目,Tsorder_OpenSingle,isnull((select Sum(Pay_AmountOf) from tb_ErpPayment where Pay_OrdNumber = Tsorder_Number and Tsorder_Category = Pay_TwoPinsCategory),0) AS 实收金额
  546. from Vw_TwoSalesOrder ) AS t " +
  547. ")" +
  548. "select * from tt " + StrWhere + "; ";
  549. }
  550. DataSet dsData = orbll.GetView_Custom(ExecuteSql);
  551. //DataSet dsTowOrderData = orbll.GetView_Custom(TwoSaleOrderSql);
  552. //DataTable towOrderCount = dsTowOrderData.Tables["ds"];
  553. //DataTable towOrderCountCompared = dsTowOrderData.Tables["ds1"];
  554. string sql = " select * from tb_ErpCommissionPercentage where Cp_ProportionType in(1,5) ";
  555. DataTable PerDt = orbll.GetView_Custom(sql).Tables[0];
  556. List<DataRow> drList = PerDt.AsEnumerable().Where(q => q.Field<int>("Cp_ProportionType") == 1).ToList();
  557. DataRow mainDr = PerDt.NewRow();
  558. DataRow deputyDr = PerDt.NewRow();
  559. if (drList.Count > 0)
  560. {
  561. mainDr = drList.Where(q => q.Field<string>("Cp_ProportionCode") == "MainStoreProportion").First();
  562. deputyDr = drList.Where(q => q.Field<string>("Cp_ProportionCode") == "DeputyStoreProportion").First();
  563. }
  564. drList = PerDt.AsEnumerable().Where(q => q.Field<int>("Cp_ProportionType") == 5).ToList();
  565. DataRow mainTwoSalesDr= PerDt.NewRow();
  566. DataRow deputyTwoSalesDr = PerDt.NewRow();
  567. if (drList.Count > 0)
  568. {
  569. mainTwoSalesDr = drList.Where(q => q.Field<string>("Cp_ProportionCode") == "MainLaterOtherTwoSales").First();
  570. deputyTwoSalesDr = drList.Where(q => q.Field<string>("Cp_ProportionCode") == "DeputyLaterOtherTwoSales").First();
  571. }
  572. DataTable dtOrderCount = dsData.Tables["ds"];
  573. List<DataRow> drOrderList = dtOrderCount.AsEnumerable().Where(p1 => p1.Field<decimal?>("主门市金额") == null).ToList();
  574. foreach(DataRow dr in drOrderList)
  575. {
  576. string OrdersPerson = dr["OrdersPerson"].ToString_s();
  577. string[] personList = OrdersPerson.Split(',');
  578. if(personList.Length>1)
  579. {
  580. dr["主门市金额"] = dr["实收金额"];
  581. dr["副门市金额"] = dr["实收金额"];
  582. dr["主门市实收"] = dr["实收金额"];
  583. dr["副门市实收"] = dr["实收金额"];
  584. }
  585. else
  586. {
  587. dr["主门市金额"] = dr["实收金额"];
  588. dr["副门市金额"] = 0;
  589. dr["主门市实收"] = dr["实收金额"];
  590. dr["副门市实收"] = 0;
  591. }
  592. }
  593. DataTable dtOrderCountCompared = dsData.Tables["ds1"];
  594. DataTable dt = orbll.GetView_Custom("tb_ErpUser", StrWhere: "User_Department in (" + GetStoreTreeViewByStoreList() + ") And User_Status != '离职'", ShowColumnName: "User_EmployeeID,User_Name").Tables[0];
  595. #region 计算图片高度
  596. int ForTopLoad = 15;
  597. int RowHeight = 240 / 7;
  598. int DownHeight = 55 * dt.Rows.Count;
  599. int panelEx3Height = this.panelEx3.Height - 6;
  600. if (this.chkComparedStartUp.Checked)
  601. {
  602. panelEx3Height -= this.panelEx2.Height;
  603. DownHeight = 95 * dt.Rows.Count;
  604. }
  605. int TotalHeight = panelEx3Height;
  606. if (DownHeight > panelEx3Height)
  607. {
  608. TotalHeight = DownHeight + 20;
  609. this.PictImage.Dock = DockStyle.None;
  610. this.PictImage.Height = TotalHeight;
  611. this.PictImage.Width = this.panelEx3.Width - 20;
  612. this.panelEx3.AutoScroll = true;
  613. }
  614. else
  615. {
  616. this.PictImage.Dock = DockStyle.Fill;
  617. }
  618. #endregion
  619. Bitmap newBmp = new Bitmap(this.PictImage.Width, TotalHeight);
  620. Graphics g = Graphics.FromImage(newBmp);
  621. g.Clear(System.Drawing.Color.White);
  622. int LeftWidth = 30;
  623. int TableWidth = newBmp.Width - LeftWidth * 2;
  624. int ColumnWidth1 = 30;
  625. int ColumnWidth2 = 80;
  626. int ColumnWidth3 = TableWidth - ColumnWidth1 - ColumnWidth2;
  627. #endregion
  628. #region 从高到低排序
  629. Hashtable htData = new Hashtable();
  630. Hashtable htDataPaid = new Hashtable();
  631. for (int i = 0; i < dt.Rows.Count; i++)
  632. {
  633. if (dt.Rows[i]["User_EmployeeID"].ToString().Trim() == "20180128180834992")
  634. {
  635. string txt = "";
  636. }
  637. DataRow[] dtRow = dtOrderCount.Select("OrdersPerson like '%" + dt.Rows[i]["User_EmployeeID"].ToString().Trim() + "%'");
  638. //DataRow[] towDataRow = towOrderCount.Select(" EmployeeID like '%" + dt.Rows[i]["User_EmployeeID"].ToString().Trim() + "%' ");
  639. decimal decOrdSeriesPrice = 0;
  640. decimal decOrdSeriesPaid = 0;
  641. for (int j = 0; j < dtRow.Length; j++)
  642. {
  643. if (dtRow[j]["OrdersPerson"].ToString().Trim().Length != dtRow[j]["OrdersPerson"].ToString().Trim().Replace(",", "").Length)
  644. {
  645. string[] StrArrayPerson = dtRow[j]["OrdersPerson"].ToString().Trim().Split(',');
  646. if (StrArrayPerson[0].Trim() == dt.Rows[i]["User_EmployeeID"].ToString().Trim())
  647. {
  648. if(dtRow[j]["类型"].ToString_s()== "订单")
  649. {
  650. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainDr, deputyDr);
  651. }
  652. else
  653. {
  654. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainTwoSalesDr, deputyTwoSalesDr);
  655. }
  656. //decOrdSeriesPrice += Convert.ToDecimal(dtRow[j]["主门市金额"]);
  657. decOrdSeriesPaid += Convert.ToDecimal(dtRow[j]["主门市实收"]);
  658. }
  659. else
  660. {
  661. if (dtRow[j]["类型"].ToString_s() == "订单")
  662. {
  663. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainDr, deputyDr);
  664. }
  665. else
  666. {
  667. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainTwoSalesDr, deputyTwoSalesDr);
  668. }
  669. //decOrdSeriesPrice += Convert.ToDecimal(dtRow[j]["副门市金额"]);
  670. decOrdSeriesPaid += Convert.ToDecimal(dtRow[j]["副门市实收"]);
  671. }
  672. }
  673. else
  674. {
  675. if (dtRow[j]["类型"].ToString_s() == "订单")
  676. {
  677. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainDr, deputyDr);
  678. }
  679. else
  680. {
  681. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainTwoSalesDr, deputyTwoSalesDr);
  682. }
  683. //decOrdSeriesPrice += Convert.ToDecimal(dtRow[j]["主门市金额"]);
  684. decOrdSeriesPaid += Convert.ToDecimal(dtRow[j]["主门市实收"]);
  685. }
  686. }
  687. //for (int j = 0; j < towDataRow.Length; j++)
  688. //{
  689. // DataRow dr = towDataRow[j];
  690. // if(dr["EmployeeID"].ToString().Contains(dt.Rows[i]["User_EmployeeID"].ToString().Trim()))
  691. // {
  692. // decOrdSeriesPrice += Convert.ToDecimal(dr["Price"]);
  693. // decOrdSeriesPaid += Convert.ToDecimal(dr["PayPrice"]);
  694. // }
  695. //}
  696. htData[dt.Rows[i]["User_EmployeeID"].ToString().Trim()] = decOrdSeriesPrice;
  697. htDataPaid[dt.Rows[i]["User_EmployeeID"].ToString().Trim()] = decOrdSeriesPaid;
  698. }
  699. string[] arrKey = new string[htData.Count]; //暂存 Hashtable 的键
  700. decimal[] arrValue = new decimal[htData.Count];//暂存 Hashtable 的值
  701. htData.Keys.CopyTo(arrKey, 0);
  702. htData.Values.CopyTo(arrValue, 0);
  703. Array.Sort(arrValue, arrKey); //按 HashTable 的值排序
  704. #endregion
  705. if (!this.chkComparedStartUp.Checked)
  706. {
  707. // StrItemName +
  708. #region 无启动对比
  709. string StrValue = Convert.ToDateTime(this.dtDataTimeStart.DateValue).ToString("yyyy年MM月dd日") + " — " + Convert.ToDateTime(this.dtDataTimeEnd.DateValue).ToString("yyyy年MM月dd日") + " " + this.cmbtreevDepartment.Text.Trim() + "分析表";
  710. SizeF sizef = g.MeasureString(StrValue, ft15);
  711. int FtHeigth = Convert.ToInt32(sizef.Height);
  712. int FtWidth = Convert.ToInt32(sizef.Width) + 1;
  713. Rectangle rec = new Rectangle(TableWidth / 2 - FtWidth / 2, ForTopLoad, FtWidth, FtHeigth);
  714. g.DrawString(StrValue, ft15, b, rec);//画消费法规
  715. ForTopLoad = rec.Y + rec.Height + 30;
  716. float ProgressWidth = float.Parse((newBmp.Width - 200).ToString());
  717. float WidthRatio = 0;
  718. int forint = 1;
  719. for (int i = arrKey.Length - 1; i >= 0; i--)
  720. {
  721. Rectangle rec1 = new Rectangle(LeftWidth, ForTopLoad, ColumnWidth1, RowHeight);
  722. g.DrawString(forint.ToString().Trim(), ft11, b, rec1);
  723. string StrUserName = "";
  724. DataRow[] dtRowUser = dt.Select("User_EmployeeID = '" + arrKey[i].ToString().Trim() + "'");
  725. if (dtRowUser.Length > 0)
  726. { StrUserName = dtRowUser[0]["User_Name"].ToString().Trim(); }
  727. Rectangle rec2 = new Rectangle(rec1.X + rec1.Width + 5, rec1.Y, ColumnWidth2, RowHeight);
  728. g.DrawString(StrUserName.Trim(), ft11, b, rec2);
  729. if (forint == 1)
  730. {
  731. if (float.Parse(arrValue[i].ToString()) > 0)
  732. { WidthRatio = ProgressWidth / float.Parse(arrValue[i].ToString()); }
  733. }
  734. int intValue = Convert.ToInt32(WidthRatio * float.Parse(arrValue[i].ToString()));
  735. Rectangle rec3 = new Rectangle(rec2.X + rec2.Width + 5, rec1.Y, intValue, 20);
  736. g.FillRectangle(Brushes.Red, rec3);
  737. SetPostionData(StrUserName, arrKey[i].ToString().Trim(), rec3, "", StrTimeStrat, StrTimeEnd);
  738. string StrPaid = htDataPaid[arrKey[i].ToString().Trim()].ToString().Trim();
  739. int intValuePaid = Convert.ToInt32(WidthRatio * float.Parse(StrPaid));
  740. if (intValuePaid > intValue)
  741. {
  742. if (Convert.ToDecimal(StrPaid) > Convert.ToDecimal(arrValue[arrKey.Length - 1]))
  743. { intValuePaid = Convert.ToInt32(WidthRatio * float.Parse(arrValue[arrKey.Length - 1].ToString())); }
  744. }
  745. Rectangle rec3Paid = new Rectangle(rec2.X + rec2.Width + 5, rec1.Y, intValuePaid, 20);
  746. g.FillRectangle(Brushes.Green, rec3Paid);
  747. int rec4LocationY = rec1.Y;
  748. if (intValue > 0 || intValuePaid > 0)
  749. { rec4LocationY -= 20; }
  750. string StrStatisticsText = "业绩:" + LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(arrValue[i]) + " 实收:" + LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(StrPaid) + " 欠款:" + LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(Convert.ToDecimal(arrValue[i]) - Convert.ToDecimal(StrPaid));
  751. sizef = g.MeasureString(StrStatisticsText, ft11);
  752. FtWidth = Convert.ToInt32(sizef.Width) + 1;
  753. FtHeigth = Convert.ToInt32(sizef.Height);
  754. Rectangle rec4 = new Rectangle(rec3.X, rec4LocationY, FtWidth, FtHeigth);
  755. g.DrawString(StrStatisticsText, ft11, b, rec4);
  756. ForTopLoad += rec1.Height + 20;
  757. forint++;
  758. }
  759. #endregion
  760. }
  761. else
  762. {
  763. #region 启动对比
  764. Hashtable htData2 = new Hashtable();
  765. Hashtable htDataPaid2 = new Hashtable();
  766. for (int i = 0; i < dt.Rows.Count; i++)
  767. {
  768. DataRow[] dtRow = dtOrderCountCompared.Select("OrdersPerson like '%" + dt.Rows[i]["User_EmployeeID"].ToString().Trim() + "%'");
  769. //DataRow[] towDataRow = towOrderCountCompared.Select(" EmployeeID like '%" + dt.Rows[i]["User_EmployeeID"].ToString().Trim() + "%' ");
  770. decimal decOrdSeriesPrice = 0;
  771. decimal decOrdSeriesPaid = 0;
  772. for (int j = 0; j < dtRow.Length; j++)
  773. {
  774. if (dtRow[j]["OrdersPerson"].ToString().Trim().Length != dtRow[j]["OrdersPerson"].ToString().Trim().Replace(",", "").Length)
  775. {
  776. string[] StrArrayPerson = dtRow[j]["OrdersPerson"].ToString().Trim().Split(',');
  777. if (StrArrayPerson[0].Trim() == dt.Rows[i]["User_EmployeeID"].ToString().Trim())
  778. {
  779. if (dtRow[j]["类型"].ToString_s() == "订单")
  780. {
  781. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainDr, deputyDr);
  782. }
  783. else
  784. {
  785. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainTwoSalesDr, deputyTwoSalesDr);
  786. }
  787. //decOrdSeriesPrice += Convert.ToDecimal(dtRow[j]["主门市金额"]);
  788. decOrdSeriesPaid += Convert.ToDecimal(dtRow[j]["主门市实收"]);
  789. }
  790. else
  791. {
  792. if (dtRow[j]["类型"].ToString_s() == "订单")
  793. {
  794. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainDr, deputyDr);
  795. }
  796. else
  797. {
  798. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainTwoSalesDr, deputyTwoSalesDr);
  799. }
  800. //decOrdSeriesPrice += Convert.ToDecimal(dtRow[j]["副门市金额"]);
  801. decOrdSeriesPaid += Convert.ToDecimal(dtRow[j]["副门市实收"]);
  802. }
  803. }
  804. else
  805. {
  806. if (dtRow[j]["类型"].ToString_s() == "订单")
  807. {
  808. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainDr, deputyDr);
  809. }
  810. else
  811. {
  812. decOrdSeriesPrice += GetAchievement(Convert.ToDecimal(dtRow[j]["SeriesPrice"]), dtRow[j]["OrdersPerson"].ToString(), dt.Rows[i]["User_EmployeeID"].ToString().Trim(), mainTwoSalesDr, deputyTwoSalesDr);
  813. }
  814. //decOrdSeriesPrice += Convert.ToDecimal(dtRow[j]["主门市金额"]);
  815. decOrdSeriesPaid += Convert.ToDecimal(dtRow[j]["主门市实收"]);
  816. }
  817. //decOrdSeriesPrice += Convert.ToDecimal(dtRow[j]["SeriesPrice"]);
  818. }
  819. //for (int j = 0; j < towDataRow.Length; j++)
  820. //{
  821. // DataRow dr = towDataRow[j];
  822. // if (dr["EmployeeID"].ToString().Contains(dt.Rows[i]["User_EmployeeID"].ToString().Trim()))
  823. // {
  824. // decOrdSeriesPrice += Convert.ToDecimal(dr["Price"]);
  825. // decOrdSeriesPaid += Convert.ToDecimal(dr["PayPrice"]);
  826. // }
  827. //}
  828. htData2[dt.Rows[i]["User_EmployeeID"].ToString().Trim()] = decOrdSeriesPrice;
  829. htDataPaid2[dt.Rows[i]["User_EmployeeID"].ToString().Trim()] = decOrdSeriesPaid;
  830. }
  831. string[] arrKey2 = new string[htData2.Count]; //暂存 Hashtable 的键
  832. decimal[] arrValue2 = new decimal[htData2.Count];//暂存 Hashtable 的值
  833. htData2.Keys.CopyTo(arrKey2, 0);
  834. htData2.Values.CopyTo(arrValue2, 0);
  835. Array.Sort(arrValue2, arrKey2); //按 HashTable 的值排序 + StrItemName
  836. string StrValue = StrTimeStrat + "—" + StrTimeEnd + " 与 " + StrTimeStratDb + "—" + StrTimeEndDb + " " + this.cmbtreevDepartment.Text.Trim() + "分析表";
  837. SizeF sizef = g.MeasureString(StrValue, ft15);
  838. int FtHeigth = Convert.ToInt32(sizef.Height);
  839. int FtWidth = Convert.ToInt32(sizef.Width) + 1;
  840. Rectangle rec = new Rectangle(TableWidth / 2 - FtWidth / 2, ForTopLoad, FtWidth, FtHeigth);
  841. g.DrawString(StrValue, ft15, b, rec);//画消费法规
  842. ForTopLoad = rec.Y + rec.Height + 30;
  843. float ProgressWidth = float.Parse((newBmp.Width - 200).ToString());
  844. float WidthRatio = 0;
  845. int forint = 1;
  846. for (int i = arrKey.Length - 1; i >= 0; i--)
  847. {
  848. Rectangle rec1 = new Rectangle(LeftWidth, ForTopLoad, ColumnWidth1, RowHeight);
  849. g.DrawString(forint.ToString().Trim(), ft11, b, rec1);
  850. string StrUserName = "";
  851. DataRow[] dtRowUser = dt.Select("User_EmployeeID = '" + arrKey[i].ToString().Trim() + "'");
  852. if (dtRowUser.Length > 0)
  853. { StrUserName = dtRowUser[0]["User_Name"].ToString().Trim(); }
  854. Rectangle rec2 = new Rectangle(rec1.X + rec1.Width + 5, rec1.Y, ColumnWidth2, RowHeight);
  855. g.DrawString(StrUserName, ft11, b, rec2);
  856. decimal StrValue1 = Convert.ToDecimal(arrValue[i]);
  857. if (forint == 1)
  858. {
  859. if (arrValue.Length > 0 && arrValue2.Length > 0)
  860. {
  861. if (float.Parse(arrValue[i].ToString()) >= float.Parse(arrValue2[arrValue2.Length - 1].ToString()))
  862. {
  863. if (Convert.ToDecimal(arrValue[i]) > 0)
  864. { WidthRatio = ProgressWidth / float.Parse(arrValue[i].ToString()); }
  865. }
  866. else
  867. {
  868. if (Convert.ToDecimal(arrValue2[arrValue2.Length - 1]) > 0)
  869. { WidthRatio = ProgressWidth / float.Parse(arrValue2[arrValue2.Length - 1].ToString()); }
  870. }
  871. }
  872. else if (arrValue.Length > 0 && arrValue2.Length == 0)
  873. {
  874. if (Convert.ToDecimal(arrValue[i]) > 0)
  875. { WidthRatio = ProgressWidth / float.Parse(arrValue[i].ToString()); }
  876. }
  877. else if (arrValue.Length == 0 && arrValue2.Length > 0)
  878. {
  879. if (Convert.ToDecimal(arrValue2[arrValue2.Length - 1]) > 0)
  880. { WidthRatio = ProgressWidth / float.Parse(arrValue2[arrValue2.Length - 1].ToString()); }
  881. }
  882. }
  883. int intValue1 = Convert.ToInt32(WidthRatio * float.Parse(arrValue[i].ToString()));
  884. Rectangle rec3 = new Rectangle(rec2.X + rec2.Width + 5, rec1.Y - 10, intValue1, 20);
  885. g.FillRectangle(Brushes.Red, rec3);
  886. SetPostionData(StrUserName, arrKey[i].ToString().Trim(), rec3, "", StrTimeStrat, StrTimeEnd);
  887. string StrPaid = htDataPaid[arrKey[i].ToString().Trim()].ToString().Trim();
  888. int intValuePaid = Convert.ToInt32(WidthRatio * float.Parse(StrPaid));
  889. if (intValuePaid > intValue1)
  890. {
  891. if (Convert.ToDecimal(StrPaid) > Convert.ToDecimal(arrValue[arrKey.Length - 1]))
  892. { intValuePaid = Convert.ToInt32(WidthRatio * float.Parse(arrValue[arrKey.Length - 1].ToString())); }
  893. }
  894. Rectangle rec3Paid = new Rectangle(rec3.X, rec3.Y, intValuePaid, 20);
  895. g.FillRectangle(Brushes.Green, rec3Paid);
  896. string StrStatisticsText = "业绩:" + LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(StrValue1) + " 实收:" + LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(StrPaid) + " 欠款:" + LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(Convert.ToDecimal(StrValue1) - Convert.ToDecimal(StrPaid));
  897. sizef = g.MeasureString(StrStatisticsText, ft11);
  898. FtWidth = Convert.ToInt32(sizef.Width) + 1;
  899. FtHeigth = Convert.ToInt32(sizef.Height);
  900. int rec4LocationY = rec3.Y;
  901. if (intValue1 > 0 || intValuePaid > 0)
  902. { rec4LocationY -= FtHeigth; }
  903. Rectangle rec4 = new Rectangle(rec3.X, rec4LocationY, FtWidth, FtHeigth);
  904. g.DrawString(StrStatisticsText, ft11, b, rec4);
  905. int intValue2 = 0;
  906. decimal StrValue2 = 0;
  907. if (htData2.ContainsKey(arrKey[i].ToString().Trim()))
  908. {
  909. if (Convert.ToDecimal(htData2[arrKey[i].ToString().Trim()]) > 0)
  910. {
  911. intValue2 = Convert.ToInt32(WidthRatio * float.Parse(htData2[arrKey[i].ToString().Trim()].ToString()));
  912. StrValue2 = Convert.ToDecimal(htData2[arrKey[i].ToString().Trim()]);
  913. }
  914. }
  915. Rectangle rec5 = new Rectangle(rec2.X + rec2.Width + 5, rec3.Y + rec3.Height + 1, intValue2, 20);
  916. g.FillRectangle(Brushes.Blue, rec5);
  917. SetPostionData(StrUserName, arrKey[i].ToString().Trim(), rec5, "", StrTimeStratDb, StrTimeEndDb);
  918. string StrPaid5 = htDataPaid2[arrKey[i].ToString().Trim()].ToString().Trim();
  919. int intValuePaid5 = Convert.ToInt32(WidthRatio * float.Parse(StrPaid5));
  920. if (intValuePaid5 > intValue1)
  921. {
  922. if (Convert.ToDecimal(StrPaid5) > Convert.ToDecimal(arrValue2[arrKey.Length - 1]))
  923. { intValuePaid5 = Convert.ToInt32(WidthRatio * float.Parse(arrValue2[arrKey.Length - 1].ToString())); }
  924. }
  925. Rectangle rec5Paid = new Rectangle(rec5.X, rec5.Y, intValuePaid5, 20);
  926. g.FillRectangle(Brushes.Green, rec5Paid);
  927. int rec4LocationY2 = rec5.Y;
  928. if (intValue2 > 0 || intValuePaid5 > 0)
  929. { rec4LocationY2 += rec5.Height; }
  930. StrStatisticsText = "业绩:" + LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(StrValue2) + " 实收:" + LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(StrPaid5) + " 欠款:" + LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(Convert.ToDecimal(StrValue2) - Convert.ToDecimal(StrPaid5));
  931. sizef = g.MeasureString(StrStatisticsText, ft11);
  932. FtWidth = Convert.ToInt32(sizef.Width) + 1;
  933. FtHeigth = Convert.ToInt32(sizef.Height);
  934. Rectangle rec6 = new Rectangle(rec3.X, rec4LocationY2, FtWidth, FtHeigth);
  935. g.DrawString(StrStatisticsText, ft11, b, rec6);
  936. string StrPercentage = "";
  937. if (StrValue2 != StrValue1)
  938. {
  939. if (StrValue1 > 0)
  940. {
  941. StrPercentage = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(LYFZ.Command.Command_Validate.GetIsNotRoundedString((StrValue1 - StrValue2) / StrValue1));
  942. if (StrValue1 > StrValue2)
  943. { StrPercentage = "同比上涨 " + StrPercentage.Replace("-", ""); }
  944. else
  945. { StrPercentage = "同比下降 " + StrPercentage.Replace("-", ""); }
  946. }
  947. else
  948. { StrPercentage = "同比下降 " + LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(StrValue2 - StrValue1); }
  949. }
  950. if (!string.IsNullOrEmpty(StrPercentage))
  951. { StrPercentage += "%"; }
  952. sizef = g.MeasureString(StrPercentage, ft11);
  953. FtWidth = Convert.ToInt32(sizef.Width) + 1;
  954. FtHeigth = Convert.ToInt32(sizef.Height);
  955. Rectangle rec7 = new Rectangle(rec4.X + rec4.Width + 30, rec4.Y, FtWidth, FtHeigth);
  956. g.DrawString(StrPercentage, ft11, b, rec7);
  957. ForTopLoad += rec1.Height + 60;
  958. forint++;
  959. }
  960. #endregion
  961. }
  962. this.PictImage.Image = newBmp;
  963. }
  964. string GetStoreTreeViewByStoreList()
  965. {
  966. string strDepartment = "";
  967. List<string> department = new List<string>();
  968. if( this.cmbtreevDepartment.Tag.ToString()=="")
  969. {
  970. foreach(TreeNode treeNode in this.cmbtreevDepartment.TreeView.Nodes)
  971. {
  972. department.AddRange(GetStoreTreeViewByDepartmentList(treeNode));
  973. }
  974. }
  975. else if (this.cmbtreevDepartment.SelectedNode.Nodes.Count>0)
  976. {
  977. department.AddRange(GetStoreTreeViewByDepartmentList(this.cmbtreevDepartment.SelectedNode));
  978. }
  979. else
  980. {
  981. department.Add(this.cmbtreevDepartment.SelectedNode.Tag.ToString());
  982. }
  983. strDepartment ="'" + string.Join("','", department.ToArray()) + "'";
  984. return strDepartment;
  985. }
  986. List<string> GetStoreTreeViewByDepartmentList(TreeNode treeNode)
  987. {
  988. List<string> department = new List<string>();
  989. foreach (TreeNode node in treeNode.Nodes)
  990. {
  991. department.Add(node.Tag.ToString());
  992. }
  993. return department;
  994. }
  995. decimal GetAchievement(decimal totalValue, string personData, string EmployeeName, DataRow mainDr, DataRow deputyDr)
  996. {
  997. string[] personList = personData.Split(',');
  998. if (personList.Length > 1)
  999. {
  1000. for (int i = 0; i < personList.Length; i++)
  1001. {
  1002. if (personList[i] == EmployeeName)
  1003. {
  1004. if (i == 0)
  1005. {
  1006. if (mainDr["Cp_Enabled"].ToString() == "1")
  1007. {
  1008. return totalValue / (Convert.ToInt32(mainDr["Cp_Proportion"]) + Convert.ToInt32(deputyDr["Cp_Proportion"]) * (personList.Length - 1)) * Convert.ToInt32(mainDr["Cp_Proportion"]);
  1009. }
  1010. else
  1011. {
  1012. return totalValue;
  1013. }
  1014. }
  1015. else
  1016. {
  1017. if (deputyDr["Cp_Enabled"].ToString() == "1")
  1018. {
  1019. return totalValue / (Convert.ToInt32(mainDr["Cp_Proportion"]) + Convert.ToInt32(deputyDr["Cp_Proportion"]) * (personList.Length - 1)) * Convert.ToInt32(deputyDr["Cp_Proportion"]);
  1020. }
  1021. else
  1022. {
  1023. return totalValue;
  1024. }
  1025. }
  1026. }
  1027. }
  1028. }
  1029. return totalValue;
  1030. }
  1031. }
  1032. }