public Guid CreateNewInvestigationRecord(NewInvestigationRecordDto newrecord) { if (newrecord == null) { throw new ArgumentNullException("记录参数不能为空!"); } using (NutritionalResearchDatabaseEntities mydb = new NutritionalResearchDatabaseEntities()) { var queneId = mydb.InvestigationRecord.Where(nObj => nObj.QueueId == newrecord.QueueId).FirstOrDefault(); if (queneId != null) { throw new ArgumentException("输入的队列编码重复"); } int _stage = 1; if (newrecord.Week < 13) { _stage = 1; } else if (newrecord.Week >= 13 && newrecord.Week <= 28) { _stage = 2; } else { _stage = 3; } InvestigationRecord record = new InvestigationRecord() { Id = Guid.NewGuid(), BeforeWeight = newrecord.BeforeWeight, BeforeBMI = 10000 * newrecord.BeforeWeight / (newrecord.Height * newrecord.Height), Birthday = newrecord.Birthday, CreationTime = DateTime.Now, CurrentWeight = newrecord.CurrentWeight, HealthBookId = newrecord.HealthBookId, Height = newrecord.Height, InvestigatorName = newrecord.InvestigatorName, Name = newrecord.Name, QueueId = newrecord.QueueId, Stage = _stage, State = (int)InvestigationRecordStateType.NoFinish, Week = newrecord.Week }; mydb.InvestigationRecord.Add(record); try { mydb.SaveChanges(); return(record.Id); } catch (Exception ex) { throw ex; } } }
private void buttonBegin_Click(object sender, RoutedEventArgs e) { //App.Current.Properties["CurrentRecordId"] = Guid.Parse("f02a6307-9042-4424-b239-d96efd650a57"); //Frame myframe = App.Current.Properties["MyFrame"] as Frame; //myframe.Navigate(new Uri(@"Pages\QuestionPage.xaml", UriKind.Relative)); if (string.IsNullOrEmpty(textBoxQueueID.Text)) { textBlock_Required1.Visibility = Visibility.Visible; return; } if (string.IsNullOrEmpty(textBoxHealthbookID.Text)) { textBlock_Required2.Visibility = Visibility.Visible; return; } if (string.IsNullOrEmpty(textBoxInvestigatorName.Text)) { textBlock_Required3.Visibility = Visibility.Visible; return; } if (string.IsNullOrEmpty(textBoxName.Text)) { textBlock_Required4.Visibility = Visibility.Visible; return; } if (string.IsNullOrEmpty(textBoxBirthday.Text)) { textBlock_Required5.Visibility = Visibility.Visible; return; } if (string.IsNullOrEmpty(textBoxWeek.Text)) { textBlock_Required6.Visibility = Visibility.Visible; return; } if (string.IsNullOrEmpty(textBoxHeight.Text)) { textBlock_Required7.Visibility = Visibility.Visible; return; } if (string.IsNullOrEmpty(textBoxBeforeWeight.Text)) { textBlock_Required8.Visibility = Visibility.Visible; return; } if (string.IsNullOrEmpty(textBoxCurrentWeight.Text)) { textBlock_Required9.Visibility = Visibility.Visible; return; } if (!textBoxQueueID.Text.IsNumeric()) { MessageBox.Show("队列编码必须为数字"); return; } if (!textBoxHealthbookID.Text.IsNumeric()) { MessageBox.Show("围产保健手册编码必须为数字"); return; } if (!textBoxBirthday.Text.IsDateTime()) { MessageBox.Show("生日应为日期格式"); return; } if (!textBoxWeek.Text.IsNumeric()) { MessageBox.Show("孕周必须为数字"); return; } if (!textBoxHeight.Text.IsFloat()) { MessageBox.Show("身高必须为数字"); return; } if (!textBoxBeforeWeight.Text.IsFloat()) { MessageBox.Show("体重必须为数字"); return; } if (!textBoxCurrentWeight.Text.IsFloat()) { MessageBox.Show("体重必须为数字"); return; } INRMainService myMainService = BusinessStaticInstances.GetSingleMainServiceInstance(); try { NewInvestigationRecordDto newRecord = new NewInvestigationRecordDto() { BeforeWeight = double.Parse(textBoxBeforeWeight.Text), Birthday = DateTime.Parse(textBoxBirthday.Text), CurrentWeight = double.Parse(textBoxCurrentWeight.Text), HealthBookId = textBoxHealthbookID.Text, Height = double.Parse(textBoxHeight.Text), InvestigatorName = textBoxInvestigatorName.Text, Name = textBoxName.Text, QueueId = textBoxQueueID.Text, Week = int.Parse(textBoxWeek.Text) }; Guid myID = myMainService.CreateNewInvestigationRecord(newRecord); App.Current.Properties["CurrentRecordId"] = myID; Frame myframe = App.Current.Properties["MyFrame"] as Frame; myframe.Navigate(new Uri(@"Pages\QuestionPage.xaml", UriKind.Relative), 1); } catch (Exception ex) { MessageBox.Show(ex.Message); } }