Exemplo n.º 1
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 Mod_TypeInfor GetInfor(Int16 ID)
 {
     DataSet ds = new Mod_TypeController().GetData("Mod_Type_ID=" + ID );
     Mod_TypeInfor Infor = new Mod_TypeInfor();
     if (ds != null)
     {
         if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
         {
             Infor.Mod_Type_ID = Utility.Int16Dbnull(ds.Tables[0].Rows[0]["Mod_Type_ID"]);
             Infor.Mod_Type_Code = Utility.sDbnull(ds.Tables[0].Rows[0]["Mod_Type_Code"]);
             Infor.Mod_Type_Name = Utility.sDbnull(ds.Tables[0].Rows[0]["Mod_Type_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;
     }
 }
Exemplo n.º 2
0
        private void LoadDeviceType()
        {
            try
            {
                DataTable dtmod_Type = new Mod_TypeController().GetAllData().Tables[0];
                DataTable dtmod_Type1 = dtmod_Type.Copy();
                Utility.AddColumnAlltoDataTable(ref dtmod_Type, "Mod_Type_ID", "Mod_Type_Name", "");
                dtmod_Type.DefaultView.Sort = "Mod_Type_Name ASC";
                //cboSearchModType.DataSource = dtmod_Type.DefaultView;
                //cboSearchModType.DisplayMember = "Mod_Type_Name";
                //cboSearchModType.ValueMember = "Mod_Type_ID";

                dtmod_Type1.DefaultView.Sort = "Mod_Type_Name ASC";
                cboModType.DataSource = dtmod_Type1.DefaultView;
                cboModType.DisplayMember = "Mod_Type_Name";
                cboModType.ValueMember = "Mod_Type_ID";
                //if (cboSearchModType.Items.Count > 0) cboSearchModType.SelectedIndex = 0;
                if (cboModType.Items.Count > 0) cboModType.SelectedIndex = 0;
            }
            catch
            {
            }
        }
Exemplo n.º 3
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 Mod_TypeEntity vào DataEntity
            SetValueforEntity();

            //Khởi tạo BusinessRule để xử lý nghiệp vụ
            Mod_TypeInfor Infor = new Mod_TypeInfor();
            Utility.MapValueFromEntityIntoObjectInfor(Infor, Mod_TypeEntity);
            Mod_TypeController _BusRule = new Mod_TypeController(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à Mod_TypeEntity có cấu trúc giống nhau mới dùng hàm này
                        DataRow dr = Utility.CopyData(Mod_TypeEntity.Rows[0], DataSource);
                        dr["Mod_Type_ID"] = Infor.Mod_Type_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, "colMod_Type_ID", Infor.Mod_Type_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 loạ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 loạ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, "Mod_Type_ID", txtID.Text.Trim());
                        if (dr != null)
                        {
                            Utility.CopyData(Mod_TypeEntity.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, "colMod_Type_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 loại thiết bị. Liên hệ với VBIT",true);
                                break;
                            default:
                               mdlStatic.SetMsg(lblMsg,"Lỗi khi cập nhật loại 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 loại thiết bị đang chọn hay không?", "Xác nhận xóa", true))
                    {
                        string Mod_Type_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, "Mod_Type_ID", Mod_Type_ID);
                            if (dr != null)
                            {
                                DataSource.Rows.Remove(dr);
                                DataSource.AcceptChanges();
                            }
                            //Return to the InitialStatus
                            Act = action.FirstOrFinished;
                            mdlStatic.SetMsg(lblMsg, "Đã xóa loại thiết bị có ID: " + Mod_Type_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, "loại thiết bị có ID: " + Mod_Type_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 loại thiết bị. Liên hệ với VBIT",true);
                                    break;
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
        }