Exemplo n.º 1
0
        protected void BindDictionaryBranch(JsonTreeNode branch, Guid parentDict)
        {
            using (DictionaryProvider provider = new DictionaryProvider())
            {
                List<DictionaryTree> dicts = provider.GetDictionaryTreeList(parentDict, this.Roles);

                foreach (DictionaryTree dict in dicts)
                {
                    JsonTreeNode tempNode = new JsonTreeNode(dict.Name);
                    branch.children.Add(tempNode);
                    BindDictionaryBranch(tempNode, dict.ID);
                }
                if (!parentDict.Equals(Guid.Empty))
                {
                    DictionaryTree entity = provider.DictionaryTrees.SingleOrDefault(d => d.ID == parentDict);
                    List<DictionaryProperty> source = provider.GetAvailableDictionaryProperties(this.Roles, entity.DictionaryID);

                    foreach (DictionaryProperty prop in source)
                    {
                        JsonTreeNode tempNode = new JsonTreeNode(prop.Name);
                        tempNode.uid = String.Format("{0}_{1}", prop.Dictionary.TableName, prop.ColumnName);
                        tempNode.leaf = true;
                        branch.children.Add(tempNode);
                    }
                }
            }
        }
Exemplo n.º 2
0
 protected void BindPropertyTree()
 {
     JsonTreeNode rootProps = new JsonTreeNode("Свойства");
     using (DictionaryProvider provider = new DictionaryProvider())
     {
         List<Property> source = provider.GetAvailableProperties(this.Roles);
         foreach (Property prop in source)
         {
             JsonTreeNode tempNode = new JsonTreeNode(prop.Name);
             tempNode.leaf = true;
             tempNode.uid = prop.Alias;
             rootProps.children.Add(tempNode);
         }
     }
     jsonReponse.children.Add(rootProps);
 }
Exemplo n.º 3
0
        private void BindDictionaryList(List<ITreeNode> parents, bool isEmpty)
        {
            using (DictionaryProvider provider = new DictionaryProvider())
            {
                //--- dictionary property -----
                Product product = provider.Products.SingleOrDefault(p => p.ID == this.RequestProductID);
                if (product == null) this.RedirectToErrorPage();

                List<DictionaryTree> list = provider.GetDictionaryTreeList(Guid.Empty, this.Roles);
                var q = from l in list.Where(f => f.ClassificationID.HasValue)
                        join m in parents on l.ClassificationID.Value equals m.ID
                        select new Pair<DictionaryTree, string>(l, m.Name);

                List<DictionaryDDLSource> source = new List<DictionaryDDLSource>();
                foreach (Pair<DictionaryTree, string> item in q.ToList())
                {
                    DictionaryDDLSource entity = new DictionaryDDLSource();
                    entity.DictionaryTreeID = item.First.ID;
                    //set dictionary property title
                    entity.Title = string.Format("{0} ({1})", item.First.Name, item.Second);
                    //get product dicitonary value
                    object value = provider.GetProductDicitonaryValue(this.RequestProductID, item.First.FK);

                    if (value != null && !string.IsNullOrEmpty(value.ToString()) && !isEmpty)
                    {
                        entity.ID = new Guid(value.ToString());//entity.SelectedValue = value.ToString();
                        string valueText = provider.GetProductDictionaryText(entity.ID, item.First).ToString();
                        if (!string.IsNullOrEmpty(valueText) && valueText.Trim().Length > 0) entity.ValueText = valueText;
                    }

                    source.Add(entity);
                }
                DictionaryPropertyRepeater.DataSource = source;
                DictionaryPropertyRepeater.DataBind();
            }
        }
