frmCustomPerformance.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using LYFZ.ComponentLibrary;
  7. using System.Drawing;
  8. using LYFZ.BLL;
  9. namespace LYFZ.Software.MainBusiness.DoorCityProcess
  10. {
  11. public class frmCustomPerformance : LYFZ.Software.UI.DoorCityProcess.frmCustomPerformance
  12. {
  13. public frmCustomPerformance()
  14. {
  15. this.btnAddPerformancePerson.Click += BtnAddPerformancePerson_Click;
  16. this.Shown += FrmCustomPerformance_Shown;
  17. this.btnEnter.Click += BtnEnter_Click;
  18. this.btnCloes.Click += BtnCloes_Click;
  19. this.likAverageAllocation.Click += LikAverageAllocation_Click;
  20. this.likFullAllocation.Click += LikFullAllocation_Click;
  21. this.linkNoPerformance.Click += LinkNoPerformance_Click;
  22. #if DEBUG
  23. // this.isReadOnly = true;
  24. /* this._CollectionAmount = 5800.00m;
  25. LYFZ.Model.OrderPersonCommissionRatio personRatio = new Model.OrderPersonCommissionRatio();
  26. personRatio.IsMain = 0;
  27. personRatio.UserID = "20150507101744200";
  28. personRatio.CommissionRatio = 51.7241m;
  29. this.personCommissionRatio.OrderPersonCommissionRatioList.Add(personRatio);*/
  30. #else
  31. #endif
  32. }
  33. private void LinkNoPerformance_Click(object sender, EventArgs e)
  34. {
  35. this.UpdatePerformanceValue(0.00m);
  36. }
  37. private void LikFullAllocation_Click(object sender, EventArgs e)
  38. {
  39. this.UpdatePerformanceValue(100.00m);
  40. }
  41. private void LikAverageAllocation_Click(object sender, EventArgs e)
  42. {
  43. List<PerformancePerson> PersonList = this.GetPerformancePersonList();
  44. decimal AverageValue = 100.00m / (PersonList.Count==0?1 : PersonList.Count);
  45. this.UpdatePerformanceValue(AverageValue);
  46. }
  47. /// <summary>
  48. /// 更新业绩分配
  49. /// </summary>
  50. /// <param name="ratio"></param>
  51. void UpdatePerformanceValue(decimal ratio)
  52. {
  53. List<PerformancePerson> PersonList = this.GetPerformancePersonList();
  54. if (PersonList.Count > 0)
  55. {
  56. if (this.verificationUserID(PersonList))
  57. {
  58. foreach (PerformancePerson person in PersonList)
  59. {
  60. person.PerformanceRatio.Value = ratio;
  61. }
  62. }
  63. else
  64. {
  65. MessageBoxCustom.Show("业绩人不能重复");
  66. }
  67. }
  68. }
  69. private void BtnCloes_Click(object sender, EventArgs e)
  70. {
  71. this.DialogResult = DialogResult.Cancel;
  72. }
  73. private void BtnEnter_Click(object sender, EventArgs e)
  74. {
  75. List<PerformancePerson> PersonList = this.GetPerformancePersonList();
  76. if (this.GetOrderPersonCommissionRatio(PersonList))
  77. {
  78. this.DialogResult = DialogResult.OK;
  79. }
  80. }
  81. bool GetOrderPersonCommissionRatio(List<PerformancePerson> PersonList)
  82. {
  83. bool bl = true;
  84. if (this.verificationUserID(PersonList))
  85. {
  86. this.personCommissionRatio.OrderPersonCommissionRatioList.Clear();
  87. foreach (PerformancePerson person in PersonList)
  88. {
  89. if (person.GetOrderPersonCommissionRatio())
  90. {
  91. this.personCommissionRatio.OrderPersonCommissionRatioList.Add(person.CurrentPersonRatio);
  92. }
  93. }
  94. if (this.personCommissionRatio.OrderPersonCommissionRatioList.Count <= 0)
  95. {
  96. bl = false;
  97. MessageBoxCustom.Show("最少需要设置一个业绩人");
  98. }
  99. this.personCommissionRatio.OrderPersonCommissionRatioList = this.personCommissionRatio.OrderPersonCommissionRatioList.OrderBy(p => p.IsMain).ThenBy(p => p.IsAttachUser).ToList();
  100. }
  101. else {
  102. bl = false;
  103. MessageBoxCustom.Show("业绩人不能重复");
  104. }
  105. return bl;
  106. }
  107. /// <summary>
  108. /// 验证用户是否选择重复
  109. /// </summary>
  110. /// <returns></returns>
  111. bool verificationUserID(List<PerformancePerson> PersonList)
  112. {
  113. bool bl = true;
  114. List<string> userIDList = new List<string>();
  115. foreach (PerformancePerson person in PersonList)
  116. {
  117. if (person.Verification())
  118. {
  119. if (!userIDList.Contains(person.ComboBoxTreeView.Tag.ToString()))
  120. {
  121. userIDList.Add(person.ComboBoxTreeView.Tag.ToString());
  122. }
  123. else
  124. {
  125. bl = false;
  126. break;
  127. }
  128. }
  129. }
  130. return bl;
  131. }
  132. List<PerformancePerson> GetPerformancePersonList()
  133. {
  134. List<PerformancePerson> userIDList = new List<PerformancePerson>();
  135. foreach (Control PanelPerson in this.plPerformancePersonList.Controls)
  136. {
  137. if (PanelPerson.GetType() == typeof(Panel))
  138. {
  139. if (PanelPerson.Tag != null)
  140. {
  141. PerformancePerson person = (PerformancePerson)PanelPerson.Tag;
  142. if (person.Verification())
  143. {
  144. userIDList.Add(person);
  145. }
  146. }
  147. }
  148. }
  149. return userIDList.OrderBy(p=>p.Index).ToList();
  150. }
  151. /// <summary>
  152. /// 根据接单人ID 初始化业绩分配 多个接单人时 用“,”逗号分隔
  153. /// </summary>
  154. /// <param name="orderPersons"></param>
  155. public void OrderPersonInitialization(string orderPersons)
  156. {
  157. this.PersonCommissionRatio = new BLL.OrderPersonCommissionRatio();
  158. foreach (string person in orderPersons.Split(','))
  159. {
  160. if (!String.IsNullOrWhiteSpace(person))
  161. {
  162. LYFZ.Model.OrderPersonCommissionRatio commissionRatio = new Model.OrderPersonCommissionRatio();
  163. if (this.PersonCommissionRatio.OrderPersonCommissionRatioList.Count <= 0)
  164. {
  165. commissionRatio.IsMain = 0;
  166. }
  167. else
  168. {
  169. commissionRatio.IsMain = 1;
  170. }
  171. commissionRatio.IsAttachUser = 0;
  172. commissionRatio.UserID = person;
  173. commissionRatio.CommissionRatio = 100.00m;
  174. if (!this.PersonCommissionRatio.OrderPersonCommissionRatioList.Any(p => p.UserID == person))
  175. {
  176. this.PersonCommissionRatio.OrderPersonCommissionRatioList.Add(commissionRatio);
  177. }
  178. }
  179. }
  180. }
  181. /// <summary>
  182. /// 根据已设置的业绩分配JsonData数据初始化业绩分配
  183. /// </summary>
  184. /// <param name="commissionRatioJsonData"></param>
  185. public void PersonCommissionRatioJsonDataInitialization(string commissionRatioJsonData)
  186. {
  187. if (!String.IsNullOrWhiteSpace(commissionRatioJsonData))
  188. {
  189. this.PersonCommissionRatio = new BLL.OrderPersonCommissionRatio(commissionRatioJsonData);
  190. }
  191. }
  192. /// <summary>
  193. /// 绑定业绩分配结果
  194. /// </summary>
  195. /// <param name="listBoxPerformance"></param>
  196. public void BindListBoxPerformance(ComponentLibrary.ListBoxEx listBoxPerformance)
  197. {
  198. listBoxPerformance.Items.Clear();
  199. listBoxPerformance.Tag = personCommissionRatio;
  200. foreach (LYFZ.Model.OrderPersonCommissionRatio commissionRatio in this.personCommissionRatio.OrderPersonCommissionRatioList)
  201. {
  202. listBoxPerformance.Items.Add(String.Format("{0}({1}元*{2}%={3}元)"
  203. ,LYFZ.DAL.DAL_ErpUser.GetUserIDToUserName(commissionRatio.UserID)
  204. ,this.CollectionAmount.ToString("n2")
  205. , commissionRatio.CommissionRatio.ToString("n4")
  206. , (this.CollectionAmount* commissionRatio.CommissionRatio/100.00m).ToString("n2")));
  207. }
  208. }
  209. bool isReadOnly = false;
  210. decimal _CollectionAmount = 0.00m;
  211. OrderPersonCommissionRatio personCommissionRatio = new OrderPersonCommissionRatio();
  212. /// <summary>
  213. /// 业绩人提成分配信息
  214. /// </summary>
  215. public OrderPersonCommissionRatio PersonCommissionRatio { get => personCommissionRatio; set => personCommissionRatio = value; }
  216. /// <summary>
  217. /// 收款金额
  218. /// </summary>
  219. public decimal CollectionAmount { get => _CollectionAmount; set => _CollectionAmount = value; }
  220. /// <summary>
  221. /// 是否为只读查看模式
  222. /// </summary>
  223. public bool IsReadOnly { get => isReadOnly; set => isReadOnly = value; }
  224. private void FrmCustomPerformance_Shown(object sender, EventArgs e)
  225. {
  226. if (this.plPerformancePersonList.Controls.Count <= 0)
  227. {
  228. this.BindPerformancePersonControls();
  229. }
  230. }
  231. /// <summary>
  232. /// 绑定业绩人控件
  233. /// </summary>
  234. public void BindPerformancePersonControls()
  235. {
  236. if (this.isReadOnly)
  237. {
  238. this.btnAddPerformancePerson.Enabled = false;
  239. this.btnEnter.Enabled = false;
  240. this.likFullAllocation.Enabled = false;
  241. this.likAverageAllocation.Enabled = false;
  242. this.linkNoPerformance.Enabled = false;
  243. }
  244. this.txtPaymentAmount.Text = this.CollectionAmount.ToString("n2");
  245. this.SuspendLayout();
  246. foreach (LYFZ.Model.OrderPersonCommissionRatio personRatio in this.personCommissionRatio.OrderPersonCommissionRatioList)
  247. {
  248. PerformancePerson person = new PerformancePerson(this.CollectionAmount, personRatio, this.plPerformancePersonList.Controls.Count);
  249. person.PanelPerformancePerson.Size = new Size(this.flowLayoutPanel1.Width, 32);
  250. this.plPerformancePersonList.Controls.Add(person.PanelPerformancePerson);
  251. person.PanelPerformancePerson.BringToFront();
  252. if (this.isReadOnly)
  253. {
  254. person.PanelPerformancePerson.Enabled = false;
  255. }
  256. }
  257. this.SetFormHeight();
  258. this.ResumeLayout();
  259. }
  260. private void BtnAddPerformancePerson_Click(object sender, EventArgs e)
  261. {
  262. if (this.plPerformancePersonList.Controls.Count < 8)
  263. {
  264. PerformancePerson person = new PerformancePerson(this.CollectionAmount, this.plPerformancePersonList.Controls.Count);
  265. person.PanelPerformancePerson.Size = new Size(this.flowLayoutPanel1.Width, 32);
  266. this.plPerformancePersonList.Controls.Add(person.PanelPerformancePerson);
  267. person.PanelPerformancePerson.BringToFront();
  268. }
  269. else {
  270. MessageBoxCustom.Show("业绩分配人最多只能添加 8 个");
  271. }
  272. this.SetFormHeight();
  273. }
  274. void SetFormHeight()
  275. {
  276. int pCount = this.plPerformancePersonList.Controls.Count - 3;
  277. if (pCount <= 0)
  278. {
  279. pCount = 0;
  280. }
  281. this.plPerformancePersonList.Height = 100 + pCount * 32;
  282. this.Height = 180 + this.plPerformancePersonList.Height;
  283. }
  284. }
  285. public class PerformancePerson
  286. {
  287. public PerformancePerson(decimal collectionAmount, int _index)
  288. :this(collectionAmount, null,_index)
  289. {
  290. }
  291. public PerformancePerson(decimal collectionAmount, LYFZ.Model.OrderPersonCommissionRatio personRatio,int _index) {
  292. if (personRatio != null)
  293. {
  294. this.CurrentPersonRatio = personRatio;
  295. }
  296. else {
  297. this.CurrentPersonRatio.IsAttachUser = 1;
  298. this.CurrentPersonRatio.IsMain = 1;
  299. }
  300. this.index = _index;
  301. this._ComboBoxTreeView.TreeView.AfterSelect += TreeView_AfterSelect;
  302. this.currentCollectionAmount = collectionAmount;
  303. this._PerformanceRatio.KeyUp += _PerformanceRatio_KeyUp;
  304. this._PerformanceAmount.KeyUp += _PerformanceAmount_KeyUp;
  305. this._PerformanceRatio.ValueChanged += _PerformanceRatio_ValueChanged;
  306. this._PerformanceAmount.ValueChanged += _PerformanceAmount_ValueChanged;
  307. this._PerformanceRatio.Font = new Font("微软雅黑", this._PerformanceRatio.Font.Size);
  308. this._PerformanceAmount.Font = new Font("微软雅黑", this._PerformanceAmount.Font.Size);
  309. this._PerformanceRatio.Width = 130;
  310. this._PerformanceAmount.Width = 130;
  311. this._PerformanceRatio.TextAlign = HorizontalAlignment.Center;
  312. this._PerformanceAmount.TextAlign = HorizontalAlignment.Center;
  313. this._PerformanceRatio.Minimum = -999999999;
  314. this._PerformanceRatio.Maximum = 999999999;
  315. this._PerformanceAmount.Minimum = -999999999;
  316. this._PerformanceAmount.Maximum = 999999999;
  317. this._PerformanceRatio.DecimalPlaces = 4;
  318. this._PerformanceAmount.DecimalPlaces = 2;
  319. this._PanelPerformancePerson.Dock = DockStyle.Top;
  320. // this._PanelPerformancePerson.BackColor = Color.Red;
  321. LabelEx label0 = this.GetNewLabelEx(String.Format("业绩人{0}:",this.index+1), new Point(17, 7));
  322. this._PanelPerformancePerson.Controls.Add(label0);
  323. this._ComboBoxTreeView.Width = 170;
  324. this._ComboBoxTreeView.ReadOnly = true;
  325. this._ComboBoxTreeView.Location = new Point(label0.Location.X+ label0.Width+2, label0.Location.Y);
  326. this._PanelPerformancePerson.Controls.Add(this._ComboBoxTreeView);
  327. LabelEx label1 = this.GetNewLabelEx("业绩比例(%):", new Point(_ComboBoxTreeView.Location.X + _ComboBoxTreeView.Width + 10, _ComboBoxTreeView.Location.Y));
  328. this._PanelPerformancePerson.Controls.Add(label1);
  329. this._PerformanceRatio.Location = new Point(label1.Location.X + label1.Width + 2, label1.Location.Y);
  330. this._PanelPerformancePerson.Controls.Add(this._PerformanceRatio);
  331. LabelEx label2 = this.GetNewLabelEx("业绩金额(元):", new Point(_PerformanceRatio.Location.X + _PerformanceRatio.Width + 10, _PerformanceRatio.Location.Y));
  332. this._PanelPerformancePerson.Controls.Add(label2);
  333. this._PerformanceAmount.Location = new Point(label2.Location.X + label2.Width + 2, label2.Location.Y);
  334. this._PanelPerformancePerson.Controls.Add(this._PerformanceAmount);
  335. LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee(this._ComboBoxTreeView, IsFirstNodeNull: true, IsShowResign: false, tb_User: LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable);
  336. if (!String.IsNullOrWhiteSpace(this.CurrentPersonRatio.UserID))
  337. {
  338. this._PerformanceRatio.Tag = 1;
  339. this._PerformanceRatio.Value = this.CurrentPersonRatio.CommissionRatio;
  340. this._PerformanceAmount.Value = collectionAmount * this.CurrentPersonRatio.CommissionRatio / 100.00m;
  341. this._ComboBoxTreeView.TagFindText(this.CurrentPersonRatio.UserID);
  342. }
  343. if (this.CurrentPersonRatio.IsAttachUser == 1)
  344. {
  345. this._ComboBoxTreeView.Enabled = true;
  346. }
  347. else {
  348. this._ComboBoxTreeView.Enabled = false;
  349. }
  350. this._PanelPerformancePerson.Tag = this;
  351. }
  352. private void TreeView_AfterSelect(object sender, TreeViewEventArgs e)
  353. {
  354. if (e.Node.Nodes.Count <= 0)
  355. {
  356. if (this._PerformanceRatio.Tag == null && !String.IsNullOrWhiteSpace(e.Node.Text.Trim()))
  357. {
  358. this._PerformanceRatio.Tag = 1;
  359. this._PerformanceRatio.Value = 100;
  360. this._PerformanceAmount.Value = this.currentCollectionAmount;
  361. }
  362. else if(String.IsNullOrWhiteSpace(e.Node.Text.Trim()))
  363. {
  364. this._PerformanceRatio.Tag = null;
  365. this._PerformanceRatio.Value = 0;
  366. this._PerformanceAmount.Value = 0;
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// 获取业绩人业绩分配比例值
  372. /// </summary>
  373. /// <returns></returns>
  374. public bool GetOrderPersonCommissionRatio()
  375. {
  376. if (this.Verification())
  377. {
  378. this.currentPersonRatio.UserID = this._ComboBoxTreeView.Tag.ToString();
  379. this.currentPersonRatio.CommissionRatio = this._PerformanceRatio.Value;
  380. return true;
  381. }
  382. else {
  383. return false;
  384. }
  385. }
  386. /// <summary>
  387. /// 验证是否已选择业绩人
  388. /// </summary>
  389. /// <returns></returns>
  390. public bool Verification()
  391. {
  392. if (this._ComboBoxTreeView.Tag != null && !String.IsNullOrWhiteSpace(this._ComboBoxTreeView.Tag.ToString()))
  393. {
  394. return true;
  395. }
  396. else
  397. {
  398. return false;
  399. }
  400. }
  401. /// <summary>
  402. /// 获取用户ID
  403. /// </summary>
  404. /// <returns></returns>
  405. public string GetUserID()
  406. {
  407. if (this.Verification())
  408. {
  409. return this._ComboBoxTreeView.Tag.ToString();
  410. }
  411. else {
  412. return "";
  413. }
  414. }
  415. private void _PerformanceAmount_KeyUp(object sender, KeyEventArgs e)
  416. {
  417. if (e.KeyCode == Keys.Enter)
  418. {
  419. this._PerformanceAmount_ValueChanged(sender,null);
  420. }
  421. }
  422. private void _PerformanceRatio_KeyUp(object sender, KeyEventArgs e)
  423. {
  424. if (e.KeyCode == Keys.Enter)
  425. {
  426. this._PerformanceRatio_ValueChanged(sender, null);
  427. }
  428. }
  429. private void _PerformanceAmount_ValueChanged(object sender, EventArgs e)
  430. {
  431. // if (this._PerformanceAmount.Focused)
  432. {
  433. this._PerformanceRatio.Value = this._PerformanceAmount.Value / this.currentCollectionAmount * 100.00m;
  434. }
  435. }
  436. private void _PerformanceRatio_ValueChanged(object sender, EventArgs e)
  437. {
  438. //if (this._PerformanceRatio.Focused)
  439. {
  440. this._PerformanceAmount.Value = this.currentCollectionAmount * this._PerformanceRatio.Value / 100.00m;
  441. }
  442. }
  443. LabelEx GetNewLabelEx(string text,Point point)
  444. {
  445. LabelEx label = new LabelEx();
  446. label.AutoSize = true;
  447. label.Text = text;
  448. label.Location = point;
  449. label.Padding=new Padding(0,2,0,0);
  450. return label;
  451. }
  452. int index = 0;
  453. decimal currentCollectionAmount = 0.00m;
  454. LYFZ.Model.OrderPersonCommissionRatio currentPersonRatio = new Model.OrderPersonCommissionRatio();
  455. Panel _PanelPerformancePerson = new Panel();
  456. LYFZ.ComponentLibrary.ComboBoxTreeViewEx _ComboBoxTreeView = new ComponentLibrary.ComboBoxTreeViewEx();
  457. LYFZ.ComponentLibrary.NumericUpDownEx _PerformanceRatio = new ComponentLibrary.NumericUpDownEx();
  458. LYFZ.ComponentLibrary.NumericUpDownEx _PerformanceAmount = new ComponentLibrary.NumericUpDownEx();
  459. /// <summary>
  460. /// Panel组容器
  461. /// </summary>
  462. public Panel PanelPerformancePerson { get => _PanelPerformancePerson; set => _PanelPerformancePerson = value; }
  463. /// <summary>
  464. /// 业绩人
  465. /// </summary>
  466. public ComboBoxTreeViewEx ComboBoxTreeView { get => _ComboBoxTreeView; set => _ComboBoxTreeView = value; }
  467. /// <summary>
  468. /// 业绩比例(%)
  469. /// </summary>
  470. public NumericUpDownEx PerformanceRatio { get => _PerformanceRatio; set => _PerformanceRatio = value; }
  471. /// <summary>
  472. /// 业绩金额(元)
  473. /// </summary>
  474. public NumericUpDownEx PerformanceAmount { get => _PerformanceAmount; set => _PerformanceAmount = value; }
  475. /// <summary>
  476. /// 当前等分配的金额
  477. /// </summary>
  478. public decimal CurrentCollectionAmount { get => currentCollectionAmount; set => currentCollectionAmount = value; }
  479. /// <summary>
  480. /// 当前业绩分配信息
  481. /// </summary>
  482. public Model.OrderPersonCommissionRatio CurrentPersonRatio { get => currentPersonRatio; set => currentPersonRatio = value; }
  483. /// <summary>
  484. /// 索引
  485. /// </summary>
  486. public int Index { get => index; set => index = value; }
  487. }
  488. }