Пример #1
0
        public void LoadItem(int id)
        {
            DataAccess da = new DataAccess();
            _spare = da.GetSpare(id);
            if (_spare != null)
            {
                IsNew = false;
                if (_spare.brand == null)
                    _spare.brandReference.Load();
                if (_spare.spare_group == null)
                    _spare.spare_groupReference.Load();
                if (_spare.unit == null)
                    _spare.unitReference.Load();
                _id = _spare.id;
                string Name = _spare.name;
                string Code = _spare.code;
                string CodeShatem = _spare.codeShatem;
                string QDemand = _spare.q_demand.ToString();
                int GroupID = _spare.spare_group.id;
                int BrandID = _spare.brand.id;
                int UnitID = _spare.unit.id;
                string BrandName = _spare.brand.name;
                string GroupName = _spare.spare_group.name;
                string UnitName = _spare.unit.name;
                string Description = _spare.description;
                OldBrandName = BrandName;
                OldGroupID = GroupID;

                edtName.Text = Name;
                edtCode.Text = Code;
                edtCodeShatem.Text = CodeShatem;
                edtQ_Demand.Text = QDemand;
                edtGroup.SelectedValue = GroupID;
                edtBrand.SelectedValue = BrandID;
                edtUnit.SelectedValue = UnitID;
                edtDescr.Text = Description;
            }
        }
Пример #2
0
        // ЗАПЧАСТЬ - ДОБАВИТЬ - СОХРАНИТЬ
        public spare SpareCreate(string Name, string Code, string CodeShatem, int QDemand, int GroupID, int BrandID, string UnitName, string Description)
        {
            DataAccess da = new DataAccess();
            spare sp = new spare();
            sp.name = Name;
            sp.code = Code;
            sp.codeShatem = CodeShatem;
            sp.q_demand = QDemand;
            sp.q_demand_clear = QDemand;
            sp.q_rest = 0;
            sp.description = Description;
            spare s = da.SpareCreate(sp, BrandID, GroupID, UnitName);

            SpareContainer.Instance.Update(s.id);

            if (SpareContainer.Instance.Spares.Where(
                    i => i.BrandID == BrandID && i.GroupID == GroupID).Count() == 1)
            {
                da.SpareGroupCreate(GroupID, BrandID);
            }
            return s;
        }
Пример #3
0
        //private delegate void UpdateProgressBarDelegate(System.Windows.DependencyProperty dp, Object value);
        public static int getSpares(string FilePath)
        {
            List<spare> items = new List<spare>();

            // Объявляем и забиваем файл в документ
            XmlDocument xd = new XmlDocument();
            FileStream fs = new FileStream(FilePath, FileMode.Open);
            xd.Load(fs);
            DataAccess da = new DataAccess();

            XmlNodeList list = xd.GetElementsByTagName("Row"); // Создаем и заполняем лист по тегу "user"

            LoadingWindowView v = new LoadingWindowView();
            v._ProgressBar.Minimum = 0;
            v._ProgressBar.Maximum = list.Count;
            v._ProgressBar.Value = list.Count / 2;

            //object value = 0;
            //Сохраняем значение ProgressBar
            //Создаем новый экземпляр делегата для ProgressBar
            // который показывает на метод ProgressBar.SetValue
            //UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(v._ProgressBar.SetValue);
            v.Show();
            string Errors = "";
            for (int i = 1; i < list.Count; i++)
            {
                try
                {
                    spare b = new spare();
                    b.code1C = list[i].ChildNodes[0].InnerText;
                    if (!da.ExistCode1C(b.code1C))
                    {
                        b.codeShatem = list[i].ChildNodes[1].InnerText;
                        b.name = list[i].ChildNodes[2].InnerText;
                        string BrandCode1C = list[i].ChildNodes[3].InnerText;
                        string GroupCode1C = list[i].ChildNodes[4].InnerText;
                        da.SpareCreate(b, BrandCode1C, GroupCode1C);
                    }
                }
                catch (Exception qwe)
                {
                    Errors += qwe.Message;
                }
            }

            // Закрываем поток
            fs.Close();
            v.Close();
            return items.Count;
        }
Пример #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the spares EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTospares(spare spare)
 {
     base.AddObject("spares", spare);
 }
Пример #5
0
 /// <summary>
 /// Create a new spare object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="name">Initial value of the name property.</param>
 /// <param name="code">Initial value of the code property.</param>
 /// <param name="codeShatem">Initial value of the codeShatem property.</param>
 public static spare Createspare(global::System.Int32 id, global::System.String name, global::System.String code, global::System.String codeShatem)
 {
     spare spare = new spare();
     spare.id = id;
     spare.name = name;
     spare.code = code;
     spare.codeShatem = codeShatem;
     return spare;
 }
Пример #6
0
        private void BackgroundCreate_DoWork(object sender, DoWorkEventArgs e)
        {
            DataAccess da = new DataAccess();
            spare sp = new spare();
            sp.name = SpareUpdateName;
            sp.code = SpareUpdateCode;
            sp.codeShatem = SpareUpdateCodeShatem;
            sp.q_demand = SpareUpdateQDemand;
            sp.q_demand_clear = SpareUpdateQDemand;
            sp.q_rest = 0;
            sp.description = SpareUpdateDescription;
            spare s = da.SpareCreate(sp, SpareUpdateBrandID, SpareUpdateGroupID, SpareUpdateUnitID);
            SpareContainer.Instance.Update(s.id);

            if (SpareContainer.Instance.Spares.Where(i => i.BrandID == SpareUpdateBrandID && i.GroupID == SpareUpdateGroupID).Count() == 1)
            {
                if (s.brand == null)
                    s.brandReference.Load();
                da.SpareGroupCreate(SpareUpdateGroupID, s.brand.name);
                ReloadGroups = true;
            }
        }
