private void btnAdd_Click(object sender, EventArgs e) { double parsedWeight; if (cmbMembers.SelectedIndex == -1 || txtWeight.Text == "") { MessageBox.Show("請輸入所有欄位"); } else if (!double.TryParse(txtWeight.Text, out parsedWeight)) { MessageBox.Show("請輸入正確的體重數值"); } else { detail.MemberID = Convert.ToInt32(cmbMembers.SelectedValue); detail.Weight = parsedWeight; if (isUpdate) { bll.Update(detail); MessageBox.Show("已修改體重紀錄"); frmWeightLog.ShowWeightLogs(); this.Close(); } else { detail.UpdatedDate = Convert.ToDateTime(cmbTime.SelectedItem); bll.Add(detail); MessageBox.Show("已新增體重記錄"); frmWeightLog.ShowWeightLogs(); this.Close(); } } }
private void btnAdd_Click(object sender, EventArgs e) { double weight; if (double.TryParse(txtWeight.Text, out weight)) { if (isUpdate) { DateTime updatedDate = Convert.ToDateTime(cmbTime.SelectedItem); detail.Weight = weight; detail.UpdatedDate = updatedDate; bll.Update(detail); MessageBox.Show("已修改體重記錄"); frmWeightLog.ShowWeightLogs(); this.Close(); } else { DateTime updatedDate = Convert.ToDateTime(cmbTime.SelectedItem); detail.MemberID = UserStatic.UserID; detail.Weight = weight; detail.UpdatedDate = updatedDate; bll.Add(detail); MessageBox.Show("已新增體重記錄"); frmWeightLog.ShowWeightLogs(); this.Close(); } } else { MessageBox.Show("請輸入正確的體重數值"); } }