三、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能提升多少拼接效率呢?为此写个简 ...
随机推荐
- pytorch例子学习——TRANSFER LEARNING TUTORIAL
参考:https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html 以下是两种主要的迁移学习场景 微调convnet : ...
- sqlmap的简单使用
SQLmap基于Python编写,只要安装了Python的操作系统就可以使用它. 一.SQLMap判断是否存在注入 1. sqlmap -u "http://XXXXXXX?id=1&quo ...
- Java8之lambda表达式
一.什么是lambda表达式? Lambda 是一个匿名函数,我们可以把 Lambda 表达式理解为是一段可以传递的代码(将代码像数据一样进行传递).可以写出更简洁.更灵活的代码.作为一种更紧凑的代码 ...
- Vue2.x源码学习笔记-Vue实例的属性和方法整理
还是先从浏览器直观的感受下实例属性和方法. 实例属性: 对应解释如下: vm._uid // 自增的id vm._isVue // 标示是vue对象,避免被observe vm._renderProx ...
- 探讨.NET Core数据进行3DES加密和解密问题
前言 一直困扰着我关于数据加密这一块,24号晚上用了接近3个小时去完成一项任务,本以为立马能解决,但是为了保证数据的安全性,我们开始去对数据进行加密,然后接下来3个小时专门去研究加密这一块,然而用着用 ...
- SpringBoot分布式 - Dubbo+ZooKeeper
一:介绍 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务.它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护.域名服务.分布式同步.组服务等. Dubbo是Alib ...
- Sequelize 连接微软云数据库 SQL Azure
function getConnection(){ var sequelize=new Sequelize("DBName","sa","000000 ...
- 一起学习造轮子(二):从零开始写一个Redux
本文是一起学习造轮子系列的第二篇,本篇我们将从零开始写一个小巧完整的Redux,本系列文章将会选取一些前端比较经典的轮子进行源码分析,并且从零开始逐步实现,本系列将会学习Promises/A+,Red ...
- Flask序列化
我们在做后台接口的时候,对于返回值,用的最多的就是json数据格式 flask中,返回json数据格式,我们可以用到flask的jsonify函数. 对于基础序列是可以直接序列化的,但是更多的情况下, ...
- POJ - 2528 区间离散化,线段树区间修改,区间询问
这个题非常有意思的地方是,我们发现区间[1,4]和[5,8]是紧挨着的,因为这个的数代表的是一段区间,原本我们对于普通的离散, a[1]=1,a[2]=5,a[3]=6,a[4]=8;数组下标就是重新 ...