public static void Populate() { Session session = null; try { session = XpoHelper.GetNewSession(); //insert default data into Person table if (!Util.isExistXpoObject <AccountingPeriod>("Code", Utility.Constant.NAAN_DEFAULT_CODE)) { XPQuery <Organization> organizationQuery = session.Query <Organization>(); XPQuery <AccountType> AccountTypeQuery = session.Query <AccountType>(); Organization.Populate(); AccountType.Populate(); AccountType accountType = AccountTypeQuery.Where(r => r.Code == Utility.Constant.NAAN_DEFAULT_CODE).FirstOrDefault(); Organization organization = organizationQuery.Where(r => r.Code == Utility.Constant.NAAN_DEFAULT_CODE).FirstOrDefault(); AccountingPeriod accountingPeriod = new AccountingPeriod(session) { Code = Utility.Constant.NAAN_DEFAULT_CODE, OrganizationId = organization, Description = "", fIsActive = false, fFromDateTime = DateTime.Now, fToDateTime = DateTime.Now, RowStatus = Constant.ROWSTATUS_DEFAULT }; accountingPeriod.Save(); } if (!Util.isExistXpoObject <AccountingPeriod>("AccountingPeriodId", "5eaa2bf5-34ba-47c6-88df-48ad25bc6e18")) { XPQuery <Organization> organizationQuery = session.Query <Organization>(); XPQuery <AccountType> AccountTypeQuery = session.Query <AccountType>(); Organization.Populate(); AccountType.Populate(); AccountType accountType = AccountTypeQuery.Where(r => r.Code == Utility.Constant.NAAN_DEFAULT_CODE).FirstOrDefault(); Organization organization = organizationQuery.Where(r => r.Code == Utility.Constant.NAAN_DEFAULT_CODE).FirstOrDefault(); AccountingPeriod accountingPeriod = new AccountingPeriod(session) { AccountingPeriodId = Guid.Parse("5eaa2bf5-34ba-47c6-88df-48ad25bc6e18"), Code = "MACDINH", OrganizationId = organization, Description = "Chu kì Mặc định", fIsActive = true, fFromDateTime = DateTime.Today, fToDateTime = DateTime.Today.AddMonths(1), RowStatus = Constant.ROWSTATUS_ACTIVE }; accountingPeriod.Save(); } } catch (Exception) { } finally { if (session != null) { session.Dispose(); } } }
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; } }