C#选择弹框控件使用(可多选)

 

点击事件触发此方法

private void selectCurryCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)

{

判断所选是否为空
if (this.SelectBeneficiary == null)
return;

//获取待选择项

通过字典获取数据方法获取对应数据
var dictList = VineERP.Utils.CommonDictHelper.GetCommonDictList("Currency");

判断是否存在数据
if (dictList == null || dictList.Count == 0)
return;

构造弹框

frmSelectedDialog<sys_common_dict> dialog = new frmSelectedDialog<sys_common_dict>("Code,CodeName", "代码,币种", "50,80");
dialog.AllowMultiSelect = true; //设置多选

获取控件所分配的窗体
dialog.Parent = this.ParentForm;
//根据当前内容,设置已选项
if (!string.IsNullOrEmpty(this.SelectBeneficiary.CurrencyCode))
{

将已选择项进行拆分
var codeArr = this.SelectBeneficiary.CurrencyCode.Split(',').ToList();
dialog.SelectedEntities = new List<sys_common_dict>();

默认勾选已选
foreach (var code in codeArr)
{
var dict = dictList.Find(p => p.Code == code);
if (dict != null)
dialog.SelectedEntities.Add(dict);
}
}
//传递待选择项,并返回选择项并处理
dialog.ShowDialog(dictList, p =>
{
if (p.SelectedEntities == null || p.SelectedEntities.Count == 0)
return;

this.SelectBeneficiary.CurrencyCode = string.Empty;

显示所有数据

foreach (var dict in p.SelectedEntities)
{
this.SelectBeneficiary.CurrencyCode += string.Format("{0}{1}",
string.IsNullOrEmpty(this.SelectBeneficiary.CurrencyCode) ? "" : ",", dict.Code);
}

});
}

 1    private void textBeneficiary_ItemChanged(object sender, EdwFramework.Controls.ChangedEventArgs e)
 2         {
 3             this.SelectBeneficiary.ChecklistInformation();
 4         }
 5 
 6         /// <summary>
 7         /// 弹出币种选择框
 8         /// </summary>
 9         /// <param name="sender"></param>
