Пример #1
0
        private void btn_Luu_Click(object sender, EventArgs e)
        {
            if (txt_Ten.Text != "")
            {
                #region thao tac them
                if (AddFlag)
                {
                    if (MessageBox.Show("Bạn thực sự muốn thêm văn bằng này ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        //Department = ToDepartmentObject();
                        int?id        = null;
                        int?trinhdoid = null;
                        if (comB_TrinhDo.Text != "")
                        {
                            trinhdoid = Convert.ToInt32(comB_TrinhDo.SelectedValue.ToString());
                        }

                        try
                        {
                            vanbang = new VanBangChinhQuy(id, txt_Ten.Text, trinhdoid, rtb_MoTa.Text);
                            vanbang.Add();
                            MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            ResetInterface(true);
                            RefreshDataSource();

                            return;
                        }
                        catch
                        {
                            MessageBox.Show("Thao tác thêm thất bại.", "Lỗi", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        }
                    }
                }
                #endregion
                #region thao tac sua
                else                // thao tac sua
                {
                    if (MessageBox.Show("Bạn thực sự muốn sửa văn bằng này ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        int id        = Convert.ToInt16(dtgv_DSVanBang.CurrentRow.Cells["id"].Value.ToString());
                        int?trinhdoid = null;
                        if (comB_TrinhDo.Text != "")
                        {
                            trinhdoid = Convert.ToInt32(comB_TrinhDo.SelectedValue.ToString());
                        }

                        try
                        {
                            vanbang = new VanBangChinhQuy(id, txt_Ten.Text, trinhdoid, rtb_MoTa.Text);
                            vanbang.Update();
                            MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            ResetInterface(true);
                            RefreshDataSource();

                            return;
                        }
                        catch
                        {
                            MessageBox.Show("Thao tác sửa thất bại.", "Lỗi", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        }
                    }
                }
                #endregion
            }
            else
            {
                MessageBox.Show("Tên văn bằng không được rỗng, xin vui lòng cung cấp tên văn bằng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        private void btn_Luu_Click(object sender, EventArgs e)
        {
            if (txt_Ten.Text != "")
            {
                #region thao tac them
                if (AddFlag)
                {
                    if (MessageBox.Show("Bạn thực sự muốn thêm văn bằng này ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        //Department = ToDepartmentObject();
                        int? id = null;
                        int? trinhdoid = null;
                        if (comB_TrinhDo.Text != "")
                            trinhdoid = Convert.ToInt32(comB_TrinhDo.SelectedValue.ToString());
                        
                        try
                        {
                            vanbang = new VanBangChinhQuy(id, txt_Ten.Text, trinhdoid, rtb_MoTa.Text);
                            vanbang.Add();
                            MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            ResetInterface(true);
                            RefreshDataSource();

                            return;
                        }
                        catch
                        {
                            MessageBox.Show("Thao tác thêm thất bại.", "Lỗi", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        }

                    }

                }
                #endregion
                #region thao tac sua
                else                // thao tac sua
                {
                    if (MessageBox.Show("Bạn thực sự muốn sửa văn bằng này ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        int id = Convert.ToInt16(dtgv_DSVanBang.CurrentRow.Cells["id"].Value.ToString());
                        int? trinhdoid = null;
                        if (comB_TrinhDo.Text != "")
                            trinhdoid = Convert.ToInt32(comB_TrinhDo.SelectedValue.ToString());
                        
                        try
                        {
                            vanbang = new VanBangChinhQuy(id, txt_Ten.Text, trinhdoid, rtb_MoTa.Text);
                            vanbang.Update();
                            MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            ResetInterface(true);
                            RefreshDataSource();

                            return;
                        }
                        catch
                        {
                            MessageBox.Show("Thao tác sửa thất bại.", "Lỗi", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                        }

                    }
                }
                #endregion
            }
            else
                MessageBox.Show("Tên văn bằng không được rỗng, xin vui lòng cung cấp tên văn bằng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }