示例#1
0
 private void ADD_NEW_Click(object sender, EventArgs e)
 {
     ID_text.Clear();
     name_text.Clear();
     statue_text.Clear();
     AmountOfMedicine_txt.Clear();
     phoneNumber_text.Clear();
 }
示例#2
0
        private void ADD_Click(object sender, EventArgs e)
        {
            try
            {
                con.Open();

                OleDbCommand command = new OleDbCommand();
                command.Connection = con;

                if (name_text.Text != "" && statue_text.Text != "" && phoneNumber_text.Text != "")
                {
                    if (phoneNumber_text.TextLength == 11)
                    {
                        string s = "insert into Doctor (doctor_ID,name,statue,phone,amount_of_medicine)" +
                                   "values('" + ID_text.Text + "','" + name_text.Text + "','" + statue_text.Text + "','" + phoneNumber_text.Text + "','" + AmountOfMedicine_txt.Text + "')";
                        command.CommandText = s;
                        command.ExecuteNonQuery();
                        MessageBox.Show("ADD is done! ");
                        ID_text.Clear();
                        name_text.Clear();
                        statue_text.Clear();
                        AmountOfMedicine_txt.Clear();
                        phoneNumber_text.Clear();
                    }
                    else
                    {
                        MessageBox.Show("phone number is not correct, mobile phone number should be 11 number! ");
                    }
                }
                else
                {
                    MessageBox.Show(" data not complete, please complete it ");
                }



                comboBox1.Items.Clear();

                con.Close();

                try
                {
                    con.Open();

                    command.Connection = con;
                    string query = "select * from Doctor";

                    command.CommandText = query;
                    OleDbDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        comboBox1.Items.Add(reader["name"].ToString());
                    }

                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Happen! ");
                }
                finally
                {
                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(" patient number already exist! ");
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
        }