protected void ASPxGridView2_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) { e.NewValues["RowStatus"] = Constant.ROWSTATUS_ACTIVE; if (e.NewValues["IsDefault"] == null) { e.NewValues["IsDefault"] = false; } if (Util.isExistXpoObject <AccountingPeriodType>("Name", (string)e.NewValues["Name"])) { e.Cancel = true; throw(new Exception("Trùng tên thể loại chu kì")); } if ((bool)e.NewValues["IsDefault"] == true) { CriteriaOperator criteria = new BinaryOperator("IsDefault", true, BinaryOperatorType.Equal); AccountingPeriodType type = session.FindObject <AccountingPeriodType>(criteria); e.NewValues["RowStatus"] = Constant.ROWSTATUS_ACTIVE; if (type != null) { if (AccountingPeriodTypeBO.IsUsedAccoutingPeriodType(session, type.AccountingPeriodTypeId)) { ASPxGridView2.CancelEdit(); throw new Exception("Loại chu kì nhỏ nhất " + type.Name + " đang được sử dụng nên không thể thay đổi"); } type.IsDefault = false; type.Save(); } } }
protected void GridACCPeriodType_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { try { if (bo.checkIsAccountingPeriodTypeIdInCurrency(uow, e.Values["AccountingPeriodTypeId"].ToString().Trim())) { e.Cancel = true; throw new Exception(String.Format("Lỗi không thể xóa vì có chứa Chu Kỳ ")); } else { e.Cancel = true; uow.BeginTransaction(); Guid a = Guid.Parse(e.Keys[0].ToString()); AccountingPeriodType accpT = uow.GetObjectByKey <AccountingPeriodType>(a); accpT.RowStatus = Utility.Constant.ROWSTATUS_DELETED; accpT.Save(); uow.CommitTransaction(); } } catch (Exception) { uow.RollbackTransaction(); e.Cancel = true; throw; } }
protected void ASPxGridView2_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) { if (Util.isExistXpoObject <AccountingPeriodType>("Name", (string)e.NewValues["Name"])) { CriteriaOperator criteria_0 = new BinaryOperator("Name", (string)e.NewValues["Name"], BinaryOperatorType.Equal); CriteriaOperator criteria_1 = new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator criteria_2 = new BinaryOperator("AccountingPeriodTypeId", e.Keys[0], BinaryOperatorType.NotEqual); CriteriaOperator criteria = new GroupOperator(GroupOperatorType.And, criteria_0, criteria_1, criteria_2); AccountingPeriodType type = session.FindObject <AccountingPeriodType>(criteria); if (type != null) { e.Cancel = true; throw (new Exception("Trùng tên thể loại chu kì")); } } if (e.NewValues["IsDefault"] == null) { e.NewValues["IsDefault"] = false; } if ((bool)e.NewValues["IsDefault"] == true) { CriteriaOperator criteria = new BinaryOperator("IsDefault", true, BinaryOperatorType.Equal); AccountingPeriodType type = session.FindObject <AccountingPeriodType>(criteria); if (type != null) { if (AccountingPeriodTypeBO.IsUsedAccoutingPeriodType(session, type.AccountingPeriodTypeId)) { ASPxGridView2.CancelEdit(); throw new Exception("Loại chu kì nhỏ nhất " + type.Name + " đang được sử dụng nên không thể thay đổi"); } type.IsDefault = false; type.Save(); } } else { if (e.OldValues["IsDefault"].ToString() == "True") { e.Cancel = true; ASPxGridView2.CancelEdit(); throw (new Exception("Phải luôn có 1 thể loại chu kì nhỏ nhất")); } } }
protected void treelistACCPeriod_NodeUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) { try { e.Cancel = true; //CHECK CODE ASPxTreeList treelist = sender as ASPxTreeList; object keyValue = GetMasterRowKeyValue(treelist); AccountingPeriodType AccPTId = uow.GetObjectByKey <AccountingPeriodType>(Guid.Parse(keyValue.ToString())); if (AccPTId == null) { throw new Exception(String.Format("AccountingPeriodType is not exist in system")); } if (!e.OldValues["Code"].Equals(e.NewValues["Code"])) { if (bo.checkAccountingPeriod_Code(uow, e.NewValues["Code"].ToString().Trim(), AccPTId.AccountingPeriodTypeId.ToString())) { e.Cancel = true; throw new Exception(String.Format("Lỗi Chu Kỳ đã có")); } } //END CHECK CODE AccountingPeriod ap = uow.GetObjectByKey <AccountingPeriod>(Guid.Parse(e.Keys[0].ToString())); if (ap != null) { if (e.NewValues["IsActive"] != null) { bool IsActive = bool.Parse(e.NewValues["IsActive"].ToString()); if (IsActive) { if (bo.changeIsActiveAccountingPeriod(uow))//, Guid.Parse(treelistCurrency.FocusedNode.Key.ToString()) { ap.IsActive = true; } if (bo.changeIsDefaultAccountingPeriodType(uow)) { AccPTId.IsDefault = true; AccPTId.Save(); //if (ap.ParentAccountingPeriodId != null) //{ // Guid parentID = Guid.Parse(ap.ParentAccountingPeriodId.AccountingPeriodId.ToString()); // bo.changeIsActiveParentInParentAccP(uow, parentID, IsActive); //} } } else { ap.IsActive = false; } } if (e.NewValues["Description"] == null) { e.NewValues["Description"] = ""; } ap.Description = e.NewValues["Description"].ToString(); ap.Code = e.NewValues["Code"].ToString(); ap.FromDateTime = DateTime.Parse(e.NewValues["FromDateTime"].ToString()); ap.ToDateTime = DateTime.Parse(e.NewValues["ToDateTime"].ToString()); uow.FlushChanges(); } treelist.CancelEdit(); GridACCPeriodType.DataBind(); treelist.JSProperties.Add("cpSaved", true); } catch (Exception) { e.Cancel = true; throw; } }
protected void treelistACCPeriod_NodeInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) { try { e.Cancel = true; ASPxTreeList treelist = sender as ASPxTreeList; object keyValue = GetMasterRowKeyValue(treelist); AccountingPeriodType AccPTypeId = uow.GetObjectByKey <AccountingPeriodType>(Guid.Parse(keyValue.ToString())); if (AccPTypeId == null) { throw new Exception(String.Format("AccountingPeriodType is not exist in System")); } if (bo.checkAccountingPeriod_Code(uow, e.NewValues["Code"].ToString().Trim(), AccPTypeId.AccountingPeriodTypeId.ToString())) { throw new Exception(String.Format("Lỗi Chu Kỳ Đã Có")); } else { AccountingPeriod ap = new AccountingPeriod(uow); #region add parentACCPeriodId string parentKeyStr = treelist.NewNodeParentKey.ToString(); if (parentKeyStr != null && !parentKeyStr.Equals(String.Empty)) { NAS.DAL.Accounting.Journal.AccountingPeriod parentAccPeriod = uow.GetObjectByKey <NAS.DAL.Accounting.Journal.AccountingPeriod>(Guid.Parse(parentKeyStr.ToString())); if (parentAccPeriod == null) { throw new Exception(String.Format("AccountingPeriod is not exist in system")); } // ap.ParentAccountingPeriodId = parentAccPeriod; } #endregion #region add AccountingPeriodTypeId if (AccPTypeId != null) { ap.AccountingPeriodTypeId = AccPTypeId; } #endregion #region add OrganizationId Organization org = uow.FindObject <Organization>(new BinaryOperator("Name", "QUASAPHARCO", BinaryOperatorType.Equal)); if (org != null) { ap.OrganizationId = org; } #endregion #region add IsActive if (e.NewValues["IsActive"] != null) { bool IsActive = bool.Parse(e.NewValues["IsActive"].ToString()); if (IsActive) { if (bo.changeIsActiveAccountingPeriod(uow))//, Guid.Parse(treelistCurrency.FocusedNode.Key.ToString()) { e.NewValues["IsActive"] = true; } if (bo.changeIsDefaultAccountingPeriodType(uow)) { AccPTypeId.IsDefault = true; AccPTypeId.Save(); // bo.changeIsActiveParentInParentAccP(uow, Guid.Parse(parentKeyStr.ToString()), IsActive); } } else { e.NewValues["IsActive"] = false; } ap.IsActive = bool.Parse(e.NewValues["IsActive"].ToString()); } #endregion ap.Code = e.NewValues["Code"].ToString(); ap.FromDateTime = DateTime.Parse(e.NewValues["FromDateTime"].ToString()); ap.ToDateTime = DateTime.Parse(e.NewValues["ToDateTime"].ToString()); if (e.NewValues["Description"] == null) { e.NewValues["Description"] = ""; } ap.Description = e.NewValues["Description"].ToString(); ap.RowStatus = Utility.Constant.ROWSTATUS_ACTIVE; uow.FlushChanges(); treelist.CancelEdit(); } GridACCPeriodType.DataBind(); treelist.JSProperties.Add("cpSaved", true); } catch (Exception) { e.Cancel = true; throw; } }