Esempio n. 1
0
        private void ExecuteAction()
        {
            try
            {
                //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 ModalityEntity vào DataEntity
                SetValueforEntity();

                //Khởi tạo BusinessRule để xử lý nghiệp vụ
                ModalityInfor Infor = new ModalityInfor();
                Utility.MapValueFromEntityIntoObjectInfor(Infor, ModalityEntity);
                ModalityController _BusRule = new ModalityController(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à ModalityEntity có cấu trúc giống nhau mới dùng hàm này
                            DataRow dr = Utility.CopyData(ModalityEntity.Rows[0], DataSource);
                            dr["Modality_ID"] = Infor.Modality_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, "colModality_ID", Infor.Modality_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 thiết bị 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 thiết bị. 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, "Modality_ID", txtID.Text.Trim());
                            if (dr != null)
                            {
                                Utility.CopyData(ModalityEntity.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, "colModality_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 thiết bị. Liên hệ với VBIT", true);
                                    break;
                                default:
                                    mdlStatic.SetMsg(lblMsg, "Lỗi khi cập nhật thiết bị. Liên hệ với VBIT", true);
                                    break;
                            }
                        }
                        break;

                    case action.Delete:
                        if (Utility.AcceptQuestion("Bạn có muốn xóa thiết bị đang chọn hay không?", "Xác nhận xóa", true))
                        {
                            string Modality_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, "Modality_ID", Modality_ID);
                                if (dr != null)
                                {
                                    DataSource.Rows.Remove(dr);
                                    DataSource.AcceptChanges();
                                }
                                //Return to the InitialStatus
                                Act = action.FirstOrFinished;
                                mdlStatic.SetMsg(lblMsg, "Đã xóa thiết bị có ID: " + Modality_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, "thiết bị có ID: " + Modality_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 thiết bị. Liên hệ với VBIT", true);
                                        break;
                                }
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            catch
            {
            }
        }
Esempio n. 2
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, ModalityInfor Infor)
        {

            if (Infor != null)
            {
                dr["Modality_ID"] =Infor.Modality_ID;
                dr["Modality_Code"] = Utility.sDbnull(Infor.Modality_Code);
                dr["Modality_Name"] = Utility.sDbnull(Infor.Modality_Name);
                dr["Pos"] = Utility.Int16Dbnull(Infor.Pos);
                dr["Desc"] = Utility.sDbnull(Infor.Desc);

               dr["Mod_Type_ID"]= Utility.Int16Dbnull(Infor.Mod_Type_ID );
               dr["Manufacture_ID"]=  Utility.Int16Dbnull(Infor.Manufacture_ID);
               dr["Country_ID"] = Utility.sDbnull(Infor.Country_ID);
                dr["Room_ID"]=Utility.Int16Dbnull(Infor.Room_ID );
               dr["AE_TITLE"]=Utility.sDbnull( Infor.AE_TITLE);
               dr["RESTRICTION"]= Utility.sDbnull(Infor.RESTRICTION);
               dr["STATUS"] = Utility.ByteDbnull(Infor.STATUS);
                dr["PORT_NUM"]= Utility.Int16Dbnull(Infor.PORT_NUM );
                dr["DEVICE_WORKLIST"] = Utility.ByteDbnull(Infor.DEVICE_WORKLIST);

                dr["Country_Name"] = Utility.sDbnull(Infor.Country_Name);
                dr["Manufacture_Name"] = Utility.sDbnull(Infor.Manufacture_Name);
                dr["Room_Name"] = Utility.sDbnull(Infor.Room_Name);
                dr["Mod_Type_Name"] = Utility.sDbnull(Infor.Mod_Type_Name);

                dr["IMGH"]=Infor.IMGH;
                dr["IMGW"]=Infor.IMGW;
                dr["LOW"]=Infor.LOW;
                dr["HIGH"]=Infor.HIGH ;
                dr["StartColor"]=Infor.StartColor ;
                dr["EndColor"] = Infor.EndColor;
                dr["Range"]=Infor.Range ;
            }
        }
