コード例 #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (dgvAuthor.SelectedCells.Count > 0)
     {
         int selectedrowindex = dgvAuthor.SelectedCells[0].RowIndex;
         DataGridViewRow selectedRow = dgvAuthor.Rows[selectedrowindex];
         int id = Convert.ToInt32(selectedRow.Cells["clmnId"].Value);
         DialogResult result = MessageBox.Show("Do you want to delete author: " + selectedRow.Cells["clmnName"].Value + "?", "Warning", MessageBoxButtons.OKCancel);
         switch (result)
         {
             case DialogResult.Cancel:
                 break;
             case DialogResult.OK:
                 AuthorBLL authorBLL = new AuthorBLL(Convert.ToInt32(selectedRow.Cells["clmnId"].Value), selectedRow.Cells["clmnName"].Value.ToString(), selectedRow.Cells["clmnWorkPlace"].Value.ToString());
                 if (AuthorDAL.getAuthorItem(authorBLL) != null)
                 {
                     MessageBox.Show("Can't delete! Please delete all book of " + selectedRow.Cells["clmnName"].Value + " before delete this author!", "Error");
                     break;
                 }
                 else
                 {
                     AuthorDAL.deleteAuthor(authorBLL);
                     MessageBox.Show("Delete complete!", "Success");
                     this.LoadDataToGridView();
                     break;
                 }
         }
     }
 }
コード例 #2
0
 public static AuthorBLL getAuthorItem(AuthorBLL authorBLL)
 {
     String sql = "SELECT * FROM [tacgia] WHERE matacgia=" + authorBLL.AuthorId;
     DataTable dt = TypeOfBookDAL._condb.getDataTable(sql);
     if (dt.Rows.Count > 0)
     {
         DataRow row = dt.Rows[0];
         return new AuthorBLL(Int32.Parse(row["matacgia"].ToString()), row["tentacgia"].ToString(), row["noicongtac"].ToString());
     }
     return null;
 }
コード例 #3
0
 public static List<AuthorBLL> search(string catalog, string key)
 {
     string sql = "SELECT * FROM [tacgia] WHERE " + catalog + " LIKE '%" + key + "%'";
     DataTable dt = AuthorDAL._condb.getDataTable(sql);
     List<AuthorBLL> authorList = new List<AuthorBLL>();
     foreach (DataRow row in dt.Rows)
     {
         AuthorBLL authorBLL = new AuthorBLL(Int32.Parse(row["matacgia"].ToString()), row["tentacgia"].ToString(), row["noicongtac"].ToString());
         authorList.Add(authorBLL);
     }
     return authorList;
 }
コード例 #4
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     AuthorBLL authorBLL = new AuthorBLL();
     authorBLL.Name = this.txtAuthorName.Text;
     authorBLL.WorkPlace = this.txtWorkPlace.Text;
     if (authorBLL.Name == "")
     {
         MessageBox.Show("Author name is not null!", "Notice");
         return;
     }
     AuthorDAL.addAuthor(authorBLL);
     MessageBox.Show("Add success!", "Success");
     this.LoadDataToGridView();
 }
コード例 #5
0
 public static List<AuthorBLL> getAuthorList()
 {
     string sql = "SELECT * FROM [tacgia]";
     DataTable dt = AuthorDAL._condb.getDataTable(sql);
     if (dt.Rows.Count > 0)
     {
         List<AuthorBLL> authorList = new List<AuthorBLL>();
         foreach (DataRow row in dt.Rows)
         {
             AuthorBLL authorBLL = new AuthorBLL(Int32.Parse(row["matacgia"].ToString()), row["tentacgia"].ToString(), row["noicongtac"].ToString());
             authorList.Add(authorBLL);
         }
         return authorList;
     }
     return null;
 }
コード例 #6
0
 private void setSelectedValueComboboxAuthor(AuthorBLL authorBLL)
 {
     foreach (ComboboxItem item in this.cboAuthor.Items)
     {
         if (Convert.ToInt32(item.Value) == authorBLL.AuthorId)
             this.cboAuthor.SelectedItem = item;
     }
 }
コード例 #7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (dgvAuthor.SelectedCells.Count > 0)
            {

                int selectedrowindex = dgvAuthor.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = dgvAuthor.Rows[selectedrowindex];

                AuthorBLL authorBLL = new AuthorBLL(Convert.ToInt32(selectedRow.Cells["clmnId"].Value), txtAuthorName.Text, txtWorkPlace.Text);

                if (authorBLL.Name == "")
                {
                    MessageBox.Show("Author name is not null!", "Notice");
                    return;
                }
                AuthorDAL.updateAuthor(authorBLL);
                MessageBox.Show("Update success!", "Success");
                this.LoadDataToGridView();
            }
        }
コード例 #8
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string key = this.txtSearch.Text;
            string catalog = "";
            if (key == "".Trim())
            {
                MessageBox.Show("Please enter keyword!", "Notice");
                return;
            }
            if (this.cboSearch.SelectedItem.ToString() == "Work Place")
            {
                catalog = "noicongtac";
            }
            else
            {
                catalog = "tentacgia";
            }
            AuthorBLL authorBLL = new AuthorBLL();
            List<AuthorBLL> authorArr = new List<AuthorBLL>();
            authorArr = AuthorDAL.search(catalog, key);
            this.dgvAuthor.Rows.Clear();
            foreach (AuthorBLL row in authorArr)
            {
                this.dgvAuthor.Rows.Add(row.AuthorId, row.Name, row.WorkPlace);
            }
            this.GetSelectedValue();

            this.dgvAuthor.CellClick += new DataGridViewCellEventHandler(dgvAuthor_CellClick);
        }
コード例 #9
0
 public static void updateAuthor(AuthorBLL authorBLL)
 {
     String sql = "UPDATE [tacgia] SET tentacgia=N'" + authorBLL.Name + "', noicongtac=N'" + authorBLL.WorkPlace + "' WHERE matacgia=" + authorBLL.AuthorId;
         AuthorDAL._condb.ExecuteNonQuery(sql);
 }
コード例 #10
0
 public static void deleteAuthor(AuthorBLL authorBLL)
 {
     String sql = "DELETE FROM [tacgia] WHERE matacgia=" + authorBLL.AuthorId;
     AuthorDAL._condb.ExecuteNonQuery(sql);
 }
コード例 #11
0
 public static void addAuthor(AuthorBLL authorBLL)
 {
     String sql = "INSERT INTO [tacgia] (tentacgia, noicongtac) VALUES ( N'" + authorBLL.Name + "', N'" + authorBLL.WorkPlace + "')";
     AuthorDAL._condb.ExecuteNonQuery(sql);
 }