Example #1
0
        protected void btnSaveAssetTypePrices_Click(object sender, EventArgs e)
        {
            foreach (GridDataItem assetCategoryItem in rdAssetTypeGrid.Items)
            {
                GridNestedViewItem detailView = (GridNestedViewItem)assetCategoryItem.ChildItem;

                if (detailView != null)
                {
                    GridTableView tableView = detailView.NestedTableViews.First();
                    foreach (GridDataItem assetTypeItem in tableView.Items)
                    {
                        Hashtable assetTypeValues = new Hashtable();
                        assetTypeItem.ExtractValues(assetTypeValues);
                        int serviceLocationAssetTypeId = Convert.ToInt32(assetTypeValues["ServiceLocationAssetTypeId"].ToString());
                        ServiceLocationAssetTypeEntity serviceLocationAssetType = new ServiceLocationAssetTypeEntity(serviceLocationAssetTypeId);

                        TextBox     txtPricePerUnit = assetTypeItem.FindControl("txtPricePerUnit") as TextBox;
                        HiddenField hdnOrigPrice    = assetTypeItem.FindControl("hdnOrigPrice") as HiddenField;

                        decimal price     = 0;
                        decimal origPrice = Convert.ToDecimal(hdnOrigPrice.Value.Trim().Replace("$", ""));

                        if (txtPricePerUnit.Text.Trim().Length > 0)
                        {
                            price = Convert.ToDecimal(txtPricePerUnit.Text.Trim().Replace("$", ""));
                        }

                        serviceLocationAssetType.PricePerUnit = price;
                        serviceLocationAssetType.Save();

                        if (price != origPrice)
                        {
                            ChangeLogEntity cle = new ChangeLogEntity();
                            cle.UserId       = sm.AuthenticatedUser.UserId;
                            cle.ChangeDate   = DateTime.Now;
                            cle.ChangeTypeId = (int)ChangeTypeEntity.ChangeTypes.AssetTypePriceChange;
                            cle.Save();
                            ServiceLocationAssetTypeChangeLogEntity slatcle = new ServiceLocationAssetTypeChangeLogEntity();
                            slatcle.ServiceLocationAssetTypeId = serviceLocationAssetType.ServiceLocationAssetTypeId;
                            slatcle.ChangeLog = cle;
                            slatcle.Save();
                        }
                    }
                }
            }

            messages.AddSuccessDiv("Asset types successfully saved");
        }