//Các phương thức khởi tạo của Class #region "Constructors" public frm_dmuc_doituongkcb() { InitializeComponent(); m_Query = DmucDoituongkcb.CreateQuery(); InitEvents(); }
/// <summary> /// Thực hiện nghiệp vụ Update dữ liệu /// </summary> private void PerformUpdateAction() { //Create Again to ignore Where Clause m_Query = DmucDoituongkcb.CreateQuery(); //Gọi Business cập nhật dữ liệu int v_intObjectTypeID = Convert.ToInt32(txtID.Text); //Kiểm tra trùng tên đối tượng và cảnh báo DmucDoituongkcbCollection v_arrSameNameObject = new DmucDoituongkcbController() .FetchByQuery(m_Query.AddWhere(DmucDoituongkcb.Columns.TenDoituongKcb, Comparison.Equals, txtName.Text.Trim().ToUpper()) .AND(DmucDoituongkcb.Columns.IdDoituongKcb, Comparison.NotEquals, v_intObjectTypeID)); if (v_arrSameNameObject.Count > 0) { if (!Utility.AcceptQuestion("Đã có đối tượng có tên:" + txtName.Text.Trim() + ". Bạn có muốn tiếp tục ghi hay không?", "Cảnh báo", true)) { return; } } int actionResult = CreateObjectType(); if (actionResult > -1) { m_DataSource.Sort(DmucDoituongkcb.Columns.SttHthi, true); ProcessData1(); //Return to the InitialStatus m_enAction = 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.GotoNewRowJanus(grdList, DmucDoituongkcb.Columns.IdLoaidoituongKcb, txtID.Text.Trim()); SetControlStatus(); Utility.ShowMsg("Cập nhật dữ liệu thành công."); } else { Utility.ShowMsg("Bạn gặp lỗi trong quá trình cập nhập", "Thông báo"); return; } }
/// <summary> /// Thực hiện nghiệp vụ Insert dữ liệu /// </summary> private void PerformInsertAction() { //Kiểm tra trùng tên đối tượng và cảnh báo DmucDoituongkcbCollection v_arrSameNameObject = new DmucDoituongkcbController().FetchByQuery(m_Query.AddWhere(DmucDoituongkcb.Columns.TenDoituongKcb, txtName.Text.Trim().ToUpper())); if (v_arrSameNameObject.Count > 0) { if (!Utility.AcceptQuestion("Đã có đối tượng có tên:" + txtName.Text.Trim() + ". Bạn có muốn tiếp tục ghi hay không?", "Cảnh báo", true)) { //Create Again to ignore Where Clause txtName.Focus(); m_Query = DmucDoituongkcb.CreateQuery(); return; } } //Create Again to ignore Where Clause m_Query = DmucDoituongkcb.CreateQuery(); // Lấy về MaxID vừa được thêm vào CSDL int actionResult = CreateObjectType(); if (actionResult > 0) { ProcessData(actionResult); //Return to the InitialStatus m_enAction = 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.GotoNewRowJanus(grdList, DmucDoituongkcb.Columns.IdLoaidoituongKcb, actionResult.ToString()); Utility.ShowMsg("Thêm mới dữ liệu thành công!"); SetControlStatus(); this.Activate(); } else//Có lỗi xảy ra { Utility.ShowMsg("Thêm mới không thành công. Mời bạn xem lại"); } }
/// <summary> /// Thực hiện nghiệp vụ Update dữ liệu /// </summary> private void PerformUpdateAction() { Utility.SetMsg(lblMsg, "", true); //Gọi Business cập nhật dữ liệu int v_shtIdLoaithuoc = Convert.ToInt32(txtID.Text); //Kiểm tra trùng tên đối tượng và cảnh báo DmucLoaithuocCollection v_arrSameObject = new DmucLoaithuocController().FetchByQuery(m_Query.AddWhere("ma_loaithuoc", txtDrug_Code.Text.Trim().ToUpper()).AND("Id_Loaithuoc", Comparison.NotEquals, v_shtIdLoaithuoc)); if (v_arrSameObject.Count > 0) { if (!Utility.AcceptQuestion("Đã có nhóm có mã:" + txtDrug_Code.Text.Trim() + ". Bạn có muốn tiếp tục ghi hay không?", "Cảnh báo", true)) { //Create Again to ignore Where Clause m_Query = DmucDoituongkcb.CreateQuery(); return; } } v_arrSameObject = new DmucLoaithuocController().FetchByQuery(m_Query.AddWhere("ten_loaithuoc", txtName.Text.Trim().ToUpper()).AND("Id_Loaithuoc", Comparison.NotEquals, v_shtIdLoaithuoc)); if (v_arrSameObject.Count > 0) { if (!Utility.AcceptQuestion("Đã có nhóm có tên:" + txtName.Text.Trim() + ". Bạn có muốn tiếp tục ghi hay không?", "Cảnh báo", true)) { //Create Again to ignore Where Clause m_Query = DmucDoituongkcb.CreateQuery(); return; } } //Create Again to ignore Where Clause m_Query = DmucLoaithuoc.CreateQuery(); DmucLoaithuoc v_NewObjectChangePos = null; DmucLoaithuoc objDrugType = DmucLoaithuoc.FetchByID(Convert.ToInt16(txtID.Text)); if (objDrugType != null) { objDrugType.MaLoaithuoc = Utility.sDbnull(txtDrug_Code.Text); objDrugType.TenLoaithuoc = Utility.sDbnull(txtName.Text); objDrugType.MotaThem = Utility.sDbnull(txtDesc.Text); objDrugType.MaNhomthuoc = Utility.sDbnull(txtNhom.myCode, ""); objDrugType.SttHthi = Convert.ToInt16(txtPos.Text); objDrugType.InRieng = Convert.ToInt16(chkInrieng.Checked ? 1 : 0); objDrugType.KieuThuocvattu = txtKieuthuocVT.myCode; objDrugType.IsNew = false; objDrugType.MarkOld(); objDrugType.Save(); } DataRow[] arrDr = m_dtLoaithuoc.Select(DmucLoaithuoc.Columns.IdLoaithuoc + "=" + txtID.Text); if (arrDr.Length > 0) { arrDr[0][DmucLoaithuoc.Columns.MaLoaithuoc] = Utility.sDbnull(txtDrug_Code.Text); arrDr[0][DmucLoaithuoc.Columns.TenLoaithuoc] = Utility.sDbnull(txtName.Text); arrDr[0][DmucLoaithuoc.Columns.MotaThem] = Utility.sDbnull(txtDesc.Text); arrDr[0][DmucLoaithuoc.Columns.MaNhomthuoc] = Utility.sDbnull(txtNhom.myCode, ""); arrDr[0][DmucLoaithuoc.Columns.SttHthi] = Convert.ToInt16(txtPos.Text); arrDr[0][DmucLoaithuoc.Columns.InRieng] = Convert.ToInt16(chkInrieng.Checked ? 1 : 0); arrDr[0][DmucLoaithuoc.Columns.KieuThuocvattu] = txtKieuthuocVT.myCode; arrDr[0]["ten_nhomthuoc"] = txtNhom.Text; } //Return to the InitialStatus m_enAction = 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.GotoNewRowJanus(grdList, "Id_Loaithuoc", txtID.Text.Trim()); SetControlStatus(); Utility.SetMsg(lblMsg, "Cập nhật dữ liệu thành công.", false); }
/// <summary> /// Thiết lập trạng thái các Control trên Form theo thao tác nghiệp vụ cần thực hiện /// Insert, Update hoặc Delete... /// </summary> private void SetControlStatus() { switch (m_enAction) { case action.Insert: //Cho phép nhập liệu mã loại đối tượng,vị trí, tên loại đối tượng và mô tả thêm Utility.DisabledTextBox(txtID); // Utility.EnabledTextBox(txtfee); Utility.EnabledTextBox(txtName); Utility.EnabledTextBox(txtPos); Utility.EnabledTextBox(txtDesc); txtObjectCode.Enabled = true; txtDiscountCorrectLine.Enabled = true; txtDiscountDiscorrectLine.Enabled = true; txtDiscountCorrectLine.Clear(); txtDiscountDiscorrectLine.Clear(); chkThanhtoantruockhikham.Enabled = true; chkAutoPayment.Enabled = true; chkLaygiathuocquanhe.Enabled = true; txtPos.Clear(); txtName.Clear(); txtDesc.Clear(); chkLaygiathuocquanhe.Checked = false; chkThanhtoantruockhikham.Checked = false; chkAutoPayment.Checked = false; Int16 MaxPos = Utility.Int16Dbnull(DmucDoituongkcb.CreateQuery().GetMax(DmucDoituongkcb.Columns.SttHthi), 0); MaxPos += 1; txtPos.Text = MaxPos.ToString(); m_shtOldPos = Convert.ToInt16(txtPos.Text); //-------------------------------------------------------------- //Thiết lập trạng thái các nút Insert, Update, Delete... //Không cho phép nhấn Insert, Update,Delete cmdInsert.Enabled = false; cmdUpdate.Enabled = false; cmdDelete.Enabled = false; //Cho phép nhấn nút Ghi cmdSave.Enabled = true; //Nút thoát biến thành nút hủy cmdClose.Text = "Hủy"; //-------------------------------------------------------------- //Không cho phép chọn trên lưới dữ liệu được fill vào các Control m_blnAllowCurrentCellChangedOnGridView = false; //Tự động Focus đến mục ID để người dùng nhập liệu txtID.Text = "Tự sinh"; txtPos.Focus(); break; case action.Update: //Không cho phép cập nhật lại mã loại đối tượng Utility.DisabledTextBox(txtID); //Cho phép cập nhật lại vị trí, tên loại đối tượng và mô tả thêm Utility.EnabledTextBox(txtName); Utility.EnabledTextBox(txtPos); Utility.EnabledTextBox(txtDesc); txtObjectCode.Enabled = true; txtDiscountCorrectLine.Enabled = true; txtDiscountDiscorrectLine.Enabled = true; chkLaygiathuocquanhe.Enabled = true; chkThanhtoantruockhikham.Enabled = true; chkAutoPayment.Enabled = true; //Utility.EnabledTextBox(txtfee); m_shtOldPos = Utility.Int16Dbnull(grdList.GetValue(DmucDoituongkcb.Columns.SttHthi), 0); //-------------------------------------------------------------- //Thiết lập trạng thái các nút Insert, Update, Delete... //Không cho phép nhấn Insert, Update,Delete cmdInsert.Enabled = false; cmdUpdate.Enabled = false; cmdDelete.Enabled = false; //Cho phép nhấn nút Ghi cmdSave.Enabled = true; //Nút thoát biến thành nút hủy cmdClose.Text = "Hủy"; //-------------------------------------------------------------- //Không cho phép chọn trên lưới dữ liệu được fill vào các Control m_blnAllowCurrentCellChangedOnGridView = false; //Tự động Focus đến mục Position để người dùng nhập liệu txtPos.Focus(); break; case action.FirstOrFinished: //Hủy hoặc trạng thái ban đầu khi mới hiển thị Form //Không cho phép nhập liệu mã loại đối tượng, tên loại đối tượng và mô tả thêm Utility.DisabledTextBox(txtID); Utility.DisabledTextBox(txtName); Utility.DisabledTextBox(txtDesc); //Utility.DisabledTextBox(txtfee); Utility.DisabledTextBox(txtPos); txtObjectCode.Enabled = false; txtDiscountCorrectLine.Enabled = false; txtDiscountDiscorrectLine.Enabled = false; chkThanhtoantruockhikham.Enabled = false; chkLaygiathuocquanhe.Enabled = false; chkAutoPayment.Enabled = false; //-------------------------------------------------------------- //Thiết lập trạng thái các nút Insert, Update, Delete... //Sau khi nhấn Ghi thành công hoặc Hủy thao tác thì quay về trạng thái ban đầu //Cho phép thêm mới cmdInsert.Enabled = true; //Tùy biến nút Update và Delete tùy theo việc có hay không dữ liệu trên lưới cmdUpdate.Enabled = grdList.RowCount <= 0 ? false : true; cmdDelete.Enabled = grdList.RowCount <= 0 ? false : true; cmdSave.Enabled = false; chkLaygiathuocquanhe.Checked = false; chkThanhtoantruockhikham.Checked = false; chkAutoPayment.Checked = false; //Nút Hủy biến thành nút thoát cmdClose.Text = "Thoát"; //-------------------------------------------------------------- //Cho phép chọn trên lưới dữ liệu được fill vào các Control m_blnAllowCurrentCellChangedOnGridView = true; //Tự động chọn dòng hiện tại trên lưới để hiển thị lại trên Control grdList_CurrentCellChanged(grdList, new EventArgs()); //Tự động Focus đến nút thêm mới? cmdInsert.Focus(); break; default: break; } }