Exemple #1
0
        void processSave()
        {
            int posid = cat.getID(cmbPosition.Text);

            if (id > 0)
            {
                con = Connection.con();
                con.Open();
                query = "update phonebook set lname = ?lname, fname=?fname, mname=?mname," +
                        " mobileNo = ?mobile, positionID=?posid where phonebookID=?id";
                cmd = new MySqlCommand(query, con);
                cmd.Parameters.AddWithValue("?lname", txtlname.Text.Trim());
                cmd.Parameters.AddWithValue("?fname", txtfname.Text.Trim());
                cmd.Parameters.AddWithValue("?mname", txtmname.Text.Trim());
                cmd.Parameters.AddWithValue("?mobile", txtContact.Text);
                cmd.Parameters.AddWithValue("?posid", posid);

                cmd.Parameters.AddWithValue("?id", id);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                con.Close();
                con.Dispose();

                Box.infoBox("Contact successfully updated!");
                _frm.loaddata();
                this.Close();
            }
            else
            {
                con = Connection.con();
                con.Open();
                query = "insert into phonebook set lname = ?lname, fname=?fname, mname=?mname, " +
                        "mobileNo = ?mobile, positionID=?posid";
                cmd = new MySqlCommand(query, con);
                cmd.Parameters.AddWithValue("?lname", txtlname.Text.Trim());
                cmd.Parameters.AddWithValue("?fname", txtfname.Text.Trim());
                cmd.Parameters.AddWithValue("?mname", txtlname.Text.Trim());
                cmd.Parameters.AddWithValue("?mobile", txtContact.Text);
                cmd.Parameters.AddWithValue("?posid", posid);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                con.Close();
                con.Dispose();

                Box.infoBox("Contact successfully saved!");
                _frm.loaddata();
                this.Close();
            }
        }
        void processSave()
        {
            int posid = pos.getID(cmbPosition.Text);

            if (id > 0)
            {
                con = Connection.con();
                con.Open();
                if (update(posid) > 0)
                {
                    con.Close();
                    con.Dispose();
                    Box.infoBox("Data successfully updated.");
                }
                else
                {
                    con.Close();
                    con.Dispose();
                    Box.errBox("Something went wrong. Please contact System Administrator.");
                }
            }
            else
            {
                con = Connection.con();
                con.Open();
                if (insert(posid) > 0)
                {
                    con.Close();
                    con.Dispose();
                    Box.infoBox("Data successfully saved.");
                }
                else
                {
                    con.Close();
                    con.Dispose();
                    Box.errBox("Something went wrong. Please contact System Administrator.");
                }
            }
        }