@ -1,4 +1,5 @@
using AForge.Video.DirectShow ;
using DevExpress.XtraEditors.Controls ;
using PEIS.Base ;
using PEIS.Entity ;
using PEIS.Event ;
@ -26,6 +27,7 @@ namespace PEIS.View.Enrollment
private readonly EnrollmentPatient _ regInfo = null ;
private BasePatient _ baseInfo = null ;
private FilterInfoCollection videoDevices ;
private List < string > _ hazardFactors ;
public NewEnrollmentPersonForm ( EnrollmentPatient item , bool editStatus )
{
@ -84,6 +86,77 @@ namespace PEIS.View.Enrollment
// BirthdayDateTimePicker.Enabled = true;
// CardTypeComboBox.Enabled = true;
//}
HazardFactorsEdit . Properties . BeforePopup + = Properties_BeforePopup ;
HazardFactorsFilter . TextChanged + = HazardFactorsFilter_TextChanged ;
HazardFactorsCheckedListBoxControl . ItemCheck + = HazardFactorsCheckedListBoxControl_ItemCheck ;
}
private void HazardFactorsCheckedListBoxControl_ItemCheck ( object sender , DevExpress . XtraEditors . Controls . ItemCheckEventArgs e )
{
// 实时更新文本
var selectedItems = new List < string > ( ) ;
foreach ( CheckedListBoxItem checkedItem in HazardFactorsCheckedListBoxControl . CheckedItems )
{
selectedItems . Add ( checkedItem . Value . ToString ( ) ) ;
}
// 处理当前正在变更的项
//var changingItem = HazardFactorsCheckedListBoxControl.Items[e.Index].Value.ToString();
//if (e.State == CheckState.Checked)
// selectedItems.Add(changingItem);
//else
// selectedItems.Remove(changingItem);
HazardFactorsEdit . Text = string . Join ( "; " , selectedItems ) ;
}
private void Properties_BeforePopup ( object sender , EventArgs e )
{
// 1. 清空搜索框,准备新的筛选
HazardFactorsFilter . Text = string . Empty ;
// 2. 获取当前PopupContainerEdit中已保存的选中项
// 我们约定使用分号分隔的字符串来存储,例如 "Apple;Orange;Mango"
string currentSelectedText = HazardFactorsEdit . Text ;
List < string > currentlySelectedItems = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( currentSelectedText ) )
{
// 分割字符串,移除可能存在的空字符串
currentlySelectedItems = currentSelectedText . Split ( new [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries )
. Select ( s = > s . Trim ( ) )
. ToList ( ) ;
}
// 3. 加载所有数据,并回显当前已选中的项
ShowHazardFactorsData ( _ hazardFactors , currentlySelectedItems ) ;
}
private void HazardFactorsFilter_TextChanged ( object sender , EventArgs e )
{
string filterText = HazardFactorsFilter . Text . Trim ( ) ;
// 获取当前所有已选中的项,以便在筛选后保持它们的选中状态
var currentlyCheckedItems = new List < string > ( ) ;
foreach ( CheckedListBoxItem item in HazardFactorsCheckedListBoxControl . CheckedItems )
{
currentlyCheckedItems . Add ( item . Value . ToString ( ) ) ;
}
// 如果搜索框为空,显示所有项
IEnumerable < string > itemsToShow ;
if ( string . IsNullOrEmpty ( filterText ) )
{
itemsToShow = _ hazardFactors ;
}
else
{
// 进行不区分大小写的包含筛选
itemsToShow = _ hazardFactors . Where ( item = > item . IndexOf ( filterText , StringComparison . OrdinalIgnoreCase ) > = 0 ) ;
}
// 重新加载筛选后的列表,并保持之前已选中的项
ShowHazardFactorsData ( itemsToShow , currentlyCheckedItems ) ;
}
private void JobStatusComboBox_SelectedIndexChanged ( object sender , EventArgs e )
@ -95,12 +168,9 @@ namespace PEIS.View.Enrollment
var _l st = DAOHelp . GetDataBySQL < DictHazardType > ( $ @ "SELECT Name FROM Dict_HazardType
WHERE ParentID IN ( SELECT ID FROM Dict_HazardType WHERE ParentID in ( SELECT ID FROM Dict_HazardType WHERE Name = ' { status } ' ) ) ");
foreach ( var item in _l st )
{
HazardFactorsComboBox . Properties . Items . Add ( item . Name ) ;
}
HazardFactorsComboBox . Properties . DisplayMember = "Name" ;
HazardFactorsComboBox . Properties . ValueMember = "Name" ;
_ hazardFactors = _l st . Select ( x = > x . Name ) . ToList ( ) ;
HazardFactorsEdit . Text = string . Empty ;
ShowHazardFactorsData ( _ hazardFactors ) ;
}
private void ExamTypeComboBox_SelectedValueChanged ( object sender , EventArgs e )
@ -112,7 +182,7 @@ namespace PEIS.View.Enrollment
WorkYears . Enabled = true ;
HazardYears . Enabled = true ;
JobStatusComboBox . Enabled = true ;
HazardFactorsComboBox . Enabled = true ;
HazardFactorsEdit . Enabled = true ;
}
else
{
@ -120,7 +190,7 @@ namespace PEIS.View.Enrollment
WorkYears . Enabled = false ;
HazardYears . Enabled = false ;
JobStatusComboBox . Enabled = false ;
HazardFactorsComboBox . Enabled = false ;
HazardFactorsEdit . Enabled = false ;
}
}
@ -236,13 +306,17 @@ namespace PEIS.View.Enrollment
Description . Text = item ? . Description ;
Photo . Image = Base64ToImage ( item ? . Photo ) ;
JobTypes . Text = item ? . JobTypes ;
JobStatusComboBox . SelectedValue = item ? . JobStatus ? ? "岗前" ;
JobStatusComboBox . SelectedIndex = - 1 ;
if ( item ? . JobStatus ! = null )
{
JobStatusComboBox . SelectedValue = item ? . JobStatus ;
}
WorkYears . Text = item ? . WorkYears ;
HazardYears . Text = item ? . HazardYears ;
if ( item . ExamType ! = null & & item . ExamType . Contains ( "职业" ) )
{
HazardFactorsComboBox . SetEditValue ( item ? . HazardFactors . Split ( ';' ) . Select ( s = > ( object ) s . Trim ( ) ) . ToList ( ) ) ;
HazardFactorsEdit . Text = item ? . HazardFactors ;
}
OnGetPid ( ) ;
@ -352,7 +426,7 @@ namespace PEIS.View.Enrollment
return ;
}
if ( string . IsNullOrEmpty ( HazardFactorsComboBox . Text . Trim ( ) ) )
if ( string . IsNullOrEmpty ( HazardFactorsEdit . Text . Trim ( ) ) )
{
Global . Msg ( "err" , "请选择接害因素!" ) ;
return ;
@ -397,64 +471,66 @@ namespace PEIS.View.Enrollment
item . WorkYears = WorkYears . Text . Trim ( ) ;
item . HazardYears = HazardYears . Text . Trim ( ) ;
item . JobStatus = JobStatusComboBox . SelectedValue ? . ToString ( ) ;
item . HazardFactors = HazardFactorsComboBox . Text ;
item . HazardFactors = HazardFactorsEdit . Text ;
}
var _ hazardListeee = HazardFactorsComboBox . EditValue as List < object > ;
if ( _ editStatus ) // 编辑
{
item . ID = _ regInfo . ID ;
item . PID = _ regInfo ? . PID ;
OnUpdateRegItem ( item ) ;
// 判断是否更改为职业体检
if ( ExamType ! = null & & ExamType . Contains ( "职业" ) )
{
// 避免重复开设,删除个人所有项目
DAOHelp . ExecuteSql ( $@"UPDATE Enrollment_FeeItem SET EID = -{_regInfo?.ID}, CreateTime = GETDATE(), CreatorCode = '{Global.currentUser.Code}', Creator = '{Global.currentUser.Name}', IsSend = 0 WHERE EID = {_regInfo?.ID}" ) ;
List < FeeItem > _f eeItemsList = new List < FeeItem > ( ) ;
#region //编辑人员信息时不再修改项目
// 接害类型
var _ hazardList = HazardFactorsComboBox . EditValue as List < object > ;
foreach ( var hItem in _ hazardList ? . Select ( s = > s ? . ToString ( ) ) . ToList ( ) )
{
var feeItem = DAOHelp . GetDataBySQL < FeeItem > ( $@"EXEC sp_HazardFactors_FeeItem '{item.JobStatus.Trim()}', '{hItem.Trim()}' " ) ;
_f eeItemsList . AddRange ( feeItem ) ;
}
// 去除重复项
var _d istFeeItem = _f eeItemsList . GroupBy ( g = > g . KeyNo ) . Select ( s = > s . First ( ) ) . ToList ( ) ;
foreach ( var dItem in _d istFeeItem )
{
EnrollmentFeeItem eItem = new EnrollmentFeeItem ( ) ;
Int32 index = 0 ;
eItem . EID = _ regInfo ? . ID ;
eItem . FID = dItem . ID ;
eItem . FeeItemCode = dItem . FeeItemCode ;
eItem . FeeItemName = dItem . FeeItemName ;
eItem . Quantity = 1 ;
eItem . Unit = dItem . Unit ;
eItem . Price = dItem . Price ;
eItem . SettlePrice = dItem . SettlePrice ;
eItem . ItemClass = dItem . ItemClass ;
eItem . CreateTime = DateTime . Now ;
eItem . CreatorCode = Global . currentUser . Code ;
eItem . Creator = Global . currentUser . Name ;
eItem . DeptCode = dItem . DeptCode ;
eItem . DeptName = dItem . DeptName ;
eItem . Seq = index ;
eItem . KeyNo = dItem . KeyNo ;
eItem . IsOccupational = true ;
eItem . Save ( ) ;
}
}
// 判断是否更改为职业体检
//if (ExamType != null && ExamType.Contains("职业"))
//{
// // 避免重复开设,删除个人所有项目
// DAOHelp.ExecuteSql($@"UPDATE Enrollment_FeeItem SET EID = -{_regInfo?.ID}, CreateTime = GETDATE(), CreatorCode = '{Global.currentUser.Code}', Creator = '{Global.currentUser.Name}', IsSend = 0 WHERE EID = {_regInfo?.ID}");
// List<FeeItem> _feeItemsList = new List<FeeItem>();
// // 接害类型
// var _hazardList = HazardFactorsEdit.Text.Split(';').ToList();
// foreach (var hItem in _hazardList)
// {
// var feeItem = DAOHelp.GetDataBySQL<FeeItem>($@"EXEC sp_HazardFactors_FeeItem '{item.JobStatus.Trim()}', '{hItem.Trim()}' ");
// _feeItemsList.AddRange(feeItem);
// }
// // 去除重复项
// var _distFeeItem = _feeItemsList.GroupBy(g => g.KeyNo).Select(s => s.First()).ToList();
// foreach (var dItem in _distFeeItem)
// {
// EnrollmentFeeItem eItem = new EnrollmentFeeItem();
// Int32 index = 0;
// eItem.EID = _regInfo?.ID;
// eItem.FID = dItem.ID;
// eItem.FeeItemCode = dItem.FeeItemCode;
// eItem.FeeItemName = dItem.FeeItemName;
// eItem.Quantity = 1;
// eItem.Unit = dItem.Unit;
// eItem.Price = dItem.Price;
// eItem.SettlePrice = dItem.SettlePrice;
// eItem.ItemClass = dItem.ItemClass;
// eItem.CreateTime = DateTime.Now;
// eItem.CreatorCode = Global.currentUser.Code;
// eItem.Creator = Global.currentUser.Name;
// eItem.DeptCode = dItem.DeptCode;
// eItem.DeptName = dItem.DeptName;
// eItem.Seq = index;
// eItem.KeyNo = dItem.KeyNo;
// eItem.IsOccupational = true;
// eItem.Save();
// }
//}
# endregion
}
else //新增
{
@ -476,9 +552,9 @@ namespace PEIS.View.Enrollment
var EPItem = _l ist [ 0 ] ;
// 接害类型
var _ hazardList = HazardFactorsComboBox . EditValue as List < object > ;
var _ hazardList = HazardFactorsEdit . Text . Split ( ';' ) . ToList ( ) ;
foreach ( var hItem in _ hazardList ? . Select ( s = > s ? . ToString ( ) ) . ToList ( ) )
foreach ( var hItem in _ hazardList )
{
var feeItem = DAOHelp . GetDataBySQL < FeeItem > ( $@"EXEC sp_HazardFactors_FeeItem '{item.JobStatus.Trim()}', '{hItem.Trim()}' " ) ;
_f eeItemsList . AddRange ( feeItem ) ;
@ -797,20 +873,26 @@ namespace PEIS.View.Enrollment
Console . WriteLine ( items . Count ) ;
if ( items . Count = = 0 ) return ;
CompanyTxtBox . BeginUpdate ( ) ;
// 更新ComboBox
CompanyTxtBox . Items . Clear ( ) ;
foreach ( var item in items )
{
if ( string . IsNullOrEmpty ( item . Name ) ) continue ;
CompanyTxtBox . Items . Add ( item . Name ) ;
}
CompanyTxtBox . EndUpdate ( ) ;
// 保持下拉框打开
CompanyTxtBox . Items . AddRange ( items . Select ( x = > x . Name ) . ToArray ( ) ) ;
CompanyTxtBox . DroppedDown = true ;
// 保持文本选择状态,方便继续输入
CompanyTxtBox . SelectionStart = CompanyTxtBox . Text . Length ;
CompanyTxtBox . SelectionLength = 0 ;
//CompanyTxtBox.BeginUpdate();
//CompanyTxtBox.Items.Clear();
//foreach (var item in items)
//{
// if (string.IsNullOrEmpty(item.Name)) continue;
// CompanyTxtBox.Items.Add(item.Name);
//}
//CompanyTxtBox.EndUpdate();
//// 保持下拉框打开
//CompanyTxtBox.DroppedDown = true;
//// 保持文本选择状态,方便继续输入
//CompanyTxtBox.SelectionStart = CompanyTxtBox.Text.Length;
//CompanyTxtBox.SelectionLength = 0;
}
public void OnGetNationData ( )
@ -833,6 +915,41 @@ namespace PEIS.View.Enrollment
NationBoxTxt . SelectionStart = NationBoxTxt . Text . Length ;
NationBoxTxt . SelectionLength = 0 ;
}
/// <summary>
/// 加载数据到HazardFactors,并可选择性地设置某些项为选中状态
/// </summary>
/// <param name="items">要加载的数据项</param>
/// <param name="itemsToCheck">需要被选中的项(默认为null,不选中任何项)</param>
private void ShowHazardFactorsData ( IEnumerable < string > items , IEnumerable < string > itemsToCheck = null )
{
// 清除现有项
HazardFactorsCheckedListBoxControl . Items . Clear ( ) ;
// 添加已选项
if ( itemsToCheck ! = null )
{
foreach ( var item in itemsToCheck )
{
int index = HazardFactorsCheckedListBoxControl . Items . Add ( item , item ) ;
HazardFactorsCheckedListBoxControl . SetItemChecked ( index , true ) ;
}
}
// 添加筛选项
foreach ( var item in items )
{
if ( itemsToCheck ! = null & & itemsToCheck . Contains ( item ) )
{
continue ;
}
else
{
int index = HazardFactorsCheckedListBoxControl . Items . Add ( item , item ) ;
HazardFactorsCheckedListBoxControl . SetItemChecked ( index , false ) ;
}
}
}
# endregion
}
}