Пример #7
0
        public spare SpareEdit(spare item)
        {
            spare original = objDataContext.spares.FirstOrDefault(b => b.id == item.id);
            if (original != null)
            {
                original.name = item.name;

                //original.description = item.description;
                //if (original.created_on == null)
                //    original.created_on = DateTime.Now;
                objDataContext.SaveChanges();
            }
            return original;
        }
Пример #8
0
 public spare SpareEdit(spare item, int BrandID, int GroupID, int UnitID)
 {
     spare original = objDataContext.spares.FirstOrDefault(b => b.id == item.id);
     if (original != null)
     {
         original.name = item.name;
         original.brand = objDataContext.brands.FirstOrDefault(i => i.id == BrandID);
         if (original.spare_group == null)
             original.spare_groupReference.Load();
         int OldGroupID = original.spare_group.id;
         original.spare_group = objDataContext.spare_group.FirstOrDefault(i => i.id == GroupID);
         if (original.spare_group.id != OldGroupID)
         {
             int ParentID1 = GetParentGroupID(original.spare_group.id);
             if (ParentID1 > 0)
             {
                 original.spare_group1 = objDataContext.spare_group.FirstOrDefault(i => i.id == ParentID1);
                 int ParentID2 = GetParentGroupID(original.spare_group1.id);
                 if (ParentID2 > 0)
                 {
                     original.spare_group2 = objDataContext.spare_group.FirstOrDefault(i => i.id == ParentID2);
                     int ParentID3 = GetParentGroupID(original.spare_group2.id);
                     if (ParentID3 > 0)
                     {
                         original.spare_group3 = objDataContext.spare_group.FirstOrDefault(i => i.id == ParentID3);
                     }
                 }
             }
         }
         original.unit = objDataContext.units.FirstOrDefault(i => i.id == UnitID);
         original.description = item.description;
         original.cashless = item.cashless;
         original.code = item.code;
         original.codeShatem = item.codeShatem;
         original.q_demand = item.q_demand;
         original.q_rest = item.q_rest;
         objDataContext.SaveChanges();
     }
     return original;
 }
Пример #9
0
        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;
        }
Пример #10
0
        public spare SpareCreate(spare item, string BrandCode1C, string GroupCode1C)
        {
            item.q_rest = 0;
            string UnitName = "шт.";
            item.brand = objDataContext.brands.FirstOrDefault(i => i.code1C == BrandCode1C);
            item.spare_group = objDataContext.spare_group.FirstOrDefault(i => i.code1C == GroupCode1C);
            int spare_group1ID = GetParentGroupID(item.spare_group.id);

            if (spare_group1ID > 0)
            {
                item.spare_group1 = objDataContext.spare_group.FirstOrDefault(i => i.id == spare_group1ID);
                int spare_group2ID = GetParentGroupID(spare_group1ID);
                if (spare_group2ID > 0)
                {
                    item.spare_group2 = objDataContext.spare_group.FirstOrDefault(i => i.id == spare_group2ID);
                    int spare_group3ID = GetParentGroupID(spare_group2ID);
                    if (spare_group3ID > 0)
                        item.spare_group3 = objDataContext.spare_group.FirstOrDefault(i => i.id == spare_group3ID);
                }
            }

            item.unit = objDataContext.units.FirstOrDefault(i => i.name == UnitName);
            objDataContext.AddTospares(item);
            objDataContext.SaveChanges();
            return item;
        }
Пример #11
0
        public spare SpareCreate(spare _obj, int BrandID, int GroupID, string UnitName)
        {
            _obj.q_rest = 0;
            if (_obj.code == null)
                _obj.code = "";
            _obj.brand = objDataContext.brands.FirstOrDefault(i => i.id == BrandID);

            // group
            _obj.spare_group = objDataContext.spare_group.FirstOrDefault(i => (i.id == GroupID && i.ChildCount == 0));
            int ParentID1 = GetParentGroupID(_obj.spare_group.id);
            if (ParentID1 > 0)
            {
                _obj.spare_group1 = objDataContext.spare_group.FirstOrDefault(i => i.id == ParentID1);
                int ParentID2 = GetParentGroupID(_obj.spare_group1.id);
                if (ParentID2 > 0)
                {
                    _obj.spare_group2 = objDataContext.spare_group.FirstOrDefault(i => i.id == ParentID2);
                    int ParentID3 = GetParentGroupID(_obj.spare_group2.id);
                    if (ParentID3 > 0)
                    {
                        _obj.spare_group3 = objDataContext.spare_group.FirstOrDefault(i => i.id == ParentID3);
                    }
                }
            }
            _obj.unit = objDataContext.units.FirstOrDefault(i => i.name == UnitName);
            objDataContext.AddTospares(_obj);
            objDataContext.SaveChanges();
            return objDataContext.spares.FirstOrDefault(i => i.id == _obj.id);
        }
Пример #12
0
        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();
        }
Пример #13
0
        public void SpareCreate(spare _obj)
        {
            _obj.q_rest = 0;

            //_obj.created_on = DateTime.Now;
            objDataContext.AddTospares(_obj);
            objDataContext.SaveChanges();
        }