protected void grdBooking_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { CriteriaOperator filter = new BinaryOperator("PurchaseInvoiceInventoryTransactionId", Guid.Parse(Session["InventoryTransactionId"].ToString()), BinaryOperatorType.Equal); XPCollection <PurchaseInvoiceInventoryAccountingTransaction> purchaseInvoiceTransaction = new XPCollection <PurchaseInvoiceInventoryAccountingTransaction>(session, filter); if (purchaseInvoiceTransaction.Count > 0) { foreach (PurchaseInvoiceInventoryAccountingTransaction item in purchaseInvoiceTransaction) { if (item.RowStatus == ROW_NOT_DELETE) { e.Cancel = true; return; } } } filter = new BinaryOperator("TransactionId", Guid.Parse(e.Values["TransactionId"].ToString()), BinaryOperatorType.Equal); PurchaseInvoiceInventoryAccountingTransaction purchaseInvoiceInventoryTransaction = session.FindObject <PurchaseInvoiceInventoryAccountingTransaction>(filter); if (purchaseInvoiceInventoryTransaction != null) { purchaseInvoiceInventoryTransaction.RowStatus = ROW_DELETE; purchaseInvoiceInventoryTransaction.Save(); } //e.Cancel = true; }
protected void cpBooking_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e) { session = XpoHelper.GetNewSession(); switch (e.Parameter) { case "view": Session["InventoryTransactionId"] = hWarehouseBookingId.Get("id").ToString(); grdBooking.DetailRows.CollapseAllRows(); CriteriaOperator filter = new BinaryOperator("PurchaseInvoiceInventoryTransactionId", Guid.Parse(Session["InventoryTransactionId"].ToString()), BinaryOperatorType.Equal); XPCollection <PurchaseInvoiceInventoryAccountingTransaction> inventoryTransaction = new XPCollection <PurchaseInvoiceInventoryAccountingTransaction>(session, filter); if (inventoryTransaction.Count > 0) { foreach (PurchaseInvoiceInventoryAccountingTransaction item in inventoryTransaction) { if (item.RowStatus == ROW_NOT_DELETE) { grdBooking.Columns["Thao tác"].Visible = false; break; } else { grdBooking.Columns["Thao tác"].Visible = true; } } } else { grdBooking.AddNewRow(); grdBooking.Columns["Thao tác"].Visible = true; } cpBooking.JSProperties.Add("cpEnable", "true"); break; case "booking": filter = new BinaryOperator("PurchaseInvoiceInventoryTransactionId", Guid.Parse(Session["InventoryTransactionId"].ToString()), BinaryOperatorType.Equal); inventoryTransaction = new XPCollection <PurchaseInvoiceInventoryAccountingTransaction>(session, filter); foreach (PurchaseInvoiceInventoryAccountingTransaction item in inventoryTransaction) { double credit = 0; double debit = 0; filter = new GroupOperator(GroupOperatorType.And, new BinaryOperator("TransactionId", item.TransactionId, BinaryOperatorType.Equal), new BinaryOperator("RowStatus", ROW_NEW, BinaryOperatorType.Equal)); XPCollection <GeneralJournal> generalJournal = new XPCollection <GeneralJournal>(session, filter); foreach (GeneralJournal x in generalJournal) { filter = new GroupOperator(GroupOperatorType.And, new BinaryOperator("TransactionId", item.TransactionId, BinaryOperatorType.Equal), new BinaryOperator("AccountId", x.AccountId, BinaryOperatorType.Equal), new BinaryOperator("RowStatus", ROW_NEW, BinaryOperatorType.Equal)); XPCollection <GeneralJournal> generalJ = new XPCollection <GeneralJournal>(session, filter); if (generalJ.Count >= 2) { cpBooking.JSProperties.Add("cpUnbooked", "1"); return; } credit += x.Credit; debit += x.Debit; } if (credit != debit) { cpBooking.JSProperties.Add("cpUnbooked", "2"); return; } } foreach (PurchaseInvoiceInventoryAccountingTransaction item in inventoryTransaction) { item.RowStatus = ROW_NOT_DELETE; item.Save(); filter = new BinaryOperator("TransactionId", item.TransactionId, BinaryOperatorType.Equal); XPCollection <GeneralJournal> generalJournal = new XPCollection <GeneralJournal>(session, filter); double milsec = 0; foreach (GeneralJournal x in generalJournal) { NAS.DAL.Accounting.AccountChart.Account account = session.GetObjectByKey <NAS.DAL.Accounting.AccountChart.Account>(x.AccountId.AccountId); //General general = new General(); //general.BalanceUpdate(session, account, x, false, x.Debit-x.Credit); AccountingBO accountBO = new AccountingBO(); accountBO.CreateGeneralLedger(session, x.TransactionId.TransactionId, x.GeneralJournalId, milsec); milsec += 10; } } filter = new BinaryOperator("PurchaseInvoiceInventoryTransactionId", Guid.Parse(Session["InventoryTransactionId"].ToString()), BinaryOperatorType.Equal); PurchaseInvoiceInventoryAccountingTransaction purchaseInvoiceInventoryTransaction = session.FindObject <PurchaseInvoiceInventoryAccountingTransaction>(filter); purchaseInvoiceInventoryTransaction.RowStatus = ROW_NOT_DELETE; purchaseInvoiceInventoryTransaction.Save(); grdBooking.DetailRows.CollapseAllRows(); grdBooking.Columns["Thao tác"].Visible = false; cpBooking.JSProperties.Add("cpEnable", "true"); break; default: break; } }