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);
                }
            });
        }

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM