三、checkedListBoxControl
一、checkedListBoxControl的使用全选
private void InitDate()
{
CheckedListBoxItem[] itemArr = {
new CheckedListBoxItem("全选",false),
new CheckedListBoxItem("星期一", false),
new CheckedListBoxItem("星期二", false),
new CheckedListBoxItem("星期三", false),
new CheckedListBoxItem("星期四", false),
new CheckedListBoxItem("星期五", true),
new CheckedListBoxItem("星期六", true),
new CheckedListBoxItem("星期日", false)
};
checkedListBoxControl1.Items.AddRange(itemArr);
checkedListBoxControl1.CheckOnClick = true;//控件点击一次就可以选中复选框
checkedListBoxControl1.ItemCheck += CheckedListBoxControl1_ItemCheck; } /// <summary>
/// 监听所有ItemCheck选中状态事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
{ //MessageBox.Show(checkedListBoxControl1.GetItemText(e.Index));
//throw new NotImplementedException();
if (checkedListBoxControl1.GetItemText(e.Index) == "全选")
{
if (checkedListBoxControl1.GetItemChecked(0))
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, true);
}
return;
}
else
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, false);
}
return;//return 解决了 CheckOnClick 检测单击或者双击延迟的问题
} }
else
{
MessageBox.Show("osa");
} }
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YKERP.BaseForms;
using YKERP.Business;
using YKERP.Common;
using YKERP.Tools; namespace YKERP.SCM._ReplenishmentMgt.PurchaseOrders
{
public partial class ReplenishmentCycleAddOrEdit : YKBaseForm
{
private string series = null;
//定义委托
public delegate void FuncRefresh();
//定义事件
public event FuncRefresh myRefresh; public ReplenishmentCycleAddOrEdit(Dictionary<string, string> Par)
{
InitializeComponent();
InitData();
if (Par != null)
{
this.series = Par["series"];
Select_Store.ReadOnly = true;
Select_Store.EditValue = Par["sub_unit_num_id"];
Select_Status.EditValue = Par["status_num_id"];
Text_Delivery.Text = Par["delivery_day"];
char[] chs = Par["replenish_weekly_day_flag"].ToCharArray();//分成一个一个的数字
List<string> scoreList = new List<string>();//创建了一个空列表
foreach (var stu in chs)
{
switch (stu)
{
case '1':
scoreList.Add("星期一");
break;
case '2':
scoreList.Add("星期二");
break;
case '3':
scoreList.Add("星期三");
break;
case '4':
scoreList.Add("星期四");
break;
case '5':
scoreList.Add("星期五");
break;
case '6':
scoreList.Add("星期六");
break;
case '7':
scoreList.Add("星期日");
break;
default:
break;
}
} System.String[] str = scoreList.ToArray(); for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{ foreach (string _statisticalTime in str)
{
if (checkedListBoxControl1.GetItemValue(i).ToString() == _statisticalTime)
{
checkedListBoxControl1.SetItemChecked(i, true);
}
} } //CheckedComboBoxEdit 类型的控件
/* if (str != null)
//修改默认选中
foreach (CheckedListBoxItem item in Text_SupplierReplenishment.Properties.Items)
{
foreach (string _statisticalTime in str)
{
if (item.Value.ToString() == _statisticalTime)
{
item.CheckState = CheckState.Checked;
} }
}*/
} } private void InitData()
{
Select_Store.BindData(CommonDicType.门店);
var status_type = new List<object>() {
new { id = "1", name = "未生效" },
new { id = "2", name = "生效" },
};
Select_Status.BindDataTable(YKTool.listToDataTable(status_type));
Select_Status.EditValue = 2; //选择第一项
//自定义数组
//string[] strs = new string[] { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };
//添加项
// Text_SupplierReplenishment.Properties.Items.AddRange(strs);
InitDate(); } private void InitDate()
{
CheckedListBoxItem[] itemArr = {
new CheckedListBoxItem("全选",false),
new CheckedListBoxItem("星期一", false),
new CheckedListBoxItem("星期二", false),
new CheckedListBoxItem("星期三", false),
new CheckedListBoxItem("星期四", false),
new CheckedListBoxItem("星期五", true),
new CheckedListBoxItem("星期六", true),
new CheckedListBoxItem("星期日", false)
};
checkedListBoxControl1.Items.AddRange(itemArr);
checkedListBoxControl1.CheckOnClick = true;//控件点击一次就可以选中复选框
checkedListBoxControl1.ItemCheck += CheckedListBoxControl1_ItemCheck;
checkedListBoxControl1.SelectedValueChanged += CheckedListBoxControl1_SelectedValueChanged; ; } private void CheckedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
{
//MessageBox.Show(checkedListBoxControl1.GetItemText(e.Index));
//throw new NotImplementedException();
if (checkedListBoxControl1.GetItemText(e.Index) == "全选")
{
if (checkedListBoxControl1.GetItemChecked(0))
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
if (checkedListBoxControl1.SelectedIndex != i)
checkedListBoxControl1.SetItemChecked(i, true);
}
return;
}
else
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
if (checkedListBoxControl1.SelectedIndex != i)
checkedListBoxControl1.SetItemChecked(i, false);
}
return;//return 解决了 CheckOnClick 检测单击或者双击延迟的问题
} }
} private void CheckedListBoxControl1_SelectedValueChanged(object sender, EventArgs e)
{
List<object> objList = checkedListBoxControl1.Items.GetCheckedValues();
//解决失灵的
if (checkedListBoxControl1.GetItemChecked(checkedListBoxControl1.SelectedIndex))
{
checkedListBoxControl1.SetItemCheckState(checkedListBoxControl1.SelectedIndex, CheckState.Checked);
}
else
checkedListBoxControl1.SetItemCheckState(checkedListBoxControl1.SelectedIndex, CheckState.Unchecked); if (objList.Count() == (checkedListBoxControl1.Items.Count - 2))
{
checkedListBoxControl1.SetItemCheckState(0, CheckState.Checked);
//checkedListBoxControl1.SetItemCheckState(checkedListBoxControl1.SelectedIndex, CheckState.Unchecked);
}
if (objList.Count() == 2)
{
checkedListBoxControl1.SetItemCheckState(0, CheckState.Unchecked);
//checkedListBoxControl1.SetItemCheckState(checkedListBoxControl1.SelectedIndex, CheckState.Unchecked);
} } private void btn_AddOrEdit_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(Select_Store.Text))
{
MessageHelper.InfoMsg("请选择门店");
return;
} //MessageBox.Show(Text_SupplierReplenishment.EditValue.ToString());
Dictionary<string, string> data = new Dictionary<string, string>();
var _Store = Select_Store.EditValue?.ToString()?.ToInt() ?? 0;
if (_Store > 0) //门店
data.Add("sub_unit_num_id", _Store.ToString());
data.Add("delivery_day", Text_Delivery.Text);
var _Status = Select_Status.EditValue?.ToString()?.ToInt() ?? 0;
if (_Status > 0) //状态
data.Add("status_num_id", _Status.ToString());
else
{
MessageHelper.InfoMsg("状态不能为空");
return;
}
if (this.series != null)
data.Add("series", this.series); // //List<object> List = Text_SupplierReplenishment.Properties.Items.GetCheckedValues();
List<Object> list = new List<object> { };
string a = null;
for (int i = 0; i < checkedListBoxControl1.Items.Count; i++)
{
if (checkedListBoxControl1.GetItemChecked(i))
{
a = checkedListBoxControl1.GetItemValue(i).ToString();
list.Add(a);
}
} char[] charnumbers = new char[7] { '0', '0', '0', '0', '0', '0', '0' };//定长
foreach (var stu in list)
{
switch (stu)
{
case "星期一":
charnumbers[0] = '1';
break;
case "星期二":
charnumbers[1] = '2';
break;
case "星期三":
charnumbers[2] = '3';
break;
case "星期四":
charnumbers[3] = '4';
break;
case "星期五":
charnumbers[4] = '5';
break;
case "星期六":
charnumbers[5] = '6';
break;
case "星期日":
charnumbers[6] = '7';
break;
default:
break; }
} //MessageBox.Show(res + "--" + res.Count());
data.Add("replenish_weekly_day_flag", string.Join("", charnumbers));
string result = UnitOfWork<DAL>.Resolve.ReplenishmentCycleAddOrEdit(data, out string errors);
if (errors != null)
{
MessageHelper.InfoMsg(errors);
return;
}
if (result != "" || result != null)
{
if (this.series != null)
MessageHelper.InfoMsg("编辑成功");
else
MessageHelper.InfoMsg("添加成功");
this.Close();
myRefresh();
}
else
{
MessageHelper.InfoMsg(errors.ToString());
}
}
}
}
原本的
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YKERP.BaseForms;
using YKERP.Business;
using YKERP.Common;
using YKERP.Tools; namespace YKERP.SCM._ReplenishmentMgt.PurchaseOrders
{
public partial class ReplenishmentCycleAddOrEdit : YKBaseForm
{
private string series = null;
//定义委托
public delegate void FuncRefresh();
//定义事件
public event FuncRefresh myRefresh; public ReplenishmentCycleAddOrEdit(Dictionary<string, string> Par)
{
InitializeComponent();
InitData();
if (Par != null)
{
this.series = Par["series"];
Select_Store.ReadOnly = true;
Select_Store.EditValue = Par["sub_unit_num_id"];
Select_Status.EditValue = Par["status_num_id"];
Text_Delivery.Text = Par["delivery_day"];
char[] chs = Par["replenish_weekly_day_flag"].ToCharArray();//分成一个一个的数字
List<string> scoreList = new List<string>();//创建了一个空列表
foreach (var stu in chs)
{
switch (stu)
{
case '1':
scoreList.Add("星期一");
break;
case '2':
scoreList.Add("星期二");
break;
case '3':
scoreList.Add("星期三");
break;
case '4':
scoreList.Add("星期四");
break;
case '5':
scoreList.Add("星期五");
break;
case '6':
scoreList.Add("星期六");
break;
case '7':
scoreList.Add("星期日");
break;
default:
break;
}
} System.String[] str = scoreList.ToArray(); for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{ foreach (string _statisticalTime in str)
{
if (checkedListBoxControl1.GetItemValue(i).ToString() == _statisticalTime)
{
checkedListBoxControl1.SetItemChecked(i, true);
}
} } //CheckedComboBoxEdit 类型的控件
/* if (str != null)
//修改默认选中
foreach (CheckedListBoxItem item in Text_SupplierReplenishment.Properties.Items)
{
foreach (string _statisticalTime in str)
{
if (item.Value.ToString() == _statisticalTime)
{
item.CheckState = CheckState.Checked;
} }
}*/
} } private void InitData()
{
Select_Store.BindData(CommonDicType.门店);
var status_type = new List<object>() {
new { id = "1", name = "未生效" },
new { id = "2", name = "生效" },
};
Select_Status.BindDataTable(YKTool.listToDataTable(status_type));
Select_Status.EditValue = 2; //选择第一项
//自定义数组
//string[] strs = new string[] { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };
//添加项
// Text_SupplierReplenishment.Properties.Items.AddRange(strs);
InitDate(); } private void InitDate()
{
CheckedListBoxItem[] itemArr = {
new CheckedListBoxItem("全选",false),
new CheckedListBoxItem("星期一", false),
new CheckedListBoxItem("星期二", false),
new CheckedListBoxItem("星期三", false),
new CheckedListBoxItem("星期四", false),
new CheckedListBoxItem("星期五", true),
new CheckedListBoxItem("星期六", true),
new CheckedListBoxItem("星期日", false)
};
checkedListBoxControl1.Items.AddRange(itemArr);
checkedListBoxControl1.CheckOnClick = true;//控件点击一次就可以选中复选框
checkedListBoxControl1.ItemChecking += CheckedListBoxControl1_ItemChecking; ; } private void CheckedListBoxControl1_ItemChecking(object sender, ItemCheckingEventArgs e)
{
//MessageBox.Show(checkedListBoxControl1.GetItemText(e.Index));
//throw new NotImplementedException();
if (checkedListBoxControl1.GetItemText(e.Index) == "全选")
{
if (checkedListBoxControl1.GetItemChecked(0))
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, false);
}
return;
}
else
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, true);
}
return;//return 解决了 CheckOnClick 检测单击或者双击延迟的问题
} } if (checkedListBoxControl1.GetItemText(e.Index) != "全选")
{ if (checkedListBoxControl1.SelectedItems.Count() == checkedListBoxControl1.Items.Count)
{
checkedListBoxControl1.SetItemChecked(0, true);
} } } /// <summary>
/// 监听所有ItemCheck选中状态事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
{ //MessageBox.Show(checkedListBoxControl1.GetItemText(e.Index));
//throw new NotImplementedException();
if (checkedListBoxControl1.GetItemText(e.Index) == "全选")
{
if (checkedListBoxControl1.GetItemChecked(0))
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, true);
}
return;
}
else
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, false);
}
return;//return 解决了 CheckOnClick 检测单击或者双击延迟的问题
} }
else
{
MessageBox.Show("osa");
} } private void btn_AddOrEdit_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(Select_Store.Text))
{
MessageHelper.InfoMsg("请选择门店");
return;
} //MessageBox.Show(Text_SupplierReplenishment.EditValue.ToString());
Dictionary<string, string> data = new Dictionary<string, string>();
var _Store = Select_Store.EditValue?.ToString()?.ToInt() ?? 0;
if (_Store > 0) //门店
data.Add("sub_unit_num_id", _Store.ToString());
data.Add("delivery_day", Text_Delivery.Text);
var _Status = Select_Status.EditValue?.ToString()?.ToInt() ?? 0;
if (_Status > 0) //状态
data.Add("status_num_id", _Status.ToString());
else
{
MessageHelper.InfoMsg("状态不能为空");
return;
}
if (this.series != null)
data.Add("series", this.series); // //List<object> List = Text_SupplierReplenishment.Properties.Items.GetCheckedValues();
List<Object> list = new List<object> { };
string a=null;
for (int i = 0; i < checkedListBoxControl1.Items.Count; i++)
{
if (checkedListBoxControl1.GetItemChecked(i))
{
a = checkedListBoxControl1.GetItemValue(i).ToString();
list.Add(a);
}
} char[] charnumbers = new char[7] { '0', '0', '0', '0', '0', '0', '0' };//定长
foreach (var stu in list)
{
switch (stu)
{
case "星期一":
charnumbers[0] = '1';
break;
case "星期二":
charnumbers[1] = '2';
break;
case "星期三":
charnumbers[2] = '3';
break;
case "星期四":
charnumbers[3] = '4';
break;
case "星期五":
charnumbers[4] = '5';
break;
case "星期六":
charnumbers[5] = '6';
break;
case "星期日":
charnumbers[6] = '7';
break;
default:
break; }
} //MessageBox.Show(res + "--" + res.Count());
data.Add("replenish_weekly_day_flag", string.Join("", charnumbers));
string result = UnitOfWork<DAL>.Resolve.ReplenishmentCycleAddOrEdit(data, out string errors);
if (errors!=null)
{
MessageHelper.InfoMsg(errors);
return;
}
if (result != "" || result != null)
{
if (this.series != null)
MessageHelper.InfoMsg("编辑成功");
else
MessageHelper.InfoMsg("添加成功");
this.Close();
myRefresh();
}
else
{
MessageHelper.InfoMsg(errors.ToString());
}
}
}
}
三、checkedListBoxControl的更多相关文章
- 常用 Gulp 插件汇总 —— 基于 Gulp 的前端集成解决方案(三)
前两篇文章讨论了 Gulp 的安装部署及基本概念,借助于 Gulp 强大的 插件生态 可以完成很多常见的和不常见的任务.本文主要汇总常用的 Gulp 插件及其基本使用,需要读者对 Gulp 有一个基本 ...
- 【原】FMDB源码阅读(三)
[原]FMDB源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 FMDB比较优秀的地方就在于对多线程的处理.所以这一篇主要是研究FMDB的多线程处理的实现.而 ...
- Jquery的点击事件,三句代码完成全选事件
先来看一下Js和Jquery的点击事件 举两个简单的例子 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...
- node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理
一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...
- 简谈百度坐标反转至WGS84的三种思路
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 基于百度地图进行数据展示是目前项目中常见场景,但是因为百度地图 ...
- 一起学 Java(三) 集合框架、数据结构、泛型
一.Java 集合框架 集合框架是一个用来代表和操纵集合的统一架构.所有的集合框架都包含如下内容: 接口:是代表集合的抽象数据类型.接口允许集合独立操纵其代表的细节.在面向对象的语言,接口通常形成一个 ...
- 谈谈一些有趣的CSS题目(三)-- 层叠顺序与堆栈上下文知多少
开本系列,讨论一些有趣的 CSS 题目,抛开实用性而言,一些题目为了拓宽一下解决问题的思路,此外,涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题中有你感觉 ...
- 如何一步一步用DDD设计一个电商网站(三)—— 初涉核心域
一.前言 结合我们本次系列的第一篇博文中提到的上下文映射图(传送门:如何一步一步用DDD设计一个电商网站(一)—— 先理解核心概念),得知我们这个电商网站的核心域就是销售子域.因为电子商务是以信息网络 ...
- 测试一下StringBuffer和StringBuilder及字面常量拼接三种字符串的效率
之前一篇里写过字符串常用类的三种方式<java中的字符串相关知识整理>,只不过这个只是分析并不知道他们之间会有多大的区别,或者所谓的StringBuffer能提升多少拼接效率呢?为此写个简 ...
随机推荐
- 四、Oracle 序列、常用函数、多表连接
一.序列定义:是oracle数据库专门用来产生连续且自动增长的数字的对象创建语法:create sequence 序列名(sq_表名) nocache(无缓存) create sequence sq_ ...
- pytorch visdom可视化工具学习—1—详细使用-3-Generic Plots和Others
4)Generic Plots 注意,服务器API遵循数据和布局对象的规则,这样您就可以生成自己的任意Plotly可视化: # Arbitrary visdom content trace = dic ...
- 盘点 Oracle 11g 中新特性带来的10大性能影响
Oracle的任何一个新版本,总是会带来大量引人瞩目的新特性,但是往往在这些新特性引入之初,首先引起的是一些麻烦,因为对于新技术的不了解.因为对于旧环境的不适应,从Oracle产品到技术服务运维,总是 ...
- Python分析微信好友性别比例和省份城市分布比例
如需转发请注明:小婷儿的博客:https://www.cnblogs.com/xxtalhr/p/10642241.html 一.安装模块 pip install itchat pip install ...
- Java常见的几种内存溢出及解决方案
1.JVM Heap(堆)溢出:java.lang.OutOfMemoryError: Java heap space JVM在启动的时候会自动设置JVM Heap的值, 可以利用JVM提供的-Xmn ...
- Wireshark抓包分析TCP 3次握手、4次挥手过程
Wireshark简介 更多有关Wireshark的教程.软件下载等,请见:http://www.52im.net/thread-259-1-1.html,本文只作简要介绍. 1Wireshark 是 ...
- mysql中添加索引
创建普通索引 alter table xxxxxx add index index_name(xxxxxxx) 表名↑ 列 ...
- 深入浅出:5G和HTTP
本文将会讲到5G和HTTP.曾经在深入浅出经典面试题:从浏览器中输入URL到页面加载发生了什么 - Part 3 提到为什么有些RPC框架不选用HTTP,而5G会采用HTTP. 您可以从本文里获取到一 ...
- 朱晔和你聊Spring系列S1E4:灵活但不算好用的Spring MVC
阅读PDF版本 本文会以一些例子来展现Spring MVC的常见功能和一些扩展点,然后我们来讨论一下Spring MVC好用不好用. 使用SpringBoot快速开始 基于之前的parent模块,我们 ...
- CSS 伪类 (Pseudo-classes)实例
CSS 伪类 (Pseudo-classes)实例CSS 伪类用于向某些选择器添加特殊的效果在支持 CSS 的浏览器中,链接的不同状态都可以不同的方式显示,这些状态包括:活动状态,已被访问状态,未被访 ...