public DataAccess() { objDataContext = new DriveEntities(); objDataContext.ContextOptions.LazyLoadingEnabled = true; root = objDataContext.spare_group.FirstOrDefault(i => i.id == 1); u = objDataContext.units.FirstOrDefault(i => i.id == 1); }
public static List<spare_group> getGroups(string FilePath) { List<spare_group> items = new List<spare_group>(); // Объявляем и забиваем файл в документ XmlDocument xd = new XmlDocument(); FileStream fs = new FileStream(FilePath, FileMode.Open); xd.Load(fs); XmlNodeList list = xd.GetElementsByTagName("Row"); // Создаем и заполняем лист по тегу "row" for (int i = 0; i < list.Count; i++) { spare_group b = new spare_group(); b.code1C = list[i].FirstChild.InnerText; b.name = list[i].LastChild.InnerText; items.Add(b); } MessageBox.Show("Сформирован список из " + items.Count.ToString() + " элементов."); DataAccess da = new DataAccess(); int xc = 0; foreach (spare_group i in items) { da.SpareGroupCreate(i); xc++; } MessageBox.Show("Добавлено " + xc.ToString() + " элементов."); FixGroupsParents(list); // Закрываем поток fs.Close(); return items; }
private int EditItem() { DataAccess da = new DataAccess(); spare_group item = new spare_group(); item.id = da.GetSpareGroups().FirstOrDefault(g => g.name == _groupName).id; item.name = edtName.Text; item.description = edtDescr.Text; return da.SpareGroupEdit(item); }
private spare_group CreateItem() { DataAccess da = new DataAccess(); spare_group i = new spare_group(); i.name = edtName.Text; i.description = edtDescr.Text; i.ParentGroup = da.GetSpareGroups().FirstOrDefault(g => g.name == _parentName); return da.SpareGroupCreate(i); }
/// <summary> /// Deprecated Method for adding a new object to the spare_group EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddTospare_group(spare_group spare_group) { base.AddObject("spare_group", spare_group); }
/// <summary> /// Create a new spare_group object. /// </summary> /// <param name="id">Initial value of the id property.</param> /// <param name="name">Initial value of the name property.</param> /// <param name="isBrand">Initial value of the IsBrand property.</param> public static spare_group Createspare_group(global::System.Int32 id, global::System.String name, global::System.Boolean isBrand) { spare_group spare_group = new spare_group(); spare_group.id = id; spare_group.name = name; spare_group.IsBrand = isBrand; return spare_group; }
public int SpareGroupEdit(spare_group i) { spare_group original = objDataContext.spare_group.FirstOrDefault(b => b.id == i.id); if (original != null) { if (SpareGroupNameExist(i.name)) return -1; original.name = i.name; original.description = i.description; objDataContext.SaveChanges(); return 0; } return -1; }
public void SpareGroupDelete(spare_group i) { var childs = objDataContext.spare_group.Where(g => g.ParentGroup.id == i.id); while (childs.Count() > 0) { spare_group g = childs.ToList()[0]; moveSparesInGroupToRoot(g.id); SpareGroupDelete(g); } moveSparesInGroupToRoot(i.id); objDataContext.DeleteObject(i); objDataContext.SaveChanges(); }
public int SpareGroupCreate(int GroupID, int BrandID) { brand b = objDataContext.brands.FirstOrDefault(br => br.id == BrandID); if (b == null) return 0; spare_group i = new spare_group(); i.IsBrand = true; i.name = b.name; spare_group sg = objDataContext.spare_group.FirstOrDefault(s => s.id == GroupID); i.ParentGroupName = sg.name; i.ParentGroup = sg; i.description = b.name; i.ChildCount = 0; i.code1C = ""; objDataContext.AddTospare_group(i); objDataContext.SaveChanges(); return 0; }
public int SpareGroupCreate(int GroupID, string BrandName) { spare_group i = new spare_group(); i.IsBrand = true; i.name = BrandName; spare_group sg = objDataContext.spare_group.FirstOrDefault(s => s.id == GroupID); i.ParentGroupName = sg.name; i.ParentGroup = sg; i.description = BrandName; i.ChildCount = 0; i.code1C = ""; objDataContext.AddTospare_group(i); objDataContext.SaveChanges(); return 0; }
public spare_group SpareGroupCreate(spare_group i) { if (SpareGroupNameExist(i.name)) i.name += " "; objDataContext.AddTospare_group(i); objDataContext.SaveChanges(); return i; }
public spare SpareCreateSilent(string Name, string CodeShatem, string GroupName, string ParentGroupName, string BrandName, string UnitName, string Description) { // получим группу //spare_group ParentGroup = objDataContext.spare_group.FirstOrDefault(i => i.id == 1).spare_group1.FirstOrDefault(x => x.name.ToUpper() == ParentGroupName.ToUpper()); List<spare_group> groups = objDataContext.spare_group.Where(i => i.ParentGroup.id == 1).ToList(); // все группы, дочерние группе #1 groups = groups.Where(i => i.name.ToUpper().Equals(ParentGroupName.ToUpper())).ToList(); spare_group ParentGroup = null; if (groups.Count > 0) ParentGroup = groups[0]; if (ParentGroup == null) { // создать новую группу spare_group sgNew = new spare_group(); sgNew.name = ParentGroupName; spare_group root = objDataContext.spare_group.FirstOrDefault(x => x.id == 1); sgNew.ParentGroup = root; sgNew.IsBrand = false; sgNew.ChildCount = 0; sgNew.code1C = ""; sgNew.description = ""; sgNew.ParentGroupName = root.name; objDataContext.AddTospare_group(sgNew); objDataContext.SaveChanges(); ParentGroup = sgNew; } // получим подгруппу //spare_group group = objDataContext.spare_group.FirstOrDefault(i => i.id == ParentGroup.id).spare_group1.FirstOrDefault(x => x.name.ToUpper() == GroupName.ToUpper()); groups = objDataContext.spare_group.Where(i => i.ParentGroup.id == ParentGroup.id).ToList(); groups = groups.Where(i => i.name.ToUpper().Equals(GroupName.ToUpper())).ToList(); spare_group group = null; if (groups.Count > 0) group = groups[0]; if (group == null) { // создать новую группу spare_group sgNew = new spare_group(); sgNew.name = GroupName; spare_group parent = objDataContext.spare_group.FirstOrDefault(x => x.id == ParentGroup.id); sgNew.ParentGroup = parent; sgNew.IsBrand = false; sgNew.ChildCount = 0; sgNew.code1C = ""; sgNew.description = ""; sgNew.ParentGroupName = parent.name; parent.ChildCount++; objDataContext.AddTospare_group(sgNew); objDataContext.SaveChanges(); group = sgNew; } // получим брэнд brand b = objDataContext.brands.FirstOrDefault(i => i.name == BrandName); if (b == null) { brand bNew = new brand(); bNew.name = BrandName; objDataContext.AddTobrands(bNew); objDataContext.SaveChanges(); b = bNew; } // получим unit unit u = objDataContext.units.FirstOrDefault(x => x.name == UnitName); if (u == null) { unit bNew = new unit(); bNew.name = UnitName; objDataContext.AddTounits(bNew); objDataContext.SaveChanges(); u = bNew; } spare sp = new spare(); sp.name = Name; sp.code = ""; sp.codeShatem = CodeShatem; sp.q_demand = 0; sp.q_demand_clear = 0; sp.q_rest = 0; sp.description = Description; sp.spare_group1 = ParentGroup; sp.spare_group = group; int GroupID = group.id; sp.brand = b; sp.unit = u; // [spare_group2_id] if (sp.spare_group1.ParentGroup != null) { spare_group group2 = objDataContext.spare_group.FirstOrDefault(x => x.id == sp.spare_group1.ParentGroup.id); if (group2 != null) { sp.spare_group2 = group2; // [spare_group3_id] if (group2.ParentGroup != null) { spare_group group3 = objDataContext.spare_group.FirstOrDefault(x => x.id == group2.ParentGroup.id); if (group3 != null) sp.spare_group3 = group3; } } } // [BrandName] sp.BrandName = sp.brand.name; // [GroupName] sp.GroupName = sp.spare_group.name; // [ParentGroupName] sp.ParentGroupName = sp.spare_group1.name; objDataContext.AddTospares(sp); objDataContext.SaveChanges(); //spare s = SpareCreate(sp, sp.brand.id, sp.spare_group.id, b.id); return sp; }
public void SpareCreate(string GrandParentGroupName, string ParentGroupName, string BrandName, string SpareCode, string SpareName, string SpareCars) { if (GrandParentGroupName.Equals(ParentGroupName)) ParentGroupName += "_"; // ============================================= // grand pa group spare_group gsg = null; //get group gsg = objDataContext.spare_group.FirstOrDefault(i => i.name.Equals(GrandParentGroupName)); if (gsg == null) { // create new brand gsg = new spare_group(); gsg.name = GrandParentGroupName; gsg.ParentGroup = root; objDataContext.AddTospare_group(gsg); objDataContext.SaveChanges(); } // ============================================= // pa group spare_group sg = null; //get group sg = objDataContext.spare_group.FirstOrDefault(i => i.name.Equals(ParentGroupName)); if (sg == null) { // create new brand sg = new spare_group(); sg.name = ParentGroupName; sg.ParentGroup = gsg; objDataContext.AddTospare_group(sg); objDataContext.SaveChanges(); } // ============================================= // brand brand b = null; //get brand b = objDataContext.brands.FirstOrDefault(i => i.name.Equals(BrandName)); if (b == null) { // create new brand b = new brand(); b.name = BrandName; objDataContext.AddTobrands(b); objDataContext.SaveChanges(); } // spare spare s = new spare(); s.spare_group2 = root; s.spare_group1 = gsg; s.spare_group = sg; s.brand = b; // ============================================= // code s.code = SpareCode; // ============================================= // name + models s.name = SpareName + "( " + SpareCars + ")"; // ============================================= // defs s.description = ""; s.q_rest = 0; s.q_demand = 0; s.cashless = 0; s.unit = u; s.q_demand_clear = 0; s.codeShatem = ""; // add & save objDataContext.AddTospares(s); objDataContext.SaveChanges(); }