private void buttonUpdate_Click(object sender, EventArgs e) { try { int id_P = Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells["ID_Procedure"].Value); int ran = Convert.ToInt32(textBoxID_Procedure.Text); if (comboBoxIDDep.Text != "" && textBoxName.Text != "" && textBoxCost.Text != "") { if (textBoxID_Procedure.Text != "" && (ran != id_P)) { if (DBConnect.Contains(String.Format("SELECT Name FROM [Procedure] WHERE ID_Procedure = {0}", ran)) == true) { MessageBox.Show("Услуга с данным кодом уже существует, выберите другой код."); } else { id_P = ran; DBConnect.InsertDeleteDB(String.Format("UPDATE [Procedure] SET ID_Procedure = {0}, Name = '{1}', Cost = '{2}', ID_Dep = {3} WHERE ID_Procedure = {4}", id_P, textBoxName.Text, textBoxCost.Text, Convert.ToInt32(comboBoxIDDep.Text), Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells["ID_Procedure"].Value))); UpdateI(); MessageBox.Show("Данные обновлены!"); } } } else { DBConnect.InsertDeleteDB(String.Format("UPDATE [Procedure] SET ID_Procedure = {0}, Name = '{1}', Cost = '{2}', ID_Dep = {3} WHERE ID_Procedure = {4}", id_P, textBoxName.Text, textBoxCost.Text, Convert.ToInt32(comboBoxIDDep.Text), Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells["ID_Procedure"].Value))); UpdateI(); MessageBox.Show("Данные обновлены!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonAdd_Click(object sender, EventArgs e) { try { if (textBoxName.Text != "") { if (textBoxID.Text != "") { int ran = Convert.ToInt32(textBoxID.Text); if (DBConnect.Contains(String.Format("SELECT Name FROM Department WHERE ID_Dep = {0}", ran)) == true) { MessageBox.Show("Отделение с данным кодом уже существует, выберите другой код отделения."); } else { DBConnect.InsertDeleteDB(String.Format("INSERT INTO Department (ID_Dep, Name) VALUES ({0},'{1}')", ran, textBoxName.Text.ToString())); textBoxID.Text = ""; textBoxName.Text = ""; UpdateI(); MessageBox.Show("Отделение успешно добавлено!"); } } else { int ran = Ran.Next(1, 10000); if (DBConnect.Contains(String.Format("SELECT Name FROM Department WHERE ID_Dep = {0}", ran)) == true) { while (DBConnect.Contains(String.Format("SELECT Name FROM Department WHERE ID_Dep = {0}", ran)) == true) { ran = Ran.Next(1, 10000); } } else { DBConnect.InsertDeleteDB(String.Format("INSERT INTO Department (ID_Dep, Name) VALUES ({0},'{1}')", ran, textBoxName.Text.ToString())); textBoxID.Text = ""; textBoxName.Text = ""; MessageBox.Show("Отделение успешно добавлено!"); UpdateI(); } } } else { MessageBox.Show("Заполнены не все поля."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonAdd_Click(object sender, EventArgs e) { try { if (maskedTextBoxP.Text != "" && maskedTextBoxP.Text.Length > 11 && maskedTextBoxData.Text != "" && textBoxF.Text != "" && textBoxN.Text != "" && textBoxP.Text != "") { int ran; if (textBoxID.Text != "") { ran = Convert.ToInt32(textBoxID.Text); if (DBConnect.Contains(String.Format("SELECT Name FROM Patients WHERE ID_Pat = {0}", ran)) == true) { MessageBox.Show("Клиент с данным кодом уже существует, выберите другой код клиента."); } else { DBConnect.InsertDeleteDB(String.Format("INSERT INTO Patients (ID_Pat, Surname, Name, Patronymic, Phone, Date_of_birth) VALUES ({0},'{1}','{2}','{3}','{4}','{5}')", ran, textBoxF.Text, textBoxN.Text, textBoxP.Text, maskedTextBoxP.Text, maskedTextBoxData.Text)); UpdateI(); MessageBox.Show("Данные успешно добавлены!"); } } else { ran = Ran.Next(1, 10000); if (DBConnect.Contains(String.Format("SELECT Name FROM Patients WHERE ID_Pat = {0}", ran)) == true) { while (DBConnect.Contains(String.Format("SELECT Name FROM Patients WHERE ID_Pat = {0}", ran)) == true) { ran = Ran.Next(1, 10000); } } else { DBConnect.InsertDeleteDB(String.Format("INSERT INTO Patients (ID_Pat, Surname, Name, Patronymic, Phone, Date_of_birth) VALUES ({0},'{1}','{2}','{3}','{4}','{5}')", ran, textBoxF.Text, textBoxN.Text, textBoxP.Text, maskedTextBoxP.Text, maskedTextBoxData.Text)); UpdateI(); MessageBox.Show("Данные успешно добавлены!"); } } } else { MessageBox.Show("Заполнены не все поля или заданы некорректные значения."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonAdd_Click(object sender, EventArgs e) { try { if (comboBoxIDDep.Text != "" && textBoxName.Text != "" && textBoxCost.Text != "") { int ran; if (textBoxID_Procedure.Text != "") { ran = Convert.ToInt32(textBoxID_Procedure.Text); if (DBConnect.Contains(String.Format("SELECT Name FROM [Procedure] WHERE ID_Procedure = {0}", ran)) == true) { MessageBox.Show("Процедура с данным кодом уже существует, выберите другой код процедуры."); } else { DBConnect.InsertDeleteDB(String.Format("INSERT INTO [Procedure] (ID_Procedure, Name, Cost, ID_Dep) VALUES ({0},'{1}','{2}',{3})", ran, textBoxName.Text, textBoxCost.Text, Convert.ToInt32(comboBoxIDDep.Text))); MessageBox.Show("Процедура успешно добавлена!"); UpdateI(); } } else { ran = Ran.Next(1, 10000); if (DBConnect.Contains(String.Format("SELECT Name FROM [Procedure] WHERE ID_Procedure = {0}", ran)) == true) { while (DBConnect.Contains(String.Format("SELECT Name FROM [Procedure] WHERE ID_Procedure = {0}", ran)) == true) { ran = Ran.Next(1, 10000); } } else { DBConnect.InsertDeleteDB(String.Format("INSERT INTO [Procedure] (ID_Procedure, Name, Cost, ID_Dep) VALUES ({0},'{1}','{2}',{3})", ran, textBoxName.Text, textBoxCost.Text, Convert.ToInt32(comboBoxIDDep.Text))); MessageBox.Show("Процедура успешно добавлена!"); UpdateI(); } } } else { MessageBox.Show("Заполнены не все поля."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonAdd_Click(object sender, EventArgs e) { try { if (maskedTextBoxP.Text != "" && maskedTextBoxP.Text.Length > 11 && textBoxF.Text != "" && textBoxN.Text != "" && textBoxP.Text != "" && textBoxPosition.Text != "" && comboBoxIDDep.Text != "") { int ran; if (textBoxID.Text != "") { ran = Convert.ToInt32(textBoxID.Text); if (DBConnect.Contains(String.Format("SELECT Name FROM Doctors WHERE ID_Doc = {0}", ran)) == true) { MessageBox.Show("Врач с данным кодом уже существует, выберите другой код врача."); } else { DBConnect.InsertDeleteDB(String.Format("INSERT INTO Doctors (ID_Doc, Surname, Name, Patronymic, [Position], Phone, E_mail, ID_Dep) VALUES ({0},'{1}','{2}','{3}','{4}','{5}','{6}', {7})", ran, textBoxF.Text, textBoxN.Text, textBoxP.Text, textBoxPosition.Text, maskedTextBoxP.Text, textBoxE_mail.Text, comboBoxIDDep.Text)); UpdateI(); MessageBox.Show("Новый сотрудник успешно добавлен!"); } } else { ran = Ran.Next(1, 10000); if (DBConnect.Contains(String.Format("SELECT Name FROM Doctors WHERE ID_Doc = {0}", ran)) == true) { while (DBConnect.Contains(String.Format("SELECT Name FROM Doctors WHERE ID_Doc = {0}", ran)) == true) { ran = Ran.Next(1, 10000); } } else { DBConnect.InsertDeleteDB(String.Format("INSERT INTO Doctors (ID_Doc, Surname, Name, Patronymic, [Position], Phone, E_mail, ID_Dep) VALUES ({0},'{1}','{2}','{3}','{4}','{5}','{6}', {7})", ran, textBoxF.Text, textBoxN.Text, textBoxP.Text, textBoxPosition.Text, maskedTextBoxP.Text, textBoxE_mail.Text, comboBoxIDDep.Text)); UpdateI(); MessageBox.Show("Новый сотрудник успешно добавлен!"); } } } else { MessageBox.Show("Заполнены не все поля или заданы некорректные значения."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonAdd_Click(object sender, EventArgs e) { if (dateTimePicker.Value.ToString() != null && comboBoxTime.SelectedItem != null && comboBoxPat.SelectedItem != null && comboBoxDoc.SelectedItem != null && comboBoxProcedure.SelectedItem != null && comboBoxDep.SelectedItem != null) { int ran = Ran.Next(1, 10000); //MessageBox.Show(ran.ToString()); if (DBConnect.Contains(String.Format("SELECT Data FROM Records WHERE ID_Record = {0}", ran)) == true) { while (DBConnect.Contains(String.Format("SELECT Data FROM Records WHERE ID_Record = {0}", ran)) == true) { ran = Ran.Next(1, 10000); } } try { DataTable table1 = DBConnect.ShowDB(String.Format("SELECT ID_Procedure FROM [Procedure] WHERE Name = '{0}'", comboBoxProcedure.SelectedItem.ToString())); int ID_Procedure = Convert.ToInt32(table1.Rows[0]["ID_Procedure"]); DataTable table2 = DBConnect.ShowDB(String.Format("SELECT ID_Pat FROM Patients")); int ID_Patient = Convert.ToInt32(table2.Rows[comboBoxPat.SelectedIndex]["ID_Pat"]); DataTable tableD = DBConnect.ShowDB(String.Format("SELECT ID_Dep FROM Department")); int ID_Dep = Convert.ToInt32(tableD.Rows[comboBoxDep.SelectedIndex]["ID_Dep"]); DataTable table3 = DBConnect.ShowDB(String.Format("SELECT ID_Doc FROM Doctors WHERE ID_Dep = {0}", ID_Dep)); int ID_Doc = Convert.ToInt32(table3.Rows[comboBoxDoc.SelectedIndex]["ID_Doc"]); DBConnect.InsertDeleteDB(String.Format("INSERT INTO Records (ID_Record, ID_Procedure, [Time], Data, Status,ID_Doc, ID_Pat) VALUES ({0},{1},'{2}','{3}','{4}',{5},{6})", ran, ID_Procedure, comboBoxTime.SelectedItem.ToString(), dateTimePicker.Value.ToShortDateString(), "Ожидание", ID_Doc, ID_Patient)); DBConnect.InsertDeleteDB(String.Format("INSERT INTO Report (ID_Record, Payment, Comment) VALUES ({0},'{1}','{2}')", ran, "Не оплачено", "")); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Заполнены не все поля."); } }
private void buttonUpdate_Click(object sender, EventArgs e) { try { if (maskedTextBoxP.Text != "" && maskedTextBoxP.Text.Length > 11 && maskedTextBoxData.Text != "" && textBoxF.Text != "" && textBoxN.Text != "" && textBoxP.Text != "") { int id_P = Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells["ID_Pat"].Value); int ran = Convert.ToInt32(textBoxID.Text); if (textBoxID.Text != "" && (ran != id_P)) { if (DBConnect.Contains(String.Format("SELECT Name FROM Patients WHERE ID_Pat = {0}", ran)) == true) { MessageBox.Show("Клиент с данным кодом уже существует, выберите другой код клиента."); } else { id_P = ran; DBConnect.InsertDeleteDB(String.Format("UPDATE Patients SET ID_Pat = {0}, Surname = '{1}', Name = '{2}', Patronymic = '{3}', Phone = '{4}', Date_of_birth = '{5}' WHERE ID_Pat = {6}", id_P, textBoxF.Text, textBoxN.Text, textBoxP.Text, maskedTextBoxP.Text, maskedTextBoxData.Text, Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells["ID_Pat"].Value))); UpdateI(); MessageBox.Show("Данные обновлены!"); } } else { DBConnect.InsertDeleteDB(String.Format("UPDATE Patients SET ID_Pat = {0}, Surname = '{1}', Name = '{2}', Patronymic = '{3}', Phone = '{4}', Date_of_birth = '{5}' WHERE ID_Pat = {6}", id_P, textBoxF.Text, textBoxN.Text, textBoxP.Text, maskedTextBoxP.Text, maskedTextBoxData.Text, Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells["ID_Pat"].Value))); UpdateI(); MessageBox.Show("Данные обновлены!"); } } else { MessageBox.Show("Заполнены не все поля или заданы некорректные значения."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonUpdate_Click(object sender, EventArgs e) { try { if (maskedTextBoxP.Text != "" && maskedTextBoxP.Text.Length > 11 && textBoxF.Text != "" && textBoxN.Text != "" && textBoxP.Text != "" && textBoxPosition.Text != "" && comboBoxIDDep.Text != "") { int id_D = Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells["ID_Doc"].Value); int ran = Convert.ToInt32(textBoxID.Text); if (textBoxID.Text != "" && (ran != id_D)) { if (DBConnect.Contains(String.Format("SELECT Name FROM Doctors WHERE ID_Doc = {0}", ran)) == true) { MessageBox.Show("Врач с данным кодом уже существует, выберите другой код врача."); } else { id_D = ran; DBConnect.InsertDeleteDB(String.Format("UPDATE Doctors SET ID_Doc = {0}, Surname = '{1}', Name = '{2}', Patronymic = '{3}', [Position] = '{4}', Phone = '{5}', E_mail = '{6}', ID_Dep = {7} WHERE ID_Doc = {8}", id_D, textBoxF.Text, textBoxN.Text, textBoxP.Text, textBoxPosition.Text, maskedTextBoxP.Text, textBoxE_mail.Text, Convert.ToInt32(comboBoxIDDep.Text), Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells["ID_Doc"].Value))); UpdateI(); MessageBox.Show("Данные обновлены!"); } } else { DBConnect.InsertDeleteDB(String.Format("UPDATE Doctors SET ID_Doc = {0}, Surname = '{1}', Name = '{2}', Patronymic = '{3}', [Position] = '{4}', Phone = '{5}', E_mail = '{6}', ID_Dep = {7} WHERE ID_Doc = {8}", id_D, textBoxF.Text, textBoxN.Text, textBoxP.Text, textBoxPosition.Text, maskedTextBoxP.Text, textBoxE_mail.Text, Convert.ToInt32(comboBoxIDDep.Text), Convert.ToInt32(dataGridView.Rows[dataGridView.CurrentRow.Index].Cells["ID_Doc"].Value))); UpdateI(); MessageBox.Show("Данные обновлены!"); } } else { MessageBox.Show("Заполнены не все поля или заданы некорректные значения."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }