示例#1
0
        private void LoadDiscsFromReader(SpreadsheetReader reader, LoadResult result)
        {
            //проверка наличия в файле единственного листа с заказом
            reader.CurrentSheet = 0;
            int numOfFields = 9;

            List<RmsAuto.Store.Cms.Entities.Disc> t = new List<RmsAuto.Store.Cms.Entities.Disc>();
            for (int r = 1; r < reader.RecordCount; r++)
            {
                string[] rec = new string[numOfFields];
                for (int i = 0; i < numOfFields; i++)
                    rec[i] = reader[r, i];

                rec = rec.Each(s => s.Trim()).ToArray();

                if (rec.All(s => s == ""))
                    continue;

                if (rec.All(s => string.IsNullOrEmpty(s)))
                {
                    break;
                }

                var t1 = new RmsAuto.Store.Cms.Entities.Disc();

                for (int c = 0; c < numOfFields; c++)
                {
                    string value = rec[c];
                    try
                    {
                        switch (c)
                        {
                            case 0: t1.Manufacturer = value; break;
                            case 1: t1.ModelName = value; break;
                            case 2: t1.PartNumber = value; break;
                            case 3: t1.Width = Decimal.Parse(value); break;
                            case 4: t1.Diameter = Decimal.Parse(value); break;
                            case 5: t1.Gab = Decimal.Parse(value); break;
                            case 6: t1.PCD = value; break;
                            case 7: t1.Dia = Decimal.Parse(value); break;
                        }
                    }
                    catch
                    {
                        //TODO допилить обработку ошибок
                    }
                }
                t.Add(t1);
            }

            using (CmsDataContext cms = new CmsDataContext())
            {
                try
                {
                    cms.Connection.Open();
                    cms.Transaction = cms.Connection.BeginTransaction();
                    var current = cms.Discs.Select(x => x).ToList();
                    current.Sort(new DiscComparer());
                    t.Sort(new DiscComparer());

                    t = t.Select(x => x).Distinct(new DiscComparer()).ToList();

                    //Пробегаем по каждому объекту каталога и смотрим какая у него была картинка
                    foreach (var RefObj in t)
                    {
                        var tmp = current.Where(x => x.PartNumber == RefObj.PartNumber).FirstOrDefault();
                        RefObj.ImageUrl = tmp != null && tmp.ImageUrl.HasValue ? tmp.ImageUrl : (int)NoPhotoID.Disc;
                    }

                    // "мерджим" старое и новое
                    t = t.UnionAndDistinct<RmsAuto.Store.Cms.Entities.Disc>(current, new DiscComparer());

                    cms.Discs.DeleteAllOnSubmit(current);
                    cms.Discs.InsertAllOnSubmit(t);
                    cms.SubmitChanges(ConflictMode.ContinueOnConflict);
                    cms.Transaction.Commit();
                    Response.Redirect(Request.Url.ToString());
                }
                catch (ChangeConflictException)
                {
                    //TODO допилить обработку ошибок
                    //Если не удалось изменить какую-то одну запись это не значит что нужно делать откат всего
                }
                catch (Exception)
                {
                    cms.Transaction.Rollback();
                    //ShowMessage("Указано неиспользуемое имя бренда");
                    Logger.WriteError("Ошибка при сохранении результатов загрузки дисков", EventLogerID.BLException, EventLogerCategory.BLError);
                }
                finally
                {
                    if (cms.Connection.State == System.Data.ConnectionState.Open) { cms.Connection.Close(); }
                }
            }
        }
示例#2
0
        public static void RemoveLinkFromCatalogItem(int bannerID, int catalogItemID, byte position)
        {
            using (var dc = new CmsDataContext())
            {
                try
                {
                    if (BannersForCatalogItem.Locked == false)
                    {
                        BannersForCatalogItem.Locked = true;
                        Cms.Entities.BannersForCatalogItem b = Cms.Entities.BannersForCatalogItem.GetRecord(dc, bannerID, catalogItemID, position);
                        if (b != null)
                        {
                            dc.BannersForCatalogItems.DeleteOnSubmit(b);
                            dc.SubmitChanges();
                        }
                        BannersForCatalogItem.Locked = false;
                    }
                }

                catch (Exception)
                {
                    // Записать не получилось, освободим
                    BannersForCatalogItem.Locked = false;
                }
            }
        }