Exemplo n.º 4
0
        public void BindDictionaryTreeView(Guid parentID, TreeNode parentNode, ContentDomain domain, List<ITreeNode> parents)
        {
            using (DictionaryProvider provider = new DictionaryProvider())
            {
                //bind child dictionaries
                List<ITreeNode> list = new List<ITreeNode>();
                if (parentID.Equals(Guid.Empty))
                {
                    List<DictionaryTree> list1 = provider.GetDictionaryTreeList(parentID, this.Roles);
                    var q = from l in list1.Where(f => f.ClassificationID.HasValue)
                            join m in parents on l.ClassificationID.Value equals m.ID
                            select new DictionaryTree
                            {
                                ID = l.ID,
                                ParentID = l.ParentID,
                                Name = string.Format("{0} ({1})", l.Name, m.Name)
                            } as ITreeNode;
                    //l as ITreeNode;
                    list = q.ToList();
                }
                else
                {
                    list = provider.GetList(parentID, User.ID, Roles);
                }
                foreach (ITreeNode item in list)
                {
                    TreeNode node = new TreeNode(item.Name, item.ID.ToString());
                    node.SelectAction = TreeNodeSelectAction.Expand;
                    if (parentNode != null) parentNode.ChildNodes.Add(node);
                    else DictionaryTreeView.Nodes.Add(node);

                    this.BindDictionaryTreeView(item.ID, node, domain, parents);
                }
                //bind fields
                if (parentNode != null && !parentID.Equals(Guid.Empty))
                {
                    DictionaryTree entity = provider.DictionaryTrees.SingleOrDefault(d => d.ID == parentID);
                    List<IUserField> fields = domain.GetUserFields(this.User.ID, RequestClassificationTreeID, this.FieldPlaceHolderID).Where(uf => uf.DictionaryTreeID == parentID).ToList();

                    List<Guid> previous = this.PreviouseDictionaries;
                    previous.AddRange(fields.Select(f => f.DictionaryProperty.ID));
                    this.PreviouseDictionaries = previous;

                    //List<DictionaryProperty> source = entity.Dictionary.DictionaryProperties.ToList();
                    List<DictionaryProperty> source = provider.GetAvailableDictionaryProperties(this.Roles, entity.DictionaryID);

                    foreach (DictionaryProperty prop in source)
                    {
                        TreeNode node = new TreeNode(prop.Name, prop.ID.ToString());
                        node.SelectAction = TreeNodeSelectAction.None;
                        IUserField field = fields.Find(f => f.DictionaryProperty.ID == prop.ID);
                        if (field != null)
                        {
                            node.Checked = true;
                            node.Value = string.Format("{0},{1}", node.Value, field.Sequence);
                        }
                        else node.Checked = false;
                        parentNode.ChildNodes.AddAt(0, node);
                    }
                }
                //--
            }
        }
Exemplo n.º 5
0
        private void DataLoad()
        {
            using (DictionaryProvider domain = new DictionaryProvider())
            {
                object val = domain.GetProductDictionaryText(this.RequestDictionaryEntityID, this.DictionaryTreeID);
                //Aspect.Domain.Product prod = domain.GetProduct(this.RequestDictionaryEntityID);

                //if (prod == null) return;
                this.Title = HeaderLiteral.Text = string.Format("Редактирование {0}", val.ToString());
                if (this.IsNew) this.Title = HeaderLiteral.Text = string.Format("Добавление по аналогу {0}", val.ToString());
                HeaderDateLiteral.Text = string.Format(HeaderDateLiteral.Text, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());

                BindGeneralPropertyList();
                BindDictionaryList();
            }
        }
Exemplo n.º 6
0
        private void BindGeneralPropertyList()
        {
            using (DictionaryProvider provider = new DictionaryProvider())
            {
                //--- general property-------
                List<DictionaryProperty> props = provider.GetAvailableDictionaryPropertiesToModify(this.DictionaryTreeID, this.Roles);

                List<Pair<DictionaryProperty, object>> source = new List<Pair<DictionaryProperty, object>>();
                foreach (DictionaryProperty item in props)
                {
                    object obj = provider.GetDictionaryItemValue(this.DictionaryTreeID, this.RequestDictionaryEntityID, item.ColumnName);
                    Pair<DictionaryProperty, object> entity = new Pair<DictionaryProperty, object>(item, obj);
                    source.Add(entity);
                }
                GeneralPropertyRepeater.DataSource = source;//props;
                GeneralPropertyRepeater.DataBind();

                NotSavedProperties = new List<Pair<string, string>>();
            }
        }
Exemplo n.º 7
0
        private void BindDictionaryList()
        {
            using (DictionaryProvider provider = new DictionaryProvider())
            {
                List<DictionaryTree> list = provider.GetDictionaryTreeList(this.DictionaryTreeID, this.Roles);

                List<DictionaryDDLSource> source = new List<DictionaryDDLSource>();
                foreach (DictionaryTree item in list)
                {
                    DictionaryDDLSource entity = new DictionaryDDLSource();
                    entity.DictionaryTreeID = item.ID;
                    //set dictionary property title
                    entity.Title = item.Name; //string.Format("{0} ({1})", item.First.Name, item.Second);
                    //get product dicitonary value
                    object value = provider.GetDictionaryItemValue(this.DictionaryTreeID, this.RequestDictionaryEntityID, item.FK);

                    if (value != null && !string.IsNullOrEmpty(value.ToString()))
                    {
                        entity.ID = new Guid(value.ToString());//entity.SelectedValue = value.ToString();
                        string valueText = provider.GetProductDictionaryText(entity.ID, item).ToString();
                        if (!string.IsNullOrEmpty(valueText) && valueText.Trim().Length > 0) entity.ValueText = valueText;
                    }

                    source.Add(entity);
                }
                DictionaryPropertyRepeater.DataSource = source;
                DictionaryPropertyRepeater.DataBind();
            }
        }
