private void Populate(ScheduleDoctorMeeting meeting) { textBox1.Text = meeting.TherapyCode; comboBox2.Text = meeting.WhoCanGiveTheTherapy; textBox2.Text = meeting.IdDoctor; comboBox1.SelectedIndex = meeting.Day - 1; textBox3.Text = meeting.Hour; }
private bool UpdateObject(ScheduleDoctorMeeting s) { bool ok = true; try { s.TherapyCode = textBox1.Text; errorProvider1.SetError(textBox1, ""); } catch (Exception ex) { ok = false; errorProvider1.SetError(textBox1, ex.Message); } try { s.IdDoctor = textBox2.Text; errorProvider1.SetError(textBox2, ""); } catch (Exception ex) { ok = false; errorProvider1.SetError(textBox2, ex.Message); } try { s.WhoCanGiveTheTherapy = comboBox2.Text; errorProvider1.SetError(comboBox2, ""); } catch (Exception ex) { ok = false; errorProvider1.SetError(comboBox2, ex.Message); } try { s.Day = comboBox1.SelectedIndex + 1; errorProvider1.SetError(comboBox1, ""); } catch (Exception ex) { ok = false; errorProvider1.SetError(comboBox1, ex.Message); } try { s.Hour = textBox3.Text; errorProvider1.SetError(textBox3, ""); } catch (Exception ex) { ok = false; errorProvider1.SetError(textBox3, ex.Message); } return(ok); }
private void save_Click(object sender, EventArgs e) { try { ScheduleDoctorMeeting s = new ScheduleDoctorMeeting(); //s.Day = comboBox1.SelectedIndex + 1; if (UpdateObject(s)) { if (state == AddState.ADDNEW) { //string SQLadd = "INSERT INTO MeetingDoctor ( TherapyCode, WhoCanGiveTheTherapy, IdDoctor, [day], [hour] ) VALUES('" + s.TherapyCode + "','" + s.WhoCanGiveTheTherapy + "','" + s.IdDoctor + "',[" + s.Day + "],['" + s.Hour + "'])"; //string path = System.IO.Directory.GetCurrentDirectory(); //int x = path.IndexOf("\\bin"); //path = path.Substring(0, x) + "\\Data\\try.accdb"; //string myConnectionStr = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + path + "';Persist Security Info=True"); //con = new OleDbConnection(myConnectionStr); //con.Open(); //OleDbCommand SQLCommand = new OleDbCommand(); //SQLCommand.CommandText = SQLadd; //SQLCommand.Connection = con; //int response1 = -1; // response1 = SQLCommand.ExecuteNonQuery(); //response1 = DAL.GetInstance().ExecuteNonQuery(SQLadd); myMeetingDoctorTableAdapter.MyInsert(s.TherapyCode, s.WhoCanGiveTheTherapy, s.IdDoctor, s.Day, s.Hour); } else { ScheduleDoctorMeeting orginal = meetings.GetCurrentRow(); myMeetingDoctorTableAdapter.MyUpdate(s.WhoCanGiveTheTherapy, s.IdDoctor, s.Day, s.Hour, orginal.TherapyCode); } } SetButtonStates(true); state = AddState.NAVIGATE; //.. meetings.Save(); label6.Visible = false; } catch { MyMessage m = new MyMessage("the data is already exist in the database", 2); m.applyCustomChange(); m.ShowDialog(); } }
public void Update(ScheduleDoctorMeeting cos) { DataRow dr = base.GetCurrentRow(); cos.Populate(dr); }