StableVersion4.3/HL_FristAidPlatform_Apoplexy/Screen/UserControl/UC_LifeStyle.cs

187 lines
6.8 KiB
C#

using DevExpress.XtraEditors;
using HL_FristAidPlatform_DTO;
using HL_FristAidPlatform_Public;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HL_FristAidPlatform_Apoplexy
{
public partial class UC_LifeStyle : UserControl
{
public string patientGuid;
public string flag;
public UC_LifeStyle(string _patientGuid, string _flag)
{
InitializeComponent();
patientGuid = _patientGuid;
flag = _flag;
}
private void UC_LifeStyle_Load(object sender, EventArgs e)
{
GetScreenLifeStyle();
}
/// <summary>
/// 获取生活方式
/// </summary>
public void GetScreenLifeStyle()
{
ScreenLifeStyleDTO dto = new ScreenLifeStyleDTO();
string url = string.Format("api/service/T_Service_ApoplexyScreen/GetScreenLifeStyle?patientGuid={0}&flag={1}", patientGuid, flag);
dto = DBHelpClass.GetDateModel<ScreenLifeStyleDTO>(url);
if (dto != null)
{
txt_LifeStyleScreener.Text = dto.Screener;
radio_IsSmoke.EditValue = dto.IsSmoke;
if (dto.IsSmoke == "1")
{
radio_SmokingStatus.EditValue = dto.SmokingStatus;
if (dto.SmokingStatus == "1")
{
txt_SmokeYears.Text = dto.SmokeYears;
txt_Quantity.Text = dto.Quantity;
}
if (dto.SmokingStatus == "2")
{
txt_QuitSmokingYears.Text = dto.QuitSmokingYears;
txt_SmokerLength.Text = dto.SmokerLength;
}
}
radio_Drink.EditValue = dto.Drink;
radio_ExerciseHabits.EditValue = dto.ExerciseHabits;
radio_Taste.EditValue = dto.Taste;
radio_Omnivorous.EditValue = dto.Omnivorous;
radio_Vegetable.EditValue = dto.Vegetable;
radio_Fruit.EditValue = dto.Fruit;
}
}
/// <summary>
/// 保存生活方式
/// </summary>
public void SaveScreenLifeStyle()
{
try
{
ScreenLifeStyleDTO dto = new ScreenLifeStyleDTO();
List<ScreenLifeStyleDTO> list = new List<ScreenLifeStyleDTO>();
dto.Flag = flag;
dto.PatientGUID = patientGuid;
dto.Screener = txt_LifeStyleScreener.Text;
dto.IsSmoke = GetEditValue(radio_IsSmoke);
if (dto.IsSmoke == "1")
{
dto.SmokingStatus = GetEditValue(radio_SmokingStatus);
if (dto.SmokingStatus == "1")
{
dto.SmokeYears = txt_SmokeYears.Text;
dto.Quantity = txt_Quantity.Text;
}
if (dto.SmokingStatus == "2")
{
dto.QuitSmokingYears = txt_QuitSmokingYears.Text;
dto.SmokerLength = txt_SmokerLength.Text;
}
}
dto.Drink = GetEditValue(radio_Drink);
dto.ExerciseHabits = GetEditValue(radio_ExerciseHabits);
dto.Taste = GetEditValue(radio_Taste);
dto.Omnivorous = GetEditValue(radio_Omnivorous);
dto.Vegetable = GetEditValue(radio_Vegetable);
dto.Fruit = GetEditValue(radio_Fruit);
dto.CreateID = Information.User.ID;
list.Add(dto);
string Url = "api/service/T_Service_ApoplexyScreen/SaveScreenLifeStyle";
//初始化两个工厂
ClientFactory<ScreenLifeStyleDTO> httpClient = new HttpClientFactory<ScreenLifeStyleDTO>();
Client<ScreenLifeStyleDTO> client = httpClient.VisitFactory();
//访问
ListEntity<ScreenLifeStyleDTO> t = client.Post(Url, list);
if (t.Success)
{
if (!string.IsNullOrEmpty(t.DataString))
{
if (t.DataString.Contains("Success"))
{
JObject jo = (JObject)JsonConvert.DeserializeObject(t.DataString);
string msg = jo["Msg"].ToString();
if (!string.IsNullOrEmpty(msg))
{
XtraMessageBox.Show(msg);
GetScreenLifeStyle();
}
}
else
{
string msg1 = t.DataString.Replace("/", "").Replace(@"\", "").Replace("\"", "");
XtraMessageBox.Show(msg1);
}
}
else
{
XtraMessageBox.Show("保存失败");
}
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取单选组件value
/// </summary>
/// <param name="radio"></param>
/// <returns></returns>
public string GetEditValue(RadioGroup radio)
{
string value = "";
if (radio.SelectedIndex > -1 && radio.EditValue.ToString() != null)
value = radio.EditValue.ToString();
return value;
}
private void radio_IsSmoke_SelectedIndexChanged(object sender, EventArgs e)
{
if (radio_IsSmoke.SelectedIndex == 0)
radio_SmokingStatus.Enabled = true;
if (radio_IsSmoke.SelectedIndex == 1)
{
radio_SmokingStatus.Enabled = false;
radio_SmokingStatus.SelectedIndex = -1;
}
}
private void radio_SmokingStatus_SelectedIndexChanged(object sender, EventArgs e)
{
if (radio_SmokingStatus.SelectedIndex == 0)
{
panel_Smoke.Visible = true;
panel_QuitSmoking.Visible = false;
}
if (radio_SmokingStatus.SelectedIndex == 1)
{
panel_Smoke.Visible = false;
panel_QuitSmoking.Visible = true;
}
if (radio_SmokingStatus.SelectedIndex == -1)
{
panel_Smoke.Visible = false;
panel_QuitSmoking.Visible = false;
}
}
}
}