private void btnAdd_Click(object sender, EventArgs e) { detail.MemberID = Convert.ToInt32(txtID.Text); detail.MemberName = txtName.Text; detail.WorkoutID = Convert.ToInt32(cmbWorkout.SelectedValue); detail.WorkoutHours = Convert.ToDouble(txtHours.Text); detail.EditTime = DateTime.Now.Date; if (txtName.Text == "" || txtID.Text == "" || cmbWorkout.SelectedIndex == -1 || txtHours.Text == "") { MessageBox.Show("請填寫所有資訊"); return; } if (IsUpdate) { bll.UpDate(detail); MessageBox.Show("已修改運動紀錄"); this.Close(); } else { if (bll.Add(detail)) { MessageBox.Show("已加入新運動紀錄"); this.Close(); } } }
private void btnAdd_Click(object sender, EventArgs e) { if (threeDaysAgo.Date < DateTime.Now.Date) { threeDaysAgo = threeDaysAgo.AddDays(1); } if (!double.TryParse(this.txtWorkoutHours.Text, out double workoutHours) || workoutHours == 0) { this.lblWorkoutCategoryTest.Text = "請輸入數字且必須大於0"; return; } else { this.lblWorkoutCategoryTest.Text = ""; } bool isSuccess = false; if (workoutLogForm.isUpdate) { isSuccess = wlBll.Edit(new WorkoutLog { ID = workoutLogForm.dto.ID, MemberID = UserStatic.UserID, WorkoutID = (int)this.cmbWorkout.SelectedValue, EditTime = DateTime.Now, WorkoutHours = workoutHours });; if (isSuccess) { MessageBox.Show("修改成功"); } else { MessageBox.Show("修改失敗"); } } else { isSuccess = wlBll.Add(new WorkoutLog { MemberID = UserStatic.UserID, WorkoutID = (int)this.cmbWorkout.SelectedValue, EditTime = threeDaysAgo, WorkoutHours = workoutHours }); if (isSuccess) { MessageBox.Show("新增成功"); } else { MessageBox.Show("新增失敗"); } } }