using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using LYFZ.ComponentLibrary; using System.Drawing; using LYFZ.BLL; namespace LYFZ.Software.MainBusiness.DoorCityProcess { public class frmCustomPerformance : LYFZ.Software.UI.DoorCityProcess.frmCustomPerformance { public frmCustomPerformance() { this.btnAddPerformancePerson.Click += BtnAddPerformancePerson_Click; this.Shown += FrmCustomPerformance_Shown; this.btnEnter.Click += BtnEnter_Click; this.btnCloes.Click += BtnCloes_Click; this.likAverageAllocation.Click += LikAverageAllocation_Click; this.likFullAllocation.Click += LikFullAllocation_Click; this.linkNoPerformance.Click += LinkNoPerformance_Click; #if DEBUG // this.isReadOnly = true; /* this._CollectionAmount = 5800.00m; LYFZ.Model.OrderPersonCommissionRatio personRatio = new Model.OrderPersonCommissionRatio(); personRatio.IsMain = 0; personRatio.UserID = "20150507101744200"; personRatio.CommissionRatio = 51.7241m; this.personCommissionRatio.OrderPersonCommissionRatioList.Add(personRatio);*/ #else #endif } private void LinkNoPerformance_Click(object sender, EventArgs e) { this.UpdatePerformanceValue(0.00m); } private void LikFullAllocation_Click(object sender, EventArgs e) { this.UpdatePerformanceValue(100.00m); } private void LikAverageAllocation_Click(object sender, EventArgs e) { List PersonList = this.GetPerformancePersonList(); decimal AverageValue = 100.00m / (PersonList.Count==0?1 : PersonList.Count); this.UpdatePerformanceValue(AverageValue); } /// /// 更新业绩分配 /// /// void UpdatePerformanceValue(decimal ratio) { List PersonList = this.GetPerformancePersonList(); if (PersonList.Count > 0) { if (this.verificationUserID(PersonList)) { foreach (PerformancePerson person in PersonList) { person.PerformanceRatio.Value = ratio; } } else { MessageBoxCustom.Show("业绩人不能重复"); } } } private void BtnCloes_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } private void BtnEnter_Click(object sender, EventArgs e) { List PersonList = this.GetPerformancePersonList(); if (this.GetOrderPersonCommissionRatio(PersonList)) { this.DialogResult = DialogResult.OK; } } bool GetOrderPersonCommissionRatio(List PersonList) { bool bl = true; if (this.verificationUserID(PersonList)) { this.personCommissionRatio.OrderPersonCommissionRatioList.Clear(); foreach (PerformancePerson person in PersonList) { if (person.GetOrderPersonCommissionRatio()) { this.personCommissionRatio.OrderPersonCommissionRatioList.Add(person.CurrentPersonRatio); } } if (this.personCommissionRatio.OrderPersonCommissionRatioList.Count <= 0) { bl = false; MessageBoxCustom.Show("最少需要设置一个业绩人"); } this.personCommissionRatio.OrderPersonCommissionRatioList = this.personCommissionRatio.OrderPersonCommissionRatioList.OrderBy(p => p.IsMain).ThenBy(p => p.IsAttachUser).ToList(); } else { bl = false; MessageBoxCustom.Show("业绩人不能重复"); } return bl; } /// /// 验证用户是否选择重复 /// /// bool verificationUserID(List PersonList) { bool bl = true; List userIDList = new List(); foreach (PerformancePerson person in PersonList) { if (person.Verification()) { if (!userIDList.Contains(person.ComboBoxTreeView.Tag.ToString())) { userIDList.Add(person.ComboBoxTreeView.Tag.ToString()); } else { bl = false; break; } } } return bl; } List GetPerformancePersonList() { List userIDList = new List(); foreach (Control PanelPerson in this.plPerformancePersonList.Controls) { if (PanelPerson.GetType() == typeof(Panel)) { if (PanelPerson.Tag != null) { PerformancePerson person = (PerformancePerson)PanelPerson.Tag; if (person.Verification()) { userIDList.Add(person); } } } } return userIDList.OrderBy(p=>p.Index).ToList(); } /// /// 根据接单人ID 初始化业绩分配 多个接单人时 用“,”逗号分隔 /// /// public void OrderPersonInitialization(string orderPersons) { this.PersonCommissionRatio = new BLL.OrderPersonCommissionRatio(); foreach (string person in orderPersons.Split(',')) { if (!String.IsNullOrWhiteSpace(person)) { LYFZ.Model.OrderPersonCommissionRatio commissionRatio = new Model.OrderPersonCommissionRatio(); if (this.PersonCommissionRatio.OrderPersonCommissionRatioList.Count <= 0) { commissionRatio.IsMain = 0; } else { commissionRatio.IsMain = 1; } commissionRatio.IsAttachUser = 0; commissionRatio.UserID = person; commissionRatio.CommissionRatio = 100.00m; if (!this.PersonCommissionRatio.OrderPersonCommissionRatioList.Any(p => p.UserID == person)) { this.PersonCommissionRatio.OrderPersonCommissionRatioList.Add(commissionRatio); } } } } /// /// 根据已设置的业绩分配JsonData数据初始化业绩分配 /// /// public void PersonCommissionRatioJsonDataInitialization(string commissionRatioJsonData) { if (!String.IsNullOrWhiteSpace(commissionRatioJsonData)) { this.PersonCommissionRatio = new BLL.OrderPersonCommissionRatio(commissionRatioJsonData); } } /// /// 绑定业绩分配结果 /// /// public void BindListBoxPerformance(ComponentLibrary.ListBoxEx listBoxPerformance) { listBoxPerformance.Items.Clear(); listBoxPerformance.Tag = personCommissionRatio; foreach (LYFZ.Model.OrderPersonCommissionRatio commissionRatio in this.personCommissionRatio.OrderPersonCommissionRatioList) { listBoxPerformance.Items.Add(String.Format("{0}({1}元*{2}%={3}元)" ,LYFZ.DAL.DAL_ErpUser.GetUserIDToUserName(commissionRatio.UserID) ,this.CollectionAmount.ToString("n2") , commissionRatio.CommissionRatio.ToString("n4") , (this.CollectionAmount* commissionRatio.CommissionRatio/100.00m).ToString("n2"))); } } bool isReadOnly = false; decimal _CollectionAmount = 0.00m; OrderPersonCommissionRatio personCommissionRatio = new OrderPersonCommissionRatio(); /// /// 业绩人提成分配信息 /// public OrderPersonCommissionRatio PersonCommissionRatio { get => personCommissionRatio; set => personCommissionRatio = value; } /// /// 收款金额 /// public decimal CollectionAmount { get => _CollectionAmount; set => _CollectionAmount = value; } /// /// 是否为只读查看模式 /// public bool IsReadOnly { get => isReadOnly; set => isReadOnly = value; } private void FrmCustomPerformance_Shown(object sender, EventArgs e) { if (this.plPerformancePersonList.Controls.Count <= 0) { this.BindPerformancePersonControls(); } } /// /// 绑定业绩人控件 /// public void BindPerformancePersonControls() { if (this.isReadOnly) { this.btnAddPerformancePerson.Enabled = false; this.btnEnter.Enabled = false; this.likFullAllocation.Enabled = false; this.likAverageAllocation.Enabled = false; this.linkNoPerformance.Enabled = false; } this.txtPaymentAmount.Text = this.CollectionAmount.ToString("n2"); this.SuspendLayout(); foreach (LYFZ.Model.OrderPersonCommissionRatio personRatio in this.personCommissionRatio.OrderPersonCommissionRatioList) { PerformancePerson person = new PerformancePerson(this.CollectionAmount, personRatio, this.plPerformancePersonList.Controls.Count); person.PanelPerformancePerson.Size = new Size(this.flowLayoutPanel1.Width, 32); this.plPerformancePersonList.Controls.Add(person.PanelPerformancePerson); person.PanelPerformancePerson.BringToFront(); if (this.isReadOnly) { person.PanelPerformancePerson.Enabled = false; } } this.SetFormHeight(); this.ResumeLayout(); } private void BtnAddPerformancePerson_Click(object sender, EventArgs e) { if (this.plPerformancePersonList.Controls.Count < 8) { PerformancePerson person = new PerformancePerson(this.CollectionAmount, this.plPerformancePersonList.Controls.Count); person.PanelPerformancePerson.Size = new Size(this.flowLayoutPanel1.Width, 32); this.plPerformancePersonList.Controls.Add(person.PanelPerformancePerson); person.PanelPerformancePerson.BringToFront(); } else { MessageBoxCustom.Show("业绩分配人最多只能添加 8 个"); } this.SetFormHeight(); } void SetFormHeight() { int pCount = this.plPerformancePersonList.Controls.Count - 3; if (pCount <= 0) { pCount = 0; } this.plPerformancePersonList.Height = 100 + pCount * 32; this.Height = 180 + this.plPerformancePersonList.Height; } } public class PerformancePerson { public PerformancePerson(decimal collectionAmount, int _index) :this(collectionAmount, null,_index) { } public PerformancePerson(decimal collectionAmount, LYFZ.Model.OrderPersonCommissionRatio personRatio,int _index) { if (personRatio != null) { this.CurrentPersonRatio = personRatio; } else { this.CurrentPersonRatio.IsAttachUser = 1; this.CurrentPersonRatio.IsMain = 1; } this.index = _index; this._ComboBoxTreeView.TreeView.AfterSelect += TreeView_AfterSelect; this.currentCollectionAmount = collectionAmount; this._PerformanceRatio.KeyUp += _PerformanceRatio_KeyUp; this._PerformanceAmount.KeyUp += _PerformanceAmount_KeyUp; this._PerformanceRatio.ValueChanged += _PerformanceRatio_ValueChanged; this._PerformanceAmount.ValueChanged += _PerformanceAmount_ValueChanged; this._PerformanceRatio.Font = new Font("微软雅黑", this._PerformanceRatio.Font.Size); this._PerformanceAmount.Font = new Font("微软雅黑", this._PerformanceAmount.Font.Size); this._PerformanceRatio.Width = 130; this._PerformanceAmount.Width = 130; this._PerformanceRatio.TextAlign = HorizontalAlignment.Center; this._PerformanceAmount.TextAlign = HorizontalAlignment.Center; this._PerformanceRatio.Minimum = -999999999; this._PerformanceRatio.Maximum = 999999999; this._PerformanceAmount.Minimum = -999999999; this._PerformanceAmount.Maximum = 999999999; this._PerformanceRatio.DecimalPlaces = 4; this._PerformanceAmount.DecimalPlaces = 2; this._PanelPerformancePerson.Dock = DockStyle.Top; // this._PanelPerformancePerson.BackColor = Color.Red; LabelEx label0 = this.GetNewLabelEx(String.Format("业绩人{0}:",this.index+1), new Point(17, 7)); this._PanelPerformancePerson.Controls.Add(label0); this._ComboBoxTreeView.Width = 170; this._ComboBoxTreeView.ReadOnly = true; this._ComboBoxTreeView.Location = new Point(label0.Location.X+ label0.Width+2, label0.Location.Y); this._PanelPerformancePerson.Controls.Add(this._ComboBoxTreeView); LabelEx label1 = this.GetNewLabelEx("业绩比例(%):", new Point(_ComboBoxTreeView.Location.X + _ComboBoxTreeView.Width + 10, _ComboBoxTreeView.Location.Y)); this._PanelPerformancePerson.Controls.Add(label1); this._PerformanceRatio.Location = new Point(label1.Location.X + label1.Width + 2, label1.Location.Y); this._PanelPerformancePerson.Controls.Add(this._PerformanceRatio); LabelEx label2 = this.GetNewLabelEx("业绩金额(元):", new Point(_PerformanceRatio.Location.X + _PerformanceRatio.Width + 10, _PerformanceRatio.Location.Y)); this._PanelPerformancePerson.Controls.Add(label2); this._PerformanceAmount.Location = new Point(label2.Location.X + label2.Width + 2, label2.Location.Y); this._PanelPerformancePerson.Controls.Add(this._PerformanceAmount); LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_DepartmentAndEmployee(this._ComboBoxTreeView, IsFirstNodeNull: true, IsShowResign: false, tb_User: LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable); if (!String.IsNullOrWhiteSpace(this.CurrentPersonRatio.UserID)) { this._PerformanceRatio.Tag = 1; this._PerformanceRatio.Value = this.CurrentPersonRatio.CommissionRatio; this._PerformanceAmount.Value = collectionAmount * this.CurrentPersonRatio.CommissionRatio / 100.00m; this._ComboBoxTreeView.TagFindText(this.CurrentPersonRatio.UserID); } if (this.CurrentPersonRatio.IsAttachUser == 1) { this._ComboBoxTreeView.Enabled = true; } else { this._ComboBoxTreeView.Enabled = false; } this._PanelPerformancePerson.Tag = this; } private void TreeView_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node.Nodes.Count <= 0) { if (this._PerformanceRatio.Tag == null && !String.IsNullOrWhiteSpace(e.Node.Text.Trim())) { this._PerformanceRatio.Tag = 1; this._PerformanceRatio.Value = 100; this._PerformanceAmount.Value = this.currentCollectionAmount; } else if(String.IsNullOrWhiteSpace(e.Node.Text.Trim())) { this._PerformanceRatio.Tag = null; this._PerformanceRatio.Value = 0; this._PerformanceAmount.Value = 0; } } } /// /// 获取业绩人业绩分配比例值 /// /// public bool GetOrderPersonCommissionRatio() { if (this.Verification()) { this.currentPersonRatio.UserID = this._ComboBoxTreeView.Tag.ToString(); this.currentPersonRatio.CommissionRatio = this._PerformanceRatio.Value; return true; } else { return false; } } /// /// 验证是否已选择业绩人 /// /// public bool Verification() { if (this._ComboBoxTreeView.Tag != null && !String.IsNullOrWhiteSpace(this._ComboBoxTreeView.Tag.ToString())) { return true; } else { return false; } } /// /// 获取用户ID /// /// public string GetUserID() { if (this.Verification()) { return this._ComboBoxTreeView.Tag.ToString(); } else { return ""; } } private void _PerformanceAmount_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this._PerformanceAmount_ValueChanged(sender,null); } } private void _PerformanceRatio_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this._PerformanceRatio_ValueChanged(sender, null); } } private void _PerformanceAmount_ValueChanged(object sender, EventArgs e) { // if (this._PerformanceAmount.Focused) { this._PerformanceRatio.Value = this._PerformanceAmount.Value / this.currentCollectionAmount * 100.00m; } } private void _PerformanceRatio_ValueChanged(object sender, EventArgs e) { //if (this._PerformanceRatio.Focused) { this._PerformanceAmount.Value = this.currentCollectionAmount * this._PerformanceRatio.Value / 100.00m; } } LabelEx GetNewLabelEx(string text,Point point) { LabelEx label = new LabelEx(); label.AutoSize = true; label.Text = text; label.Location = point; label.Padding=new Padding(0,2,0,0); return label; } int index = 0; decimal currentCollectionAmount = 0.00m; LYFZ.Model.OrderPersonCommissionRatio currentPersonRatio = new Model.OrderPersonCommissionRatio(); Panel _PanelPerformancePerson = new Panel(); LYFZ.ComponentLibrary.ComboBoxTreeViewEx _ComboBoxTreeView = new ComponentLibrary.ComboBoxTreeViewEx(); LYFZ.ComponentLibrary.NumericUpDownEx _PerformanceRatio = new ComponentLibrary.NumericUpDownEx(); LYFZ.ComponentLibrary.NumericUpDownEx _PerformanceAmount = new ComponentLibrary.NumericUpDownEx(); /// /// Panel组容器 /// public Panel PanelPerformancePerson { get => _PanelPerformancePerson; set => _PanelPerformancePerson = value; } /// /// 业绩人 /// public ComboBoxTreeViewEx ComboBoxTreeView { get => _ComboBoxTreeView; set => _ComboBoxTreeView = value; } /// /// 业绩比例(%) /// public NumericUpDownEx PerformanceRatio { get => _PerformanceRatio; set => _PerformanceRatio = value; } /// /// 业绩金额(元) /// public NumericUpDownEx PerformanceAmount { get => _PerformanceAmount; set => _PerformanceAmount = value; } /// /// 当前等分配的金额 /// public decimal CurrentCollectionAmount { get => currentCollectionAmount; set => currentCollectionAmount = value; } /// /// 当前业绩分配信息 /// public Model.OrderPersonCommissionRatio CurrentPersonRatio { get => currentPersonRatio; set => currentPersonRatio = value; } /// /// 索引 /// public int Index { get => index; set => index = value; } } }