Exemplo n.º 8
0
 private void BindGridColumns()
 {
     SelectorGrid.Columns.Clear();
     HyperLinkField selector = new HyperLinkField();
     selector.Text = "Выбрать";
     selector.ItemStyle.Width = new Unit(30, UnitType.Pixel);
     SelectorGrid.Columns.Add(selector);
     using (DictionaryProvider provider = new DictionaryProvider())
     {
         List<GridColumn> columns = provider.GetGridColumns(this.User.ID, DictionaryTreeID, FieldPlaceHolder.Grid);
         foreach (GridColumn item in columns)
         {
             ProductGridField field = new ProductGridField(item.Name, item.DataItem);
             field.SortExpression = item.DataItem;
             SelectorGrid.Columns.Add(field);
             SearchExpression expr = this.SearchConditions.FirstOrDefault(s => s.FieldID == item.ID);
             field.HeaderText = expr == null ? field.HeaderText : string.Format("{0} ({1})", field.HeaderText, expr.FieldValue);
         }
     }
 }
Exemplo n.º 9
0
        protected void SelectorGrid_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.DataItem != null)
                {
                    if (e.Row.RowState == DataControlRowState.Alternate) e.Row.CssClass += " row2";

                    //HyperLink link = e.Row.Cells[0].FindControl("СhooseButton") as HyperLink;
                    HyperLink link = e.Row.Cells[0].Controls[0] as HyperLink;
                    link.NavigateUrl = "javascript:void(0);";
                    using (DictionaryProvider provider = new DictionaryProvider())
                    {
                        if (tree == null) tree = provider.GetDictionaryTreeNode(this.DictionaryTreeID);
                        Guid id = new Guid(DataBinder.Eval(e.Row.DataItem, /*this.ValueField*/"ID").ToString());
                        string text = provider.GetProductDictionaryText(id, tree).ToString();
                        string function;
                        if (MultiMode)
                        {
                            function = String.Format("fnSelectRow('{0}','{1}');return false;", id, text);
                            e.Row.CssClass += " " + id.ToString();

                            var pair = MultiSelection.Value.Split(';').Where(i => !String.IsNullOrEmpty(i));
            ;
                            var idsList = pair.Select(i => new Guid (i.Split(':').First()));

                            if (idsList.Contains(id)) e.Row.CssClass += " RowSelected";
                        }
                        else
                        {
                            function = String.Format("self.parent.setSelectedValue('{0}','{1}','{2}','{3}');self.parent.tb_remove();return false;", this.HiddenControlID, id, this.TextControlID, text);
                        }

                        //string function = String.Format("self.parent.setSelectedValue('{0}','{1}','{2}','{3}');self.parent.tb_remove();return false;", this.HiddenControlID, DataBinder.Eval(e.Row.DataItem, /*this.ValueField*/"ID"), this.TextControlID, DataBinder.Eval(e.Row.DataItem, this.TextField));
                        link.Attributes.Add("onclick", function);
                    }

                    e.Row.Attributes["onmouseover"] = "highLightRow(this)";
                    e.Row.Attributes["onmouseout"] = "unHighLightRow(this)";
                }
            }
        }
Exemplo n.º 10
0
        protected void GridPager_CurrentPageChanged(object sender, PagerEventArgs e)
        {
            using (DictionaryProvider provider = new DictionaryProvider())
            {
                DictionaryTree entity = provider.DictionaryTrees.Single(d => d.ID == DictionaryTreeID);
                List<GridColumn> columns = provider.GetGridColumns(this.User.ID, DictionaryTreeID, FieldPlaceHolder.Grid);
                System.Data.DataSet source = provider.GetList(DictionaryTreeID, this.User.ID, this.OrderExpression,
                    this.SearchConditions, new PagingInfo(false));
                //provider.GetDictionaryDataSource(entity, SearchExp);
                ValueField = entity.PK;
                TextField = entity.Dictionary.IdentifierField;
                if (source != null && source.Tables.Count > 0)
                {
                    GridPager.Visible = SelectorGrid.Visible = true;
                    GridPager.CurrentPage = e.CurrentPage;
                    GridPager.TotalRecords = source.Tables[0].DefaultView.Count;

                    SelectorGrid.DataSource = source;
                    SelectorGrid.PageIndex = e.CurrentPage;
                    SelectorGrid.DataBind();
                    this.AppendGridHeader(columns);
                }
            }
        }