示例#3
0
        public static void AddLinkToCatalogItem(int bannerID, int catalogItemID, byte position)
        {
            using (var dc = new CmsDataContext())
            {
                try
                {
                    if (BannersForCatalogItem.Locked == false)
                    {
                        BannersForCatalogItem.Locked = true;
                        Cms.Entities.BannersForCatalogItem b = Cms.Entities.BannersForCatalogItem.GetRecord(dc, bannerID, catalogItemID, position);
                        if (b == null)
                        {
                            b = new BannersForCatalogItem();
                            b.BannerID = bannerID;
                            b.CatalogItemID = catalogItemID;
                            b.IsVisible = true;
                            b.Position = position;
                            dc.BannersForCatalogItems.InsertOnSubmit(b);
                            dc.SubmitChanges();
                        }
                        else
                        {
                            b.BannerID = bannerID;
                            b.CatalogItemID = catalogItemID;
                            b.IsVisible = true;
                            b.Position = position;
                            dc.SubmitChanges();
                        }
                        BannersForCatalogItem.Locked = false;
                    }
                }

                catch (Exception)
                {
                    // Записать не получилось, освободим
                    BannersForCatalogItem.Locked = false;
                }
            }
        }
示例#4
0
 public static void ChangeLinkVisibilityToCatalogItem(int bannerID, int catalogItemID, byte position, bool isVisible)
 {
     using (var dc = new CmsDataContext())
     {
         Cms.Entities.BannersForCatalogItem b;
         try
         {
             if (BannersForCatalogItem.Locked == false)
             {
                 BannersForCatalogItem.Locked = true;
                 b = Cms.Entities.BannersForCatalogItem.GetRecord(dc, bannerID, catalogItemID, position);
                 b.IsVisible = isVisible;
                 dc.SubmitChanges();
                 BannersForCatalogItem.Locked = false;
             }
         }
         catch (Exception)
         {
             // значит записи такой нет
             BannersForCatalogItem.Locked = false;
         }
     }
 }
示例#5
0
        private void LoadTiresFromReader(SpreadsheetReader reader, LoadResult result)
        {
            //проверка наличия в файле единственного листа с заказом
            reader.CurrentSheet = 0;
            int numOfFields = 9;

            List<RmsAuto.Store.Cms.Entities.Battery> t = new List<RmsAuto.Store.Cms.Entities.Battery>();
            for (int r = 1; r < reader.RecordCount; r++)
            {
                string[] rec = new string[numOfFields];
                for (int i = 0; i < numOfFields; i++)
                    rec[i] = reader[r, i];

                rec = rec.Each(s => s.Trim()).ToArray();

                if (rec.All(s => s == ""))
                    continue;

                if (rec.All(s => string.IsNullOrEmpty(s)))
                {
                    break;
                }

                var t1 = new RmsAuto.Store.Cms.Entities.Battery();

                for (int c = 0; c < numOfFields; c++)
                {
                    string value = rec[c];
                    try
                    {
                        switch (c)
                        {
                            case 0: t1.Manufacturer = value; break;
                            case 1: t1.ModelName = value; break;
                            case 2: t1.PartNumber = value; break;
                            case 3: t1.Capacity = Decimal.Parse(value); break;
                            case 4: t1.polarity = value; break;
                            case 5: t1.cleat = value; break;
                            case 6: t1.Size = value; break;
                        }
                    }
                    catch
                    {
                        //TODO допилить обработку ошибок
                    }
                }
                t.Add(t1);
            }

            using (CmsDataContext cms = new CmsDataContext())
            {
                try
                {
                    cms.Connection.Open();
                    cms.Transaction = cms.Connection.BeginTransaction();
                    var current = cms.Batteries.Select(x => x).ToList();
                    current.Sort(new BatteryComparer());
                    t.Sort(new BatteryComparer());

                    t = t.Select(x => x).Distinct(new BatteryComparer()).ToList();

                    //Пробегаем по каждому объекту каталога и смотрим какая у него была картинка
                    foreach (var RefObj in t)
                    {
                        var tmp = current.Where(x => x.PartNumber == RefObj.PartNumber).FirstOrDefault();
                        RefObj.ImageUrl = tmp != null && tmp.ImageUrl.HasValue ? tmp.ImageUrl : (int)NoPhotoID.Battery;
                    }

                    t = t.UnionAndDistinct<RmsAuto.Store.Cms.Entities.Battery>(current, new BatteryComparer());

                    cms.Batteries.DeleteAllOnSubmit(current);
                    cms.Batteries.InsertAllOnSubmit(t);
                    cms.SubmitChanges(ConflictMode.ContinueOnConflict);
                    cms.Transaction.Commit();
                }
                catch (ChangeConflictException)
                {
                    //TODO допилить обработку ошибок
                }
                catch (Exception)
                {
                    cms.Transaction.Rollback();
                    Logger.WriteError("Ошибка при сохранении результатов загрузки аккумуляторов", EventLogerID.BLException, EventLogerCategory.BLError);
                }
                finally
                {
                    if (cms.Connection.State == System.Data.ConnectionState.Open) { cms.Connection.Close(); }
                }
            }
        }