/// <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(rdpCreatedAt, rdpCreatedAt, null, UpdatePanelRenderMode.Inline); RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(ucShipmentProducts, lrlShipmentAmount, null, UpdatePanelRenderMode.Inline); RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(ucShipmentProducts, ucShipmentInvoices, null, UpdatePanelRenderMode.Inline); RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(dcbBuyerCompanyLegalAccount, ucShipmentInvoices, null, UpdatePanelRenderMode.Inline); RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(dcbExecutorCompanyLegalAccount, ucShipmentInvoices, null, UpdatePanelRenderMode.Inline); rdpCreatedAt.SelectedDateChanged += rdpShipmentDate_SelectedDateChanged; ucShipmentProducts.SiteId = SiteId; ucShipmentProducts.ShipmentProductsChanged += ucShipmentProducts_OrderProductsChanged; if (Page.RouteData.Values["id"] != null) { _shipmentId = Guid.Parse(Page.RouteData.Values["id"] as string); } hlCancel.NavigateUrl = UrlsData.AP_Shipments(); tagsShipments.ObjectID = _shipmentId; ucContentComments.ContentId = _shipmentId; gridShipmentHistory.Where.Add(new GridWhere() { Column = "ShipmentID", Value = _shipmentId.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 shipment = DataManager.Shipment.SelectById(SiteId, _shipmentId) ?? new tbl_Shipment(); shipment.CreatedAt = (DateTime)rdpCreatedAt.SelectedDate; shipment.ShipmentTypeID = dcbShipmentType.SelectedId; shipment.ShipmentStatusID = int.Parse(ddlShipmentStatus.SelectedValue); shipment.Note = txtNote.Text; if (dcbExecutorCompany.SelectedId != Guid.Empty) { shipment.ExecutorCompanyID = dcbExecutorCompany.SelectedId; } else { shipment.ExecutorCompanyID = null; } if (dcbBuyerCompany.SelectedId != Guid.Empty) { shipment.BuyerCompanyID = dcbBuyerCompany.SelectedId; } else { shipment.BuyerCompanyID = null; } if (dcbExecutorCompanyLegalAccount.SelectedId != Guid.Empty) { shipment.ExecutorCompanyLegalAccountID = dcbExecutorCompanyLegalAccount.SelectedId; } else { shipment.ExecutorCompanyLegalAccountID = null; } if (dcbBuyerCompanyLegalAccount.SelectedId != Guid.Empty) { shipment.BuyerCompanyLegalAccountID = dcbBuyerCompanyLegalAccount.SelectedId; } else { shipment.BuyerCompanyLegalAccountID = null; } shipment.BuyerContactID = ucBuyerContact.SelectedValue; shipment.ExecutorContactID = ucExecutorContact.SelectedValue; shipment.SendDate = rdpSendDate.SelectedDate; shipment.PriceListID = null; if (dcbOrders.SelectedId != Guid.Empty) { shipment.OrderID = dcbOrders.SelectedId; } else { shipment.OrderID = null; } shipment.ShipmentAmount = ucShipmentProducts.ShipmentProductsList.Sum(shipmentProduct => shipmentProduct.TotalAmount); shipment.tbl_Invoice.Clear(); var invoiceIds = ucShipmentInvoices.ShipmentInvoicesList.Select(x => x.ID).ToList(); var invoices = DataManager.Invoice.SelectAll(SiteId).Where( o => invoiceIds.Contains(o.ID)); foreach (var invoice in invoices) { shipment.tbl_Invoice.Add(invoice); } if (shipment.ID == Guid.Empty) { shipment.SiteID = SiteId; shipment.OwnerID = CurrentUser.Instance.ContactID; var shipmentType = DataManager.ShipmentType.SelectById(SiteId, shipment.ShipmentTypeID); if (shipmentType != null) { var documentNumerator = DocumentNumerator.GetNumber((Guid)shipmentType.NumeratorID, shipment.CreatedAt, shipmentType.tbl_Numerator.Mask, "tbl_Shipment"); shipment.Number = documentNumerator.Number; shipment.SerialNumber = documentNumerator.SerialNumber; } DataManager.Shipment.Add(shipment); } else { DataManager.Shipment.Update(shipment); } DataManager.ShipmentProducts.Update(ucShipmentProducts.ShipmentProductsList, shipment.ID); tagsShipments.SaveTags(shipment.ID); Response.Redirect(UrlsData.AP_Shipments()); }