private void ConditionControlDeleted(object sender, EventArgs e) { CategoryRecordControl control = (CategoryRecordControl)sender; CategoryRecord cond = control.CategoryRecord; if (cond.ItemId > 0 && MessageBox.Show("Do you really want to delete Category record?", "Deleting confirmation", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { //если информация о состоянии сохранена в БД //и получен положительный ответ на ее удаление try { GlobalObjects.NewKeeper.Delete(cond); } catch (Exception ex) { Program.Provider.Logger.Log("Error while removing data", ex); } flowLayoutPanelMain.Controls.Remove(control); control.Deleted -= ConditionControlDeleted; control.Dispose(); } else if (cond.ItemId <= 0) { flowLayoutPanelMain.Controls.Remove(control); control.Deleted -= ConditionControlDeleted; control.Dispose(); } }
public void SeedCategories(eCommerceContext context) { Category uncategorized = new Category() { SanitizedName = "uncategorized", DisplaySeqNo = 0, ModifiedOn = DateTime.Now }; CategoryRecord uncategorizedEnRecord = new CategoryRecord() { Category = uncategorized, LanguageID = EnglishLanguageID, //global Name = "Uncategorized", Description = "Products that are not categorized. uncategorised, unclassified - not arranged in any specific grouping.", ModifiedOn = DateTime.Now }; CategoryRecord uncategorizedArRecord = new CategoryRecord() { Category = uncategorized, LanguageID = ArabicLanguageID, //global Name = "غير مصنف", Description = "المنتجات غير المصنفة. غير مصنفة ، غير مصنفة - غير مرتبة في أي مجموعة محددة.", ModifiedOn = DateTime.Now }; context.Categories.Add(uncategorized); context.CategoryRecords.Add(uncategorizedEnRecord); context.CategoryRecords.Add(uncategorizedArRecord); context.SaveChanges(); }
public bool SaveCategoryRecord(CategoryRecord categoryRecord) { var context = DataContextHelper.GetNewContext(); context.CategoryRecords.Add(categoryRecord); return(context.SaveChanges() > 0); }
public bool UpdateCategoryRecord(CategoryRecord categoryRecord) { var context = DataContextHelper.GetNewContext(); var existingRecord = context.CategoryRecords.Find(categoryRecord.ID); context.Entry(existingRecord).CurrentValues.SetValues(categoryRecord); return(context.SaveChanges() > 0); }
private static CategoryRecord UnpackCategoryRecord(BinaryReader reader) { var catRec = new CategoryRecord(); catRec.Category = new Guid(reader.ReadBytes(16)); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { catRec.ColorRecords.Add(UnpackColorRecord(reader)); } return(catRec); }
/// <summary> /// Creates a category record /// </summary> /// <param name="r"></param> private void CreateCategory(Product[] products, ref List <IRecord> recList, ref List <ulong> indexList) { for (int x = 0; x < products.Length; x++) { //if the list is null skip iteration if (products[x].categories == null) { continue; } for (int y = 0; y < products[x].categories.Length; y++) { //new category record CategoryRecord catRec = new CategoryRecord(indexList[x], products[x].categories[y]); //add to recList recList.Add(catRec); } } }
/// <summary> /// Контрол редактирует данные о залитом масле для одного агрегата /// </summary> public CategoryRecordControl(CategoryRecord runup) : this() { AttachedObject = runup; }
protected override void Seed(ItsmDataContext db) { db.Urgencies.Add(new Urgency { Title = "High", Description = "я тут по русски вам говорю" }); db.Urgencies.Add(new Urgency { Title = "Medium", Description = "я тут по русски вам говорю" }); db.Urgencies.Add(new Urgency { Title = "Low", Description = "я тут по русски вам говорю" }); db.Impacts.Add(new Impact { Title = "Low", Description = "я тут по русски вам говорю" }); db.Impacts.Add(new Impact { Title = "Medium", Description = "я тут по русски вам говорю" }); db.Impacts.Add(new Impact { Title = "High", Description = "я тут по русски вам говорю" }); db.SaveChanges(); Urgency urg = db.Urgencies.First(u => u.Title == "Medium"); Impact imp = db.Impacts.First(i => i.Title == "Low"); IncidentPriority priority = new IncidentPriority() { Title = "Incident", Description = "Description", Impact = imp, Urgency = urg, ResolutionTime = "60", ResponceTime = "3000" }; db.IncidentPriorities.Add(priority); db.SaveChanges(); db.MethodOfNotifications.Add(new MethodOfNotification() { Title = "Phone", Description = "Phone phone" }); db.MethodOfNotifications.Add(new MethodOfNotification() { Title = "email", Description = "email email" }); db.SaveChanges(); db.ResolutionTypes.Add(new ResolutionType() { Title = "close", Description = "Closed" }); db.ResolutionTypes.Add(new ResolutionType() { Title = "registered", Description = "REGistatetd" }); db.SaveChanges(); db.CategoryRecords.Add(new CategoryRecord() { Title = "network", Description = "" }); db.SaveChanges(); CategoryRecord categoryRecord = db.CategoryRecords.First(c => c.Title == "network"); db.CategoryRecords.Add(new CategoryRecord() { Title = "switch", PearentCategory = categoryRecord }); db.SaveChanges(); List <CategoryRecord> categoryRecords = new List <CategoryRecord>(); categoryRecords.Add(db.CategoryRecords.Find(1)); List <MethodOfNotification> methodOfNotifications = new List <MethodOfNotification>(); methodOfNotifications.Add(db.MethodOfNotifications.Find(1)); methodOfNotifications.Add(db.MethodOfNotifications.Find(2)); ClosureData closure = new ClosureData() { ResolutionType = db.ResolutionTypes.Find(2), CustomerFeedback = "feedback", ClosureCategories = categoryRecords, }; db.ClosureDatas.Add(closure); db.SaveChanges(); Incident incident = new Incident() { Title = "incident 1", Description = "не работае сеть в отделе снабжения. не горят лампочки на свиче.", MethodOfNotification = db.MethodOfNotifications.Find(1), MethodOfCallback = methodOfNotifications, IncidentPriority = db.IncidentPriorities.Find(1), Owner = "Admininstartor", ServiceDescAgent = "Operator", OrderDate = DateTime.Now, Closure = db.ClosureDatas.Find(1) }; db.Incidents.Add(incident); db.SaveChanges(); }
protected virtual void AddNewRecords() { ArrayList newRecordList = new ArrayList(); System.Collections.Generic.List<Hashtable> newUIDataList = new System.Collections.Generic.List<Hashtable>(); // Loop though all the record controls and if the record control // does not have a unique record id set, then create a record // and add to the list. if (!this.ResetData) { System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater)(BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "CategoryTableControlRepeater")); if (rep == null){return;} foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items) { // Loop through all rows in the table, set its DataSource and call DataBind(). CategoryTableControlRow recControl = (CategoryTableControlRow)(repItem.FindControl("CategoryTableControlRow")); if (recControl.Visible && recControl.IsNewRecord) { CategoryRecord rec = new CategoryRecord(); if (recControl.CatDesc.Text != "") { rec.Parse(recControl.CatDesc.Text, CategoryTable.CatDesc); } if (recControl.CatName.Text != "") { rec.Parse(recControl.CatName.Text, CategoryTable.CatName); } if (recControl.ParentCatID.Text != "") { rec.Parse(recControl.ParentCatID.Text, CategoryTable.ParentCatID); } if (recControl.Status.Text != "") { rec.Parse(recControl.Status.Text, CategoryTable.Status); } newUIDataList.Add(recControl.PreservedUIData()); newRecordList.Add(rec); } } } // Add any new record to the list. for (int count = 1; count <= this.AddNewRecord; count++) { newRecordList.Insert(0, new CategoryRecord()); newUIDataList.Insert(0, new Hashtable()); } this.AddNewRecord = 0; // Finally, add any new records to the DataSource. if (newRecordList.Count > 0) { ArrayList finalList = new ArrayList(this.DataSource); finalList.InsertRange(0, newRecordList); Type myrec = typeof(FPCEstimate.Business.CategoryRecord); this.DataSource = (CategoryRecord[])(finalList.ToArray(myrec)); } // Add the existing UI data to this hash table if (newUIDataList.Count > 0) this.UIData.InsertRange(0, newUIDataList); }
internal static void ReadCategories(this IDataReader reader, out List <CategoryType> categoryTypes, out List <Category> categories) { #region load data from reader var records = new List <CategoryRecord>(); while (reader.Read()) { var cat = new CategoryRecord { ProductId = reader.GetValue <int>("product_id"), TagId = reader.GetValue <int>("tag_id"), TagName = reader.GetValue <string>("tag_name"), TagParentId = reader.IsDBNull("tag_parent_id") ? null : (int?)reader.GetValue <int>("tag_parent_id"), TagExportTypeId = reader.IsDBNull("tag_export_type_id") ? null : (int?)reader.GetValue <int>("tag_export_type_id"), IsFoodType = reader.GetValue <bool>("IsFoodType"), TagGuid = reader.GetValue <Guid>("tag_guid"), TagParentGuid = reader.IsDBNull("tag_parent_guid") ? null : (Guid?)reader.GetValue <Guid>("tag_parent_guid"), IsSelected = reader.GetValue <bool>("IsSelected") }; records.Add(cat); } #endregion #region get category types // category types don't have a parent categoryTypes = records.Where(i => !i.TagParentId.HasValue) .Select(i => new CategoryType { ProductId = i.ProductId, Id = i.TagId, ExternalId = Convert.ToString(i.TagGuid), Name = i.TagName, CategoryExportType = i.TagExportTypeId, MainCategories = new List <Category>() // will be at least one item in category }).ToList(); #endregion #region build category legs for selected ones categories = new List <Category>(); var stack = new Stack <CategoryRecord>(); records.Where(i => i.IsSelected).ToList().ForEach(c => stack.Push(c)); // for each category take all parents up to the type (the type is not included) while (stack.Count > 0) { var categoryRecord = stack.Peek(); if (categoryRecord.TagParentId.HasValue) { var parentRecord = records.Single(i => i.TagId == categoryRecord.TagParentId.Value && !i.IsSelected && i.ProductId == categoryRecord.ProductId); stack.Push(parentRecord); } else // met a category type { // build the leg of items from the top to the selected one var typeRecord = stack.Pop(); // skip the type var categoryType = categoryTypes.Single(t => t.Id == typeRecord.TagId && t.ProductId == typeRecord.ProductId); var currentRecord = stack.Pop(); var parentCategory = currentRecord.CreateCategory(); categories.Add(parentCategory); // this item maybe the selected one, so that sub items will be created later if needed categoryType.MainCategories.Add(parentCategory); // all category legs should be added to their types respectively while (!currentRecord.IsSelected) // if the current category is not selected, then need to create nested one { // take the next one and create category item currentRecord = stack.Pop(); var currentCategory = currentRecord.CreateCategory(); // add category to its parent and go down in the hierarchy parentCategory.SubCategories = new List <Category> { currentCategory }; parentCategory = currentCategory; } } } #endregion }
public JsonResult Action(CategoryActionViewModel model) { JsonResult json = new JsonResult(); try { if (model.CategoryID > 0) { var category = CategoriesService.Instance.GetCategoryByID(model.CategoryID); if (category == null) { throw new Exception("Dashboard.Categories.Action.Validation.CategoryNotFound".LocalizedString()); } if (model.ParentCategoryID > 0) { category.ParentCategoryID = model.ParentCategoryID; } else { category.ParentCategoryID = null; category.ParentCategory = null; } category.PictureID = model.PictureID; category.isFeatured = model.isFeatured; category.SanitizedName = !string.IsNullOrEmpty(model.SanitizedName) ? model.SanitizedName : model.Name.SanitizeLowerString(); category.ModifiedOn = DateTime.Now; if (!CategoriesService.Instance.UpdateCategory(category)) { throw new Exception("Dashboard.Categories.Action.Validation.UnableToUpdateCategory".LocalizedString()); } var currentCategoryRecord = category.CategoryRecords.FirstOrDefault(x => x.LanguageID == AppDataHelper.CurrentLanguage.ID); var isNewRecord = false; if (currentCategoryRecord == null) { currentCategoryRecord = new CategoryRecord(); isNewRecord = true; } currentCategoryRecord.CategoryID = category.ID; currentCategoryRecord.LanguageID = AppDataHelper.CurrentLanguage.ID; currentCategoryRecord.Name = model.Name; currentCategoryRecord.Description = model.Description; currentCategoryRecord.Summary = model.Summary; currentCategoryRecord.ModifiedOn = DateTime.Now; var result = false; if (isNewRecord) { result = CategoriesService.Instance.SaveCategoryRecord(currentCategoryRecord); } else { result = CategoriesService.Instance.UpdateCategoryRecord(currentCategoryRecord); } if (!result) { throw new Exception("Dashboard.Categories.Action.Validation.UnableToUpdateCategoryRecord".LocalizedString()); } } else { var category = new Category(); if (model.ParentCategoryID > 0) { category.ParentCategoryID = model.ParentCategoryID; } else { category.ParentCategoryID = null; category.ParentCategory = null; } category.PictureID = model.PictureID; category.isFeatured = model.isFeatured; category.SanitizedName = !string.IsNullOrEmpty(model.SanitizedName) ? model.SanitizedName : model.Name.SanitizeLowerString(); var currentLanguageCategoryRecord = new CategoryRecord { Category = category, LanguageID = AppDataHelper.CurrentLanguage.ID, Name = model.Name, Description = model.Description, Summary = model.Summary, ModifiedOn = DateTime.Now }; var result = CategoriesService.Instance.SaveCategoryRecord(currentLanguageCategoryRecord); if (!result) { throw new Exception("Dashboard.Categories.Action.Validation.UnableToCreateCategory".LocalizedString()); } } json.Data = new { Success = true }; } catch (Exception ex) { json.Data = new { Success = false, Message = ex.Message }; } return(json); }