/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { ((Site)Page.Master).HideInaccessibleTabs(ref RadTabStrip1, ref RadMultiPage1); access = Access.Check(); if (!access.Write) { lbtnSave.Visible = false; } Title = "Счет - LeadForce"; RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(ucPriceList, ucPriceList); RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(rdpInvoiceDate, rdpInvoiceDate, null, UpdatePanelRenderMode.Inline); RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(ucInvoiceProducts, lrlInvoiceAmount, null, UpdatePanelRenderMode.Inline); RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(ucInvoiceProducts, ucInvoiceShipments, null, UpdatePanelRenderMode.Inline); RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(dcbBuyerCompanyLegalAccount, ucInvoiceShipments, null, UpdatePanelRenderMode.Inline); RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(dcbExecutorCompanyLegalAccount, ucInvoiceShipments, null, UpdatePanelRenderMode.Inline); ucPriceList.SelectedIndexChanged += ucPriceList_SelectedIndexChanged; rdpInvoiceDate.SelectedDateChanged += rdpInvoiceDate_SelectedDateChanged; ucInvoiceProducts.SiteId = SiteId; ucInvoiceProducts.InvoiceProductsChanged += ucInvoiceProducts_OrderProductsChanged; if (Page.RouteData.Values["id"] != null) { _invoiceId = Guid.Parse(Page.RouteData.Values["id"] as string); } hlCancel.NavigateUrl = UrlsData.AP_Invoices(); tagsInvoices.ObjectID = _invoiceId; ucContentComments.ContentId = _invoiceId; gridInvoiceHistory.Where.Add(new GridWhere() { Column = "InvoiceID", Value = _invoiceId.ToString() }); if (!Page.IsPostBack) { BindData(); } }
/// <summary> /// Handles the OnClick event of the lbtnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void lbtnSave_OnClick(object sender, EventArgs e) { if (!access.Write) { return; } var invoice = DataManager.Invoice.SelectById(SiteId, _invoiceId) ?? new tbl_Invoice(); invoice.CreatedAt = (DateTime)rdpInvoiceDate.SelectedDate; invoice.InvoiceTypeID = dcbInvoiceType.SelectedId; invoice.InvoiceStatusID = int.Parse(ddlInvoiceStatus.SelectedValue); invoice.Note = txtNote.Text; if (dcbExecutorCompany.SelectedId != Guid.Empty) { invoice.ExecutorCompanyID = dcbExecutorCompany.SelectedId; } else { invoice.ExecutorCompanyID = null; } if (dcbBuyerCompany.SelectedId != Guid.Empty) { invoice.BuyerCompanyID = dcbBuyerCompany.SelectedId; } else { invoice.BuyerCompanyID = null; } if (dcbExecutorCompanyLegalAccount.SelectedId != Guid.Empty) { invoice.ExecutorCompanyLegalAccountID = dcbExecutorCompanyLegalAccount.SelectedId; } else { invoice.ExecutorCompanyLegalAccountID = null; } if (dcbBuyerCompanyLegalAccount.SelectedId != Guid.Empty) { invoice.BuyerCompanyLegalAccountID = dcbBuyerCompanyLegalAccount.SelectedId; } else { invoice.BuyerCompanyLegalAccountID = null; } invoice.BuyerContactID = ucBuyerContact.SelectedValue; invoice.ExecutorContactID = ucExecutorContact.SelectedValue; invoice.PaymentDatePlanned = rdpPaymentDatePlanned.SelectedDate; invoice.PaymentDateActual = rdpPaymentDateActual.SelectedDate; invoice.IsPaymentDateFixedByContract = chxIsPaymentDateFixedByContract.Checked; invoice.IsExistBuyerComplaint = chxIsExistBuyerComplaint.Checked; if (ucPriceList.SelectedId != Guid.Empty) { invoice.PriceListID = ucPriceList.SelectedId; } else { invoice.PriceListID = null; } if (dcbOrders.SelectedId != Guid.Empty) { invoice.OrderID = dcbOrders.SelectedId; } else { invoice.OrderID = null; } invoice.InvoiceAmount = ucInvoiceProducts.InvoiceProductsList.Sum(invoiceProduct => invoiceProduct.TotalAmount); if (rntxtPaid.Value.HasValue) { invoice.Paid = (decimal)rntxtPaid.Value; } else { invoice.Paid = 0; } invoice.tbl_Shipment.Clear(); var shipmentIds = ucInvoiceShipments.InvoiceShipmentsList.Select(x => x.ID).ToList(); var shipments = DataManager.Shipment.SelectAll(SiteId).Where( o => shipmentIds.Contains(o.ID)); foreach (var shipment in shipments) { invoice.tbl_Shipment.Add(shipment); } if (invoice.ID == Guid.Empty) { invoice.SiteID = SiteId; invoice.OwnerID = CurrentUser.Instance.ContactID; var invoiceType = DataManager.InvoiceType.SelectById(SiteId, invoice.InvoiceTypeID); if (invoiceType != null && invoiceType.NumeratorID.HasValue) { var documentNumerator = DocumentNumerator.GetNumber((Guid)invoiceType.NumeratorID, invoice.CreatedAt, invoiceType.tbl_Numerator.Mask, "tbl_Invoice"); invoice.Number = documentNumerator.Number; invoice.SerialNumber = documentNumerator.SerialNumber; } DataManager.Invoice.Add(invoice); } else { DataManager.Invoice.Update(invoice); } DataManager.InvoiceProducts.Update(ucInvoiceProducts.InvoiceProductsList, invoice.ID); tagsInvoices.SaveTags(invoice.ID); Response.Redirect(UrlsData.AP_Invoices()); }