123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using WpfTest1.SQLite;
- namespace WpfTest1
- {
- /// <summary>
- /// TreatmentPlanPage.xaml 的交互逻辑
- /// </summary>
- public partial class TreatmentPlanPage : UserControl
- {
- MainWindow father;
- public List<Treatment> treatmentList;
- private Treatment target = null;
- public TreatmentPlanPage()
- {
- InitializeComponent();
- loadDataGrid();
- }
- public TreatmentPlanPage(MainWindow father)
- {
- this.father = father;
- InitializeComponent();
- loadDataGrid();
- }
-
- public void setMainWindow(MainWindow father)
- {
- this.father = father;
- }
- public void loadDataGrid()
- {
- treatmentList = SQLiteModel.getALLTreatment();
- dataGrid.ItemsSource = treatmentList;
- target = null;
- }
- private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- target = (Treatment)dataGrid.CurrentItem;
- if (target != null)
- {
- textBoxDisease.Text = target.disease;
- textBoxBodyParts.Text = target.bodyParts;
- textBoxRate1.Text = target.rate1.ToString();
- textBoxRate2.Text = target.rate2.ToString();
- textBoxRate3.Text = target.rate3.ToString();
- textBoxRate4.Text = target.rate4.ToString();
- textBoxRate5.Text = target.rate5.ToString();
- textBoxRate6.Text = target.rate6.ToString();
- textBoxRate7.Text = target.rate7.ToString();
- textBoxRate8.Text = target.rate8.ToString();
- textBoxRate9.Text = target.rate9.ToString();
- textBoxRate10.Text = target.rate10.ToString();
- textBoxNum1.Text = target.num1.ToString();
- textBoxNum2.Text = target.num2.ToString();
- textBoxNum3.Text = target.num3.ToString();
- textBoxNum4.Text = target.num4.ToString();
- textBoxNum5.Text = target.num5.ToString();
- textBoxNum6.Text = target.num6.ToString();
- textBoxNum7.Text = target.num7.ToString();
- textBoxNum8.Text = target.num8.ToString();
- textBoxNum9.Text = target.num9.ToString();
- textBoxNum10.Text = target.num10.ToString();
- textBoxIntervalTime.Text = target.intervalTime.ToString();
- textBoxRepeatTimes.Text = target.repeatTimes.ToString();
- textBoxTotalTime.Text = target.totalTime.ToString();
- textBoxTotalNum.Text = target.totalNum.ToString();
- } else {
- textBoxDisease.Text = "";
- textBoxBodyParts.Text = "";
- textBoxRate1.Text = "";
- textBoxRate2.Text = "";
- textBoxRate3.Text = "";
- textBoxRate4.Text = "";
- textBoxRate5.Text = "";
- textBoxRate6.Text = "";
- textBoxRate7.Text = "";
- textBoxRate8.Text = "";
- textBoxRate9.Text = "";
- textBoxRate10.Text = "";
- textBoxNum1.Text = "";
- textBoxNum2.Text = "";
- textBoxNum3.Text = "";
- textBoxNum4.Text = "";
- textBoxNum5.Text = "";
- textBoxNum6.Text = "";
- textBoxNum7.Text = "";
- textBoxNum8.Text = "";
- textBoxNum9.Text = "";
- textBoxNum10.Text = "";
- textBoxIntervalTime.Text = "";
- textBoxRepeatTimes.Text = "";
- textBoxTotalTime.Text = "";
- textBoxTotalNum.Text = "";
- }
- }
- private void textBoxDisease_TextChanged(object sender, TextChangedEventArgs e)
- {
- checkChange();
- }
- private void textBoxBodyParts_TextChanged(object sender, TextChangedEventArgs e)
- {
- checkChange();
- }
- private void textBoxRateAll_TextChanged(object sender, TextChangedEventArgs e)
- {
- checkChange();
- }
- private void textBoxIntervalTime_TextChanged(object sender, TextChangedEventArgs e)
- {
- checkChange();
- }
- private void textBoxRepeatTimes_TextChanged(object sender, TextChangedEventArgs e)
- {
- checkChange();
- }
- private void checkChange()
- {
- if (target != null)
- {
- textBoxDisease.Background = textBoxDisease.Text == target.disease ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxBodyParts.Background = textBoxBodyParts.Text == target.bodyParts ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRate1.Background = textBoxRate1.Text == target.rate1.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRate2.Background = textBoxRate2.Text == target.rate2.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRate3.Background = textBoxRate3.Text == target.rate3.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRate4.Background = textBoxRate4.Text == target.rate4.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRate5.Background = textBoxRate5.Text == target.rate5.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRate6.Background = textBoxRate6.Text == target.rate6.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRate7.Background = textBoxRate7.Text == target.rate7.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRate8.Background = textBoxRate8.Text == target.rate8.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRate9.Background = textBoxRate9.Text == target.rate9.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRate10.Background = textBoxRate10.Text == target.rate10.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxNum1.Background = textBoxNum1.Text == target.num1.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxNum2.Background = textBoxNum2.Text == target.num2.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxNum3.Background = textBoxNum3.Text == target.num3.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxNum4.Background = textBoxNum4.Text == target.num4.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxNum5.Background = textBoxNum5.Text == target.num5.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxNum6.Background = textBoxNum6.Text == target.num6.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxNum7.Background = textBoxNum7.Text == target.num7.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxNum8.Background = textBoxNum8.Text == target.num8.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxNum9.Background = textBoxNum9.Text == target.num9.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxNum10.Background = textBoxNum10.Text == target.num10.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxIntervalTime.Background = textBoxIntervalTime.Text == target.intervalTime.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- textBoxRepeatTimes.Background = textBoxRepeatTimes.Text == target.repeatTimes.ToString() ? Brushes.White : (Brush)new BrushConverter().ConvertFrom("#FFC2FFB0");
- checkError();
- } else {
- textBoxDisease.Background = Brushes.White;
- textBoxBodyParts.Background = Brushes.White;
- textBoxRate1.Background = Brushes.White;
- textBoxRate2.Background = Brushes.White;
- textBoxRate3.Background = Brushes.White;
- textBoxRate4.Background = Brushes.White;
- textBoxRate5.Background = Brushes.White;
- textBoxRate6.Background = Brushes.White;
- textBoxRate7.Background = Brushes.White;
- textBoxRate8.Background = Brushes.White;
- textBoxRate9.Background = Brushes.White;
- textBoxRate10.Background = Brushes.White;
- textBoxNum1.Background = Brushes.White;
- textBoxNum2.Background = Brushes.White;
- textBoxNum3.Background = Brushes.White;
- textBoxNum4.Background = Brushes.White;
- textBoxNum5.Background = Brushes.White;
- textBoxNum6.Background = Brushes.White;
- textBoxNum7.Background = Brushes.White;
- textBoxNum8.Background = Brushes.White;
- textBoxNum9.Background = Brushes.White;
- textBoxNum10.Background = Brushes.White;
- textBoxIntervalTime.Background = Brushes.White;
- textBoxRepeatTimes.Background = Brushes.White;
- }
- }
- private bool checkError()
- {
- bool error = false;
- TextBox[] textBoxRateList = { textBoxRate1, textBoxRate2, textBoxRate3, textBoxRate4, textBoxRate5, textBoxRate6, textBoxRate7, textBoxRate8, textBoxRate9, textBoxRate10 };
- for (int i = 0; i < 10; i++)
- {
- double t = 0;
- if (double.TryParse(textBoxRateList[i].Text, out t))
- {
- if (t >= 0 & t < 1)
- {
- if ((t * 10 % 1).Equals(0))
- {
- continue;
- }
- }
- else if (t >= 1 & t <= 100)
- {
- if (t % 1 == 0)
- {
- continue;
- }
- }
- }
- textBoxRateList[i].Background = (Brush)new BrushConverter().ConvertFrom("#FFFFB5B5");
- error = true;
- }
- TextBox[] textBoxNumList = { textBoxNum1, textBoxNum2, textBoxNum3, textBoxNum4, textBoxNum5, textBoxNum6, textBoxNum7, textBoxNum8, textBoxNum9, textBoxNum10, textBoxIntervalTime, textBoxRepeatTimes };
- for (int i = 0; i < 12; i++)
- {
- int t = 0;
- if (int.TryParse(textBoxNumList[i].Text, out t))
- {
- if (t >= 0 & t <= 100)
- {
- if (t % 1 == 0)
- {
- continue;
- }
- }
- }
- textBoxNumList[i].Background = (Brush)new BrushConverter().ConvertFrom("#FFFFB5B5");
- error = true;
- }
- return error;
- }
- private bool isEqualsTarget()
- {
- if (target == null) return true;
- int changenum = 0;
- changenum = textBoxDisease.Text == target.disease ? changenum : changenum + 1;
- changenum = textBoxBodyParts.Text == target.bodyParts ? changenum : changenum + 1;
- changenum = textBoxRate1.Text == target.rate1.ToString() ? changenum : changenum + 1;
- changenum = textBoxRate2.Text == target.rate2.ToString() ? changenum : changenum + 1;
- changenum = textBoxRate3.Text == target.rate3.ToString() ? changenum : changenum + 1;
- changenum = textBoxRate4.Text == target.rate4.ToString() ? changenum : changenum + 1;
- changenum = textBoxRate5.Text == target.rate5.ToString() ? changenum : changenum + 1;
- changenum = textBoxRate6.Text == target.rate6.ToString() ? changenum : changenum + 1;
- changenum = textBoxRate7.Text == target.rate7.ToString() ? changenum : changenum + 1;
- changenum = textBoxRate8.Text == target.rate8.ToString() ? changenum : changenum + 1;
- changenum = textBoxRate9.Text == target.rate9.ToString() ? changenum : changenum + 1;
- changenum = textBoxRate10.Text == target.rate10.ToString() ? changenum : changenum + 1;
- changenum = textBoxNum1.Text == target.num1.ToString() ? changenum : changenum + 1;
- changenum = textBoxNum2.Text == target.num2.ToString() ? changenum : changenum + 1;
- changenum = textBoxNum3.Text == target.num3.ToString() ? changenum : changenum + 1;
- changenum = textBoxNum4.Text == target.num4.ToString() ? changenum : changenum + 1;
- changenum = textBoxNum5.Text == target.num5.ToString() ? changenum : changenum + 1;
- changenum = textBoxNum6.Text == target.num6.ToString() ? changenum : changenum + 1;
- changenum = textBoxNum7.Text == target.num7.ToString() ? changenum : changenum + 1;
- changenum = textBoxNum8.Text == target.num8.ToString() ? changenum : changenum + 1;
- changenum = textBoxNum9.Text == target.num9.ToString() ? changenum : changenum + 1;
- changenum = textBoxNum10.Text == target.num10.ToString() ? changenum : changenum + 1;
- changenum = textBoxIntervalTime.Text == target.intervalTime.ToString() ? changenum : changenum + 1;
- changenum = textBoxRepeatTimes.Text == target.repeatTimes.ToString() ? changenum : changenum + 1;
- return changenum == 0 ? true : false;
- }
- private void buttonChange_Click(object sender, RoutedEventArgs e)
- {
- if (target == null)
- {
- MessageBox.Show("请选择要修改的治疗方案!");
- return;
- }
- int id = target.id;
- string disease = textBoxDisease.Text;
- string bodyParts = textBoxBodyParts.Text;
- double.TryParse(textBoxRate1.Text, out double rate1);
- double.TryParse(textBoxRate2.Text, out double rate2);
- double.TryParse(textBoxRate3.Text, out double rate3);
- double.TryParse(textBoxRate4.Text, out double rate4);
- double.TryParse(textBoxRate5.Text, out double rate5);
- double.TryParse(textBoxRate6.Text, out double rate6);
- double.TryParse(textBoxRate7.Text, out double rate7);
- double.TryParse(textBoxRate8.Text, out double rate8);
- double.TryParse(textBoxRate9.Text, out double rate9);
- double.TryParse(textBoxRate10.Text, out double rate10);
- int.TryParse(textBoxNum1.Text, out int num1);
- int.TryParse(textBoxNum2.Text, out int num2);
- int.TryParse(textBoxNum3.Text, out int num3);
- int.TryParse(textBoxNum4.Text, out int num4);
- int.TryParse(textBoxNum5.Text, out int num5);
- int.TryParse(textBoxNum6.Text, out int num6);
- int.TryParse(textBoxNum7.Text, out int num7);
- int.TryParse(textBoxNum8.Text, out int num8);
- int.TryParse(textBoxNum9.Text, out int num9);
- int.TryParse(textBoxNum10.Text, out int num10);
- double.TryParse(textBoxIntervalTime.Text, out double intervalTime);
- int.TryParse(textBoxRepeatTimes.Text, out int repeatTimes);
- if (checkError())
- {
- MessageBox.Show("存在无效数据,请检查后再点击修改按钮!");
- return;
- }
- if (isEqualsTarget())
- {
- MessageBox.Show("未进行任何修改!");
- return;
- }
- SQLiteModel.updateTreatment(id, disease, bodyParts, rate1, rate2, rate3, rate4, rate5, rate6, rate7, rate8, rate9, rate10, num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, intervalTime, repeatTimes);
- loadDataGrid();
- }
- private void buttonAdd_Click(object sender, RoutedEventArgs e)
- {
- if (target == null)
- {
- MessageBox.Show("请先随意选择一个方案,修改完成后再点击新增按钮。");
- return;
- }
- string disease = textBoxDisease.Text;
- string bodyParts = textBoxBodyParts.Text;
- double.TryParse(textBoxRate1.Text, out double rate1);
- double.TryParse(textBoxRate2.Text, out double rate2);
- double.TryParse(textBoxRate3.Text, out double rate3);
- double.TryParse(textBoxRate4.Text, out double rate4);
- double.TryParse(textBoxRate5.Text, out double rate5);
- double.TryParse(textBoxRate6.Text, out double rate6);
- double.TryParse(textBoxRate7.Text, out double rate7);
- double.TryParse(textBoxRate8.Text, out double rate8);
- double.TryParse(textBoxRate9.Text, out double rate9);
- double.TryParse(textBoxRate10.Text, out double rate10);
- int.TryParse(textBoxNum1.Text, out int num1);
- int.TryParse(textBoxNum2.Text, out int num2);
- int.TryParse(textBoxNum3.Text, out int num3);
- int.TryParse(textBoxNum4.Text, out int num4);
- int.TryParse(textBoxNum5.Text, out int num5);
- int.TryParse(textBoxNum6.Text, out int num6);
- int.TryParse(textBoxNum7.Text, out int num7);
- int.TryParse(textBoxNum8.Text, out int num8);
- int.TryParse(textBoxNum9.Text, out int num9);
- int.TryParse(textBoxNum10.Text, out int num10);
- double.TryParse(textBoxIntervalTime.Text, out double intervalTime);
- int.TryParse(textBoxRepeatTimes.Text, out int repeatTimes);
- if (checkError())
- {
- MessageBox.Show("存在无效数据,请检查后再点击修改按钮!");
- return;
- }
- if (isEqualsTarget())
- {
- MessageBox.Show("新方案与旧方案重复!");
- return;
- }
- SQLiteModel.insertTreatment(disease, bodyParts, rate1, rate2, rate3, rate4, rate5, rate6, rate7, rate8, rate9, rate10, num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, intervalTime, repeatTimes);
- loadDataGrid();
- }
- private void buttonDelete_Click(object sender, RoutedEventArgs e)
- {
- if (target == null)
- {
- MessageBox.Show("请选择要删除的治疗方案!");
- return;
- }
- int id = target.id;
- SQLiteModel.deleteTreatment(id);
- loadDataGrid();
- }
- private void buttonSelect_Click(object sender, RoutedEventArgs e)
- {
- if (target == null)
- {
- MessageBox.Show("请选择治疗方案!");
- return;
- }
- father.setTreatment(target);
-
- }
- }
- }
|