using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using HL_FristAidPlatform_DTO;
using HL_FristAidPlatform_Public;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace HL_FristAidPlatform_FollowUp
{
public partial class Form_FollowUpMain_Apoplexy : XtraForm
{
#region 变量
///
/// 当前页
///
private int curPage = 1;
///
/// 所有记录条数
///
public int totalNumber = 0;
///
/// 每页大小
///
private int pageSize = 32;
///
///Guid
///
private string Guid;
///
/// 需随访患者是否弹窗提醒
///
public int flag = 0;
///
/// 需随访患者
///
public string followUpRemindNeed = "近期需随访患者:";
public Form_FollowUpAndHealthDetail fur;
#endregion
public Form_FollowUpMain_Apoplexy() { InitializeComponent(); }
private void MyPagerEvents(int curPage, int pageSize)
{
this.curPage = curPage;
this.pageSize = pageSize;
FillGridListCtrlQuery(curPage);
}
public void ExportEvents(bool singlePage)//单页,所有
{
}
///
/// 窗体加载事件
///
///
///
private void Form_FollowUpMain_Apoplexy_Load(object sender, EventArgs e)
{
try
{
timeControl_startime.TimeValue = null;
timeControl_endtime.TimeValue = null;
textBox_endage.Text = null;
textBox_startage.Text = null;
textBox1.Text = null;
FillGridListCtrlQuery(curPage);
LoadApoplexyRemind();
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "卒中健康与随访主页面:\r\n" + ex);
}
}
private void LoadApoplexyRemind()
{
string Url = string.Format("api/service/T_Service_Apoplexy_FAHBase/GetPageList1?&hospitalGuid={0}", Information.Hospital.GUID);
List keyValuelist = DBHelpClass.GetList(Url);
if (flag == 0)
{
if (keyValuelist != null && keyValuelist.Count > 0)
{
for (int i = 0; i < keyValuelist.Count; i++)
{
followUpRemindNeed += keyValuelist[i].Key + ";";
}
flag = 1;
//弹窗提醒需随访患者
if (followUpRemindNeed != "近期需随访患者:")
{
Form_Followupremind followupremind = new Form_Followupremind(followUpRemindNeed);
followupremind.TopMost = true;
followupremind.Location = new Point(SystemInformation.PrimaryMonitorSize.Width / 2 - 200, SystemInformation.PrimaryMonitorSize.Height / 2 - 150);
followupremind.Show();
}
}
}
}
///
/// 绑定数据源
///
///
public void FillGridListCtrlQuery(int curPage)
{
try
{
string startTime;
string endTime;
string Url = string.Empty;
string ageStart;
string ageEnd;
string name;
if (!string.IsNullOrEmpty(timeControl_startime.TimeValue))
{
startTime = timeControl_startime.TimeValue;
}
else
{
startTime = "";
}
if (!string.IsNullOrEmpty(timeControl_endtime.TimeValue))
{
endTime = timeControl_endtime.TimeValue;
}
else
{
endTime = "";
}
if (!string.IsNullOrEmpty(textBox_startage.Text))
{
ageStart = textBox_startage.Text;
}
else
{
ageStart = "";
}
if (!string.IsNullOrEmpty(textBox_endage.Text))
{
ageEnd = textBox_endage.Text;
}
else
{
ageEnd = "";
}
if (!string.IsNullOrEmpty(textBox1.Text))
{
name = textBox1.Text;
}
else
{
name = "";
}
string systemModuleID = "3";
string hospitalGuid = Information.Hospital.GUID;
Url = string.Format("api/service/T_Service_Apoplexy_FAHBase/GetPageList?pageIndex={0}&pageSize={1}&hospitalGuid={2}&systemModuleID={3}&starttime={4}&endtime={5}&ageStart={6}&ageEnd={7}&name={8}",
curPage, pageSize, hospitalGuid, systemModuleID, startTime, endTime, ageStart, ageEnd, name);
DataTable dt = DBHelpClass.Get(Url);
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (!string.IsNullOrEmpty(dt.Rows[i]["Sex"].ToString()))
{
switch (dt.Rows[i]["Sex"].ToString())
{
case "1":
dt.Rows[i]["Sex"] = "男";
break;
case "2":
dt.Rows[i]["Sex"] = "女";
break;
}
}
//FNextDay
if (!string.IsNullOrEmpty(dt.Rows[i]["FNextDay"] + ""))
{
DateTime t1 = Convert.ToDateTime(dt.Rows[i]["FNextDay"] + "");
DateTime t2 = DateTime.Now;
TimeSpan sp = t1.Subtract(t2);
dt.Rows[i]["FNextDay"] = sp.Days + 1;
}
}
}
gridControl_Patients.DataSource = dt;
totalNumber = DBHelpClass.TotalNumber;
userControlForPage1.RefreshPager(pageSize, totalNumber, curPage);//更新分页控件显示。
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定数据源:\r\n" + ex);
}
}
///
/// 列表双击事件
///
///
///
private void gridControl_Patients_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (gridView_Patients.DataRowCount > 0)
{
int selectRow = gridView_Patients.GetSelectedRows()[0];
long PatientID = PublicClass.ToInt64(gridView_Patients.GetRowCellValue(selectRow, "ID").ToString(), 0);
Guid = gridView_Patients.GetRowCellValue(selectRow, "GUID").ToString();
string name = gridView_Patients.GetRowCellValue(selectRow, "Name").ToString();
string age = gridView_Patients.GetRowCellValue(selectRow, "Age").ToString();
string gender = gridView_Patients.GetRowCellValue(selectRow, "Sex").ToString();
fur = new Form_FollowUpAndHealthDetail(Guid, name, age, gender);
fur.Owner = this;
fur.Show();
}
}
#region 随访状态判断
private void gridView_Patients_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
GridView View = sender as GridView;
//随访状态
if (e.Column.FieldName == "FollowUpStatus")
{
var FollowUpStatus = e.CellValue;
switch (FollowUpStatus)
{
case "0":
e.Appearance.BackColor = Color.Red;
e.Appearance.BackColor2 = Color.FromArgb(255, 255, 255);
break;
case "1":
e.Appearance.BackColor = Color.Green;
e.Appearance.BackColor2 = Color.FromArgb(255, 255, 255);
break;
default:
break;
}
}
if (e.Column.FieldName == "FollowUpDate")
{
var FollowUpDate = Convert.ToString(e.CellValue);
if (!string.IsNullOrEmpty(FollowUpDate))
{
if (DateTime.Now.Day == Convert.ToDateTime(FollowUpDate).Day)
{
e.Appearance.BackColor = Color.Red;
e.Appearance.BackColor2 = Color.FromArgb(255, 255, 255);
}
else
{
e.Appearance.BackColor = Color.Green;
e.Appearance.BackColor2 = Color.FromArgb(255, 255, 255);
}
}
else
{
e.Appearance.BackColor = Color.Green;
e.Appearance.BackColor2 = Color.FromArgb(255, 255, 255);
}
}
}
private void gridView_Patients_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
GridView View = sender as GridView;
//随访状态
if (e.Column.FieldName == "FollowUpDate")
{
var FollowUpDate = Convert.ToString(e.Value);
e.DisplayText = FollowUpDate;
}
if (e.Column.FieldName == "FollowUpStatus")
{
var FollowUpStatus = Convert.ToString(e.Value);
switch (FollowUpStatus)
{
case "0":
e.DisplayText = "未随访";
break;
case "1":
e.DisplayText = "已随访";
break;
default:
break;
}
}
}
#endregion
public void MdiChildrenClose()
{
//关闭所有已经打开的子窗体
if (MdiChildren.Length > 0)
{
foreach (Form myForm in this.MdiChildren)
{
myForm.Close();
}
}
}
private bool ShowChildrenForm(string p_ChildrenFormText)
{
int i;
//依次检测当前窗体的子窗体
for (i = 0; i < MdiChildren.Length; i++)
{
//判断当前子窗体的Text属性值是否与传入的字符串值相同
if (MdiChildren[i].Name == p_ChildrenFormText)
{
//如果值相同则表示此子窗体为想要调用的子窗体,激活此子窗体并返回true值
MdiChildren[i].Activate();
return true;
}
}
//如果没有相同的值则表示要调用的子窗体还没有被打开,返回false值
return false;
}
///
/// 新建患者页面加载
///
///
///
private void Button_Addfollowup_Click(object sender, EventArgs e)
{
Form_AddFollowUpPatient form_AddPatient = new Form_AddFollowUpPatient();
form_AddPatient.Owner = this;
form_AddPatient.Show();
}
///
/// 今日
///
///
///
private void simpleButton_ToDay_Click(object sender, EventArgs e)
{
timeControl_startime.TimeValue = DateTime.Now.ToString("yyyy-MM-dd");
timeControl_endtime.TimeValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
FillGridListCtrlQuery(curPage);
}
///
/// 本周
///
///
///
private void simpleButton_ThisWeek_Click(object sender, EventArgs e)
{
timeControl_startime.TimeValue = DateTime.Now.AddDays(0 - DateTime.Now.DayOfWeek).ToString("yyyy-MM-dd");
timeControl_endtime.TimeValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
FillGridListCtrlQuery(curPage);
}
///
/// 本月
///
///
///
private void simpleButton_ThisMonth_Click(object sender, EventArgs e)
{
timeControl_startime.TimeValue = DateTime.Now.ToString("yyyy-MM");
timeControl_endtime.TimeValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
FillGridListCtrlQuery(curPage);
}
///
/// 本季
///
///
///
private void simpleButton_quarter_Click(object sender, EventArgs e)
{
timeControl_startime.TimeValue = DateTime.Now.AddMonths(-3).Date.ToString("yyyy-MM");
timeControl_endtime.TimeValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
FillGridListCtrlQuery(curPage);
}
///
/// 本年
///
///
///
private void simpleButton_thisyear_Click(object sender, EventArgs e)
{
timeControl_startime.TimeValue = DateTime.Now.AddMonths(-DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd"); ;
timeControl_endtime.TimeValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
FillGridListCtrlQuery(curPage);
}
///
/// 全部
///
///
///
private void simpleButton_all_Click(object sender, EventArgs e)
{
timeControl_startime.TimeValue = null;
timeControl_endtime.TimeValue = null;
FillGridListCtrlQuery(curPage);
}
///
/// 查询按钮
///
///
///
private void simpleButton_Search_Click(object sender, EventArgs e)
{
FillGridListCtrlQuery(curPage);
}
private void userControlForPage1_myPagerEvents(int curPage, int pageSize)
{
userControlForPage1.myPagerEvents += MyPagerEvents;
}
private void userControlForPage1_exportEvents(bool singlePage)
{
userControlForPage1.exportEvents += ExportEvents;
}
private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
if (gridView_Patients.DataRowCount > 0)
{
int selectRow = gridView_Patients.GetSelectedRows()[0];
long PatientID = PublicClass.ToInt64(gridView_Patients.GetRowCellValue(selectRow, "ID").ToString(), 0);
Guid = gridView_Patients.GetRowCellValue(selectRow, "GUID").ToString();
DialogResult dr = XtraMessageBox.Show("是否确定删除该健康档案?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
List list = new List();
T_Service_Apoplexy_FAHBaseDTO dto = new T_Service_Apoplexy_FAHBaseDTO();
dto.PatientGUID = Guid;
dto.DeleteFlag = 1;
string Url = "api/service/T_Service_Apoplexy_FAHBase/LogicDelete";
list.Add(dto);
//初始化两个工厂
ClientFactory httpClient = new HttpClientFactory();
Client client = httpClient.VisitFactory();
//访问
ListEntity t = client.Post(Url, list);
if (t.Success)
{
JObject jo = (JObject)JsonConvert.DeserializeObject(t.DataString);
string msg = jo["Msg"].ToString();
if (!string.IsNullOrEmpty(msg))
{
XtraMessageBox.Show(msg);
FillGridListCtrlQuery(curPage);
}
}
else
{
MessageBox.Show("删除失败");
}
}
else
{
return;
}
}
}
}
}