private void btnEditApp_Click(object sender, EventArgs e) { if (btnEditApp.Text.TrimEnd() == "EDIT") { dtpEdAppBooked.Enabled = false; dtpEdAppDate.Enabled = true; cmbEdTimes.Enabled = true; cmbEditTransID.Enabled = true; cmbEdStaffID.Enabled = true; cmbEdDur.Enabled = true; txtEDesc.Enabled = true; btnEditApp.Text = "SAVE"; } else { MyAppointment myAppointment = new MyAppointment(); bool ok = true; errP.Clear(); try { myAppointment.AppID = lblEditAID.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(lblEditAID, MyEx.toString()); } try { myAppointment.AppTime = cmbEdTimes.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cmbEdTimes, MyEx.toString()); } try { myAppointment.Duration = Convert.ToInt32(cmbEdDur.Text.Trim()); } catch (MyException MyEx) { ok = false; errP.SetError(cmbEdDur, MyEx.toString()); } try { myAppointment.DateBooked = DateTime.Parse(dtpEdAppBooked.Text.Trim()); } catch (MyException MyEx) { ok = false; errP.SetError(dtpEdAppBooked, MyEx.toString()); } try { myAppointment.Appdate = DateTime.Parse(dtpEdAppDate.Text.Trim()); } catch (MyException MyEx) { ok = false; errP.SetError(dtpEdAppDate, MyEx.toString()); } try { myAppointment.TransID = cmbEditTransID.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cmbEditTransID, MyEx.toString()); } try { myAppointment.StaffID = cmbEdStaffID.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cmbEdStaffID, MyEx.toString()); } try { myAppointment.AppDesc = txtEDesc.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtEDesc, MyEx.toString()); } try { if (ok) { drAppointment = dsKaizen.Tables["Appointment"].Rows.Find(lblEditAID.Text); drAppointment.BeginEdit(); //drAppointment = dsKaizen.Tables["Appointment"].NewRow(); drAppointment["AppID"] = myAppointment.AppID; drAppointment["DateBooked"] = myAppointment.DateBooked; drAppointment["AppDate"] = myAppointment.Appdate; drAppointment["AppTime"] = cmbEdTimes.Text; drAppointment["Duration"] = Convert.ToInt32(cmbEdDur.Text); drAppointment["StaffID"] = myAppointment.StaffID; drAppointment["TransID"] = myAppointment.TransID; drAppointment["AppDesc"] = myAppointment.AppDesc; drAppointment.EndEdit(); SqlCommandBuilder daAppoinment = new SqlCommandBuilder(daAppointment); daAppointment.UpdateCommand = daAppoinment.GetUpdateCommand(); daAppointment.Update(dsKaizen, "Appointment"); MessageBox.Show("Appointment Updated"); btnEditApp.Text = "EDIT"; tabApp.SelectedIndex = 0; DisplayApps(); } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error !", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } } }
private void btnAddApp_Click_1(object sender, EventArgs e) { MyAppointment myAppointment = new MyAppointment(); bool ok = true; errP.Clear(); try { myAppointment.AppID = lblAddAppID.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(lblAddAppID, MyEx.toString()); } try { myAppointment.AppTime = cmbAddTime.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cmbAddTime, MyEx.toString()); } try { myAppointment.Duration = Convert.ToInt32(cmbDuration.Text.Trim()); } catch (MyException MyEx) { ok = false; errP.SetError(cmbDuration, MyEx.toString()); } try { myAppointment.DateBooked = DateTime.Parse(dtpDateBooked.Text.Trim()); } catch (MyException MyEx) { ok = false; errP.SetError(dtpDateBooked, MyEx.toString()); } try { myAppointment.Appdate = DateTime.Parse(dtpAppDate.Text.Trim()); } catch (MyException MyEx) { ok = false; errP.SetError(dtpDateBooked, MyEx.toString()); } try { myAppointment.TransID = cmbATransID.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cmbATransID, MyEx.toString()); } try { myAppointment.StaffID = cmbAStaffID.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cmbAStaffID, MyEx.toString()); } try { myAppointment.AppDesc = txtADesc.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtADesc, MyEx.toString()); } try { if (ok) { //conn = new SqlConnection(connStr); //sqlAppval = @"select count(*)from Appointment WHERE /*Appointment.AppDate = @FrmDT AND*/ Appointment.StaffID= @StaffID AND Appointment.AppTime=@AppTime"; //cmdAppval = new SqlCommand(sqlAppval, conn); //cmdAppval.Parameters.Add("@FrmDT", SqlDbType.Date); //cmdAppval.Parameters.Add("@StaffID", SqlDbType.VarChar); //cmdAppval.Parameters.Add("@AppTime", SqlDbType.VarChar); //cmdAppval.Parameters["@FrmDt"].Value = theDate; //cmdAppval.Parameters["@StaffID"].Value = cmbStaff.Text.Trim(); //cmdAppval.Parameters["@AppTime"].Value = cmbAddTime.Text.Trim(); //daAppval = new SqlDataAdapter(cmdAppval); //daAppval.FillSchema(dsKaizen, SchemaType.Source, "Appointment"); //daAppval.Fill(dsKaizen, "Appointment"); //conn.Open(); //Int32 count = Convert.ToInt32(cmdAppval.ExecuteScalar()); //MessageBox.Show(count.ToString()); //found = true; //MessageBox.Show("you Cannane do that", "Appointment"); //tabApp.SelectedIndex = 0; DataRow drAppointment = dsKaizen.Tables["Appointment"].NewRow(); drAppointment["AppID"] = myAppointment.AppID; drAppointment["DateBooked"] = myAppointment.DateBooked; drAppointment["AppDate"] = myAppointment.Appdate; drAppointment["AppTime"] = cmbAddTime.Text; drAppointment["Duration"] = Convert.ToInt32(cmbDuration.Text); drAppointment["StaffID"] = myAppointment.StaffID; drAppointment["TransID"] = myAppointment.TransID; drAppointment["AppDesc"] = myAppointment.AppDesc; dsKaizen.Tables["Appointment"].Rows.Add(drAppointment); SqlCommandBuilder daAppoinment = new SqlCommandBuilder(daAppointment); daAppointment.UpdateCommand = daAppoinment.GetUpdateCommand(); daAppointment.Update(dsKaizen, "Appointment"); MessageBox.Show("Appointment Added"); txtADesc.Text = ""; dtpAppDate.Enabled = true; if (MessageBox.Show("Do you wish to add another Appointment?", "Add Appointment", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { clearAddForm(); getAppID(dsKaizen.Tables["Appointment"].Rows.Count); } else { tabApp.SelectedIndex = 0; DisplayApps(); } //found = false; } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error !", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } }