using CallingClient.core.api;
using CallingClient.core.constants;
using CallingClient.core.enums;
using CallingClient.core.model;
using CallingClient.core.ui;
using Newtonsoft.Json;
using Serilog;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ToastNotifications;
using ToastNotifications.Lifetime;
using ToastNotifications.Position;
using ToastNotifications.Messages;
using System.Configuration;
using System.Threading.Tasks;
namespace CallingClient
{
public class State : INotifyPropertyChanged
{
private Visibility listVisibility = Visibility.Visible;
private User userInfo = new User();
private double listHeight = Double.NaN;
private bool listHeightAuto = true;
private int _callingStatus = 1;
private CallingPatient _currentPatient = new CallingPatient();
private ButtonGroupStyleConfig _mybuttonGroupStyleConfig = new ButtonGroupStyleConfig();
public int CallingStatus { get { return _callingStatus; } set { _callingStatus = value; OnPropertyChanged("CallingStatus"); } }
public State() {
}
public Visibility ListVisibility
{
get { return listVisibility; }
set
{
listVisibility = value;
OnPropertyChanged("ListVisibility");
}
}
public User UserInfo
{
get { return userInfo; }
set
{
userInfo = value;
OnPropertyChanged("UserInfoChange");
}
}
public double ListHeight
{
get { return listHeight; }
set
{
listHeight = value;
OnPropertyChanged("ListHeight");
}
}
public bool ListHeightAuto
{
get { return listHeightAuto; }
set
{
listHeightAuto = value;
OnPropertyChanged("ListHeightAuto");
}
}
public CallingPatient CurrentPatient { get => _currentPatient;
set {
_currentPatient = value;
OnPropertyChanged("CurrentPatient");
}
}
public ButtonGroupStyleConfig MyButtonGroupStyleConfig { get => _mybuttonGroupStyleConfig; set {
_mybuttonGroupStyleConfig = value;
OnPropertyChanged("MyButtonGroupStyleConfig");
} }
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string info)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(info));
}
}
}
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public State PageState { get; set; } = new State();
private double ListHeightStored { get; set; } = Double.NaN;
private PatientQuery _patientQuery = new PatientQuery();
Notifier _mainWindownotifier;
private string _shift;//班次
public MainWindow()
{
InitializeComponent();
//listview打开后默认选中第一行
// this.lvUsers.SelectedIndex = 0;
//设置位置、大小
Rect restoreBounds = Properties.Settings.Default.MainRestoreBounds;
this.WindowState = WindowState.Normal;
this.Left = restoreBounds.Left;
this.Top = restoreBounds.Top;
this.Width = restoreBounds.Width;
this.Height = restoreBounds.Height;
this.WindowStyle = WindowStyle.None;
this.MouseDown += MainWindow_MouseDown;
DataContext = PageState;
PageState.PropertyChanged += PageState_PropertyChanged;
if(Properties.Settings.Default.MainRestoreHeight > 5)
{
this.Height = Properties.Settings.Default.MainRestoreHeight;
}
this.Loaded += MainWindow_Loaded;
this.Topmost = true;
_mainWindownotifier = new Notifier(cfg =>
{
cfg.PositionProvider = new WindowPositionProvider(
parentWindow: this,
corner: Corner.BottomCenter,
offsetX: 10,
offsetY: -70);
cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
notificationLifetime: TimeSpan.FromSeconds(1),
maximumNotificationCount: MaximumNotificationCount.FromCount(3));
cfg.Dispatcher = Application.Current.Dispatcher;
});
}
private void WindowRendered(object sender, EventArgs e)
{
this.initApp();
String autoRefreshSeconds = ConfigurationManager.AppSettings["auto_refresh_seconds"];
if (!string.IsNullOrEmpty(autoRefreshSeconds))
{
int autoRefreshSecondsInt = int.Parse(autoRefreshSeconds);
if (autoRefreshSecondsInt > 0)
{
this.InitTimer();
}
}
}
//定义Timer类
System.Timers.Timer timer;
/// <summary>
/// 初始化Timer控件
/// </summary>
private void InitTimer()
{
try
{
//设置定时间隔(毫秒为单位)
String autoRefreshSeconds = ConfigurationManager.AppSettings["auto_refresh_seconds"];
int autoRefreshSecondsInt = int.Parse(autoRefreshSeconds);
int interval = autoRefreshSecondsInt * 1000;
timer = new System.Timers.Timer(interval);
//设置执行一次(false)还是一直执行(true)
timer.AutoReset = true;
//设置是否执行System.Timers.Timer.Elapsed事件
timer.Enabled = true;
//绑定Elapsed事件
timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerUp);
}
catch(Exception ee)
{
MessageBox.Show(ee.Message+"定时刷新异常请联系小号72179");
}
}
/// <summary>
/// Timer类执行定时到点事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TimerUp(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
this.Dispatcher.Invoke(new Action(delegate
{
//this.doRefresh();
this.refreshData();
}));
}
catch (Exception ex)
{
MessageBox.Show("执行定时到点事件失败:" + ex.Message);
Log.Logger.Error("执行定时查询失败");
}
}
private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
this.DragMove();
}
private void PageState_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if(e.PropertyName == "CallingStatus")
{
_patientQuery.CallingStatusList = PageState.CallingStatus.ToString();
refreshData();
}
}
private async void initApp()
{
try
{
PageState.UserInfo = await UserInfo.FetchUserInfo();
if (PageState.UserInfo == null)
{
Log.Logger.Error("未获取到用户身份信息, 请联系管理人员");
this.statusBarText.Text = "未获取到用户身份信息, 请联系管理人员";
this.Dispatcher.Invoke(new Action(delegate
{
this._mainWindownotifier.ShowError("获取用户信息失败,请联系技术人员");
}));
return;
}
userNameLabel.Content = PageState.UserInfo.Name;
_patientQuery.AreaId = PageState.UserInfo.AreaId;
_patientQuery.DoctCategoryid = PageState.UserInfo.DoctCategoryid;
_patientQuery.DoctAttribute = PageState.UserInfo.DoctAttribute;
_patientQuery.QueueId = PageState.UserInfo.DoctQueue;
_patientQuery.PatientName = PageState.UserInfo.PatientName;
dp1.SelectedDate = DateTime.Now;
//_patientQuery.callingRegDatetime = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")+ "T16:00:00.000Z";
_patientQuery.callingRegDatetime = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
initShiftSelect();
Constants.CallingQueueModels = await CallingQueue.CallingQueueDict(PageState.UserInfo.AreaId.ToString());
initQueueSelect(_patientQuery.QueueId);
dp1.SelectedDateChanged += dp1_SelectedDateChanged;
refreshData();
}
catch (Exception ee)
{
Log.Logger.Error(ee.Message);
}
}
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
try
{
userNameLabel.Content = PageState.UserInfo.Name;
mnuCheckForUpdates.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
await Task.Run(() => sender);
//this.lvUsers.SelectedIndex = 0;
}
catch (Exception ee)
{
Log.Logger.Error(ee.Message);
}
}
private List<string> selectQueues;
private void initQueueSelect(string queueId)
{
Log.Logger.Debug("初始化队列 | " + queueId);
if (!string.IsNullOrWhiteSpace(queueId))
{
//Log.Logger.Debug("队列字典 | " + JsonConvert.SerializeObject(Constants.CallingQueueModels));
string[] queueArray = queueId.Split(',');
if (Constants.UserInfo.DoctAttribute == 0)
{
selectQueues = queueArray.ToList();
}
else
{
selectQueues = new List<string>();
}
}
if (Constants.CallingQueueModels == null || Constants.CallingQueueModels.Length == 0)
{
Log.Logger.Error("未获取到队列字典");
return;
}
foreach (var item in Constants.CallingQueueModels)
{
MenuItem menuItem = new MenuItem();
menuItem.Header = item.QueueName;
menuItem.Tag = item.QueueId;
if (selectQueues != null && selectQueues.Count > 0)
{
if (item.QueueId == selectQueues[0])
{
menuItem.IsChecked = true;
}
}
menuItem.Click += QueueMenuItem_Click;
changeQueueMenu.Items.Add(menuItem);
}
}
private string selectQueueToString()
{
if(selectQueues == null)
{
return "";
}
return String.Join(",", selectQueues);
}
private void QueueMenuItem_Click(object sender, RoutedEventArgs e)
{
if (selectQueues == null)
{
selectQueues=new List<string>();
}
MenuItem item = sender as MenuItem;
if (item.IsChecked)
{
selectQueues.Remove(item.Tag.ToString());
item.IsChecked = false;
}
else
{
selectQueues.Clear();
selectQueues.Add(item.Tag.ToString());
item.IsChecked = true;
foreach (MenuItem it in changeQueueMenu.Items)
{
if (it.Tag.ToString() != item.Tag.ToString())
{
it.IsChecked = false;
}
}
}
refreshData();
}
private void initShiftSelect()
{
string[] shiftArray = { "上午", "下午", "晚上", "全天" };
String shift = ConfigurationManager.AppSettings["shift"];
var hour = DateTime.Now.Hour;
if (hour>=6 && hour < 13)
{
shift = "上午";
}
else if(hour>=13 && hour<18)
{
shift = "下午";
}else if(hour>=18 && hour<=24)
{
shift = "晚上";
}else if(hour>=0 && hour < 6)
{
shift = "晚上";
}
if (!string.IsNullOrEmpty(shift))
{
_patientQuery.Shift = shift; //加入默认班次
}
foreach (var item in shiftArray)
{
MenuItem menuItem = new MenuItem();
menuItem.Header = item;
menuItem.Tag = item;
if (!string.IsNullOrEmpty(shift) && item == shift)
{
menuItem.IsChecked = true;
}
menuItem.Click += ShiftMenuItem_Click;
changeShiftMenu.Items.Add(menuItem);
}
}
private void ShiftMenuItem_Click(object sender, RoutedEventArgs e)
{
MenuItem item = sender as MenuItem;
_shift = item.Tag.ToString();
item.IsChecked = true;
foreach(MenuItem it in changeShiftMenu.Items)
{
if (it.Tag.ToString() != _shift)
{
it.IsChecked = false;
}
}
refreshData();
}
private async void refreshData()
{
try
{
_patientQuery.QueueId = selectQueueToString();
if (dp1.SelectedDate != null)
{
_patientQuery.callingRegDatetime = ((DateTime)dp1.SelectedDate).AddDays(-1).ToString("yyyy-MM-dd") + "T16:00:00.000Z";
}
if (Constants.UserInfo.DoctAttribute == 1)
{
_patientQuery.DoctId = Constants.UserInfo.IdCard;
_patientQuery.PatientName = Constants.UserInfo.PatientName;
}
if (!string.IsNullOrWhiteSpace(_shift))
{
_patientQuery.Shift = _shift;
}
Log.Logger.Information("selectQueueToString | " + _patientQuery.QueueId);
if (String.IsNullOrEmpty(_patientQuery.QueueId))
{
_patientQuery.DoctAttribute = Constants.UserInfo.DoctAttribute;
_patientQuery.DoctCategoryid = Constants.UserInfo.DoctCategoryid;
}
else
{
//如果选择了队列,统一置为普通诊医生
_patientQuery.DoctAttribute = 0;
}
lvUsers.ItemsSource = await CallingMaster.doctqueryListPage(_patientQuery.getQueryString());
this.lvUsers.SelectedIndex = 0;
}
catch (Exception ee)
{
//MessageBox.Show(ee.Message + "请联系72179");
Log.Logger.Error(ee.Message);
}
//lvUsers.Items.Refresh();
// ICollectionView view = CollectionViewSource.GetDefaultView(lvUsers.ItemsSource);
// view.Refresh();
}
public void SwitchCategory()
{
SwitchCategoryDialog dlg = new SwitchCategoryDialog
{
Owner = this
};
dlg.ShowDialog();
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
SwitchCategory();
}
private void Expander_Collapsed(object sender, RoutedEventArgs e)
{
PageState.ListHeight = ListHeightStored;
PageState.ListVisibility = Visibility.Collapsed;
DataContext = PageState;
this._listheight = this.Height;
this.SizeToContent = SizeToContent.Height;
PageState.MyButtonGroupStyleConfig = new ButtonGroupStyleConfig(ButtonSize.SMALL);
}
private double _listheight = 0;
private void Expander_Expanded(object sender, RoutedEventArgs e)
{
ListHeightStored = 0;
PageState.ListVisibility = Visibility.Visible;
DataContext = PageState;
if(this._listheight >= 5)
{
this.SizeToContent = SizeToContent.Manual;
this.Height = this._listheight;
}
PageState.MyButtonGroupStyleConfig = new ButtonGroupStyleConfig();
}
private void list_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (e.HeightChanged != true)
{
return;
}
}
private CallingFuncParam getCallingBaseParam()
{
CallingFuncParam callingFuncParam = new CallingFuncParam();
callingFuncParam.DoctAttribute = Constants.UserInfo.DoctAttribute;
callingFuncParam.DoctCategoryid = Constants.UserInfo.DoctCategoryid;
callingFuncParam.QueueId = selectQueueToString();
Log.Logger.Information("autoCalling_Click | selectQueueToString | " + _patientQuery.QueueId);
if (String.IsNullOrEmpty(callingFuncParam.QueueId))
{
callingFuncParam.DoctAttribute = Constants.UserInfo.DoctAttribute;
callingFuncParam.DoctCategoryid = Constants.UserInfo.DoctCategoryid;
}
else
{
//如果选择了队列,统一置为普通诊医生
callingFuncParam.DoctAttribute = 0;
}
callingFuncParam.DoctId = Constants.UserInfo.IdCard;
callingFuncParam.AreaId = Constants.UserInfo.AreaId;
return callingFuncParam;
}
private async void autoCalling_Click(object sender, RoutedEventArgs e)
{
/* if (0 != lvUsers.SelectedItems.Count)
{
CallingPatient item = lvUsers.SelectedItems[0] as CallingPatient;
item.FuncCode = "calling";
String queueId = selectQueueToString();
if (String.IsNullOrEmpty(queueId))
{
item.DoctAttribute = Constants.UserInfo.DoctAttribute.ToString();
item.DoctCategoryid = Constants.UserInfo.DoctCategoryid;
}
else
{
//如果选择了队列,统一置为普通诊医生
item.DoctAttribute = 0.ToString();
}
//if(item.DoctAttribute == 1.ToString())
// {
// item.DoctId = Constants.UserInfo.IdCard;
//}
//item.DoctAttribute = Constants.UserInfo.DoctAttribute.ToString();
//item.DoctCategoryid = Constants.UserInfo.DoctCategoryid;
List<CallingPatient> callingPatients = new List<CallingPatient>();
callingPatients.Add(item);
string jsonString = JsonConvert.SerializeObject(callingPatients, Formatting.Indented);
Boolean result = await DoCalling.CallingSelect(JsonConvert.DeserializeObject(jsonString));
if (result)
{
PageState.CurrentPatient = item;
this._mainWindownotifier.ShowSuccess("呼叫成功");
this.refreshData();
}
}
this.refreshData();
//this.lvUsers.SelectedIndex=0;
// MessageBox.Show(callingPatient.PatientName);
/* CallingFuncParam callingFuncParam = getCallingBaseParam();
callingFuncParam.FuncCode = "autoCalling";
CallingPatient callingPatient = await DoCalling.AutoCalling(callingFuncParam.getJsonObject());
if (callingPatient != null)
{
PageState.CurrentPatient = callingPatient;
this.refreshData();
this._mainWindownotifier.ShowSuccess("呼叫成功");
}
else
{
this.statusBarText.Text = "当前没有等待病人";
this._mainWindownotifier.ShowInformation("当前没有等待病人");
}
*/
CallingFuncParam callingFuncParam = getCallingBaseParam();
callingFuncParam.FuncCode = "autoCalling";
//CallingPatient callingPatient = await DoCalling.AutoCalling(callingFuncParam.getJsonObject());
var result = await DoCalling.AutoCalling(callingFuncParam.getJsonObject());
if (result.Code == 200)
{
if (result.Data == "没有已到病人")
{
PageState.CurrentPatient = null;
this.statusBarText.Text = "当前没有等待病人";
this._mainWindownotifier.ShowInformation("当前没有等待病人");
}
else
{
var CallingStatus = _patientQuery.CallingStatusList;
_patientQuery.CallingStatusList = "3";
var CallingPatientList = await CallingMaster.doctqueryListPage(_patientQuery.getQueryString());
PageState.CurrentPatient = CallingPatientList[0];
_patientQuery.CallingStatusList = CallingStatus;
this.refreshData();
this._mainWindownotifier.ShowSuccess(result.Message);
}
}
else
{
this._mainWindownotifier.ShowError(result.Message);
}
}
private async void repetCalling_Click(object sender, RoutedEventArgs e)
{
CallingFuncParam callingFuncParam = getCallingBaseParam();
callingFuncParam.FuncCode = "repeatcalling";
CallingPatient callingPatient = await DoCalling.RepeatCalling(callingFuncParam.getJsonObject());
if (callingPatient != null)
{
PageState.CurrentPatient = callingPatient;
this.refreshData();
//this._mainWindownotifier.ShowSuccess("重呼成功");
}
this._mainWindownotifier.ShowSuccess("重呼成功");
}
private async void pass_Click(object sender, RoutedEventArgs e)
{
if(PageState.CurrentPatient != null)
{
CallingPatient callingPatient = PageState.CurrentPatient;
callingPatient.CallingStatus = Convert.ToInt32(CallingStatusEnums.PASS);
doChangeStatus(callingPatient);
}
else
{
notifyStatusMsg("不存在当前病人");
}
}
public void notifyStatusMsg(string msg)
{
if(!string.IsNullOrEmpty(msg))
{
statusBarText.Text = msg;
}
}
private async void doChangeStatus(CallingPatient callingPatient)
{
List<CallingPatient> callingPatients = new List<CallingPatient>();
callingPatients.Add(callingPatient);
string jsonString = JsonConvert.SerializeObject(callingPatients, Formatting.Indented);
Boolean changeSuccess = await CallingStatus.ChangeCallingStatus(JsonConvert.DeserializeObject(jsonString));
if (changeSuccess)
{
notifyStatusMsg("更改病人状态成功");
}
else
{
notifyStatusMsg("更改病人状态失败");
}
}
private void complete_Click(object sender, RoutedEventArgs e)
{
if (PageState.CurrentPatient != null)
{
CallingPatient callingPatient = PageState.CurrentPatient;
callingPatient.CallingStatus = Convert.ToInt32(CallingStatusEnums.COMPLETE);
doChangeStatus(callingPatient);
}
else
{
notifyStatusMsg("不存在当前病人");
}
}
private async void lvUsers_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (0 != lvUsers.SelectedItems.Count)
{
CallingPatient item = lvUsers.SelectedItems[0] as CallingPatient;
item.FuncCode = "calling";
String queueId = selectQueueToString();
if (String.IsNullOrEmpty(queueId))
{
item.DoctAttribute = Constants.UserInfo.DoctAttribute.ToString();
item.DoctCategoryid = Constants.UserInfo.DoctCategoryid;
}
else
{
//如果选择了队列,统一置为普通诊医生
item.DoctAttribute = 0.ToString();
}
//if(item.DoctAttribute == 1.ToString())
// {
// item.DoctId = Constants.UserInfo.IdCard;
//}
//item.DoctAttribute = Constants.UserInfo.DoctAttribute.ToString();
//item.DoctCategoryid = Constants.UserInfo.DoctCategoryid;
List<CallingPatient> callingPatients = new List<CallingPatient>();
callingPatients.Add(item);
string jsonString = JsonConvert.SerializeObject(callingPatients, Formatting.Indented);
Boolean result = await DoCalling.CallingSelect(JsonConvert.DeserializeObject(jsonString));
if(result)
{
PageState.CurrentPatient = item;
this.refreshData();
this._mainWindownotifier.ShowSuccess("呼叫成功");
}
this.refreshData();
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//保存当前位置、大小和状态,到配置文件
Properties.Settings.Default.MainRestoreBounds = this.RestoreBounds;
Properties.Settings.Default.MainRestoreCollapse = PageState.ListVisibility == Visibility.Visible ? true : false;
Properties.Settings.Default.MainRestoreHeight = this._listheight;
Properties.Settings.Default.Save();
}
private void quit_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("确认退出?", "退出应用", System.Windows.Forms.MessageBoxButtons.OKCancel);
if(dialogResult == System.Windows.Forms.DialogResult.OK)
{
this.Close();
System.Environment.Exit(0);
}
}
private void minize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void refreshDataBtn_Click(object sender, RoutedEventArgs e)
{
this.doRefresh();
}
private async void doRefresh(Boolean notifyEnabled = true)
{
_patientQuery.QueueId = selectQueueToString();
if (Constants.UserInfo.DoctAttribute == 1)
{
_patientQuery.DoctId = Constants.UserInfo.IdCard;
}
Log.Logger.Information("selectQueueToString | " + _patientQuery.QueueId);
if (String.IsNullOrEmpty(_patientQuery.QueueId))
{
_patientQuery.DoctAttribute = Constants.UserInfo.DoctAttribute;
_patientQuery.DoctCategoryid = Constants.UserInfo.DoctCategoryid;
}
else
{
//如果选择了队列,统一置为普通诊医生
_patientQuery.DoctAttribute = 0;
}
lvUsers.ItemsSource = await CallingMaster.doctqueryListPage(_patientQuery.getQueryString());
if (notifyEnabled)
{
//this._mainWindownotifier.ShowSuccess("刷新成功");
Log.Logger.Information("刷新成功");
}
}
private void dp1_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
this.refreshData();
}
}
}
文章描述了一个名为CallingClient的应用程序中的State类和MainWindow类的实现,这两个类主要用于管理用户信息、队列选择、呼叫状态以及界面更新。State类包含用户信息、列表显示状态等属性,而MainWindow类处理UI交互,如拖动窗口、定时刷新数据、处理队列和班次选择。应用程序使用Timers进行定时刷新,显示通知,并在用户操作如选择队列或日期变化时更新数据。

1114

被折叠的 条评论
为什么被折叠?



