/// <summary> /// Заполнение списка характеристик товара /// </summary> /// <param name="__row"></param> private void FillOptions(ref FileRow __row) { dsParserTableAdapters.tInventOptionsTableAdapter ta = new dsParserTableAdapters.tInventOptionsTableAdapter(); dsParser.tInventOptionsDataTable tbl = ta.GetDataByInventItemId(__row.XmlId); if (tbl.Rows.Count > 0) { // Блок характеристик добавляется только при условии наличия характеристик string srcCode = ""; foreach (dsParser.tInventOptionsRow row in tbl) { if (row.Name.Trim() != string.Empty && row.Value.Trim() != string.Empty) { srcCode += row.Name.Trim().Replace(";", " ").Replace("\n", " ").Replace("\r", " ") + @": " + row.Value.Trim().Replace(";", " ").Replace("\n", " ").Replace("\r", " ") + @", "; } } if (srcCode.Length > 0) { __row.DetailText += @" Характеристики: " + srcCode; } } }
/// <summary> /// Записывает данные товара в БД /// </summary> public void RegisterInventItem() { if (Url.Length > 0 && Parent != null) { dsParserTableAdapters.tInventItemsTableAdapter taInventItems = new dsParserTableAdapters.tInventItemsTableAdapter(); dsParser.tInventItemsDataTable tblInventItems = taInventItems.GetDataByUrl(Url); dsParser.tInventItemsRow rowInventItems; if (tblInventItems.Rows.Count > 0) { rowInventItems = (dsParser.tInventItemsRow)tblInventItems.Rows[0]; } else { rowInventItems = tblInventItems.NewtInventItemsRow(); rowInventItems.Url = Url; } // Обновление данных товара rowInventItems.ParentId = Parent.Id; rowInventItems.Name = Name; rowInventItems.ShortDescr = ShortDescr; rowInventItems.Descr = Descr; rowInventItems.OldPrice = (decimal)OldPrice; rowInventItems.Price = (decimal)Price; if (rowInventItems.RowState == System.Data.DataRowState.Detached) { tblInventItems.Rows.Add(rowInventItems); } taInventItems.Update(tblInventItems); // Сохранение данных о картинках dsParserTableAdapters.tInventImagesTableAdapter taImages = new dsParserTableAdapters.tInventImagesTableAdapter(); dsParser.tInventImagesDataTable tblImages; dsParser.tInventImagesRow rowImages; foreach (string imageUrl in Images) { tblImages = taImages.GetDataByUrl(rowInventItems.Id, imageUrl); if (tblImages.Rows.Count == 0) { rowImages = tblImages.NewtInventImagesRow(); rowImages.InventItemId = rowInventItems.Id; rowImages.Url = imageUrl; tblImages.Rows.Add(rowImages); taImages.Update(tblImages); } } // Сохранение данных о характеристиках dsParserTableAdapters.tInventOptionsTableAdapter taOptions = new dsParserTableAdapters.tInventOptionsTableAdapter(); dsParser.tInventOptionsDataTable tblOptions; dsParser.tInventOptionsRow rowOptions; foreach (InventItemOption optionItem in Options) { tblOptions = taOptions.GetDataByName(rowInventItems.Id, optionItem.Name); if (tblOptions.Rows.Count > 0) { rowOptions = (dsParser.tInventOptionsRow)tblOptions.Rows[0]; } else { rowOptions = tblOptions.NewtInventOptionsRow(); rowOptions.InventItemId = rowInventItems.Id; rowOptions.Name = optionItem.Name; } rowOptions.Value = optionItem.Value; if (rowOptions.RowState == System.Data.DataRowState.Detached) { tblOptions.Rows.Add(rowOptions); } taOptions.Update(tblOptions); } } }