protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) { if (e.NewValues["IsActive"] == null) { e.NewValues["IsActive"] = false; } if (Util.isExistXpoObject <AccountingPeriod>("Code", (string)e.NewValues["Code"])) { e.Cancel = true; throw (new Exception("Trùng mã chu kì")); return; } if (e.NewValues["AccountingPeriodTypeId!Key"] == null) { e.Cancel = true; throw (new Exception("Chưa chọn thể loại")); return; } AccountingPeriod accountingPeriod = new AccountingPeriod(session); accountingPeriod.Description = (string)e.NewValues["Description"]; accountingPeriod.Code = (string)e.NewValues["Code"]; accountingPeriod.AccountingPeriodTypeId = session.GetObjectByKey <AccountingPeriodType>(Guid.Parse(e.NewValues["AccountingPeriodTypeId!Key"].ToString())); accountingPeriod.FromDateTime = (DateTime)e.NewValues["FromDateTime"]; accountingPeriod.ToDateTime = (DateTime)e.NewValues["ToDateTime"]; accountingPeriod.RowStatus = Constant.ROWSTATUS_ACTIVE; accountingPeriod.IsActive = (bool)e.NewValues["IsActive"]; if (accountingPeriod.Code != null) { accountingPeriod.Save(); } ASPxGridLookup grid = ASPxGridView1.FindEditRowCellTemplateControl(ASPxGridView1.Columns[5] as GridViewDataColumn, "cp_Grid1").FindControl("GridUnderPeriod") as ASPxGridLookup; List <object> selectedRows = grid.GridView.GetSelectedFieldValues("AccountingPeriodId"); if (!accountingPeriod.AccountingPeriodTypeId.IsDefault) { foreach (var o in selectedRows) { AccountingPeriodBO.CreatAccountingPeriodComposite(session, accountingPeriod.AccountingPeriodId, Guid.Parse(o.ToString())); } } e.Cancel = true; ASPxGridView1.CancelEdit(); }
protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) { try { AccountingPeriod currentAP = session.GetObjectByKey <AccountingPeriod>((Guid)e.Keys[0]); if (Util.isExistXpoObject <AccountingPeriod>("Code", e.NewValues["Code"].ToString())) { CriteriaOperator criteria0 = new BinaryOperator("Code", e.NewValues["Code"].ToString(), BinaryOperatorType.Equal); CriteriaOperator criteria1 = new BinaryOperator("AccountingPeriodId", e.Keys[0], BinaryOperatorType.NotEqual); CriteriaOperator criteria2 = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator cr = new GroupOperator(GroupOperatorType.And, criteria0, criteria1, criteria2); AccountingPeriod ap = session.FindObject <AccountingPeriod>(cr); if (ap != null) { e.Cancel = true; throw (new Exception("Trùng mã chu kì")); return; } } ASPxGridLookup grid = ASPxGridView1.FindEditRowCellTemplateControl(ASPxGridView1.Columns[5] as GridViewDataColumn, "cp_Grid1").FindControl("GridUnderPeriod") as ASPxGridLookup; CriteriaOperator criteria_0 = new BinaryOperator("AccountingPeriodId", currentAP, BinaryOperatorType.Equal); CriteriaOperator criteria_1 = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator criteria = new GroupOperator(GroupOperatorType.And, criteria_0, criteria_1); XPCollection <AccountingPeriodComposite> collection = new XPCollection <AccountingPeriodComposite>(session, criteria); foreach (AccountingPeriodComposite cp in collection) { cp.RowStatus = Constant.ROWSTATUS_DELETED; cp.Save(); } List <object> selectedRows = grid.GridView.GetSelectedFieldValues("AccountingPeriodId"); if (!currentAP.AccountingPeriodTypeId.IsDefault) { foreach (var o in selectedRows) { AccountingPeriodBO.CreatAccountingPeriodComposite(session, currentAP.AccountingPeriodId, Guid.Parse(o.ToString())); } } } catch (Exception) { throw (new Exception("Trùng mã chu kì")); } }