Exemplo n.º 11
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            //if (this.IsNew)
            //{
                string version = null;
                string nomenValue = null;
                CustomValidator validator1 = null;
                CustomValidator validator2 = null;
                #region Get the @version
                foreach (RepeaterItem item in GeneralPropertyRepeater.Items)
                {
                    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                    {
                        Guid id = new Guid((item.FindControl("HiddenID") as HiddenField).Value);
                        if (id == new Guid("0789DB1A-9BAA-4574-B405-AE570C746C03"))
                        {
                            EditControl editControl = item.FindControl("PropertyValueAdv") as EditControl;
                            if (!editControl.Validate()) return;
                            version = editControl.Value.ToString().Trim();
                            //version = (item.FindControl("PropertyValue") as TextBox).Text.Trim();
                            validator1 = item.FindControl("UniqueValueValidator") as CustomValidator;
                        }
                    }
                }
                #endregion
                #region Get the @nomenValue
                foreach (RepeaterItem item in DictionaryPropertyRepeater.Items)
                {
                    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                    {
                        Guid dictId = new Guid((item.FindControl("HiddenTreeID") as HiddenField).Value);
                        if (dictId == new Guid("316C6BC7-D883-44C8-AAE0-602F49C73595"))
                        {
                            nomenValue = (item.FindControl("HiddenID") as HiddenField).Value;
                            validator2 = item.FindControl("UniqueValueValidator") as CustomValidator;
                        }
                    }
                }
                #endregion
                #region Check the unique @version && @nomenValue
                if (version != null && nomenValue != null && validator1 != null && validator2 != null)
                {
                    using (ProductProvider provider = new ProductProvider())
                    {
                        var q = from p in provider.Products
                                join pp in provider.ProductProperties on p.ID equals pp.ProductID
                                where pp.PropertyID == new Guid("0789DB1A-9BAA-4574-B405-AE570C746C03") //&& p.ID == this.RequestProductID
                                && pp.Value == version && p._dictNomenID == new Guid(nomenValue)
                                select p;
                        List<Product> list = q.ToList();
                        if (list.Count > 0 && this.IsNew)
                        {
                            validator1.IsValid = false;
                            validator2.IsValid = false;
                            return;
                        }
                        else if (list.Count > 0 && list.Where(p => p.ID == this.RequestProductID).Count() == 0)
                        {
                            validator1.IsValid = false;
                            validator2.IsValid = false;
                            return;
                        }
                    }
                }
                else
                {
                    return;
                }
                #endregion
                #region Check the main version canceling...
                string mainVersionValue = null;
                CustomValidator mainVersionValidator = null;
                foreach (RepeaterItem item in GeneralPropertyRepeater.Items)
                {
                    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                    {
                        Guid id = new Guid((item.FindControl("HiddenID") as HiddenField).Value);
                        if (id == new Guid("bbe170b0-28e4-4738-b365-1038b03f4552"))
                        {
                            EditControl editControl = item.FindControl("PropertyValueAdv") as EditControl;
                            if (!editControl.Validate()) return;
                            mainVersionValue = editControl.Value.ToString().Trim();
                            mainVersionValidator = item.FindControl("UniqueValueValidator") as CustomValidator;
                        }
                    }
                }
                if (mainVersionValue != null && mainVersionValidator != null && !this.IsNew)
                {
                    using (ProductProvider provider = new ProductProvider())
                    {
                        var q = from p in provider.ProductProperties
                                where p.PropertyID == new Guid("bbe170b0-28e4-4738-b365-1038b03f4552")
                                && p.ProductID == this.RequestProductID
                                select p;
                        List<ProductProperty> list = q.ToList();
                        if (list.Count == 1)
                        {
                            // попытка изменить основную версию
                            if (list.First().Value == "1")
                            {
                                mainVersionValidator.IsValid = false;
                                return;
                            }
                        }
                    }
                }
                #endregion
                //}
            if (this.IsNew)
            {
                using (ProductProvider provider = new ProductProvider())
                {
                    Guid newID = provider.AddNewProduct(this.RequestProductID, User.ID);
                    if (this.IsWithConfs)
                    {
                        // копирование по аналогу вместе с составом
                        provider.CopyConfiguration(this.RequestProductID, newID, this.User.ID);
                    }
                    newProductID = newID;
                }
            }

            using (ProductProvider provider = new ProductProvider())
            {
                Product editedProduct = provider.GetProduct(RequestProductID);
                if (editedProduct.userID != User.ID)
                {
                    editedProduct.userID = User.ID;
                    provider.SubmitChanges();
                }
            }

            #region update dictionary values
            using (DictionaryProvider provider = new DictionaryProvider())
            {
                foreach (RepeaterItem item in DictionaryPropertyRepeater.Items)
                {
                    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                    {
                        Guid dictId = new Guid((item.FindControl("HiddenTreeID") as HiddenField).Value);
                        string valueString = (item.FindControl("HiddenID") as HiddenField).Value;
                        DictionaryTree dict = provider.DictionaryTrees.Single(d => d.ID == dictId);
                        if (!string.IsNullOrEmpty(valueString) && !(new Guid(valueString).Equals(Guid.Empty)))
                        {
                            provider.SetProductDictioanryValue(this.RequestProductID, dict.FK, valueString.Trim(), User.ID);
                        }
                        else
                        {
                            provider.DeleteProductDictionaryValue(this.RequestProductID, dict.FK, User.ID);
                        }
                    }
                }
                provider.SubmitChanges();
            }
            #endregion

            #region update properties values
            using (ProductProvider provider = new ProductProvider())
            {
                bool settingMainVersion = false;

                foreach (RepeaterItem item in GeneralPropertyRepeater.Items)
                {
                    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                    {
                        Guid id = new Guid((item.FindControl("HiddenID") as HiddenField).Value);
                        //string value = (item.FindControl("PropertyValue") as TextBox).Text.Trim();
                        EditControl editControl = item.FindControl("PropertyValueAdv") as EditControl;
                        if (!editControl.IsEmpty && !editControl.Validate())
                        {
                            continue;
                        }

                        // Если поле "Вес по приказу" не заполнено, то заполняем его из номенклатуры
                        if (id == new Guid("AC37F816-E4C1-4751-99ED-6180D7CCA142") && editControl.IsEmpty)
                        {
                            Product prod = provider.GetProduct(this.RequestProductID);
                            if (prod._dictNomen.pw.HasValue)
                            {
                                editControl.Value = prod._dictNomen.pw.Value.ToString(CultureInfo.InvariantCulture).Replace(".", ",");
                            }

                        }

                        if (editControl.IsEmpty)
                        {
                            ProductProperty prop = provider.ProductProperties.SingleOrDefault(pp => pp.PropertyID == id && pp.ProductID == this.RequestProductID);
                            if (prop != null)
                            {
                                provider.ProductProperties.DeleteOnSubmit(prop);
                                provider.SubmitChanges();
                            }
                            continue;
                        }

                        string value = editControl.Value.ToString().Trim();
                        if (editControl.ControlType == TypeEnum.Datetime)
                        {
                            DateTime dt = DateTime.ParseExact(value, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
                            if (dt == DateTime.MinValue) value = string.Empty;
                            else value = dt.ToString("yyyy-MM-dd hh:mm:ss.fff");
                        }

                        // установка признака "Основная версия"
                        if (id == new Guid ("BBE170B0-28E4-4738-B365-1038B03F4552") && value == "1")
                        {
                            settingMainVersion = true;
                        }

                        ProductProperty property = provider.ProductProperties.SingleOrDefault(pp => pp.PropertyID == id && pp.ProductID == this.RequestProductID);
                        if (property != null)
                        {
                            if (property.Value != value)
                            {
                                Aspect.Utility.TraceHelper.Log(User.ID, "Продукт: {0}. Свойство изменино: {1}. Старое значение {2}. Новое значение {3}", this.RequestProductID, property.Property.Name, property.Value, value);
                            }
                            property.Value = value;
                        }
                        else
                        {
                            property = new ProductProperty()
                            {
                                ID = Guid.NewGuid(),
                                ProductID = this.RequestProductID,
                                PropertyID = id,
                                Value = value
                            };
                            provider.ProductProperties.InsertOnSubmit(property);
                            Property prop = provider.Properties.Single(p => p.ID == id);
                            Aspect.Utility.TraceHelper.Log(User.ID, "Продукт: {0}. Свойство изменино: {1}. Старое значение NULL. Новое значение {2}", this.RequestProductID, prop.Name, value);
                        }
                        provider.SubmitChanges();
                    }
                }

                // Переносим вес из продуктов в _dictNomen, если там он отсутствует (0 или null)
                if (settingMainVersion)
                {
                    try
                    {
                        // Пытаемся получить свойство с весом если оно есть
                        string raw_pw = (from p in provider.Products
                                      join pp in provider.ProductProperties on p.ID equals pp.ProductID
                                      where p.ID == this.RequestProductID && pp.PropertyID == new Guid("AC37F816-E4C1-4751-99ED-6180D7CCA142")
                                      select pp.Value).Single();
                        decimal prod_pw = Convert.ToDecimal(raw_pw.Replace(',', '.'), CultureInfo.InvariantCulture);

                        // Если свойство есть переносим его
                        if (prod_pw != 0)
                        {
                            _dictNomen dict = (from p in provider.Products
                                               join d in provider._dictNomens on p._dictNomenID equals d.ID
                                               where p.ID == this.RequestProductID
                                               select d).Single();
                            dict.pw = prod_pw;
                            provider.SubmitChanges();
                        }
                    }
                    catch
                    {
                        // перехватываем исключение, так как веса у продукта может вовсе и не быть
                    }
                }
            }
            #endregion

            if (this.IsNew)
            {
                // добавить свойство "пустой состав"
                if (!this.IsWithConfs)
                {
                    using (CommonDomain provider = new CommonDomain())
                    {
                        var properties = from props in provider.ProductProperties
                                         where props.PropertyID == new Guid("00ACC1C7-6857-4317-8713-8B8D9479C5CC") // Свойство "Наличие состава"
                                         && props.ProductID == RequestProductID
                                         select props;

                        if (properties.Count() > 1)
                        {
                            // если несколько одинаковых свойств - генерируем исключение
                            throw new Exception("У продукта не может быть больше одного свойства \"Наличие состава\"!");
                        }
                        else if (properties.Count() == 1)
                        {
                            // если только одно свойство - редактируем его, и сохраняемся
                            properties.First().Value = "-";
                        } else
                        {
                            // если нет ниодного свойства, создаём его с нужным нам значеним
                            provider.ProductProperties.InsertOnSubmit(new ProductProperty()
                            {
                                ID = Guid.NewGuid(),
                                ProductID = RequestProductID,
                                PropertyID = new Guid("00ACC1C7-6857-4317-8713-8B8D9479C5CC"),
                                Value = "-"
                            });

                        }
                        provider.SubmitChanges();
                    }
                }

                // перенаправить на редактирование
                Response.Redirect(string.Format("Edit.aspx?ID={0}", this.RequestProductID));
                return;
            }
            if(Page.IsValid) this.DataLoad();
        }