Esempio n. 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 ModalityInfor GetInfor(DataRow dr)
        {
            ModalityInfor Infor = new ModalityInfor();
            if (dr != null)
            {

                Infor.Modality_Code = Utility.sDbnull(dr["Modality_Code"]);
                Infor.Modality_ID = Utility.Int16Dbnull(dr["Modality_ID"]);
                Infor.Modality_Name = Utility.sDbnull(dr["Modality_Name"]);
                Infor.Pos = Utility.Int16Dbnull(dr["Pos"]);
                Infor.Desc = Utility.sDbnull(dr["Desc"]);
                Infor.Mod_Type_ID = Utility.Int16Dbnull(dr["Mod_Type_ID"]);
                Infor.Manufacture_ID = Utility.Int16Dbnull(dr["Manufacture_ID"]);
                Infor.Country_ID = Utility.sDbnull(dr["Country_ID"]);
                Infor.Room_ID = Utility.Int16Dbnull(dr["Room_ID"]);
                Infor.AE_TITLE = Utility.sDbnull(dr["AE_TITLE"]);
                Infor.RESTRICTION = Utility.sDbnull(dr["RESTRICTION"]);
                Infor.STATUS = Utility.ByteDbnull(dr["STATUS"]);
                Infor.PORT_NUM = Utility.Int16Dbnull(dr["PORT_NUM"]);
                Infor.DEVICE_WORKLIST = Utility.ByteDbnull(dr["DEVICE_WORKLIST"]);

                Infor.Country_Name = Utility.sDbnull(dr["Country_Name"]);
                Infor.Room_Name = Utility.sDbnull(dr["Room_Name"]);
                Infor.Manufacture_Name = Utility.sDbnull(dr["Manufacture_Name"]);
                Infor.Mod_Type_Name = Utility.sDbnull(dr["Mod_Type_Name"]);

                Infor.IMGH = Utility.Int32Dbnull(dr["IMGH"]);
                Infor.IMGW = Utility.Int32Dbnull(dr["IMGW"]);
                Infor.LOW = Utility.Int32Dbnull(dr["LOW"]);
                Infor.HIGH = Utility.Int32Dbnull(dr["HIGH"]);
                Infor.StartColor = Utility.Int32Dbnull(dr["StartColor"]);
                Infor.EndColor = Utility.Int32Dbnull(dr["EndColor"]);
                Infor.Range = Utility.sDbnull(dr["Range"]);

                Infor.AUTO_FLIPH = Utility.Int32Dbnull(dr["AUTO_FLIPH"]);
                Infor.AUTO_FLIPV = Utility.Int32Dbnull(dr["AUTO_FLIPV"]);

                
                    return Infor;
            }
            else
            {
                return null;
            }
        }
Esempio n. 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 ModalityInfor GetInfor(Int16 ID)
        {
            DataSet ds = new ModalityController().GetData("Modality_ID=" + ID );
            ModalityInfor Infor = new ModalityInfor();
            if (ds != null)
            {
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    Infor.Modality_ID = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["Modality_ID"]);
                    Infor.Modality_Code = Utility.sDbnull(ds.Tables[0].Rows[0]["Modality_Code"]);
                    Infor.Modality_Name = Utility.sDbnull(ds.Tables[0].Rows[0]["Modality_Name"]);
                    Infor.Pos = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["Pos"]);
                    Infor.Desc = Utility.sDbnull(ds.Tables[0].Rows[0]["Desc"]);
                    Infor.Mod_Type_ID = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["Mod_Type_ID"]);
                    Infor.Manufacture_ID = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["Manufacture_ID"]);
                    Infor.Country_ID = Utility.sDbnull(ds.Tables[0].Rows[0]["Country_ID"]);
                    Infor.Room_ID = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["Room_ID"]);
                    Infor.AE_TITLE = Utility.sDbnull(ds.Tables[0].Rows[0]["AE_TITLE"]);
                    Infor.RESTRICTION = Utility.sDbnull(ds.Tables[0].Rows[0]["RESTRICTION"]);
                    Infor.STATUS = Utility.ByteDbnull(ds.Tables[0].Rows[0]["STATUS"]);
                    Infor.PORT_NUM = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["PORT_NUM"]);
                    Infor.DEVICE_WORKLIST = Utility.ByteDbnull(ds.Tables[0].Rows[0]["DEVICE_WORKLIST"]);

                    Infor.Country_Name = Utility.sDbnull(ds.Tables[0].Rows[0]["Country_Name"]);
                    Infor.Room_Name = Utility.sDbnull(ds.Tables[0].Rows[0]["Room_Name"]);
                    Infor.Manufacture_Name = Utility.sDbnull(ds.Tables[0].Rows[0]["Manufacture_Name"]);
                    Infor.Mod_Type_Name = Utility.sDbnull(ds.Tables[0].Rows[0]["Mod_Type_Name"]);

                    Infor.IMGH = Utility.Int32Dbnull(ds.Tables[0].Rows[0]["IMGH"]);
                    Infor.IMGW = Utility.Int32Dbnull(ds.Tables[0].Rows[0]["IMGW"]);
                    Infor.LOW = Utility.Int32Dbnull(ds.Tables[0].Rows[0]["LOW"]);
                    Infor.HIGH = Utility.Int32Dbnull(ds.Tables[0].Rows[0]["HIGH"]);
                    Infor.StartColor = Utility.Int32Dbnull(ds.Tables[0].Rows[0]["StartColor"]);
                    Infor.EndColor = Utility.Int32Dbnull(ds.Tables[0].Rows[0]["EndColor"]);
                    Infor.Range = Utility.sDbnull(ds.Tables[0].Rows[0]["Range"]);
                    Infor.AUTO_FLIPH = Utility.Int32Dbnull(ds.Tables[0].Rows[0]["AUTO_FLIPH"]);
                    Infor.AUTO_FLIPV = Utility.Int32Dbnull(ds.Tables[0].Rows[0]["AUTO_FLIPV"]);
                    return Infor;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
Esempio n. 5
0
 public ModalityController(ModalityInfor Infor)
 {
     this.Infor = Infor;
 }