Пример #1
0
        /// <summary>
        /// Tạo DataRow của Entity từ ObjectInfor
        /// </summary>
        /// <param name="dr">DataRow</param>
        /// <param name="Infor">ObjectInfor</param>
        public static void CreateDatarowFromObjectInfor(ref DataRow dr, RoomInfor Infor)
        {

            if (Infor != null)
            {
                dr["Department_ID"] = Infor.Department_ID;
                dr["Department_Name"] = Utility.sDbnull(Infor.Department_Name);
                dr["Room_ID"] =Infor.Room_ID;
                dr["Room_Code"] = Utility.sDbnull(Infor.Room_Code);
                dr["Room_Name"] = Utility.sDbnull(Infor.Room_Name);
                dr["Pos"] = Utility.Int16Dbnull(Infor.Pos);
                dr["Desc"] = Utility.sDbnull(Infor.Desc);
            }
        }
Пример #2
0
 public RoomController(RoomInfor Infor)
 {
     this.Infor = Infor;
 }
Пример #3
0
        /// <summary>
        /// Trả về đối tượng Infor dựa vào Primary key của nó
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static RoomInfor GetInfor(DataRow dr)
        {
            RoomInfor Infor = new RoomInfor();
            if (dr != null)
            {

                Infor.Room_Code = Utility.sDbnull(dr["Room_Code"]);
                Infor.Room_ID = Utility.Int16Dbnull(dr["Room_ID"]);
                Infor.Department_ID = Utility.Int16Dbnull(dr["Department_ID"]);
                Infor.Department_Name = Utility.sDbnull(dr["Department_Name"]);
                Infor.Room_Name = Utility.sDbnull(dr["Room_Name"]);
                Infor.Pos = Utility.Int16Dbnull(dr["Pos"]);
                Infor.Desc = Utility.sDbnull(dr["Desc"]);
                    return Infor;
            }
            else
            {
                return null;
            }
        }
Пример #4
0
 /// <summary>
 /// Trả về đối tượng Infor dựa vào Primary key của nó
 /// </summary>
 /// <param name="ID"></param>
 /// <returns></returns>
 public static RoomInfor GetInfor(Int16 ID)
 {
     DataSet ds = new RoomController().GetData("Room_ID=" + ID );
     RoomInfor Infor = new RoomInfor();
     if (ds != null)
     {
         if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
         {
             Infor.Department_ID = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["Department_ID"]);
             Infor.Department_Name = Utility.sDbnull(ds.Tables[0].Rows[0]["Department_Name"]);
             Infor.Room_ID = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["Room_ID"]);
             Infor.Room_Code = Utility.sDbnull(ds.Tables[0].Rows[0]["Room_Code"]);
             Infor.Room_Name = Utility.sDbnull(ds.Tables[0].Rows[0]["Room_Name"]);
             Infor.Pos = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["Pos"]);
             Infor.Desc = Utility.sDbnull(ds.Tables[0].Rows[0]["Desc"]);
             return Infor;
         }
         else
         {
             return null;
         }
     }
     else
     {
         return null;
     }
 }