Exemplo n.º 12
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (this.DictionaryTreeID == new Guid("316C6BC7-D883-44C8-AAE0-602F49C73595"))
            {
                Guid _dictP1STID = Guid.Empty;
                Guid _dictGOSTID = Guid.Empty;
                string PN1 = string.Empty;
                string PN2_2 = string.Empty;
                EditControl superfieldControl = null;
                EditControl superfieldControl_ua = null;
                foreach (RepeaterItem item in GeneralPropertyRepeater.Items)
                {
                    string col_name = (item.FindControl("HiddenID") as HiddenField).Value;
                    if (col_name.ToUpper() == "PN1")
                    {
                        EditControl editControl = item.FindControl("PropertyValueAdv") as EditControl;
                        if (!editControl.Validate()) return;
                        PN1 = editControl.Value.ToString().Trim();
                    }
                    if (col_name.ToUpper() == "PN2_2")
                    {
                        EditControl editControl = item.FindControl("PropertyValueAdv") as EditControl;
                        if (!editControl.Validate()) return;
                        PN2_2 = editControl.Value.ToString().Trim();
                    }
                    if (col_name.ToLower() == "superpole")
                    {
                        superfieldControl = item.FindControl("PropertyValueAdv") as EditControl;
                    }
                    if (col_name.ToLower() == "superpole_ua")
                    {
                        superfieldControl_ua = item.FindControl("PropertyValueAdv") as EditControl;
                    }
                }

                foreach (RepeaterItem item in DictionaryPropertyRepeater.Items)
                {
                    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                    {
                        Guid dictId = new Guid((item.FindControl("HiddenTreeID") as HiddenField).Value);
                        if (dictId == new Guid("98C60832-A66C-4A84-BC90-EB83EE43C4C9"))
                        {
                            _dictP1STID = new Guid((item.FindControl("HiddenID") as HiddenField).Value);
                        }
                        if (dictId == new Guid("BB4BCA91-C56D-4746-B5C2-C7CF29596F3D"))
                        {
                            _dictGOSTID = new Guid((item.FindControl("HiddenID") as HiddenField).Value);
                        }
                    }
                }

               using (DictionaryProvider provider = new DictionaryProvider())
               {
                   string superfield = provider.GetNomenSuperFieldValue(_dictP1STID, _dictGOSTID, PN1, PN2_2);
                   string superfield_ua = provider.GetNomenSuperFieldValueUa(_dictP1STID, _dictGOSTID, PN1, PN2_2);

                   if (superfieldControl != null) superfieldControl.Value = superfield;
                   if (superfieldControl_ua != null )
                   {
                       if (String.IsNullOrEmpty(superfieldControl_ua.Value.ToString().Trim()))
                       {
                           // если поле с "укр. суперполем" пусто, устанавливаем расчитанное значение
                           superfieldControl_ua.Value = superfield_ua;
                       }
                   }

                   #region Check [superpole] && [pn1] for uniqueness
                   // Проверка поля [superpole] на уникальность
                   List<_dictNomen> list = provider._dictNomens.Where(d => d.superpole.Trim() == superfield).ToList();
                   if (this.IsNew && !this.IsNewAdded && list.Count > 0)
                   {

                       UniqueValueValidator.ErrorMessage = string.Format("Значение Общ. наименование должно быть уникальным ( {0} )", superfield);
                       UniqueValueValidator.IsValid = false;
                       return;
                   }
                   else if (list.Count > 0 && list.Where(l => l.ID == this.RequestDictionaryEntityID).Count() == 0)
                   {
                       UniqueValueValidator.ErrorMessage = string.Format("Значение Общ. наименование должно быть уникальным ( {0} )", superfield);
                       UniqueValueValidator.IsValid = false;
                       return;
                   }

                   // Проверка поля [pn1] на уникальность
                   List<_dictNomen> listPn1 = provider._dictNomens.Where(d => d.pn1.Trim() == PN1).ToList();
                   if (this.IsNew && !this.IsNewAdded && listPn1.Count > 0)
                   {
                       UniqueValueValidator.Text = string.Format("! Значение поля [Обозначение] должно быть уникальным ( {0} )", PN1);
                       UniqueValueValidator.IsValid = false;
                       return;
                   }
                   else if (listPn1.Count > 0 && listPn1.Where(l => l.ID == this.RequestDictionaryEntityID).Count() == 0)
                   {
                       UniqueValueValidator.Text = string.Format("! Значение поля [Обозначение] должно быть уникальным ( {0} )", PN1);
                       UniqueValueValidator.IsValid = false;
                       return;
                   }

                   #endregion
               }
            }

            Guid oldDictionaryEntityID = this.RequestDictionaryEntityID;
            if (this.IsNew && !this.IsNewAdded)
            {
                using (DictionaryProvider provider = new DictionaryProvider())
                {
                    Guid newID = provider.AddNewDictionaryEntity(this.DictionaryTreeID, this.RequestDictionaryEntityID);
                    this.RequestDictionaryEntityID = newID;
                    IsNewAdded = true;
                    //newDictionaryEntityID = newID;
                    Aspect.Utility.TraceHelper.Log(User.ID, "Справочник treeID: {0}. Новая запись: {1}", this.DictionaryTreeID, newID);
                }
            }
            using (DictionaryProvider provider = new DictionaryProvider())
            {
                //update properties
                foreach (RepeaterItem item in GeneralPropertyRepeater.Items)
                {
                    string col_name = (item.FindControl("HiddenID") as HiddenField).Value;
                    //string value = (item.FindControl("PropertyValue") as TextBox).Text.Trim();
                    EditControl editControl = item.FindControl("PropertyValueAdv") as EditControl;
                    if (!editControl.Validate())
                    {
                        continue;
                    }
                    string value = editControl.Value.ToString().Trim();
                    /*if (col_name == "superpole" && this.DictionaryTreeID == new Guid("316C6BC7-D883-44C8-AAE0-602F49C73595"))
                    {
                    }*/
                    try
                    {
                        if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                        {
                            object obj = provider.GetDictionaryItemValue(this.DictionaryTreeID, this.RequestDictionaryEntityID, col_name);
                            if (obj == null || obj == DBNull.Value || !value.Equals(obj.ToString().Trim()))
                            {
                                Aspect.Utility.TraceHelper.Log(User.ID, "Справочник treeID: {0}.  Запись: {4}. Свойство изменино: {1}. Старое значение {2}. Новое значение {3}", this.DictionaryTreeID, col_name, ((obj == null || obj == DBNull.Value) ? "NULL" : obj.ToString()), value, RequestDictionaryEntityID);
                                if (editControl.ControlType == TypeEnum.Datetime)
                                {
                                    DateTime dt = DateTime.ParseExact(value, "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
                                    if (dt == DateTime.MinValue) provider.DeleteDictionaryItemValue(this.DictionaryTreeID, this.RequestDictionaryEntityID, col_name);
                                    else provider.SetDictionaryItemValue(this.DictionaryTreeID, this.RequestDictionaryEntityID, col_name, dt.ToString("MM/dd/yyyy"), User.ID);
                                }
                                else
                                {
                                    if (IsNew && col_name == "raznes") value = "0";
                                    /*
                                     * Переносим вес в первую версию продукта основную версию при условии
                                     */
                                    #region moving_weight
                                    if (IsNew && col_name == "pw")
                                    {
                                        using (ProductProvider productProvider = new ProductProvider())
                                        {
                                            try
                                            {
                                                productProvider.SetProductWeight(this.RequestDictionaryEntityID, Convert.ToDecimal(value.Replace(",", "."), CultureInfo.InvariantCulture));
                                            }
                                            catch { }
                                        }
                                    }
                                    #endregion
                                    provider.SetDictionaryItemValue(this.DictionaryTreeID, this.RequestDictionaryEntityID, col_name, value, User.ID);
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        this.NotSavedProperties.Add(new Pair<string, string>(col_name, value));
                        //(item.FindControl("PropertyValidator") as CustomValidator).IsValid = false;
                    }
                }

                foreach (RepeaterItem item in DictionaryPropertyRepeater.Items)
                {
                    if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                    {
                        Guid dictId = new Guid((item.FindControl("HiddenTreeID") as HiddenField).Value);
                        string valueString = (item.FindControl("HiddenID") as HiddenField).Value;
                        DictionaryTree dict = provider.DictionaryTrees.Single(d => d.ID == dictId);

                        object obj = provider.GetDictionaryItemValue(this.DictionaryTreeID, this.RequestDictionaryEntityID, dict.FK);

                        if (!string.IsNullOrEmpty(valueString) && !(new Guid(valueString).Equals(Guid.Empty)))
                        {
                            if (obj == null || obj == DBNull.Value || obj.ToString() != valueString)
                            {
                                Aspect.Utility.TraceHelper.Log(User.ID, "Справочник treeID: {0}. Запись: {4}. Свойство изменино: {1}. Старое значение {2}. Новое значение {3}", this.DictionaryTreeID, dict.FK, ((obj == null || obj == DBNull.Value) ? "NULL" : obj.ToString()), valueString, this.RequestDictionaryEntityID);
                                provider.SetDictionaryItemValue(this.DictionaryTreeID, this.RequestDictionaryEntityID, dict.FK, valueString.Trim(), User.ID);
                            }
                        }
                        else
                        {
                            if (obj != null && obj != DBNull.Value)
                            {
                                Aspect.Utility.TraceHelper.Log(User.ID, "Справочник treeID: {0}. Запись: {3}. Свойство удалено: {1}. Старое значение {2}. Новое значение NULL", this.DictionaryTreeID, dict.FK, obj.ToString(), this.RequestDictionaryEntityID);
                                provider.DeleteDictionaryItemValue(this.DictionaryTreeID, this.RequestDictionaryEntityID, dict.FK);
                            }
                        }
                    }
                }
                //provider.SubmitChanges();
            }
            //this.BindDictionaryList();
            /*if (this.IsNew && this.IsValid)
            {
                Response.Redirect(string.Format("~/Editarea/EditDict.aspx?ID={0}&new=false&DictID={1}", this.RequestDictionaryEntityID, Request["DictID"]));
            }*/

            // для "Номенклатура" и "Номен. материала"
            if (this.IsNew && DictionaryTreeID == new Guid("316c6bc7-d883-44c8-aae0-602f49c73595"))
            {
                // если "Копировать состав из основной версии"
                if (this.CopyMainVersion.Checked)
                {
                    using (ProductProvider provider = new ProductProvider())
                    {
                        Guid newMainProductID = (from prod in provider.Products
                                                 where prod._dictNomenID == this.RequestDictionaryEntityID
                                                 select prod.ID).FirstOrDefault();
                        Guid oldMainProductID = (from prod in provider.Products
                                              join vers in provider.ProductProperties
                                                on prod.ID equals vers.ProductID
                                              where vers.Value == "1" && vers.PropertyID == new Guid("BBE170B0-28E4-4738-B365-1038B03F4552") // основная версия
                                              && prod._dictNomenID == oldDictionaryEntityID
                                              select prod.ID).FirstOrDefault();

                        if (!Guid.Empty.Equals(oldMainProductID))
                        {
                            //newMainProductID = provider.CopyProduct(oldMainProductID, 2, RequestDictionaryEntityID);
                            provider.CopyConfiguration(oldMainProductID, newMainProductID, User.ID);
                        }
                    }
                }
                // если класс не "МатРесурсы"
                if (new Guid(userCID.Value) != new Guid("55c7b455-0638-4acb-ac2e-5b4992e48462"))
                {
                    using (ProductProvider provider = new ProductProvider())
                    {
                        provider.ChangeProductClassification(this.RequestDictionaryEntityID, new Guid(userCID.Value));
                    }
                }
            }
            if (IsNew) Response.Redirect(string.Format("/Editarea/EditDict.aspx?ID={0}&new=false&DictID={1}", RequestDictionaryEntityID, DictionaryTreeID));
            else if(Page.IsValid) this.DataLoad();
        }
Exemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                IsNewAdded = false;
                try
                {
                    RequestDictionaryEntityID = new Guid(this.Request["ID"]);
                }
                catch
                {
                    this.RedirectToErrorPage();
                }

                // для "Номенклатура" и "Номен. материала"
                if (IsNew && DictionaryTreeID == new Guid("316c6bc7-d883-44c8-aae0-602f49c73595"))
                {
                    using (DictionaryProvider provider = new DictionaryProvider())
                    {
                        if (!provider.IsSimpleDetal(this.RequestDictionaryEntityID))
                        {
                            CopyMainVersion.Visible = true;
                        }
                    }
                }
                // только для новых пунктов в Номенклатуре
                if (!IsNew || !DictionaryTreeID.Equals(new Guid("316c6bc7-d883-44c8-aae0-602f49c73595")))
                {
                    SelectorButton.Visible = false;
                }
                this.DataLoad();
            }
        }