using DevExpress.XtraEditors; using HL_FristAidPlatform_DTO; using HL_FristAidPlatform_Public; using Microsoft.AspNetCore.SignalR.Client; using System; using System.Collections.Generic; using System.Data; using System.Threading.Tasks; using System.Windows.Forms; namespace HL_FristAidPlatform_PreHospitalEmergency { public partial class Form_120Main : XtraForm { #region 变量 /// /// 当前操作患者编号 /// private string Cur_PatientGuid; /// /// 条码机打印名称 /// private string BarCodePrinterName = string.Empty; /// /// 当前页 /// public int curPage = 1; /// /// 每页大小 /// public int pageSize = 100; /// /// 所有记录条数 /// public int totalNumber = 0; private HubConnection connection; #endregion #region 分页实现 public void ExportEvents(bool singlePage)//单页,所有 { //导出GridControl代码写在这。 } public void RefreshGridList() { FillGridListCtrlQuery(curPage);//自己实现FillGridListCtrlQuery函数。 } /// /// 绑定数据源 /// /// private void FillGridListCtrlQuery(int curPage) { try { #region 绑定数据源 int status = PublicClass.ToInt32(comboBox_Sel_Status.SelectedIndex, -1); string strParameter = string.Empty; //没有所有院区权限 只获取当前院区数据 if (!PublicHelp.IsHaveAllDistrictRight(Information.User.ID)) { strParameter += "&hospitalGuid=" + Information.Hospital.GUID; } if (!string.IsNullOrEmpty(txt_Key.Text.ToString().Trim())) { strParameter += "&keyWord=" + txt_Key.Text.ToString().Trim(); } string startTime = dateEdit_Start.TimeValue; string endTime = dateEdit_End.TimeValue; string Url = string.Format("api/service/T_Service_120FirstAid?pageIndex={0}&pageSize={1}&startTime={2}&endTime={3}&status={4}{5}", curPage, pageSize, startTime, endTime, status, strParameter); DataTable ResultDT = DBHelpClass.GetJsonText(Url); gridControl_Patient.DataSource = ResultDT;//显示分页结果 gridView_Patient.BestFitColumns();//列宽自适应 totalNumber = DBHelpClass.TotalNumber; userControlForPage.RefreshPager(pageSize, totalNumber, curPage);//更新分页控件显示。 #endregion } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定数据源:\r\n" + ex); } } private void MyPagerEvents(int curPage, int pageSize) { this.curPage = curPage; this.pageSize = pageSize; FillGridListCtrlQuery(curPage); } private void userControlForPage_exportEvents(bool singlePage) { userControlForPage.exportEvents += ExportEvents; } private void userControlForPage_myPagerEvents(int curPage, int pageSize) { userControlForPage.myPagerEvents += MyPagerEvents; } #endregion public Form_120Main() { InitializeComponent(); SignalRConnection(); } /// /// 窗体加载 /// /// /// private void Form_120Main_Load(object sender, EventArgs e) { dateEdit_Start.TimeValue = DateTime.Now.AddDays(-7).ToShortDateString() + " 00:00:00"; dateEdit_End.TimeValue = DateTime.Now.ToShortDateString() + " 23:59:59"; //查询 btn_Select_ItemClick(null, null); } #region 查询 /// /// 查询 /// /// /// private void btn_Select_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { RefreshGridList(); } /// /// 本月 /// /// /// private void simpleButton_ThisMonth_Click(object sender, EventArgs e) { dateEdit_Start.TimeValue = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.ToString(); dateEdit_End.TimeValue = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1).ToString(); RefreshGridList(); } /// /// 本周 /// /// /// private void simpleButton_ThisWeek_Click(object sender, EventArgs e) { dateEdit_Start.TimeValue = DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString() + " 00:00:00"; dateEdit_End.TimeValue = DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString() + " 23:59:59"; RefreshGridList(); } /// /// 今天 /// /// /// private void simpleButton_ToDay_Click(object sender, EventArgs e) { dateEdit_Start.TimeValue = DateTime.Now.Date.ToShortDateString() + " 00:00:00"; dateEdit_End.TimeValue = DateTime.Now.Date.ToShortDateString() + " 23:59:59"; RefreshGridList(); } /// /// 全部 /// /// /// private void simpleButton_All_Click(object sender, EventArgs e) { dateEdit_Start.TimeValue = "1990-01-01 00:00:00"; dateEdit_End.TimeValue = DateTime.Now.ToShortDateString() + " 23:59:59"; RefreshGridList(); } #endregion /// /// 新增 /// /// /// private void btn_Insert_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { //Form_120Edit frm = new Form_120Edit(); //frm.ShowDialog(); simpleButton_ToDay_Click(null, null); } /// /// 修改 /// /// /// private void btn_Update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (gridView_Patient.DataRowCount > 0) { int selectRow = gridView_Patient.GetSelectedRows()[0]; string ID = PublicClass.ToString(gridView_Patient.GetRowCellValue(selectRow, "ID"), "0"); Cur_PatientGuid = PublicClass.ToString(gridView_Patient.GetRowCellValue(selectRow, "PatientGuid"), ""); if (!string.IsNullOrEmpty(Cur_PatientGuid)) { //Form_120Edit frm = new Form_120Edit(Cur_PatientGuid); //frm.ShowDialog(); //定位 PublicClass.LocationForGridView(gridView_Patient, ID.ToString(), 0); } } } /// /// 退出 /// /// /// private void btn_Exit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { Close(); } /// /// 删除 /// /// /// private void btn_Delete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { if (gridView_Patient.DataRowCount > 0) { int selectRow = gridView_Patient.GetSelectedRows()[0]; string guid = gridView_Patient.GetRowCellValue(selectRow, "GUID").ToString(); if (XtraMessageBox.Show(string.Format("确定要删除患者【{0}】的信息么?", gridView_Patient.GetRowCellValue(selectRow, "Name").ToString()), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { List list = new List(); T_Service_PatientDTO model = new T_Service_PatientDTO(); model.GUID = guid; model.DeleteFlag = 1; #region 赋值不更新 model.CreationDate = PublicClass.DateTimeNow(); model.RegisterTime = PublicClass.DateTimeNow(); model.EditTime = PublicClass.DateTimeNow(); #endregion list.Add(model); string Url = "api/service/T_Service_Patient/Delete"; //初始化两个工厂 ClientFactory httpClient = new HttpClientFactory(); Client client = httpClient.VisitFactory(); //访问 ListEntity t = client.Post(Url, list); if (t.Success) { XtraMessageBox.Show("已删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //绑定列表 RefreshGridList(); } else { XtraMessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "删除:\r\n" + ex); } } /// /// 打印 /// /// /// private void btn_Print_Click(object sender, EventArgs e) { try { #region 打印 if (gridView_Patient.DataRowCount > 0) { if (!string.IsNullOrEmpty(Cur_PatientGuid)) { //打印调度单 string messageStr = Print.PrintDispatchOrder(Cur_PatientGuid, ckb_IsPrintPreview.Checked); if (!string.IsNullOrEmpty(messageStr)) { XtraMessageBox.Show(messageStr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { XtraMessageBox.Show("请先在列表中选择急救任务再打印调度单!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } #endregion } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "打印:\r\n" + ex); } } /// /// 双击跳转 /// /// /// private void gridControl_Patient_MouseDoubleClick(object sender, MouseEventArgs e) { try { if (gridView_Patient.DataRowCount > 0) { int selectRow = gridView_Patient.GetSelectedRows()[0]; Cur_PatientGuid = PublicClass.ToString(gridView_Patient.GetRowCellValue(selectRow, "PatientGuid"), ""); if (!string.IsNullOrEmpty(Cur_PatientGuid)) { //Form_120Edit frm = new Form_120Edit(Cur_PatientGuid); //frm.ShowDialog(); } } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "双击跳转:\r\n" + ex); } } /// /// 单击赋值 /// /// /// private void gridControl_Patient_MouseClick(object sender, MouseEventArgs e) { if (gridView_Patient.DataRowCount > 0) { int selectRow = gridView_Patient.GetSelectedRows()[0]; Cur_PatientGuid = PublicClass.ToString(gridView_Patient.GetRowCellValue(selectRow, "PatientGuid"), ""); } } #region public async void SignalRConnection() { connection = new HubConnectionBuilder() .WithUrl("http://47.112.158.86:4998/ChatHub") .Build(); await connection.StartAsync(); connection.Closed += async (error) => { await Task.Delay(new Random().Next(0, 5) * 1000); await connection.StartAsync(); }; } private async void button1_Click(object sender, EventArgs e) { try { await connection.InvokeAsync("WinFormsApp", "SignalRClient", this.txt_Key.Text); connection.On("ReceiveUpdate", (message) => { this.Invoke(new Action(() => { this.txt_Key.Text = message.ToString(); })); }); } catch (Exception ex) { this.txt_Key.Text = ex.Message; } } #endregion } }