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.Data; using System.Text.RegularExpressions; using System.Windows.Forms; namespace HL_FristAidPlatform_EmergencyTriage { public partial class Form_PatientInfo : XtraForm { /// /// 民族 /// private DataTable NationDT; private string _guid; private string fpGuid; public Form_PatientInfo(string guid) { InitializeComponent(); _guid = guid; ; } private void Form_PatientInfo_Load(object sender, EventArgs e) { //职业 PublicClass.SetLookUpList(lookUpEdit_Profession, Enumerate.PublicDictionaryType.职业, true, "请选择"); BindGender(); BindPathogeny(); BindNation(); QueryInfo(_guid); } public void QueryInfo(string guid) { string url = string.Format("/api/service/T_Service_Patient/GetPatients?guid={0}", _guid); DataTable dt = DBHelpClass.GetDataRow(url); if (dt != null) { if (dt.Rows.Count > 0) { fpGuid = dt.Rows[0]["FPGUID"].ToString(); txt_Name.Text = dt.Rows[0]["Name"].ToString(); radioGroup_Gender.EditValue = dt.Rows[0]["Gender"].ToString(); txt_Age.Text = dt.Rows[0]["Age"].ToString(); lookUpEdit_Nation.EditValue = dt.Rows[0]["Nation"].ToString(); txt_Phone.Text = dt.Rows[0]["MobilePhone"].ToString(); lookUpEdit_Pathogeny.EditValue = dt.Rows[0]["PathogenyGUID"].ToString(); txt_IDNumber.Text = dt.Rows[0]["IdentityCard"].ToString(); txt_Address.Text = dt.Rows[0]["Address"].ToString(); txt_Attack_Address.Text = dt.Rows[0]["Attack_Address"].ToString(); dateEdit_Birthday.TimeValue = dt.Rows[0]["Birthday"].ToString(); lookUpEdit_Profession.EditValue = dt.Rows[0]["Profession"].ToString(); txt_EmergencyContact.Text = dt.Rows[0]["EmergencyContact"].ToString(); txt_EmergencyContactPhone.Text = dt.Rows[0]["EmergencyContactPhone"].ToString(); lookUpEdit_Pathogeny.Text = dt.Rows[0]["PathogenyGUID"].ToString(); txt_DisposalRecord.Text = dt.Rows[0]["DisposalRecord"].ToString(); dateEdit_Attack_Time.TimeValue = dt.Rows[0]["Attack_Time"].ToString(); ckb_Category.Checked = dt.Rows[0]["Category"].ToString() == "1" ? true : false; } } } /// /// 绑定民族 /// private void BindNation() { try { NationDT = DBHelpClass.Get("/api/base/T_Base_Nation/GetList"); PublicClass.SetLookUpList(ref lookUpEdit_Nation, NationDT, 8, 2, true, "请选择"); } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定民族:\r\n" + ex); } } /// /// 绑定性别 /// private void BindGender() { try { DataTable GenderDT = DBHelpClass.Get("/api/base/T_Base_Gender/GetList"); PublicClass.BindRadioGroupData(radioGroup_Gender, GenderDT, "GenderName", "GenderCode"); radioGroup_Gender.EditValue = "0"; } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定性别:\r\n" + ex); } } /// /// 绑定病因 /// private void BindPathogeny() { try { DataTable dt = DBHelpClass.Get("/api/base/T_Base_Pathogeny/GetList"); PublicClass.SetLookUpList(ref lookUpEdit_Pathogeny, dt, 1, 2, true, "请选择"); } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定民族:\r\n" + ex); } } public List SavePatientInfo() { try { List dtLst = new List(); UpdateFirstAidPatientsDTO dto = new UpdateFirstAidPatientsDTO(); List list = new List(); dto.PatientGUID = _guid; dto.FPGUID = fpGuid; dto.Name = txt_Name.Text; dto.Gender = int.Parse(radioGroup_Gender.EditValue.ToString()); dto.Age = int.Parse(txt_Age.Text); dto.Nation = lookUpEdit_Nation.EditValue.ToString(); dto.IdentityCard = txt_IDNumber.Text; dto.MobilePhone = txt_Phone.Text; dto.EmergencyContact = txt_EmergencyContact.Text; dto.EmergencyContactPhone = txt_EmergencyContactPhone.Text; dto.Address = txt_Address.Text; dto.Attack_Address = txt_Attack_Address.Text; dto.Profession = lookUpEdit_Profession.EditValue.ToString(); dto.Birthday = dateEdit_Birthday.TimeValue.ToString(); dto.PathogenyGUID = lookUpEdit_Pathogeny.EditValue.ToString(); dto.DisposalRecord = txt_DisposalRecord.Text; dto.Attack_Time = dateEdit_Attack_Time.TimeValue.ToString(); dto.Category = ckb_Category.Checked == true ? 1 : 0; list.Add(dto); string Url = string.Empty; Url = "api/service/T_Service_Patient/UpdateFirstAidPatientsInfo"; //初始化两个工厂 ClientFactory httpClient = new HttpClientFactory(); Client client = httpClient.VisitFactory(); ListEntity 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); } dtLst.Add(txt_Name.Text); dtLst.Add(txt_Age.Text); dtLst.Add(radioGroup_Gender.EditValue.ToString()); } else { string msg1 = t.DataString.Replace("/", "").Replace(@"\", "").Replace("\"", ""); XtraMessageBox.Show(msg1); } } else { XtraMessageBox.Show("保存失败"); } } else { XtraMessageBox.Show("保存失败"); } return dtLst; } catch (Exception) { throw; } } private void simpleButton1_Click(object sender, EventArgs e) { UpdateFirstAidPatientsDTO dto = new UpdateFirstAidPatientsDTO(); List list = new List(); dto.PatientGUID = _guid; dto.FPGUID = fpGuid; dto.Name = txt_Name.Text; dto.Gender = int.Parse(radioGroup_Gender.EditValue.ToString()); dto.Age = int.Parse(txt_Age.Text); dto.Nation = lookUpEdit_Nation.EditValue.ToString(); dto.IdentityCard = txt_IDNumber.Text; dto.MobilePhone = txt_Phone.Text; dto.EmergencyContact = txt_EmergencyContact.Text; dto.EmergencyContactPhone = txt_EmergencyContactPhone.Text; dto.Address = txt_Address.Text; dto.Attack_Address = txt_Attack_Address.Text; dto.Profession = lookUpEdit_Profession.EditValue.ToString(); dto.Birthday = dateEdit_Birthday.TimeValue.ToString(); dto.PathogenyGUID = lookUpEdit_Pathogeny.EditValue.ToString(); dto.DisposalRecord = txt_DisposalRecord.Text; dto.Attack_Time = dateEdit_Attack_Time.TimeValue.ToString(); dto.Category = ckb_Category.Checked == true ? 1 : 0; list.Add(dto); string Url = string.Empty; Url = "api/service/T_Service_Patient/UpdateFirstAidPatientsInfo"; //初始化两个工厂 ClientFactory httpClient = new HttpClientFactory(); Client client = httpClient.VisitFactory(); if (client.Post(Url, list).Success) { XtraMessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } private void dateEdit_Birthday_TimeValueChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(dateEdit_Birthday.TimeValue)) { DateTime dateTime = Convert.ToDateTime(dateEdit_Birthday.TimeValue); int ageUnit = 1; txt_Age.Text = PublicClass.GetAge(dateTime, DateTime.Now, out ageUnit).ToString(); } } private void ckb_Category_CheckedChanged(object sender, EventArgs e) { try { if (ckb_Category.Checked) { txt_Name.ReadOnly = true; txt_Age.ReadOnly = true; radioGroup_Gender.ReadOnly = true; txt_Name.Text = PublicClassForDataBase.CreateCategoryName(); txt_Age.Text = "0"; } else { txt_Name.ReadOnly = false; txt_Age.ReadOnly = false; radioGroup_Gender.ReadOnly = false; txt_Name.Text = ""; txt_Age.Text = ""; } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "是否三无人员:\r\n" + ex); } } private void txt_IDNumber_EditValueChanged(object sender, EventArgs e) { string resulst = txt_IDNumber.Text.ToString().Trim(); try { #region 18位 if (resulst.Length == 18) { long n = 0; if (long.TryParse(resulst.Remove(17), out n) == false || n < Math.Pow(10, 16) || long.TryParse(resulst.Replace('x', '0').Replace('X', '0'), out n) == false) { txt_IDNumber.Visible = true; } string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91"; if (address.IndexOf(resulst.Remove(2)) == -1) { txt_IDNumber.Visible = true; } string birth = resulst.Substring(6, 8).Insert(6, "-").Insert(4, "-"); DateTime time = new DateTime(); if (DateTime.TryParse(birth, out time) == false) { txt_IDNumber.Visible = true; } string brithdaystr = resulst.Substring(6, 8); dateEdit_Birthday.TimeValue = DateTime.Parse(string.Format("{0}-{1}-{2}", string.Format("{0}", brithdaystr.Substring(0, 4)), brithdaystr.Substring(4, 2), brithdaystr.Substring(6, 2))).ToString(); //性别 int sex = Convert.ToInt32(resulst.Substring(resulst.Length - 2, 1)); if (sex % 2 == 0) radioGroup_Gender.EditValue = "2"; else if (sex % 2 == 1) radioGroup_Gender.EditValue = "1"; else radioGroup_Gender.EditValue = "0"; radioGroup_Gender.Enabled = false; txt_Age.Enabled = false; dateEdit_Birthday.Enabled = false; } else { radioGroup_Gender.Enabled = true; txt_Age.Enabled = true; dateEdit_Birthday.Enabled = true; } #endregion if (Regex.IsMatch(resulst, @"[\u4e00-\u9fa5]")) { radioGroup_Gender.Enabled = true; txt_Age.Enabled = true; dateEdit_Birthday.Enabled = true; MessageBox.Show("身份证格式错误,不能包含中文字符"); } } catch { radioGroup_Gender.Enabled = true; txt_Age.Enabled = true; dateEdit_Birthday.Enabled = true; MessageBox.Show("身份证格式错误,加载失败。"); } } } }