123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525 |
- 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<PerformancePerson> PersonList = this.GetPerformancePersonList();
- decimal AverageValue = 100.00m / (PersonList.Count==0?1 : PersonList.Count);
- this.UpdatePerformanceValue(AverageValue);
- }
- /// <summary>
- /// 更新业绩分配
- /// </summary>
- /// <param name="ratio"></param>
- void UpdatePerformanceValue(decimal ratio)
- {
- List<PerformancePerson> 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<PerformancePerson> PersonList = this.GetPerformancePersonList();
- if (this.GetOrderPersonCommissionRatio(PersonList))
- {
- this.DialogResult = DialogResult.OK;
- }
- }
- bool GetOrderPersonCommissionRatio(List<PerformancePerson> 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;
- }
-
- /// <summary>
- /// 验证用户是否选择重复
- /// </summary>
- /// <returns></returns>
- bool verificationUserID(List<PerformancePerson> PersonList)
- {
- bool bl = true;
- List<string> userIDList = new List<string>();
- 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<PerformancePerson> GetPerformancePersonList()
- {
- List<PerformancePerson> userIDList = new List<PerformancePerson>();
- 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();
- }
- /// <summary>
- /// 根据接单人ID 初始化业绩分配 多个接单人时 用“,”逗号分隔
- /// </summary>
- /// <param name="orderPersons"></param>
- 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);
- }
- }
- }
- }
- /// <summary>
- /// 根据已设置的业绩分配JsonData数据初始化业绩分配
- /// </summary>
- /// <param name="commissionRatioJsonData"></param>
- public void PersonCommissionRatioJsonDataInitialization(string commissionRatioJsonData)
- {
- if (!String.IsNullOrWhiteSpace(commissionRatioJsonData))
- {
- this.PersonCommissionRatio = new BLL.OrderPersonCommissionRatio(commissionRatioJsonData);
- }
- }
- /// <summary>
- /// 绑定业绩分配结果
- /// </summary>
- /// <param name="listBoxPerformance"></param>
- 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();
- /// <summary>
- /// 业绩人提成分配信息
- /// </summary>
- public OrderPersonCommissionRatio PersonCommissionRatio { get => personCommissionRatio; set => personCommissionRatio = value; }
- /// <summary>
- /// 收款金额
- /// </summary>
- public decimal CollectionAmount { get => _CollectionAmount; set => _CollectionAmount = value; }
- /// <summary>
- /// 是否为只读查看模式
- /// </summary>
- public bool IsReadOnly { get => isReadOnly; set => isReadOnly = value; }
- private void FrmCustomPerformance_Shown(object sender, EventArgs e)
- {
- if (this.plPerformancePersonList.Controls.Count <= 0)
- {
- this.BindPerformancePersonControls();
- }
- }
- /// <summary>
- /// 绑定业绩人控件
- /// </summary>
- 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;
- }
- }
- }
- /// <summary>
- /// 获取业绩人业绩分配比例值
- /// </summary>
- /// <returns></returns>
- public bool GetOrderPersonCommissionRatio()
- {
- if (this.Verification())
- {
- this.currentPersonRatio.UserID = this._ComboBoxTreeView.Tag.ToString();
- this.currentPersonRatio.CommissionRatio = this._PerformanceRatio.Value;
- return true;
- }
- else {
- return false;
- }
- }
- /// <summary>
- /// 验证是否已选择业绩人
- /// </summary>
- /// <returns></returns>
- public bool Verification()
- {
- if (this._ComboBoxTreeView.Tag != null && !String.IsNullOrWhiteSpace(this._ComboBoxTreeView.Tag.ToString()))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 获取用户ID
- /// </summary>
- /// <returns></returns>
- 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();
- /// <summary>
- /// Panel组容器
- /// </summary>
- public Panel PanelPerformancePerson { get => _PanelPerformancePerson; set => _PanelPerformancePerson = value; }
- /// <summary>
- /// 业绩人
- /// </summary>
- public ComboBoxTreeViewEx ComboBoxTreeView { get => _ComboBoxTreeView; set => _ComboBoxTreeView = value; }
- /// <summary>
- /// 业绩比例(%)
- /// </summary>
- public NumericUpDownEx PerformanceRatio { get => _PerformanceRatio; set => _PerformanceRatio = value; }
- /// <summary>
- /// 业绩金额(元)
- /// </summary>
- public NumericUpDownEx PerformanceAmount { get => _PerformanceAmount; set => _PerformanceAmount = value; }
- /// <summary>
- /// 当前等分配的金额
- /// </summary>
- public decimal CurrentCollectionAmount { get => currentCollectionAmount; set => currentCollectionAmount = value; }
- /// <summary>
- /// 当前业绩分配信息
- /// </summary>
- public Model.OrderPersonCommissionRatio CurrentPersonRatio { get => currentPersonRatio; set => currentPersonRatio = value; }
- /// <summary>
- /// 索引
- /// </summary>
- public int Index { get => index; set => index = value; }
- }
- }
|