Пример #1
0
        public void insertRecord(Author a)
        {
            NpgsqlCMD = new NpgsqlCommand();
            NpgsqlCMD.CommandText = @"Insert into AUTHORS (AUTHOR_ID, AUTHOR_LNAME, AUTHOR_FNAME, AUTHOR_MNAME, AUTHOR_EMAIL,                                      AUTHOR_ASSOC, AUTHOR_DEPT) 
                             VALUES (nextval('authors_author_id_seq'), :lname, :fname, :mi, :email, :association, :dept)";

            NpgsqlCMD.Parameters.Add(new NpgsqlParameter(":lname", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter(":fname", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("mi", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("email", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("association", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("dept", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters[0].Value = a.LastName;
            NpgsqlCMD.Parameters[1].Value = a.FirstName;
            NpgsqlCMD.Parameters[2].Value = a.MI;
            NpgsqlCMD.Parameters[3].Value = a.Email;
            NpgsqlCMD.Parameters[4].Value = a.Association;
            NpgsqlCMD.Parameters[5].Value = a.Department;

            if(GlobalVariables.GlobalConnection.insertData(NpgsqlCMD))
                MessageBox.Show("Author record has been inserted.", "Author Inserted", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
                MessageBox.Show("Author record has not been inserted.", "Author Not Inserted", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Пример #2
0
        public void updateRecord(Author a)
        {
            NpgsqlCMD = new NpgsqlCommand();
            NpgsqlCMD.CommandText = @"Update AUTHORS 
                              Set AUTHOR_LNAME = :lname, 
                              AUTHOR_FNAME  = :fname,
                              AUTHOR_MNAME  = :mi,
                              AUTHOR_EMAIL  = :email,
                              AUTHOR_ASSOC  = :association,
                              AUTHOR_DEPT = :dept
                              Where AUTHOR_ID = :authID";

            NpgsqlCMD.Parameters.Add(new NpgsqlParameter(":lname", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter(":fname", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("mi", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("email", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("association", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("dept", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("authID", NpgsqlDbType.Integer));
            NpgsqlCMD.Parameters[0].Value = a.LastName;
            NpgsqlCMD.Parameters[1].Value = a.FirstName;
            NpgsqlCMD.Parameters[2].Value = a.MI;
            NpgsqlCMD.Parameters[3].Value = a.Email;
            NpgsqlCMD.Parameters[4].Value = a.Association;
            NpgsqlCMD.Parameters[5].Value = a.Department;
            NpgsqlCMD.Parameters[6].Value = a.ID;

            if(GlobalVariables.GlobalConnection.updateData(NpgsqlCMD))
                MessageBox.Show("Author record has been updated.", "Author Updated", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
                MessageBox.Show("Author record has not been inserted.", "Author Not Updated", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Пример #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Author rec = new Author();
            rec.LastName = cbLName.Text;
            rec.FirstName = txtFName.Text;
            rec.MI = txtMI.Text;
            rec.Department = txtDept.Text;
            rec.Email = txtEmail.Text;
            rec.Association = txtAff.Text;

            if (bIsEdit)
            {
                rec.ID = Convert.ToInt32(cbLName.SelectedValue);
                _authors.updateRecord(rec);
            }
            else
                _authors.insertRecord(rec);

            txtFName.Enabled = false;
            txtMI.Enabled = false;
            txtEmail.Enabled = false;
            txtAff.Enabled = false;
            txtDept.Enabled = false;
            cbLName.DropDownStyle = ComboBoxStyle.DropDownList;
            SetAuthors();

            int id = cbLName.Items.Count - 1;
            cbLName.SelectedIndex = id;

            btnNew.Enabled = true;
            btnEdit.Enabled = true;
            btnDel.Enabled = true;
            btnTakePic.Enabled = true;
            btnDelPic.Enabled = true;
            btnSave.Enabled = false;

            bHasChanged = true;

        }