/// <summary> /// Для выделенных в гриде продуктов устанавливает поле "Основная версия" в "1", /// при условии что в данный момент времени это поле установлено в "0" /// </summary> protected void SetMainVersion_Click(object sender, EventArgs e) { using (ProductProvider provider = new ProductProvider()) { // составляем список выделенных продуктов List<Guid> selectedRows; if (hiddenSelectedProducts.Value.ToString() != "") selectedRows = hiddenSelectedProducts.Value.ToString().Split(',').Select(s => new Guid(s)).ToList(); else return ; provider.SetMainVersion(this.User.ID, selectedRows); // insert here // RefreshButton_Click(sender, e); // GridPanel1.Reload(); } }
protected void Save_Click(object sender, EventArgs e) { this.Validate(); if (this.IsValid) { // Проверяем, является ли продукт основной версией ProductProvider productProvider = new ProductProvider(); if (productProvider.IsMainVersion(this.ProductID)) { LabelErrorMessage.Text = "[ ! ] Содержащий данную спецификацию продукт является основной версией. Сохранение отменено."; return; } JavaScriptSerializer js = new JavaScriptSerializer(); List<Dictionary<string, string>> rows = js.Deserialize<List<Dictionary<string, string>>>(hiddenStoreData.Value.ToString()); EditConfigurationProvider provider = new EditConfigurationProvider(); List<GridColumn> gridColumns = provider.GetGridColumns(); // Сохраняем данные, полученные от пользователя в списке конфигураций List<Aspect.Domain.Configuration> result = new List<Aspect.Domain.Configuration>(); #region convert Request to list of Configuration foreach (Dictionary<string, string> row in rows) { Guid productID = new Guid(row["ID"]); Aspect.Domain.Configuration conf = new Aspect.Domain.Configuration(); conf.ID = new Guid(row["ConfID"]); conf.ProductID = productID; conf.ProductOwnerID = this.ProductID; conf.UserID = this.User.ID; foreach (GridColumn column in gridColumns) { if (column is EditableGridColumn) { System.Reflection.PropertyInfo prop = typeof(Aspect.Domain.Configuration).GetProperty(column.DataItem); if (prop.PropertyType == typeof(decimal) || prop.PropertyType == typeof(Nullable<decimal>)) { prop.SetValue(conf, Convert.ToDecimal(row[column.DataItem]), null); } else if (prop.PropertyType == typeof(int) || prop.PropertyType == typeof(Nullable<int>)) { prop.SetValue(conf, Convert.ToInt32(row[column.DataItem]), null); } else if (prop.PropertyType == typeof(Guid) || prop.PropertyType == typeof(Nullable<Guid>)) { prop.SetValue(conf, new Guid(row[column.DataItem]), null); } else if (prop.PropertyType == typeof(Boolean) || prop.PropertyType == typeof(Nullable<Boolean>)) { prop.SetValue(conf, Convert.ToBoolean(row[column.DataItem]), null); } else { prop.SetValue(conf, row[column.DataItem], null); } } } result.Add(conf); } #endregion using (CommonDomain domain = new CommonDomain()) { // Проверка на включение материалов #region check_including_material foreach (Aspect.Domain.Configuration conf in result) { Product prod = domain.Products.Single(p => p.ID == conf.ProductID); if (prod._dictNomen.cod >= 1000000) { LabelErrorMessage.Text = "[ ! ] Обнаружены материалы в спецификации. Сохранение отменино."; return; } } #endregion // Проверка на циклы #region check_for_cycles Guid dictNomenID = (Guid) (from p in domain.Products where p.ID == this.ProductID select p).Single()._dictNomenID; foreach (Aspect.Domain.Configuration conf in result) { Product prod = domain.Products.Where(p => p.ID == conf.ProductID).Single(); if (dictNomenID == prod._dictNomenID) { LabelErrorMessage.Text = "[ ! ] Обнаружены циклические включения продуктов в спецификацию. Сохранение отменино."; return; } if (fnCheckContains(dictNomenID, prod.ID)) { LabelErrorMessage.Text = "[ ! ] Обнаружены циклические включения продуктов в спецификацию. Сохранение отменино."; return; } } #endregion } provider.SaveProductConfiguration(this.ProductID, result, this.User.ID); // установка признака "Основная версия" if (MadeBasicVersion.Checked) { productProvider.SetMainVersion(this.User.ID, new List<Guid>{ProductID}); } // устанавливаем основание изменений if (!String.IsNullOrEmpty(ReasonChanges.Text)) { ProductProperty reasonProperty = productProvider.ProductProperties.SingleOrDefault( pr => pr.PropertyID == new Guid("C266B994-9740-41F6-94DD-07EA5B5FA34A") && pr.ProductID == this.ProductID); if (reasonProperty == null) { reasonProperty = new ProductProperty() { ID = Guid.NewGuid(), PropertyID = new Guid("C266B994-9740-41F6-94DD-07EA5B5FA34A"), ProductID = this.ProductID, Value = ReasonChanges.Text }; productProvider.ProductProperties.InsertOnSubmit(reasonProperty); } else { reasonProperty.Value = ReasonChanges.Text; } productProvider.SubmitChanges(); } // Очищаем сообщение об ошибке и обновляем данные о спецификации LabelErrorMessage.Text = ""; this.BindGridColumns2(); this.BindData(new Dictionary<Guid, Guid>()); } }