using ivf_tl_Entity.DTO; using ivf_tl_Entity.GlobalEntitys; using ivf_tl_Entity.GlobalEnums; using ivf_tl_Operate.Converts; using ivf_tl_Operate.Windows; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; namespace ivf_tl_Operate.View { /// /// AddDishWindowView.xaml 的交互逻辑 /// public partial class AddDishWindowView : Window { private double centerX, centerY; private int Count = 16; private double angle; private double angleOffset = 90; private double imageBigRadius = 450; private double imageRadius = 80; private double textBigRadius = 300; int ellipseCount = 16; List BorderList = new List(); private string tlsn; private int housesn; private bool isBalacne = false; private long balanceId = 0; private ExDish ExDish = null; /// /// 新建患者 /// /// /// /// /// public AddDishWindowView(int housesn, bool isBalacne, long balanceId) { InitializeComponent(); this.Owner = AppData.Instance.MainWindow; this.isBalacne = isBalacne; this.balanceId = balanceId; this.TextBlock_HouseSn.Text = housesn.ToString(); if (isBalacne) { //this._balance_Button.Content = "结束平衡"; this._balance_Button.Content = KeyToStringConvert.GetLanguageStringByKey("C0029"); } this.tlsn = AppData.Instance.TlSn; this.housesn = housesn; //this.numbertext.Text = $"新建患者信息"; this.numbertext.Text = KeyToStringConvert.GetLanguageStringByKey("C0262"); centerX = 1422 / 2.0; centerY = 1229 / 2.0; angle = 360.00 / 16; int curreYeat = DateTime.Now.Year; for (int i = 1963; i <= curreYeat; i++) YearsList.Add(i); for (int i = 1; i <= 12; i++) MonthList.Add(i); for (int i = 1; i <= 31; i++) DayList.Add(i); this._wifeYear.ItemsSource = YearsList; this._wifeMonth.ItemsSource = MonthList; this._wifeDay.ItemsSource = DayList; this._husbandYear.ItemsSource = YearsList; this._husbandMonth.ItemsSource = MonthList; this._husbandDay.ItemsSource = DayList; this._freType_ComboBox.ItemsSource = AppData.Instance.FertilizationTypeEntitieList; InitAddCustom(); Closed += (a, b) => AppData.Instance.MainWindow.Activate(); } /// /// 修改患者 /// /// /// public AddDishWindowView(ExDish exDish, List datas) { InitializeComponent(); this.Owner = AppData.Instance.MainWindow; ExDish = exDish; this.TextBlock_HouseSn.Text = ExDish.houseSn.ToString(); //this.numbertext.Text = $"编辑患者信息"; this.numbertext.Text = KeyToStringConvert.GetLanguageStringByKey("C0263"); centerX = 1422 / 2.0; centerY = 1229 / 2.0; angle = 360.00 / 16; int curreYeat = DateTime.Now.Year; for (int i = 1963; i <= curreYeat; i++) YearsList.Add(i); for (int i = 1; i <= 12; i++) MonthList.Add(i); for (int i = 1; i <= 31; i++) DayList.Add(i); this._wifeYear.ItemsSource = YearsList; this._wifeMonth.ItemsSource = MonthList; this._wifeDay.ItemsSource = DayList; this._husbandYear.ItemsSource = YearsList; this._husbandMonth.ItemsSource = MonthList; this._husbandDay.ItemsSource = DayList; this._freType_ComboBox.ItemsSource = AppData.Instance.FertilizationTypeEntitieList; InitEditCustom(datas); Closed += (a, b) => AppData.Instance.MainWindow.Activate(); } List YearsList = new List(); List MonthList = new List(); List DayList = new List(); private void InitAddCustom() { this._addDishButton.Visibility = Visibility.Visible; for (int i = 0; i < ellipseCount; i++) { TextBlock borderT = new TextBlock(); Panel.SetZIndex(borderT, 7); this._canvas.Children.Add(borderT); borderT.Height = 28; borderT.Width = 35; borderT.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - borderT.Width / 2); borderT.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - borderT.Height / 2); borderT.Text = $"{i + 1}"; borderT.TextAlignment = TextAlignment.Center; borderT.FontSize = 27; borderT.Foreground = new SolidColorBrush(Colors.Gray); Border border = new Border(); this._canvas.Children.Add(border); BorderList.Add(border); border.Name = $"B{i + 1}"; border.CornerRadius = new CornerRadius(imageRadius); border.Background = new SolidColorBrush(Colors.Red); Panel.SetZIndex(border, 9); border.Tag = false; border.Width = imageRadius * 2; border.Height = imageRadius * 2; border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - border.Width / 2); border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - border.Height / 2); border.SetValue(Panel.ZIndexProperty, 9); border.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/ellipse_backgroud.png", UriKind.RelativeOrAbsolute))); border.MouseUp += (s, e) => { if (!(s is Border so)) return; var newTag = !(bool)so.Tag; if (newTag) { so.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/photo_embryo.png", UriKind.RelativeOrAbsolute))); } else { so.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/ellipse_backgroud.png", UriKind.RelativeOrAbsolute))); } so.Tag = newTag; }; } if (this._freType_ComboBox.HasItems) { this._freType_ComboBox.SelectedIndex = 0; } } private void InitEditCustom(List datas) { this._editDishButton.Visibility = Visibility.Visible; this._caseId_TextBox.IsEnabled = false; this._freType_ComboBox.IsEnabled = false; this._Border_TextBox.IsEnabled = false; this._cycle_TextBox.IsEnabled = false; this._Border_TextBox.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E4E4E4")); this._Border_TextBox.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#D1D1D1")); this._startTime_TextBox.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#A4A4A4")); this._caseId_TextBox.Text = ExDish.caseId; this._wife_TextBox.Text = ExDish.wife; this._cycle_TextBox.Text = ExDish.cycle; this._isVip.IsChecked = ExDish.vip == 1 ? true : false; if (DateTime.TryParse(ExDish.wifeBirth, out DateTime wifeTime)) { this._wifeYear.SelectedItem = wifeTime.Year; this._wifeMonth.SelectedItem = wifeTime.Month; this._wifeDay.SelectedItem = wifeTime.Day; } this._husband_TextBox.Text = ExDish.husband; if (DateTime.TryParse(ExDish.husbandBirth, out DateTime husTime)) { this._husbandYear.SelectedItem = husTime.Year; this._husbandMonth.SelectedItem = husTime.Month; this._husbandDay.SelectedItem = husTime.Day; } this._startTime_TextBox.Text = ExDish.startTime; int k = -1; for (int i = 0; i < AppData.Instance.FertilizationTypeEntitieList.Count; i++) { if (AppData.Instance.FertilizationTypeEntitieList[i].dictKey == ExDish.fertilizationType) { k = i; break; } } if (k != -1) this._freType_ComboBox.SelectedIndex = k; ExEmbryo exEmbryo = null; for (int i = 0; i < ellipseCount; i++) { exEmbryo = ExDish.embryoList.FirstOrDefault(x => x.wellSn == (i + 1)); TextBlock borderT = new TextBlock(); Panel.SetZIndex(borderT, 7); this._canvas.Children.Add(borderT); borderT.Height = 28; borderT.Width = 35; borderT.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - borderT.Width / 2); borderT.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - borderT.Height / 2); borderT.Text = $"{i + 1}"; borderT.TextAlignment = TextAlignment.Center; borderT.FontSize = 27; borderT.Foreground = new SolidColorBrush(Colors.Gray); Border border = new Border(); this._canvas.Children.Add(border); BorderList.Add(border); border.Name = $"B{i + 1}"; border.CornerRadius = new CornerRadius(imageRadius); border.Background = new SolidColorBrush(Colors.Red); Panel.SetZIndex(border, 9); border.Tag = false; border.Width = imageRadius * 2; border.Height = imageRadius * 2; border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - border.Width / 2); border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - border.Height / 2); border.SetValue(Panel.ZIndexProperty, 9); border.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/ellipse_backgroud.png", UriKind.RelativeOrAbsolute))); if (exEmbryo == null) { border.MouseUp += (s, e) => { if (!(s is Border so)) return; var newTag = !(bool)so.Tag; if (newTag) { so.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/photo_embryo.png", UriKind.RelativeOrAbsolute))); } else { so.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/ellipse_backgroud.png", UriKind.RelativeOrAbsolute))); } so.Tag = newTag; }; } else { border.Tag = true; var currentData = datas.FirstOrDefault(x => x.wellSn == exEmbryo.wellSn); if (currentData != null && !string.IsNullOrEmpty(currentData.lastPicture)) { string imageurl = $"{AppData.Instance.BaseUrl}{currentData.lastPicture.Replace(AppData.Instance.PicSuf, $"_160x160{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpHelper.GetToken()}"; border.Background = new ImageBrush(AppData.Instance.ConvertHelper.StringToBitmapImage(imageurl)); } else { border.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/photo_embryo.png", UriKind.RelativeOrAbsolute))); } } } } /// /// 修改培养 /// /// /// private void EditDishSave_Click(object sender, RoutedEventArgs e) { try { List wellList = new List(); foreach (var item in BorderList) { if ((bool)item.Tag == true) { string borderName = item.Name; string number = borderName.Substring(1); if (int.TryParse(number, out int result)) { wellList.Add(result); } } } string caseIdString = this._caseId_TextBox.Text.Trim(); if (string.IsNullOrEmpty(caseIdString)) { //MessageInfo("请输入病例编号"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0148")); return; } string cycleIdString = this._cycle_TextBox.Text.Trim(); if (string.IsNullOrEmpty(cycleIdString)) { //MessageInfo("请输入周期编号"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0316")); return; } string wifeString = this._wife_TextBox.Text.Trim(); if (string.IsNullOrEmpty(wifeString)) { //MessageInfo("请输入女方姓名"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0149")); return; } //if (wifeString.Length > 100) //{ // MessageInfo("女方姓名字符长度为1-100"); // return; //} string wifeBirthString = this._wifeAge.Text.Trim(); if (string.IsNullOrEmpty(wifeBirthString)) { wifeBirthString = null; //MessageInfo("请输入女方年龄"); //return; } else { if (DateTime.TryParse($"{this._wifeYear.SelectedItem}-{this._wifeMonth.SelectedItem}-{this._wifeDay.SelectedItem}", out DateTime wifeTime)) wifeBirthString = wifeTime.ToString("yyyy-MM-dd HH:mm:ss"); else { MessageInfo("女方年龄错误"); return; } } string husbandString = this._husband_TextBox.Text.Trim(); if (string.IsNullOrEmpty(husbandString)) { //MessageInfo("请输入男方姓名"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0150")); return; } //if (husbandString.Length > 100) //{ // MessageInfo("男方姓名字符长度为1-100"); // return; //} string husbandBirthString = this._husbandAge.Text.Trim(); if (string.IsNullOrEmpty(husbandBirthString)) { husbandBirthString = null; //MessageInfo("请输入男方年龄"); //return; } else { if (DateTime.TryParse($"{this._husbandYear.SelectedItem}-{this._husbandMonth.SelectedItem}-{(int)this._husbandDay.SelectedItem}", out DateTime husTime)) husbandBirthString = husTime.ToString("yyyy-MM-dd HH:mm:ss"); else { MessageInfo("男方年龄错误"); return; } } //ExDish.caseId = caseIdString; ExDish.wife = wifeString; ExDish.wifeBirth = wifeBirthString; ExDish.husbandBirth = husbandBirthString; ExDish.husband = husbandString; ExDish.vip = this._isVip.IsChecked == true ? 1 : 0; ExDish.embryoCount = wellList.Count; ExDish.cycle = cycleIdString; string body = JsonConvert.SerializeObject(new { embryoCount = ExDish.embryoCount, husband = ExDish.husband, husbandBirth = ExDish.husbandBirth, id = ExDish.id, vip = ExDish.vip, wellSn = wellList, wife = ExDish.wife, wifeBirth = ExDish.wifeBirth, cycle = ExDish.cycle, }); if (!AppData.Instance.HttpHelper.UpdateDishInfoApi(body)) { //MessageInfo("修改信息失败"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0243")); } else { this.DialogResult = true; } } catch (Exception ex) { AppData.Instance.LogHelper.ExceptionLog(ex, "AddDishWindowView.EditDishSave_Click", LogEnum.RunException); } } /// /// 开始培养 /// /// /// private void StartDish_Click(object sender, RoutedEventArgs e) { try { List wellList = new List(); foreach (var item in BorderList) { if ((bool)item.Tag == true) { string borderName = item.Name; string number = borderName.Substring(1); if (int.TryParse(number, out int result)) wellList.Add(result); } } if (!wellList.Any()) { //MessageInfo("请选择胚胎孔位"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0317")); return; } string caseIdString = this._caseId_TextBox.Text.Trim(); if (string.IsNullOrEmpty(caseIdString)) { //MessageInfo("请输入病例编号"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0148")); return; } string cycleIdString = this._cycle_TextBox.Text.Trim(); if (string.IsNullOrEmpty(cycleIdString)) { //MessageInfo("请输入周期编号"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0316")); return; } string wifeString = this._wife_TextBox.Text.Trim(); if (string.IsNullOrEmpty(wifeString)) { //MessageInfo("请输入女方姓名"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0149")); return; } //if (wifeString.Length > 100) //{ // MessageInfo("女方姓名字符长度为1-100"); // return; //} string wifeBirthString = this._wifeAge.Text.Trim(); if (string.IsNullOrEmpty(wifeBirthString)) { wifeBirthString = null; //MessageInfo("请输入女方年龄"); //return; } else { if (DateTime.TryParse($"{this._wifeYear.SelectedItem}-{this._wifeMonth.SelectedItem}-{this._wifeDay.SelectedItem}", out DateTime wifeTime)) wifeBirthString = wifeTime.ToString("yyyy-MM-dd HH:mm:ss"); else { MessageInfo("女方年龄错误"); return; } } string husbandString = this._husband_TextBox.Text.Trim(); if (string.IsNullOrEmpty(husbandString)) { //MessageInfo("请输入男方姓名"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0150")); return; } //if (husbandString.Length > 100) //{ // MessageInfo("男方姓名字符长度为1-100"); // return; //} string husbandBirthString = this._husbandAge.Text.Trim(); if (string.IsNullOrEmpty(husbandBirthString)) { husbandBirthString = null; //MessageInfo("请输入男方年龄"); //return; } else { if (DateTime.TryParse($"{this._husbandYear.SelectedItem}-{this._husbandMonth.SelectedItem}-{(int)this._husbandDay.SelectedItem}", out DateTime husTime)) husbandBirthString = husTime.ToString("yyyy-MM-dd HH:mm:ss"); else { MessageInfo("男方年龄错误"); return; } } string startTimeString = this._startTime_TextBox.Text.Trim(); if (string.IsNullOrEmpty(startTimeString)) { //MessageInfo("请输入受精时间"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0154")); return; } if (DateTime.TryParse(startTimeString, out DateTime result1)) { if (result1 > DateTime.Now) { //MessageInfo("受精时间不能超过当前时间"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0264")); return; } } else { //MessageInfo("受精时间输入错误"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0154")); return; } //string cycleString = this._cycle_TextBox.Text.Trim(); //string phoneString = this._phone_TextBox.Text.Trim(); //if (string.IsNullOrEmpty(phoneString)) //{ // MessageInfo("请输入联系方式"); // return; //} //if (!Regex.IsMatch(phoneString, @"^1[3456789]\d{9}$")) //{ // MessageInfo("联系方式输入错误"); // return; //} ExDish exDish = new ExDish(); exDish.tlSn = tlsn; exDish.houseSn = housesn; exDish.caseId = caseIdString; exDish.wife = wifeString; exDish.cycle = cycleIdString; exDish.wifeBirth = wifeBirthString; exDish.husbandBirth = husbandBirthString; exDish.husband = husbandString; exDish.vip = this._isVip.IsChecked == true ? 1 : 0; exDish.embryoCount = wellList.Count; exDish.startTime = startTimeString; if (this._freType_ComboBox.SelectedItem is FertilizationTypeEntity typeEntity) { exDish.fertilizationType = typeEntity.dictKey; exDish.fertilizationTypeId = int.Parse(typeEntity.dictValue); } //exDish.phone = phoneString; exDish.embryoCount = wellList.Count; exDish.wellSn = wellList; string error = AppData.Instance.HttpHelper.AddCultureRecordApi(exDish); if (!string.IsNullOrEmpty(error)) { //MessageInfo($"开始培养失败:{error}"); MessageInfo($"{KeyToStringConvert.GetLanguageStringByKey("C0265")}:{error}"); } else { this.DialogResult = true; } } catch (Exception ex) { AppData.Instance.LogHelper.ExceptionLog(ex, "AddDishWindowView.StartDish_Click", LogEnum.RunException); } e.Handled = true; } /// /// 平衡操作 /// /// /// private void StartBalance_Click(object sender, RoutedEventArgs e) { //Debug.WriteLine("平衡按钮"); if (isBalacne)//结束平衡 { if (balanceId == 0) { //MessageInfo("获取平衡记录失败"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0266")); return; } if (AppData.Instance.HttpHelper.StopBalanceApi(balanceId)) { this.DialogResult = true; } else { //MessageInfo("结束平衡失败"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0267")); } } else//开始平衡 { if (AppData.Instance.HttpHelper.StartBalanceApi(housesn, tlsn)) { this.DialogResult = true; } else { //MessageInfo("开始平衡失败"); MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0268")); } } } private void Cancel_Click(object sender, RoutedEventArgs e) { this.DialogResult = false; } private void Cancel_MouseUp(object sender, MouseButtonEventArgs e) { //MessageBox.Show("点击×"); //int is1 = 1 + 1; //Debug.WriteLine("=============================================================="); this.DialogResult = false; } private string GetDataTime() { try { this._mask.Visibility = Visibility.Visible; GetDateWindow getDate = new GetDateWindow(this); getDate._dateControl.SetNYR(false); getDate.isClos = false; var result = getDate.ShowDialog(); if (result.Value == true) { return $"{getDate.Date}:00"; } return null; } catch (Exception ex) { return null; } finally { this._mask.Visibility = Visibility.Hidden; } } private void StartTime_MouseUp(object sender, MouseButtonEventArgs e) { string newTime = GetDataTime(); if (string.IsNullOrEmpty(newTime)) { return; } this._startTime_TextBox.Text = newTime; this._startTime_TextBox.Foreground = new SolidColorBrush(Colors.Black); } private void WifeBirth_MouseUp(object sender, MouseButtonEventArgs e) { string newTime = GetDataTime(); if (string.IsNullOrEmpty(newTime)) { return; } //this._wifeBirth_TextBox.Text = newTime; } private void HusbandBirth_MouseUp(object sender, MouseButtonEventArgs e) { string newTime = GetDataTime(); if (string.IsNullOrEmpty(newTime)) { return; } //this._husbandBirth_TextBox.Text = newTime; } private void Wifi_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this._wifeYear.SelectedItem != null && this._wifeMonth.SelectedItem != null && this._wifeDay.SelectedItem != null) { int CurrentYear = (int)this._wifeYear.SelectedItem; int CurrentMonth = (int)this._wifeMonth.SelectedItem; int CurrentDay = (int)this._wifeDay.SelectedItem; int age = DateTime.Now.Year - CurrentYear; if (DateTime.Now.Month < CurrentMonth || (DateTime.Now.Month == CurrentMonth && DateTime.Now.Day < CurrentDay)) age--; this._wifeAge.Text = age.ToString(); } } private void HusBand_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this._husbandYear.SelectedItem != null && this._husbandMonth.SelectedItem != null && this._husbandDay.SelectedItem != null) { int CurrentYear = (int)this._husbandYear.SelectedItem; int CurrentMonth = (int)this._husbandMonth.SelectedItem; int CurrentDay = (int)this._husbandDay.SelectedItem; int age = DateTime.Now.Year - CurrentYear; if (DateTime.Now.Month < CurrentMonth || (DateTime.Now.Month == CurrentMonth && DateTime.Now.Day < CurrentDay)) age--; this._husbandAge.Text = age.ToString(); } } private void Border_MouseUp(object sender, MouseButtonEventArgs e) { //MessageBox.Show("点击生效"); int kk = 1 + 1; } private void Grid_PreviewTouchDown(object sender, TouchEventArgs e) { //Debug.WriteLine("===================ImageTouchDown==========================================="); } private void MessageInfo(string mess) { this._errorInfo_TextBlock.Text = mess; } } }