Exemple #1
0
        private void btnDoctor_Click_1(object sender, EventArgs e)
        {
            try
            {
                grdAll.DataSource = null;
                //xóa dữ liệu trên grid
                grdAll.Rows.Clear();
                grdAll.Columns.Clear();
                grdAll.Tag = btnDoctor.Tag;

                //Cột ID (UserId)
                grdAll.Columns.Add(Utilities.UI.CreateGridTextColumn(LUser.Columns.UserId, "ID",
                                                                     LUser.Columns.UserId, null, true));

                //Cột UserName
                grdAll.Columns.Add(Utilities.UI.CreateGridTextColumn(LUser.Columns.UserName, "Tên bác sỹ",
                                                                     LUser.Columns.UserName));

                //Cột RoleId
                grdAll.Columns.Add(Utilities.UI.CreateGridTextColumn(LUser.Columns.RoleId, "Vai trò",
                                                                     LUser.Columns.RoleId));
                grdAll.DataSource = DoctorBusiness.GetAllDoctor();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        /// Xử lý thêm mới và update cho bảng Doctor
        public void UpdateDoctor()
        {
            LUser  pitems;
            string Username = "", RoleId = "";
            var    dataTable = grdAll.DataSource as DataTable;

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                DataRow dr = dataTable.Rows[i];
                object  c  = dr[LUser.Columns.UserId];
                //Kiểm tra trạng thái của dòng:
                if ((dr.RowState == DataRowState.Modified) || (dr.RowState == DataRowState.Added))
                {
                    Username = dr[LUser.Columns.UserName].ToString();
                    RoleId   = dr[LUser.Columns.RoleId].ToString();
                    if ((Username == "") || (RoleId == ""))
                    {
                        SetTextForWarning(MsgEror);
                        continue;
                    }
                }
                if (dr.RowState == DataRowState.Modified)
                {
                    pitems          = new LUser(dr[LUser.Columns.UserId]);
                    pitems.UserName = Username;
                    pitems.RoleId   = Convert.ToInt32(RoleId);
                    DoctorBusiness.UpdateDoctor(pitems);
                    SetTextForWarning(MsgUpdate);
                }
                else if (dr.RowState == DataRowState.Added)
                {
                    pitems                   = new LUser();
                    pitems.UserName          = Username;
                    pitems.RoleId            = Convert.ToInt32(RoleId);
                    dr[LUser.Columns.UserId] = DoctorBusiness.InsertDoctor(pitems);
                    SetTextForWarning(MsgNew);
                }
            }
            dataTable.AcceptChanges();
        }
Exemple #3
0
        ////Xử lý xóa dữ liệu trên bảng Doctor
        private void DeleteDocTor()
        {
            try
            {
                DataGridViewRow currentRow = grdAll.CurrentRow;

                if (currentRow != null)
                {
                    string pid = Utilities.UI.GetCellValue(currentRow.Cells[LUser.Columns.UserId]);
                    if (pid != "")
                    {
                        // int pid = Convert.ToInt32(.Value);
                        if (
                            MessageBox.Show("Bạn có muốn xóa ?", "Thông báo", MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question) ==
                            DialogResult.Yes)
                        {
                            DoctorBusiness.DeleteDoctor(Convert.ToInt32(pid));
                            grdAll.Rows.Remove(currentRow);
                            SetTextForWarning(MsgDelete);
                        }
                    }
                    else
                    {
                        SetTextForWarning(MsgEror);
                    }
                }
            }
            catch (Exception ex)
            {
                SetTextForWarning(MsgEror);
            }
            finally
            {
                (grdAll.DataSource as DataTable).AcceptChanges();
            }
        }