private void PersonalInfo_Load(object sender, EventArgs e) { treeView1.ExpandAll(); InitTree(this.treeView1.Nodes, "0"); treeView1.ExpandAll(); toolStrip_save.Enabled = false; toolStripButton2.Enabled = false; MySQLConnection.OpenConn(); }
private void insertData() { int parentID = 0; if (cmb_position.SelectedIndex == 0) { parentID = 1; } if (cmb_position.SelectedIndex == 1) { parentID = 2; } if (cmb_position.SelectedIndex == 2) { parentID = 3; } if (cmb_position.SelectedIndex == 3) { parentID = 4; } if (!IsEmail(txt_Email.Text)) { MessageBox.Show("the email address is invalid"); } else { string InsertSql = "insert into staff_info(last_name,address_id,phone,parent_id,gender,birthday,ssn,email) " + "values ('" + txt_name.Text + "','" + txt_Address.Text + "','" + txt_Phone.Text + "','" + parentID + "','" + comBox_gender.Text + "','" + dateTimePicker1.Value.Date.ToString("yyyy-MM-dd HH:mm") + "','" + txt_SSN.Text + "','" + txt_Email.Text + "')"; try { if (local) { SqlConnection sqlcon = new SqlConnection(strcon); sqlcon.Open(); SqlCommand com = new SqlCommand(InsertSql, sqlcon); com.ExecuteNonQuery(); SqlDataAdapter ada = new SqlDataAdapter("select * from staff_info", sqlcon); DataSet ds = new DataSet(); ada.Fill(ds, "staff_info"); sqlcon.Close(); } else { MySqlConnection MySqlCon = new MySqlConnection(MySQLConnection.SqlCon); MySqlCon.Open(); MySQLConnection.OpenConn(); MySqlCommand com = new MySqlCommand(InsertSql, MySqlCon); com.ExecuteNonQuery(); MySqlDataAdapter ada = new MySqlDataAdapter("select * from staff_info", MySqlCon); DataSet ds = new DataSet(); ada.Fill(ds, "staff_info"); MySQLConnection.CloseConn(); } MessageBox.Show("successful"); treeView1.Nodes.Clear(); InitTree(this.treeView1.Nodes, "0"); treeView1.ExpandAll(); } catch (Exception ex) { MessageBox.Show(ex.Message); } toolStripButton1.Text = "Add"; toolStripButton1.Image = imageList1.Images[2]; toolStripButton1.Enabled = true; initial(); } }