private void deleteData(int id)
 {
     try
     {
         string DeleteSql = "Delete from stock where itemID = '" + id + "'";
         if (local)
         {
             SqlConnection sqlcon = new SqlConnection(strcon);
             sqlcon.Open();
             SqlCommand com = new SqlCommand(DeleteSql, sqlcon);
             com.ExecuteNonQuery();
             SqlDataAdapter ada = new SqlDataAdapter("select * from stock", sqlcon);
             DataSet        ds  = new DataSet();
             ada.Fill(ds, "stock");
             sqlcon.Close();
         }
         else
         {
             MySqlConnection MySqlCon = new MySqlConnection(MySQLConnection.SqlCon);
             MySqlCon.Open();
             MySqlCommand com = new MySqlCommand(DeleteSql, MySqlCon);
             com.ExecuteNonQuery();
             MySqlDataAdapter ada = new MySqlDataAdapter("select * from stock", MySqlCon);
             DataSet          ds  = new DataSet();
             ada.Fill(ds, "stock");
             MySQLConnection.CloseConn();
         }
         MySqlConnection MySqlCon1 = new MySqlConnection(MySQLConnection.SqlCon);
         MySqlCon1.Open();
         MySqlCommand com1 = new MySqlCommand("ALTER TABLE stock AUTO_INCREMENT = 1;", MySqlCon1);
         com1.ExecuteNonQuery();
         MySqlDataAdapter ada1 = new MySqlDataAdapter("select * from stock", MySqlCon1);
         DataSet          ds1  = new DataSet();
         ada1.Fill(ds1, "stock");
         MySQLConnection.CloseConn();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void updateData(int id, string name, int safe, int qty)
 {
     try
     {
         string UpdateSql = "update stock" +
                            " set itemName = '" + name + "'," +
                            "itemSafeStock = '" + safe + "'," +
                            "quantity = '" + qty + "'" +
                            "where itemID = '" + id + "'";
         if (local)
         {
             SqlConnection sqlcon = new SqlConnection(strcon);
             sqlcon.Open();
             SqlCommand com = new SqlCommand(UpdateSql, sqlcon);
             com.ExecuteNonQuery();
             SqlDataAdapter ada = new SqlDataAdapter("select * from stock", sqlcon);
             DataSet        ds  = new DataSet();
             ada.Fill(ds, "stock");
             sqlcon.Close();
         }
         else
         {
             MySqlConnection MySqlCon = new MySqlConnection(MySQLConnection.SqlCon);
             MySqlCon.Open();
             MySqlCommand com = new MySqlCommand(UpdateSql, MySqlCon);
             com.ExecuteNonQuery();
             MySqlDataAdapter ada = new MySqlDataAdapter("select * from stock", MySqlCon);
             DataSet          ds  = new DataSet();
             ada.Fill(ds, "stock");
             MySQLConnection.CloseConn();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#3
0
 private void deleteData()
 {
     try
     {
         string DeleteSql = "Delete from staff_info where id = '" + treeView1.SelectedNode.Tag + "'";
         if (local)
         {
             SqlConnection sqlcon = new SqlConnection(strcon);
             sqlcon.Open();
             SqlCommand com = new SqlCommand(DeleteSql, 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();
             MySqlCommand com = new MySqlCommand(DeleteSql, MySqlCon);
             com.ExecuteNonQuery();
             MySqlDataAdapter ada = new MySqlDataAdapter("select * from staff_info", MySqlCon);
             DataSet          ds  = new DataSet();
             ada.Fill(ds, "staff_info");
             MySQLConnection.CloseConn();
         }
         treeView1.Nodes.Clear();
         InitTree(this.treeView1.Nodes, "0");
         treeView1.ExpandAll();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void insertData()
        {
            try
            {
                if (!IsNumberic(txt_safe.Text))
                {
                    MessageBox.Show("Safe stock must be a number");
                    return;
                }
                if (!IsNumberic(txt_qty.Text))
                {
                    MessageBox.Show("Qty must be be a number");
                    return;
                }
                if (comboB_type1.Text == "")
                {
                    MessageBox.Show("Must select the type of item");
                    return;
                }
                else
                {
                    string InsertSql = "insert into stock(itemName,itemSafeStock,quantity,type) " +
                                       "values ('" + txt_name1.Text + "'" +
                                       ",'" + txt_safe.Text + "'" +
                                       ",'" + txt_qty.Text + "'" +
                                       ",'" + comboB_type1.Text + "')";

                    if (local)
                    {
                        SqlConnection sqlcon = new SqlConnection(strcon);
                        sqlcon.Open();
                        SqlCommand com = new SqlCommand(InsertSql, sqlcon);
                        com.ExecuteNonQuery();
                        SqlDataAdapter ada = new SqlDataAdapter("select * from stock", sqlcon);
                        DataSet        ds  = new DataSet();
                        ada.Fill(ds, "stock");
                        sqlcon.Close();
                    }
                    else
                    {
                        MySqlConnection MySqlCon = new MySqlConnection(MySQLConnection.SqlCon);
                        MySqlCon.Open();
                        MySqlCommand com = new MySqlCommand(InsertSql, MySqlCon);
                        com.ExecuteNonQuery();
                        MySqlDataAdapter ada = new MySqlDataAdapter("select * from stock", MySqlCon);
                        DataSet          ds  = new DataSet();
                        ada.Fill(ds, "stock");
                        MySQLConnection.CloseConn();
                    }
                    MessageBox.Show("successful");
                    txt_name1.Text    = "";
                    txt_safe.Text     = "";
                    txt_qty.Text      = "";
                    comboB_type1.Text = "";
                    InitialGrid();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#5
0
        private void updateData()
        {
            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");
                return;
            }
            else
            {
                string UpdateSql = "update staff_info" +
                                   " set last_name = '" + txt_name.Text + "'," +
                                   "address_id = '" + txt_Address.Text + "'," +
                                   "phone = '" + txt_Phone.Text + "'," +
                                   "parent_id = '" + parentID + "'," +
                                   "gender = '" + comBox_gender.Text + "'," +
                                   "birthday = '" + dateTimePicker1.Value.Date.ToString("yyyy-MM-dd HH:mm") + "'," +
                                   "ssn = '" + txt_SSN.Text + "'," +
                                   "email = '" + txt_Email.Text + "' " +
                                   "where id = '" + treeView1.SelectedNode.Tag + "'";


                try
                {
                    if (local)
                    {
                        SqlConnection sqlcon = new SqlConnection(strcon);
                        sqlcon.Open();
                        SqlCommand com = new SqlCommand(UpdateSql, 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();
                        MySqlCommand com = new MySqlCommand(UpdateSql, 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();
            }
        }