10         /// <param name="e"></param>
11         private void selectCurryCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
12         {
13             if (this.SelectBeneficiary == null)
14                 return;
15 
16             //获取待选择项
17             var dictList = VineERP.Utils.CommonDictHelper.GetCommonDictList("Currency");
18             if (dictList == null || dictList.Count == 0)
19                 return;
20 
21             frmSelectedDialog<sys_common_dict> dialog = new frmSelectedDialog<sys_common_dict>("Code,CodeName", "代码,币种", "50,80");
22             dialog.AllowMultiSelect = true; //设置多选
23             dialog.Parent = this.ParentForm;
24             //根据当前内容,设置已选项
25             if (!string.IsNullOrEmpty(this.SelectBeneficiary.CurrencyCode))
26             {
27                 var codeArr = this.SelectBeneficiary.CurrencyCode.Split(',').ToList();
28                 dialog.SelectedEntities = new List<sys_common_dict>();
29                 foreach (var code in codeArr)
30                 {
31                     var dict = dictList.Find(p => p.Code == code);
32                     if (dict != null)
33                         dialog.SelectedEntities.Add(dict);
34                 }
35             }
36             //传递待选择项,并返回选择项并处理
37             dialog.ShowDialog(dictList, p =>
38             {
39                 if (p.SelectedEntities == null || p.SelectedEntities.Count == 0)
40                     return;
41 
42                 this.SelectBeneficiary.CurrencyCode = string.Empty;
43                 foreach (var dict in p.SelectedEntities)
44                 {
45                     this.SelectBeneficiary.CurrencyCode += string.Format("{0}{1}",
46                         string.IsNullOrEmpty(this.SelectBeneficiary.CurrencyCode) ? "" : ",", dict.Code);
47                 }
48 
49             });
50         }

 弹框例子

 private void sel_CustomCodeList_Click(object sender, EventArgs e)
        {
            if (this.CurrCostParam == null || this.ViewState == ModelViewState.Normal)
                return;
            var RateService = EngineContext.Current.Resolve<IRepository<Customer>>();
            string companyid = User.CompanyId;
            var tempList = RateService.Search(p=>p.Companyid == companyid,false);
            frmSelectedDialog<Customer> dialog = new frmSelectedDialog<Customer>("CustomCode,ShortName", "代码,名称", "100,120");
            dialog.AllowMultiSelect = true;
            dialog.Parent = this.ParentForm;

            //根据当前内容,设置已选项
            if(!string.IsNullOrEmpty(this.CurrCostParam.CustomCodeList))
            {
                var codeArr = this.CurrCostParam.CustomCodeList.Split(',').ToList();
                dialog.SelectedEntities = new List<Customer>();
                foreach(var code in codeArr)
                {
                    var dict = tempList.Find(p => p.CustomCode == code);
                    if (dict != null)
                        dialog.SelectedEntities.Add(dict);
                }
            }

            //传递带选项,并返回选择项并处理
            dialog.ShowDialog(tempList,p=>
            {
                this.sel_CustomCodeList.Items.Clear();
                this.CurrCostParam.CustomCodeList =string.Empty;

                if (p.SelectedEntities == null || p.SelectedEntities.Count == 0)
                    return;

                foreach(var dict in p.SelectedEntities)
                {
                    this.sel_CustomCodeList.Items.Add(dict.CustomCode);
                    this.CurrCostParam.CustomCodeList +=string.Format("{0}{1}",
                      string.IsNullOrEmpty(this.CurrCostParam.CustomCodeList) ? "" : ",", dict.CustomCode);
                }
            });
        }

  排除已选过的客户

 private List<Customer> custList = new List<Customer>();
        /// <summary>
        /// 客户代码选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sel_CustomCodeList_Click(object sender, EventArgs e)
        {
            if (this.CurrCostParam == null || this.ViewState == ModelViewState.Normal)
                return;
            custList = VineERP.Utils.CustomerHelper.GetAllCustom(this.CurrCostParam.Companyid);

            if (custList == null || custList.Count == 0)
            {
                MessageDxUtil.ShowError("客户信息不存在");
                return;
            }
            #region 排除已设置客户
            string sql = string.Format(@"select fdw.List(a.CustomCodeList)
                        from tblCostParam a 
                        where a.CustomCodeList !='{0}' and a.Companyid='{1}'",
                        this.CurrCostParam.CustomCodeList, this.CurrCostParam.Companyid);

            var useCusotm = EdwFramework.Core.SqlClientFactory.Instance.ExecuteScalar(sql);
            if (!string.IsNullOrEmpty(useCusotm))
            {
                var useCustlist = useCusotm.Split(',').ToList();
                foreach (var cust in useCustlist)
                {
                    if (string.IsNullOrEmpty(cust))
                        continue;

                    custList.RemoveAll(p => p.CustomCode == cust);
                }
            }

            if (custList == null || custList.Count == 0)
            {
                MessageDxUtil.ShowError("所有客户都已完成成本参数设定");
                return;
            }
            #endregion

            frmSelectedDialog<Customer> dialog = new frmSelectedDialog<Customer>("CustomCode,ShortName", "代码,名称", "100,120");
            dialog.AllowMultiSelect = true;
            dialog.Parent = this.ParentForm;

            //根据当前内容,设置已选项
            if(!string.IsNullOrEmpty(this.CurrCostParam.CustomCodeList))
            {
                var codeArr = this.CurrCostParam.CustomCodeList.Split(',').ToList();
                dialog.SelectedEntities = new List<Customer>();
                foreach(var code in codeArr)
                {
                    var dict = custList.Find(p => p.CustomCode == code);
                    if (dict != null)
                        dialog.SelectedEntities.Add(dict);
                }
            }

            //传递带选项,并返回选择项并处理
            dialog.ShowDialog(custList, p =>
            {
                this.sel_CustomCodeList.Items.Clear();
                this.CurrCostParam.CustomCodeList =string.Empty;

                if (p.SelectedEntities == null || p.SelectedEntities.Count == 0)
                    return;

                foreach(var dict in p.SelectedEntities)
                {
                    this.sel_CustomCodeList.Items.Add(dict.CustomCode);
                    this.CurrCostParam.CustomCodeList +=string.Format("{0}{1}",
                      string.IsNullOrEmpty(this.CurrCostParam.CustomCodeList) ? "" : ",", dict.CustomCode);
                }
            });
        }

  

 

转载于:https://www.cnblogs.com/BottleKing/p/9134122.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C是一种编程语言,它由美国贝尔实验室的Dennis Ritchie 在20世纪70年代开发。C语言是一种通用的、面向过程的编程语言,被广泛应用于系统软件、嵌入式系统以及游戏开发等领域。 C语言具有简洁、高效、可移植和灵活的特点,这些特点使得它成为了许多编程语言的基础,如C++、Java和Python等。C语言的语法和结构较为简单,学习起来相对容易,但它也比较底层,需要程序员手动管理内存。 C语言提供了丰富的库函数和运算符,可以进行各种数据操作和算术运算。它支持变量、循环、条件判断和函数等基本的编程概念,同时也支持指针,允许直接访问和操作内存地址。C语言的灵活性使得程序员可以更加高效地利用计算机的资源,但也需要程序员注意内存泄漏等问题。 C语言在计算机领域有着广泛的应用,例如,操作系统的内核、驱动程序、网络通信协议、数据库管理系统等核心软件都是使用C语言编写的。此外,许多嵌入式系统,如手机、智能家居设备和汽车控制系统等,也广泛使用C语言。 总的来说,C语言是一种强大且灵活的编程语言,它在计算机科学领域有着广泛的应用。学习C语言对于想要从事软件开发或嵌入式系统开发的人来说是很重要的,它可以帮助程序员更好地理解计算机底层原理,并且能够编写出高效、可靠的系统软件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值