Пример #5
0
        private void ExecuteAction()
        {
            //Kiểm tra tính hợp lệ của dữ liệu trước khi thêm mới
            if (!IsValidData())
            {
                return;
            }
            //Gán RoomEntity vào DataEntity
            SetValueforEntity();

            //Khởi tạo BusinessRule để xử lý nghiệp vụ
            RoomInfor Infor = new RoomInfor();
            Utility.MapValueFromEntityIntoObjectInfor(Infor, RoomEntity);
            RoomController _BusRule = new RoomController(Infor);
            switch (Act)
            {
                case action.Insert:
                    //Gọi nghiệp vụ Insert dữ liệu
                    ActionResult InsertResult = _BusRule.Insert();
                    if (InsertResult == ActionResult.Success)//Nếu thành công
                    {
                        //Thêm mới một dòng vào Datasource để cập nhật lại dữ liệu trên DataGridView
                        //phải đảm bảo Datasource và RoomEntity có cấu trúc giống nhau mới dùng hàm này
                        DataRow dr = Utility.CopyData(RoomEntity.Rows[0], DataSource);
                        dr["Room_ID"] = Infor.Room_ID;
                        if (dr != null)//99.99% là sẽ !=null
                        {
                            DataSource.Rows.Add(dr);
                            DataSource.AcceptChanges();
                        }
                        //Return to the InitialStatus
                        Act = action.FirstOrFinished;
                        //Nhảy đến bản ghi vừa thêm mới trên lưới. Do txtID chưa bị reset nên dùng luôn
                        Utility.GotoNewRow(grdList, "colRoom_ID", Infor.Room_ID.ToString());
                       mdlStatic.SetMsg(lblMsg,"Thêm mới dữ liệu thành công!",false);

                        SetControlStatus();
                        CurrentCellChanged();
                    }
                    else//Có lỗi xảy ra
                    {
                        switch (InsertResult)
                        {
                            case ActionResult.ExistedRecord:
                                mdlStatic.SetMsg(lblMsg, "Đã tồn tại Phòng có mã: " + txtCode.Text.Trim() + ". Đề nghị bạn xem lại",true);
                               Utility.FocusAndSelectAll( txtCode);
                                break;
                            default:
                               mdlStatic.SetMsg(lblMsg,"Lỗi trong quá trình thêm mới Phòng. Liên hệ với VBIT",true);
                                break;
                        }
                    }
                    break;
                case action.Update:
                    //Gọi Business cập nhật dữ liệu
                    ActionResult UpdateResult = _BusRule.Update();
                    if (UpdateResult == ActionResult.Success)//Nếu thành công
                    {
                        //Cập nhật số thứ tự cho bản ghi tráo số thứ tự với bản ghi đang được cập nhật(nếu có)?
                        foreach (DataRow drUpdatePos in DataSource.Rows)
                        {
                            if (Utility.Int16Dbnull(drUpdatePos["Pos"]) == Convert.ToInt16(txtPos.Text))
                            {
                                drUpdatePos["Pos"] = OldPos;
                                break; // TODO: might not be correct. Was : Exit For
                            }
                        }
                        DataSource.AcceptChanges();
                        //Cập nhật dòng hiện thời trong Datasource để cập nhật lại dữ liệu trên DataGridView
                        DataRow dr = Utility.GetDataRow(DataSource, "Room_ID", txtID.Text.Trim());
                        if (dr != null)
                        {
                            Utility.CopyData(RoomEntity.Rows[0], ref dr);
                            DataSource.AcceptChanges();
                        }
                        //Return to the InitialStatus
                        Act = action.FirstOrFinished;
                        //Nhảy đến bản ghi vừa cập nhật trên lưới. Do txtID chưa bị reset nên dùng luôn
                        Utility.GotoNewRow(grdList, "colRoom_ID", txtCode.Text.Trim());
                       mdlStatic.SetMsg(lblMsg,"Cập nhật dữ liệu thành công.",false);
                        SetControlStatus();
                        CurrentCellChanged();
                    }
                    else//Có lỗi xảy ra
                    {
                        switch (UpdateResult)
                        {
                            case ActionResult.Error:
                               mdlStatic.SetMsg(lblMsg,"Lỗi khi cập nhật Phòng. Liên hệ với VBIT",true);
                                break;
                            default:
                               mdlStatic.SetMsg(lblMsg,"Lỗi khi cập nhật Phòng. Liên hệ với VBIT",true);
                                break;
                        }
                    }
                    break;

                case action.Delete:
                    if (Utility.AcceptQuestion("Bạn có muốn xóa Phòng đang chọn hay không?", "Xác nhận xóa", true))
                    {
                        string Room_ID = txtID.Text.Trim();
                        //Gọi nghiệp vụ xóa dữ liệu
                        ActionResult DeleteResult = _BusRule.Delete();
                        if (DeleteResult == ActionResult.Success)//Nếu xóa thành công trong CSDL
                        {
                            //Xóa dòng dữ liệu vừa chọn trong Datasource để cập nhật lại dữ liệu trên DataGridView
                            DataRow dr = Utility.GetDataRow(DataSource, "Room_ID", Room_ID);
                            if (dr != null)
                            {
                                DataSource.Rows.Remove(dr);
                                DataSource.AcceptChanges();
                            }
                            //Return to the InitialStatus
                            Act = action.FirstOrFinished;
                            mdlStatic.SetMsg(lblMsg, "Đã xóa Phòng có ID: " + Room_ID + " ra khỏi hệ thống.", false);
                            SetControlStatus();
                            CurrentCellChanged();
                        }
                        else//Có lỗi xảy ra
                        {
                            switch (DeleteResult)
                            {
                                case ActionResult.DataHasUsedinAnotherTable:
                                    mdlStatic.SetMsg(lblMsg, "Phòng có ID: " + Room_ID + " đã được sử dụng trong bảng khác nên bạn không thể xóa!", true);
                                    break;
                                default:
                                   mdlStatic.SetMsg(lblMsg,"Lỗi khi xóa Phòng. Liên hệ với VBIT",true);
                                    break;
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
        }