private void btnEditRates_Click(object sender, EventArgs e) { if (this.grdOrders.Items.Count > 0) { Button editRates = (Button)sender; if (editRates.Text == "Edit Rates") { foreach (GridItem item in grdOrders.MasterTableView.Items) { if (item is GridEditableItem) { GridEditableItem editableItem = item as GridDataItem; editableItem.Edit = true; } } this.btnEditRates.Text = "Update Rates"; } else { foreach (GridEditableItem editedItem in grdOrders.EditItems) { bool orderInGroupOverridden = false; bool updateOrder = false; // UpdateRate if it has changed HtmlInputText txtRate = editedItem.FindControl("txtOrderRate") as HtmlInputText; int orderId = int.Parse(editedItem.GetDataKeyValue("OrderID").ToString()); Facade.IOrder facOrder = new Facade.Order(); // get the data item so we can compare the rate before it was changed Entities.Order order = facOrder.GetForOrderID(orderId); CheckRateInformation(order, ref orderInGroupOverridden, ref updateOrder); CultureInfo culture = new CultureInfo(order.LCID); decimal newRate = Decimal.Parse(txtRate.Value, NumberStyles.Any, culture); if (newRate != order.ForeignRate) { // Mark as overridden... update the rate on the order. order.ForeignRate = newRate; if (!order.IsTariffOverride) { order.IsTariffOverride = true; order.TariffOverrideDate = DateTime.Now; order.TariffOverrideUserID = User.Identity.Name; } // Recalculate the GBP amounts BusinessLogicLayer.IExchangeRates blER = new BusinessLogicLayer.ExchangeRates(); BusinessLogicLayer.CurrencyConverter currencyConverter = blER.CreateCurrencyConverter(order.LCID, order.CollectionDateTime); order.Rate = currencyConverter.ConvertToLocal(order.ForeignRate); updateOrder = true; } // Update the order as the CheckRateInformation method may have amended the order if (updateOrder) { facOrder.Update(order, User.Identity.Name); } if (orderInGroupOverridden && order.OrderGroupID > 0) { Facade.IOrderGroup facOrderGroup = new Facade.Order(); Entities.OrderGroup orderGroup = facOrderGroup.Get(order.OrderGroupID); orderGroup.TariffRateDescription = "Overridden"; facOrderGroup.Update(orderGroup, this.Page.User.Identity.Name); } editedItem.Edit = false; } this.btnEditRates.Text = "Edit Rates"; } this.grdOrders.Rebind(); } }
private void SaveBatchChanges() { string userName = ((Entities.CustomPrincipal)Page.User).UserName; // React to the user's options. foreach (GridDataItem row in gvPreInvoices.Items) { string tableName = row.OwnerTableView.Name; int preInvoiceId = -1; int.TryParse(row.GetDataKeyValue("PreInvoiceID").ToString(), out preInvoiceId); if (tableName == PreInvoiceTableName && (row.ItemType == GridItemType.Item || row.ItemType == GridItemType.AlternatingItem)) { HiddenField hidIsDirty = row.FindControl("hidIsDirty") as HiddenField; bool isDirty = false; if (bool.TryParse(hidIsDirty.Value, out isDirty) && isDirty) { #region Update PreInvoice DateTime?invoiceDate = null; string clientReference = string.Empty, purchaseOrderReference = string.Empty; int taxRateID = -1; RadDateInput rdiInvoiceDate = row.FindControl("rdiInvoiceDate") as RadDateInput; RadTextBox rtClientReference = row.FindControl("rtClientReference") as RadTextBox; RadTextBox rtPurchaseOrderReference = row.FindControl("rtPurchaseOrderReference") as RadTextBox; DropDownList cboTaxRate = row.FindControl("cboTaxRate") as DropDownList; if (rdiInvoiceDate.SelectedDate.HasValue) { invoiceDate = rdiInvoiceDate.SelectedDate.Value; } clientReference = rtClientReference.Text; purchaseOrderReference = rtPurchaseOrderReference.Text; int.TryParse(cboTaxRate.SelectedValue, out taxRateID); Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice(); facPreInvoice.UpdatePreinvoiceDetails(preInvoiceId, invoiceDate, clientReference, purchaseOrderReference, taxRateID, userName); #endregion } } else if (tableName == PreInvoiceItemTableName && (row.ItemType == GridItemType.Item || row.ItemType == GridItemType.AlternatingItem)) { HiddenField hidInvoiceItemIsDirty = row.FindControl("hidInvoiceItemIsDirty") as HiddenField; bool isDirty = false; HiddenField hidInvoiceItemPendingDelete = row.FindControl("hidInvoiceItemPendingDelete") as HiddenField; bool isPendingDelete = false; if (bool.TryParse(hidInvoiceItemPendingDelete.Value, out isPendingDelete) && isPendingDelete) { Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice(); TextBox txtRate = row.FindControl("txtRate") as TextBox; GridDataItem parentItem = row.OwnerTableView.ParentItem; int itemID = int.Parse(txtRate.Attributes["ItemID"]); // Update the rate (depends on item type - depends on invoice type) int preInvoiceID = int.Parse(parentItem.GetDataKeyValue("PreInvoiceID").ToString()); facPreInvoice.RemovePreInvoiceOrder(preInvoiceID, itemID); } else if (bool.TryParse(hidInvoiceItemIsDirty.Value, out isDirty) && isDirty) { #region Pre Invoice Item decimal rate = 0; HiddenField hidOldRate = row.FindControl("hidOldRate") as HiddenField; TextBox txtRate = row.FindControl("txtRate") as TextBox; GridDataItem parentItem = row.OwnerTableView.ParentItem; int lcid = int.Parse(parentItem.GetDataKeyValue("LCID").ToString()); CultureInfo preInvoiceCulture = new CultureInfo(lcid); if (Decimal.TryParse(txtRate.Text, System.Globalization.NumberStyles.Currency, preInvoiceCulture, out rate)) { //decimal oldRate = 0; //oldRate = decimal.Parse(hidOldRate.Value); // Only apply the rate change if the rate has altered. //if (oldRate != rate) if (hidOldRate.Value != txtRate.Text) { int itemID = int.Parse(txtRate.Attributes["ItemID"]); // Update the rate (depends on item type - depends on invoice type) int preInvoiceID = int.Parse(parentItem.GetDataKeyValue("PreInvoiceID").ToString()); eInvoiceType invoiceType = (eInvoiceType)int.Parse(parentItem.GetDataKeyValue("InvoiceTypeID").ToString()); CultureInfo culture = new CultureInfo(Orchestrator.Globals.Configuration.NativeCulture); Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice(); Facade.IExchangeRates facER = new Facade.ExchangeRates(); switch (invoiceType) { case eInvoiceType.ClientInvoicing: #region Client Invoice Facade.IOrder facOrder = new Facade.Order(); Entities.Order order = facOrder.GetForOrderID(itemID); order.ForeignRate = rate; if (order.LCID != culture.LCID) { BusinessLogicLayer.IExchangeRates blER = new BusinessLogicLayer.ExchangeRates(); BusinessLogicLayer.CurrencyConverter currencyConverter = blER.CreateCurrencyConverter(order.LCID, order.CollectionDateTime); order.Rate = currencyConverter.ConvertToLocal(order.ForeignRate); } else { order.Rate = decimal.Round(order.ForeignRate, 4, MidpointRounding.AwayFromZero); } facPreInvoice.UpdateOrderRate(preInvoiceID, itemID, order.ForeignRate, order.Rate, userName); #endregion break; case eInvoiceType.SubContractorSelfBill: case eInvoiceType.SubContract: #region Subby Invoicing // Needs to be Amended For Currency : TL 12/05/08; Facade.IJobSubContractor facJSC = new Facade.Job(); Entities.JobSubContractor jobSubContractor = facJSC.GetSubContractorForJobSubContractId(itemID); jobSubContractor.ForeignRate = rate; if (jobSubContractor.LCID != culture.LCID) { jobSubContractor.Rate = facER.GetConvertedRate((int)jobSubContractor.ExchangeRateID, jobSubContractor.ForeignRate); } else { jobSubContractor.Rate = decimal.Round(jobSubContractor.ForeignRate, 4, MidpointRounding.AwayFromZero); } facPreInvoice.UpdateJobSubContractRate(preInvoiceID, itemID, jobSubContractor.ForeignRate, jobSubContractor.Rate, jobSubContractor.ExchangeRateID, userName); #endregion break; default: throw new NotSupportedException("You can not alter item rates on invoices of type " + invoiceType.ToString()); } } } #endregion } } } }
void gvPreInvoices_ItemCommand(object source, GridCommandEventArgs e) { string userName = ((Entities.CustomPrincipal)Page.User).UserName; switch (e.CommandName.ToLower()) { #region Client Reference Editing case "cancelclientreference": e.Item.Edit = false; gvPreInvoices.Rebind(); break; case "editclientreference": e.Item.Edit = true; gvPreInvoices.Rebind(); break; case "editpurchaseorderreference": e.Item.Edit = true; gvPreInvoices.Rebind(); break; case "updateclientreference": e.Item.Edit = false; string clientReference = string.Empty; LinkButton lnkChangeClientReference = e.Item.FindControl("lnkChangeClientReference") as LinkButton; TextBox txtClientReference = e.Item.FindControl("txtClientReference") as TextBox; if (lnkChangeClientReference != null && txtClientReference != null) { string oldClientReference = lnkChangeClientReference.Text; clientReference = txtClientReference.Text; // Only apply the change if the client reference has been altered if (oldClientReference != clientReference) { // Update the client reference int preInvoiceID = int.Parse(((GridDataItem)e.Item).GetDataKeyValue("PreInvoiceID").ToString()); Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice(); facPreInvoice.UpdateClientInvoiceReference(preInvoiceID, clientReference, userName); } } gvPreInvoices.Rebind(); break; case "updatepurchaseorderreference": e.Item.Edit = false; string purchaseOrderReference = string.Empty; LinkButton lnkChangePurchaseOrderReference = e.Item.FindControl("lnkChangePurchaseOrderReference") as LinkButton; TextBox txtPurchaseOrderReference = e.Item.FindControl("txtPurchaseOrderReference") as TextBox; if (lnkChangePurchaseOrderReference != null && txtPurchaseOrderReference != null) { string oldPurchaseOrderReference = lnkChangePurchaseOrderReference.Text; purchaseOrderReference = txtPurchaseOrderReference.Text; // Only apply the change if the client reference has been altered if (oldPurchaseOrderReference != purchaseOrderReference) { // Update the client reference int preInvoiceID = int.Parse(((GridDataItem)e.Item).GetDataKeyValue("PreInvoiceID").ToString()); Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice(); facPreInvoice.UpdatePurchaseOrderReference(preInvoiceID, purchaseOrderReference, userName); } } gvPreInvoices.Rebind(); break; #endregion #region Rate Editing //case "cancelrate": // e.Item.Edit = false; // e.Item.OwnerTableView.Rebind(); // gvPreInvoices.MasterTableView.Rebind(); // StayOpen = e.Item.OwnerTableView.ParentItem.ItemIndex; // break; //case "editrate": // e.Item.Edit = true; // e.Item.OwnerTableView.Rebind(); // gvPreInvoices.MasterTableView.Rebind(); // StayOpen = e.Item.OwnerTableView.ParentItem.ItemIndex; // break; case "update": // update rate and pallet spaces. e.Item.Edit = false; decimal rate = 0; //LinkButton lnkChangeRate = e.Item.FindControl("lnkChangeRate") as LinkButton; HiddenField hidOldRate = e.Item.FindControl("hidOldRate") as HiddenField; TextBox txtRate = e.Item.FindControl("txtRate") as TextBox; GridDataItem parentItem = e.Item.OwnerTableView.ParentItem; int lcid = int.Parse(parentItem.GetDataKeyValue("LCID").ToString()); CultureInfo preInvoiceCulture = new CultureInfo(lcid); if (Decimal.TryParse(txtRate.Text, System.Globalization.NumberStyles.Currency, preInvoiceCulture, out rate)) { decimal oldRate = 0; oldRate = decimal.Parse(hidOldRate.Value); // Only apply the rate change if the rate has altered. if (oldRate != rate) { int itemID = int.Parse(txtRate.Attributes["ItemID"]); // Update the rate (depends on item type - depends on invoice type) int preInvoiceID = int.Parse(parentItem.GetDataKeyValue("PreInvoiceID").ToString()); eInvoiceType invoiceType = (eInvoiceType)int.Parse(parentItem.GetDataKeyValue("InvoiceTypeID").ToString()); CultureInfo culture = new CultureInfo(Orchestrator.Globals.Configuration.NativeCulture); Facade.IPreInvoice facPreInvoice = new Facade.PreInvoice(); Facade.IExchangeRates facER = new Facade.ExchangeRates(); switch (invoiceType) { case eInvoiceType.ClientInvoicing: Facade.IOrder facOrder = new Facade.Order(); Entities.Order order = facOrder.GetForOrderID(itemID); order.ForeignRate = rate; if (order.LCID != culture.LCID) { BusinessLogicLayer.IExchangeRates blER = new BusinessLogicLayer.ExchangeRates(); BusinessLogicLayer.CurrencyConverter currencyConverter = blER.CreateCurrencyConverter(order.LCID, order.CollectionDateTime); order.Rate = currencyConverter.ConvertToLocal(order.ForeignRate); } else { order.Rate = decimal.Round(order.ForeignRate, 4, MidpointRounding.AwayFromZero); } //if (order.OrderGroupID > 0) //facPreInvoice.UpdateOrderGroupRate(preInvoiceID, order.OrderGroupID, order.ForeignRate, order.Rate, userName); //else facPreInvoice.UpdateOrderRate(preInvoiceID, itemID, order.ForeignRate, order.Rate, userName); break; case eInvoiceType.SubContractorSelfBill: case eInvoiceType.SubContract: // Needs to be Amended For Currency : TL 12/05/08; Facade.IJobSubContractor facJSC = new Facade.Job(); Entities.JobSubContractor jobSubContractor = facJSC.GetSubContractorForJobSubContractId(itemID); jobSubContractor.ForeignRate = rate; if (jobSubContractor.LCID != culture.LCID) { jobSubContractor.Rate = facER.GetConvertedRate((int)jobSubContractor.ExchangeRateID, jobSubContractor.ForeignRate); } else { jobSubContractor.Rate = decimal.Round(jobSubContractor.ForeignRate, 4, MidpointRounding.AwayFromZero); } facPreInvoice.UpdateJobSubContractRate(preInvoiceID, itemID, jobSubContractor.ForeignRate, jobSubContractor.Rate, jobSubContractor.ExchangeRateID, userName); break; default: throw new NotSupportedException("You can not alter item rates on invoices of type " + invoiceType.ToString()); } this.lblSavedMessage.Text = string.Format("Your changes were saved at {0}", DateTime.Now.ToLongTimeString()); } } e.Item.OwnerTableView.Rebind(); gvPreInvoices.MasterTableView.Rebind(); StayOpen = parentItem.ItemIndex; break; #endregion } }
void btnUpdateOrders_Click(object sender, EventArgs e) { Facade.IOrder facOrder = new Facade.Order(); decimal rateTotal = 0m; bool orderInGroupOverridden = false; bool updateOrder = false; foreach (Entities.Order order in this.OrderGroup.Orders) { updateOrder = false; /* * Tom Farrow 24/03/2010 * * ---------------------------------------- * CHECK FOR THE EXISTENCE OF A TARIFF RATE * ---------------------------------------- * This check is required in the scenario where tariff tables are created * after orders are created. When orders are initally created without * a tariff table present, they cannot be auto-rated and cannot be marked as rate * overridden. If a tariff table is subsequently created with rates that would * apply to those existing orders, those orders would be in an inconsistent state. * * Thus, upon opening these orders a check needs to be made to see if a tariff-rate exists. * If a rate exists and the order has a DIFFERENT rate, then the order should be * marked as rate overridden. If a rate exists but it is the same as the orders * rate, then the order should be marked as auto-rated. * */ /* START OF CHECK */ CheckRateInformation(order, ref orderInGroupOverridden, ref updateOrder); /* END OF CHECK */ GridDataItem gdi = this.grdOrders.MasterTableView.FindItemByKeyValue("OrderID", order.OrderID); RadNumericTextBox rntForeignRate = gdi.FindControl("rntForeignRate") as RadNumericTextBox; if (Convert.ToDecimal(rntForeignRate.Value) != order.ForeignRate) { // Mark as overridden... update the rate on the order. decimal newRate = Convert.ToDecimal(rntForeignRate.Value); order.ForeignRate = newRate; if (!order.IsTariffOverride) { order.IsTariffOverride = true; order.TariffOverrideDate = DateTime.Now; order.TariffOverrideUserID = User.Identity.Name; this.txtRateTariffCard.Text = "Overridden"; } // Recalculate the GBP amounts BusinessLogicLayer.IExchangeRates blER = new BusinessLogicLayer.ExchangeRates(); BusinessLogicLayer.CurrencyConverter currencyConverter = blER.CreateCurrencyConverter(order.LCID, order.CollectionDateTime); order.Rate = currencyConverter.ConvertToLocal(order.ForeignRate); rateTotal += newRate; updateOrder = true; } else { rateTotal += order.ForeignRate; } if (!String.IsNullOrEmpty(this.txtLoadNumber.Text)) { updateOrder = true; order.CustomerOrderNumber = this.txtLoadNumber.Text; } // Update the order as the CheckRateInformation method may have amended the order if (updateOrder) { facOrder.Update(order, User.Identity.Name); } } if (orderInGroupOverridden) { this.txtRateTariffCard.Text = this.OrderGroup.TariffRateDescription = "Overridden"; Facade.IOrderGroup facOrderGroup = new Facade.Order(); facOrderGroup.Update(this.OrderGroup, this.Page.User.Identity.Name); } RebindPage(); //CultureInfo culture = new CultureInfo(this.OrderGroup.LCID); //if (_decimalPlaces != 2) // culture.NumberFormat.CurrencyDecimalDigits = _decimalPlaces; //lblRate.Text = rateTotal.ToString("C", culture); this.ReturnValue = "refresh"; }