Beispiel #1
0
 public SalesRebateRecentParameterModifyViewModel()
 {
     _salesRebateAmountRangeService = new SalesRebateAmountRangeService();
     InitCommand();
     InitData();
 }
Beispiel #2
0
        private void InitCommand()
        {
            QueryBaseCommand = new DelegateCommand((obj) =>
            {
                AmountRangeString = "";
                SalesRebateRecentParameterLists.Clear();
                SalesRebateService.GetSalesRebateOrgRecentParameterLists(CommonService.GetSqlWhereString(QueryParameter)).ForEach(x => SalesRebateRecentParameterLists.Add(x));
            });

            QueryCommand = new DelegateCommand((obj) =>
            {
                SalesRebateK3RecordParameterLists.Clear();
                SalesRebateService.GetSalesRebateK3RecordParameterLists(CommonService.GetSqlWhereString(QueryParameter1)).ForEach(x => SalesRebateK3RecordParameterLists.Add(x));
            });

            DoubleClickModifyCommand = new DelegateCommand((obj) =>
            {
                if (SalesRebateRecentParameterSelectedItem != null)
                {
                    IsChanged     = true;
                    var cloneData = ObjectDeepCopyHelper <SalesRebateRecentParameterMainModel, SalesRebateRecentParameterMainModel> .Trans(SalesRebateRecentParameterSelectedItem);
                    SalesRebateRecentParameterModifyView view = new SalesRebateRecentParameterModifyView();
                    (view.DataContext as SalesRebateRecentParameterModifyViewModel).WithParam(cloneData, (type, outputEntity) =>
                    {
                        view.Close();
                        if (type == 1)
                        {
                            SalesRebateService.RecentParameterUpdate(outputEntity);
                            QueryBaseCommand.Execute(null);
                        }
                    });
                    view.ShowDialog();
                }
            });

            RecentParameterClearCommand = new DelegateCommand((obj) =>
            {
                var selectedItems = (obj as DataGrid).SelectedItems;
                if (selectedItems.Count > 0)
                {
                    IsChanged = true;
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (SalesRebateRecentParameterMainModel item in selectedItems)
                    {
                        stringBuilder.Append($",'{item.Guid}'");
                    }
                    string guids = stringBuilder.ToString().Substring(1);
                    SalesRebateService.ClearRecentMainParameter(guids);
                    QueryBaseCommand.Execute(null);
                }
                else
                {
                    MessageBox.Show("必须先选择一行或多行");
                }
            });

            RecentParameterCopyCommand = new DelegateCommand((obj) =>
            {
                var selectedItems = (obj as DataGrid).SelectedItems;
                if (selectedItems.Count == 2)
                {
                    IsChanged = true;
                    var first = selectedItems[0] as SalesRebateRecentParameterMainModel;
                    var last  = selectedItems[1] as SalesRebateRecentParameterMainModel;
                    if ((last.IsPassed && !first.IsPassed))
                    {
                        SalesRebateService.SalesRebateParameterCopy(first.Id, last.Id, first.Guid, last.Guid, 1);
                        QueryBaseCommand.Execute(null);
                    }
                    else if (!last.IsPassed && first.IsPassed)
                    {
                        SalesRebateService.SalesRebateParameterCopy(last.Id, first.Id, last.Guid, first.Guid, 1);
                        QueryBaseCommand.Execute(null);
                    }
                    else if (last.IsPassed && first.IsPassed)
                    {
                        MessageBox.Show("所选行的参数都已通过验证,请先选择一行【清空参数】");
                    }
                    else
                    {
                        MessageBox.Show("必须有一行参数是已通过验证,用来覆盖先选的");
                    }
                }
                else
                {
                    MessageBox.Show("每次只能选择2行,【后选的行】参数 覆盖 【先选的行】");
                }
            });

            K3RecordParameterCopyCommand = new DelegateCommand((obj) =>
            {
                var selectedItems = (obj as DataGrid).SelectedItems;
                if (selectedItems.Count == 1)
                {
                    if (!SalesRebateRecentParameterSelectedItem.IsPassed)
                    {
                        if (SalesRebateK3RecordParameterSelectedItem != null)
                        {
                            IsChanged = true;
                            SalesRebateService.SalesRebateParameterCopy(SalesRebateRecentParameterSelectedItem.Id, SalesRebateK3RecordParameterSelectedItem.Id, SalesRebateRecentParameterSelectedItem.Guid, SalesRebateK3RecordParameterSelectedItem.Guid, 2);
                            QueryBaseCommand.Execute(null);
                        }
                        else
                        {
                            MessageBox.Show("需要选择一行历史参数,【历史待选的行】参数 覆盖 【当前参数】");
                        }
                    }
                    else
                    {
                        MessageBox.Show("已通过验证的行参数不能被覆盖,请先【清空参数】");
                    }
                }
                else
                {
                    MessageBox.Show("只能选择一行被复制的行,【历史待选的行】参数 覆盖 【当前参数】");
                }
            });

            SelectionChangedCommand = new DelegateCommand((obj) =>
            {
                if (obj != null)
                {
                    var model = obj as SalesRebateRecentParameterMainModel;
                    if (model.RebatePctType == 2)
                    {
                        var lists            = SalesRebateAmountRangeService.GetSalesRebateAmountRangeRecentParameterLists(model.PGuid);
                        StringBuilder result = new StringBuilder();
                        foreach (var item in lists)
                        {
                            result.Append($"金额区间:{item.AmountLower}-{item.AmountUpper} 万元   比例:{item.SalesRebatePctValue}% \t\t");
                        }

                        AmountRangeString = result.ToString();
                    }
                    else
                    {
                        AmountRangeString = string.Empty;
                    }
                }
            });
        }